iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	iommu@lists.linux-foundation.org, joro@8bytes.org,
	bhelgaas@google.com
Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	ashok.raj@intel.com, will@kernel.org, alex.williamson@redhat.com,
	robin.murphy@arm.com, dwmw2@infradead.org
Subject: [PATCH 2/4] iommu/amd: Use pci_ats_supported()
Date: Fri, 15 May 2020 12:44:00 +0200	[thread overview]
Message-ID: <20200515104359.1178606-3-jean-philippe@linaro.org> (raw)
In-Reply-To: <20200515104359.1178606-1-jean-philippe@linaro.org>

The pci_ats_supported() function checks if a device supports ATS and is
allowed to use it. In addition to checking that the device has an ATS
capability and that the global pci=noats is not set
(pci_ats_disabled()), it also checks if a device is untrusted.

A device is untrusted if it is plugged into an external-facing port such
as Thunderbolt and could be spoofing an existing device to exploit
weaknesses in the IOMMU configuration. By calling pci_ats_supported() we
keep DTE[I]=0 for untrusted devices and abort transactions with
Pretranslated Addresses.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 drivers/iommu/amd_iommu.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 1dc3718560d0e8..8b7a9e811d33a6 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -313,16 +313,15 @@ static struct iommu_group *acpihid_device_group(struct device *dev)
 static bool pci_iommuv2_capable(struct pci_dev *pdev)
 {
 	static const int caps[] = {
-		PCI_EXT_CAP_ID_ATS,
 		PCI_EXT_CAP_ID_PRI,
 		PCI_EXT_CAP_ID_PASID,
 	};
 	int i, pos;
 
-	if (pci_ats_disabled())
+	if (!pci_ats_supported(pdev))
 		return false;
 
-	for (i = 0; i < 3; ++i) {
+	for (i = 0; i < 2; ++i) {
 		pos = pci_find_ext_capability(pdev, caps[i]);
 		if (pos == 0)
 			return false;
@@ -3150,11 +3149,8 @@ int amd_iommu_device_info(struct pci_dev *pdev,
 
 	memset(info, 0, sizeof(*info));
 
-	if (!pci_ats_disabled()) {
-		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
-		if (pos)
-			info->flags |= AMD_IOMMU_DEVICE_FLAG_ATS_SUP;
-	}
+	if (pci_ats_supported(pdev))
+		info->flags |= AMD_IOMMU_DEVICE_FLAG_ATS_SUP;
 
 	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
 	if (pos)
-- 
2.26.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  parent reply	other threads:[~2020-05-15 10:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 10:43 [PATCH 0/4] PCI, iommu: Factor 'untrusted' check for ATS enablement Jean-Philippe Brucker
2020-05-15 10:43 ` [PATCH 1/4] PCI/ATS: Only enable ATS for trusted devices Jean-Philippe Brucker
2020-05-15 11:57   ` Joerg Roedel
2020-05-15 21:18   ` Bjorn Helgaas
2020-05-15 10:44 ` Jean-Philippe Brucker [this message]
2020-05-15 12:01   ` [PATCH 2/4] iommu/amd: Use pci_ats_supported() Joerg Roedel
2020-05-15 12:11     ` Jean-Philippe Brucker
2020-05-15 12:21       ` Joerg Roedel
2020-05-15 10:44 ` [PATCH 3/4] iommu/arm-smmu-v3: " Jean-Philippe Brucker
2020-05-18 15:37   ` Will Deacon
2020-05-15 10:44 ` [PATCH 4/4] iommu/vt-d: " Jean-Philippe Brucker
2020-05-15 15:43 ` [PATCH 0/4] PCI, iommu: Factor 'untrusted' check for ATS enablement Christoph Hellwig
2020-05-15 17:19   ` Raj, Ashok
2020-05-15 17:21     ` Will Deacon
2020-05-18 15:47     ` David Woodhouse
2020-05-18 16:29       ` Raj, Ashok
2020-05-18 16:36   ` Jean-Philippe Brucker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200515104359.1178606-3-jean-philippe@linaro.org \
    --to=jean-philippe@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=bhelgaas@google.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).