Skip to content

Commit 8637afa

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/amd: Fix geometry.aperture_end for V2 tables
The AMD IOMMU documentation seems pretty clear that the V2 table follows the normal CPU expectation of sign extension. This is shown in Figure 25: AMD64 Long Mode 4-Kbyte Page Address Translation Where bits Sign-Extend [63:57] == [56]. This is typical for x86 which would have three regions in the page table: lower, non-canonical, upper. The manual describes that the V1 table does not sign extend in section 2.2.4 Sharing AMD64 Processor and IOMMU Page Tables GPA-to-SPA Further, Vasant has checked this and indicates the HW has an addtional behavior that the manual does not yet describe. The AMDv2 table does not have the sign extended behavior when attached to PASID 0, which may explain why this has gone unnoticed. The iommu domain geometry does not directly support sign extended page tables. The driver should report only one of the lower/upper spaces. Solve this by removing the top VA bit from the geometry to use only the lower space. This will also make the iommu_domain work consistently on all PASID 0 and PASID != 1. Adjust dma_max_address() to remove the top VA bit. It now returns: 5 Level: Before 0x1ffffffffffffff After 0x0ffffffffffffff 4 Level: Before 0xffffffffffff After 0x7fffffffffff Fixes: 11c439a ("iommu/amd/pgtbl_v2: Fix domain max address") Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 9628e5c commit 8637afa

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,8 +2529,21 @@ static inline u64 dma_max_address(enum protection_domain_mode pgtable)
25292529
if (pgtable == PD_MODE_V1)
25302530
return PM_LEVEL_SIZE(amd_iommu_hpt_level);
25312531

2532-
/* V2 with 4/5 level page table */
2533-
return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
2532+
/*
2533+
* V2 with 4/5 level page table. Note that "2.2.6.5 AMD64 4-Kbyte Page
2534+
* Translation" shows that the V2 table sign extends the top of the
2535+
* address space creating a reserved region in the middle of the
2536+
* translation, just like the CPU does. Further Vasant says the docs are
2537+
* incomplete and this only applies to non-zero PASIDs. If the AMDv2
2538+
* page table is assigned to the 0 PASID then there is no sign extension
2539+
* check.
2540+
*
2541+
* Since the IOMMU must have a fixed geometry, and the core code does
2542+
* not understand sign extended addressing, we have to chop off the high
2543+
* bit to get consistent behavior with attachments of the domain to any
2544+
* PASID.
2545+
*/
2546+
return ((1ULL << (PM_LEVEL_SHIFT(amd_iommu_gpt_level) - 1)) - 1);
25342547
}
25352548

25362549
static bool amd_iommu_hd_support(struct amd_iommu *iommu)

0 commit comments

Comments
 (0)