[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] vpci: translate virtual PCI bus topology for guests
commit ad3ac58a9d54206fdca61edd74b937b27334f65a Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> AuthorDate: Thu May 8 06:46:07 2025 -0400 Commit: Stefano Stabellini <stefano.stabellini@xxxxxxx> CommitDate: Fri May 9 13:58:43 2025 -0700 vpci: translate virtual PCI bus topology for guests 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. Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx> Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx> --- 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(-) diff --git a/tools/tests/vpci/emul.h b/tools/tests/vpci/emul.h index da446bba86..dd048cffbf 100644 --- a/tools/tests/vpci/emul.h +++ b/tools/tests/vpci/emul.h @@ -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 diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3a3ff5d081..0ce11ffcc5 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -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); } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 1e6aa5d799..d2f0f97e0a 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -174,6 +174,35 @@ int vpci_assign_device(struct pci_dev *pdev) } #endif /* __XEN__ */ +/* + * Find the physical device which is mapped to the virtual device + * and translate virtual SBDF to the physical one. + */ +static const struct pci_dev *translate_virtual_device(const struct domain *d, + pci_sbdf_t *sbdf) +{ +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + const struct pci_dev *pdev; + + ASSERT(!is_hardware_domain(d)); + ASSERT(rw_is_locked(&d->pci_lock)); + + for_each_pdev ( d, pdev ) + { + if ( pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf) ) + { + /* Replace guest SBDF with the physical one. */ + *sbdf = pdev->sbdf; + return pdev; + } + } +#else /* !CONFIG_HAS_VPCI_GUEST_SUPPORT */ + ASSERT_UNREACHABLE(); +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ + + return NULL; +} + static int vpci_register_cmp(const struct vpci_register *r1, const struct vpci_register *r2) { @@ -453,9 +482,15 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) * pci_lock is sufficient. */ read_lock(&d->pci_lock); - pdev = pci_get_pdev(d, sbdf); - if ( !pdev && is_hardware_domain(d) ) - pdev = pci_get_pdev(dom_xen, sbdf); + if ( is_hardware_domain(d) ) + { + pdev = pci_get_pdev(d, sbdf); + if ( !pdev ) + pdev = pci_get_pdev(dom_xen, sbdf); + } + else + pdev = translate_virtual_device(d, &sbdf); + if ( !pdev || !pdev->vpci ) { read_unlock(&d->pci_lock); @@ -571,9 +606,15 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, * are modifying BARs, so there is a room for improvement. */ write_lock(&d->pci_lock); - pdev = pci_get_pdev(d, sbdf); - if ( !pdev && is_hardware_domain(d) ) - pdev = pci_get_pdev(dom_xen, sbdf); + if ( is_hardware_domain(d) ) + { + pdev = pci_get_pdev(d, sbdf); + if ( !pdev ) + pdev = pci_get_pdev(dom_xen, sbdf); + } + else + pdev = translate_virtual_device(d, &sbdf); + if ( !pdev || !pdev->vpci ) { /* Ignore writes to read-only devices, which have no ->vpci. */ -- generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |