Skip to content

Commit d2a463b

Browse files
committed
PCI/MSI: Reject multi-MSI early
When hierarchical MSI interrupt domains are enabled then there is no point to do tons of work and detect the missing support for multi-MSI late in the allocation path. Just query the domain feature flags right away. The query function is going to be used for other purposes later and has a mode argument which influences the result: ALLOW_LEGACY returns true when: - there is no irq domain attached (legacy support) - there is a irq domain attached which has the feature flag set DENY_LEGACY returns only true when: - there is a irq domain attached which has the feature flag set This allows to use the function universally without ifdeffery in the calling code. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bab65e4 commit d2a463b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

drivers/pci/msi/irqdomain.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
187187
}
188188
EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain);
189189

190+
/**
191+
* pci_msi_domain_supports - Check for support of a particular feature flag
192+
* @pdev: The PCI device to operate on
193+
* @feature_mask: The feature mask to check for (full match)
194+
* @mode: If ALLOW_LEGACY this grants the feature when there is no irq domain
195+
* associated to the device. If DENY_LEGACY the lack of an irq domain
196+
* makes the feature unsupported
197+
*/
198+
bool pci_msi_domain_supports(struct pci_dev *pdev, unsigned int feature_mask,
199+
enum support_mode mode)
200+
{
201+
struct msi_domain_info *info;
202+
struct irq_domain *domain;
203+
204+
domain = dev_get_msi_domain(&pdev->dev);
205+
206+
if (!domain || !irq_domain_is_hierarchy(domain))
207+
return mode == ALLOW_LEGACY;
208+
info = domain->host_data;
209+
return (info->flags & feature_mask) == feature_mask;
210+
}
211+
190212
/*
191213
* Users of the generic MSI infrastructure expect a device to have a single ID,
192214
* so with DMA aliases we have to pick the least-worst compromise. Devices with

drivers/pci/msi/msi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
347347
struct msi_desc *entry;
348348
int ret;
349349

350+
/* Reject multi-MSI early on irq domain enabled architectures */
351+
if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY))
352+
return 1;
353+
350354
/*
351355
* Disable MSI during setup in the hardware, but mark it enabled
352356
* so that setup code can evaluate it.

drivers/pci/msi/msi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int
9797
void __pci_restore_msi_state(struct pci_dev *dev);
9898
void __pci_restore_msix_state(struct pci_dev *dev);
9999

100+
/* irq_domain related functionality */
101+
102+
enum support_mode {
103+
ALLOW_LEGACY,
104+
DENY_LEGACY,
105+
};
106+
107+
bool pci_msi_domain_supports(struct pci_dev *dev, unsigned int feature_mask, enum support_mode mode);
108+
100109
/* Legacy (!IRQDOMAIN) fallbacks */
101110

102111
#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS

0 commit comments

Comments
 (0)