Skip to content

Commit 7e90e81

Browse files
KAGA-KOKOgregkh
authored andcommitted
PCI/MSI: Enable and mask MSI-X early
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>
1 parent 2d2c668 commit 7e90e81

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/pci/msi.c

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

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

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

791798
ret = msix_setup_entries(dev, base, entries, nvec, affd);
792799
if (ret)
793-
return ret;
800+
goto out_disable;
794801

795802
ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
796803
if (ret)
@@ -801,14 +808,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
801808
if (ret)
802809
goto out_free;
803810

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

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

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

0 commit comments

Comments
 (0)