iommu/amd: Make PerfOpt compulsory
Subsystems (4)
PATCH v4 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.
PerfOpt locks the GPU into identity mode where the DTE is ignored, so mark it require_direct (blocks VFIO/iommufd claims) and disable PASID (no GCR3 table in the fast path).
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.
---
v4:
* Disable PASID for PerfOpt devices
* Don't allow attaching a blocked domain
v3:
* Move amd_iommu_perfopt_set() to init.c and set static (Vasant)
* Clear bit if it fails to enable (Vasant)
* Use pr_err() instead of dev_err for early errors (Sashiko)
* Restore attach_device check for VFIO cases (Sashiko)
* Handle VFIO case (Sashiko)
* Handle multi-IOMMU case (Sashiko)
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 | 81 ++++--- drivers/iommu/amd/iommu.c | 233 ++------------------- include/linux/amd-iommu.h | 11 - 8 files changed, 60 insertions(+), 334 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 +0 -3
@@ -48,9 +48,6 @@ 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); -/* Protection domain ops */ void amd_iommu_init_identity_domain (void );struct protection_domain *protection_domain_alloc (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 +38 -43
127 lines not on this page · raw message
drivers/iommu/amd/iommu.c +22 -211
269 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
maintainerQuoted 12 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.
PerfOpt locks the GPU into identity mode where the DTE is ignored, so mark it
require_direct(blocks VFIO/iommufd claims) and disable PASID (no GCR3 table in the fast path).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.
Quoted 6 lines
Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v4:
* Disable PASID for PerfOpt devices
* Don't allow attaching a blocked domain
This will block attaching device to guest via vfio-pci. Is that fine?
-Vasant
Quoted 22 lines · Vasant Hegde
Quoted 12 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.
PerfOpt locks the GPU into identity mode where the DTE is ignored, so mark it
require_direct(blocks VFIO/iommufd claims) and disable PASID (no GCR3 table in the fast path).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.
Quoted 6 lines
Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v4:
* Disable PASID for PerfOpt devices
* Don't allow attaching a blocked domain
Quoted 4 lines
This will block attaching device to guest via vfio-pci. Is that fine?
-Vasant
Right - The thing is from that experiment on v3, putting it in blocked domain does nothing while PerfOpt is enabled.
I figured the user should be aware; so I was between blocking attaching a blocked domain or showing a warning.
Quoted 20 lines · Mario Limonciello
Quoted 20 lines · Mario Limonciello (AMD)
Quoted 18 lines
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.
PerfOpt locks the GPU into identity mode where the DTE is ignored, so mark it
require_direct(blocks VFIO/iommufd claims) and disable PASID (no GCR3 table in the fast path).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]>---
v4:
* Disable PASID for PerfOpt devices
* Don't allow attaching a blocked domain
Quoted 7 lines
Quoted 1 line
This will block attaching device to guest via vfio-pci. Is that fine?
Right - The thing is from that experiment on v3, putting it in blocked domain does nothing while PerfOpt is enabled.
I figured the user should be aware; so I was between blocking attaching a blocked domain or showing a warning.
Ideally you'd fix it by making the perfopt bit only set when an identity domain is attached.
Though I'm not especially happy to see a driver that can't support at least blocking, that's pretty broken in our model...
Definately don't show a warning, this is security stuff if the driver can't do an operation then it must fail.
Jason
Vasant Hegde
maintainerMario,
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 is in identity.
PerfOpt locks the GPU into identity mode where the DTE is ignored, so mark it
require_direct(blocks VFIO/iommufd claims) and disable PASID (no GCR3 table in the fast path).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.
I believe its good to get this merged in this cycle itself so that we can get rid of the command line options introduced earlier.
I have looked into this patch again. How about somthing like below:
- Do not call amd_iommu_perfopt_set() in early_enable_iommu() path Because it enables feature on all IOMMUs even though it may not have iGPUs
- amd_iommu_def_domain_type:
mark device PerfOpt-eligible
select identity
- identity attach:
Enable IOMMU perfOpt feature
- DMA / Blocked domain
Disable IOMMU perfOpt feature
- resume:
restore hardware bit
-Vasant