From patchwork Fri Mar 29 02:54:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 161382 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1487899jan; Thu, 28 Mar 2019 19:54:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvhoQvj9IAE1xYbDRuQsnY+W4+QDB467yMerFt4mRRHA4riB3ZNuHxcyqWMUez/caPuvgY X-Received: by 2002:a17:902:12f:: with SMTP id 44mr46721285plb.208.1553828096428; Thu, 28 Mar 2019 19:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553828096; cv=none; d=google.com; s=arc-20160816; b=iCv0Ho+yVmVp93nw3l4K1D8LwyEROMCo1gHHp/vNbU2TlxFU7Tq2e3033gPgJRn24h ijcczN+2EpyRRBNi51ZVWwJIJjMtGiweetocAMCsn9L9s9yET7Qs63gvPAMNyT9JrUWl XfWyx9ctnVXUGgifcAc3bIkYOzfo5boSszkI5JKs3sEER/NIAxzmO50mC5GaAC5mREGG r7zAWXj9+Ca8SUopNcf8unMaoiMD9Im5xC2KarFe9EXarexk8O7VaZBAGOn8SYR9ebMo hjapzjWDMg1AMObAx+aLWflZ46UMrjhO7P+RCExiP6taUriHZOoAO0AK1LzuFfqwgNBU Nl7w== 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 :message-id:date:subject:cc:to:from; bh=zpFQEPXm9PzfM71jaYUKpZqDW09JKsjRrgURjvAHJk4=; b=PcJFvvD/B2oMxNhFRXWfBnqncw0KPU47F+JqZWqKnv9rUXBKgueW8ha5NHs//RLZD/ UUJJbGlCRTVWDcObCVAwYgKVIb0/0jv7r/zAvyr9YjzrLZposIeolFm+5M1tkaRzb4ga OobkSiUZ2PBi/c78cFJ0RoPx8Az7b9j9BEkBQvCO63IDQglXTpZeBy0nwPQanv0eZ1X8 2lKAJedJOp6ViF8Q5Hi6vuzQ5izk7QN1BWMd0sndEIAnAWMtbw1zKZWHhW2mgbHTza3j HgxRnzcwZcwsCe7+8ft9O2pR4K7jhcf/bj/L0NDjNlP07vwX2m3dc+Bqold4EhRfSpVI jkdA== 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 g5si788814pgk.402.2019.03.28.19.54.55; Thu, 28 Mar 2019 19:54:56 -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 S1728567AbfC2Cyy (ORCPT + 31 others); Thu, 28 Mar 2019 22:54:54 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:58826 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727938AbfC2Cyx (ORCPT ); Thu, 28 Mar 2019 22:54:53 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2B900E3BB810FE93EF91; Fri, 29 Mar 2019 10:54:52 +0800 (CST) Received: from HGHY1l002753561.china.huawei.com (10.177.23.164) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.408.0; Fri, 29 Mar 2019 10:54:45 +0800 From: Zhen Lei To: Jean-Philippe Brucker , John Garry , Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , S390 , Hanjun Guo Subject: [PATCH v3 1/1] iommu: Add config option to set lazy mode as default Date: Fri, 29 Mar 2019 10:54:23 +0800 Message-ID: <20190329025423.15484-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.19.2.windows.1 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 This allows the default behaviour to be controlled by a kernel config option instead of changing the command line for the kernel to include "iommu.strict=0" on ARM64 where this is desired. This is similar to CONFIG_IOMMU_DEFAULT_PASSTHROUGH. Signed-off-by: Zhen Lei --- arch/s390/pci/pci_dma.c | 4 ++++ drivers/iommu/Kconfig | 15 +++++++++++++++ drivers/iommu/amd_iommu_init.c | 6 +++++- drivers/iommu/intel-iommu.c | 4 ++++ drivers/iommu/iommu.c | 5 +++++ 5 files changed, 33 insertions(+), 1 deletion(-) -- 1.8.3 diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c index 9e52d1527f71495..d05e8c3820793c5 100644 --- a/arch/s390/pci/pci_dma.c +++ b/arch/s390/pci/pci_dma.c @@ -17,7 +17,11 @@ static struct kmem_cache *dma_region_table_cache; static struct kmem_cache *dma_page_table_cache; +#ifdef CONFIG_IOMMU_DMA_DEFAULT_LAZY_MODE static int s390_iommu_strict; +#else +static int s390_iommu_strict = 1; +#endif static int zpci_refresh_global(struct zpci_dev *zdev) { diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 6f07f3b21816c64..ed5206a2d316599 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -85,6 +85,21 @@ config IOMMU_DEFAULT_PASSTHROUGH If unsure, say N here. +config IOMMU_DMA_DEFAULT_LAZY_MODE + bool "IOMMU DMA use lazy mode to flush IOTLB and free IOVA" + depends on IOMMU_API + default y + help + Support lazy mode, where for every IOMMU DMA unmap operation, the + flush operation of IOTLB and the free operation of IOVA are deferred. + They are only guaranteed to be done before the related IOVA will be + reused. Removing the need to pass in kernel parameters through + command line. For example, iommu.strict=0 on ARM64. If this is + enabled, you can still disable with kernel parameters, such as + iommu.strict=1 depending on the architecture. + + If unsure, say N here. + config OF_IOMMU def_bool y depends on OF && IOMMU_API diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index f773792d77fd533..a30805c2f77199c 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -166,7 +166,11 @@ struct ivmd_header { to handle */ LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings we find in ACPI */ -bool amd_iommu_unmap_flush; /* if true, flush on every unmap */ +#ifdef CONFIG_IOMMU_DMA_DEFAULT_LAZY_MODE +bool amd_iommu_unmap_flush; +#else +bool amd_iommu_unmap_flush = true; /* flush on every unmap */ +#endif LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the system */ diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 28cb713d728ceef..560191a9342b2b8 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -362,7 +362,11 @@ static int domain_detach_iommu(struct dmar_domain *domain, static int dmar_map_gfx = 1; static int dmar_forcedac; +#ifdef CONFIG_IOMMU_DMA_DEFAULT_LAZY_MODE static int intel_iommu_strict; +#else +static int intel_iommu_strict = 1; +#endif static int intel_iommu_superpage = 1; static int intel_iommu_sm; static int iommu_identity_mapping; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 33a982e33716369..5acb98e79b5b32d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -43,7 +43,12 @@ #else static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA; #endif + +#ifdef CONFIG_IOMMU_DMA_DEFAULT_LAZY_MODE +static bool iommu_dma_strict __read_mostly; +#else static bool iommu_dma_strict __read_mostly = true; +#endif struct iommu_callback_data { const struct iommu_ops *ops;