Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3833157yba; Tue, 9 Apr 2019 05:55:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCPmiJKsvCGBOoYVHxXwVtZ4zSBoycuOgnpTYa1WouGYqoxxbuUjVwxmQDi0IS/++z/qX+ X-Received: by 2002:a65:6107:: with SMTP id z7mr34530723pgu.313.1554814520590; Tue, 09 Apr 2019 05:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554814520; cv=none; d=google.com; s=arc-20160816; b=MhcblUHJRmtlCMa0C7hP5gbaz1MpEmcnvbkzaI6dqo4ZTS9ejcFsEwaBxSoyg0cQOv 2vL8eYNJnGc0XSy2/ioHkfm1u490TzMLfP5IR0peChQE3GdRdUFItyiJ7S5IoUddkpxe ECi/cxnvfrSjdJo8YidrfLJkhpndyOeDyjEApyCy1Ta3mCOhlfW4dy+LGbNOYspoQKns rdGTPphg/Mwi/aGS/upG8dpGByTCPhcKYE2nNiFrxiQi1XCkBKKahifBcAU6oBtJAEZb tTPamciPhzAY/m5mFtp53KuzbvFk1q2bSgWtOVrU/O1/TNf9nUWm533Zgcx6A2tB/pXX dJnw== 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=n9MxK2qgbst+c6vdOm6J7JZiCUW/6odB8aLV6YA072s=; b=oO5ztVc7NK6aP/aPr8CjccSl2E577SPavn0Frhg+tl7hk3tYl42WU7Oh8l8Wps5FNG 95dWgNZgaGbFUVr0gRmNo6FOqtL52t0fc/Fn3i5h7cjD8KrG8pTLq+hdxkLRFMYzJtDQ H6fXSxv8D1h9du6lIGaFoojbol53yRSgiGK2Ol1VGCLYoGiu7W4sRTnTSjpIPeD3nTVb qQxNwzOScVTJw8EBaTboSKp1Ety6FaaFcd3YIM2hc1zd/U5E/GN/hGJfHacge17SHJ9s AjHzjei0kExo1mFckVFMX1kLrrW65hvZzMqGagSTNdPAAlYk6NYiMzzkzlzo25CD4g2x 1vMQ== 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 l7si5330664pgq.263.2019.04.09.05.55.05; Tue, 09 Apr 2019 05:55:20 -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 S1727318AbfDIMyX (ORCPT + 99 others); Tue, 9 Apr 2019 08:54:23 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:44348 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726112AbfDIMyT (ORCPT ); Tue, 9 Apr 2019 08:54:19 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 56FD4951C8FD7825B0D0; Tue, 9 Apr 2019 20:54:10 +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:03 +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 2/6] iommu: add build options corresponding to iommu.dma_mode Date: Tue, 9 Apr 2019 20:53:04 +0800 Message-ID: <20190409125308.18304-3-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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 First, add build option IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the three config options in an choice, make people can only choose one of the three at a time, the same to the boot options iommu.dma_mode. Signed-off-by: Zhen Lei --- Documentation/admin-guide/kernel-parameters.txt | 6 ++-- drivers/iommu/Kconfig | 43 +++++++++++++++++++++---- drivers/iommu/iommu.c | 4 ++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index f7766f8ac8b9084..92d1b3151d003c2 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1811,9 +1811,9 @@ 1 - Bypass the IOMMU for DMA. unset - Use value of CONFIG_IOMMU_DEFAULT_PASSTHROUGH. - iommu.dma_mode= Configure default dma mode. if unset, use the value - of CONFIG_IOMMU_DEFAULT_PASSTHROUGH to determine - passthrough or not. + iommu.dma_mode= Configure default dma mode. if unset, use the build + 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 diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 6f07f3b21816c64..1986f9767da488b 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -74,17 +74,46 @@ config IOMMU_DEBUGFS debug/iommu directory, and then populate a subdirectory with entries as required. -config IOMMU_DEFAULT_PASSTHROUGH - bool "IOMMU passthrough by default" +choice + prompt "IOMMU dma mode" 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 - or iommu=nopt depending on the architecture. + default IOMMU_DEFAULT_STRICT + help + This option allows IOMMU dma mode to be chose at build time, to + override the default dma mode of each ARCHs, removing the need to + pass in kernel parameters through command line. You can still use the + generic boot option iommu.dma_mode or ARCHs specific boot options to + override this option again. + +config IOMMU_DEFAULT_PASSTHROUGH + bool "passthrough" + help + In this mode, the dma access through IOMMU without any addresses + transformation. That means, the wrong or illegal dma access can not + be caught, no error information will be reported. If unsure, say N here. +config IOMMU_DEFAULT_LAZY + bool "lazy" + 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. + +config IOMMU_DEFAULT_STRICT + bool "strict" + help + For every IOMMU DMA unmap operation, the flush operation of IOTLB and + the free operation of IOVA are guaranteed to be done in the unmap + function. + + This mode is safer than the two above, but it maybe slow in some high + performace scenarios. + +endchoice + config OF_IOMMU def_bool y depends on OF && IOMMU_API diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index df1ce8e22385b48..f4171bf4b46eaeb 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -39,8 +39,10 @@ static struct kset *iommu_group_kset; static DEFINE_IDA(iommu_group_ida); -#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH +#if defined(CONFIG_IOMMU_DEFAULT_PASSTHROUGH) #define IOMMU_DEFAULT_DMA_MODE IOMMU_DMA_MODE_PASSTHROUGH +#elif defined(CONFIG_IOMMU_DEFAULT_LAZY) +#define IOMMU_DEFAULT_DMA_MODE IOMMU_DMA_MODE_LAZY #else #define IOMMU_DEFAULT_DMA_MODE IOMMU_DMA_MODE_STRICT #endif -- 1.8.3