Skip to contentSkip to conversation

vpci/msi: fix size of the vectors fields

PATCH In review Roger Pau Monne 2 participants 3 messages Mar 26, 2018 – Mar 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 vpci/msi: fix size of the vectors fields

The current size (5bits) is not enough to store the maximum number of vectors (32), bump it by one bit.

Also change the layout so that 'vectors' is aligned to a 8bit boundary.

Note that the size of the struct is still the same.

Reported-by: Coverity
Coverity ID: 1430810

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Move the position of the 'enabled' field in the msi struct.

---
 xen/include/xen/vpci.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/include/xen/vpci.h +4 -4
index cb39e0ebea..29616624ad 100644
@@ -100,15 +100,15 @@ struct vpci {
         /* Data. */
         uint16_t data;
         /* Maximum number of vectors supported by the device. */
-        uint8_t max_vectors : 5;
-        /* Enabled? */
-        bool enabled        : 1;
+        uint8_t max_vectors : 6;
         /* Supports per-vector masking? */
         bool masking        : 1;
         /* 64-bit address capable? */
         bool address64      : 1;
         /* Number of vectors configured. */
-        uint8_t vectors     : 5;
+        uint8_t vectors     : 6;
+        /* Enabled? */
+        bool enabled        : 1;
         /* Arch-specific data. */
         struct vpci_arch_msi arch;
     } *msi;
Signature · 7 lines
2.16.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 2/2 vpci: make sure handlers can deal with size == 0

The code is not prepared to handle such case, so just return early. In the debug case add an assert.

Reported-by: Coverity
Coverity ID: 1430809

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/drivers/vpci/vpci.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
xen/drivers/vpci/vpci.c +12 -0
index 2913b56500..82607bdb9a 100644
@@ -320,6 +320,12 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size)
     unsigned int data_offset = 0;
     uint32_t data = ~(uint32_t)0;
 
+    if ( !size )
+    {
+        ASSERT_UNREACHABLE();
+        return data;
+    }
+
     /* Find the PCI dev matching the address. */
     pdev = pci_get_pdev_by_domain(d, sbdf.seg, sbdf.bus, sbdf.extfunc);
     if ( !pdev )
@@ -416,6 +422,12 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,
     const struct vpci_register *r;
     unsigned int data_offset = 0;
 
+    if ( !size )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
     /*
      * Find the PCI dev matching the address.
      * Passthrough everything that's not trapped.
Signature · 7 lines
2.16.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 for-4.11 2/2] vpci: make sure handlers can deal with size == 0

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 18:32, <[email protected]> wrote:

The code is not prepared to handle such case, so just return early. In the debug case add an assert.

Reported-by: Coverity
Coverity ID: 1430809

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel