Skip to contentSkip to conversation

iommu/vt-d: pfsid fix

PATCH Superseded Jacob Pan 2 participants 4 messages Jun 6, 2018 – Jun 7, 2018 IOMMU

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jacob Pan

author
#0 lore raw

cover iommu/vt-d: pfsid fix

When device invalidation throttling(DIT) is supported by an IOMMU, device TLB invalidation should include physical function source ID(PFSID).

Jacob Pan (2):
iommu/vt-d: add definitions for PFSID
iommu/vt-d: fix dev iotlb pfsid use

 drivers/iommu/dmar.c        |  6 +++---
 drivers/iommu/intel-iommu.c | 17 ++++++++++++++++-
 include/linux/intel-iommu.h |  8 +++++---
 3 files changed, 24 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 iommu/vt-d: add definitions for PFSID

When SRIOV VF device IOTLB is invalidated, we need to provide the PF source ID such that IOMMU hardware can gauge the depth of invalidation queue which is shared among VFs. This is needed when device invalidation throttle (DIT) capability is supported.

This patch adds bit definitions for checking and tracking PFSID.

---
 drivers/iommu/intel-iommu.c | 1 +
 include/linux/intel-iommu.h | 3 +++
 2 files changed, 4 insertions(+)
drivers/iommu/intel-iommu.c +1 -0
index 749d8f2..3d77d61 100644
@@ -422,6 +422,7 @@ struct device_domain_info {
 	struct list_head global; /* link to global list */
 	u8 bus;			/* PCI bus number */
 	u8 devfn;		/* PCI devfn number */
+	u16 pfsid;		/* SRIOV physical function source ID */
 	u8 pasid_supported:3;
 	u8 pasid_enabled:1;
 	u8 pri_supported:1;
include/linux/intel-iommu.h +3 -0
index ef169d6..af1c05f 100644
@@ -114,6 +114,7 @@
  * Extended Capability Register
  */
 
+#define ecap_dit(e)		((e >> 41) & 0x1)
 #define ecap_pasid(e)		((e >> 40) & 0x1)
 #define ecap_pss(e)		((e >> 35) & 0x1f)
 #define ecap_eafs(e)		((e >> 34) & 0x1)
@@ -284,6 +285,7 @@ enum {
 #define QI_DEV_IOTLB_SID(sid)	((u64)((sid) & 0xffff) << 32)
 #define QI_DEV_IOTLB_QDEP(qdep)	(((qdep) & 0x1f) << 16)
 #define QI_DEV_IOTLB_ADDR(addr)	((u64)(addr) & VTD_PAGE_MASK)
+#define QI_DEV_IOTLB_PFSID(pfsid) (((u64)(pfsid & 0xf) << 12) | ((u64)(pfsid & 0xfff) << 52))
 #define QI_DEV_IOTLB_SIZE	1
 #define QI_DEV_IOTLB_MAX_INVS	32
 
@@ -308,6 +310,7 @@ enum {
 #define QI_DEV_EIOTLB_PASID(p)	(((u64)p) << 32)
 #define QI_DEV_EIOTLB_SID(sid)	((u64)((sid) & 0xffff) << 16)
 #define QI_DEV_EIOTLB_QDEP(qd)	((u64)((qd) & 0x1f) << 4)
+#define QI_DEV_EIOTLB_PFSID(pfsid) (((u64)(pfsid & 0xf) << 12) | ((u64)(pfsid & 0xfff) << 52))
 #define QI_DEV_EIOTLB_MAX_INVS	32
 
 #define QI_PGRP_IDX(idx)	(((u64)(idx)) << 55)
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH 2/2 iommu/vt-d: fix dev iotlb pfsid use

In reply to Jacob Pan

PFSID should be used in the invalidation descriptor for flushing device IOTLBs on SRIOV VFs.

---
 drivers/iommu/dmar.c        |  6 +++---
 drivers/iommu/intel-iommu.c | 16 +++++++++++++++-
 include/linux/intel-iommu.h |  5 ++---
 3 files changed, 20 insertions(+), 7 deletions(-)
drivers/iommu/dmar.c +3 -3
index 460bed4..7852678 100644
@@ -1339,8 +1339,8 @@ void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,
 	qi_submit_sync(&desc, iommu);
 }
 
-void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep,
-			u64 addr, unsigned mask)
+void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid,
+			u16 qdep, u64 addr, unsigned mask)
 {
 	struct qi_desc desc;
 
@@ -1355,7 +1355,7 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep,
 		qdep = 0;
 
 	desc.low = QI_DEV_IOTLB_SID(sid) | QI_DEV_IOTLB_QDEP(qdep) |
-		   QI_DIOTLB_TYPE;
+		   QI_DIOTLB_TYPE | QI_DEV_IOTLB_PFSID(pfsid);
 
 	qi_submit_sync(&desc, iommu);
 }
drivers/iommu/intel-iommu.c +15 -1
index 3d77d61..e0e80c3 100644
@@ -1503,6 +1503,19 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info)
 		return;
 
 	pdev = to_pci_dev(info->dev);
+	/* For IOMMU that supports device IOTLB throttling (DIT), we assign
+	 * PFSID to the invalidation desc of a VF such that IOMMU HW can gauge
+	 * queue depth at PF level. If DIT is not set, PFSID will be treated as
+	 * reserved, which should be set to 0.
+	 */
+	if (!ecap_dit(info->iommu->ecap))
+		info->pfsid = 0;
+	else if (pdev && pdev->is_virtfn) {
+		if (ecap_dit(info->iommu->ecap))
+			dev_warn(&pdev->dev, "SRIOV VF device IOTLB enabled without flow control\n");
+		info->pfsid = PCI_DEVID(pdev->physfn->bus->number, pdev->physfn->devfn);
+	} else
+		info->pfsid = PCI_DEVID(info->bus, info->devfn);
 
 #ifdef CONFIG_INTEL_IOMMU_SVM
 	/* The PCIe spec, in its wisdom, declares that the behaviour of
@@ -1568,7 +1581,8 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
 
 		sid = info->bus << 8 | info->devfn;
 		qdep = info->ats_qdep;
-		qi_flush_dev_iotlb(info->iommu, sid, qdep, addr, mask);
+		qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
+				qdep, addr, mask);
 	}
 	spin_unlock_irqrestore(&device_domain_lock, flags);
 }
include/linux/intel-iommu.h +2 -3
index af1c05f..7fd9fbae 100644
@@ -456,9 +456,8 @@ extern void qi_flush_context(struct intel_iommu *iommu, u16 did, u16 sid,
 			     u8 fm, u64 type);
 extern void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,
 			  unsigned int size_order, u64 type);
-extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep,
-			       u64 addr, unsigned mask);
-
+extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid,
+			u16 qdep, u64 addr, unsigned mask);
 extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
 
 extern int dmar_ir_support(void);
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use

I love your patch! Yet something to improve:

Hi Jacob,

I love your patch! Yet something to improve:

[auto build test ERROR on iommu/next]
[also build test ERROR on v4.17 next-20180606]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jacob-Pan/iommu-vt-d-pfsid-fix/20180607-134305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
config: ia64-defconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 8.1.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64

All errors (new ones prefixed by >>):

In file included from drivers//iommu/intel-iommu.c:31:
drivers//iommu/intel-iommu.c: In function 'iommu_enable_dev_iotlb':

>> drivers//iommu/intel-iommu.c:1488:33: error: 'struct pci_dev' has no member named 'physfn'; did you mean 'is_physfn'?
      info->pfsid = PCI_DEVID(pdev->physfn->bus->number, pdev->physfn->devfn);
                                    ^~~~~~
   include/linux/pci.h:51:40: note: in definition of macro 'PCI_DEVID'
    #define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
                                           ^~~
   drivers//iommu/intel-iommu.c:1488:60: error: 'struct pci_dev' has no member named 'physfn'; did you mean 'is_physfn'?
      info->pfsid = PCI_DEVID(pdev->physfn->bus->number, pdev->physfn->devfn);
                                                               ^~~~~~
   include/linux/pci.h:51:55: note: in definition of macro 'PCI_DEVID'
    #define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
                                                          ^~~~~

vim +1488 drivers//iommu/intel-iommu.c

1467
1468 static void iommu_enable_dev_iotlb(struct device_domain_info *info)
1469 {
1470 struct pci_dev *pdev;
1471
1472 assert_spin_locked(&device_domain_lock);
1473
1474 if (!info || !dev_is_pci(info->dev))
1475 return;
1476
1477 pdev = to_pci_dev(info->dev);
1478 /* For IOMMU that supports device IOTLB throttling (DIT), we assign
1479 * PFSID to the invalidation desc of a VF such that IOMMU HW can gauge
1480 * queue depth at PF level. If DIT is not set, PFSID will be treated as
1481 * reserved, which should be set to 0.
1482 */
1483 if (!ecap_dit(info->iommu->ecap))
1484 info->pfsid = 0;
1485 else if (pdev && pdev->is_virtfn) {
1486 if (ecap_dit(info->iommu->ecap))
1487 dev_warn(&pdev->dev, "SRIOV VF device IOTLB enabled without flow control\n");

> 1488			info->pfsid = PCI_DEVID(pdev->physfn->bus->number, pdev->physfn->devfn);

1489 } else
1490 info->pfsid = PCI_DEVID(info->bus, info->devfn);
1491

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation