Skip to content

Commit c603ccb

Browse files
LuBaolugregkh
authored andcommitted
iommu/vt-d: Fix suspicious RCU usage
commit b150654 upstream. Commit <d74169ceb0d2> ("iommu/vt-d: Allocate DMAR fault interrupts locally") moved the call to enable_drhd_fault_handling() to a code path that does not hold any lock while traversing the drhd list. Fix it by ensuring the dmar_global_lock lock is held when traversing the drhd list. Without this fix, the following warning is triggered: ============================= WARNING: suspicious RCU usage 6.14.0-rc3 #55 Not tainted ----------------------------- drivers/iommu/intel/dmar.c:2046 RCU-list traversed in non-reader section!! other info that might help us debug this: rcu_scheduler_active = 1, debug_locks = 1 2 locks held by cpuhp/1/23: #0: ffffffff84a67c50 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x87/0x2c0 #1: ffffffff84a6a380 (cpuhp_state-up){+.+.}-{0:0}, at: cpuhp_thread_fun+0x87/0x2c0 stack backtrace: CPU: 1 UID: 0 PID: 23 Comm: cpuhp/1 Not tainted 6.14.0-rc3 #55 Call Trace: <TASK> dump_stack_lvl+0xb7/0xd0 lockdep_rcu_suspicious+0x159/0x1f0 ? __pfx_enable_drhd_fault_handling+0x10/0x10 enable_drhd_fault_handling+0x151/0x180 cpuhp_invoke_callback+0x1df/0x990 cpuhp_thread_fun+0x1ea/0x2c0 smpboot_thread_fn+0x1f5/0x2e0 ? __pfx_smpboot_thread_fn+0x10/0x10 kthread+0x12a/0x2d0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x4a/0x60 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Holding the lock in enable_drhd_fault_handling() triggers a lockdep splat about a possible deadlock between dmar_global_lock and cpu_hotplug_lock. This is avoided by not holding dmar_global_lock when calling iommu_device_register(), which initiates the device probe process. Fixes: d74169c ("iommu/vt-d: Allocate DMAR fault interrupts locally") Reported-and-tested-by: Ido Schimmel <[email protected]> Closes: https://lore.kernel.org/linux-iommu/[email protected]/ Tested-by: Breno Leitao <[email protected]> Cc: [email protected] Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Ido Schimmel <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 09143c9 commit c603ccb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

drivers/iommu/intel/dmar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ int enable_drhd_fault_handling(unsigned int cpu)
20432043
/*
20442044
* Enable fault control interrupt.
20452045
*/
2046+
guard(rwsem_read)(&dmar_global_lock);
20462047
for_each_iommu(iommu, drhd) {
20472048
u32 fault_status;
20482049
int ret;

drivers/iommu/intel/iommu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,14 @@ int __init intel_iommu_init(void)
31553155
iommu_device_sysfs_add(&iommu->iommu, NULL,
31563156
intel_iommu_groups,
31573157
"%s", iommu->name);
3158+
/*
3159+
* The iommu device probe is protected by the iommu_probe_device_lock.
3160+
* Release the dmar_global_lock before entering the device probe path
3161+
* to avoid unnecessary lock order splat.
3162+
*/
3163+
up_read(&dmar_global_lock);
31583164
iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL);
3165+
down_read(&dmar_global_lock);
31593166

31603167
iommu_pmu_register(iommu);
31613168
}

0 commit comments

Comments
 (0)