Skip to contentSkip to conversation

vPCI capabilities filtering

PATCH Superseded Stewart Hildebrand 2 participants 10 messages Aug 10, 2023 – Aug 15, 2023

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

cover vPCI capabilities filtering

This small series enables vPCI to filter which PCI capabilites we expose to a domU. This series adds vPCI register handlers within xen/drivers/vpci/header.c:init_bars(), along with some supporting functions.

Note there are minor rebase conflicts with the in-progress vPCI series [1]. These conflicts fall into the category of functions and code being added adjacent to one another, so are easily resolved. I did not identify any dependency on the vPCI locking work, and the two series deal with different aspects of emulating the PCI header.

Future work may involve adding handlers for more registers in the vPCI header, such as STATUS, VID/DID, etc.

[1] https://lists.xenproject.org/archives/html/xen-devel/2023-07/msg01281.html

Stewart Hildebrand (3):
xen/vpci: add vpci_hw_read8 helper
xen/vpci: add vpci_read_val helper
xen/vpci: header: filter PCI capabilities

 xen/drivers/vpci/header.c | 78 +++++++++++++++++++++++++++++++++++++++
 xen/drivers/vpci/vpci.c   | 12 ++++++
 xen/include/xen/vpci.h    |  5 +++
 3 files changed, 95 insertions(+)

base-commit: b70ffd23865e6c320fe2e8931f0d0366d7e03cac

Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/3 xen/vpci: add vpci_hw_read8 helper

This will be used in a subsequent patch.

---
 xen/drivers/vpci/vpci.c | 6 ++++++
 xen/include/xen/vpci.h  | 2 ++
 2 files changed, 8 insertions(+)
xen/drivers/vpci/vpci.c +6 -0
index d73fa7630237..acadba1fd6c5 100644
@@ -133,6 +133,12 @@ static void cf_check vpci_ignored_write(
 {
 }
 
+uint32_t cf_check vpci_hw_read8(
+    const struct pci_dev *pdev, unsigned int reg, void *data)
+{
+    return pci_conf_read8(pdev->sbdf, reg);
+}
+
 uint32_t cf_check vpci_hw_read16(
     const struct pci_dev *pdev, unsigned int reg, void *data)
 {
xen/include/xen/vpci.h +2 -0
index 0b8a2a3c745b..ee7a8fcdee83 100644
@@ -46,6 +46,8 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,
                 uint32_t data);
 
 /* Passthrough handlers. */
+uint32_t cf_check vpci_hw_read8(
+    const struct pci_dev *pdev, unsigned int reg, void *data);
 uint32_t cf_check vpci_hw_read16(
     const struct pci_dev *pdev, unsigned int reg, void *data);
 uint32_t cf_check vpci_hw_read32(
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/3 xen/vpci: add vpci_read_val helper

In reply to Stewart Hildebrand

Introduce a vPCI read helper function that returns a fixed value. This may be used for RAZ registers, or registers whose value doesn't change. This helper will be used in a subsequent patch.

---
RFC: I'm not a fan of the (uintptr_t) cast, but without it I wasn't sure how to
pass a value without allocating more memory (either with an xalloc function of sorts, or by adding a new element in struct vpci_register and changing the interface). Plus, in the current state, to pass a value to vpci_add_register(), it may be necessary to cast twice:
(void *)(uintptr_t)myval. See next patch. Perhaps a new allocation is worth it to avoid the casts? Or maybe I'm being overly pedantic and the casts are okay?

---
 xen/drivers/vpci/vpci.c | 6 ++++++
 xen/include/xen/vpci.h  | 3 +++
 2 files changed, 9 insertions(+)
xen/drivers/vpci/vpci.c +6 -0
index acadba1fd6c5..4a96aa50494d 100644
@@ -133,6 +133,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;
+}
+
 uint32_t cf_check vpci_hw_read8(
     const struct pci_dev *pdev, unsigned int reg, void *data)
 {
xen/include/xen/vpci.h +3 -0
index ee7a8fcdee83..17fd252746ec 100644
@@ -45,6 +45,9 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size);
 void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,
                 uint32_t data);
 
+uint32_t cf_check vpci_read_val(
+    const struct pci_dev *pdev, unsigned int reg, void *data);
+
 /* Passthrough handlers. */
 uint32_t cf_check vpci_hw_read8(
     const struct pci_dev *pdev, unsigned int reg, void *data);
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/3 xen/vpci: header: filter PCI capabilities

In reply to Stewart Hildebrand

Xen vPCI only supports virtualizing the MSI and MSI-X capabilities, so all other PCI capabilities should be hidden from a domU for now. We parse the physical PCI capabilities linked list and add vPCI register handlers for the next elements, inserting our own next value, thus presenting a modified linked list to the domU.

---

If there are no capabilities to be exposed to the guest, a future status register handler likely would want to mask the PCI_STATUS_CAP_LIST bit. I'm thinking we could track this in struct vpci_header as follows:

vpci.h:

     struct vpci_header {
         ...
+        bool mask_cap_list : 1;
     } header;

header.c:init_bars():

         rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
                                PCI_CAPABILITY_LIST, 1,
                                (void *)(uintptr_t)next);
         if ( rc )
             return rc;

+ if ( !next )
+ header->mask_cap_list = true;
+

         for ( ttl = 48; ttl > 0; ttl-- )
         {
             uint8_t pos;
---
 xen/drivers/vpci/header.c | 78 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
xen/drivers/vpci/header.c +78 -0
index 60f7049e3498..cb1304fa1eed 100644
@@ -513,6 +513,36 @@ static void cf_check rom_write(
         rom->addr = val & PCI_ROM_ADDRESS_MASK;
 }
 
+static uint8_t vpci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos)
+{
+    uint8_t id;
+    int ttl;
+
+    if ( pos < 0x40 )
+        pos = pci_conf_read8(sbdf, PCI_CAPABILITY_LIST);
+    else
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
+
+    for ( ttl = 48; ttl > 0; ttl-- )
+    {
+        if ( pos < 0x40 )
+            break;
+
+        pos &= ~3;
+        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
+
+        if ( id == 0xff )
+            break;
+
+        if ( id == PCI_CAP_ID_MSI ||
+             id == PCI_CAP_ID_MSIX )
+            return pos;
+
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
+    }
+    return 0;
+}
+
 static int cf_check init_bars(struct pci_dev *pdev)
 {
     uint16_t cmd;
@@ -544,6 +574,54 @@ static int cf_check init_bars(struct pci_dev *pdev)
     if ( rc )
         return rc;
 
+    if ( !is_hardware_domain(pdev->domain) )
+    {
+        if ( (pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST)
+             == 0 )
+        {
+            /* RAZ/WI */
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1, NULL);
+            if ( rc )
+                return rc;
+        }
+        else
+        {
+            /* Only expose capabilities to the guest that vPCI can handle. */
+            uint8_t next, ttl;
+
+            next = vpci_find_next_cap(pdev->sbdf, PCI_CAPABILITY_LIST);
+
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1,
+                                   (void *)(uintptr_t)next);
+            if ( rc )
+                return rc;
+
+            for ( ttl = 48; ttl > 0; ttl-- )
+            {
+                uint8_t pos;
+
+                if ( !next )
+                    break;
+
+                pos = next;
+                next = vpci_find_next_cap(pdev->sbdf, pos);
+
+                rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
+                                       pos + PCI_CAP_LIST_ID, 1, NULL);
+                if ( rc )
+                    return rc;
+
+                rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                       pos + PCI_CAP_LIST_NEXT, 1,
+                                       (void *)(uintptr_t)next);
+                if ( rc )
+                    return rc;
+            }
+        }
+    }
+
     if ( pdev->ignore_bars )
         return 0;
 
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH v1 3/3] xen/vpci: header: filter PCI capabilities

Quoted 2 lines · Stewart Hildebrand

Xen vPCI only supports virtualizing the MSI and MSI-X capabilities, so all other PCI capabilities should be hidden from a domU for now.

I'm not sure about "should"; imo this would need evaluating for every cap type separately. I'm okay though to take this as a starting point. What needs considering (and mentioning here) is that there may be (iirc: are) drivers which depend on being able to find/access certain capabilities.

Also - what about extended capabilities? Don't we want to hide them all then as well (by returning 0 for the 32-bit value at 0x100)?

Quoted 5 lines
xen/drivers/vpci/header.c +0 -0
@@ -513,6 +513,36 @@ static void cf_check rom_write(
         rom->addr = val & PCI_ROM_ADDRESS_MASK;
 }

xen/drivers/vpci/header.c static void cf_check rom_write( · line 524

Quoted 10 lines
xen/drivers/vpci/header.c +9 -0
 
+static uint8_t vpci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos)
+{
+    uint8_t id;
+    int ttl;
+
+    if ( pos < 0x40 )
+        pos = pci_conf_read8(sbdf, PCI_CAPABILITY_LIST);
+    else
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);

How about avoiding the if/else by having the caller pass in a useful value, rather than PCI_CAPABILITY_LIST? I.e.

#define PCI_CAP_LIST_FIRST (PCI_CAPABILITY_LIST - PCI_CAP_LIST_NEXT)

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+    for ( ttl = 48; ttl > 0; ttl-- )
+    {
+        if ( pos < 0x40 )
+            break;

xen/drivers/vpci/header.c static void cf_check rom_write( · line 539

Quoted 10 lines
xen/drivers/vpci/header.c +10 -0
+
+        pos &= ~3;
+        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
+
+        if ( id == 0xff )
+            break;
+
+        if ( id == PCI_CAP_ID_MSI ||
+             id == PCI_CAP_ID_MSIX )
+            return pos;

Can this please start out as switch() right away?

xen/drivers/vpci/header.c static void cf_check rom_write( · line 544

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
+    }
+    return 0;
+}

Nit: Blank line please ahead of main function return point.

I also notice that the function isn't really vPCI-specific in any way (except for the specific PCI_CAP_ID_* compared against). Would it perhaps make sense to have it be a general utility function, living in xen/drivers/pci/pci.c next to its relatives?

Quoted 15 lines
xen/drivers/vpci/header.c +11 -0
@@ -544,6 +574,54 @@ static int cf_check init_bars(struct pci_dev *pdev)
     if ( rc )
         return rc;
 
+    if ( !is_hardware_domain(pdev->domain) )
+    {
+        if ( (pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST)
+             == 0 )
+        {
+            /* RAZ/WI */
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1, NULL);
+            if ( rc )
+                return rc;
+        }

xen/drivers/vpci/header.c static int cf_check init_bars(struct pci_dev *pdev) · line 597

Quoted 10 lines
xen/drivers/vpci/header.c +10 -0
+        else
+        {
+            /* Only expose capabilities to the guest that vPCI can handle. */
+            uint8_t next, ttl;
+
+            next = vpci_find_next_cap(pdev->sbdf, PCI_CAPABILITY_LIST);
+
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1,
+                                   (void *)(uintptr_t)next);

In vpci_find_next_cap() the low 2 bits were masked off. While reserved at present, I wonder whether we wouldn't be better off passing them "through".

xen/drivers/vpci/header.c static int cf_check init_bars(struct pci_dev *pdev) · line 601

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+            if ( rc )
+                return rc;
+
+            for ( ttl = 48; ttl > 0; ttl-- )

vpci_find_next_cap() already bounds its loops; you effectively allow for 48*48 iterations here. It would seem better if the ttl applied globally, and would hence want to be an in/out for vpci_find_next_cap().

Also note that according to ./CODING_STYLE ttl shouldn't be uint<N>_t (this likely extends to other uses of such types here), and plain int also isn't really appropriate for a value which can't go negative.

Jan

#5 lore raw

Re: [PATCH v1 3/3] xen/vpci: header: filter PCI capabilities

Quoted 8 lines · Jan Beulich
Quoted 2 lines · Stewart Hildebrand

Xen vPCI only supports virtualizing the MSI and MSI-X capabilities, so all other PCI capabilities should be hidden from a domU for now.

I'm not sure about "should"; imo this would need evaluating for every cap type separately. I'm okay though to take this as a starting point. What needs considering (and mentioning here) is that there may be (iirc: are) drivers which depend on being able to find/access certain capabilities.

OK, I will re-word the commit message.

Quoted 2 lines

Also - what about extended capabilities? Don't we want to hide them all then as well (by returning 0 for the 32-bit value at 0x100)?

Yes, it certainly couldn't hurt to add a RAZ/WI handler at 0x100, so I'll do that.

Quoted 19 lines
Quoted 5 lines
xen/drivers/vpci/header.c +0 -0
@@ -513,6 +513,36 @@ static void cf_check rom_write(
         rom->addr = val & PCI_ROM_ADDRESS_MASK;
 }

xen/drivers/vpci/header.c static void cf_check rom_write( · line 524

Quoted 10 lines
xen/drivers/vpci/header.c +9 -0
 
+static uint8_t vpci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos)
+{
+    uint8_t id;
+    int ttl;
+
+    if ( pos < 0x40 )
+        pos = pci_conf_read8(sbdf, PCI_CAPABILITY_LIST);
+    else
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);

How about avoiding the if/else by having the caller pass in a useful value, rather than PCI_CAPABILITY_LIST? I.e.

Quoted 1 line

#define PCI_CAP_LIST_FIRST (PCI_CAPABILITY_LIST - PCI_CAP_LIST_NEXT)

OK, yes, I will eliminate the if/else.

Quoted 17 lines
Quoted 5 lines
xen/drivers/vpci/header.c +4 -0
+    for ( ttl = 48; ttl > 0; ttl-- )
+    {
+        if ( pos < 0x40 )
+            break;

xen/drivers/vpci/header.c static void cf_check rom_write( · line 539

Quoted 10 lines
xen/drivers/vpci/header.c +10 -0
+
+        pos &= ~3;
+        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
+
+        if ( id == 0xff )
+            break;
+
+        if ( id == PCI_CAP_ID_MSI ||
+             id == PCI_CAP_ID_MSIX )
+            return pos;

Can this please start out as switch() right away?

Yes, certainly.

Quoted 11 lines

xen/drivers/vpci/header.c static void cf_check rom_write( · line 544

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
+    }
+    return 0;
+}

Nit: Blank line please ahead of main function return point.

I also notice that the function isn't really vPCI-specific in any way (except for the specific PCI_CAP_ID_* compared against). Would it perhaps make sense to have it be a general utility function, living in xen/drivers/pci/pci.c next to its relatives?

Yes. The the PCI_CAP_ID_* comparisons were the only reason I initially decided not to use the existing pci_find_next_cap() function, which performs an almost identical task. I just noticed that the existing pci_find_next_cap() doesn't appear to have any callers. Given this, I'd prefer to modify the existing pci_find_next_cap() to suit our needs.

Quoted 21 lines
Quoted 21 lines
xen/drivers/vpci/header.c +17 -0
@@ -544,6 +574,54 @@ static int cf_check init_bars(struct pci_dev *pdev)
     if ( rc )
         return rc;
 
+    if ( !is_hardware_domain(pdev->domain) )
+    {
+        if ( (pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST)
+             == 0 )
+        {
+            /* RAZ/WI */
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1, NULL);
+            if ( rc )
+                return rc;
+        }
+        else
+        {
+            /* Only expose capabilities to the guest that vPCI can handle. */
+            uint8_t next, ttl;
+
+            next = vpci_find_next_cap(pdev->sbdf, PCI_CAPABILITY_LIST);
Quoted 8 lines

xen/drivers/vpci/header.c static int cf_check init_bars(struct pci_dev *pdev) · line 597

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+
+            rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+                                   PCI_CAPABILITY_LIST, 1,
+                                   (void *)(uintptr_t)next);

In vpci_find_next_cap() the low 2 bits were masked off. While reserved at present, I wonder whether we wouldn't be better off passing them "through".

Agreed

Quoted 8 lines

xen/drivers/vpci/header.c static int cf_check init_bars(struct pci_dev *pdev) · line 601

Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+            if ( rc )
+                return rc;
+
+            for ( ttl = 48; ttl > 0; ttl-- )

vpci_find_next_cap() already bounds its loops; you effectively allow for 48*48 iterations here. It would seem better if the ttl applied globally, and would hence want to be an in/out for vpci_find_next_cap().

OK

Quoted 3 lines

Also note that according to ./CODING_STYLE ttl shouldn't be uint<N>_t (this likely extends to other uses of such types here), and plain int also isn't really appropriate for a value which can't go negative.

Good catch, this was an oversight on my behalf. I will fix it.

#6 lore raw

Re: [PATCH v1 3/3] xen/vpci: header: filter PCI capabilities

Quoted 50 lines · Stewart Hildebrand
Quoted 20 lines · Jan Beulich
Quoted 5 lines · Stewart Hildebrand
xen/drivers/vpci/header.c +0 -0
@@ -513,6 +513,36 @@ static void cf_check rom_write(
         rom->addr = val & PCI_ROM_ADDRESS_MASK;
 }

xen/drivers/vpci/header.c static void cf_check rom_write( · line 524

Quoted 10 lines
xen/drivers/vpci/header.c +9 -0
 
+static uint8_t vpci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos)
+{
+    uint8_t id;
+    int ttl;
+
+    if ( pos < 0x40 )
+        pos = pci_conf_read8(sbdf, PCI_CAPABILITY_LIST);
+    else
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);

How about avoiding the if/else by having the caller pass in a useful value, rather than PCI_CAPABILITY_LIST? I.e.

Quoted 1 line

#define PCI_CAP_LIST_FIRST (PCI_CAPABILITY_LIST - PCI_CAP_LIST_NEXT)

OK, yes, I will eliminate the if/else.

Quoted 17 lines
Quoted 5 lines
xen/drivers/vpci/header.c +4 -0
+    for ( ttl = 48; ttl > 0; ttl-- )
+    {
+        if ( pos < 0x40 )
+            break;

xen/drivers/vpci/header.c static void cf_check rom_write( · line 539

Quoted 10 lines
xen/drivers/vpci/header.c +10 -0
+
+        pos &= ~3;
+        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
+
+        if ( id == 0xff )
+            break;
+
+        if ( id == PCI_CAP_ID_MSI ||
+             id == PCI_CAP_ID_MSIX )
+            return pos;

Can this please start out as switch() right away?

Yes, certainly.

Quoted 5 lines
Quoted 4 lines
xen/drivers/vpci/header.c +4 -0
+        pos = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_NEXT);
+    }
+    return 0;
+}
Quoted 8 lines
Quoted 6 lines

Nit: Blank line please ahead of main function return point.

I also notice that the function isn't really vPCI-specific in any way (except for the specific PCI_CAP_ID_* compared against). Would it perhaps make sense to have it be a general utility function, living in xen/drivers/pci/pci.c next to its relatives?

Yes. The the PCI_CAP_ID_* comparisons were the only reason I initially decided not to use the existing pci_find_next_cap() function, which performs an almost identical task. I just noticed that the existing pci_find_next_cap() doesn't appear to have any callers. Given this, I'd prefer to modify the existing pci_find_next_cap() to suit our needs.

Please modify the function only if it then remains (easily) usable for its original purpose. Even if right now without callers, it exists for a reason. (How to deal with the Misra unreachable code aspect in such cases remains to be decided.)

Jan

#7 lore raw
In reply to Stewart Hildebrand
Quoted 13 lines · Stewart Hildebrand

This small series enables vPCI to filter which PCI capabilites we expose to a domU. This series adds vPCI register handlers within xen/drivers/vpci/header.c:init_bars(), along with some supporting functions.

Note there are minor rebase conflicts with the in-progress vPCI series [1]. These conflicts fall into the category of functions and code being added adjacent to one another, so are easily resolved. I did not identify any dependency on the vPCI locking work, and the two series deal with different aspects of emulating the PCI header.

Future work may involve adding handlers for more registers in the vPCI header, such as STATUS, VID/DID, etc.

Quoted 6 lines

[1] https://lists.xenproject.org/archives/html/xen-devel/2023-07/msg01281.html

Stewart Hildebrand (3):
xen/vpci: add vpci_hw_read8 helper
xen/vpci: add vpci_read_val helper
xen/vpci: header: filter PCI capabilities

I'm not convinced of the split here: Seeing the new helpers in isolation leaves entirely open what they're to be used for. Plus besides introducing dead code (even if only transiently), you also introduce cf_check marked code which isn't really called indirectly from anywhere. Yet we'd like to keep the amount of these markings down (in the final binary, not so much in source code).

Jan

#8 lore raw
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Stewart Hildebrand

This small series enables vPCI to filter which PCI capabilites we expose to a domU. This series adds vPCI register handlers within xen/drivers/vpci/header.c:init_bars(), along with some supporting functions.

Note there are minor rebase conflicts with the in-progress vPCI series [1]. These conflicts fall into the category of functions and code being added adjacent to one another, so are easily resolved. I did not identify any dependency on the vPCI locking work, and the two series deal with different aspects of emulating the PCI header.

Future work may involve adding handlers for more registers in the vPCI header, such as STATUS, VID/DID, etc.

[1] https://lists.xenproject.org/archives/html/xen-devel/2023-07/msg01281.html

Quoted 7 lines
Quoted 4 lines

Stewart Hildebrand (3):
xen/vpci: add vpci_hw_read8 helper
xen/vpci: add vpci_read_val helper
xen/vpci: header: filter PCI capabilities

I'm not convinced of the split here: Seeing the new helpers in isolation leaves entirely open what they're to be used for.

Our code review guide [2] (section "General Patterns") explicitly suggests separating independent helper functions into (a) separate patch(es). Whether it is one patch per helper, or all helpers in a single patch appears ambiguous. That said, I'd still be happy to squash all these into a single patch to avoid the transient dead code situation - please confirm.

Quoted 5 lines

Plus besides introducing
dead code (even if only transiently), you also introduce cf_check marked code which isn't really called indirectly from anywhere. Yet we'd like to keep the amount of these markings down (in the final binary, not so much in source code).

The helper functions will be added to struct vpci_register objects, where they will be called from vpci.c:vpci_read():

    val = r->read(pdev, r->offset, r->private);

Does this justify the cf_check attribute?
If so, should the cf_check attributes rather be added once the helpers are actually used in the patch "xen/vpci: header: filter PCI capabilities"?

[2] http://xenbits.xenproject.org/governance/code-review-guide.html

#9 lore raw
Quoted 22 lines · Stewart Hildebrand
Quoted 21 lines · Jan Beulich
Quoted 19 lines · Stewart Hildebrand

This small series enables vPCI to filter which PCI capabilites we expose to a domU. This series adds vPCI register handlers within xen/drivers/vpci/header.c:init_bars(), along with some supporting functions.

Note there are minor rebase conflicts with the in-progress vPCI series [1]. These conflicts fall into the category of functions and code being added adjacent to one another, so are easily resolved. I did not identify any dependency on the vPCI locking work, and the two series deal with different aspects of emulating the PCI header.

Future work may involve adding handlers for more registers in the vPCI header, such as STATUS, VID/DID, etc.

[1] https://lists.xenproject.org/archives/html/xen-devel/2023-07/msg01281.html

Stewart Hildebrand (3):
xen/vpci: add vpci_hw_read8 helper
xen/vpci: add vpci_read_val helper
xen/vpci: header: filter PCI capabilities

Quoted 5 lines
Quoted 2 lines

I'm not convinced of the split here: Seeing the new helpers in isolation leaves entirely open what they're to be used for.

Our code review guide [2] (section "General Patterns") explicitly suggests separating independent helper functions into (a) separate patch(es). Whether it is one patch per helper, or all helpers in a single patch appears ambiguous. That said, I'd still be happy to squash all these into a single patch to avoid the transient dead code situation - please confirm.

I'm not the maintainer of this code, so my confirmation is of limited value, but yes, in the case here I'm of the clear opinion that separating out the helper functions is not helpful. Not doing so will then also ...

Quoted 11 lines
Quoted 5 lines

Plus besides introducing
dead code (even if only transiently), you also introduce cf_check marked code which isn't really called indirectly from anywhere. Yet we'd like to keep the amount of these markings down (in the final binary, not so much in source code).

The helper functions will be added to struct vpci_register objects, where they will be called from vpci.c:vpci_read():

    val = r->read(pdev, r->offset, r->private);

Does this justify the cf_check attribute?

It not only justifies the attribute, it actually demands it, yes. By the time these use sites appear.

Quoted 1 line

If so, should the cf_check attributes rather be added once the helpers are actually used in the patch "xen/vpci: header: filter PCI capabilities"?

... deal with this, by rendering remark and question void.

Quoted 1 line

[2] http://xenbits.xenproject.org/governance/code-review-guide.html

I'll try to remember to add a topic to the next Community Call's agenda. Actively suggesting to (even if just transiently) introduce dead code is in direct conflict with the Misra work. Plus, if such helpers were static, it also suggests actively breaking the build, again just transiently of course.

Jan