[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] PCI: don't allow "pci-phantom=" to mark real devices as phantom functions


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 29 Apr 2022 15:05:32 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s5jGIOq+SY8wUKwZIKC3ATH/uVXY4XNucamYnYy/Jyw=; b=lezfqVLYcSQPdxpC/85sWnLoLmUGTXuWzoVWCeMQjUvQe3i7I/wYJPmfl9PiYqJ/CAoLER6C/N7pfJL8/aJFWxvHVsfOw9f9pTCWxJyuLoqE460rS9rHj51/RpJT61xZ0GJ75QBPlsZrrtzsV+NPsKmfd8Co13c5CjsCPtdPKEazuTsuEv4pQfWJGb/hoZAliBP6OXaRdWJcT89xCoF1xtg77cMTOrHOos/k3o4Zo6bqICZDRwo8/4ZBybXwTSYWW+waOv9mRyJYeOeFEkjV0lmO6LXtvMweDLWX6bvGTbgm5hUogSoPHHthG9cGyeA7YBQJ0nzLXB9IUijZAnbcQw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KDkcIwaotuPqquktLULUPN2CVzOTdEa3zWbc61kPmRY+W66DkJVzgBkDfP/QMuJLGH9XUnicU4BwyCRqK7sX8Ids6h4eJrroKSudMcWvgtQabAZ09nIP0moFeAof4fKeEaMOvJFIXmubLYXpxUXrf+r8Sn0uNPnz+9XP4MslK2MWihFdQM60DyTKlV/h1MbzK1gsi7aR4DTAe2Mw044kudKbu5hXBm1oH+bXSxw7MjbxSGgUMetzT7eGOyc60Gib3e8ESADFWD7xN3BijTY2QLGM6qAVEbol8/9W5PpZU0l8SmKYgvqfxmbOglnnGDPVTlkKdwI0y+rksF20CMhKwQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Fri, 29 Apr 2022 13:05:46 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- 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;
                     }
             }




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.