From patchwork Tue Apr 9 12:53:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 161980 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4910861jan; Tue, 9 Apr 2019 05:57:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvzWyUJHiQxRLIM9E+KrhhsrySPPtAjs8DQ5lCAmR8sKMJVRoN8SUYGERJFMi1iT+f/R4u X-Received: by 2002:a65:4341:: with SMTP id k1mr34973067pgq.88.1554814651622; Tue, 09 Apr 2019 05:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554814651; cv=none; d=google.com; s=arc-20160816; b=QZpP1LSUmB2Q77qjx38dkdMtV7Eq3Ff8PQMfo8/iwtT/14CoA0lN9BxSlWCP8hwBQM SbQ8zfhlXV2swH0j64al1Ej53BwvKowRXXS4FixFQqEg33hJb6BRgnlDIQs07sk6a8hN BdZz7VkZkC//5YYlMWSbepwiHex4q98Tsk/UxVZK58hgcwtqTjR40KoO5SlYtEo+Vpls 8IWlp8c+j6B90vS9iWD7gLDBwVVvZLwUbeyTdGDWMD8qbpSUhlwwfH821eahad49WK7q 8PaViPQqtp6RISnguckkgqpCkw6GYDdcRoIuIh7EYI5BSmvc4G+zUoJzu4/TwBiGLN8E ex2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UmXWmyeGD3B3vDnObRdPPPKDXrAOO6ia5LjcoJiTiKY=; b=OnGHIuRKG51Vuye75YhbQZgPJcAz+wguTgF3z+D/yzvIEx6j7k6q+4iCi0+mYw9UqL Ytk74J8VXxfAXGaW2vJGl4sA4RfSe2Evo9ilhw6IuVIaT5Jwms0btzkcMC/CpujpL5Dk 9XONIl5dCiHIiTSB+tHr1M30ZVWKk06K2eOe1vG/LfKTzTTImDyA71a4hcCGl01miWsc /OBWeJRxIq3K7JGi3J3M4zpJBhrOy6hhevKjprrOEF1DLGylPlMPNH3eQsOP7CQkS9yX TVOtRSs9+1X0x5aEm7ZrlHpLyM/fAm2FjDDN5Y0A7JrCzjYlBySgR5BaB9jJDr25gxHB e4yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6si30601705pgp.459.2019.04.09.05.57.31; Tue, 09 Apr 2019 05:57:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727321AbfDIM5a (ORCPT + 31 others); Tue, 9 Apr 2019 08:57:30 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33590 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727030AbfDIM51 (ORCPT ); Tue, 9 Apr 2019 08:57:27 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 69556E42FB4B562EA00F; Tue, 9 Apr 2019 20:54:15 +0800 (CST) Received: from HGHY1l002753561.china.huawei.com (10.177.23.164) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 20:54:06 +0800 From: Zhen Lei To: Jean-Philippe Brucker , John Garry , Robin Murphy , Will Deacon , Joerg Roedel , Jonathan Corbet , linux-doc , Sebastian Ott , Gerald Schaefer , "Martin Schwidefsky" , Heiko Carstens , Benjamin Herrenschmidt , Paul Mackerras , "Michael Ellerman" , Tony Luck , Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , David Woodhouse , iommu , linux-kernel , linux-s390 , linuxppc-dev , x86 , linux-ia64 CC: Zhen Lei , Hanjun Guo Subject: [PATCH v5 4/6] s390/pci: add support for generic boot option iommu.dma_mode Date: Tue, 9 Apr 2019 20:53:06 +0800 Message-ID: <20190409125308.18304-5-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20190409125308.18304-1-thunder.leizhen@huawei.com> References: <20190409125308.18304-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org s390_iommu=strict is equivalent to iommu.dma_mode=strict. Signed-off-by: Zhen Lei --- Documentation/admin-guide/kernel-parameters.txt | 6 +++--- arch/s390/pci/pci_dma.c | 14 +++++++------- drivers/iommu/Kconfig | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) -- 1.8.3 Acked-by: Sebastian Ott diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 92d1b3151d003c2..ab8e3c4798c0a2a 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1815,9 +1815,9 @@ options(such as CONFIG_IOMMU_DEFAULT_PASSTHROUGH) to choose which mode to be used. Note: For historical reasons, ARM64/S390/PPC/X86 have - their specific options. Currently, only ARM64 support - this boot option, and hope other ARCHs to use this as - generic boot option. + their specific options. Currently, only ARM64/S390 + support this boot option, and hope other ARCHs to use + this as generic boot option. passthrough Configure DMA to bypass the IOMMU by default. lazy diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c index 9e52d1527f71495..f658ca41547eed5 100644 --- a/arch/s390/pci/pci_dma.c +++ b/arch/s390/pci/pci_dma.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ static struct kmem_cache *dma_region_table_cache; static struct kmem_cache *dma_page_table_cache; -static int s390_iommu_strict; static int zpci_refresh_global(struct zpci_dev *zdev) { @@ -193,13 +193,13 @@ static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr, if (!zdev->tlb_refresh) return 0; } else { - if (!s390_iommu_strict) + if (!IOMMU_DMA_MODE_IS_STRICT()) return 0; } ret = zpci_refresh_trans((u64) zdev->fh << 32, dma_addr, PAGE_ALIGN(size)); - if (ret == -ENOMEM && !s390_iommu_strict) { + if (ret == -ENOMEM && !IOMMU_DMA_MODE_IS_STRICT()) { /* enable the hypervisor to free some resources */ if (zpci_refresh_global(zdev)) goto out; @@ -278,7 +278,7 @@ static dma_addr_t dma_alloc_address(struct device *dev, int size) spin_lock_irqsave(&zdev->iommu_bitmap_lock, flags); offset = __dma_alloc_iommu(dev, zdev->next_bit, size); if (offset == -1) { - if (!s390_iommu_strict) { + if (!IOMMU_DMA_MODE_IS_STRICT()) { /* global flush before DMA addresses are reused */ if (zpci_refresh_global(zdev)) goto out_error; @@ -313,7 +313,7 @@ static void dma_free_address(struct device *dev, dma_addr_t dma_addr, int size) if (!zdev->iommu_bitmap) goto out; - if (s390_iommu_strict) + if (IOMMU_DMA_MODE_IS_STRICT()) bitmap_clear(zdev->iommu_bitmap, offset, size); else bitmap_set(zdev->lazy_bitmap, offset, size); @@ -584,7 +584,7 @@ int zpci_dma_init_device(struct zpci_dev *zdev) rc = -ENOMEM; goto free_dma_table; } - if (!s390_iommu_strict) { + if (!IOMMU_DMA_MODE_IS_STRICT()) { zdev->lazy_bitmap = vzalloc(zdev->iommu_pages / 8); if (!zdev->lazy_bitmap) { rc = -ENOMEM; @@ -675,7 +675,7 @@ void zpci_dma_exit(void) static int __init s390_iommu_setup(char *str) { if (!strncmp(str, "strict", 6)) - s390_iommu_strict = 1; + iommu_default_dma_mode_set(IOMMU_DMA_MODE_STRICT); return 0; } diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 1986f9767da488b..b7173b106cd816a 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -77,6 +77,7 @@ config IOMMU_DEBUGFS choice prompt "IOMMU dma mode" depends on IOMMU_API + default IOMMU_DEFAULT_LAZY if S390_IOMMU default IOMMU_DEFAULT_STRICT help This option allows IOMMU dma mode to be chose at build time, to