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

[PATCH] PCI: avoid bogus calls to get_pseg()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 9 Aug 2022 17:50:44 +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=j2o3e3VcZdpL1nk388vY2vbR7X6y2j6+znoiiGQykqM=; b=KT0+9yumtgfL76CfaIiq1VU5QqejDSstc74QvUmfAG9d1HhoQGP2tDQprP2ay91pE5oR/ZHTyImC8WJ/+oRzjHXe2387rCMybMUIA84WrMHFQEjFtbHPVq0mQsnKEc6YE4lmN6KoBzH9EAjKulMFgt/D1/BXEuknRpDjftM3tdPWRrBEgsBbFhOV5+re9anuG7/yTEpnPnv9Y4hwsqG5ObvIUTNSZXj13kmWu/S81XlnThLaWOSUAwWbYOYNUfPVIzJ3rLT+M7CaKHF3sP9JDFFyOsUkd5k4zCqW2LkC7nhHQIe+L0NK6YxnxOdPSpBPG0Q2gsVS4zJyzomAWDdb8g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AskTGe8AkF3GdI5Yu92z1jR1qH/ylxcYSaIOa3v0s4G41N4GDISep+p+bOr2a9lJXsMXsvZuGw5ux1ipN8hOLo2HyMieE40pvfeO11GIu1bSvt6CF6kJvQQ7W1/gJR/g7OVpzm3dr306OODrSrziOu2V2cf9VpEg3ralstvff22VhZEr3k9Fz20U6RomHguBkJzvu7xxhei1cg6igNlrMvdM0WQfF+HnnSCZxOIY0Mc7pqjC4/wDaRiZ/1sPNUd6SEbiloMNxt9LoOcjGRQvHrH3i4eUw1bon3zoYtXKCoousu/QodV/GUxIL4Mje/McDBaYOf4upuaTqbLhowMpbA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Tue, 09 Aug 2022 15:50:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When passed -1, the function (taking a u16) will look for segment
0xffff, which might exist. If it exists, we may find (return) the wrong
device.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
An alternative would be to declare that both functions cannot be called
with "wildcards" anymore. The last such use went away with f591755823a7
("IOMMU/PCI: don't let domain cleanup continue when device de-assignment
failed") afaict.

Each time I look at this pair of functions I wonder why we have two
copies of almost the same code (with a curious difference of only one
having ASSERT(pcidevs_locked())). Any opinions on deleting either one,
subsuming its functionality into the other one by allowing the domain
pointer to be NULL to signify "any"?

--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -578,20 +578,19 @@ int __init pci_ro_device(int seg, int bu
 
 struct pci_dev *pci_get_pdev(int seg, int bus, int devfn)
 {
-    struct pci_seg *pseg = get_pseg(seg);
+    struct pci_seg *pseg = NULL;
     struct pci_dev *pdev = NULL;
 
     ASSERT(pcidevs_locked());
     ASSERT(seg != -1 || bus == -1);
     ASSERT(bus != -1 || devfn == -1);
 
+    if ( seg == -1 )
+        radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1);
+    else
+        pseg = get_pseg(seg);
     if ( !pseg )
-    {
-        if ( seg == -1 )
-            radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1);
-        if ( !pseg )
-            return NULL;
-    }
+        return NULL;
 
     do {
         list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
@@ -628,19 +627,18 @@ struct pci_dev *pci_get_real_pdev(int se
 struct pci_dev *pci_get_pdev_by_domain(const struct domain *d, int seg,
                                        int bus, int devfn)
 {
-    struct pci_seg *pseg = get_pseg(seg);
+    struct pci_seg *pseg = NULL;
     struct pci_dev *pdev = NULL;
 
     ASSERT(seg != -1 || bus == -1);
     ASSERT(bus != -1 || devfn == -1);
 
+    if ( seg == -1 )
+        radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1);
+    else
+        pseg = get_pseg(seg);
     if ( !pseg )
-    {
-        if ( seg == -1 )
-            radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1);
-        if ( !pseg )
-            return NULL;
-    }
+        return NULL;
 
     do {
         list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )



 


Rackspace

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