LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] iommu/vt-d: pfsid fix
@ 2018-06-06 20:17 Jacob Pan
  2018-06-06 20:17 ` [PATCH 1/2] iommu/vt-d: add definitions for PFSID Jacob Pan
  2018-06-06 20:18 ` [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use Jacob Pan
  0 siblings, 2 replies; 4+ messages in thread
From: Jacob Pan @ 2018-06-06 20:17 UTC (permalink / raw)
  To: LKML, iommu, Joerg Roedel, David Woodhouse; +Cc: Raj Ashok, Lu Baolu, Jacob Pan

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(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] iommu/vt-d: add definitions for PFSID
  2018-06-06 20:17 [PATCH 0/2] iommu/vt-d: pfsid fix Jacob Pan
@ 2018-06-06 20:17 ` Jacob Pan
  2018-06-06 20:18 ` [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use Jacob Pan
  1 sibling, 0 replies; 4+ messages in thread
From: Jacob Pan @ 2018-06-06 20:17 UTC (permalink / raw)
  To: LKML, iommu, Joerg Roedel, David Woodhouse; +Cc: Raj Ashok, Lu Baolu, Jacob Pan

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.

Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 1 +
 include/linux/intel-iommu.h | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 749d8f2..3d77d61 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -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;
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index ef169d6..af1c05f 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -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)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use
  2018-06-06 20:17 [PATCH 0/2] iommu/vt-d: pfsid fix Jacob Pan
  2018-06-06 20:17 ` [PATCH 1/2] iommu/vt-d: add definitions for PFSID Jacob Pan
@ 2018-06-06 20:18 ` Jacob Pan
  2018-06-07  8:23   ` kbuild test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Jacob Pan @ 2018-06-06 20:18 UTC (permalink / raw)
  To: LKML, iommu, Joerg Roedel, David Woodhouse; +Cc: Raj Ashok, Lu Baolu, Jacob Pan

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

Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
 drivers/iommu/dmar.c        |  6 +++---
 drivers/iommu/intel-iommu.c | 16 +++++++++++++++-
 include/linux/intel-iommu.h |  5 ++---
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 460bed4..7852678 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -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);
 }
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 3d77d61..e0e80c3 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -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);
 }
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index af1c05f..7fd9fbae 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -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);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use
  2018-06-06 20:18 ` [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use Jacob Pan
@ 2018-06-07  8:23   ` kbuild test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2018-06-07  8:23 UTC (permalink / raw)
  To: Jacob Pan
  Cc: kbuild-all, LKML, iommu, Joerg Roedel, David Woodhouse,
	Raj Ashok, Lu Baolu, Jacob Pan

[-- Attachment #1: Type: text/plain, Size: 2996 bytes --]

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 17994 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-07  8:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-06 20:17 [PATCH 0/2] iommu/vt-d: pfsid fix Jacob Pan
2018-06-06 20:17 ` [PATCH 1/2] iommu/vt-d: add definitions for PFSID Jacob Pan
2018-06-06 20:18 ` [PATCH 2/2] iommu/vt-d: fix dev iotlb pfsid use Jacob Pan
2018-06-07  8:23   ` kbuild test robot

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).