Skip to content

Commit ba1366f

Browse files
committed
PCI: vmd: Prevent recursive locking on interrupt allocation
Tejas reported the following recursive locking issue: swapper/0/1 is trying to acquire lock: ffff8881074fd0a0 (&md->mutex){+.+.}-{3:3}, at: msi_get_virq+0x30/0xc0 but task is already holding lock: ffff8881017cd6a0 (&md->mutex){+.+.}-{3:3}, at: __pci_enable_msi_range+0xf2/0x290 stack backtrace: __mutex_lock+0x9d/0x920 msi_get_virq+0x30/0xc0 pci_irq_vector+0x26/0x30 vmd_msi_init+0xcc/0x210 msi_domain_alloc+0xbf/0x150 msi_domain_alloc_irqs_descs_locked+0x3e/0xb0 __pci_enable_msi_range+0x155/0x290 pci_alloc_irq_vectors_affinity+0xba/0x100 pcie_port_device_register+0x307/0x550 pcie_portdrv_probe+0x3c/0xd0 pci_device_probe+0x95/0x110 This is caused by the VMD MSI code which does a lookup of the Linux interrupt number for an VMD managed MSI[X] vector. The lookup function tries to acquire the already held mutex. Avoid that by caching the Linux interrupt number at initialization time instead of looking it up over and over. Fixes: 82ff8e6 ("PCI/MSI: Use msi_get_virq() in pci_get_vector()") Reported-by: "Surendrakumar Upadhyay, TejaskumarX" <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: "Surendrakumar Upadhyay, TejaskumarX" <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/87a6euub2a.ffs@tglx
1 parent cfb9244 commit ba1366f

File tree

1 file changed

+7
-7
lines changed
  • drivers/pci/controller

1 file changed

+7
-7
lines changed

drivers/pci/controller/vmd.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ struct vmd_irq {
9999
* @srcu: SRCU struct for local synchronization.
100100
* @count: number of child IRQs assigned to this vector; used to track
101101
* sharing.
102+
* @virq: The underlying VMD Linux interrupt number
102103
*/
103104
struct vmd_irq_list {
104105
struct list_head irq_list;
105106
struct srcu_struct srcu;
106107
unsigned int count;
108+
unsigned int virq;
107109
};
108110

109111
struct vmd_dev {
@@ -253,18 +255,15 @@ static int vmd_msi_init(struct irq_domain *domain, struct msi_domain_info *info,
253255
struct msi_desc *desc = arg->desc;
254256
struct vmd_dev *vmd = vmd_from_bus(msi_desc_to_pci_dev(desc)->bus);
255257
struct vmd_irq *vmdirq = kzalloc(sizeof(*vmdirq), GFP_KERNEL);
256-
unsigned int index, vector;
257258

258259
if (!vmdirq)
259260
return -ENOMEM;
260261

261262
INIT_LIST_HEAD(&vmdirq->node);
262263
vmdirq->irq = vmd_next_irq(vmd, desc);
263264
vmdirq->virq = virq;
264-
index = index_from_irqs(vmd, vmdirq->irq);
265-
vector = pci_irq_vector(vmd->dev, index);
266265

267-
irq_domain_set_info(domain, virq, vector, info->chip, vmdirq,
266+
irq_domain_set_info(domain, virq, vmdirq->irq->virq, info->chip, vmdirq,
268267
handle_untracked_irq, vmd, NULL);
269268
return 0;
270269
}
@@ -685,7 +684,8 @@ static int vmd_alloc_irqs(struct vmd_dev *vmd)
685684
return err;
686685

687686
INIT_LIST_HEAD(&vmd->irqs[i].irq_list);
688-
err = devm_request_irq(&dev->dev, pci_irq_vector(dev, i),
687+
vmd->irqs[i].virq = pci_irq_vector(dev, i);
688+
err = devm_request_irq(&dev->dev, vmd->irqs[i].virq,
689689
vmd_irq, IRQF_NO_THREAD,
690690
vmd->name, &vmd->irqs[i]);
691691
if (err)
@@ -969,7 +969,7 @@ static int vmd_suspend(struct device *dev)
969969
int i;
970970

971971
for (i = 0; i < vmd->msix_count; i++)
972-
devm_free_irq(dev, pci_irq_vector(pdev, i), &vmd->irqs[i]);
972+
devm_free_irq(dev, vmd->irqs[i].virq, &vmd->irqs[i]);
973973

974974
return 0;
975975
}
@@ -981,7 +981,7 @@ static int vmd_resume(struct device *dev)
981981
int err, i;
982982

983983
for (i = 0; i < vmd->msix_count; i++) {
984-
err = devm_request_irq(dev, pci_irq_vector(pdev, i),
984+
err = devm_request_irq(dev, vmd->irqs[i].virq,
985985
vmd_irq, IRQF_NO_THREAD,
986986
vmd->name, &vmd->irqs[i]);
987987
if (err)

0 commit comments

Comments
 (0)