Skip to content

Commit c3811a5

Browse files
weihuang-amdjoergroedel
authored andcommitted
iommu/amd: Relocate GAMSup check to early_enable_iommus
Currently, iommu_init_ga() checks and disables IOMMU VAPIC support (i.e. AMD AVIC support in IOMMU) when GAMSup feature bit is not set. However it forgets to clear IRQ_POSTING_CAP from the previously set amd_iommu_irq_ops.capability. This triggers an invalid page fault bug during guest VM warm reboot if AVIC is enabled since the irq_remapping_cap(IRQ_POSTING_CAP) is incorrectly set, and crash the system with the following kernel trace. BUG: unable to handle page fault for address: 0000000000400dd8 RIP: 0010:amd_iommu_deactivate_guest_mode+0x19/0xbc Call Trace: svm_set_pi_irte_mode+0x8a/0xc0 [kvm_amd] ? kvm_make_all_cpus_request_except+0x50/0x70 [kvm] kvm_request_apicv_update+0x10c/0x150 [kvm] svm_toggle_avic_for_irq_window+0x52/0x90 [kvm_amd] svm_enable_irq_window+0x26/0xa0 [kvm_amd] vcpu_enter_guest+0xbbe/0x1560 [kvm] ? avic_vcpu_load+0xd5/0x120 [kvm_amd] ? kvm_arch_vcpu_load+0x76/0x240 [kvm] ? svm_get_segment_base+0xa/0x10 [kvm_amd] kvm_arch_vcpu_ioctl_run+0x103/0x590 [kvm] kvm_vcpu_ioctl+0x22a/0x5d0 [kvm] __x64_sys_ioctl+0x84/0xc0 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xae Fixes by moving the initializing of AMD IOMMU interrupt remapping mode (amd_iommu_guest_ir) earlier before setting up the amd_iommu_irq_ops.capability with appropriate IRQ_POSTING_CAP flag. [joro: Squashed the two patches and limited check_features_on_all_iommus() to CONFIG_IRQ_REMAP to fix a compile warning.] Signed-off-by: Wei Huang <[email protected]> Co-developed-by: Suravee Suthikulpanit <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Fixes: 8bda0cf ("iommu/amd: Detect and initialize guest vAPIC log") Signed-off-by: Joerg Roedel <[email protected]>
1 parent d8768d7 commit c3811a5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

drivers/iommu/amd/init.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,22 @@ int amd_iommu_get_num_iommus(void)
297297
return amd_iommus_present;
298298
}
299299

300+
#ifdef CONFIG_IRQ_REMAP
301+
static bool check_feature_on_all_iommus(u64 mask)
302+
{
303+
bool ret = false;
304+
struct amd_iommu *iommu;
305+
306+
for_each_iommu(iommu) {
307+
ret = iommu_feature(iommu, mask);
308+
if (!ret)
309+
return false;
310+
}
311+
312+
return true;
313+
}
314+
#endif
315+
300316
/*
301317
* For IVHD type 0x11/0x40, EFR is also available via IVHD.
302318
* Default to IVHD EFR since it is available sooner
@@ -853,13 +869,6 @@ static int iommu_init_ga(struct amd_iommu *iommu)
853869
int ret = 0;
854870

855871
#ifdef CONFIG_IRQ_REMAP
856-
/* Note: We have already checked GASup from IVRS table.
857-
* Now, we need to make sure that GAMSup is set.
858-
*/
859-
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
860-
!iommu_feature(iommu, FEATURE_GAM_VAPIC))
861-
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
862-
863872
ret = iommu_init_ga_log(iommu);
864873
#endif /* CONFIG_IRQ_REMAP */
865874

@@ -2479,6 +2488,14 @@ static void early_enable_iommus(void)
24792488
}
24802489

24812490
#ifdef CONFIG_IRQ_REMAP
2491+
/*
2492+
* Note: We have already checked GASup from IVRS table.
2493+
* Now, we need to make sure that GAMSup is set.
2494+
*/
2495+
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
2496+
!check_feature_on_all_iommus(FEATURE_GAM_VAPIC))
2497+
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
2498+
24822499
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
24832500
amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP);
24842501
#endif

0 commit comments

Comments
 (0)