Skip to content

Commit 2021eb0

Browse files
KAGA-KOKOsmb49
authored andcommitted
PCI/MSI: Enable and mask MSI-X early
BugLink: https://bugs.launchpad.net/bugs/1944202 commit 4385539 upstream. The ordering of MSI-X enable in hardware is dysfunctional: 1) MSI-X is disabled in the control register 2) Various setup functions 3) pci_msi_setup_msi_irqs() is invoked which ends up accessing the MSI-X table entries 4) MSI-X is enabled and masked in the control register with the comment that enabling is required for some hardware to access the MSI-X table Step #4 obviously contradicts #3. The history of this is an issue with the NIU hardware. When #4 was introduced the table access actually happened in msix_program_entries() which was invoked after enabling and masking MSI-X. This was changed in commit d71d643 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") which removed the table write from msix_program_entries(). Interestingly enough nobody noticed and either NIU still works or it did not get any testing with a kernel 3.19 or later. Nevertheless this is inconsistent and there is no reason why MSI-X can't be enabled and masked in the control register early on, i.e. move step #4 above to step #1. This preserves the NIU workaround and has no side effects on other hardware. Fixes: d71d643 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Ashok Raj <ashok.raj@intel.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210729222542.344136412@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent 0bf6932 commit 2021eb0

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

drivers/pci/msi.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -778,18 +778,25 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
778778
u16 control;
779779
void __iomem *base;
780780

781-
/* Ensure MSI-X is disabled while it is set up */
782-
pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
781+
/*
782+
* Some devices require MSI-X to be enabled before the MSI-X
783+
* registers can be accessed. Mask all the vectors to prevent
784+
* interrupts coming in before they're fully set up.
785+
*/
786+
pci_msix_clear_and_set_ctrl(dev, 0, PCI_MSIX_FLAGS_MASKALL |
787+
PCI_MSIX_FLAGS_ENABLE);
783788

784789
pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
785790
/* Request & Map MSI-X table region */
786791
base = msix_map_region(dev, msix_table_size(control));
787-
if (!base)
788-
return -ENOMEM;
792+
if (!base) {
793+
ret = -ENOMEM;
794+
goto out_disable;
795+
}
789796

790797
ret = msix_setup_entries(dev, base, entries, nvec, affd);
791798
if (ret)
792-
return ret;
799+
goto out_disable;
793800

794801
ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
795802
if (ret)
@@ -800,14 +807,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
800807
if (ret)
801808
goto out_free;
802809

803-
/*
804-
* Some devices require MSI-X to be enabled before we can touch the
805-
* MSI-X registers. We need to mask all the vectors to prevent
806-
* interrupts coming in before they're fully set up.
807-
*/
808-
pci_msix_clear_and_set_ctrl(dev, 0,
809-
PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE);
810-
811810
msix_program_entries(dev, entries);
812811

813812
ret = populate_msi_sysfs(dev);
@@ -842,6 +841,9 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
842841
out_free:
843842
free_msi_irqs(dev);
844843

844+
out_disable:
845+
pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
846+
845847
return ret;
846848
}
847849

0 commit comments

Comments
 (0)