Skip to content

Commit 9ce7603

Browse files
cuiyunhuijoergroedel
authored andcommitted
iommu/vt-d: Fix system hang on reboot -f
We found that executing the command ./a.out &;reboot -f (where a.out is a program that only executes a while(1) infinite loop) can probabilistically cause the system to hang in the intel_iommu_shutdown() function, rendering it unresponsive. Through analysis, we identified that the factors contributing to this issue are as follows: 1. The reboot -f command does not prompt the kernel to notify the application layer to perform cleanup actions, allowing the application to continue running. 2. When the kernel reaches the intel_iommu_shutdown() function, only the BSP (Bootstrap Processor) CPU is operational in the system. 3. During the execution of intel_iommu_shutdown(), the function down_write (&dmar_global_lock) causes the process to sleep and be scheduled out. 4. At this point, though the processor's interrupt flag is not cleared, allowing interrupts to be accepted. However, only legacy devices and NMI (Non-Maskable Interrupt) interrupts could come in, as other interrupts routing have already been disabled. If no legacy or NMI interrupts occur at this stage, the scheduler will not be able to run. 5. If the application got scheduled at this time is executing a while(1)- type loop, it will be unable to be preempted, leading to an infinite loop and causing the system to become unresponsive. To resolve this issue, the intel_iommu_shutdown() function should not execute down_write(), which can potentially cause the process to be scheduled out. Furthermore, since only the BSP is running during the later stages of the reboot, there is no need for protection against parallel access to the DMAR (DMA Remapping) unit. Therefore, the following lines could be removed: down_write(&dmar_global_lock); up_write(&dmar_global_lock); After testing, the issue has been resolved. Fixes: 6c3a44e ("iommu/vt-d: Turn off translations at shutdown") Co-developed-by: Ethan Zhao <[email protected]> Signed-off-by: Ethan Zhao <[email protected]> Signed-off-by: Yunhui Cui <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 0ad2507 commit 9ce7603

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,16 +2871,19 @@ void intel_iommu_shutdown(void)
28712871
if (no_iommu || dmar_disabled)
28722872
return;
28732873

2874-
down_write(&dmar_global_lock);
2874+
/*
2875+
* All other CPUs were brought down, hotplug interrupts were disabled,
2876+
* no lock and RCU checking needed anymore
2877+
*/
2878+
list_for_each_entry(drhd, &dmar_drhd_units, list) {
2879+
iommu = drhd->iommu;
28752880

2876-
/* Disable PMRs explicitly here. */
2877-
for_each_iommu(iommu, drhd)
2881+
/* Disable PMRs explicitly here. */
28782882
iommu_disable_protect_mem_regions(iommu);
28792883

2880-
/* Make sure the IOMMUs are switched off */
2881-
intel_disable_iommus();
2882-
2883-
up_write(&dmar_global_lock);
2884+
/* Make sure the IOMMUs are switched off */
2885+
iommu_disable_translation(iommu);
2886+
}
28842887
}
28852888

28862889
static struct intel_iommu *dev_to_intel_iommu(struct device *dev)

0 commit comments

Comments
 (0)