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

[RFC PATCH v2 2/2] xen/vpci: header: avoid cast for value passed to vpci_read_val


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Wed, 16 Aug 2023 14:50:29 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=lUV5SZfYUs2RFem9ruC9kFS6lhh6QPi95iyU+XcQnCM=; b=f6Y2xpPz1Rmw6zWR1ISFz0phDQx+SBeuwiE8mpdhZY6btInjYzYRyaI+hZ1eSwcyyxdrv6gi8wlL7XnEMzQFe8pIp/pjpZ0glqp4q7rjzUlPM1ZViurgOnGpIjpskwERJGQIocaGDAMZHvOEkYj2mmFYFmcHJQBHKRc9dLaiovkiVaBP3cwq/QiafI49kMFNSRZ1iusymjYKdKioNp9HQ7vlWiDMDQ90xqD65KRIVfrti/mDyoiwMT3kqFt6Iqt6XRq/VlNHQKUo3/G3/IfLUkBZ95+8caevpaOfzA78+lG1SwYJwsG+ZxNX014nxHN2+Je1X5ww/OuQ7tx2mFbhQg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S1KD1Rh8713mgbnz4N82Vy8UJcoxYbs8j1RICDsd1f/0XDq7jFwGiPbDmDzgbVsq8hPxSdHYevnMUItU6cQgg9UMEWFv0n22zYeI1r3cRtkEYcCx3INvciKxoQkugbTDwprTJgGD5fHeRHF2FoB69sYV9kbidTC3Gqcc8DofDJ4j0UfjKHtWnwP0fFGymHJhqqfhfbdAuvMp4qz9cem32ktsq6xkm5zSUJ7E4Nalakx+Ppu5dCfuPIDz1HvwBV4EzYzx0zh+1O06mqLJlOyaQIqTXsXsrECicH58bUZwgQrYvru9sfMq/OxekfRcRbltyquojogNcdwH/ESxximrwQ==
  • Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 16 Aug 2023 18:51:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The only purpose of this is to give an idea of what it might look like to
introduce a new memory allocation in order to get rid of the casts for the value
passed to vpci_read_val. If this is deemed preferable vs the casts, I will
squash it for the next version of the series.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
---
v1->v2:
* new patch
---
 xen/drivers/vpci/header.c | 13 ++++++++++---
 xen/drivers/vpci/vpci.c   |  8 +++++++-
 xen/include/xen/vpci.h    |  3 +++
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index ec5947300198..ae269a0b4bbc 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -571,14 +571,19 @@ static int cf_check init_bars(struct pci_dev *pdev)
         {
             /* Only expose capabilities to the guest that vPCI can handle. */
             uint8_t next;
-            int ttl = 48;
+            int ttl = 48, i = 0;
+
+            header->caps_list = xzalloc_array(uint8_t, ttl);
+            if ( !header->caps_list )
+                return -ENOMEM;
 
             next = pci_find_next_cap(pdev->sbdf, PCI_CAPABILITY_LIST,
                                      vpci_cap_supported, &ttl);
 
+            header->caps_list[i] = next;
             rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
                                    PCI_CAPABILITY_LIST, 1,
-                                   (void *)(uintptr_t)next);
+                                   &header->caps_list[i]);
             if ( rc )
                 return rc;
 
@@ -594,9 +599,11 @@ static int cf_check init_bars(struct pci_dev *pdev)
                 if ( rc )
                     return rc;
 
+                i++;
+                header->caps_list[i] = next;
                 rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
                                        pos + PCI_CAP_LIST_NEXT, 1,
-                                       (void *)(uintptr_t)next);
+                                       &header->caps_list[i]);
                 if ( rc )
                     return rc;
 
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index 4a96aa50494d..717340b8fbe8 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -61,6 +61,7 @@ void vpci_remove_device(struct pci_dev *pdev)
             if ( pdev->vpci->msix->table[i] )
                 iounmap(pdev->vpci->msix->table[i]);
     }
+    xfree(pdev->vpci->header.caps_list);
     xfree(pdev->vpci->msix);
     xfree(pdev->vpci->msi);
     xfree(pdev->vpci);
@@ -136,7 +137,12 @@ static void cf_check vpci_ignored_write(
 uint32_t cf_check vpci_read_val(
     const struct pci_dev *pdev, unsigned int reg, void *data)
 {
-    return (uintptr_t)data;
+    uint8_t *val = data;
+
+    if ( val )
+        return *val;
+
+    return 0;
 }
 
 uint32_t cf_check vpci_hw_read8(
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 17fd252746ec..7cdee84b5123 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -88,6 +88,9 @@ struct vpci {
         } bars[PCI_HEADER_NORMAL_NR_BARS + 1];
         /* At most 6 BARS + 1 expansion ROM BAR. */
 
+        /* Guest view of capabilities next pointers. */
+        uint8_t *caps_list;
+
         /*
          * Store whether the ROM enable bit is set (doesn't imply ROM BAR
          * is mapped into guest p2m) if there's a ROM BAR on the device.
-- 
2.41.0




 


Rackspace

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