iommu/amd: Make PerfOpt compulsory
Subsystems (4)
PATCH v2 1/1 iommu/amd: Make PerfOpt compulsory
PerfOpt is only a feature usable by integrated GPUs and only in identity mode. Instead of leaving a policy knob in amdgpu, just turn it on when an integrated GPU is in identity.
This drops quite a bit of compatibility glue. There was a refcounting system, exported symbols, and device attach/detach logic. By just setting it immediately it's a lot more straightforward.
---
v2:
* Move WARN_ON to amd_iommu_perfopt_clear()
* Make amd_iommu_perfopt_clear() void
* Drop unnecessary cleanup/create paths that unset feature
* Enable the feature in IOMMU if supported (per guidance in IVRS spec)
* Use existing check_feature() helper instead
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 50 ----- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 - drivers/iommu/amd/amd_iommu.h | 3 +- drivers/iommu/amd/amd_iommu_types.h | 3 - drivers/iommu/amd/init.c | 50 +---- drivers/iommu/amd/iommu.c | 243 +++------------------ include/linux/amd-iommu.h | 11 - 8 files changed, 40 insertions(+), 333 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
@@ -156,7 +156,6 @@ struct amdgpu_watchdog_timer {* Modules parameters. */ extern int amdgpu_modeset; -extern int amdgpu_iommu_perfopt;extern unsigned int amdgpu_vram_limit;extern int amdgpu_vis_vram_limit;extern int amdgpu_gart_size;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -50
80 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -12
@@ -185,7 +185,6 @@ char *amdgpu_disable_cu;char *amdgpu_virtual_display;int amdgpu_enforce_isolation =-1 ;int amdgpu_modeset =-1 ; -int amdgpu_iommu_perfopt =-1 ;/* Specifies the default granularity for SVM, used in buffer * migration and restoration of backing memory when handling
@@ -393,17 +392,6 @@ module_param_named(fw_load_type, amdgpu_fw_load_type, int, 0444);MODULE_PARM_DESC (aspm,"ASPM support (1 = enable, 0 = disable, -1 = auto)" );module_param_named (aspm, amdgpu_aspm, int,0444 ); -/** -* DOC: iommu_perfopt (int) -* Control the AMD IOMMU PerfOpt DMA-latency optimization -* (0 = disable; -1 = enable on supported devices). -* This arms the IOMMU PerfOpt control (IOMMU spec, MMIO Offset 016Ch, EFR PerfOptSup / PerfOptEn) -* Arming it disables ATS, PRI, PASID and SVA for the GPU and removes IOMMU DMA containment for it, -* trading isolation for lower DMA latency. -*/ -MODULE_PARM_DESC (iommu_perfopt,"Control IOMMU PerfOpt DMA-latency optimization (-1 = enable on supported devices, 0 = disable)" ); -module_param_named (iommu_perfopt, amdgpu_iommu_perfopt, int,0444 ); -/** * DOC: runpm (int) * Override for runtime power management control for dGPUs. The amdgpu driver can dynamically power down
drivers/iommu/amd/amd_iommu.h +1 -2
@@ -48,8 +48,7 @@ extern u8 amd_iommu_hpt_vasize;extern unsigned long amd_iommu_pgsize_bitmap;extern bool amd_iommu_hatdis; -int amd_iommu_perfopt_clear (struct amd_iommu *iommu); -int amd_iommu_perfopt_restore (struct amd_iommu *iommu); +int amd_iommu_perfopt_set (struct amd_iommu *iommu,bool enable);/* Protection domain ops */ void amd_iommu_init_identity_domain (void );
drivers/iommu/amd/amd_iommu_types.h +0 -3
@@ -657,9 +657,6 @@ struct amd_iommu {/* Extended features 2 */ u64 features2; -/* Devices requesting PerfOpt; the shared PERF_OPT_EN bit is on while >0. Protected by @lock. */ -int perfopt_refcount; -/* PCI device id of the IOMMU device */ u16 devid;
drivers/iommu/amd/init.c +7 -43
90 lines not on this page · raw message
drivers/iommu/amd/iommu.c +32 -211
285 lines not on this page · raw message
include/linux/amd-iommu.h +0 -11
@@ -76,15 +76,4 @@ static inline int amd_iommu_snp_disable(void) { return 0; }static inline bool amd_iommu_sev_tio_supported (void ) {return false; }#endif -#ifdef CONFIG_AMD_IOMMU -int amd_iommu_enable_perfopt (struct pci_dev *pdev); -void amd_iommu_disable_perfopt (struct pci_dev *pdev); -#else -static inline int amd_iommu_enable_perfopt (struct pci_dev *pdev) -{ -return 0 ; -} -static inline void amd_iommu_disable_perfopt (struct pci_dev *pdev) { } -#endif -#endif /* _ASM_X86_AMD_IOMMU_H */
Signature · 1 line
2.53.0
Vasant Hegde
maintainerMario,
Quoted 10 lines · Mario Limonciello (AMD)
PerfOpt is only a feature usable by integrated GPUs and only in identity mode. Instead of leaving a policy knob in amdgpu, just turn it on when an integrated GPU is in identity.
This drops quite a bit of compatibility glue. There was a refcounting system, exported symbols, and device attach/detach logic. By just setting it immediately it's a lot more straightforward.
Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>
Quoted 8 lines
---
v2:
* MoveWARN_ONtoamd_iommu_perfopt_clear()
* Makeamd_iommu_perfopt_clear()void
* Drop unnecessary cleanup/create paths that unset feature
* Enable the feature in IOMMU if supported (per guidance in IVRS spec)
* Use existingcheck_feature()helper instead
---
.../...
Quoted 5 lines
drivers/iommu/amd/iommu.c +0
-0
drivers/iommu/amd/iommu.c static void pdom_detach_iommu(struct amd_iommu *iommu, · line 2353
Quoted 9 lines
drivers/iommu/amd/iommu.c +6
-0@@ -2345,6 +2345,35 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,spin_unlock_irqrestore (&pdom->lock, flags); } +/* +* Program or clear the per-IOMMU PerfOpt enable bit +* This allows a privileged internal GPU to be able to bypass IOMMU when +* in identity mode. +*/ +int amd_iommu_perfopt_set (struct amd_iommu *iommu,bool enable)
Please move this to init.c file
Quoted 10 lines
drivers/iommu/amd/iommu.c +10
-0+{ +u32 old, val, readback; + +if (!check_feature (FEATURE_PERF_OPT )) +return enable ? -ENODEV :0 ; + + old =readl (iommu->mmio_base +MMIO_PERF_OPT_OFFSET ); +if (old ==U32_MAX ) +return -EIO ; +
drivers/iommu/amd/iommu.c static void pdom_detach_iommu(struct amd_iommu *iommu, · line 2373
Quoted 10 lines
drivers/iommu/amd/iommu.c +10
-0+ val = enable ? old |PERF_OPT_EN : old & ~PERF_OPT_EN ; +if (val != old) +writel (val, iommu->mmio_base +MMIO_PERF_OPT_OFFSET ); + readback =readl (iommu->mmio_base +MMIO_PERF_OPT_OFFSET ); +if (readback ==U32_MAX || + (readback &PERF_OPT_EN ) != (val &PERF_OPT_EN )) { +dev_err (iommu->iommu.dev,"Failed to set PerfOpt to %d\n" , enable); +return -EIO ; + } +
May be check return value before enabling dev_data->perfopt?
-Vasant
Quoted 33 lines · Vasant Hegde
Mario,
Quoted 10 lines · Mario Limonciello (AMD)
PerfOpt is only a feature usable by integrated GPUs and only in identity mode. Instead of leaving a policy knob in amdgpu, just turn it on when an integrated GPU is in identity.
This drops quite a bit of compatibility glue. There was a refcounting system, exported symbols, and device attach/detach logic. By just setting it immediately it's a lot more straightforward.
Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>Quoted 8 lines
---
v2:
* MoveWARN_ONtoamd_iommu_perfopt_clear()
* Makeamd_iommu_perfopt_clear()void
* Drop unnecessary cleanup/create paths that unset feature
* Enable the feature in IOMMU if supported (per guidance in IVRS spec)
* Use existingcheck_feature()helper instead
---.../...
Quoted 8 lines
drivers/iommu/amd/iommu.c +0
-0@@ -2345,6 +2345,35 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,spin_unlock_irqrestore (&pdom->lock, flags); }
Quoted 8 lines
drivers/iommu/amd/iommu.c static void pdom_detach_iommu(struct amd_iommu *iommu, · line 2353
Quoted 6 lines
drivers/iommu/amd/iommu.c +6
-0+/* +* Program or clear the per-IOMMU PerfOpt enable bit +* This allows a privileged internal GPU to be able to bypass IOMMU when +* in identity mode. +*/ +int amd_iommu_perfopt_set (struct amd_iommu *iommu,bool enable)Please move this to
init.cfile
Thanks, good suggestion.
Quoted 15 lines
Quoted 15 lines
drivers/iommu/amd/iommu.c +14
-0+{ +u32 old, val, readback; + +if (!check_feature (FEATURE_PERF_OPT )) +return enable ? -ENODEV :0 ; + + old =readl (iommu->mmio_base +MMIO_PERF_OPT_OFFSET ); +if (old ==U32_MAX ) +return -EIO ; + + val = enable ? old |PERF_OPT_EN : old & ~PERF_OPT_EN ; +if (val != old) +writel (val, iommu->mmio_base +MMIO_PERF_OPT_OFFSET ); + readback =readl (iommu->mmio_base +MMIO_PERF_OPT_OFFSET );
Quoted 8 lines
drivers/iommu/amd/iommu.c static void pdom_detach_iommu(struct amd_iommu *iommu, · line 2373
Quoted 6 lines
drivers/iommu/amd/iommu.c +6
-0+if (readback ==U32_MAX || + (readback &PERF_OPT_EN ) != (val &PERF_OPT_EN )) { +dev_err (iommu->iommu.dev,"Failed to set PerfOpt to %d\n" , enable); +return -EIO ; + } +May be check return value before enabling
dev_data->perfopt?
I thought about this.
Let me know what you think of the approach of clearing the bit in amd_iommu_efr on failures within amd_iommu_perfopt_set().
That would mean that dev_data->perfopt doesn't get enabled later.
Vasant Hegde
maintainerQuoted 3 lines · Mario Limonciello
Quoted 2 lines · Vasant Hegde
Mario,
.../...
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
+ u32 old, val, readback;
drivers/iommu/amd/iommu.c +12
-0+ + if (!check_feature(FEATURE_PERF_OPT)) + return enable ? -ENODEV : 0; + + old = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET); + if (old == U32_MAX) + return -EIO; + + val = enable ? old | PERF_OPT_EN : old & ~PERF_OPT_EN; + if (val != old) + writel(val, iommu->mmio_base + MMIO_PERF_OPT_OFFSET); + readback = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET);Quoted 8 lines
Quoted 6 lines
+ if (readback ==
U32_MAX||
+ (readback &PERF_OPT_EN) != (val &PERF_OPT_EN)) {
+dev_err(iommu->iommu.dev, "Failed to set PerfOpt to %d\n", enable); + return-EIO;
+ }
+May be check return value before enabling
dev_data->perfopt?
Quoted 4 lines
I thought about this.
Let me know what you think of the approach of clearing the bit in
amd_iommu_efron failures withinamd_iommu_perfopt_set().
Yeah. It makes sense.
-Vasant