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

Re: [PATCH v2 1/3] PCI: simplify (and thus correct) pci_get_pdev{,_by_domain}()


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Thu, 11 Aug 2022 13:11:26 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=3xT856k0rdH+tUJBB9brTD1j+Tkm4Ehs0B5LW2Y9Cmo=; b=ofwS1JQBUOq4RHBg0qrg15HPaxYOo2otaejvxb0PFhf5seLuMsMUzZhypy1PwogrdlGZd1M3UyHZ1DphCQh82a2Kg4H06++Jb8eFhqejNrR2ioE6cI9WL3lzkmcbdaVQodVS7FVK1SIBPCreMYy1eHtFKSmJ1QaPe4NRsuUCenfIFBDHV/DzCOJdT3bZEG1eVnqa+/MQigHIPGQfprqtA6EmQc9GZYzcVOSVVr99PHcjEXJl8Iv5fq9uLq5dsaHjRE8cGpOmqIK+1EfHzd5SkSGcwTNNTSmTA6NhNfYjmVjLscgbPN+CVq6a77Uj8/2lWtXhj1yeOCOlWmDXbm4BHQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PZ/wjh9CO+A2afr6+qDDAPHiTV6/7xP8bpWTtZKP3IaGmNgjcxVIlYHN8BxSulUXVM7lEQWD+YNvL+ilULXY4OFD7l3fTqRTT35NLbgve+tR9me7iCCZTDn8Fw7CbWVU8YprFZ1X+bLPj/Xy7xRILe/C793GZDIPNSBmvfyXHagJvNeLLxU8TpR26e1U2b0WHio5BqRszJKtqHEEeR80bsC7QfNjq57K+bzPST7EjHmj8gnh/bzpmfhZkMywYL0ykAx/xv6RZu59GF/UvlEKiKwtZpnkTHctABscB75ZMWDiklby+VjBJu7lg5slyOUHRpDM6LjIH1f3dMMjJTP4ug==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Rahul Singh <Rahul.Singh@xxxxxxx>
  • Delivery-date: Thu, 11 Aug 2022 13:11:42 +0000
  • Ironport-data: A9a23:pLrUAaMISZl58tDvrR2TlsFynXyQoLVcMsEvi/4bfWQNrUorgWNTn GBMDW6PM/iIMDD0fdt/btjl/U8H68XTyIAxGgto+SlhQUwRpJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdleF+lH3dOCJQUBUjcmgXqD7BPPPJhd/TAplTDZJoR94kqsyj5UAbeKRWmthg vuv5ZyEULOZ82QsaDhMu/va8EoHUMna41v0gHRvPZing3eG/5UlJMp3Db28KXL+Xr5VEoaSL woU5Ojklo9x105F5uKNyt4XQGVTKlLhFVHmZk5tc7qjmnB/Shkaic7XAha+hXB/0F1ll/gpo DlEWAfZpQ0BZsUgk8xFO/VU/r0X0QSrN9YrLFDm2fF/wXEqfFPKxe9ONkUUI7cB0aV6WWRA3 8EBOAokO0Xra+KemNpXS8FKr+F6dYzHGd1avXttizbEEfwhXJbPBb3Q4sNV1ysxgcYIGuvCY 80eanxkaxGojx9nYw9LTs5h2rr3wCCgLlW0q3rMzUYzy0HVwBZ8z/7GN93Nd8bRbc5UglyZt iTN+GGR7hQya4PGkGPeqSjEaunnnjzDWo4iFOSB69VtjgK0y0UBJjRKfA7uyRW+ogvkMz5FE GQW8Cczqak59GSwU8LwGRa/pRasrhMaHtZdDeA+wAWM0bbPpRaUAHAeSTxMY8Bgs9U5LRQy3 0KNt8PkA3poqrL9YUiU9qqQ6wizPycVBWYYYGkPSg5t3jX4iIQ6jxaKQtM9Fqew14TxAWupn G3MqzUijbIOi8JNz7+84V3MnzOroN7OUxIx4QLUGGmi62uVebKYWmBh0nCDhd4oEWpTZgDpU KQs8yRG0N0zMA==
  • Ironport-hdrordr: A9a23:qtt4hK2ZlV9GkwJQFat9nAqjBc5xeYIsimQD101hICG9Lfb5qy n+ppUmPEHP5gr5AEtQ5exoS5PwPk80lKQFrLX5Uo3SJDUO1FHYSb2KqLGSvgEIFheUygc/79 YtT0EdMqyKMbESt6+TimTVfKdCsbu6GeKT9J3jJh9WPEdXgspbnmBE43OgYzRLrX59dPwE/f Snl656jgvlVFEvKv6wDn4DU+WrnayaqLvWJTo9QzI34giHij2lrJTgFQKD4xsYWzRThZ8/7G nsiWXCl+qemsD+7iWZ+37Y7pxQltek4MBEHtawhs8cLSipohq0Zb5mR6aJsFkO0a+SARcR4Z jxSiUbTodOAkDqDyOISNzWqkzdOQMVmj/fIJmj8D/eSILCNXUH4oF69Pxkm1PimjsdVZdHof t2N6jwjesOMfsC9B6NvOQhLXtR5xeJSSFJq59Os5QaOrFuOYO4aOQkjRlo+FNpJlOk1GjheN MeUv00rcwmAW+yfjTXuHJiz8erWWl2FhCaQlIassjQyDROmmtlpnFojPD3s01wgq7VcaM0rt jsI+BtjvVDX8UWZaVyCKMIRta2EHXERVbJPHiJKVrqGakbMzaVwqSHqokd9aWvYtgF3ZEykJ POXBdRsnMzYVvnDYmL0IdQ+h7ATW2hVXDmy91Y5ZJ+prrgLYCbehGrWRQriY+tsv8fCsrUV7 K6P49XGebqKS/0FYNAz2TFKu5vwLklIbkoU/oAKiCzS5jwW/7XX8TgAYPuGIY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYrXBZXwmbEINJNkq3LaRWDdsBqK2prNgA
  • Thread-topic: [PATCH v2 1/3] PCI: simplify (and thus correct) pci_get_pdev{,_by_domain}()

On 11/08/2022 11:51, Jan Beulich wrote:
> The last "wildcard" use of either function went away with f591755823a7
> ("IOMMU/PCI: don't let domain cleanup continue when device de-assignment
> failed"). Don't allow them to be called this way anymore. Besides
> simplifying the code this also fixes two bugs:
>
> 1) When seg != -1, the outer loops should have been terminated after the
>    first iteration, or else a device with the same BDF but on another
>    segment could be found / returned.
>
> Reported-by: Rahul Singh <rahul.singh@xxxxxxx>
>
> 2) When seg == -1 calling get_pseg() is bogus. The function (taking a
>    u16) would look for segment 0xffff, which might exist. If it exists,
>    we might then find / return a wrong device.
>
> In pci_get_pdev_by_domain() also switch from using the per-segment list
> to using the per-domain one, with the exception of the hardware domain
> (see the code comment there).
>
> While there also constify "pseg" and drop "pdev"'s already previously
> unnecessary initializer.
>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

I'm not totally convinced that special casing hwdom is right, because
quarantine devices are domio not hwdom.  But I also can't identify a
case where it's definitely wrong either.

> --- a/xen/include/xen/pci.h
> +++ b/xen/include/xen/pci.h
> @@ -177,10 +177,10 @@ int pci_add_device(u16 seg, u8 bus, u8 d
>  int pci_remove_device(u16 seg, u8 bus, u8 devfn);
>  int pci_ro_device(int seg, int bus, int devfn);
>  int pci_hide_device(unsigned int seg, unsigned int bus, unsigned int devfn);
> -struct pci_dev *pci_get_pdev(int seg, int bus, int devfn);
> +struct pci_dev *pci_get_pdev(uint16_t seg, uint8_t bus, uint8_t devfn);

I was going to make a request, but I can't quite get it to compile...

Passing sbdf as 3 parameters is a waste, and it would be great if we
could take this opportunity to improve.

Sadly,

-struct pci_dev *pci_get_pdev(uint16_t seg, uint8_t bus, uint8_t devfn);
+struct pci_dev *pci_get_pdev(pci_sbdf_t sbdf);
+
+#define pci_get_pdev(...)                               \
+    ({                                                  \
+        count_args(__VA_ARGS__) == 1                    \
+            ? pci_get_pdev(__VA_ARGS__)                 \
+            : pci_get_pdev(PCI_SBDF(__VA_ARGS__));      \
+    })

this doesn't quite compile as a transition plan, and I'm stuck for
further ideas.

~Andrew

 


Rackspace

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