iommu/amd: Make PerfOpt compulsory for APUs in identity
Subsystems (4)
PATCH 1/1 iommu/amd: Make PerfOpt compulsory for APUs in identity
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 in an APU is in identity. Re-use the heuristic in amd_iommu_def_domain_type() to make this decision.
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.
--- 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 | 2 +- drivers/iommu/amd/amd_iommu_types.h | 3 - drivers/iommu/amd/init.c | 3 +- drivers/iommu/amd/iommu.c | 234 ++++----------------- include/linux/amd-iommu.h | 11 - 8 files changed, 48 insertions(+), 268 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 -1
@@ -49,7 +49,7 @@ 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_arm (struct amd_iommu *iommu);/* 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 +1 -2
@@ -3070,7 +3070,7 @@ static int restore_perfopt_all(void)int err, ret =0 ;for_each_iommu (iommu) { - err =amd_iommu_perfopt_restore (iommu); + err =amd_iommu_perfopt_arm (iommu);if (err) ret = err; }
@@ -3115,7 +3115,6 @@ static void amd_iommu_resume(void *data)for_each_iommu (iommu)early_enable_iommu (iommu); -/* early_enable_iommu() cleared PERF_OPT_EN; re-assert it from the refcount. */ if (restore_perfopt_all ())pr_err ("Failed to restore PerfOpt after IOMMU resume\n" );
drivers/iommu/amd/iommu.c +46 -188
276 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 */
base-commit: e74db71a3530740bb783e3a01420f6af245630b4
Signature · 1 line
2.53.0
Quoted 11 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 in an APU is in identity. Re-use the heuristic in
amd_iommu_def_domain_type()to make this decision.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 10 lines
--- 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 | 2 +- drivers/iommu/amd/amd_iommu_types.h | 3 - drivers/iommu/amd/init.c | 3 +- drivers/iommu/amd/iommu.c | 234 ++++----------------- include/linux/amd-iommu.h | 11 - 8 files changed, 48 insertions(+), 268 deletions(-)
Diffing across the originals to net them out it is much smaller:
5 files changed, 122 insertions(+), 1 deletion(-)
And I think this is much better , but I have a few questions
Why is this setting and clearing perf_opt in dev_data?
I expect probe to make a determination if this device has the special path and if so then there should be a permanent flag in the dev_data.
Based on that flag amd_iommu_def_domain_type() can return identity to override things
When the driver does an identity attachment it would enable the perfopt and write out the right DTE for it.
Whenever the driver removes that identity it would disable the perf_opt. These points are all marked out in the attach function flow you don't need another variable to keep track, or the funny logic to block things. All you want is an attached identity domain that is "optimized".
Release goes to blocked which should already disable it, so no need to disable it again in amd_iommu_release_device()
The repeated pattern is a bit much:
+ if (dev_data->perfopt) {
+ if (WARN_ON(amd_iommu_perfopt_clear(iommu)))
+ dev_err(dev, "IOMMU%d: failed to clear PerfOpt on release\n",
+ iommu->index);
Clear should probably just do the warn on and not return any error code. It is never OK to allow this to fail..
I'm also scratching my head a bit why the global register needs to be set/unset like this? Does that global bit completely bypass the iommu for a single special device? With no way to discover from FW which BDF is the special device? If this is the right guess please document this in a comment around __perfopt_write (and again that's awful, ACPI should have a pointer to the special device so the OS can understand this)
Jason
Quoted 31 lines · Jason Gunthorpe
Quoted 11 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 in an APU is in identity. Re-use the heuristic in
amd_iommu_def_domain_type()to make this decision.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 10 lines
--- 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 | 2 +- drivers/iommu/amd/amd_iommu_types.h | 3 - drivers/iommu/amd/init.c | 3 +- drivers/iommu/amd/iommu.c | 234 ++++----------------- include/linux/amd-iommu.h | 11 - 8 files changed, 48 insertions(+), 268 deletions(-)Diffing across the originals to net them out it is much smaller:
5 files changed, 122 insertions(+), 1 deletion(-)And I think this is much better , but I have a few questions
Why is this setting and clearing
perf_optindev_data?
Quoted 8 lines
I expect probe to make a determination if this device has the special path and if so then there should be a permanent flag in the
dev_data.Based on that flag
amd_iommu_def_domain_type()can return identity to override thingsWhen the driver does an identity attachment it would enable the perfopt and write out the right DTE for it.
I believe you're right. This was an artifact from the tracking I had to do when it was a two driver solution. I'll rework it.
Quoted 16 lines
Whenever the driver removes that identity it would disable the
perf_opt. These points are all marked out in the attach function flow you don't need another variable to keep track, or the funny logic to block things. All you want is an attached identity domain that is "optimized".Release goes to blocked which should already disable it, so no need to disable it again in
amd_iommu_release_device()The repeated pattern is a bit much:
(quoted diff) +4
-0+ if (dev_data->perfopt) { + if (WARN_ON(amd_iommu_perfopt_clear(iommu))) + dev_err(dev, "IOMMU%d: failed to clear PerfOpt on release\n", + iommu->index);
Quoted 2 lines
Clear should probably just do the warn on and not return any error code. It is never OK to allow this to fail..
OK.
Quoted 9 lines
I'm also scratching my head a bit why the global register needs to be set/unset like this? Does that global bit completely bypass the iommu for a single special device? With no way to discover from FW which BDF is the special device? If this is the right guess please document this in a comment around
__perfopt_write(and again that's awful, ACPI should have a pointer to the special device so the OS can understand this)
Yeah; it's only for the privileged integrated GPU to access system memory.
I'll leave a comment around it in a v2.