From patchwork Mon Oct 31 15:45:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9405733 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D1CB60722 for ; Mon, 31 Oct 2016 15:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94FC329330 for ; Mon, 31 Oct 2016 15:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8987729331; Mon, 31 Oct 2016 15:45:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3986129332 for ; Mon, 31 Oct 2016 15:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S944287AbcJaPpI (ORCPT ); Mon, 31 Oct 2016 11:45:08 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:55293 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S944231AbcJaPpG (ORCPT ); Mon, 31 Oct 2016 11:45:06 -0400 Received: from ayla.of.borg ([84.193.137.253]) by laurent.telenet-ops.be with bizsmtp id 2Fl41u00H5UCtCs01Fl4c0; Mon, 31 Oct 2016 16:45:04 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1c1Elk-0005Am-6W; Mon, 31 Oct 2016 16:45:04 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1c1Elq-0002lv-OP; Mon, 31 Oct 2016 16:45:10 +0100 From: Geert Uytterhoeven To: Konrad Rzeszutek Wilk , Jonathan Corbet Cc: Magnus Damm , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, iommu@lists.linux-foundation.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/2] swiotlb: Add swiotlb=nobounce debug option Date: Mon, 31 Oct 2016 16:45:04 +0100 Message-Id: <1477928704-10611-3-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477928704-10611-1-git-send-email-geert+renesas@glider.be> References: <1477928704-10611-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On architectures like arm64, swiotlb is tied intimately to the core architecture DMA support. In addition, ZONE_DMA cannot be disabled. To aid debugging and catch devices not supporting DMA to memory outside the 32-bit address space, add a kernel command line option "swiotlb=nobounce", which disables the use of bounce buffers. If specified, trying to map memory that cannot be used with DMA will fail, and a warning will be printed (rate-limited). Note that io_tlb_nslabs is set to 1, which is the minimal supported value. Signed-off-by: Geert Uytterhoeven --- Documentation/kernel-parameters.txt | 3 ++- lib/swiotlb.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 37babf91f2cb6de2..38556cdceabaf087 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -3998,10 +3998,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted. it if 0 is given (See Documentation/cgroup-v1/memory.txt) swiotlb= [ARM,IA-64,PPC,MIPS,X86] - Format: { | force } + Format: { | force | nobounce } -- Number of I/O TLB slabs force -- force using of bounce buffers even if they wouldn't be automatically used by the kernel + nobounce -- Never use bounce buffers (for debugging) switches= [HW,M68k] diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 6ce764410ae475cc..4550e6b516c2a4c0 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -54,6 +54,7 @@ #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) int swiotlb_force; +static int swiotlb_nobounce; /* * Used to do a quick range check in swiotlb_tbl_unmap_single and @@ -106,8 +107,12 @@ } if (*str == ',') ++str; - if (!strcmp(str, "force")) + if (!strcmp(str, "force")) { swiotlb_force = 1; + } else if (!strcmp(str, "nobounce")) { + swiotlb_nobounce = 1; + io_tlb_nslabs = 1; + } return 0; } @@ -541,8 +546,15 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, map_single(struct device *hwdev, phys_addr_t phys, size_t size, enum dma_data_direction dir) { - dma_addr_t start_dma_addr = phys_to_dma(hwdev, io_tlb_start); + dma_addr_t start_dma_addr; + + if (swiotlb_nobounce) { + dev_warn_ratelimited(hwdev, "Cannot do DMA to address %pa\n", + &phys); + return SWIOTLB_MAP_ERROR; + } + start_dma_addr = phys_to_dma(hwdev, io_tlb_start); return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size, dir); } @@ -707,6 +719,9 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, swiotlb_full(struct device *dev, size_t size, enum dma_data_direction dir, int do_panic) { + if (swiotlb_nobounce) + return; + /* * Ran out of IOMMU space for this operation. This is very bad. * Unfortunately the drivers cannot handle this operation properly.