Merge tag 'irq-urgent-2021-11-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull irq fixes from Thomas Gleixner:
"A set of fixes for the interrupt subsystem

Core code:

- A regression fix for the Open Firmware interrupt mapping code where
a interrupt controller property in a node caused a map property in
the same node to be ignored.

Interrupt chip drivers:

- Workaround a limitation in SiFive PLIC interrupt chip which
silently ignores an EOI when the interrupt line is masked.

- Provide the missing mask/unmask implementation for the CSKY MP
interrupt controller.

PCI/MSI:

- Prevent a use after free when PCI/MSI interrupts are released by
destroying the sysfs entries before freeing the memory which is
accessed in the sysfs show() function.

- Implement a mask quirk for the Nvidia ION AHCI chip which does not
advertise masking capability despite implementing it. Even worse
the chip comes out of reset with all MSI entries masked, which due
to the missing masking capability never get unmasked.

- Move the check which prevents accessing the MSI[X] masking for XEN
back into the low level accessors. The recent consolidation missed
that these accessors can be invoked from places which do not have
that check which broke XEN. Move them back to he original place
instead of sprinkling tons of these checks all over the code"

* tag 'irq-urgent-2021-11-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
of/irq: Don't ignore interrupt-controller when interrupt-map failed
irqchip/sifive-plic: Fixup EOI failed when masked
irqchip/csky-mpintc: Fixup mask/unmask implementation
PCI/MSI: Destroy sysfs before freeing entries
PCI: Add MSI masking quirk for Nvidia ION AHCI
PCI/MSI: Deal with devices lying about their MSI mask capability
PCI/MSI: Move non-mask check back into low level accessors

+60 -28
+4 -4
drivers/irqchip/irq-csky-mpintc.c
··· 78 78 readl_relaxed(reg_base + INTCL_RDYIR)); 79 79 } 80 80 81 - static void csky_mpintc_enable(struct irq_data *d) 81 + static void csky_mpintc_unmask(struct irq_data *d) 82 82 { 83 83 void __iomem *reg_base = this_cpu_read(intcl_reg); 84 84 ··· 87 87 writel_relaxed(d->hwirq, reg_base + INTCL_SENR); 88 88 } 89 89 90 - static void csky_mpintc_disable(struct irq_data *d) 90 + static void csky_mpintc_mask(struct irq_data *d) 91 91 { 92 92 void __iomem *reg_base = this_cpu_read(intcl_reg); 93 93 ··· 164 164 static struct irq_chip csky_irq_chip = { 165 165 .name = "C-SKY SMP Intc", 166 166 .irq_eoi = csky_mpintc_eoi, 167 - .irq_enable = csky_mpintc_enable, 168 - .irq_disable = csky_mpintc_disable, 167 + .irq_unmask = csky_mpintc_unmask, 168 + .irq_mask = csky_mpintc_mask, 169 169 .irq_set_type = csky_mpintc_set_type, 170 170 #ifdef CONFIG_SMP 171 171 .irq_set_affinity = csky_irq_set_affinity,
+7 -1
drivers/irqchip/irq-sifive-plic.c
··· 163 163 { 164 164 struct plic_handler *handler = this_cpu_ptr(&plic_handlers); 165 165 166 - writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); 166 + if (irqd_irq_masked(d)) { 167 + plic_irq_unmask(d); 168 + writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); 169 + plic_irq_mask(d); 170 + } else { 171 + writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); 172 + } 167 173 } 168 174 169 175 static struct irq_chip plic_chip = {
+16 -3
drivers/of/irq.c
··· 161 161 * if it is then we are done, unless there is an 162 162 * interrupt-map which takes precedence. 163 163 */ 164 + bool intc = of_property_read_bool(ipar, "interrupt-controller"); 165 + 164 166 imap = of_get_property(ipar, "interrupt-map", &imaplen); 165 - if (imap == NULL && 166 - of_property_read_bool(ipar, "interrupt-controller")) { 167 + if (imap == NULL && intc) { 167 168 pr_debug(" -> got it !\n"); 168 169 return 0; 169 170 } ··· 245 244 246 245 pr_debug(" -> imaplen=%d\n", imaplen); 247 246 } 248 - if (!match) 247 + if (!match) { 248 + if (intc) { 249 + /* 250 + * The PASEMI Nemo is a known offender, so 251 + * let's only warn for anyone else. 252 + */ 253 + WARN(!IS_ENABLED(CONFIG_PPC_PASEMI), 254 + "%pOF interrupt-map failed, using interrupt-controller\n", 255 + ipar); 256 + return 0; 257 + } 258 + 249 259 goto fail; 260 + } 250 261 251 262 /* 252 263 * Successfully parsed an interrrupt-map translation; copy new
+22 -17
drivers/pci/msi.c
··· 148 148 raw_spinlock_t *lock = &desc->dev->msi_lock; 149 149 unsigned long flags; 150 150 151 + if (!desc->msi_attrib.can_mask) 152 + return; 153 + 151 154 raw_spin_lock_irqsave(lock, flags); 152 155 desc->msi_mask &= ~clear; 153 156 desc->msi_mask |= set; ··· 184 181 { 185 182 void __iomem *desc_addr = pci_msix_desc_addr(desc); 186 183 187 - writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); 184 + if (desc->msi_attrib.can_mask) 185 + writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); 188 186 } 189 187 190 188 static inline void pci_msix_mask(struct msi_desc *desc) ··· 204 200 205 201 static void __pci_msi_mask_desc(struct msi_desc *desc, u32 mask) 206 202 { 207 - if (pci_msi_ignore_mask || desc->msi_attrib.is_virtual) 208 - return; 209 - 210 203 if (desc->msi_attrib.is_msix) 211 204 pci_msix_mask(desc); 212 - else if (desc->msi_attrib.maskbit) 205 + else 213 206 pci_msi_mask(desc, mask); 214 207 } 215 208 216 209 static void __pci_msi_unmask_desc(struct msi_desc *desc, u32 mask) 217 210 { 218 - if (pci_msi_ignore_mask || desc->msi_attrib.is_virtual) 219 - return; 220 - 221 211 if (desc->msi_attrib.is_msix) 222 212 pci_msix_unmask(desc); 223 - else if (desc->msi_attrib.maskbit) 213 + else 224 214 pci_msi_unmask(desc, mask); 225 215 } 226 216 ··· 368 370 for (i = 0; i < entry->nvec_used; i++) 369 371 BUG_ON(irq_has_action(entry->irq + i)); 370 372 373 + if (dev->msi_irq_groups) { 374 + msi_destroy_sysfs(&dev->dev, dev->msi_irq_groups); 375 + dev->msi_irq_groups = NULL; 376 + } 377 + 371 378 pci_msi_teardown_msi_irqs(dev); 372 379 373 380 list_for_each_entry_safe(entry, tmp, msi_list, list) { ··· 383 380 384 381 list_del(&entry->list); 385 382 free_msi_entry(entry); 386 - } 387 - 388 - if (dev->msi_irq_groups) { 389 - msi_destroy_sysfs(&dev->dev, dev->msi_irq_groups); 390 - dev->msi_irq_groups = NULL; 391 383 } 392 384 } 393 385 ··· 477 479 goto out; 478 480 479 481 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); 482 + /* Lies, damned lies, and MSIs */ 483 + if (dev->dev_flags & PCI_DEV_FLAGS_HAS_MSI_MASKING) 484 + control |= PCI_MSI_FLAGS_MASKBIT; 480 485 481 486 entry->msi_attrib.is_msix = 0; 482 487 entry->msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT); 483 488 entry->msi_attrib.is_virtual = 0; 484 489 entry->msi_attrib.entry_nr = 0; 485 - entry->msi_attrib.maskbit = !!(control & PCI_MSI_FLAGS_MASKBIT); 490 + entry->msi_attrib.can_mask = !pci_msi_ignore_mask && 491 + !!(control & PCI_MSI_FLAGS_MASKBIT); 486 492 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 487 493 entry->msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1; 488 494 entry->msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec)); ··· 497 495 entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_32; 498 496 499 497 /* Save the initial mask status */ 500 - if (entry->msi_attrib.maskbit) 498 + if (entry->msi_attrib.can_mask) 501 499 pci_read_config_dword(dev, entry->mask_pos, &entry->msi_mask); 502 500 503 501 out: ··· 641 639 entry->msi_attrib.is_virtual = 642 640 entry->msi_attrib.entry_nr >= vec_count; 643 641 642 + entry->msi_attrib.can_mask = !pci_msi_ignore_mask && 643 + !entry->msi_attrib.is_virtual; 644 + 644 645 entry->msi_attrib.default_irq = dev->irq; 645 646 entry->mask_base = base; 646 647 647 - if (!entry->msi_attrib.is_virtual) { 648 + if (entry->msi_attrib.can_mask) { 648 649 addr = pci_msix_desc_addr(entry); 649 650 entry->msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL); 650 651 }
+6
drivers/pci/quirks.c
··· 5851 5851 pci_fixup_pericom_acs_store_forward); 5852 5852 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2303, 5853 5853 pci_fixup_pericom_acs_store_forward); 5854 + 5855 + static void nvidia_ion_ahci_fixup(struct pci_dev *pdev) 5856 + { 5857 + pdev->dev_flags |= PCI_DEV_FLAGS_HAS_MSI_MASKING; 5858 + } 5859 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0ab8, nvidia_ion_ahci_fixup);
+1 -1
include/linux/msi.h
··· 148 148 u8 is_msix : 1; 149 149 u8 multiple : 3; 150 150 u8 multi_cap : 3; 151 - u8 maskbit : 1; 151 + u8 can_mask : 1; 152 152 u8 is_64 : 1; 153 153 u8 is_virtual : 1; 154 154 u16 entry_nr;
+2
include/linux/pci.h
··· 233 233 PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 << 10), 234 234 /* Don't use Relaxed Ordering for TLPs directed at this device */ 235 235 PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 11), 236 + /* Device does honor MSI masking despite saying otherwise */ 237 + PCI_DEV_FLAGS_HAS_MSI_MASKING = (__force pci_dev_flags_t) (1 << 12), 236 238 }; 237 239 238 240 enum pci_irq_reroute_variant {
+2 -2
kernel/irq/msi.c
··· 529 529 530 530 /* 531 531 * Checking the first MSI descriptor is sufficient. MSIX supports 532 - * masking and MSI does so when the maskbit is set. 532 + * masking and MSI does so when the can_mask attribute is set. 533 533 */ 534 534 desc = first_msi_entry(dev); 535 - return desc->msi_attrib.is_msix || desc->msi_attrib.maskbit; 535 + return desc->msi_attrib.is_msix || desc->msi_attrib.can_mask; 536 536 } 537 537 538 538 int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,