On Fri, Nov 18 2022 at 10:15, Thomas Gleixner wrote: > On Fri, Nov 18 2022 at 01:58, Thomas Gleixner wrote: > Of course I "tested" this by flipping default and secondary domain > around and doing dynamic allocations from PCI/MSI-X but that won't catch > the bug because PCI/MSI-X does not have the ALLOC_SIMPLE_DESCS flag set. > > Let me fix that. Delta patch against git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v1G-part3 below. Thanks, tglx --- diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index d4f26649a185..d243ad3e5489 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -141,7 +141,7 @@ static int msi_insert_desc(struct device *dev, struct msi_desc *desc, if (ret) goto fail; - desc->msi_index = index; + desc->msi_index = index - baseidx; return 0; } else { if (index >= hwsize) { @@ -1476,9 +1476,10 @@ struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, u const struct irq_affinity_desc *affdesc, union msi_dev_cookie *cookie) { + struct msi_ctrl ctrl = { .domid = domid, .nirqs = 1, }; + struct msi_domain_info *info; struct irq_domain *domain; struct msi_map map = { }; - struct msi_desc *desc; int ret; msi_lock_descs(dev); @@ -1503,12 +1504,16 @@ struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, u goto unlock; } - map.index = desc->msi_index; - ret = msi_domain_alloc_irqs_range_locked(dev, domid, map.index, map.index); - if (ret) + ctrl.first = ctrl.last = desc->msi_index; + info = domain->host_data; + + ret = __msi_domain_alloc_irqs(dev, domain, &ctrl); + if (ret) { map.index = ret; - else + msi_domain_free_locked(dev, &ctrl); + } else { map.virq = desc->irq; + } unlock: msi_unlock_descs(dev); return map;