From patchwork Sun Apr 7 12:41:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 161922 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2603837jan; Sun, 7 Apr 2019 05:48:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXw7GniEuUuIr9FApnQjW82H01Fvp7/mMq6NgkxMVwgVEgW/zXq1+3nWgNWO2T14tZtifx X-Received: by 2002:a65:5089:: with SMTP id r9mr22758486pgp.14.1554641319835; Sun, 07 Apr 2019 05:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554641319; cv=none; d=google.com; s=arc-20160816; b=L4sr1LSC69lRN+bs/TYzQ3z6ukd5x4krc4hBugYZOk9reo5PUBvkLkYnjSitwdTIKD TLRzyzD3SW/qouHiNU1qmlH7/Cz2fz+Qj3EClos4gDy3At6ED9LoeK96r7dOPD2pASIz cgrKxJqYTg+DclmH6AVGy1mw3qRGc9JQJmLFtPyPhvTvz4KPi2Gy1DBVF3ZUur6y/BcG Jt1GOWoaj59LGJqbh5A1kpgb/5ku3uyy1DjMEUviIi3L8ms3sN7gE4xHWC7E2EoC+HhU soatxsPtlwelNao6akYF6dGSJNgGhuLpqZMnWdlDvAjDikbwq7lLA3EP1rjGyjEXj0ZL BMWw== 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=nRHHno2jHcYvjNquQhP+BkJ9Tu2LC/gIm9/YuYtwXFI=; b=P2/9hTcdko7UBqRUB4CiOzVda1hrS1Bhk2V7+Wyrjelra0ukPARMtPUXF7rYqyOSjw mezVkGtzWLnkpBRjsFKqR8FX2ajEmvoJvN+ZE/AlkgleDWSWlgFzP+ucn5Q3jfISAuUE HaS58GwMcrtqL5cA7djGrxeh9CSQ66oXhqV7aOmRAw8vr+tAZrBtKSOAAsx+3sxukNhY 4J/rvcw66y7h9mTdv094FzP4DB7rcMJOXtWP81TKvK/WMOZeScKUfENYbeIr8Rr9Sa8f H2usuGQDxlaJIZhfabZ+oCgWFGY9fNOQWj69UqxjtIc1ewsjC+M3uk1ShFFeDIENkWIR UZCQ== 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 g37si1725916plb.180.2019.04.07.05.48.39; Sun, 07 Apr 2019 05:48:39 -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 S1726706AbfDGMsi (ORCPT + 31 others); Sun, 7 Apr 2019 08:48:38 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6263 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726049AbfDGMsO (ORCPT ); Sun, 7 Apr 2019 08:48:14 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CC23CC9FA88CA792357B; Sun, 7 Apr 2019 20:48:10 +0800 (CST) Received: from HGHY1l002753561.china.huawei.com (10.177.23.164) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Sun, 7 Apr 2019 20:48:00 +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 v4 1/6] iommu: use iommu.dma_mode to replace iommu.passthrough and iommu.strict Date: Sun, 7 Apr 2019 20:41:42 +0800 Message-ID: <20190407124147.13576-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20190407124147.13576-1-thunder.leizhen@huawei.com> References: <20190407124147.13576-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 Currently the IOMMU dma contains 3 modes: passthrough, lazy, strict. The passthrough mode bypass the IOMMU, the lazy mode defer the invalidation of hardware TLBs, and the strict mode invalidate IOMMU hardware TLBs synchronously. The three modes are mutually exclusive. So people maybe confused about iommu.passthrough and iommu.strict, because thay can not be coexist. Use iommu.dma_mode to replace them will be better. Signed-off-by: Zhen Lei --- Documentation/admin-guide/kernel-parameters.txt | 33 ++++++++--------- drivers/iommu/Kconfig | 4 +-- drivers/iommu/iommu.c | 48 ++++++++++++++----------- include/linux/iommu.h | 5 +++ 4 files changed, 50 insertions(+), 40 deletions(-) -- 1.8.3 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2b8ee90bb64470d..60409ad23b2ac8b 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1792,24 +1792,21 @@ nobypass [PPC/POWERNV] Disable IOMMU bypass, using IOMMU for PCI devices. - iommu.strict= [ARM64] Configure TLB invalidation behaviour - Format: { "0" | "1" } - 0 - Lazy mode. - Request that DMA unmap operations use deferred - invalidation of hardware TLBs, for increased - throughput at the cost of reduced device isolation. - Will fall back to strict mode if not supported by - the relevant IOMMU driver. - 1 - Strict mode (default). - DMA unmap operations invalidate IOMMU hardware TLBs - synchronously. - - iommu.passthrough= - [ARM64] Configure DMA to bypass the IOMMU by default. - Format: { "0" | "1" } - 0 - Use IOMMU translation for DMA. - 1 - Bypass the IOMMU for DMA. - unset - Use value of CONFIG_IOMMU_DEFAULT_PASSTHROUGH. + + iommu.dma_mode= [ARM64] Configure default dma mode. if unset, use the + value of CONFIG_IOMMU_DEFAULT_PASSTHROUGH. + passthrough + Configure DMA to bypass the IOMMU by default. + lazy + Request that DMA unmap operations use deferred + invalidation of hardware TLBs, for increased + throughput at the cost of reduced device isolation. + Will fall back to strict mode if not supported by + the relevant IOMMU driver. + strict + Default. DMA unmap operations invalidate IOMMU hardware + TLBs synchronously. + io7= [HW] IO7 for Marvel based alpha systems See comment before marvel_specify_io7 in diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 6f07f3b21816c64..b67fcabd668f7b6 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -79,8 +79,8 @@ config IOMMU_DEFAULT_PASSTHROUGH depends on IOMMU_API help Enable passthrough by default, removing the need to pass in - iommu.passthrough=on or iommu=pt through command line. If this - is enabled, you can still disable with iommu.passthrough=off + iommu.dma_mode=passthrough or iommu=pt through command line. If this + is enabled, you can still disable with iommu.dma_mode={lazy|strict} or iommu=nopt depending on the architecture. If unsure, say N here. diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 109de67d5d727c2..e4d581e6cb8d210 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -38,12 +38,13 @@ static struct kset *iommu_group_kset; static DEFINE_IDA(iommu_group_ida); + #ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH -static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY; +#define IOMMU_DEFAULT_DMA_MODE IOMMU_DMA_MODE_PASSTHROUGH #else -static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA; +#define IOMMU_DEFAULT_DMA_MODE IOMMU_DMA_MODE_STRICT #endif -static bool iommu_dma_strict __read_mostly = true; +static int iommu_default_dma_mode __read_mostly = IOMMU_DEFAULT_DMA_MODE; struct iommu_callback_data { const struct iommu_ops *ops; @@ -141,25 +142,29 @@ static int __iommu_attach_group(struct iommu_domain *domain, static void __iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group); -static int __init iommu_set_def_domain_type(char *str) +static int __init iommu_dma_mode_setup(char *str) { - bool pt; - int ret; + if (!str) + goto fail; - ret = kstrtobool(str, &pt); - if (ret) - return ret; + if (!strncmp(str, "passthrough", 11)) + iommu_default_dma_mode = IOMMU_DMA_MODE_PASSTHROUGH; + else if (!strncmp(str, "lazy", 4)) + iommu_default_dma_mode = IOMMU_DMA_MODE_LAZY; + else if (!strncmp(str, "strict", 6)) + iommu_default_dma_mode = IOMMU_DMA_MODE_STRICT; + else + goto fail; + + pr_info("Force dma mode to be %d\n", iommu_default_dma_mode); - iommu_def_domain_type = pt ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA; return 0; -} -early_param("iommu.passthrough", iommu_set_def_domain_type); -static int __init iommu_dma_setup(char *str) -{ - return kstrtobool(str, &iommu_dma_strict); +fail: + pr_debug("Boot option iommu.dma_mode is incorrect, ignored\n"); + return -EINVAL; } -early_param("iommu.strict", iommu_dma_setup); +early_param("iommu.dma_mode", iommu_dma_mode_setup); static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) @@ -1102,14 +1107,17 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) */ if (!group->default_domain) { struct iommu_domain *dom; + int def_domain_type = + (iommu_default_dma_mode == IOMMU_DMA_MODE_PASSTHROUGH) + ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA; - dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type); - if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) { + dom = __iommu_domain_alloc(dev->bus, def_domain_type); + if (!dom && def_domain_type != IOMMU_DOMAIN_DMA) { dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); if (dom) { dev_warn(dev, "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", - iommu_def_domain_type); + def_domain_type); } } @@ -1117,7 +1125,7 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) if (!group->domain) group->domain = dom; - if (dom && !iommu_dma_strict) { + if (dom && (iommu_default_dma_mode == IOMMU_DMA_MODE_LAZY)) { int attr = 1; iommu_domain_set_attr(dom, DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ffbbc7e39ceeba3..c3f4e3416176496 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -42,6 +42,11 @@ */ #define IOMMU_PRIV (1 << 5) + +#define IOMMU_DMA_MODE_STRICT 0x0 +#define IOMMU_DMA_MODE_LAZY 0x1 +#define IOMMU_DMA_MODE_PASSTHROUGH 0x2 + struct iommu_ops; struct iommu_group; struct bus_type;