iommu/vt-d: Restore previous domain::aperture_end calculation
Subsystems (2)
Lu Baolu
maintainerPATCH 1/1 iommu/vt-d: Restore previous domain::aperture_end calculation
Commit d373449d8e97 ("iommu/vt-d: Use the generic iommu page table") changed the calculation of domain::aperture_end. Previously, it was calculated as:
domain->domain.geometry.aperture_end =
__DOMAIN_MAX_ADDR(domain->gaw - 1);where domain->gaw was limited to less than MGAW.
Currently, it is calculated purely based on the max level of the page table that the hardware supports. This is incorrect as stated in Section 3.6 of the VT-d spec:
"Software using first-stage translation structures to translate an IO
Virtual Address (IOVA) must use canonical addresses. Additionally, software must limit addresses to less than the minimum of MGAW and the lower canonical address width implied by FSPM (i.e., 47-bit when FSPM is 4-level and 56-bit when FSPM is 5-level)."
Restore the previous calculation method for domain::aperture_end to avoid violating the spec. Incorrect aperture calculation causes GPU hangs without generating VT-d faults on some Intel client platforms.
--- drivers/iommu/intel/iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/iommu/intel/iommu.c +10 -0
@@ -2817,6 +2817,16 @@ intel_iommu_domain_alloc_first_stage(struct device *dev, cfg.common.hw_max_vasz_lg2 =57 ; else cfg.common.hw_max_vasz_lg2 = 48; + +/* +* Spec 3.6 First-Stage Translation: +* +* Software must limit addresses to less than the minimum of MGAW +* and the lower canonical address width implied by FSPM (i.e., +* 47-bit when FSPM is 4-level and 56-bit when FSPM is 5-level). +*/ + cfg.common.hw_max_vasz_lg2 =min (cap_mgaw (iommu->cap), + cfg.common.hw_max_vasz_lg2); cfg.common.hw_max_oasz_lg2 =52 ; cfg.common.features =BIT (PT_FEAT_SIGN_EXTEND ) |BIT (PT_FEAT_FLUSH_RANGE );
Signature · 1 line
2.43.0
Quoted 9 lines · Lu Baolu
Fixes d373449d8e97 ("iommu/vt-d: Use the generic iommu page table")Reported-by Chaitanya Kumar Borah <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Suggested-by Kevin Tian <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/intel/iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Applied, thanks.
Quoted 9 lines · Lu Baolu
drivers/iommu/intel/iommu.c +3
-0@@ -2817,6 +2817,16 @@ intel_iommu_domain_alloc_first_stage(struct device *dev, cfg.common.hw_max_vasz_lg2 =57 ; else cfg.common.hw_max_vasz_lg2 = 48; + +/* +* Spec 3.6 First-Stage Translation:
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_first_stage(struct device *dev, · line 2832
Quoted 10 lines
drivers/iommu/intel/iommu.c +7
-0+* +* Software must limit addresses to less than the minimum of MGAW +* and the lower canonical address width implied by FSPM (i.e., +* 47-bit when FSPM is 4-level and 56-bit when FSPM is 5-level). +*/ + cfg.common.hw_max_vasz_lg2 =min (cap_mgaw (iommu->cap), + cfg.common.hw_max_vasz_lg2); cfg.common.hw_max_oasz_lg2 =52 ; cfg.common.features =BIT (PT_FEAT_SIGN_EXTEND ) |BIT (PT_FEAT_FLUSH_RANGE );
This is missing the hunk for paging_domain_compatible_first_stage(), I think that is important!
Jason
Baolu Lu
maintainerQuoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Lu Baolu
drivers/iommu/intel/iommu.c +7
-0@@ -2817,6 +2817,16 @@ intel_iommu_domain_alloc_first_stage(struct device *dev, cfg.common.hw_max_vasz_lg2 =57 ; else cfg.common.hw_max_vasz_lg2 = 48; + +/* +* Spec 3.6 First-Stage Translation: +* +* Software must limit addresses to less than the minimum of MGAW +* and the lower canonical address width implied by FSPM (i.e., +* 47-bit when FSPM is 4-level and 56-bit when FSPM is 5-level).
Quoted 8 lines
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_first_stage(struct device *dev, · line 2832
Quoted 6 lines
drivers/iommu/intel/iommu.c +3
-0+*/ + cfg.common.hw_max_vasz_lg2 =min (cap_mgaw (iommu->cap), + cfg.common.hw_max_vasz_lg2); cfg.common.hw_max_oasz_lg2 =52 ; cfg.common.features =BIT (PT_FEAT_SIGN_EXTEND ) |BIT (PT_FEAT_FLUSH_RANGE );This is missing the hunk for
paging_domain_compatible_first_stage(), I think that is important!
Yes. I want to make that a separate patch as that will be Cc'd to stable and backported further than this one. We should have such a compatibility check even without the generic iopt conversion, right?
Thanks,
baolu
Quoted 28 lines
From: Baolu Lu <[email protected]>
Sent: Friday, November 21, 2025 9:40 AMQuoted 4 lines · Jason Gunthorpe
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_first_stage(struct
Quoted 3 lines · Lu Baolu
drivers/iommu/intel/iommu.c +0
-0@@ -2817,6 +2817,16 @@ intel_iommu_domain_alloc_first_stage(structdevice *dev,
Quoted 10 lines
Quoted 10 lines
drivers/iommu/intel/iommu.c +7
-0cfg.common.hw_max_vasz_lg2 =57 ; else cfg.common.hw_max_vasz_lg2 = 48; + +/* +* Spec 3.6 First-Stage Translation: +* +* Software must limit addresses to less than the minimum of MGAW +* and the lower canonical address width implied by FSPM (i.e., +* 47-bit when FSPM is 4-level and 56-bit when FSPM is 5-level). Quoted 8 lines
drivers/iommu/intel/iommu.c intel_iommu_domain_alloc_first_stage(struct device *dev, · line 2832
Quoted 6 lines
drivers/iommu/intel/iommu.c +3
-0+*/ + cfg.common.hw_max_vasz_lg2 =min (cap_mgaw (iommu->cap), + cfg.common.hw_max_vasz_lg2); cfg.common.hw_max_oasz_lg2 =52 ; cfg.common.features =BIT (PT_FEAT_SIGN_EXTEND ) |BIT (PT_FEAT_FLUSH_RANGE );This is missing the hunk for
paging_domain_compatible_first_stage(), I think that is important!
Quoted 4 lines
Yes. I want to make that a separate patch as that will be Cc'd to stable and backported further than this one. We should have such a compatibility check even without the generic iopt conversion, right?
No, I don't think we should backport a change which might break the old usage.
Instead the main reason here is to unblock the vt-d generic_pt support in this cycle. For that purpose it's better to match the old behavior (which doesn't have this check) to avoid regression. Then we work on a follow-up patch to enforce the compatibility check which can be easily improved/reverted based on what might be (unexpectedly) broken.