Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3584119ybi; Sun, 2 Jun 2019 18:25:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFiIb59/mCl4zoLqL1WGmOoZhjfe8w0AgVaxSBqGAPoyoi1JV3Nv4S4QgyzNd0aFUYATCQ X-Received: by 2002:a63:3141:: with SMTP id x62mr25711281pgx.282.1559525140879; Sun, 02 Jun 2019 18:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559525140; cv=none; d=google.com; s=arc-20160816; b=sy7kHj55y7I9jCOIhEWg1P4iQZmWgBl9PRmbc/usDlj0FJrCZ8V8uyXu+3nlX31HR/ U9PwnwAcNO1iqs7enjD/Es2cqG+u4yhbaT/6M4ZHbCUw0avvE7DPbqEDSFuSUQuODGCj +wKFEC81LKRgDQwxRHvJxZyL9jUdceZFgPpDpBcxdrCpr2T/bTbyuMF95Pbe8fLqkHaO J2JG3BNGyZxrK5PcqKmOK3XZ1b+QNuRWqBzHBaVOIdc1cbN8uYMiZDBD7WRB5qx4Xity zjydo799EtwSabSWBAJXm12Qi99j1hRNkLzD/t/HnvpGQgKXlq7S1Rkntcc4QEzXy58V mXAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=F8FAJLdefSQpp7lh3eeFNO/hv8fG4p60taA/X33Zjx0=; b=o2tadtyaPCSDdeJdevA5lMXchXQzQF2Uc7EYxo0H82Ieav22KAS7EdeQW6ItcjZfBZ +1MQy66oSBG93Jm1VcR5oncaeCeNnXV2WmH6TNnWTbqF8oTKCGyR8xAxKf0yCKPIpiVr 5WlgE2zjNyfNhBigEaAqOhUO20vO3r/CQK/ehbaJu8a6XZ9PX7rrb0nV9+/9zl9BzoAh kzfWXXMB4/1oniPwKK+EcpB82V52Xta9citTIj0KkEXjQ9jWosZvu5C+O+uUacOHi+wj KcIP9MupneSgdTMbj7v/QgUDm7WBO3BEgSU9x3Zy7QkxdUAEQG3WOHV+9awuRzI0LRhi Duvw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si15898388pgi.579.2019.06.02.18.25.25; Sun, 02 Jun 2019 18:25:40 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbfFCBYC (ORCPT + 99 others); Sun, 2 Jun 2019 21:24:02 -0400 Received: from mga17.intel.com ([192.55.52.151]:20792 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbfFCBYA (ORCPT ); Sun, 2 Jun 2019 21:24:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jun 2019 18:24:00 -0700 X-ExtLoop1: 1 Received: from allen-box.sh.intel.com ([10.239.159.136]) by FMSMGA003.fm.intel.com with ESMTP; 02 Jun 2019 18:23:56 -0700 From: Lu Baolu To: David Woodhouse , Joerg Roedel , Bjorn Helgaas , Christoph Hellwig Cc: ashok.raj@intel.com, jacob.jun.pan@intel.com, alan.cox@intel.com, kevin.tian@intel.com, mika.westerberg@linux.intel.com, Ingo Molnar , Greg Kroah-Hartman , pengfei.xu@intel.com, Konrad Rzeszutek Wilk , Marek Szyprowski , Robin Murphy , Jonathan Corbet , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Steven Rostedt , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v4 6/9] iommu/vt-d: Check whether device requires bounce buffer Date: Mon, 3 Jun 2019 09:16:17 +0800 Message-Id: <20190603011620.31999-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190603011620.31999-1-baolu.lu@linux.intel.com> References: <20190603011620.31999-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a helper to check whether a device needs to use bounce buffer. It also provides a boot time option to disable the bounce buffer. Users can use this to prevent the iommu driver from using the bounce buffer for performance gain. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Signed-off-by: Lu Baolu Tested-by: Xu Pengfei Tested-by: Mika Westerberg --- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ drivers/iommu/intel-iommu.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 138f6664b2e2..65685c6e53e4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1728,6 +1728,11 @@ Note that using this option lowers the security provided by tboot because it makes the system vulnerable to DMA attacks. + nobounce [Default off] + Do not use the bounce buffer for untrusted devices like + the Thunderbolt devices. This will treat the untrusted + devices as the trusted ones, hence might expose security + risks of DMA attacks. intel_idle.max_cstate= [KNL,HW,ACPI,X86] 0 disables intel_idle and fall back on acpi_idle. diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 235837c50719..41439647f75d 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -371,6 +371,7 @@ static int dmar_forcedac; static int intel_iommu_strict; static int intel_iommu_superpage = 1; static int iommu_identity_mapping; +static int intel_no_bounce; #define IDENTMAP_ALL 1 #define IDENTMAP_GFX 2 @@ -384,6 +385,8 @@ EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); static DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); +#define device_needs_bounce(d) (!intel_no_bounce && dev_is_untrusted(d)) + /* * Iterate over elements in device_domain_list and call the specified * callback @fn against each element. @@ -466,6 +469,9 @@ static int __init intel_iommu_setup(char *str) printk(KERN_INFO "Intel-IOMMU: not forcing on after tboot. This could expose security risk for tboot\n"); intel_iommu_tboot_noforce = 1; + } else if (!strncmp(str, "nobounce", 8)) { + pr_info("Intel-IOMMU: No bounce buffer. This could expose security risks of DMA attacks\n"); + intel_no_bounce = 1; } str += strcspn(str, ","); -- 2.17.1