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

[PATCH v3 4/4] xen/vpci: header: status register handler


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Mon, 21 Aug 2023 21:29:52 -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=0n1yyNK6sHaopm2rNEybK0BDTFSOqSy/3YHjVA/ulc0=; b=OiHtNLn1vuFjBt2sfCrLYT1uk5odD78ncqrL6w0S3kV7fdQb2/kyZnXLHzePjviXPNTd9JdqUDPVb8ACb8xtnEhJtBzAaDaDvYVv8k0Os+ZoAmUYecZ8mQKdyiSMu2HSDzr7SfshKDtv+hWJXPY2VR2oVZVQKzzFZ3XYkAHgP+yvsO9A7B2wtr5iOhHP5OAUn/J/ui3DZFl7Rtq0FkZmhUF9tOFqPS3Y1OtZNSS8vB3EzumAWQRCc2xtBVT4THV0o5O8CUD9KdebEZ7E64vJD1c0lWp4s3lXJ0j91ykw+K3ykWIrwrPzSyEHW9pGaAOPfZR3Dwc4u/bzgAE+wirtZA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c8OEjwnlsvr7Lk9u/0W5YWXHeZT5a2US3Ixw5ZJiTrOeTiaYE5VoSh4NW2XsOBE9trfo8OEKoHUAV3MXS26IVXmyinz2ne2Jn5v7lg/esU8zJ7p5m7oU5R6jS8LzGR3iEhu7x1ycF9xJMotVZSORVP1Dg21XXenowaPxGGFJx9W5+4LEDMsKcxTCyIW6ur91y1a3VYtmf9/+Yy4JDLwQJgIICgU8r6c8tOeXP2u6PTDFtEp21QPACNKL2rHXyTut55wDhiliPN9N0+fVuVh4IiQf/m6RdbV5l6XRwCD7NrNeYgpR5gfQWoek26QTKND8WvC4fvSsN8Y0HqXZc3B2VA==
  • Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 22 Aug 2023 01:32:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce a handler for the PCI status register, with ability to mask the
capabilities bit. The status register is write-1-to-clear, so introduce handling
for this type of register in vPCI.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
---
v2->v3:
* new patch
---
 xen/drivers/vpci/header.c | 24 +++++++++++++++++++++++
 xen/drivers/vpci/vpci.c   | 41 +++++++++++++++++++++++++++++----------
 xen/include/xen/vpci.h    |  9 +++++++++
 3 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index b531ab03cec1..7061b85e337b 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -413,6 +413,17 @@ static void cf_check cmd_write(
         pci_conf_write16(pdev->sbdf, reg, cmd);
 }
 
+static uint32_t cf_check status_read(const struct pci_dev *pdev,
+                                     unsigned int reg, void *data)
+{
+    struct vpci_header *header = data;
+
+    if ( header->mask_cap_list )
+        return pci_conf_read16(pdev->sbdf, reg) & ~(PCI_STATUS_CAP_LIST);
+
+    return pci_conf_read16(pdev->sbdf, reg);
+}
+
 static void cf_check bar_write(
     const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data)
 {
@@ -556,6 +567,11 @@ static int cf_check init_bars(struct pci_dev *pdev)
     if ( rc )
         return rc;
 
+    rc = vpci_add_rw1c_register(pdev->vpci, status_read, vpci_hw_write16,
+                                PCI_STATUS, 2, header);
+    if ( rc )
+        return rc;
+
     if ( !is_hardware_domain(pdev->domain) )
     {
         if ( !(pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST) )
@@ -583,6 +599,14 @@ static int cf_check init_bars(struct pci_dev *pdev)
 
             next &= ~3;
 
+            if ( !next )
+                /*
+                 * If we don't have any supported capabilities to expose to the
+                 * guest, mask the PCI_STATUS_CAP_LIST bit in the status
+                 * register.
+                 */
+                header->mask_cap_list = true;
+
             while ( next && ttl )
             {
                 uint8_t pos = next;
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index 4a96aa50494d..a34d85f4ed3c 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -29,6 +29,7 @@ struct vpci_register {
     unsigned int offset;
     void *private;
     struct list_head node;
+    bool rw1c : 1;
 };
 
 #ifdef __XEN__
@@ -157,9 +158,15 @@ uint32_t cf_check vpci_hw_read32(
     return pci_conf_read32(pdev->sbdf, reg);
 }
 
-int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler,
-                      vpci_write_t *write_handler, unsigned int offset,
-                      unsigned int size, void *data)
+void cf_check vpci_hw_write16(
+    const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data)
+{
+    pci_conf_write16(pdev->sbdf, reg, val);
+}
+
+static int _vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler,
+                              vpci_write_t *write_handler, unsigned int offset,
+                              unsigned int size, void *data, bool rw1c)
 {
     struct list_head *prev;
     struct vpci_register *r;
@@ -179,6 +186,7 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t 
*read_handler,
     r->size = size;
     r->offset = offset;
     r->private = data;
+    r->rw1c = rw1c;
 
     spin_lock(&vpci->lock);
 
@@ -205,6 +213,22 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t 
*read_handler,
     return 0;
 }
 
+int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler,
+                      vpci_write_t *write_handler, unsigned int offset,
+                      unsigned int size, void *data)
+{
+    return _vpci_add_register(vpci, read_handler, write_handler, offset, size,
+                              data, false);
+}
+
+int vpci_add_rw1c_register(struct vpci *vpci, vpci_read_t *read_handler,
+                           vpci_write_t *write_handler, unsigned int offset,
+                           unsigned int size, void *data)
+{
+    return _vpci_add_register(vpci, read_handler, write_handler, offset, size,
+                              data, true);
+}
+
 int vpci_remove_register(struct vpci *vpci, unsigned int offset,
                          unsigned int size)
 {
@@ -419,11 +443,6 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, 
unsigned int size)
 
 /*
  * Perform a maybe partial write to a register.
- *
- * Note that this will only work for simple registers, if Xen needs to
- * trap accesses to rw1c registers (like the status PCI header register)
- * the logic in vpci_write will have to be expanded in order to correctly
- * deal with them.
  */
 static void vpci_write_helper(const struct pci_dev *pdev,
                               const struct vpci_register *r, unsigned int size,
@@ -433,9 +452,11 @@ static void vpci_write_helper(const struct pci_dev *pdev,
 
     if ( size != r->size )
     {
-        uint32_t val;
+        uint32_t val = 0;
+
+        if ( !r->rw1c )
+            val = r->read(pdev, r->offset, r->private);
 
-        val = r->read(pdev, r->offset, r->private);
         data = merge_result(val, data, size, offset);
     }
 
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 17fd252746ec..518d381b2df7 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -37,6 +37,11 @@ int __must_check vpci_add_register(struct vpci *vpci,
                                    vpci_write_t *write_handler,
                                    unsigned int offset, unsigned int size,
                                    void *data);
+int __must_check vpci_add_rw1c_register(struct vpci *vpci,
+                                        vpci_read_t *read_handler,
+                                        vpci_write_t *write_handler,
+                                        unsigned int offset, unsigned int size,
+                                        void *data);
 int __must_check vpci_remove_register(struct vpci *vpci, unsigned int offset,
                                       unsigned int size);
 
@@ -55,6 +60,8 @@ uint32_t cf_check vpci_hw_read16(
     const struct pci_dev *pdev, unsigned int reg, void *data);
 uint32_t cf_check vpci_hw_read32(
     const struct pci_dev *pdev, unsigned int reg, void *data);
+void cf_check vpci_hw_write16(
+    const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data);
 
 /*
  * Check for pending vPCI operations on this vcpu. Returns true if the vcpu
@@ -99,6 +106,8 @@ struct vpci {
          * upon to know whether BARs are mapped into the guest p2m.
          */
         bool bars_mapped      : 1;
+        /* Store whether to hide all capabilities from the guest. */
+        bool mask_cap_list : 1;
         /* FIXME: currently there's no support for SR-IOV. */
     } header;
 
-- 
2.41.0




 


Rackspace

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