]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI/P2PDMA: Avoid returning a provider for non_mappable_bars
authorMatt Evans <mattev@meta.com>
Thu, 23 Apr 2026 17:30:51 +0000 (10:30 -0700)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 27 Apr 2026 14:47:24 +0000 (09:47 -0500)
Extend the checks in pcim_p2pdma_init() and pcim_p2pdma_provider() to
exclude functions that have pdev->non_mappable_bars set.

Consumers such as VFIO were previously able to map these for access by the
CPU or P2P.  Update the comment on non_mappable_bars to show it refers to
any access, not just userspace CPU access.

Fixes: 372d6d1b8ae3c ("PCI/P2PDMA: Refactor to separate core P2P functionality from memory allocation")
Suggested-by: Alex Williamson <alex@shazbot.org>
Signed-off-by: Matt Evans <mattev@meta.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Alex Williamson <alex@shazbot.org>
Link: https://patch.msgid.link/20260423173051.1999679-1-mattev@meta.com
drivers/pci/p2pdma.c
include/linux/pci.h

index 7c898542af8d5ea309e721709440445d160f7f3b..adb17a4f69396ecdee038802d773f4110dd3df12 100644 (file)
@@ -262,6 +262,9 @@ int pcim_p2pdma_init(struct pci_dev *pdev)
        struct pci_p2pdma *p2p;
        int i, ret;
 
+       if (pdev->non_mappable_bars)
+               return -EOPNOTSUPP;
+
        p2p = rcu_dereference_protected(pdev->p2pdma, 1);
        if (p2p)
                return 0;
@@ -318,7 +321,8 @@ struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar)
 {
        struct pci_p2pdma *p2p;
 
-       if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
+       if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM) ||
+           pdev->non_mappable_bars)
                return NULL;
 
        p2p = rcu_dereference_protected(pdev->p2pdma, 1);
index 2c4454583c115b016e011a847d678a0f5cda0699..1e6802017d6b8d20009183b3ed858f37fcd307d6 100644 (file)
@@ -508,7 +508,7 @@ struct pci_dev {
        unsigned int    no_command_memory:1;    /* No PCI_COMMAND_MEMORY */
        unsigned int    rom_bar_overlap:1;      /* ROM BAR disable broken */
        unsigned int    rom_attr_enabled:1;     /* Display of ROM attribute enabled? */
-       unsigned int    non_mappable_bars:1;    /* BARs can't be mapped to user-space  */
+       unsigned int    non_mappable_bars:1;    /* BARs can't be mapped by CPU or peers */
        pci_dev_flags_t dev_flags;
        atomic_t        enable_cnt;     /* pci_enable_device has been called */