Skip to contentSkip to conversation

PCI devices passthrough on Arm, part 3

PATCH In review Stewart Hildebrand 3 participants 6 messages May 8, 2025 – May 9, 2025

lore
Share & tools
lore
#0 lore raw

v21 cover PCI devices passthrough on Arm, part 3

This is next version of vPCI rework. Aim of this series is to prepare ground for introducing PCI support on ARM platform.

in v21:
* drop ("xen/arm: check read handler behavior") as it was committed
* add ("arm/vpci: mask off upper bits in vPCI read mmio handler")

in v20:
- drop ("vpci: acquire d->pci_lock in I/O handlers") as it was unnecessary

in v19:
- ("xen/arm: check read handler behavior") is ready to be committed
- add ("vpci: acquire d->pci_lock in I/O handlers")

in v18:
- address warning in vpci test suite

in v17:
- add ("xen/arm: check read handler behavior")
- drop ("xen/arm: account IO handlers for emulated PCI MSI-X") as it should wait for future work
- drop committed patches

in v16:
- minor updates - see individual patches

in v15:
- reorder so ("arm/vpci: honor access size when returning an error") comes first

in v14:
- drop first 9 patches as they were committed
- updated ("vpci/header: emulate PCI_COMMAND register for guests")

in v13:
- drop ("xen/arm: vpci: permit access to guest vpci space") as it was unnecessary

in v12:
- I (Stewart) coordinated with Volodomyr to send this whole series. So, add my (Stewart) Signed-off-by to all patches.
- The biggest change is to re-work the PCI_COMMAND register patch. Additional feedback has also been addressed - see individual patches.
- Drop ("pci: msi: pass pdev to pci_enable_msi() function") and ("pci: introduce per-domain PCI rwlock") as they were committed
- Rename ("rangeset: add rangeset_empty() function")
to ("rangeset: add rangeset_purge() function")
- Rename ("vpci/header: rework exit path in init_bars")
to ("vpci/header: rework exit path in init_header()")

in v11:
- Added my (Volodymyr) Signed-off-by tag to all patches
- Patch "vpci/header: emulate PCI_COMMAND register for guests" is in intermediate state, because it was agreed to rework it once Stewart's series on register handling are in.
- Addressed comments, please see patch descriptions for details.

in v10:

- Removed patch ("xen/arm: vpci: check guest range"), proper fix for the issue is part of ("vpci/header: emulate PCI_COMMAND register for guests")
- Removed patch ("pci/header: reset the command register when adding devices")
- Added patch ("rangeset: add rangeset_empty() function") because this function is needed in ("vpci/header: handle p2m range sets per BAR")
- Added ("vpci/header: handle p2m range sets per BAR") which addressed an issue discovered by Andrii Chepurnyi during virtio integration
- Added ("pci: msi: pass pdev to pci_enable_msi() function"), which is prereq for ("pci: introduce per-domain PCI rwlock")
- Fixed "Since v9/v8/... " comments in changelogs to reduce confusion. I left "Since" entries for older versions, because they were added by original author of the patches.

in v9:

v9 includes addressed commentes from a previous one. Also it introduces a couple patches from Stewart. This patches are related to vPCI use on ARM. Patch "vpci/header: rework exit path in init_bars" was factored-out from "vpci/header: handle p2m range sets per BAR".

in v8:

The biggest change from previous, mistakenly named, v7 series is how locking is implemented. Instead of d->vpci_rwlock we introduce d->pci_lock which has broader scope, as it protects not only domain's vpci state, but domain's list of PCI devices as well.

As we discussed in IRC with Roger, it is not feasible to rework all the existing code to use the new lock right away. It was agreed that any write access to d->pdev_list will be protected by **both** d->pci_lock in write mode and pcidevs_lock(). Read access on other hand should be protected by either d->pci_lock in read mode or pcidevs_lock(). It is expected that existing code will use pcidevs_lock() and new users will use new rw lock. Of course, this does not mean that new users shall not use pcidevs_lock() when it is appropriate.

Changes from previous versions are described in each separate patch.

Oleksandr Andrushchenko (1):
vpci: translate virtual PCI bus topology for guests

Stewart Hildebrand (1):
arm/vpci: mask off upper bits in vPCI read mmio handler

 tools/tests/vpci/emul.h |  2 +-
 xen/arch/arm/vpci.c     |  6 ++++-
 xen/drivers/vpci/vpci.c | 53 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 8 deletions(-)

base-commit: aea52ce607fe716acc56ad89f07e1513c89018eb

Signature · 1 line
2.49.0
#1 lore raw

PATCH v21 1/2 arm/vpci: mask off upper bits in vPCI read mmio handler

On Arm, we expect read handlers to have the bits above the access size zeroed. vPCI read handlers may return all 1s. Mask off the bits above the access size.

Fixes 9a5e22b64266 ("xen/arm: check read handler behavior")
---
 xen/arch/arm/vpci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vpci.c +1 -1
index b63a356bb4a8..3a3ff5d0812c 100644
@@ -37,7 +37,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
     if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                         1U << info->dabt.size, &data) )
     {
-        *r = data;
+        *r = data & invalid;
         return 1;
     }
 
Signature · 1 line
2.49.0
Reviewed-by on v21 1/2
#2 lore raw

Re: [PATCH v21 1/2] arm/vpci: mask off upper bits in vPCI read mmio handler

Quoted 6 lines · Stewart Hildebrand

On Arm, we expect read handlers to have the bits above the access size zeroed. vPCI read handlers may return all 1s. Mask off the bits above the access size.

Fixes 9a5e22b64266 ("xen/arm: check read handler behavior")
Quoted 20 lines
---
 xen/arch/arm/vpci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vpci.c +1 -1
index b63a356bb4a8..3a3ff5d0812c 100644
@@ -37,7 +37,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
     if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                         1U << info->dabt.size, &data) )
     {
-        *r = data;
+        *r = data & invalid;
         return 1;
     }
 
Signature · 1 line
2.49.0
#3 lore raw

PATCH v21 2/2 vpci: translate virtual PCI bus topology for guests

In reply to Stewart Hildebrand

From: Oleksandr Andrushchenko <[email protected]>

There are two originators for the PCI configuration space access:
1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space.
2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices.

---
In v21:
* adjust #ifdef
* remove redundant return path
In v20:
* call translate_virtual_device() from within locked context of vpci_{read,write}
* update commit message
In v19:
* move locking to pre-patch
In v18:
* address warning in vpci test suite
In v17:
* move lock to inside vpci_translate_virtual_device()
* acks were previously given for Arm [0] and vPCI [1], but since it was two releases ago and the patch has changed, I didn't pick them up

[0] https://lore.kernel.org/xen-devel/[email protected]/
[1] https://lore.kernel.org/xen-devel/Zk70udmiriruMt0r@macbook/

In v15:
- base on top of ("arm/vpci: honor access size when returning an error") In v11:
- Fixed format issues
- Added ASSERT_UNREACHABLE() to the dummy implementation of vpci_translate_virtual_device()
- Moved variable in vpci_sbdf_from_gpa(), now it is easier to follow the logic in the function
Since v9:
- Commend about required lock replaced with ASSERT()
- Style fixes
- call to vpci_translate_virtual_device folded into vpci_sbdf_from_gpa Since v8:
- locks moved out of vpci_translate_virtual_device()
Since v6:
- add pcidevs locking to vpci_translate_virtual_device
- update wrt to the new locking scheme
Since v5:
- add vpci_translate_virtual_device for #ifndef CONFIG_HAS_VPCI_GUEST_SUPPORT case to simplify ifdefery
- add ASSERT(!is_hardware_domain(d)); to vpci_translate_virtual_device
- reset output register on failed virtual SBDF translation
Since v4:
- indentation fixes
- constify struct domain
- updated commit message
- updates to the new locking scheme (pdev->vpci_lock)
Since v3:
- revisit locking
- move code to vpci.c
Since v2:
- pass struct domain instead of struct vcpu
- constify arguments where possible
- gate relevant code with CONFIG_HAS_VPCI_GUEST_SUPPORT
New in v2

---
 tools/tests/vpci/emul.h |  2 +-
 xen/arch/arm/vpci.c     |  4 ++++
 xen/drivers/vpci/vpci.c | 53 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 52 insertions(+), 7 deletions(-)
tools/tests/vpci/emul.h +1 -1
index da446bba86b4..dd048cffbf9d 100644
@@ -89,7 +89,7 @@ typedef union {
 
 #define __hwdom_init
 
-#define is_hardware_domain(d) ((void)(d), false)
+#define is_hardware_domain(d) ((void)(d), true)
 
 #define has_vpci(d) true
 
xen/arch/arm/vpci.c +4 -0
index 3a3ff5d0812c..0ce11ffcc508 100644
@@ -34,6 +34,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
     /* data is needed to prevent a pointer cast on 32bit */
     unsigned long data;
 
+    ASSERT(!bridge == !is_hardware_domain(v->domain));
+
     if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                         1U << info->dabt.size, &data) )
     {
@@ -52,6 +54,8 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
     struct pci_host_bridge *bridge = p;
     pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa);
 
+    ASSERT(!bridge == !is_hardware_domain(v->domain));
+
     return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa),
                            1U << info->dabt.size, r);
 }
xen/drivers/vpci/vpci.c +47 -6

71 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v21 2/2
#4 lore raw

Re: [PATCH v21 2/2] vpci: translate virtual PCI bus topology for guests

Quoted 11 lines · Stewart Hildebrand

From: Oleksandr Andrushchenko <[email protected]>

There are two originators for the PCI configuration space access:
1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space.
2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices.

Quoted 3 lines

There's the addition of the ASSERTs in vpci_mmio_{read,write}() which could do with an ARM maintainer Ack/RB.

Thanks, Roger.

#5 lore raw

Re: [PATCH v21 2/2] vpci: translate virtual PCI bus topology for guests

Quoted 12 lines · Roger Pau Monné
Quoted 11 lines · Stewart Hildebrand

From: Oleksandr Andrushchenko <[email protected]>

There are two originators for the PCI configuration space access:
1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space.
2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices.

Quoted 8 lines
Quoted 3 lines

There's the addition of the ASSERTs in vpci_mmio_{read,write}() which could do with an ARM maintainer Ack/RB.