2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/drivers/iommu/intel
Lu Baolu b150654f74 iommu/vt-d: Fix suspicious RCU usage
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: d74169ceb0 ("iommu/vt-d: Allocate DMAR fault interrupts locally")
Reported-and-tested-by: Ido Schimmel <idosch@nvidia.com>
Closes: https://lore.kernel.org/linux-iommu/Zx9OwdLIc_VoQ0-a@shredder.mtl.com/
Tested-by: Breno Leitao <leitao@debian.org>
Cc: stable@vger.kernel.org
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20250218022422.2315082-1-baolu.lu@linux.intel.com
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2025-02-28 12:19:01 +01:00
..
cache.c iommu/vt-d: Link cache tags of same iommu unit together 2025-01-07 09:30:53 +01:00
debugfs.c iommu/vt-d: Remove debugfs use of private data field 2024-04-26 11:57:38 +02:00
dmar.c iommu/vt-d: Fix suspicious RCU usage 2025-02-28 12:19:01 +01:00
iommu.c iommu/vt-d: Fix suspicious RCU usage 2025-02-28 12:19:01 +01:00
iommu.h iommu: Add ops->domain_alloc_nested() 2024-11-22 14:43:45 -04:00
irq_remapping.c IOMMU Updates for Linux v6.14 2025-01-24 07:33:46 -08:00
Kconfig iommu/vt-d: Move IOMMU_IOPF into INTEL_IOMMU 2024-11-05 13:32:26 +01:00
Makefile iommu/vt-d: Remove iommu cap audit 2025-01-07 09:30:51 +01:00
nested.c iommu: Add ops->domain_alloc_nested() 2024-11-22 14:43:45 -04:00
pasid.c iommu/vt-d: Draining PRQ in sva unbind path when FPD bit set 2025-01-07 09:30:52 +01:00
pasid.h iommu/vt-d: Draining PRQ in sva unbind path when FPD bit set 2025-01-07 09:30:52 +01:00
perf.c iommu/vt-d: Use kcalloc() instead of kzalloc() 2024-03-01 13:51:18 +01:00
perf.h iommu/vt-d: Remove debugfs use of private data field 2024-04-26 11:57:38 +02:00
perfmon.c iommu/vt-d: Clean up cpumask and hotplug for perfmon 2024-09-10 11:44:13 +02:00
perfmon.h iommu/vt-d: Add IOMMU perfmon support 2023-02-03 11:06:06 +01:00
prq.c iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID 2025-02-14 09:12:47 +01:00
svm.c iommu/vt-d: Make intel_svm_set_dev_pasid() support domain replacement 2024-11-08 14:04:55 +01:00
trace.c iommu/vt-d: Move trace/events/intel_iommu.h under iommu 2022-07-15 10:21:28 +02:00
trace.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00