Skip to contentSkip to conversation

Add PGR response PASID requirement check in Intel IOMMU.

PATCH Superseded [email protected] 2 participants 4 messages Feb 7, 2019

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add PGR response PASID requirement check in Intel IOMMU.

From: Kuppuswamy Sathyanarayanan <[email protected]>

Intel IOMMU responds automatically when receiving page-requests from a PCIe endpoint and the page-request queue is full and it cannot accept any more page-requests. When it auto-responds to page-requests with a success to the endpoint, it automatically responds with the PASID if the page-request had a PASID in the incoming request. IOMMU doesn't actually have any place to check device capabilities (like whether the device expects PASID in PGR response or not) before sending the response message. Due to this restriction Intel IOMMU driver only enables PASID, if the endpoint is compliant to Intel IOMMU's.

Kuppuswamy Sathyanarayanan (2):
PCI: ATS: Add function to check PRG response PASID bit status. iommu/vt-d: Enable PASID only if device expects PASID in PRG response.

 drivers/iommu/intel-iommu.c   |  3 ++-
 drivers/pci/ats.c             | 27 +++++++++++++++++++++++++++
 include/linux/pci-ats.h       |  5 +++++
 include/uapi/linux/pci_regs.h |  1 +
 4 files changed, 35 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 PCI: ATS: Add function to check PRG response PASID bit status.

From: Kuppuswamy Sathyanarayanan <[email protected]>

Add a new function to return the status of PRG response PASID required bit in PRI status register. This function will be used by drivers like IOMMU, if it is required to enforce the PASID required for page-group responses.

---
 drivers/pci/ats.c             | 27 +++++++++++++++++++++++++++
 include/linux/pci-ats.h       |  5 +++++
 include/uapi/linux/pci_regs.h |  1 +
 3 files changed, 33 insertions(+)
drivers/pci/ats.c +27 -0
index 5b78f3b1b918..666d03332944 100644
@@ -368,6 +368,33 @@ int pci_pasid_features(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL_GPL(pci_pasid_features);
 
+/**
+ * pci_pggrp_rsp_need_pasid - Return PRG response PASID required bit status.
+ * @pdev: PCI device structure
+ *
+ * Returns positive if PASID is required, 0 otherwise.
+ *
+ * Eventhough the PRG response PASID status is read from PRI status
+ * register, Since this API will mainly be used by PASID users, this
+ * function is defined within #ifdef CONFIG_PCI_PASID instead of
+ * CONFIG_PCI_PRI.
+ *
+ */
+int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev)
+{
+	u16 status;
+	int pos;
+
+	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
+	if (!pos)
+		return 0;
+
+	pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status);
+
+	return status & PCI_PRI_STATUS_PASID;
+}
+EXPORT_SYMBOL_GPL(pci_pggrp_rsp_need_pasid);
+
 #define PASID_NUMBER_SHIFT	8
 #define PASID_NUMBER_MASK	(0x1f << PASID_NUMBER_SHIFT)
 /**
include/linux/pci-ats.h +5 -0
index 7c4b8e27268c..ea29c7c64482 100644
@@ -40,6 +40,7 @@ void pci_disable_pasid(struct pci_dev *pdev);
 void pci_restore_pasid_state(struct pci_dev *pdev);
 int pci_pasid_features(struct pci_dev *pdev);
 int pci_max_pasids(struct pci_dev *pdev);
+int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev);
 
 #else  /* CONFIG_PCI_PASID */
 
@@ -66,6 +67,10 @@ static inline int pci_max_pasids(struct pci_dev *pdev)
 	return -EINVAL;
 }
 
+static int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev)
+{
+	return 0;
+}
 #endif /* CONFIG_PCI_PASID */
 
 
include/uapi/linux/pci_regs.h +1 -0
index e1e9888c85e6..898be572b010 100644
@@ -880,6 +880,7 @@
 #define  PCI_PRI_STATUS_RF	0x001	/* Response Failure */
 #define  PCI_PRI_STATUS_UPRGI	0x002	/* Unexpected PRG index */
 #define  PCI_PRI_STATUS_STOPPED	0x100	/* PRI Stopped */
+#define  PCI_PRI_STATUS_PASID	0x8000	/* PRG Response PASID Required */
 #define PCI_PRI_MAX_REQ		0x08	/* PRI max reqs supported */
 #define PCI_PRI_ALLOC_REQ	0x0c	/* PRI max reqs allowed */
 #define PCI_EXT_CAP_PRI_SIZEOF	16
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH v1 1/2] PCI: ATS: Add function to check PRG response PASID bit status.

"PCI/ATS: Add pci_pggrp_rsp_need_pasid() interface"

Quoted 4 lines · On Thu, Feb 07, 2019 at 10:37:58AM -0800…

From: Kuppuswamy Sathyanarayanan <[email protected]>

Add a new function to return the status of PRG response PASID required bit in PRI status register. This function will be used by

"return the PRG Response PASID Required bit in the Page Request Status Register".

That's just to make it clear exactly what the name of the bit is. Without the capitalization, you can't tell where the name itself begins.

Quoted 2 lines

drivers like IOMMU, if it is required to enforce the PASID required for page-group responses.

If I'm reading the spec (PCIe r4.0, sec 10.5.2.3) correctly, when this bit is set, it means the Function expects a PASID on responses it receives from the host. It's not so much that the IOMMU "enforces" anything; it's just that when this bit is set, the IOMMU must supply the PASID in its responses to that Function.

s/page-group responses/PRG (Page Request Group) Response Messages/

Quoted 16 lines
---
 drivers/pci/ats.c             | 27 +++++++++++++++++++++++++++
 include/linux/pci-ats.h       |  5 +++++
 include/uapi/linux/pci_regs.h |  1 +
 3 files changed, 33 insertions(+)
drivers/pci/ats.c +0 -0
index 5b78f3b1b918..666d03332944 100644

drivers/pci/ats.c int pci_pasid_features(struct pci_dev *pdev) · line 372

Quoted 5 lines
drivers/pci/ats.c +2 -0
@@ -368,6 +368,33 @@ int pci_pasid_features(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL_GPL(pci_pasid_features);
 
+/**
+ * pci_pggrp_rsp_need_pasid - Return PRG response PASID required bit status.

pci_prg_resp_pasid_required()?

"PRG" seems to be the standard spec terminology, so I think using "pggrp" muddies the water a little bit.

drivers/pci/ats.c int pci_pasid_features(struct pci_dev *pdev) · line 380

Quoted 8 lines
drivers/pci/ats.c +8 -0
+ * @pdev: PCI device structure
+ *
+ * Returns positive if PASID is required, 0 otherwise.
+ *
+ * Eventhough the PRG response PASID status is read from PRI status
+ * register, Since this API will mainly be used by PASID users, this
+ * function is defined within #ifdef CONFIG_PCI_PASID instead of
+ * CONFIG_PCI_PRI.

s/Eventhough/Even though/
s/Since/since/

Quoted 58 lines
drivers/pci/ats.c +17 -0
+ *
+ */
+int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev)
+{
+	u16 status;
+	int pos;
+
+	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
+	if (!pos)
+		return 0;
+
+	pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status);
+
+	return status & PCI_PRI_STATUS_PASID;
+}
+EXPORT_SYMBOL_GPL(pci_pggrp_rsp_need_pasid);
+
 #define PASID_NUMBER_SHIFT	8
 #define PASID_NUMBER_MASK	(0x1f << PASID_NUMBER_SHIFT)
 /**
include/linux/pci-ats.h +5 -0
index 7c4b8e27268c..ea29c7c64482 100644
@@ -40,6 +40,7 @@ void pci_disable_pasid(struct pci_dev *pdev);
 void pci_restore_pasid_state(struct pci_dev *pdev);
 int pci_pasid_features(struct pci_dev *pdev);
 int pci_max_pasids(struct pci_dev *pdev);
+int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev);
 
 #else  /* CONFIG_PCI_PASID */
 
@@ -66,6 +67,10 @@ static inline int pci_max_pasids(struct pci_dev *pdev)
 	return -EINVAL;
 }
 
+static int pci_pggrp_rsp_need_pasid(struct pci_dev *pdev)
+{
+	return 0;
+}
 #endif /* CONFIG_PCI_PASID */
 
 
include/uapi/linux/pci_regs.h +1 -0
index e1e9888c85e6..898be572b010 100644
@@ -880,6 +880,7 @@
 #define  PCI_PRI_STATUS_RF	0x001	/* Response Failure */
 #define  PCI_PRI_STATUS_UPRGI	0x002	/* Unexpected PRG index */
 #define  PCI_PRI_STATUS_STOPPED	0x100	/* PRI Stopped */
+#define  PCI_PRI_STATUS_PASID	0x8000	/* PRG Response PASID Required */
 #define PCI_PRI_MAX_REQ		0x08	/* PRI max reqs supported */
 #define PCI_PRI_ALLOC_REQ	0x0c	/* PRI max reqs allowed */
 #define PCI_EXT_CAP_PRI_SIZEOF	16
Signature · 1 line
2.20.1
#3 lore raw

PATCH 2/2 iommu/vt-d: Enable PASID only if device expects PASID in PRG response.

In reply to [email protected]

From: Kuppuswamy Sathyanarayanan <[email protected]>

In Intel IOMMU, if the Page Request Queue (PRQ) is full, it will automatically respond to the device with a success message as a keep alive. And when sending the success message, IOMMU will include PASID in the response message when the page request has a PASID in request message and It does not check against the PRG response PASID requirement of the device before sending the response. Also, If the device receives the PRG response with PASID when its not expecting it then the device behavior is undefined. So enable PASID support only if device expects PASID in PRG response message.

---
 drivers/iommu/intel-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
index 1457f931218e..887847f08746 100644
@@ -1399,7 +1399,8 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info)
 	   undefined. So always enable PASID support on devices which
 	   have it, even if we can't yet know if we're ever going to
 	   use it. */
-	if (info->pasid_supported && !pci_enable_pasid(pdev, info->pasid_supported & ~1))
+	if (info->pasid_supported && pci_pggrp_rsp_need_pasid(pdev) &&
+	    !pci_enable_pasid(pdev, info->pasid_supported & ~1))
 		info->pasid_enabled = 1;
 
 	if (info->pri_supported && !pci_reset_pri(pdev) && !pci_enable_pri(pdev, 32))
Signature · 1 line
2.20.1