From 618cb8f298c1e0de7fd03081f8d32125fee7f603 Mon Sep 17 00:00:00 2001 From: Jiakun Shuai Date: Tue, 17 Jun 2025 16:51:38 +0800 Subject: [PATCH] PCI/MSI: Set device flag indicating only 32-bit MSI support ANBZ: #7077 commit 2053230af11dc651ee3024682df12668496adad2 upstream The MSI-X Capability requires devices to support 64-bit Message Addresses, but the MSI Capability can support either 32- or 64-bit addresses. Previously, we set dev->no_64bit_msi for a few broken devices that advertise 64-bit MSI support but don't correctly support it. In addition, check the MSI "64-bit Address Capable" bit for all devices and set dev->no_64bit_msi for devices that don't advertise 64-bit support. This allows msi_verify_entries() to catch arch code defects that assign 64-bit addresses when they're not supported. The warning is helpful to find defects like the one fixed by https://lore.kernel.org/r/20201117165312.25847-1-vidyas@nvidia.com [bhelgaas: set no_64bit_msi in pci_msi_init(), commit log] Link: https://lore.kernel.org/r/20201124105035.24573-1-vidyas@nvidia.com Link: https://lore.kernel.org/r/20201203185110.1583077-4-helgaas@kernel.org Signed-off-by: Vidya Sagar Signed-off-by: Bjorn Helgaas Reviewed-by: Thierry Reding Signed-off-by: Wang Yinfeng Signed-off-by: Jiakun Shuai --- drivers/pci/msi.c | 8 ++++---- drivers/pci/probe.c | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 194af6517eb1..c9739a4480ef 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -559,11 +559,11 @@ static int msi_verify_entries(struct pci_dev *dev) struct msi_desc *entry; for_each_new_pci_msi_entry(entry, dev) { - if (!dev->no_64bit_msi || !entry->msg.address_hi) - continue; - pci_err(dev, "Device has broken 64-bit MSI but arch" - " tried to assign one above 4G\n"); + if (entry->msg.address_hi && dev->no_64bit_msi) { + pci_err(dev, "arch assigned 64-bit MSI address %#x%08x but device only supports 32 bits\n", + entry->msg.address_hi, entry->msg.address_lo); return -EIO; + } } return 0; } diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 576fd48a1a31..645d97ed9020 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1722,6 +1722,8 @@ static u8 pci_hdr_type(struct pci_dev *dev) static void pci_msi_setup_pci_dev(struct pci_dev *dev) { + u16 ctrl; + /* * Disable the MSI hardware to avoid screaming interrupts * during boot. This is the power on reset default so @@ -1731,6 +1733,10 @@ static void pci_msi_setup_pci_dev(struct pci_dev *dev) if (dev->msi_cap) pci_msi_set_enable(dev, 0); + pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &ctrl); + if (!(ctrl & PCI_MSI_FLAGS_64BIT)) + dev->no_64bit_msi = 1; + dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX); if (dev->msix_cap) pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); -- Gitee