Skip to content

Commit df32e96

Browse files
LuBaolumoodyhunter
authored andcommitted
iommu/vt-d: Remove unnecessary locking in intel_irq_remapping_alloc()
The global rwsem dmar_global_lock was introduced by commit 3a5670e ("iommu/vt-d: Introduce a rwsem to protect global data structures"). It is used to protect DMAR related global data from DMAR hotplug operations. Using dmar_global_lock in intel_irq_remapping_alloc() is unnecessary as the DMAR global data structures are not touched there. Remove it to avoid below lockdep warning. ====================================================== WARNING: possible circular locking dependency detected 6.3.0-rc2 torvalds#468 Not tainted ------------------------------------------------------ swapper/0/1 is trying to acquire lock: ff1db4cb40178698 (&domain->mutex){+.+.}-{3:3}, at: __irq_domain_alloc_irqs+0x3b/0xa0 but task is already holding lock: ffffffffa0c1cdf0 (dmar_global_lock){++++}-{3:3}, at: intel_iommu_init+0x58e/0x880 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (dmar_global_lock){++++}-{3:3}: lock_acquire+0xd6/0x320 down_read+0x42/0x180 intel_irq_remapping_alloc+0xad/0x750 mp_irqdomain_alloc+0xb8/0x2b0 irq_domain_alloc_irqs_locked+0x12f/0x2d0 __irq_domain_alloc_irqs+0x56/0xa0 alloc_isa_irq_from_domain.isra.7+0xa0/0xe0 mp_map_pin_to_irq+0x1dc/0x330 setup_IO_APIC+0x128/0x210 apic_intr_mode_init+0x67/0x110 x86_late_time_init+0x24/0x40 start_kernel+0x41e/0x7e0 secondary_startup_64_no_verify+0xe0/0xeb -> #0 (&domain->mutex){+.+.}-{3:3}: check_prevs_add+0x160/0xef0 __lock_acquire+0x147d/0x1950 lock_acquire+0xd6/0x320 __mutex_lock+0x9c/0xfc0 __irq_domain_alloc_irqs+0x3b/0xa0 dmar_alloc_hwirq+0x9e/0x120 iommu_pmu_register+0x11d/0x200 intel_iommu_init+0x5de/0x880 pci_iommu_init+0x12/0x40 do_one_initcall+0x65/0x350 kernel_init_freeable+0x3ca/0x610 kernel_init+0x1a/0x140 ret_from_fork+0x29/0x50 other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(dmar_global_lock); lock(&domain->mutex); lock(dmar_global_lock); lock(&domain->mutex); *** DEADLOCK *** Fixes: 9dbb8e3 ("irqdomain: Switch to per-domain locking") Reviewed-by: Jacob Pan <[email protected]> Tested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ab95b32 commit df32e96

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

drivers/iommu/intel/irq_remapping.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,12 @@ static int set_ioapic_sid(struct irte *irte, int apic)
311311
if (!irte)
312312
return -1;
313313

314-
down_read(&dmar_global_lock);
315314
for (i = 0; i < MAX_IO_APICS; i++) {
316315
if (ir_ioapic[i].iommu && ir_ioapic[i].id == apic) {
317316
sid = (ir_ioapic[i].bus << 8) | ir_ioapic[i].devfn;
318317
break;
319318
}
320319
}
321-
up_read(&dmar_global_lock);
322320

323321
if (sid == 0) {
324322
pr_warn("Failed to set source-id of IOAPIC (%d)\n", apic);
@@ -338,14 +336,12 @@ static int set_hpet_sid(struct irte *irte, u8 id)
338336
if (!irte)
339337
return -1;
340338

341-
down_read(&dmar_global_lock);
342339
for (i = 0; i < MAX_HPET_TBS; i++) {
343340
if (ir_hpet[i].iommu && ir_hpet[i].id == id) {
344341
sid = (ir_hpet[i].bus << 8) | ir_hpet[i].devfn;
345342
break;
346343
}
347344
}
348-
up_read(&dmar_global_lock);
349345

350346
if (sid == 0) {
351347
pr_warn("Failed to set source-id of HPET block (%d)\n", id);
@@ -1339,9 +1335,7 @@ static int intel_irq_remapping_alloc(struct irq_domain *domain,
13391335
if (!data)
13401336
goto out_free_parent;
13411337

1342-
down_read(&dmar_global_lock);
13431338
index = alloc_irte(iommu, &data->irq_2_iommu, nr_irqs);
1344-
up_read(&dmar_global_lock);
13451339
if (index < 0) {
13461340
pr_warn("Failed to allocate IRTE\n");
13471341
kfree(data);

0 commit comments

Comments
 (0)