Intel IOMMU updates for Linux v6.4
Subsystems (4)
Lu Baolu
maintainerHi Joerg,
This includes patches queued for v6.4. They are:
- Allow the VT-d driver to support non-PRI IOPF
- Remove PASID supervisor request support
- Various small and misc cleanups
This series also includes an idxd patch to avoid driver regression after changes in the IOMMU driver. It has been reviewed and acked by the maintainers.
The whole series is based on v6.3-rc6 and also available at:
https://github.com/LuBaolu/intel-iommu/commits/vtd-update-for-v6.4
Please pull them for x86/vt-d branch.
Best regards,
Baolu
Change log:
- v2:
- Avoid using "fix" wording in the commit message of a cleanup patch, no functional change. [David Laight]
- Add Acked-by from Vinod Koul to the idxd patch.
- v1: https://lore.kernel.org/linux-iommu/[email protected]/
Christophe JAILLET (1):
iommu/vt-d: Do not use GFP_ATOMIC when not needed
Jacob Pan (2):
iommu/vt-d: Use non-privileged mode for all PASIDs iommu/vt-d: Remove PASID supervisor request support
Lu Baolu (7):
dmaengine: idxd: Add enable/disable device IOPF feature iommu/vt-d: Allow SVA with device-specific IOPF iommu/vt-d: Move iopf code from SVA to IOPF enabling path iommu/vt-d: Move pfsid and ats_qdep calculation to device probe path iommu/vt-d: Move PRI handling to IOPF feature path iommu/vt-d: Remove unnecessary checks in iopf disabling path iommu/vt-d: Remove extern from function prototypes
Tina Zhang (7):
iommu/vt-d: Make size of operands same in bitwise operations iommu/vt-d: Remove BUG_ON on checking valid pfn range iommu/vt-d: Remove BUG_ON in handling iotlb cache invalidation iommu/vt-d: Remove BUG_ON when domain->pgd is NULL iommu/vt-d: Remove BUG_ON in map/unmap()
iommu/vt-d: Remove a useless BUG_ON(dev->is_virtfn) iommu/vt-d: Remove BUG_ON in dmar_insert_dev_scope()
drivers/iommu/intel/iommu.h | 36 +++--- drivers/iommu/intel/pasid.h | 7 -- drivers/dma/idxd/init.c | 31 ++++- drivers/iommu/intel/dmar.c | 7 +- drivers/iommu/intel/iommu.c | 173 +++++++++++++++++----------- drivers/iommu/intel/irq_remapping.c | 2 +- drivers/iommu/intel/pasid.c | 43 ------- 7 files changed, 155 insertions(+), 144 deletions(-)
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 1/17 dmaengine: idxd: Add enable/disable device IOPF feature
The iommu subsystem requires IOMMU_DEV_FEAT_IOPF must be enabled before and disabled after IOMMU_DEV_FEAT_SVA, if device's I/O page faults rely on the IOMMU. Add explicit IOMMU_DEV_FEAT_IOPF enabling/disabling in this driver.
At present, missing IOPF enabling/disabling doesn't cause any real issue, because the IOMMU driver places the IOPF enabling/disabling in the path of SVA feature handling. But this may change.
--- drivers/dma/idxd/init.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/dma/idxd/init.c +25 -6
@@ -516,6 +516,27 @@ static void idxd_disable_system_pasid(struct idxd_device *idxd) idxd->sva =NULL ; } +static int idxd_enable_sva (struct pci_dev *pdev) +{ +int ret; + + ret =iommu_dev_enable_feature (&pdev->dev,IOMMU_DEV_FEAT_IOPF ); +if (ret) +return ret; + + ret =iommu_dev_enable_feature (&pdev->dev,IOMMU_DEV_FEAT_SVA ); +if (ret) +iommu_dev_disable_feature (&pdev->dev,IOMMU_DEV_FEAT_IOPF ); + +return ret; +} + +static void idxd_disable_sva (struct pci_dev *pdev) +{ +iommu_dev_disable_feature (&pdev->dev,IOMMU_DEV_FEAT_SVA ); +iommu_dev_disable_feature (&pdev->dev,IOMMU_DEV_FEAT_IOPF ); +} +static int idxd_probe (struct idxd_device *idxd) {struct pci_dev *pdev = idxd->pdev;
@@ -530,7 +551,7 @@ static int idxd_probe(struct idxd_device *idxd)dev_dbg (dev,"IDXD reset complete\n" );if (IS_ENABLED (CONFIG_INTEL_IDXD_SVM ) && sva) { -if (iommu_dev_enable_feature (dev,IOMMU_DEV_FEAT_SVA )) { +if (idxd_enable_sva (pdev)) {dev_warn (dev,"Unable to turn on user SVA feature.\n" ); }else {set_bit (IDXD_FLAG_USER_PASID_ENABLED , &idxd->flags);
@@ -578,21 +599,19 @@ static int idxd_probe(struct idxd_device *idxd)if (device_pasid_enabled (idxd))idxd_disable_system_pasid (idxd);if (device_user_pasid_enabled (idxd)) -iommu_dev_disable_feature (dev,IOMMU_DEV_FEAT_SVA ); +idxd_disable_sva (pdev);return rc; }static void idxd_cleanup (struct idxd_device *idxd) { -struct device *dev = &idxd->pdev->dev; -perfmon_pmu_remove (idxd);idxd_cleanup_interrupts (idxd);idxd_cleanup_internals (idxd);if (device_pasid_enabled (idxd))idxd_disable_system_pasid (idxd);if (device_user_pasid_enabled (idxd)) -iommu_dev_disable_feature (dev,IOMMU_DEV_FEAT_SVA ); +idxd_disable_sva (idxd->pdev); }static int idxd_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)
@@ -710,7 +729,7 @@ static void idxd_remove(struct pci_dev *pdev)pci_free_irq_vectors (pdev);pci_iounmap (pdev, idxd->reg_base);if (device_user_pasid_enabled (idxd)) -iommu_dev_disable_feature (&pdev->dev,IOMMU_DEV_FEAT_SVA ); +idxd_disable_sva (pdev);pci_disable_device (pdev);destroy_workqueue (idxd->wq);perfmon_pmu_remove (idxd);
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 2/17 iommu/vt-d: Allow SVA with device-specific IOPF
In reply to Lu BaoluCurrently enabling SVA requires IOPF support from the IOMMU and device PCI PRI. However, some devices can handle IOPF by itself without ever sending PCI page requests nor advertising PRI capability.
Allow SVA support with IOPF handled either by IOMMU (PCI PRI) or device driver (device-specific IOPF). As long as IOPF could be handled, SVA should continue to work.
--- drivers/iommu/intel/iommu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +15 -1
@@ -4650,7 +4650,21 @@ static int intel_iommu_enable_sva(struct device *dev)if (!(iommu->flags &VTD_FLAG_SVM_CAPABLE ))return -ENODEV ; -if (!info->pasid_enabled || !info->pri_enabled || !info->ats_enabled) +if (!info->pasid_enabled || !info->ats_enabled) +return -EINVAL ; + +/* +* Devices having device-specific I/O fault handling should not +* support PCI/PRI. The IOMMU side has no means to check the +* capability of device-specific IOPF. Therefore, IOMMU can only +* default that if the device driver enables SVA on a non-PRI +* device, it will handle IOPF in its own way. +*/ +if (!info->pri_supported) +return 0 ; + +/* Devices supporting PRI should have it enabled. */ +if (!info->pri_enabled)return -EINVAL ; ret =iopf_queue_add_device (iommu->iopf_queue, dev);
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 3/17 iommu/vt-d: Move iopf code from SVA to IOPF enabling path
In reply to Lu BaoluGenerally enabling IOMMU_DEV_FEAT_SVA requires IOMMU_DEV_FEAT_IOPF, but some devices manage I/O Page Faults themselves instead of relying on the IOMMU. Move IOPF related code from SVA to IOPF enabling path.
For the device drivers that relies on the IOMMU for IOPF through PCI/PRI, IOMMU_DEV_FEAT_IOPF must be enabled before and disabled after IOMMU_DEV_FEAT_SVA.
--- drivers/iommu/intel/iommu.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
drivers/iommu/intel/iommu.c +18 -14
@@ -4638,7 +4638,6 @@ static int intel_iommu_enable_sva(struct device *dev) {struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu; -int ret;if (!info || dmar_disabled)return -EINVAL ;
@@ -4667,6 +4666,21 @@ static int intel_iommu_enable_sva(struct device *dev)if (!info->pri_enabled)return -EINVAL ; +return 0 ; +} + +static int intel_iommu_enable_iopf (struct device *dev) +{ +struct device_domain_info *info =dev_iommu_priv_get (dev); +struct intel_iommu *iommu; +int ret; + +if (!info || !info->ats_enabled || !info->pri_enabled) +return -ENODEV ; + iommu = info->iommu; +if (!iommu) +return -EINVAL ; + ret =iopf_queue_add_device (iommu->iopf_queue, dev);if (ret)return ret;
@@ -4678,7 +4692,7 @@ static int intel_iommu_enable_sva(struct device *dev)return ret; } -static int intel_iommu_disable_sva (struct device *dev) +static int intel_iommu_disable_iopf (struct device *dev) {struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu = info->iommu;
@@ -4695,16 +4709,6 @@ static int intel_iommu_disable_sva(struct device *dev)return ret; } -static int intel_iommu_enable_iopf (struct device *dev) -{ -struct device_domain_info *info =dev_iommu_priv_get (dev); - -if (info && info->pri_supported) -return 0 ; - -return -ENODEV ; -} -static int intel_iommu_dev_enable_feat (struct device *dev,enum iommu_dev_features feat) {
@@ -4725,10 +4729,10 @@ intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features feat) {switch (feat) {case IOMMU_DEV_FEAT_IOPF : -return 0 ; +return intel_iommu_disable_iopf (dev);case IOMMU_DEV_FEAT_SVA : -return intel_iommu_disable_sva (dev); +return 0 ;default :return -ENODEV ;
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 4/17 iommu/vt-d: Move pfsid and ats_qdep calculation to device probe path
In reply to Lu BaoluThey should be part of the per-device iommu private data initialization.
--- drivers/iommu/intel/iommu.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/iommu/intel/iommu.c +11 -15
@@ -1406,20 +1406,6 @@ static void iommu_enable_pci_caps(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_dev_id (pf_pdev); - }/* The PCIe spec, in its wisdom, declares that the behaviour of the device if you enable PASID support after ATS support is
@@ -1438,7 +1424,6 @@ static void iommu_enable_pci_caps(struct device_domain_info *info) !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) { info->ats_enabled =1 ;domain_update_iotlb (info->domain); - info->ats_qdep =pci_ats_queue_depth (pdev); } }
@@ -4521,6 +4506,17 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) dmar_ats_supported(pdev, iommu)) { info->ats_supported =1 ; info->dtlb_extra_inval =dev_needs_extra_dtlb_flush (pdev); + +/* +* 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 (iommu->ecap)) + info->pfsid =pci_dev_id (pci_physfn (pdev)); + info->ats_qdep =pci_ats_queue_depth (pdev); }if (sm_supported (iommu)) {if (pasid_supported (iommu)) {
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 5/17 iommu/vt-d: Move PRI handling to IOPF feature path
In reply to Lu BaoluPRI is only used for IOPF. With this move, the PCI/PRI feature could be controlled by the device driver through iommu_dev_enable/disable_feature() interfaces.
--- drivers/iommu/intel/iommu.c | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-)
drivers/iommu/intel/iommu.c +41 -12
@@ -1415,11 +1415,6 @@ static void iommu_enable_pci_caps(struct device_domain_info *info)if (info->pasid_supported && !pci_enable_pasid (pdev, info->pasid_supported & ~1 )) info->pasid_enabled =1 ; -if (info->pri_supported && - (info->pasid_enabled ?pci_prg_resp_pasid_required (pdev) :1 ) && - !pci_reset_pri (pdev) && !pci_enable_pri (pdev,PRQ_DEPTH )) - info->pri_enabled =1 ; -if (info->ats_supported &&pci_ats_page_aligned (pdev) && !pci_enable_ats (pdev,VTD_PAGE_SHIFT )) { info->ats_enabled =1 ;
@@ -1442,11 +1437,6 @@ static void iommu_disable_pci_caps(struct device_domain_info *info)domain_update_iotlb (info->domain); } -if (info->pri_enabled) { -pci_disable_pri (pdev); - info->pri_enabled =0 ; - } -if (info->pasid_enabled) {pci_disable_pasid (pdev); info->pasid_enabled =0 ;
@@ -4667,23 +4657,48 @@ static int intel_iommu_enable_sva(struct device *dev)static int intel_iommu_enable_iopf (struct device *dev) { +struct pci_dev *pdev =dev_is_pci (dev) ?to_pci_dev (dev) :NULL ;struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu;int ret; -if (!info || !info->ats_enabled || !info->pri_enabled) +if (!pdev || !info || !info->ats_enabled || !info->pri_supported)return -ENODEV ; + +if (info->pri_enabled) +return -EBUSY ; + iommu = info->iommu;if (!iommu)return -EINVAL ; +/* PASID is required in PRG Response Message. */ +if (info->pasid_enabled && !pci_prg_resp_pasid_required (pdev)) +return -EINVAL ; + + ret =pci_reset_pri (pdev); +if (ret) +return ret; + ret =iopf_queue_add_device (iommu->iopf_queue, dev);if (ret)return ret; ret =iommu_register_device_fault_handler (dev, iommu_queue_iopf, dev);if (ret) -iopf_queue_remove_device (iommu->iopf_queue, dev); + goto iopf_remove_device; + + ret =pci_enable_pri (pdev,PRQ_DEPTH ); +if (ret) + goto iopf_unregister_handler; + info->pri_enabled =1 ; + +return 0 ; + +iopf_unregister_handler: +iommu_unregister_device_fault_handler (dev); +iopf_remove_device: +iopf_queue_remove_device (iommu->iopf_queue, dev);return ret; }
@@ -4694,6 +4709,20 @@ static int intel_iommu_disable_iopf(struct device *dev)struct intel_iommu *iommu = info->iommu;int ret; +if (!info->pri_enabled) +return -EINVAL ; + +/* +* PCIe spec states that by clearing PRI enable bit, the Page +* Request Interface will not issue new page requests, but has +* outstanding page requests that have been transmitted or are +* queued for transmission. This is supposed to be called after +* the device driver has stopped DMA, all PASIDs have been +* unbound and the outstanding PRQs have been drained. +*/ +pci_disable_pri (to_pci_dev (dev)); + info->pri_enabled =0 ; + ret =iommu_unregister_device_fault_handler (dev);if (ret)return ret;
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 6/17 iommu/vt-d: Remove unnecessary checks in iopf disabling path
In reply to Lu Baoluiommu_unregister_device_fault_handler() and iopf_queue_remove_device() are called after device has stopped issuing new page falut requests and all outstanding page requests have been drained. They should never fail. Trigger a warning if it happens unfortunately.
--- drivers/iommu/intel/iommu.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/iommu/intel/iommu.c +8 -9
@@ -4707,7 +4707,6 @@ static int intel_iommu_disable_iopf(struct device *dev) {struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu = info->iommu; -int ret;if (!info->pri_enabled)return -EINVAL ;
@@ -4723,15 +4722,15 @@ static int intel_iommu_disable_iopf(struct device *dev)pci_disable_pri (to_pci_dev (dev)); info->pri_enabled =0 ; - ret =iommu_unregister_device_fault_handler (dev); -if (ret) -return ret; - - ret =iopf_queue_remove_device (iommu->iopf_queue, dev); -if (ret) -iommu_register_device_fault_handler (dev, iommu_queue_iopf, dev); +/* +* With PRI disabled and outstanding PRQs drained, unregistering +* fault handler and removing device from iopf queue should never +* fail. +*/ +WARN_ON (iommu_unregister_device_fault_handler (dev)); +WARN_ON (iopf_queue_remove_device (iommu->iopf_queue, dev)); -return ret; +return 0 ; } static int
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 7/17 iommu/vt-d: Do not use GFP_ATOMIC when not needed
In reply to Lu BaoluFrom: Christophe JAILLET <[email protected]>
There is no need to use GFP_ATOMIC here. GFP_KERNEL is already used for some other memory allocations just a few lines above.
Commit e3a981d61d15 ("iommu/vt-d: Convert allocations to GFP_KERNEL") has changed the other memory allocation flags.
--- drivers/iommu/intel/irq_remapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/irq_remapping.c +1 -1
@@ -548,7 +548,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) goto out_free_table; } - bitmap =bitmap_zalloc (INTR_REMAP_TABLE_ENTRIES ,GFP_ATOMIC ); + bitmap =bitmap_zalloc (INTR_REMAP_TABLE_ENTRIES ,GFP_KERNEL );if (bitmap ==NULL ) {pr_err ("IR%d: failed to allocate bitmap\n" , iommu->seq_id); goto out_free_pages;
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 8/17 iommu/vt-d: Remove extern from function prototypes
In reply to Lu BaoluThe kernel coding style does not require 'extern' in function prototypes in .h files, so remove them from drivers/iommu/intel/iommu.h as they are not needed.
--- drivers/iommu/intel/iommu.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/iommu/intel/iommu.h +18 -18
@@ -798,18 +798,18 @@ static inline bool context_present(struct context_entry *context)return (context->lo &1 ); } -extern struct dmar_drhd_unit *dmar_find_matched_drhd_unit (struct pci_dev *dev); - -extern int dmar_enable_qi (struct intel_iommu *iommu); -extern void dmar_disable_qi (struct intel_iommu *iommu); -extern int dmar_reenable_qi (struct intel_iommu *iommu); -extern void qi_global_iec (struct intel_iommu *iommu); - -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 pfsid, +struct dmar_drhd_unit *dmar_find_matched_drhd_unit (struct pci_dev *dev); + +int dmar_enable_qi (struct intel_iommu *iommu); +void dmar_disable_qi (struct intel_iommu *iommu); +int dmar_reenable_qi (struct intel_iommu *iommu); +void qi_global_iec (struct intel_iommu *iommu); + +void qi_flush_context (struct intel_iommu *iommu,u16 did, +u16 sid,u8 fm,u64 type); +void qi_flush_iotlb (struct intel_iommu *iommu,u16 did,u64 addr, +unsigned int size_order,u64 type); +void qi_flush_dev_iotlb (struct intel_iommu *iommu,u16 sid,u16 pfsid,u16 qdep,u64 addr,unsigned mask); void qi_flush_piotlb(struct intel_iommu *iommu, u16 did, u32 pasid, u64 addr,
@@ -832,7 +832,7 @@ int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc,*/ #define QI_OPT_WAIT_DRAIN BIT(0) -extern int dmar_ir_support (void ); +int dmar_ir_support (void );void *alloc_pgtable_page (int node,gfp_t gfp);void free_pgtable_page (void *vaddr);
@@ -840,9 +840,9 @@ void iommu_flush_write_buffer(struct intel_iommu *iommu);struct intel_iommu *device_to_iommu (struct device *dev,u8 *bus,u8 *devfn);#ifdef CONFIG_INTEL_IOMMU_SVM -extern void intel_svm_check (struct intel_iommu *iommu); -extern int intel_svm_enable_prq (struct intel_iommu *iommu); -extern int intel_svm_finish_prq (struct intel_iommu *iommu); +void intel_svm_check (struct intel_iommu *iommu); +int intel_svm_enable_prq (struct intel_iommu *iommu); +int intel_svm_finish_prq (struct intel_iommu *iommu);int intel_svm_page_response (struct device *dev,struct iommu_fault_event *evt,struct iommu_page_response *msg);struct iommu_domain *intel_svm_domain_alloc (void );
@@ -889,8 +889,8 @@ extern const struct iommu_ops intel_iommu_ops;#ifdef CONFIG_INTEL_IOMMU extern int intel_iommu_sm; -extern int iommu_calculate_agaw (struct intel_iommu *iommu); -extern int iommu_calculate_max_sagaw (struct intel_iommu *iommu); +int iommu_calculate_agaw (struct intel_iommu *iommu); +int iommu_calculate_max_sagaw (struct intel_iommu *iommu);int ecmd_submit_sync (struct intel_iommu *iommu,u8 ecmd,u64 oa,u64 ob);static inline bool ecmd_has_pmu_essential (struct intel_iommu *iommu)
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 9/17 iommu/vt-d: Use non-privileged mode for all PASIDs
In reply to Lu BaoluFrom: Jacob Pan <[email protected]>
Supervisor Request Enable (SRE) bit in a PASID entry is for permission checking on DMA requests. When SRE = 0, DMA with supervisor privilege will be blocked. However, for in-kernel DMA this is not necessary in that we are targeting kernel memory anyway. There's no need to differentiate user and kernel for in-kernel DMA.
Let's use non-privileged (user) permission for all PASIDs used in kernel, it will be consistent with DMA without PASID (RID_PASID) as well.
--- drivers/iommu/intel/iommu.c | 2 -- 1 file changed, 2 deletions(-)
drivers/iommu/intel/iommu.c +0 -2
@@ -2316,8 +2316,6 @@ static int domain_setup_first_level(struct intel_iommu *iommu,if (level !=4 && level !=5 )return -EINVAL ; -if (pasid !=PASID_RID2PASID ) - flags |=PASID_FLAG_SUPERVISOR_MODE ;if (level ==5 ) flags |=PASID_FLAG_FL5LP ;
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 10/17 iommu/vt-d: Remove PASID supervisor request support
In reply to Lu BaoluFrom: Jacob Pan <[email protected]>
There's no more usage, remove PASID supervisor support.
--- drivers/iommu/intel/pasid.h | 7 ------ drivers/iommu/intel/pasid.c | 43 ------------------------------------- 2 files changed, 50 deletions(-)
drivers/iommu/intel/pasid.h +0 -7
@@ -41,13 +41,6 @@#define FLPT_DEFAULT_DID 1#define NUM_RESERVED_DID 2 -/* -* The SUPERVISOR_MODE flag indicates a first level translation which -* can be used for access to kernel addresses. It is valid only for -* access to the kernel's static 1:1 mapping of physical memory — not -* to vmalloc or even module mappings. -*/ -#define PASID_FLAG_SUPERVISOR_MODE BIT(0)#define PASID_FLAG_NESTED BIT(1)#define PASID_FLAG_PAGE_SNOOP BIT(2)
drivers/iommu/intel/pasid.c +0 -43
73 lines not on this page · raw message
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 11/17 iommu/vt-d: Make size of operands same in bitwise operations
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
This addresses the following issue reported by klocwork tool:
- operands of different size in bitwise operations
--- drivers/iommu/intel/dmar.c | 2 +- drivers/iommu/intel/iommu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel/dmar.c +1 -1
@@ -1690,7 +1690,7 @@ static void __dmar_enable_qi(struct intel_iommu *iommu)* is present. */ if (ecap_smts (iommu->ecap)) - val |= (1 <<11 ) |1 ; + val |=BIT_ULL (11 ) |BIT_ULL (0 );raw_spin_lock_irqsave (&iommu->register_lock, flags);
drivers/iommu/intel/iommu.c +2 -2
@@ -1870,7 +1870,7 @@ context_set_sm_rid2pasid(struct context_entry *context, unsigned long pasid)*/ static inline void context_set_sm_dte (struct context_entry *context) { - context->lo |= (1 <<2 ); + context->lo |=BIT_ULL (2 ); }/*
@@ -1879,7 +1879,7 @@ static inline void context_set_sm_dte(struct context_entry *context)*/ static inline void context_set_sm_pre (struct context_entry *context) { - context->lo |= (1 <<4 ); + context->lo |=BIT_ULL (4 ); }/* Convert value to context PASID directory size field coding. */
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 12/17 iommu/vt-d: Remove BUG_ON on checking valid pfn range
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
When encountering an unexpected invalid pfn range, the kernel should attempt recovery and proceed with execution. Therefore, using WARN_ON to replace BUG_ON to avoid halting the machine.
Besides, one redundant checking is reduced.
--- drivers/iommu/intel/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iommu/intel/iommu.c +6 -6
@@ -1005,9 +1005,9 @@ static void dma_pte_clear_range(struct dmar_domain *domain,unsigned int large_page;struct dma_pte *first_pte, *pte; -BUG_ON (!domain_pfn_supported (domain, start_pfn)); -BUG_ON (!domain_pfn_supported (domain, last_pfn)); -BUG_ON (start_pfn > last_pfn); +if (WARN_ON (!domain_pfn_supported (domain, last_pfn)) || +WARN_ON (start_pfn > last_pfn)) +return ;/* we don't need lock here; nobody else touches the iova range */ do {
@@ -1166,9 +1166,9 @@ static void dma_pte_clear_level(struct dmar_domain *domain, int level,static void domain_unmap (struct dmar_domain *domain,unsigned long start_pfn,unsigned long last_pfn,struct list_head *freelist) { -BUG_ON (!domain_pfn_supported (domain, start_pfn)); -BUG_ON (!domain_pfn_supported (domain, last_pfn)); -BUG_ON (start_pfn > last_pfn); +if (WARN_ON (!domain_pfn_supported (domain, last_pfn)) || +WARN_ON (start_pfn > last_pfn)) +return ;/* we don't need lock here; nobody else touches the iova range */ dma_pte_clear_level(domain, agaw_to_level(domain->agaw),
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 13/17 iommu/vt-d: Remove BUG_ON in handling iotlb cache invalidation
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
VT-d iotlb cache invalidation request with unexpected type is considered as a bug to developers, which can be fixed. So, when such kind of issue comes out, it needs to be reported through the kernel log, instead of halting the system. Replacing BUG_ON with warning reporting.
--- drivers/iommu/intel/iommu.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +8 -3
@@ -1272,7 +1272,9 @@ static void __iommu_flush_context(struct intel_iommu *iommu, | DMA_CCMD_SID(source_id) | DMA_CCMD_FM(function_mask);break ;default : -BUG (); +pr_warn ("%s: Unexpected context-cache invalidation type 0x%llx\n" , + iommu->name, type); +return ; } val |=DMA_CCMD_ICC ;
@@ -1308,7 +1310,9 @@ static void __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did, val_iva = size_order | addr;break ;default : -BUG (); +pr_warn ("%s: Unexpected iotlb invalidation type 0x%llx\n" , + iommu->name, type); +return ; }/* Note: set drain read/write */ #if 0
@@ -1483,7 +1487,8 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu,uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did =domain_id_iommu (domain, iommu); -BUG_ON (pages ==0 ); +if (WARN_ON (!pages)) +return ;if (ih) ih =1 <<6 ;
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 14/17 iommu/vt-d: Remove BUG_ON when domain->pgd is NULL
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
When performing domain_context_mapping or getting dma_pte of a pfn, the availability of the domain page table directory is ensured. Therefore, the domain->pgd checkings are unnecessary.
--- drivers/iommu/intel/iommu.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/iommu/intel/iommu.c +0 -4
@@ -915,8 +915,6 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,int level =agaw_to_level (domain->agaw);int offset; -BUG_ON (!domain->pgd); -if (!domain_pfn_supported (domain, pfn))/* Address beyond IOMMU's addressing capabilities. */ return NULL ;
@@ -1910,8 +1908,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,pr_debug ("Set context mapping for %02x:%02x.%d\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn)); -BUG_ON (!domain->pgd); -spin_lock (&iommu->lock); ret = -ENOMEM ; context =iommu_context_addr (iommu, bus, devfn,1 );
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 15/17 iommu/vt-d: Remove BUG_ON in map/unmap()
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
Domain map/unmap with invalid parameters shouldn't crash the kernel. Therefore, using if() replaces the BUG_ON.
--- drivers/iommu/intel/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +5 -3
@@ -2159,7 +2159,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,phys_addr_t pteval;u64 attr; -BUG_ON (!domain_pfn_supported (domain, iov_pfn + nr_pages -1 )); +if (unlikely (!domain_pfn_supported (domain, iov_pfn + nr_pages -1 ))) +return -EINVAL ;if ((prot & (DMA_PTE_READ |DMA_PTE_WRITE )) ==0 )return -EINVAL ;
@@ -4314,8 +4315,9 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain,/* Cope with horrid API which requires us to unmap more than the size argument if it happens to be a large-page mapping. */ -BUG_ON (!pfn_to_dma_pte (dmar_domain, iova >>VTD_PAGE_SHIFT , &level, -GFP_ATOMIC )); +if (unlikely (!pfn_to_dma_pte (dmar_domain, iova >>VTD_PAGE_SHIFT , + &level,GFP_ATOMIC ))) +return 0 ;if (size <VTD_PAGE_SIZE <<level_to_offset_bits (level)) size =VTD_PAGE_SIZE <<level_to_offset_bits (level);
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 16/17 iommu/vt-d: Remove a useless BUG_ON(dev->is_virtfn)
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
When dmar_alloc_pci_notify_info() is being invoked, the invoker has ensured the dev->is_virtfn is false. So, remove the useless BUG_ON in dmar_alloc_pci_notify_info().
--- drivers/iommu/intel/dmar.c | 2 -- 1 file changed, 2 deletions(-)
drivers/iommu/intel/dmar.c +0 -2
@@ -127,8 +127,6 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event)struct pci_dev *tmp;struct dmar_pci_notify_info *info; -BUG_ON (dev->is_virtfn); -/* * Ignore devices that have a domain number higher than what can * be looked up in DMAR, e.g. VMD subdevices with domain 0x10000
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v2 17/17 iommu/vt-d: Remove BUG_ON in dmar_insert_dev_scope()
In reply to Lu BaoluFrom: Tina Zhang <[email protected]>
The dmar_insert_dev_scope() could fail if any unexpected condition is encountered. However, in this situation, the kernel should attempt recovery and proceed with execution. Remove BUG_ON with WARN_ON, so that kernel can avoid being crashed when an unexpected condition occurs.
--- drivers/iommu/intel/dmar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel/dmar.c +2 -1
@@ -262,7 +262,8 @@ int dmar_insert_dev_scope(struct dmar_pci_notify_info *info, get_device(dev));return 1 ; } -BUG_ON (i >= devices_cnt); +if (WARN_ON (i >= devices_cnt)) +return -EINVAL ; }return 0 ;
Signature · 1 line
2.34.1
Quoted 9 lines · Lu Baolu
Lu Baolu (7):
dmaengine: idxd: Add enable/disable device IOPF feature iommu/vt-d: Allow SVA with device-specific IOPF iommu/vt-d: Move iopf code from SVA to IOPF enabling path iommu/vt-d: Move pfsid andats_qdepcalculation to device probe path iommu/vt-d: Move PRI handling to IOPF feature path iommu/vt-d: Remove unnecessary checks in iopf disabling path iommu/vt-d: Remove extern from function prototypes
Quoted 8 lines
Tina Zhang (7):
iommu/vt-d: Make size of operands same in bitwise operations iommu/vt-d: RemoveBUG_ONon checking valid pfn range iommu/vt-d: RemoveBUG_ONin handling iotlb cache invalidation iommu/vt-d: RemoveBUG_ONwhendomain->pgdis NULL iommu/vt-d: RemoveBUG_ONin map/unmap()
iommu/vt-d: Remove a uselessBUG_ON(dev->is_virtfn)iommu/vt-d: RemoveBUG_ONindmar_insert_dev_scope()
Applied, thanks.