* [PATCH v3 1/8] arm/pci: Add pci-scan boot argument
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 2/8] xen/dt: pass flags to callback in dt_for_each_range() Mykyta Poturai
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Edward Pickup, Andrew Cooper, Anthony PERARD, Michal Orzel,
Jan Beulich, Julien Grall, Roger Pau Monné,
Stefano Stabellini, Bertrand Marquis, Volodymyr Babchuk,
Luca Fancellu, Stewart Hildebrand, Mykyta Poturai
From: Edward Pickup <Edward.Pickup@arm.com>
This patch adds a Xen boot arguments that, if enabled, causes a call to
existing code to scan pci devices enumerated by the firmware.
This will be needed ahead of dom0less support for pci passthrough on
arm.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* add define for cases when HAS_PCI is not set
v1->v2:
* remove dead code
* don't return errors from pci_init, but report them
changes from previous series:
* remove is_pci_scan_enabled wrapper
* make pci_scan_enabled ro_after_init
* drop debug prints
* drop Edward's SOB
---
docs/misc/xen-command-line.pandoc | 7 +++++++
xen/arch/arm/include/asm/pci.h | 2 ++
xen/arch/arm/pci/pci-host-common.c | 1 +
xen/arch/arm/pci/pci.c | 29 +++++++++++++++++++++++++++--
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc
index 34004ce282..e5f7275bdc 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -2079,6 +2079,13 @@ This option can be specified more than once (up to 8 times at present).
Flag to enable or disable support for PCI passthrough
+### pci-scan (arm)
+> `= <boolean>`
+
+> Default: `false`
+
+Flag to enable or disable Xen PCI scan at boot.
+
### pcid (x86)
> `= <boolean> | xpti=<bool>`
diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h
index 08ffcd4438..0680b2f50c 100644
--- a/xen/arch/arm/include/asm/pci.h
+++ b/xen/arch/arm/include/asm/pci.h
@@ -155,6 +155,8 @@ bool arch_pci_device_physdevop(void);
#else /*!CONFIG_HAS_PCI*/
+#define pci_scan_enabled false
+
struct pci_dev;
static inline void arch_pci_init_pdev(struct pci_dev *pdev) {}
diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index 487c545f3a..d3481b05eb 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -284,6 +284,7 @@ pci_host_common_probe(struct dt_device_node *dev,
}
pci_add_host_bridge(bridge);
+ pci_add_segment(bridge->segment);
return bridge;
diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
index beb1f971fa..49ee003c5e 100644
--- a/xen/arch/arm/pci/pci.c
+++ b/xen/arch/arm/pci/pci.c
@@ -91,8 +91,14 @@ bool arch_pci_device_physdevop(void)
bool __read_mostly pci_passthrough_enabled;
boolean_param("pci-passthrough", pci_passthrough_enabled);
+/* By default pci scan is disabled. */
+static __ro_after_init bool pci_scan_enabled;
+boolean_param("pci-scan", pci_scan_enabled);
+
static int __init pci_init(void)
{
+ int ret;
+
/*
* Enable PCI passthrough when has been enabled explicitly
* (pci-passthrough=on).
@@ -104,9 +110,28 @@ static int __init pci_init(void)
panic("Could not initialize PCI segment 0\n");
if ( acpi_disabled )
- return dt_pci_init();
+ ret = dt_pci_init();
else
- return acpi_pci_init();
+ ret = acpi_pci_init();
+
+ if ( ret < 0 )
+ {
+ printk(XENLOG_ERR "PCI: Failed to initialize PCI host bridges (rc=%d)\n", ret);
+ return 0;
+ }
+
+ if ( pci_scan_enabled )
+ {
+ ret = scan_pci_devices();
+
+ if ( ret < 0 )
+ {
+ printk(XENLOG_ERR "PCI: Failed to scan PCI devices (rc=%d)\n", ret);
+ return 0;
+ }
+ }
+
+ return 0;
}
__initcall(pci_init);
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v3 2/8] xen/dt: pass flags to callback in dt_for_each_range()
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 1/8] arm/pci: Add pci-scan boot argument Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 3/8] xen/vpci: introduce has_vpci_bridge Mykyta Poturai
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Stewart Hildebrand, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk, Mykyta Poturai
From: Stewart Hildebrand <stewart.hildebrand@amd.com>
PCI ranges have prefetchable / non-prefetchable flags that will be
needed in the callback. Pass the flags to the callback.
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* style fixes
v1->v2:
* no changes
---
xen/arch/arm/device.c | 4 ++--
xen/arch/arm/domain_build.c | 3 ++-
xen/arch/arm/include/asm/setup.h | 2 +-
xen/arch/arm/pci/pci-host-common.c | 4 ++--
xen/common/device-tree/device-tree.c | 5 +++--
xen/include/xen/device_tree.h | 2 +-
6 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c
index 74b54cad34..732c84e726 100644
--- a/xen/arch/arm/device.c
+++ b/xen/arch/arm/device.c
@@ -49,7 +49,7 @@ int map_irq_to_domain(struct domain *d, unsigned int irq,
return 0;
}
-int map_range_to_domain(const struct dt_device_node *dev,
+int map_range_to_domain(const struct dt_device_node *dev, uint32_t flags,
uint64_t addr, uint64_t len, void *data)
{
struct map_range_data *mr_data = data;
@@ -325,7 +325,7 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
return res;
}
- res = map_range_to_domain(dev, addr, size, &mr_data);
+ res = map_range_to_domain(dev, 0, addr, size, &mr_data);
if ( res )
return res;
}
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index fb8fbb1650..4bbffdf535 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -762,7 +762,8 @@ int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
}
static int __init handle_pci_range(const struct dt_device_node *dev,
- uint64_t addr, uint64_t len, void *data)
+ uint32_t flags, uint64_t addr, uint64_t len,
+ void *data)
{
struct rangeset *mem_holes = data;
paddr_t start, end;
diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
index 1eaf13bd66..97bc5f90a1 100644
--- a/xen/arch/arm/include/asm/setup.h
+++ b/xen/arch/arm/include/asm/setup.h
@@ -62,7 +62,7 @@ int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev,
int map_irq_to_domain(struct domain *d, unsigned int irq,
bool need_mapping, const char *devname);
-int map_range_to_domain(const struct dt_device_node *dev,
+int map_range_to_domain(const struct dt_device_node *dev, uint32_t flags,
uint64_t addr, uint64_t len, void *data);
struct init_info
diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index d3481b05eb..46e7e3b707 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -418,7 +418,7 @@ int __init pci_host_bridge_mappings(struct domain *d)
bridge->child_ops->need_p2m_hwdom_mapping(d, bridge, addr);
if ( need_mapping )
{
- err = map_range_to_domain(dev, addr, size, &mr_data);
+ err = map_range_to_domain(dev, 0, addr, size, &mr_data);
if ( err )
return err;
}
@@ -433,7 +433,7 @@ int __init pci_host_bridge_mappings(struct domain *d)
* to be page aligned. We should check for alignment but this is not the
* right place for alignment check.
*/
-static int is_bar_valid(const struct dt_device_node *dev,
+static int is_bar_valid(const struct dt_device_node *dev, uint32_t flags,
uint64_t addr, uint64_t len, void *data)
{
struct pdev_bar_check *bar_data = data;
diff --git a/xen/common/device-tree/device-tree.c b/xen/common/device-tree/device-tree.c
index 0b5375f151..5ee1fa4eb1 100644
--- a/xen/common/device-tree/device-tree.c
+++ b/xen/common/device-tree/device-tree.c
@@ -976,7 +976,7 @@ int dt_device_get_paddr(const struct dt_device_node *dev, unsigned int index,
int dt_for_each_range(const struct dt_device_node *dev,
int (*cb)(const struct dt_device_node *dev,
- uint64_t addr, uint64_t length,
+ uint32_t flags, uint64_t addr, uint64_t length,
void *data),
void *data)
{
@@ -1041,13 +1041,14 @@ int dt_for_each_range(const struct dt_device_node *dev,
{
uint64_t a, s;
int ret;
+ uint32_t flags = bus->get_flags(ranges);
memcpy(addr, ranges + na, 4 * pna);
a = __dt_translate_address(dev, addr, "ranges");
s = dt_read_number(ranges + na + pna, ns);
- ret = cb(dev, a, s, data);
+ ret = cb(dev, flags, a, s, data);
if ( ret )
{
dt_dprintk(" -> callback failed=%d\n", ret);
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 06d7643622..1091e34a10 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -667,7 +667,7 @@ int dt_for_each_irq_map(const struct dt_device_node *dev,
*/
int dt_for_each_range(const struct dt_device_node *dev,
int (*cb)(const struct dt_device_node *dev,
- uint64_t addr, uint64_t length,
+ uint32_t flags, uint64_t addr, uint64_t length,
void *data),
void *data);
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v3 3/8] xen/vpci: introduce has_vpci_bridge
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 1/8] arm/pci: Add pci-scan boot argument Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 2/8] xen/dt: pass flags to callback in dt_for_each_range() Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 13:55 ` Jan Beulich
2025-11-18 13:36 ` [PATCH v3 4/8] xen/pci: update DT for hwdom when it uses vpci Mykyta Poturai
` (4 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk,
Roger Pau Monné, Stewart Hildebrand, Mykyta Poturai
From: Stefano Stabellini <stefano.stabellini@amd.com>
With Dom0 now being able to use a virtual bridge we need a way to
distinguish Dom0 using HW bridghe from Dom0 using virtual bridge.
Introduce a new macro has_vpci_bridge that would determine if a domain
should be treated as using HW bridge (only Dom0 with pci-scan disabled)
or as using a virtual one (all DomUs and Dom0 with pci-scan enabled)
Use the macro in drivers/vpci.
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* s/is_hwdom/is_hw_bridge/
v1->v2:
* simplify definition
---
xen/arch/arm/include/asm/pci.h | 1 +
xen/arch/arm/pci/pci.c | 2 +-
| 74 +++++++++++++++++-----------------
xen/drivers/vpci/vpci.c | 4 +-
xen/include/xen/vpci.h | 8 ++++
5 files changed, 50 insertions(+), 39 deletions(-)
diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h
index 0680b2f50c..7289f7688b 100644
--- a/xen/arch/arm/include/asm/pci.h
+++ b/xen/arch/arm/include/asm/pci.h
@@ -23,6 +23,7 @@
#define pci_to_dev(pcidev) (&(pcidev)->arch.dev)
extern bool pci_passthrough_enabled;
+extern bool pci_scan_enabled;
struct rangeset;
diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
index 49ee003c5e..951639eb3f 100644
--- a/xen/arch/arm/pci/pci.c
+++ b/xen/arch/arm/pci/pci.c
@@ -92,7 +92,7 @@ bool __read_mostly pci_passthrough_enabled;
boolean_param("pci-passthrough", pci_passthrough_enabled);
/* By default pci scan is disabled. */
-static __ro_after_init bool pci_scan_enabled;
+__ro_after_init bool pci_scan_enabled;
boolean_param("pci-scan", pci_scan_enabled);
static int __init pci_init(void)
--git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index 469f497744..528e8b660b 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -230,7 +230,7 @@ bool vpci_process_pending(struct vcpu *v)
read_unlock(&v->domain->pci_lock);
- if ( !is_hardware_domain(v->domain) )
+ if ( has_vpci_bridge(v->domain) )
domain_crash(v->domain);
return false;
@@ -492,7 +492,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
}
}
- if ( !is_hardware_domain(d) )
+ if ( has_vpci_bridge(d) )
break;
d = dom_xen;
@@ -522,7 +522,7 @@ static void cf_check cmd_write(
{
struct vpci_header *header = data;
- if ( !is_hardware_domain(pdev->domain) )
+ if ( has_vpci_bridge(pdev->domain) )
{
const struct vpci *vpci = pdev->vpci;
@@ -564,7 +564,7 @@ static void cf_check bar_write(
struct vpci_bar *bar = data;
bool hi = false;
- ASSERT(is_hardware_domain(pdev->domain));
+ ASSERT(!has_vpci_bridge(pdev->domain));
if ( bar->type == VPCI_BAR_MEM64_HI )
{
@@ -747,7 +747,7 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
{
int rc;
bool mask_cap_list = false;
- bool is_hwdom = is_hardware_domain(pdev->domain);
+ bool is_hw_bridge = !has_vpci_bridge(pdev->domain);
if ( pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST )
{
@@ -758,17 +758,17 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
PCI_CAP_ID_MSIX,
};
/*
- * For dom0, we should expose all capabilities instead of a fixed
+ * For hw bridge, we should expose all capabilities instead of a fixed
* capabilities array, so setting n to 0 here is to get the next
* capability position directly in pci_find_next_cap_ttl.
*/
- const unsigned int n = is_hwdom ? 0 : ARRAY_SIZE(supported_caps);
+ const unsigned int n = is_hw_bridge ? 0 : ARRAY_SIZE(supported_caps);
next = pci_find_next_cap_ttl(pdev->sbdf, PCI_CAPABILITY_LIST,
supported_caps, n, &ttl);
rc = vpci_add_register(pdev->vpci, vpci_read_val,
- is_hwdom ? vpci_hw_write8 : NULL,
+ is_hw_bridge ? vpci_hw_write8 : NULL,
PCI_CAPABILITY_LIST, 1,
(void *)(uintptr_t)next);
if ( rc )
@@ -776,7 +776,7 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
next &= ~3;
- if ( !next && !is_hwdom )
+ if ( !next && !is_hw_bridge )
/*
* If we don't have any supported capabilities to expose to the
* guest, mask the PCI_STATUS_CAP_LIST bit in the status
@@ -792,7 +792,7 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
pos + PCI_CAP_LIST_NEXT,
supported_caps, n, &ttl);
- if ( !is_hwdom )
+ if ( !is_hw_bridge )
{
rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
pos + PCI_CAP_LIST_ID, 1, NULL);
@@ -801,7 +801,7 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
}
rc = vpci_add_register(pdev->vpci, vpci_read_val,
- is_hwdom ? vpci_hw_write8 : NULL,
+ is_hw_bridge ? vpci_hw_write8 : NULL,
pos + PCI_CAP_LIST_NEXT, 1,
(void *)(uintptr_t)next);
if ( rc )
@@ -811,8 +811,8 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
}
}
- /* Return early for the hw domain, no masking of PCI_STATUS. */
- if ( is_hwdom )
+ /* Return early for the hw bridge, no masking of PCI_STATUS. */
+ if ( is_hw_bridge )
return 0;
/* Utilize rsvdp_mask to hide PCI_STATUS_CAP_LIST from the guest. */
@@ -829,7 +829,7 @@ static int vpci_init_ext_capability_list(const struct pci_dev *pdev)
{
unsigned int pos = PCI_CFG_SPACE_SIZE;
- if ( !is_hardware_domain(pdev->domain) )
+ if ( has_vpci_bridge(pdev->domain) )
/* Extended capabilities read as zero, write ignore for DomU */
return vpci_add_register(pdev->vpci, vpci_read_val, NULL,
pos, 4, (void *)0);
@@ -866,7 +866,7 @@ int vpci_init_header(struct pci_dev *pdev)
struct vpci_header *header = &pdev->vpci->header;
struct vpci_bar *bars = header->bars;
int rc;
- bool is_hwdom = is_hardware_domain(pdev->domain);
+ bool is_hw_bridge = !has_vpci_bridge(pdev->domain);
ASSERT(rw_is_write_locked(&pdev->domain->pci_lock));
@@ -893,15 +893,15 @@ int vpci_init_header(struct pci_dev *pdev)
* PCI_COMMAND_PARITY, PCI_COMMAND_SERR, and PCI_COMMAND_FAST_BACK.
*/
rc = vpci_add_register_mask(pdev->vpci,
- is_hwdom ? vpci_hw_read16 : guest_cmd_read,
+ is_hw_bridge ? vpci_hw_read16 : guest_cmd_read,
cmd_write, PCI_COMMAND, 2, header, 0, 0,
- is_hwdom ? 0
- : PCI_COMMAND_RSVDP_MASK |
- PCI_COMMAND_IO |
- PCI_COMMAND_PARITY |
- PCI_COMMAND_WAIT |
- PCI_COMMAND_SERR |
- PCI_COMMAND_FAST_BACK,
+ is_hw_bridge ? 0
+ : PCI_COMMAND_RSVDP_MASK |
+ PCI_COMMAND_IO |
+ PCI_COMMAND_PARITY |
+ PCI_COMMAND_WAIT |
+ PCI_COMMAND_SERR |
+ PCI_COMMAND_FAST_BACK,
0);
if ( rc )
return rc;
@@ -925,7 +925,7 @@ int vpci_init_header(struct pci_dev *pdev)
* start with memory decoding disabled, and modify_bars() will not be called
* at the end of this function.
*/
- if ( !is_hwdom )
+ if ( !is_hw_bridge )
cmd &= ~(PCI_COMMAND_VGA_PALETTE | PCI_COMMAND_INVALIDATE |
PCI_COMMAND_SPECIAL | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
PCI_COMMAND_IO);
@@ -933,7 +933,7 @@ int vpci_init_header(struct pci_dev *pdev)
header->guest_cmd = cmd;
/* Disable memory decoding before sizing. */
- if ( !is_hwdom || (cmd & PCI_COMMAND_MEMORY) )
+ if ( !is_hw_bridge || (cmd & PCI_COMMAND_MEMORY) )
pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY);
for ( i = 0; i < num_bars; i++ )
@@ -945,9 +945,10 @@ int vpci_init_header(struct pci_dev *pdev)
{
bars[i].type = VPCI_BAR_MEM64_HI;
rc = vpci_add_register(pdev->vpci,
- is_hwdom ? vpci_hw_read32
- : guest_mem_bar_read,
- is_hwdom ? bar_write : guest_mem_bar_write,
+ is_hw_bridge ? vpci_hw_read32
+ : guest_mem_bar_read,
+ is_hw_bridge ? bar_write
+ : guest_mem_bar_write,
reg, 4, &bars[i]);
if ( rc )
goto fail;
@@ -959,7 +960,7 @@ int vpci_init_header(struct pci_dev *pdev)
if ( (val & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO )
{
bars[i].type = VPCI_BAR_IO;
- if ( !IS_ENABLED(CONFIG_X86) && !is_hwdom )
+ if ( !IS_ENABLED(CONFIG_X86) && !is_hw_bridge )
{
rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
reg, 4, (void *)0);
@@ -988,7 +989,7 @@ int vpci_init_header(struct pci_dev *pdev)
{
bars[i].type = VPCI_BAR_EMPTY;
- if ( !is_hwdom )
+ if ( !is_hw_bridge )
{
rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
reg, 4, (void *)0);
@@ -1005,17 +1006,18 @@ int vpci_init_header(struct pci_dev *pdev)
bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH;
rc = vpci_add_register(pdev->vpci,
- is_hwdom ? vpci_hw_read32 : guest_mem_bar_read,
- is_hwdom ? bar_write : guest_mem_bar_write,
+ is_hw_bridge ? vpci_hw_read32
+ : guest_mem_bar_read,
+ is_hw_bridge ? bar_write : guest_mem_bar_write,
reg, 4, &bars[i]);
if ( rc )
goto fail;
}
/* Check expansion ROM. */
- rc = is_hwdom ? pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size,
- PCI_BAR_ROM)
- : 0;
+ rc = is_hw_bridge ? pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size,
+ PCI_BAR_ROM)
+ : 0;
if ( rc > 0 && size )
{
struct vpci_bar *rom = &header->bars[num_bars];
@@ -1038,7 +1040,7 @@ int vpci_init_header(struct pci_dev *pdev)
goto fail;
}
}
- else if ( !is_hwdom )
+ else if ( !is_hw_bridge )
{
/* TODO: Check expansion ROM, we do not handle ROM for guests for now */
header->bars[num_bars].type = VPCI_BAR_EMPTY;
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index 07c7071d0a..8ea89b9805 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -48,7 +48,7 @@ static int assign_virtual_sbdf(struct pci_dev *pdev)
ASSERT(rw_is_write_locked(&pdev->domain->pci_lock));
- if ( is_hardware_domain(d) )
+ if ( !has_vpci_bridge(d) )
return 0;
/*
@@ -429,7 +429,7 @@ static const struct pci_dev *translate_virtual_device(const struct domain *d,
#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
const struct pci_dev *pdev;
- ASSERT(!is_hardware_domain(d));
+ ASSERT(has_vpci_bridge(d));
ASSERT(rw_is_locked(&d->pci_lock));
for_each_pdev ( d, pdev )
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 9ae75d946a..d4695cb353 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -339,6 +339,14 @@ static inline int __must_check vpci_reset_device(struct pci_dev *pdev)
return vpci_assign_device(pdev);
}
+#ifdef CONFIG_ARM
+#include <asm/pci.h>
+
+#define has_vpci_bridge(d) (!is_hardware_domain(d) || pci_scan_enabled)
+#else
+#define has_vpci_bridge(d) (!is_hardware_domain(d))
+#endif
+
#endif
/*
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v3 3/8] xen/vpci: introduce has_vpci_bridge
2025-11-18 13:36 ` [PATCH v3 3/8] xen/vpci: introduce has_vpci_bridge Mykyta Poturai
@ 2025-11-18 13:55 ` Jan Beulich
0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2025-11-18 13:55 UTC (permalink / raw)
To: Mykyta Poturai, Stefano Stabellini
Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
Volodymyr Babchuk, Roger Pau Monné, Stewart Hildebrand,
xen-devel@lists.xenproject.org
On 18.11.2025 14:36, Mykyta Poturai wrote:
> From: Stefano Stabellini <stefano.stabellini@amd.com>
>
> With Dom0 now being able to use a virtual bridge we need a way to
> distinguish Dom0 using HW bridghe from Dom0 using virtual bridge.
> Introduce a new macro has_vpci_bridge that would determine if a domain
> should be treated as using HW bridge (only Dom0 with pci-scan disabled)
> or as using a virtual one (all DomUs and Dom0 with pci-scan enabled)
Where does the connection of "pci-scan {en,dis}abled" with "kind of bridges
in use" come from? There is a connection for what you're trying to achieve
right now, but this doesn't want setting in stone now, to avoid making it
harder to decouple the two again later.
> --- a/xen/drivers/vpci/header.c
> +++ b/xen/drivers/vpci/header.c
> @@ -230,7 +230,7 @@ bool vpci_process_pending(struct vcpu *v)
>
> read_unlock(&v->domain->pci_lock);
>
> - if ( !is_hardware_domain(v->domain) )
> + if ( has_vpci_bridge(v->domain) )
> domain_crash(v->domain);
At this example (applies more or less similarly elsewhere as well, and needs
answering separately for every instance), and effectively re-iterating a
point made previously: Why is it the kind of bridges that are used which
determines whether to call domain_crash() here?
Jan
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 4/8] xen/pci: update DT for hwdom when it uses vpci
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
` (2 preceding siblings ...)
2025-11-18 13:36 ` [PATCH v3 3/8] xen/vpci: introduce has_vpci_bridge Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 5/8] arm/pci: Mark pci_host_common_probe as init Mykyta Poturai
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Luca Fancellu, Andrew Cooper, Anthony PERARD, Michal Orzel,
Jan Beulich, Julien Grall, Roger Pau Monné,
Stefano Stabellini, Bertrand Marquis, Volodymyr Babchuk,
Stewart Hildebrand, Mykyta Poturai
From: Luca Fancellu <luca.fancellu@arm.com>
When pci-scan is enabled and Xen supports vpci for guests, Xen will
scan the pci bus to find devices and emulate the pci bus, so the hw
domain must see the emulated bus instead of the real one.
A new helper function, hwdom_uses_vpci, is implemented and returns true
when pci-scan is enabled and Xen is built with
CONFIG_HAS_VPCI_GUEST_SUPPORT=y. When hwdom_uses_vpci() is true, a vpci
node is created for the hwdom device tree.
Depending on whether the guest is using vPCI or not, and whether the
domain is using host layout or not, generate the appropriate device tree
nodes for the guest and handle the right MMIO regions traps.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* use has_vpci_bridge in place of hwdom_uses_vpci
v1->v2:
* make make_vpci_node static
---
docs/misc/xen-command-line.pandoc | 4 +-
xen/arch/arm/domain_build.c | 151 +++++++++++++++++++++++++++++-
2 files changed, 153 insertions(+), 2 deletions(-)
diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc
index e5f7275bdc..4a546f94a7 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -2084,7 +2084,9 @@ Flag to enable or disable support for PCI passthrough
> Default: `false`
-Flag to enable or disable Xen PCI scan at boot.
+Flag to enable or disable Xen PCI scan at boot. When the flag is enabled, the
+hardware domain cannot have access to the real PCI bus, it will see the bus
+emulated by Xen.
### pcid (x86)
> `= <boolean> | xpti=<bool>`
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 4bbffdf535..7423605b61 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -41,6 +41,7 @@
#include <xen/grant_table.h>
#include <asm/grant_table.h>
#include <xen/serial.h>
+#include <xen/resource.h>
static unsigned int __initdata opt_dom0_max_vcpus;
integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);
@@ -1557,6 +1558,142 @@ int __init make_chosen_node(const struct kernel_info *kinfo)
return res;
}
+#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
+struct vpci_param {
+ uint64_t vpci_ecam_base;
+ uint64_t vpci_ecam_size;
+ uint64_t vpci_mem_base;
+ uint64_t vpci_mem_size;
+ uint64_t vpci_mem_prefetch_base;
+ uint64_t vpci_mem_prefetch_size;
+};
+
+static int __init handle_vpci_range(const struct dt_device_node *dev,
+ uint32_t flags, uint64_t addr, uint64_t len,
+ void *data)
+{
+ struct vpci_param *vpci = (struct vpci_param *)data;
+
+ if ( !(flags & IORESOURCE_MEM) )
+ return 0;
+
+ if ( !(flags & IORESOURCE_PREFETCH) && addr < GB(4) )
+ {
+ vpci->vpci_mem_base = addr;
+ vpci->vpci_mem_size = len;
+ }
+ else if ( flags & IORESOURCE_PREFETCH )
+ {
+ vpci->vpci_mem_prefetch_base = addr;
+ vpci->vpci_mem_prefetch_size = len;
+ }
+ return 0;
+}
+
+static int __init make_vpci_node(struct domain *d, void *fdt)
+{
+ /* reg is sized to be used for all the needed properties below */
+ __be32 reg[((GUEST_ROOT_ADDRESS_CELLS * 2) + GUEST_ROOT_SIZE_CELLS + 1)
+ * 2];
+ __be32 *cells;
+ char buf[22]; /* pcie@ + max 16 char address + '\0' */
+ int res;
+ struct vpci_param vpci = {
+ .vpci_ecam_base = GUEST_VPCI_ECAM_BASE,
+ .vpci_ecam_size = GUEST_VPCI_ECAM_SIZE,
+ .vpci_mem_base = GUEST_VPCI_MEM_ADDR,
+ .vpci_mem_size = GUEST_VPCI_MEM_SIZE,
+ .vpci_mem_prefetch_base = GUEST_VPCI_PREFETCH_MEM_ADDR,
+ .vpci_mem_prefetch_size = GUEST_VPCI_PREFETCH_MEM_SIZE
+ };
+
+ if ( domain_use_host_layout(d) )
+ {
+ struct pci_host_bridge *bridge;
+
+ bridge = pci_find_host_bridge(0, 0);
+
+ vpci.vpci_ecam_base = bridge->cfg->phys_addr;
+ vpci.vpci_ecam_size = bridge->cfg->size;
+
+ res = dt_for_each_range(bridge->dt_node, handle_vpci_range, &vpci);
+ if ( res < 0 )
+ return -EINVAL;
+ }
+
+ snprintf(buf, sizeof(buf), "pcie@%"PRIx64, vpci.vpci_ecam_base);
+ dt_dprintk("Create vpci node\n");
+ res = fdt_begin_node(fdt, buf);
+ if ( res )
+ return res;
+
+ res = fdt_property_string(fdt, "compatible", "pci-host-ecam-generic");
+ if ( res )
+ return res;
+
+ res = fdt_property_string(fdt, "device_type", "pci");
+ if ( res )
+ return res;
+
+ /* Create reg property */
+ cells = ®[0];
+ dt_child_set_range(&cells, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS,
+ vpci.vpci_ecam_base, vpci.vpci_ecam_size);
+
+ res = fdt_property(fdt, "reg", reg,
+ (GUEST_ROOT_ADDRESS_CELLS +
+ GUEST_ROOT_SIZE_CELLS) * sizeof(*reg));
+ if ( res )
+ return res;
+
+ /* Create bus-range property */
+ cells = ®[0];
+ dt_set_cell(&cells, 1, 0);
+ dt_set_cell(&cells, 1, 255);
+ res = fdt_property(fdt, "bus-range", reg, 2 * sizeof(*reg));
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "#address-cells", 3);
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "#size-cells", 2);
+ if ( res )
+ return res;
+
+ res = fdt_property_string(fdt, "status", "okay");
+ if ( res )
+ return res;
+
+ /*
+ * Create ranges property as:
+ * <(PCI bitfield) (PCI address) (CPU address) (Size)>
+ */
+ cells = ®[0];
+ dt_set_cell(&cells, 1, GUEST_VPCI_ADDR_TYPE_MEM);
+ dt_set_cell(&cells, GUEST_ROOT_ADDRESS_CELLS, vpci.vpci_mem_base);
+ dt_set_cell(&cells, GUEST_ROOT_ADDRESS_CELLS, vpci.vpci_mem_base);
+ dt_set_cell(&cells, GUEST_ROOT_SIZE_CELLS, vpci.vpci_mem_size);
+ dt_set_cell(&cells, 1, GUEST_VPCI_ADDR_TYPE_PREFETCH_MEM);
+ dt_set_cell(&cells, GUEST_ROOT_ADDRESS_CELLS, vpci.vpci_mem_prefetch_base);
+ dt_set_cell(&cells, GUEST_ROOT_ADDRESS_CELLS, vpci.vpci_mem_prefetch_base);
+ dt_set_cell(&cells, GUEST_ROOT_SIZE_CELLS, vpci.vpci_mem_prefetch_size);
+ res = fdt_property(fdt, "ranges", reg, sizeof(reg));
+ if ( res )
+ return res;
+
+ res = fdt_end_node(fdt);
+
+ return res;
+}
+#else
+static inline int __init make_vpci_node(struct domain *d, void *fdt)
+{
+ return 0;
+}
+#endif
+
static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
struct dt_device_node *node,
p2m_type_t p2mt)
@@ -1615,7 +1752,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
dt_dprintk(" Skip it (blacklisted)\n");
return 0;
}
-
+ /* If Xen is scanning the PCI devices, don't expose real bus to hwdom */
+ if ( has_vpci_bridge(d) && dt_device_type_is_equal(node, "pci") )
+ {
+ dt_dprintk(" Skip it (pci-scan is enabled)\n");
+ return 0;
+ }
/*
* Replace these nodes with our own. Note that the original may be
* used_by DOMID_XEN so this check comes first.
@@ -1766,6 +1908,13 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
if ( res )
return res;
}
+
+ if ( has_vpci_bridge(d) )
+ {
+ res = make_vpci_node(d, kinfo->fdt);
+ if ( res )
+ return res;
+ }
}
res = fdt_end_node(kinfo->fdt);
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v3 5/8] arm/pci: Mark pci_host_common_probe as init
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
` (3 preceding siblings ...)
2025-11-18 13:36 ` [PATCH v3 4/8] xen/pci: update DT for hwdom when it uses vpci Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 6/8] xen/pci: initialize BARs Mykyta Poturai
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Mykyta Poturai, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
pci_host_common_probe is only ever called from init context so mark it
as such.
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* patch introduced
---
xen/arch/arm/pci/pci-host-common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index 46e7e3b707..de30fb0aec 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -232,7 +232,7 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev)
return domain;
}
-struct pci_host_bridge *
+struct pci_host_bridge * __init
pci_host_common_probe(struct dt_device_node *dev,
const struct pci_ecam_ops *ops,
const struct pci_ecam_ops *child_ops)
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v3 6/8] xen/pci: initialize BARs
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
` (4 preceding siblings ...)
2025-11-18 13:36 ` [PATCH v3 5/8] arm/pci: Mark pci_host_common_probe as init Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 14:41 ` Jan Beulich
2025-11-18 13:36 ` [PATCH v3 7/8] xen/pci: assign discovered devices to hwdom Mykyta Poturai
2025-11-18 13:36 ` [PATCH v3 8/8] arm/pci: enable vpci for hwdom when pci-scan is enabled Mykyta Poturai
7 siblings, 1 reply; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Stewart Hildebrand, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Jan Beulich, Roger Pau Monné, Mykyta Poturai
From: Stewart Hildebrand <stewart.hildebrand@amd.com>
A PCI device must have valid BARs in order to assign it to a domain. On
ARM, firmware is unlikely to have initialized the BARs, so we must do
this in Xen. During setup_hwdom_pci_devices(), check if each BAR is
valid. If the BAR happens to already be valid, remove the BAR range from
a rangeset of valid PCI ranges so as to avoid overlap when reserving a
new BAR. If not valid, reserve a new BAR address from the rangeset and
write it to the device.
Avaliable ranges are read from DT during init and stored in two distinct
rangesets, one for prefetchable and one for non-prefetchable BARs.
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* drop hwdom_uses_vpci
* check that rangeset can handle u64
* rework rangeset manipulaiton
* mark more functions as __init
* move bar init to arm files
* style fixes
v1->v2:
* move hwdom_uses_vpci to this patch
* fixup error reporting
---
xen/arch/arm/include/asm/pci.h | 7 ++
xen/arch/arm/pci/pci-host-common.c | 92 ++++++++++++++++++++++++
xen/arch/arm/pci/pci.c | 110 +++++++++++++++++++++++++++++
xen/common/rangeset.c | 62 ++++++++++++++--
xen/include/xen/rangeset.h | 11 +++
5 files changed, 277 insertions(+), 5 deletions(-)
diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h
index 7289f7688b..ac4e87f9c1 100644
--- a/xen/arch/arm/include/asm/pci.h
+++ b/xen/arch/arm/include/asm/pci.h
@@ -74,6 +74,8 @@ struct pci_host_bridge {
struct pci_config_window *child_cfg;
const struct pci_ops *child_ops;
void *priv; /* Private data of the bridge. */
+ struct rangeset *bar_ranges;
+ struct rangeset *bar_ranges_prefetch;
};
struct pci_ops {
@@ -154,6 +156,11 @@ void pci_generic_init_bus_range_child(struct dt_device_node *dev,
bool arch_pci_device_physdevop(void);
+uint64_t pci_get_new_bar_addr(const struct pci_dev *pdev, uint64_t size,
+ bool is_64bit, bool prefetch);
+int pci_reserve_bar_range(const struct pci_dev *pdev, uint64_t addr,
+ uint64_t size, bool prefetch);
+
#else /*!CONFIG_HAS_PCI*/
#define pci_scan_enabled false
diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index de30fb0aec..28c26af9eb 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -21,6 +21,7 @@
#include <xen/rwlock.h>
#include <xen/sched.h>
#include <xen/vmap.h>
+#include <xen/resource.h>
#include <asm/setup.h>
@@ -232,6 +233,25 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev)
return domain;
}
+static int __init add_bar_range(const struct dt_device_node *dev,
+ uint32_t flags, uint64_t addr, uint64_t len,
+ void *data)
+{
+ struct pci_host_bridge *bridge = data;
+
+ /* Ensure we are not using bits in a rangeset */
+ BUILD_BUG_ON(sizeof(unsigned long) != sizeof(uint64_t));
+
+ if ( !(flags & IORESOURCE_MEM) )
+ return 0;
+
+ if ( flags & IORESOURCE_PREFETCH )
+ return rangeset_add_range(bridge->bar_ranges_prefetch, addr,
+ addr + len - 1);
+ else
+ return rangeset_add_range(bridge->bar_ranges, addr, addr + len - 1);
+}
+
struct pci_host_bridge * __init
pci_host_common_probe(struct dt_device_node *dev,
const struct pci_ecam_ops *ops,
@@ -283,6 +303,18 @@ pci_host_common_probe(struct dt_device_node *dev,
bridge->child_ops = &child_ops->pci_ops;
}
+ bridge->bar_ranges = rangeset_new(NULL, "BAR ranges",
+ RANGESETF_prettyprint_hex);
+ bridge->bar_ranges_prefetch = rangeset_new(NULL,
+ "BAR ranges (prefetchable)",
+ RANGESETF_prettyprint_hex);
+ if ( bridge->bar_ranges && bridge->bar_ranges_prefetch )
+ {
+ err = dt_for_each_range(bridge->dt_node, add_bar_range, bridge);
+ if ( err )
+ goto err_child;
+ }
+
pci_add_host_bridge(bridge);
pci_add_segment(bridge->segment);
@@ -476,6 +508,66 @@ bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end)
return bar_data.is_valid;
}
+
+/*
+ * Find suitable place for an uninitialized bar of specified size in the
+ * host bridge ranges
+ */
+uint64_t __init pci_get_new_bar_addr(const struct pci_dev *pdev, uint64_t size,
+ bool is_64bit, bool prefetch)
+{
+ struct pci_host_bridge *bridge;
+ struct rangeset *range;
+ uint64_t addr = 0, end = GB(4);
+
+ /* Make sure we can store addr in a rangeset */
+ BUILD_BUG_ON(sizeof(addr) != sizeof(unsigned long));
+
+ bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
+ if ( !bridge )
+ return 0;
+
+ range = prefetch ? bridge->bar_ranges_prefetch : bridge->bar_ranges;
+
+ if ( size < PAGE_SIZE )
+ size = PAGE_SIZE;
+
+ if ( is_64bit )
+ {
+ addr = GB(4);
+ end = ~0;
+ }
+
+ if ( !rangeset_claim_aligned_range(range, size, &addr, end) )
+ return addr;
+
+ printk(XENLOG_ERR "Failed to claim BAR range %lx-%lx from rangeset\n",
+ addr, addr + size - 1);
+
+ return 0;
+}
+
+/*
+ * Remove already used memory from the host bridge bar ranges
+ */
+int __init pci_reserve_bar_range(const struct pci_dev *pdev, uint64_t addr,
+ uint64_t size, bool prefetch)
+{
+ struct pci_host_bridge *bridge;
+ struct rangeset *range;
+
+ /* Make sure we can store addr in a rangeset */
+ BUILD_BUG_ON(sizeof(addr) != sizeof(unsigned long));
+
+ bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
+ if ( !bridge )
+ return 0;
+
+ range = prefetch ? bridge->bar_ranges_prefetch : bridge->bar_ranges;
+
+ return rangeset_remove_range(range, addr, addr + size - 1);
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
index 951639eb3f..0330220e93 100644
--- a/xen/arch/arm/pci/pci.c
+++ b/xen/arch/arm/pci/pci.c
@@ -95,6 +95,108 @@ boolean_param("pci-passthrough", pci_passthrough_enabled);
__ro_after_init bool pci_scan_enabled;
boolean_param("pci-scan", pci_scan_enabled);
+typedef int (*bar_callback_t)(struct pci_dev *, uint8_t, uint64_t, uint64_t,
+ bool, bool);
+
+static int __init reserve_bar_range(struct pci_dev *pdev, uint8_t reg,
+ uint64_t addr, uint64_t size, bool is_64bit,
+ bool prefetch)
+{
+ if ( pci_check_bar(pdev, maddr_to_mfn(addr),
+ maddr_to_mfn(addr + size - 1)) )
+ return pci_reserve_bar_range(pdev, addr, size, prefetch);
+ return 0;
+}
+
+static int __init setup_bar(struct pci_dev *pdev, uint8_t reg, uint64_t addr,
+ uint64_t size, bool is_64bit, bool prefetch)
+{
+ if ( !pci_check_bar(pdev, maddr_to_mfn(addr),
+ maddr_to_mfn(addr + size - 1)) )
+ {
+ uint16_t cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
+
+ addr = pci_get_new_bar_addr(pdev, size, is_64bit, prefetch);
+ if ( !addr )
+ return -ENOMEM;
+
+ pci_conf_write16(pdev->sbdf, PCI_COMMAND,
+ cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+
+ pci_conf_write32(pdev->sbdf, reg,
+ (addr & GENMASK(31, 0)) |
+ (is_64bit ? PCI_BASE_ADDRESS_MEM_TYPE_64 : 0));
+
+ if ( is_64bit )
+ pci_conf_write32(pdev->sbdf, reg + 4, addr >> 32);
+
+ pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
+ }
+
+ return 0;
+}
+
+static int __init bars_iterate(struct pci_dev *pdev, void *arg)
+{
+ unsigned int i, barsize, ret = 0, num_bars = PCI_HEADER_NORMAL_NR_BARS;
+ uint64_t addr, size;
+ bar_callback_t cb = arg;
+
+ if ( (pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f) ==
+ PCI_HEADER_TYPE_NORMAL )
+ {
+ for ( i = 0; i < num_bars; i += barsize )
+ {
+ uint8_t reg = PCI_BASE_ADDRESS_0 + i * 4;
+ bool prefetch;
+
+ if ( (pci_conf_read32(pdev->sbdf, reg) & PCI_BASE_ADDRESS_SPACE) ==
+ PCI_BASE_ADDRESS_SPACE_IO )
+ {
+ barsize = 1;
+ continue;
+ }
+
+ barsize = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size,
+ (i == num_bars - 1) ? PCI_BAR_LAST : 0);
+
+ if ( !size )
+ continue;
+
+ prefetch = pci_conf_read32(pdev->sbdf, reg) &
+ PCI_BASE_ADDRESS_MEM_PREFETCH;
+
+ ret = cb(pdev, reg, addr, size, barsize == 2, prefetch);
+ if ( ret )
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+static int __init pci_setup_bars(void)
+{
+ int ret;
+ /* We can't change the signature of bars_iterate to only accept
+ * bar_callback_t, so use intermediate variables to ensure callback
+ * signatures are always correct
+ */
+ bar_callback_t cb_reserve = reserve_bar_range;
+ bar_callback_t cb_setup = setup_bar;
+
+ pcidevs_lock();
+ ret = pci_iterate_devices(bars_iterate, cb_reserve);
+ if ( ret )
+ goto out;
+
+ ret = pci_iterate_devices(bars_iterate, cb_setup);
+
+out:
+ pcidevs_unlock();
+ return ret;
+}
+
static int __init pci_init(void)
{
int ret;
@@ -129,6 +231,14 @@ static int __init pci_init(void)
printk(XENLOG_ERR "PCI: Failed to scan PCI devices (rc=%d)\n", ret);
return 0;
}
+
+ ret = pci_setup_bars();
+
+ if ( ret < 0 )
+ {
+ printk(XENLOG_ERR "PCI: Failed to configure BARs (rc=%d)\n", ret);
+ return 0;
+ }
}
return 0;
diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index 0e3b9acd35..6a0c20ab41 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -180,16 +180,13 @@ int rangeset_add_range(
return rc;
}
-int rangeset_remove_range(
- struct rangeset *r, unsigned long s, unsigned long e)
+static int remove_range(struct rangeset *r, unsigned long s, unsigned long e)
{
struct range *x, *y, *t;
int rc = 0;
ASSERT(s <= e);
- write_lock(&r->lock);
-
x = find_range(r, s);
y = find_range(r, e);
@@ -244,8 +241,18 @@ int rangeset_remove_range(
destroy_range(r, x);
}
- out:
+out:
+ return rc;
+}
+
+int rangeset_remove_range(struct rangeset *r, unsigned long s, unsigned long e)
+{
+ int rc = 0;
+
+ write_lock(&r->lock);
+ rc = remove_range(r, s, e);
write_unlock(&r->lock);
+
return rc;
}
@@ -357,6 +364,51 @@ int rangeset_claim_range(struct rangeset *r, unsigned long size,
return 0;
}
+int rangeset_claim_aligned_range(struct rangeset *r, unsigned long size,
+ unsigned long *s, unsigned long e)
+{
+ struct range *x;
+ int rc = 0;
+
+ /* Power of 2 check */
+ if ( (size & (size - 1)) != 0 && size != 0 )
+ {
+ *s = 0;
+ return -EINVAL;
+ }
+
+ if ( e < *s )
+ return -EINVAL;
+
+ write_lock(&r->lock);
+
+ for ( x = first_range(r); x; x = next_range(r, x) )
+ {
+ /* Assumes size is a power of 2 */
+ unsigned long start_aligned = ROUNDUP(x->s, size);
+
+ if ( x->e > start_aligned &&
+ (x->e - start_aligned) >= size &&
+ start_aligned >= *s &&
+ start_aligned + size <= e)
+ {
+ rc = remove_range(r, start_aligned, start_aligned + size - 1);
+ if ( !rc )
+ *s = start_aligned;
+ else
+ *s = 0;
+
+ write_unlock(&r->lock);
+ return rc;
+ }
+ }
+
+ *s = 0;
+
+ write_unlock(&r->lock);
+ return -ENOSPC;
+}
+
int rangeset_consume_ranges(struct rangeset *r,
int (*cb)(unsigned long s, unsigned long e,
void *ctxt, unsigned long *c),
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index 817505badf..dcef96cb2c 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -61,6 +61,17 @@ int __must_check rangeset_add_range(
struct rangeset *r, unsigned long s, unsigned long e);
int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size,
unsigned long *s);
+
+/*
+ * Find a range subset that starts at or after s, ends before e,
+ * and is aligned to the size.
+ * If such subset is present it is removed from the rangeset and
+ * it's start is written to s, otherwise s is set to 0.
+ */
+int __must_check rangeset_claim_aligned_range(struct rangeset *r,
+ unsigned long size,
+ unsigned long *s,
+ unsigned long e);
int __must_check rangeset_remove_range(
struct rangeset *r, unsigned long s, unsigned long e);
bool __must_check rangeset_contains_range(
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v3 6/8] xen/pci: initialize BARs
2025-11-18 13:36 ` [PATCH v3 6/8] xen/pci: initialize BARs Mykyta Poturai
@ 2025-11-18 14:41 ` Jan Beulich
0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2025-11-18 14:41 UTC (permalink / raw)
To: Mykyta Poturai
Cc: Stewart Hildebrand, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné,
xen-devel@lists.xenproject.org
On 18.11.2025 14:36, Mykyta Poturai wrote:
> @@ -232,6 +233,25 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev)
> return domain;
> }
>
> +static int __init add_bar_range(const struct dt_device_node *dev,
> + uint32_t flags, uint64_t addr, uint64_t len,
> + void *data)
> +{
> + struct pci_host_bridge *bridge = data;
> +
> + /* Ensure we are not using bits in a rangeset */
> + BUILD_BUG_ON(sizeof(unsigned long) != sizeof(uint64_t));
Can you please help me interpret the comment?
Also, rather than != isn't < sufficient to check for?
> @@ -283,6 +303,18 @@ pci_host_common_probe(struct dt_device_node *dev,
> bridge->child_ops = &child_ops->pci_ops;
> }
>
> + bridge->bar_ranges = rangeset_new(NULL, "BAR ranges",
> + RANGESETF_prettyprint_hex);
> + bridge->bar_ranges_prefetch = rangeset_new(NULL,
> + "BAR ranges (prefetchable)",
> + RANGESETF_prettyprint_hex);
> + if ( bridge->bar_ranges && bridge->bar_ranges_prefetch )
> + {
> + err = dt_for_each_range(bridge->dt_node, add_bar_range, bridge);
> + if ( err )
> + goto err_child;
> + }
I'm pretty sure I commented on this already: Without an "else" use sites
of the two rangesets need to have NULL checks added, plus imo there would
want to be a comment here explaining to readers why omitting the "else"
(and hence proper error handling) is okay.
> @@ -476,6 +508,66 @@ bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end)
>
> return bar_data.is_valid;
> }
> +
> +/*
> + * Find suitable place for an uninitialized bar of specified size in the
> + * host bridge ranges
> + */
> +uint64_t __init pci_get_new_bar_addr(const struct pci_dev *pdev, uint64_t size,
> + bool is_64bit, bool prefetch)
Seeing the comment - why only "host bridge"? Especially for Dom0, if other
bridges are present in the system, I think you won't get away without having
a virtual counterpart for evey one of them (or alternatively without hiding
all of them plus the devices behind them).
> +{
> + struct pci_host_bridge *bridge;
> + struct rangeset *range;
> + uint64_t addr = 0, end = GB(4);
> +
> + /* Make sure we can store addr in a rangeset */
> + BUILD_BUG_ON(sizeof(addr) != sizeof(unsigned long));
While "store" looks right here, ...
> + bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
> + if ( !bridge )
> + return 0;
> +
> + range = prefetch ? bridge->bar_ranges_prefetch : bridge->bar_ranges;
> +
> + if ( size < PAGE_SIZE )
> + size = PAGE_SIZE;
> +
> + if ( is_64bit )
> + {
> + addr = GB(4);
> + end = ~0;
> + }
> +
> + if ( !rangeset_claim_aligned_range(range, size, &addr, end) )
> + return addr;
> +
> + printk(XENLOG_ERR "Failed to claim BAR range %lx-%lx from rangeset\n",
> + addr, addr + size - 1);
> +
> + return 0;
> +}
> +
> +/*
> + * Remove already used memory from the host bridge bar ranges
> + */
> +int __init pci_reserve_bar_range(const struct pci_dev *pdev, uint64_t addr,
> + uint64_t size, bool prefetch)
> +{
> + struct pci_host_bridge *bridge;
> + struct rangeset *range;
> +
> + /* Make sure we can store addr in a rangeset */
> + BUILD_BUG_ON(sizeof(addr) != sizeof(unsigned long));
... it doen't here, as ...
> + bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
> + if ( !bridge )
> + return 0;
> +
> + range = prefetch ? bridge->bar_ranges_prefetch : bridge->bar_ranges;
> +
> + return rangeset_remove_range(range, addr, addr + size - 1);
... there's nothing being stored.
But I'm apparently confused in a broader way: Here you remove a range from the
selected rangeset. rangeset_claim_aligned_range() also does so. Why are there
two removals?
> --- a/xen/arch/arm/pci/pci.c
> +++ b/xen/arch/arm/pci/pci.c
> @@ -95,6 +95,108 @@ boolean_param("pci-passthrough", pci_passthrough_enabled);
> __ro_after_init bool pci_scan_enabled;
> boolean_param("pci-scan", pci_scan_enabled);
>
> +typedef int (*bar_callback_t)(struct pci_dev *, uint8_t, uint64_t, uint64_t,
> + bool, bool);
Hmm, okay, you have a typedef now. But ...
> +static int __init reserve_bar_range(struct pci_dev *pdev, uint8_t reg,
> + uint64_t addr, uint64_t size, bool is_64bit,
> + bool prefetch)
... if I altered e.g. this function's signature, ...
> +{
> + if ( pci_check_bar(pdev, maddr_to_mfn(addr),
> + maddr_to_mfn(addr + size - 1)) )
> + return pci_reserve_bar_range(pdev, addr, size, prefetch);
> + return 0;
> +}
> +
> +static int __init setup_bar(struct pci_dev *pdev, uint8_t reg, uint64_t addr,
> + uint64_t size, bool is_64bit, bool prefetch)
> +{
> + if ( !pci_check_bar(pdev, maddr_to_mfn(addr),
> + maddr_to_mfn(addr + size - 1)) )
> + {
> + uint16_t cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
> +
> + addr = pci_get_new_bar_addr(pdev, size, is_64bit, prefetch);
> + if ( !addr )
> + return -ENOMEM;
> +
> + pci_conf_write16(pdev->sbdf, PCI_COMMAND,
> + cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
> +
> + pci_conf_write32(pdev->sbdf, reg,
> + (addr & GENMASK(31, 0)) |
> + (is_64bit ? PCI_BASE_ADDRESS_MEM_TYPE_64 : 0));
> +
> + if ( is_64bit )
> + pci_conf_write32(pdev->sbdf, reg + 4, addr >> 32);
> +
> + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
> + }
> +
> + return 0;
> +}
> +
> +static int __init bars_iterate(struct pci_dev *pdev, void *arg)
... the use of void * here still renders things type-unsafe. Plus you
needlessly introduce function pointer <=> data pointer conversions,
which Misra wants us to avoid. IOW ...
> +{
> + unsigned int i, barsize, ret = 0, num_bars = PCI_HEADER_NORMAL_NR_BARS;
> + uint64_t addr, size;
> + bar_callback_t cb = arg;
... this (bar_callback_t cb) is what the function parameter wants to be.
Ideally though as "bar_callback_t *cb" to not hide the pointer-ness, then
requiring the pointer part to be dropped from the typedef itself.
> + if ( (pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f) ==
> + PCI_HEADER_TYPE_NORMAL )
> + {
> + for ( i = 0; i < num_bars; i += barsize )
> + {
> + uint8_t reg = PCI_BASE_ADDRESS_0 + i * 4;
> + bool prefetch;
> +
> + if ( (pci_conf_read32(pdev->sbdf, reg) & PCI_BASE_ADDRESS_SPACE) ==
> + PCI_BASE_ADDRESS_SPACE_IO )
> + {
> + barsize = 1;
> + continue;
> + }
> +
> + barsize = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size,
> + (i == num_bars - 1) ? PCI_BAR_LAST : 0);
> +
> + if ( !size )
> + continue;
> +
> + prefetch = pci_conf_read32(pdev->sbdf, reg) &
> + PCI_BASE_ADDRESS_MEM_PREFETCH;
> +
> + ret = cb(pdev, reg, addr, size, barsize == 2, prefetch);
> + if ( ret )
> + return ret;
> + }
> + }
> +
> + return ret;
> +}
> +
> +static int __init pci_setup_bars(void)
> +{
> + int ret;
> + /* We can't change the signature of bars_iterate to only accept
> + * bar_callback_t, so use intermediate variables to ensure callback
> + * signatures are always correct
> + */
> + bar_callback_t cb_reserve = reserve_bar_range;
> + bar_callback_t cb_setup = setup_bar;
Oh, here you actually fake partial type-safety. This should be dropped.
> @@ -244,8 +241,18 @@ int rangeset_remove_range(
> destroy_range(r, x);
> }
>
> - out:
> +out:
Why are you violating style here? See ./CODING_STYLE, also for other labels
you introduce.
> + return rc;
> +}
> +
> +int rangeset_remove_range(struct rangeset *r, unsigned long s, unsigned long e)
> +{
> + int rc = 0;
Pointless initializer.
> + write_lock(&r->lock);
> + rc = remove_range(r, s, e);
> write_unlock(&r->lock);
> +
> return rc;
> }
>
> @@ -357,6 +364,51 @@ int rangeset_claim_range(struct rangeset *r, unsigned long size,
> return 0;
> }
>
> +int rangeset_claim_aligned_range(struct rangeset *r, unsigned long size,
> + unsigned long *s, unsigned long e)
> +{
> + struct range *x;
> + int rc = 0;
Again, plus this variable looks to be used only ...
> + /* Power of 2 check */
> + if ( (size & (size - 1)) != 0 && size != 0 )
> + {
> + *s = 0;
> + return -EINVAL;
> + }
> +
> + if ( e < *s )
> + return -EINVAL;
> +
> + write_lock(&r->lock);
> +
> + for ( x = first_range(r); x; x = next_range(r, x) )
> + {
> + /* Assumes size is a power of 2 */
> + unsigned long start_aligned = ROUNDUP(x->s, size);
I don't think the comment is very useful - you do the necessary check above,
and what is said is an inherent property of ROUNDUP().
> + if ( x->e > start_aligned &&
> + (x->e - start_aligned) >= size &&
Remember that x->e is an inclusive upper bound.
> + start_aligned >= *s &&
> + start_aligned + size <= e)
> + {
> + rc = remove_range(r, start_aligned, start_aligned + size - 1);
... in the narrow scope (so should move here).
> + if ( !rc )
> + *s = start_aligned;
> + else
> + *s = 0;
Is it reasonably possible to take this path? If not, please add
ASSERT_UNREACHABLE().
> + write_unlock(&r->lock);
This can move up some, can't it? We want to keep locked regions as narrow as
possible.
> + return rc;
> + }
> + }
> +
> + *s = 0;
> +
> + write_unlock(&r->lock);
> + return -ENOSPC;
Blank line please ahead of the main / final "return" of a function.
> --- a/xen/include/xen/rangeset.h
> +++ b/xen/include/xen/rangeset.h
> @@ -61,6 +61,17 @@ int __must_check rangeset_add_range(
> struct rangeset *r, unsigned long s, unsigned long e);
> int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size,
> unsigned long *s);
> +
> +/*
> + * Find a range subset that starts at or after s, ends before e,
> + * and is aligned to the size.
Is "before" correct? Isn't it "at or before", just like for s it's "at or after"?
As to "aligned", nothing contrary being said here I think I ought to be able to
pass e.g. 7. (Tying together size and alignment is suitable for the BAR handling
purpose you have, but is making this new interface pretty much not general-
purpose.)
Jan
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 7/8] xen/pci: assign discovered devices to hwdom
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
` (5 preceding siblings ...)
2025-11-18 13:36 ` [PATCH v3 6/8] xen/pci: initialize BARs Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
2025-11-18 14:44 ` Jan Beulich
2025-11-18 13:36 ` [PATCH v3 8/8] arm/pci: enable vpci for hwdom when pci-scan is enabled Mykyta Poturai
7 siblings, 1 reply; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Luca Fancellu, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk, Jan Beulich,
Roger Pau Monné, Stewart Hildebrand, Mykyta Poturai
From: Luca Fancellu <luca.fancellu@arm.com>
Hook up existing PCI setup routines for hwdom into Arm iommu
initialization sequence, only assign endpoint devices.
During scanned PCI device assignment, also permit access to the BAR
ranges if hwdom is using vpci and hide host bridges from domains that
use the fully emulated one.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* style fixes
* rework iomem access configuration
v1->v2:
* add host bridge hiding
* fix build without CONFIG_HAS_PCI
---
xen/arch/arm/pci/pci-host-common.c | 11 +++++++++++
xen/drivers/passthrough/arm/iommu.c | 15 +++++++++++++++
xen/drivers/passthrough/pci.c | 11 +++++++++++
3 files changed, 37 insertions(+)
diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index 28c26af9eb..110c334f59 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -430,6 +430,17 @@ int __init pci_host_bridge_mappings(struct domain *d)
unsigned int i;
bool need_mapping;
+ /*
+ * Only allow iomem access to ranges if we use pci-scan
+ * Actual mappings will be handled by VPCI code.
+ */
+ if ( has_vpci_bridge(d) )
+ {
+ mr_data.skip_mapping = true;
+ dt_for_each_range(dev, map_range_to_domain, &mr_data);
+ continue;
+ }
+
for ( i = 0; i < dt_number_of_address(dev); i++ )
{
paddr_t addr, size;
diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c
index 100545e23f..124a99f198 100644
--- a/xen/drivers/passthrough/arm/iommu.c
+++ b/xen/drivers/passthrough/arm/iommu.c
@@ -19,6 +19,7 @@
#include <xen/device_tree.h>
#include <xen/iommu.h>
#include <xen/lib.h>
+#include <xen/sched.h>
#include <asm/device.h>
@@ -133,6 +134,16 @@ void arch_iommu_domain_destroy(struct domain *d)
{
}
+#ifdef CONFIG_HAS_PCI
+static int __hwdom_init iommu_add_hwdom_pci_device(u8 devfn,
+ struct pci_dev *pdev)
+{
+ const struct domain_iommu *hd = dom_iommu(hardware_domain);
+
+ return iommu_call(hd->platform_ops, add_device, devfn, pci_to_dev(pdev));
+}
+#endif
+
void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
{
/* Set to false options not supported on ARM. */
@@ -142,6 +153,10 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
if ( iommu_hwdom_reserved == 1 )
printk(XENLOG_WARNING "map-reserved dom0-iommu option is not supported on ARM\n");
iommu_hwdom_reserved = 0;
+
+#ifdef CONFIG_HAS_PCI
+ setup_hwdom_pci_devices(d, iommu_add_hwdom_pci_device);
+#endif
}
/*
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 52c22fa50c..70c21403d5 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -20,6 +20,7 @@
#include <xen/pci_ids.h>
#include <xen/list.h>
#include <xen/prefetch.h>
+#include <xen/iocap.h>
#include <xen/iommu.h>
#include <xen/irq.h>
#include <xen/param.h>
@@ -1041,6 +1042,12 @@ enum pdev_type pdev_type(u16 seg, u8 bus, u8 devfn)
return pos ? DEV_TYPE_PCIe_ENDPOINT : DEV_TYPE_PCI;
}
+static bool __hwdom_init pdev_is_endpoint(const struct pci_dev *pdev)
+{
+ enum pdev_type type = pdev_type(pdev->seg, pdev->bus, pdev->devfn);
+ return type == DEV_TYPE_PCIe_ENDPOINT || type == DEV_TYPE_PCI;
+}
+
/*
* find the upstream PCIe-to-PCI/PCIX bridge or PCI legacy bridge
* return 0: the device is integrated PCI device or PCIe
@@ -1221,6 +1228,10 @@ static int __hwdom_init cf_check _setup_hwdom_pci_devices(
if ( !pdev )
continue;
+ /* Hide real bridges from HWdom when it's using the emulated one */
+ if ( has_vpci_bridge(hardware_domain) && !pdev_is_endpoint(pdev) )
+ pci_hide_device(pdev->seg, pdev->bus, pdev->devfn);
+
if ( !pdev->domain )
{
pdev->domain = ctxt->d;
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v3 7/8] xen/pci: assign discovered devices to hwdom
2025-11-18 13:36 ` [PATCH v3 7/8] xen/pci: assign discovered devices to hwdom Mykyta Poturai
@ 2025-11-18 14:44 ` Jan Beulich
0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2025-11-18 14:44 UTC (permalink / raw)
To: Mykyta Poturai, Luca Fancellu
Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
Volodymyr Babchuk, Roger Pau Monné, Stewart Hildebrand,
xen-devel@lists.xenproject.org
On 18.11.2025 14:36, Mykyta Poturai wrote:
> @@ -1041,6 +1042,12 @@ enum pdev_type pdev_type(u16 seg, u8 bus, u8 devfn)
> return pos ? DEV_TYPE_PCIe_ENDPOINT : DEV_TYPE_PCI;
> }
>
> +static bool __hwdom_init pdev_is_endpoint(const struct pci_dev *pdev)
> +{
> + enum pdev_type type = pdev_type(pdev->seg, pdev->bus, pdev->devfn);
> + return type == DEV_TYPE_PCIe_ENDPOINT || type == DEV_TYPE_PCI;
Once again - blank line please before the main return of a function (or, for
that matter, between declaration(s) and statement(s)).
> @@ -1221,6 +1228,10 @@ static int __hwdom_init cf_check _setup_hwdom_pci_devices(
> if ( !pdev )
> continue;
>
> + /* Hide real bridges from HWdom when it's using the emulated one */
> + if ( has_vpci_bridge(hardware_domain) && !pdev_is_endpoint(pdev) )
> + pci_hide_device(pdev->seg, pdev->bus, pdev->devfn);
As said elsewhere, when you hide bridges without introducing virtual counterparts,
everything behind the bridge also needs hiding.
Jan
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 8/8] arm/pci: enable vpci for hwdom when pci-scan is enabled
2025-11-18 13:36 [PATCH v3 0/8] Implement PCI device enumeration on Arm Mykyta Poturai
` (6 preceding siblings ...)
2025-11-18 13:36 ` [PATCH v3 7/8] xen/pci: assign discovered devices to hwdom Mykyta Poturai
@ 2025-11-18 13:36 ` Mykyta Poturai
7 siblings, 0 replies; 12+ messages in thread
From: Mykyta Poturai @ 2025-11-18 13:36 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Mykyta Poturai, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
With pci-scan implemented it is now possible to use vpci for hardware
domains. Update has_vpci to reflect this change.
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
v2->v3:
* replace hwdom_uses_vpci with has_vpci_bridge
v1->v2:
* fix typo in commit message
---
xen/arch/arm/include/asm/domain.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h
index af3e168374..3eac0aea64 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -305,8 +305,7 @@ static inline void arch_vcpu_block(struct vcpu *v) {}
#define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
-/* vPCI is not available on Arm */
-#define has_vpci(d) ({ (void)(d); false; })
+#define has_vpci(d) (is_hardware_domain(d) && has_vpci_bridge(d))
struct arch_vcpu_io {
struct instr_details dabt_instr; /* when the instruction is decoded */
--
2.51.2
^ permalink raw reply related [flat|nested] 12+ messages in thread