All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: don't allow "pci-phantom=" to mark real devices as phantom functions
@ 2022-04-29 13:05 Jan Beulich
  2022-05-05 15:00 ` Roger Pau Monné
  2022-05-05 19:10 ` Andrew Cooper
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Beulich @ 2022-04-29 13:05 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org; +Cc: Paul Durrant, Andrew Cooper

IOMMU code mapping / unmapping devices and interrupts will misbehave if
a wrong command line option declared a function "phantom" when there's a
real device at that position. Warn about this and adjust the specified
stride (in the worst case ignoring the option altogether).

Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -451,7 +451,24 @@ static struct pci_dev *alloc_pdev(struct
                          phantom_devs[i].slot == PCI_SLOT(devfn) &&
                          phantom_devs[i].stride > PCI_FUNC(devfn) )
                     {
-                        pdev->phantom_stride = phantom_devs[i].stride;
+                        pci_sbdf_t sbdf = pdev->sbdf;
+                        unsigned int stride = phantom_devs[i].stride;
+
+                        while ( (sbdf.fn += stride) > PCI_FUNC(devfn) )
+                        {
+                            if ( pci_conf_read16(sbdf, PCI_VENDOR_ID) == 0xffff &&
+                                 pci_conf_read16(sbdf, PCI_DEVICE_ID) == 0xffff )
+                                continue;
+                            stride <<= 1;
+                            printk(XENLOG_WARNING
+                                   "%pp looks to be a real device; bumping %04x:%02x:%02x stride to %u\n",
+                                   &sbdf, phantom_devs[i].seg,
+                                   phantom_devs[i].bus, phantom_devs[i].slot,
+                                   stride);
+                            sbdf = pdev->sbdf;
+                        }
+                        if ( PCI_FUNC(stride) )
+                           pdev->phantom_stride = stride;
                         break;
                     }
             }



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-19 12:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-29 13:05 [PATCH] PCI: don't allow "pci-phantom=" to mark real devices as phantom functions Jan Beulich
2022-05-05 15:00 ` Roger Pau Monné
2022-05-05 15:14   ` Jan Beulich
2022-05-05 15:36     ` Roger Pau Monné
2022-05-05 19:10 ` Andrew Cooper
2022-05-06  6:21   ` Jan Beulich
2022-05-19 12:22     ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.