Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp549203ybe; Fri, 6 Sep 2019 03:40:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUNECxquVtN0rNN7OvS8e7O2KvH5LmjpSTWUPGMc7SENuirCKYNSIIy4m3ooepXZftxc98 X-Received: by 2002:a17:902:3363:: with SMTP id a90mr8529677plc.270.1567766420083; Fri, 06 Sep 2019 03:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567766420; cv=none; d=google.com; s=arc-20160816; b=ay7Y6vNYkyvX7JOlCBYjI/05DUHa2RY5fD+2CeIrzKdnd4KccRNBli9b4OG6AfeUNw wvQKMswqN6+8H1O82v7XnWj3gTsbrwoC2shA7O++2aNTjeFf6QESnTRUTsQPeq+A7xG+ bmKJBNU72DSbLtfbuARmmX8PidkH9H3nteWv4ESszV5QWcL01SE7COJdFTZPT5we3EyT EXIF2FdJ2APbF1Bq54BQgOQ4XerPz5gs1hDAvBGPmLRfQRkA780EEZQlF09t78QytUvC xnCXu3vca6pNrlc/1IdC/AQJ6bNK+kbqptsXoZX5vw9VbOxqxN+BeByXYlAEUOzxsF12 MJXg== 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=fwiQs1qMStdIUuEzPvJXSNOR14EL0yH35/ej/6CTxL0=; b=oV9Y+5oskDSRYFBYC5l0tEayeqDaazeQ/5zGloy1DSoHVOD1S7/W6TKG68AgChZ5wL hTthlKoL5Fd+mAeTvZ7hO+1xk4xcPN0xKZMoTKitNk4mCudU3wUjKmpBWi/fHt6HIEk4 cGahrg2KK5Z34aW0LZcNS5yCFP2lA616ohcD/f4iBPysl5LtRTao5eC7VZN0DSwDm46G pLJ2oYhTl6hqGzjIZrCBoNl+0TR53zcCLS8OudZh3Sdjf4QEr6uH4S2MnfQnYPbLuwOz Bp29/8OQ8K5yIs7wxVPeUGycitipNfCuGT2TInxnUsm7EoZsss5CxDgGL+iMMAywDoTZ JD3w== 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 f1si4575978pje.79.2019.09.06.03.40.04; Fri, 06 Sep 2019 03:40: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391481AbfIFGQn (ORCPT + 99 others); Fri, 6 Sep 2019 02:16:43 -0400 Received: from mga01.intel.com ([192.55.52.88]:4005 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388719AbfIFGQm (ORCPT ); Fri, 6 Sep 2019 02:16:42 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 23:16:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,472,1559545200"; d="scan'208";a="383159368" Received: from allen-box.sh.intel.com ([10.239.159.136]) by fmsmga005.fm.intel.com with ESMTP; 05 Sep 2019 23:16:38 -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 v9 3/5] iommu/vt-d: Don't switch off swiotlb if bounce page is used Date: Fri, 6 Sep 2019 14:14:50 +0800 Message-Id: <20190906061452.30791-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906061452.30791-1-baolu.lu@linux.intel.com> References: <20190906061452.30791-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 The bounce page implementation depends on swiotlb. Hence, don't switch off swiotlb if the system has untrusted devices or could potentially be hot-added with any untrusted devices. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig --- drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index e15cdcd8cb3c..a4ddeade8ac4 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -182,6 +182,7 @@ config INTEL_IOMMU select IOMMU_IOVA select NEED_DMA_MAP_STATE select DMAR_TABLE + select SWIOTLB help DMA remapping (DMAR) devices support enables independent address translations for Direct Memory Access (DMA) from devices. diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index e12aa73008df..34e1265bb2ad 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -4576,22 +4576,20 @@ const struct attribute_group *intel_iommu_groups[] = { NULL, }; -static int __init platform_optin_force_iommu(void) +static inline bool has_untrusted_dev(void) { struct pci_dev *pdev = NULL; - bool has_untrusted_dev = false; - if (!dmar_platform_optin() || no_platform_optin) - return 0; + for_each_pci_dev(pdev) + if (pdev->untrusted) + return true; - for_each_pci_dev(pdev) { - if (pdev->untrusted) { - has_untrusted_dev = true; - break; - } - } + return false; +} - if (!has_untrusted_dev) +static int __init platform_optin_force_iommu(void) +{ + if (!dmar_platform_optin() || no_platform_optin || !has_untrusted_dev()) return 0; if (no_iommu || dmar_disabled) @@ -4605,9 +4603,6 @@ static int __init platform_optin_force_iommu(void) iommu_identity_mapping |= IDENTMAP_ALL; dmar_disabled = 0; -#if defined(CONFIG_X86) && defined(CONFIG_SWIOTLB) - swiotlb = 0; -#endif no_iommu = 0; return 1; @@ -4747,7 +4742,14 @@ int __init intel_iommu_init(void) up_write(&dmar_global_lock); #if defined(CONFIG_X86) && defined(CONFIG_SWIOTLB) - swiotlb = 0; + /* + * If the system has no untrusted device or the user has decided + * to disable the bounce page mechanisms, we don't need swiotlb. + * Mark this and the pre-allocated bounce pages will be released + * later. + */ + if (!has_untrusted_dev() || intel_no_bounce) + swiotlb = 0; #endif dma_ops = &intel_dma_ops; -- 2.17.1