@@ -153,6 +153,8 @@ bool amd_iommu_dump;
153153bool amd_iommu_irq_remap __read_mostly ;
154154
155155enum io_pgtable_fmt amd_iommu_pgtable = AMD_IOMMU_V1 ;
156+ /* Guest page table level */
157+ int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL ;
156158
157159int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC ;
158160static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE ;
@@ -306,6 +308,11 @@ static bool check_feature_on_all_iommus(u64 mask)
306308 return !!(amd_iommu_efr & mask );
307309}
308310
311+ static inline int check_feature_gpt_level (void )
312+ {
313+ return ((amd_iommu_efr >> FEATURE_GATS_SHIFT ) & FEATURE_GATS_MASK );
314+ }
315+
309316/*
310317 * For IVHD type 0x11/0x40, EFR is also available via IVHD.
311318 * Default to IVHD EFR since it is available sooner
@@ -2155,8 +2162,10 @@ static void print_iommu_info(void)
21552162 if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE )
21562163 pr_info ("X2APIC enabled\n" );
21572164 }
2158- if (amd_iommu_pgtable == AMD_IOMMU_V2 )
2159- pr_info ("V2 page table enabled\n" );
2165+ if (amd_iommu_pgtable == AMD_IOMMU_V2 ) {
2166+ pr_info ("V2 page table enabled (Paging mode : %d level)\n" ,
2167+ amd_iommu_gpt_level );
2168+ }
21602169}
21612170
21622171static int __init amd_iommu_init_pci (void )
@@ -3026,6 +3035,11 @@ static int __init early_amd_iommu_init(void)
30263035 if (ret )
30273036 goto out ;
30283037
3038+ /* 5 level guest page table */
3039+ if (cpu_feature_enabled (X86_FEATURE_LA57 ) &&
3040+ check_feature_gpt_level () == GUEST_PGTABLE_5_LEVEL )
3041+ amd_iommu_gpt_level = PAGE_MODE_5_LEVEL ;
3042+
30293043 /* Disable any previously enabled IOMMUs */
30303044 if (!is_kdump_kernel () || amd_iommu_disabled )
30313045 disable_iommus ();
@@ -3557,6 +3571,11 @@ __setup("ivrs_acpihid", parse_ivrs_acpihid);
35573571
35583572bool amd_iommu_v2_supported (void )
35593573{
3574+ /* CPU page table size should match IOMMU guest page table size */
3575+ if (cpu_feature_enabled (X86_FEATURE_LA57 ) &&
3576+ amd_iommu_gpt_level != PAGE_MODE_5_LEVEL )
3577+ return false;
3578+
35603579 /*
35613580 * Since DTE[Mode]=0 is prohibited on SNP-enabled system
35623581 * (i.e. EFR[SNPSup]=1), IOMMUv2 page table cannot be used without
0 commit comments