iommu/vt-d: pfsid fix
Subsystems (2)
v2 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).
Changes since v1:
- Fixed compile error when CONFIG_PCI_ATS is not set
- Simplified how PF source ID is retrieved
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 | 18 +++++++++++++++++- include/linux/intel-iommu.h | 8 +++++--- 3 files changed, 25 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 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
@@ -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
@@ -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
Re: [PATCH v2 1/2] iommu/vt-d: add definitions for PFSID
Hi Joerg/David,
Any comments on this? I will rebase to 18-rc1.
Thanks,
Jacob
Quoted 55 lines · On Thu, 7 Jun 2018 09:56:59 -0700 Jacob Pan <[email protected]>…
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 <[email protected]>Cc "Ashok Raj" <[email protected]>Cc "Lu Baolu" <[email protected]>--- drivers/iommu/intel-iommu.c | 1 + include/linux/intel-iommu.h | 3 +++ 2 files changed, 4 insertions(+)drivers/iommu/intel-iommu.c +1
-0@@ -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 +2
-0@@ -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)) #defineQI_DEV_IOTLB_SIZE1
#defineQI_DEV_IOTLB_MAX_INVS32include/linux/intel-iommu.h +1
-0@@ -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)) #defineQI_DEV_EIOTLB_MAX_INVS32
Quoted 1 line
#define
QI_PGRP_IDX(idx)(((u64)(idx)) << 55)
[Jacob Pan]
PATCH v2 2/2 iommu/vt-d: fix dev iotlb pfsid use
In reply to Jacob PanPFSID should be used in the invalidation descriptor for flushing device IOTLBs on SRIOV VFs.
--- drivers/iommu/dmar.c | 6 +++--- drivers/iommu/intel-iommu.c | 17 ++++++++++++++++- include/linux/intel-iommu.h | 5 ++--- 3 files changed, 21 insertions(+), 7 deletions(-)
drivers/iommu/dmar.c +3 -3
@@ -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 +16 -1
@@ -1503,6 +1503,20 @@ 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 { +struct pci_dev *pf_pdev; + +/* pdev will be returned if device is not a vf */ + pf_pdev =pci_physfn (pdev); + info->pfsid =PCI_DEVID (pf_pdev->bus->number, pf_pdev->devfn); + }#ifdef CONFIG_INTEL_IOMMU_SVM /* The PCIe spec, in its wisdom, declares that the behaviour of
@@ -1568,7 +1582,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
@@ -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
Quoted 10 lines · Jacob Pan
When device invalidation throttling(DIT) is supported by an IOMMU, device TLB invalidation should include physical function source ID(PFSID).
Changes since v1:
- Fixed compile error whenCONFIG_PCI_ATSis not set
- Simplified how PF source ID is retrievedJacob Pan (2):
iommu/vt-d: add definitions for PFSID
iommu/vt-d: fix dev iotlb pfsid use
Applied, thanks Jacob.