The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5
@ 2025-02-28 10:27 Lu Baolu
  2025-02-28 10:27 ` [PATCH 1/2] iommu/vt-d: Remove device comparison in context_setup_pass_through_cb Lu Baolu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lu Baolu @ 2025-02-28 10:27 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Jerry Snitselaar, iommu, linux-kernel

Hi Joerg,

The following fixes have been queued for v6.14-rc:

- Fix suspicious RCU usage splat
- Fix passthrough for devices under PCIe-PCI bridge

They have been reviewed and tested. Can you please take them?

Best regards,
baolu

Jerry Snitselaar (1):
  iommu/vt-d: Remove device comparison in context_setup_pass_through_cb

Lu Baolu (1):
  iommu/vt-d: Fix suspicious RCU usage

 drivers/iommu/intel/dmar.c  |  1 +
 drivers/iommu/intel/iommu.c | 10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] iommu/vt-d: Remove device comparison in context_setup_pass_through_cb
  2025-02-28 10:27 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Lu Baolu
@ 2025-02-28 10:27 ` Lu Baolu
  2025-02-28 10:27 ` [PATCH 2/2] iommu/vt-d: Fix suspicious RCU usage Lu Baolu
  2025-02-28 11:19 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Lu Baolu @ 2025-02-28 10:27 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Jerry Snitselaar, iommu, linux-kernel

From: Jerry Snitselaar <jsnitsel@redhat.com>

Remove the device comparison check in context_setup_pass_through_cb.
pci_for_each_dma_alias already makes a decision on whether the
callback function should be called for a device. With the check
in place it will fail to create context entries for aliases as
it walks up to the root bus.

Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
Closes: https://lore.kernel.org/linux-iommu/82499eb6-00b7-4f83-879a-e97b4144f576@linux.intel.com/
Cc: stable@vger.kernel.org
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
Link: https://lore.kernel.org/r/20250224180316.140123-1-jsnitsel@redhat.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index cc46098f875b..4d8d4593c9c8 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4378,9 +4378,6 @@ static int context_setup_pass_through_cb(struct pci_dev *pdev, u16 alias, void *
 {
 	struct device *dev = data;
 
-	if (dev != &pdev->dev)
-		return 0;
-
 	return context_setup_pass_through(dev, PCI_BUS_NUM(alias), alias & 0xff);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] iommu/vt-d: Fix suspicious RCU usage
  2025-02-28 10:27 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Lu Baolu
  2025-02-28 10:27 ` [PATCH 1/2] iommu/vt-d: Remove device comparison in context_setup_pass_through_cb Lu Baolu
@ 2025-02-28 10:27 ` Lu Baolu
  2025-02-28 11:19 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Lu Baolu @ 2025-02-28 10:27 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Jerry Snitselaar, iommu, linux-kernel

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: d74169ceb0d2 ("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
---
 drivers/iommu/intel/dmar.c  | 1 +
 drivers/iommu/intel/iommu.c | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 9f424acf474e..e540092d664d 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -2043,6 +2043,7 @@ int enable_drhd_fault_handling(unsigned int cpu)
 	/*
 	 * Enable fault control interrupt.
 	 */
+	guard(rwsem_read)(&dmar_global_lock);
 	for_each_iommu(iommu, drhd) {
 		u32 fault_status;
 		int ret;
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 4d8d4593c9c8..bf1f0c814348 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3146,7 +3146,14 @@ int __init intel_iommu_init(void)
 		iommu_device_sysfs_add(&iommu->iommu, NULL,
 				       intel_iommu_groups,
 				       "%s", iommu->name);
+		/*
+		 * The iommu device probe is protected by the iommu_probe_device_lock.
+		 * Release the dmar_global_lock before entering the device probe path
+		 * to avoid unnecessary lock order splat.
+		 */
+		up_read(&dmar_global_lock);
 		iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL);
+		down_read(&dmar_global_lock);
 
 		iommu_pmu_register(iommu);
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5
  2025-02-28 10:27 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Lu Baolu
  2025-02-28 10:27 ` [PATCH 1/2] iommu/vt-d: Remove device comparison in context_setup_pass_through_cb Lu Baolu
  2025-02-28 10:27 ` [PATCH 2/2] iommu/vt-d: Fix suspicious RCU usage Lu Baolu
@ 2025-02-28 11:19 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2025-02-28 11:19 UTC (permalink / raw)
  To: Lu Baolu; +Cc: Jerry Snitselaar, iommu, linux-kernel

On Fri, Feb 28, 2025 at 06:27:24PM +0800, Lu Baolu wrote:
> Hi Joerg,
> 
> The following fixes have been queued for v6.14-rc:
> 
> - Fix suspicious RCU usage splat
> - Fix passthrough for devices under PCIe-PCI bridge
> 
> They have been reviewed and tested. Can you please take them?
> 
> Best regards,
> baolu
> 
> Jerry Snitselaar (1):
>   iommu/vt-d: Remove device comparison in context_setup_pass_through_cb
> 
> Lu Baolu (1):
>   iommu/vt-d: Fix suspicious RCU usage
> 
>  drivers/iommu/intel/dmar.c  |  1 +
>  drivers/iommu/intel/iommu.c | 10 +++++++---
>  2 files changed, 8 insertions(+), 3 deletions(-)

Applied, thanks Baolu.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-28 11:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 10:27 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Lu Baolu
2025-02-28 10:27 ` [PATCH 1/2] iommu/vt-d: Remove device comparison in context_setup_pass_through_cb Lu Baolu
2025-02-28 10:27 ` [PATCH 2/2] iommu/vt-d: Fix suspicious RCU usage Lu Baolu
2025-02-28 11:19 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.14-rc5 Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox