dom0less pci passthrough support on Arm part 1
cover dom0less pci passthrough support on Arm part 1
This series adds basic PCI device enumeration in Xen. This will allow us to not rely on Dom0 enumeration for supported controllers, which will enable PCI passthrough for dom0less setups.
Enumeration is disabled by default and can be enabled with "pci-scan" cmdline option. Discovered devices are added to Xen and assigned to dom_io by default.
Edward Pickup (1):
arm/pci: Add pci-scan boot argument
Luca Fancellu (2):
xen/pci: modify pci_add_device to handle device add by Xen xen/pci: add discovered PCI device at boot
docs/misc/xen-command-line.pandoc | 7 ++++ xen/arch/arm/include/asm/pci.h | 11 ++++++ xen/arch/arm/pci/pci-host-common.c | 1 + xen/arch/arm/pci/pci.c | 27 ++++++++++++- xen/arch/x86/physdev.c | 9 ++--- xen/drivers/passthrough/pci.c | 62 +++++++++++++++++++++++------- xen/drivers/pci/physdev.c | 3 +- xen/include/xen/pci.h | 4 +- 8 files changed, 102 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 arm/pci: Add pci-scan boot argument
From: Edward Pickup <[email protected]>
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 patch also makes an existing debug function viewable outside its translation unit, and uses this to dump the PCI devices found. The debug message is controlled by config DEBUG.
Additionally, this patch modifies segment loading to ensure that PCI devices on other segments are properly found.
This will be needed ahead of dom0less support for pci passthrough on arm.
---
(cherry picked from commit bce463e1588a45e1bfdf59fc0d5f88b16604e439 from
the downstream branch poc/pci-passthrough from
https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git)
changes since cherry-pick:
* s/always_inline/inline/
* replace additional kconfig option with config DEBUG
--- docs/misc/xen-command-line.pandoc | 7 +++++++ xen/arch/arm/include/asm/pci.h | 11 +++++++++++ xen/arch/arm/pci/pci-host-common.c | 1 + xen/arch/arm/pci/pci.c | 26 ++++++++++++++++++++++++-- xen/drivers/passthrough/pci.c | 2 +- xen/include/xen/pci.h | 1 + 6 files changed, 45 insertions(+), 3 deletions(-)
docs/misc/xen-command-line.pandoc +7 -0
@@ -2058,6 +2058,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>`
xen/arch/arm/include/asm/pci.h +11 -0
@@ -23,6 +23,7 @@#define pci_to_dev (pcidev) (&(pcidev)->arch.dev)extern bool pci_passthrough_enabled; +extern bool pci_scan_enabled;struct rangeset ;
@@ -128,6 +129,11 @@ static always_inline bool is_pci_passthrough_enabled(void)return pci_passthrough_enabled; } +static inline bool is_pci_scan_enabled (void ) +{ +return pci_scan_enabled; +} +void arch_pci_init_pdev (struct pci_dev *pdev);int pci_get_new_domain_nr (void );
@@ -155,6 +161,11 @@ bool arch_pci_device_physdevop(void);#else /*!CONFIG_HAS_PCI*/ +static inline bool is_pci_scan_enabled (void ) +{ +return false; +} +struct pci_dev ;static inline void arch_pci_init_pdev (struct pci_dev *pdev) {}
xen/arch/arm/pci/pci-host-common.c +1 -0
@@ -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;
xen/arch/arm/pci/pci.c +24 -2
@@ -91,8 +91,13 @@ 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. */ +bool __read_mostly 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 +109,26 @@ 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 ) +return ret; + +if (is_pci_scan_enabled () ) + { + ret =scan_pci_devices (); + +if ( ret <0 ) +return ret; + +#ifdef DEBUG +dump_pci_devices ('c' ); +#endif + } + +return 0 ; }__initcall (pci_init);
xen/drivers/passthrough/pci.c +1 -1
@@ -1384,7 +1384,7 @@ static int cf_check _dump_pci_devices(struct pci_seg *pseg, void *arg)return 0 ; } -static void cf_check dump_pci_devices(unsigned char ch) +void cf_check dump_pci_devices(unsigned char ch) {printk ("==== PCI devices ====\n" );pcidevs_lock ();
xen/include/xen/pci.h +1 -0
@@ -217,6 +217,7 @@ static always_inline bool pcidevs_trylock(void)bool pci_known_segment (u16 seg);bool pci_device_detect (u16 seg,u8 bus,u8 dev,u8 func);int scan_pci_devices (void ); +void dump_pci_devices (unsigned char ch);enum pdev_type pdev_type (u16 seg,u8 bus,u8 devfn);int find_upstream_bridge (u16 seg,u8 *bus,u8 *devfn,u8 *secbus);
Signature · 1 line
2.34.1
Re: [PATCH v1 1/3] arm/pci: Add pci-scan boot argument
Quoted 9 lines · Mykyta Poturai
From: Edward Pickup <[email protected]>
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 patch also makes an existing debug function viewable outside its translation unit, and uses this to dump the PCI devices found. The debug message is controlled by config DEBUG.
Quoted 8 lines
Additionally, this patch modifies segment loading to ensure that PCI devices on other segments are properly found.
This will be needed ahead of dom0less support for pci passthrough on arm.
Signed-off-by Luca Fancellu <[email protected]>Signed-off-by Edward Pickup <[email protected]>
Considering the From: above and this order of S-o-b: Who is it really that was the original author here?
xen/arch/arm/include/asm/pci.h line 26
Quoted 7 lines
xen/arch/arm/include/asm/pci.h +1
-0@@ -23,6 +23,7 @@#define pci_to_dev (pcidev) (&(pcidev)->arch.dev)extern bool pci_passthrough_enabled; +extern bool pci_scan_enabled;
With the variable non-static, ...
Quoted 13 lines
xen/arch/arm/include/asm/pci.h +5
-0@@ -128,6 +129,11 @@ static always_inline bool is_pci_passthrough_enabled(void)return pci_passthrough_enabled; } +static inline bool is_pci_scan_enabled (void ) +{ +return pci_scan_enabled; +} +void arch_pci_init_pdev (struct pci_dev *pdev);int pci_get_new_domain_nr (void );
xen/arch/arm/include/asm/pci.h bool arch_pci_device_physdevop(void); · line 167
Quoted 7 lines
xen/arch/arm/include/asm/pci.h +4
-0@@ -155,6 +161,11 @@ bool arch_pci_device_physdevop(void);#else /*!CONFIG_HAS_PCI*/ +static inline bool is_pci_scan_enabled (void ) +{ +return false; +}
... what's the point of the wrappers? Constrain the variable as such to HAS_PCI=y, and use "#define pci_scan_enabled false" in the opposite case. Just like we do elsewhere in a number of cases.
xen/arch/arm/pci/pci.c bool arch_pci_device_physdevop(void) · line 95
Quoted 8 lines
xen/arch/arm/pci/pci.c +2
-0@@ -91,8 +91,13 @@ 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. */ +bool __read_mostly pci_scan_enabled;
__ro_after_init?
xen/arch/arm/pci/pci.c bool arch_pci_device_physdevop(void) · line 101
Quoted 6 lines
xen/arch/arm/pci/pci.c +3
-0+boolean_param ("pci-scan" , pci_scan_enabled); +static int __init pci_init (void ) { +int ret;/*
Nit: Blank line please between declaration(s) and statement(s).
Quoted 13 lines
xen/arch/arm/pci/pci.c +6
-2@@ -104,9 +109,26 @@ 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 ) +return ret; +
xen/arch/arm/pci/pci.c static int __init pci_init(void) · line 128
Quoted 10 lines
xen/arch/arm/pci/pci.c +10
-0+if (is_pci_scan_enabled () ) + { + ret =scan_pci_devices (); + +if ( ret <0 ) +return ret; + +#ifdef DEBUG +dump_pci_devices ('c' ); +#endif
If I was a maintainer of this code, I would request such to be dropped. Or if there was a good reason to have such, I think it would want to be arch-independent.
xen/drivers/passthrough/pci.c static int cf_check _dump_pci_devices(struct pci_seg *pseg, void *arg) · line 1387
Quoted 8 lines
xen/drivers/passthrough/pci.c +1
-1@@ -1384,7 +1384,7 @@ static int cf_check _dump_pci_devices(struct pci_seg *pseg, void *arg)return 0 ; } -static void cf_check dump_pci_devices(unsigned char ch) +void cf_check dump_pci_devices(unsigned char ch)
Note the cf_check here. It, for some reason, ...
xen/include/xen/pci.h static always_inline bool pcidevs_trylock(void) · line 220
Quoted 7 lines
xen/include/xen/pci.h +1
-0@@ -217,6 +217,7 @@ static always_inline bool pcidevs_trylock(void)bool pci_known_segment (u16 seg);bool pci_device_detect (u16 seg,u8 bus,u8 dev,u8 func);int scan_pci_devices (void ); +void dump_pci_devices (unsigned char ch);
... needs reproducing on the declaration. What about x86 though? It'll end up as a non-static function with no caller outside of the defining CU, hence violating some Misra rule.
Jan
Re: [PATCH v1 1/3] arm/pci: Add pci-scan boot argument
Hi Jan,
Quoted 15 lines · Jan Beulich
Quoted 12 lines · Mykyta Poturai
From: Edward Pickup <[email protected]>
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 patch also makes an existing debug function viewable outside its translation unit, and uses this to dump the PCI devices found. The debug message is controlled by config DEBUG.
Additionally, this patch modifies segment loading to ensure that PCI devices on other segments are properly found.
Quoted 8 lines
Quoted 5 lines
This will be needed ahead of dom0less support for pci passthrough on arm.
Signed-off-by Luca Fancellu <[email protected]>Signed-off-by Edward Pickup <[email protected]>Considering the From: above and this order of S-o-b: Who is it really that was the original author here?
I think this patch was mine, probably some issues from Edward, anyway he doesn’t work at arm anymore.
Cheers,
Luca
PATCH 2/3 xen/pci: modify pci_add_device to handle device add by Xen
In reply to Mykyta PoturaiFrom: Luca Fancellu <[email protected]>
Currently pci_add_device is called from hypercalls requested by Dom0 to add pci devices and when the device has no domain associated with it, it is assumed that hardware_domain is the owner.
On the dom0less scenario, the enumeration is performed by the firmware and Xen at boot time might want to assign some pci devices to guests, so it has to firstly add the device and then assign it to the final guest.
Modify pci_add_device to have the owner domain passed as a parameter to the function, so that when it is called from the hypercall the owner would be the hardware domain, otherwise when Xen is calling it, it would be another domain since hw domain could not be there (dom0less guests without Dom0 use case).
In pci_add_device there is a call to xsm that doesn't consider the requester of the function to be Xen itself, so add a check to skip the call if the owner domain is dom_io, since it means the call is coming directly from Xen.
---
(cherry picked from commit f0c85d9043f7c9402e85b73361c8a13c683428ca from
the downstream branch poc/pci-passthrough from
https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git)
changes since cherry-pick:
* s/hardware_domain/d/ in some write_unlock calls in xen/drivers/passthrough/pci.c
--- xen/arch/x86/physdev.c | 9 ++++----- xen/drivers/passthrough/pci.c | 32 ++++++++++++++++++++------------ xen/drivers/pci/physdev.c | 3 ++- xen/include/xen/pci.h | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-)
xen/arch/x86/physdev.c +4 -5
@@ -446,8 +446,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&manage_pci, arg,1 ) !=0 )break ; - ret =pci_add_device (0 , manage_pci.bus, manage_pci.devfn, -NULL ,NUMA_NO_NODE ); + ret =pci_add_device (hardware_domain,0 , manage_pci.bus, + manage_pci.devfn,NULL ,NUMA_NO_NODE );break ; }
@@ -477,9 +477,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) pdev_info.is_virtfn = manage_pci_ext.is_virtfn; pdev_info.physfn.bus = manage_pci_ext.physfn.bus; pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn; - ret =pci_add_device (0 , manage_pci_ext.bus, - manage_pci_ext.devfn, - &pdev_info,NUMA_NO_NODE ); + ret =pci_add_device (hardware_domain,0 , manage_pci_ext.bus, + manage_pci_ext.devfn, &pdev_info,NUMA_NO_NODE );break ; }
xen/drivers/passthrough/pci.c +20 -12
@@ -654,7 +654,7 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,return is64bits ?2 :1 ; } -int pci_add_device (u16 seg,u8 bus,u8 devfn, +int pci_add_device (struct domain *d,u16 seg,u8 bus,u8 devfn,const struct pci_dev_info *info,nodeid_t node) {struct pci_seg *pseg;
@@ -672,9 +672,12 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else type ="device" ; - ret =xsm_resource_plug_pci (XSM_PRIV , (seg <<16 ) | (bus <<8 ) | devfn); -if ( ret ) -return ret; +if ( d != dom_io ) + { + ret =xsm_resource_plug_pci (XSM_PRIV , (seg <<16 ) | (bus <<8 ) | devfn); +if ( ret ) +return ret; + } ret = -ENOMEM ;
@@ -767,9 +770,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, ret =0 ;if ( !pdev->domain ) { - pdev->domain = hardware_domain; -write_lock (&hardware_domain->pci_lock); -list_add (&pdev->domain_list, &hardware_domain->pdev_list); + pdev->domain = d; +write_lock (&d->pci_lock); +list_add (&pdev->domain_list, &pdev->domain->pdev_list);/* * For devices not discovered by Xen during boot, add vPCI handlers
@@ -779,25 +782,30 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( ret ) {list_del (&pdev->domain_list); -write_unlock (&hardware_domain->pci_lock); +write_unlock (&d->pci_lock); pdev->domain =NULL ;printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); goto out; } -write_unlock (&hardware_domain->pci_lock); +write_unlock (&d->pci_lock); ret =iommu_add_device (pdev);if ( ret ) { -write_lock (&hardware_domain->pci_lock); +write_lock (&d->pci_lock);vpci_deassign_device (pdev);list_del (&pdev->domain_list); -write_unlock (&hardware_domain->pci_lock); +write_unlock (&d->pci_lock); pdev->domain =NULL ; goto out; } } -else +else if ( pdev->domain == d )iommu_enable_device (pdev); +else + { + ret = -EINVAL ; + goto out; + }pci_enable_acs (pdev);
xen/drivers/pci/physdev.c +2 -1
@@ -50,7 +50,8 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }#endif - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); + ret =pci_add_device (hardware_domain, add.seg, add.bus, add.devfn, + &pdev_info, node);break ; }
xen/include/xen/pci.h +1 -1
@@ -227,7 +227,7 @@ void setup_hwdom_pci_devices(struct domain *d,int pci_release_devices (struct domain *d);int pci_add_segment (u16 seg);const unsigned long *pci_get_ro_map (u16 seg); -int pci_add_device (u16 seg,u8 bus,u8 devfn, +int pci_add_device (struct domain *d,u16 seg,u8 bus,u8 devfn,const struct pci_dev_info *info,nodeid_t node);int pci_remove_device (u16 seg,u8 bus,u8 devfn);int pci_ro_device (int seg,int bus,int devfn);
Signature · 1 line
2.34.1
Re: [PATCH v1 2/3] xen/pci: modify pci_add_device to handle device add by Xen
Quoted 17 lines · Mykyta Poturai
From: Luca Fancellu <[email protected]>
Currently
pci_add_deviceis called from hypercalls requested by Dom0 to add pci devices and when the device has no domain associated with it, it is assumed thathardware_domainis the owner.On the dom0less scenario, the enumeration is performed by the firmware and Xen at boot time might want to assign some pci devices to guests, so it has to firstly add the device and then assign it to the final guest.
Modify
pci_add_deviceto have the owner domain passed as a parameter to the function, so that when it is called from the hypercall the owner would be the hardware domain, otherwise when Xen is calling it, it would be another domain since hw domain could not be there (dom0less guests without Dom0 use case).
Quoted 4 lines
In
pci_add_devicethere is a call to xsm that doesn't consider the requester of the function to be Xen itself, so add a check to skip the call if the owner domain isdom_io, since it means the call is coming directly from Xen.
I don't understand this particular aspect: All call sites pass hardware_domain. Checking against dom_io therefore looks unnecessary, or at least premature. In Misra's terms it is "dead code" that you add.
xen/drivers/passthrough/pci.c unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos, · line 658
Quoted 9 lines
xen/drivers/passthrough/pci.c +1
-1@@ -654,7 +654,7 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,return is64bits ?2 :1 ; } -int pci_add_device (u16 seg,u8 bus,u8 devfn, +int pci_add_device (struct domain *d,u16 seg,u8 bus,u8 devfn,const struct pci_dev_info *info,nodeid_t node)
For a pci_*() function I don't think it's appropriate to have a domain (not a PCI domain, aka segment, which would be fine) as first parameter.
While you touch this it might also be nice if you switched u<N> to uint<N>_t.
xen/drivers/pci/physdev.c ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 54
Quoted 9 lines
xen/drivers/pci/physdev.c +2
-1@@ -50,7 +50,8 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }#endif - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); + ret =pci_add_device (hardware_domain, add.seg, add.bus, add.devfn, + &pdev_info, node);
Here as well as in the x86-specific counterparts: Why hardware_domain, i.e. why not current->domain? Yes, what you do is in line with how the code has behaved so far, but now that you want to change it, it needs to be sorted what it is that's really wanted. This btw also plays into the XSM aspect that you're fiddling with.
Also, what if you end up passing NULL here in the dom0less case?
Jan
PATCH 3/3 xen/pci: add discovered PCI device at boot
In reply to Mykyta PoturaiFrom: Luca Fancellu <[email protected]>
Create add_discovered_pci_devices function that calls pci_device_add on every PCI device discovered.
The devices will be added to dom_io so that they can be assigned later to other domains.
---
(cherry picked from commit eff51e50021b75f5a50533f7de681b2ce044f5bd from
the downstream branch poc/pci-passthrough from
https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git)
--- xen/arch/arm/pci/pci.c | 1 + xen/drivers/passthrough/pci.c | 28 ++++++++++++++++++++++++++++ xen/include/xen/pci.h | 1 + 3 files changed, 30 insertions(+)
xen/arch/arm/pci/pci.c +1 -0
@@ -123,6 +123,7 @@ static int __init pci_init(void)if ( ret <0 )return ret; +add_discovered_pci_devices ();#ifdef DEBUG dump_pci_devices ('c' );#endif
xen/drivers/passthrough/pci.c +28 -0
@@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)return ret; } +static int __init _add_discovered_pci_devices (struct pci_seg *pseg,void *arg) +{ +struct pci_dev *pdev; +int ret =0 ; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + ret =pci_add_device (dom_io, pdev->seg, pdev->bus, pdev->devfn,NULL , +NUMA_NO_NODE ); +if ( ret <0 ) + { +printk (XENLOG_ERR +"%pp: Failure adding the discovered pci device (Error %d)\n" , + &pdev->sbdf, ret); +break ; + } + } + +return ret; +} + +void __init add_discovered_pci_devices (void ) +{ +pcidevs_lock (); +pci_segments_iterate (_add_discovered_pci_devices,NULL ); +pcidevs_unlock (); +} +struct setup_hwdom {struct domain *d;int (*handler)(uint8_t devfn,struct pci_dev *pdev);
xen/include/xen/pci.h +1 -0
@@ -217,6 +217,7 @@ static always_inline bool pcidevs_trylock(void)bool pci_known_segment (u16 seg);bool pci_device_detect (u16 seg,u8 bus,u8 dev,u8 func);int scan_pci_devices (void ); +void add_discovered_pci_devices (void );void dump_pci_devices (unsigned char ch);enum pdev_type pdev_type (u16 seg,u8 bus,u8 devfn);int find_upstream_bridge (u16 seg,u8 *bus,u8 *devfn,u8 *secbus);
Signature · 1 line
2.34.1
Re: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot
Quoted 4 lines · Mykyta Poturai
Create
add_discovered_pci_devicesfunction that callspci_device_addon every PCI device discovered.
The devices will be added todom_ioso that they can be assigned later to other domains.
And why's the intermediate step necessary? IOW can't they be assigned to their target domains right away, and only whatever's left would go to DOM_IO?
Quoted 23 lines
xen/drivers/passthrough/pci.c +17
-0@@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)return ret; } +static int __init _add_discovered_pci_devices (struct pci_seg *pseg,void *arg) +{ +struct pci_dev *pdev; +int ret =0 ; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + ret =pci_add_device (dom_io, pdev->seg, pdev->bus, pdev->devfn,NULL , +NUMA_NO_NODE ); +if ( ret <0 ) + { +printk (XENLOG_ERR +"%pp: Failure adding the discovered pci device (Error %d)\n" , + &pdev->sbdf, ret); +break ; + } + }
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 1209
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+ +return ret; +} + +void __init add_discovered_pci_devices (void ) +{ +pcidevs_lock (); +pci_segments_iterate (_add_discovered_pci_devices,NULL ); +pcidevs_unlock (); +}
This looks to merely be a specialized form of what ...
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 1213
Quoted 3 lines
xen/drivers/passthrough/pci.c +0
-0struct setup_hwdom {struct domain *d;int (*handler)(uint8_t devfn,struct pci_dev *pdev);
... follows below here. By generalizing what we have (perhaps from the top, i.e. iommu_hwdom_init()), you'd also avoid violating Misra rule 2.1 on x86, as you add unreachable code there.
Jan
Re: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot
Quoted 8 lines · Jan Beulich
Quoted 4 lines · Mykyta Poturai
Create
add_discovered_pci_devicesfunction that callspci_device_addon every PCI device discovered.
The devices will be added todom_ioso that they can be assigned later to other domains.And why's the intermediate step necessary? IOW can't they be assigned to their target domains right away, and only whatever's left would go to
DOM_IO?
For Dom0less case, guest domains are not yet created at this point.
Quoted 40 lines
Quoted 23 lines
xen/drivers/passthrough/pci.c +17
-0@@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)return ret; } +static int __init _add_discovered_pci_devices (struct pci_seg *pseg,void *arg) +{ +struct pci_dev *pdev; +int ret =0 ; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + ret =pci_add_device (dom_io, pdev->seg, pdev->bus, pdev->devfn,NULL , +NUMA_NO_NODE ); +if ( ret <0 ) + { +printk (XENLOG_ERR +"%pp: Failure adding the discovered pci device (Error %d)\n" , + &pdev->sbdf, ret); +break ; + } + }xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 1209
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+ +return ret; +} + +void __init add_discovered_pci_devices (void ) +{ +pcidevs_lock (); +pci_segments_iterate (_add_discovered_pci_devices,NULL ); +pcidevs_unlock (); +}This looks to merely be a specialized form of what ...
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 1213
Quoted 3 lines
xen/drivers/passthrough/pci.c +0
-0struct setup_hwdom {struct domain *d;int (*handler)(uint8_t devfn,struct pci_dev *pdev);
Quoted 5 lines
... follows below here. By generalizing what we have (perhaps from the top, i.e.
iommu_hwdom_init()), you'd also avoid violating Misra rule 2.1 on x86, as you add unreachable code there.Jan
Can you please elaborate a little further on how you see this generalization? With routines you mentioned being specifically for hwdom, which may not exist, and the different approaches to PCI initialization on Arm/x86 (as far as I understand on x86 all of the PCI related stuff is initialized from iommu helpers, while Arm has a dedicated init step) I am afraid I can't find a nice point of contact to generalize this, but I can be missing somthing due to unfamiliarity with x86 code.
Another way of addressing possible MISRA violation I can see is moving the add_discovered_pci_devices to xen/arch/arm/pci/pci.c so it will only be compiled when used.
Signature · 1 line
Mykyta
Re: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot
Quoted 11 lines · Mykyta Poturai
Quoted 8 lines · Jan Beulich
Quoted 4 lines · Mykyta Poturai
Create
add_discovered_pci_devicesfunction that callspci_device_addon every PCI device discovered.
The devices will be added todom_ioso that they can be assigned later to other domains.And why's the intermediate step necessary? IOW can't they be assigned to their target domains right away, and only whatever's left would go to
DOM_IO?For Dom0less case, guest domains are not yet created at this point.
I understand that, but this doesn't answer my question. Once the guest domains are there, can't you directly assign their devices to them?
Quoted 40 lines
Quoted 40 lines
Quoted 23 lines
xen/drivers/passthrough/pci.c +17
-0@@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)return ret; } +static int __init _add_discovered_pci_devices (struct pci_seg *pseg,void *arg) +{ +struct pci_dev *pdev; +int ret =0 ; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { + ret =pci_add_device (dom_io, pdev->seg, pdev->bus, pdev->devfn,NULL , +NUMA_NO_NODE ); +if ( ret <0 ) + { +printk (XENLOG_ERR +"%pp: Failure adding the discovered pci device (Error %d)\n" , + &pdev->sbdf, ret); +break ; + } + }xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 1209
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+ +return ret; +} + +void __init add_discovered_pci_devices (void ) +{ +pcidevs_lock (); +pci_segments_iterate (_add_discovered_pci_devices,NULL ); +pcidevs_unlock (); +}This looks to merely be a specialized form of what ...
Quoted 3 lines
xen/drivers/passthrough/pci.c +0
-0struct setup_hwdom {struct domain *d;int (*handler)(uint8_t devfn,struct pci_dev *pdev);
Quoted 7 lines
Quoted 3 lines
... follows below here. By generalizing what we have (perhaps from the top, i.e.
iommu_hwdom_init()), you'd also avoid violating Misra rule 2.1 on x86, as you add unreachable code there.Can you please elaborate a little further on how you see this generalization? With routines you mentioned being specifically for hwdom, which may not exist,
That's precisely the generalization I'm having in mind. What's hwdom-only now ought to be possible to be made usable in wider manner.
Quoted 4 lines
and the different approaches to PCI
initialization on Arm/x86 (as far as I understand on x86 all of the PCI related stuff is initialized from iommu helpers, while Arm has a dedicated init step)
This, too, may want harmonizing.
Quoted 7 lines
I am afraid I can't find a nice point of contact to generalize this, but I can be missing somthing due to unfamiliarity with x86 code.
Another way of addressing possible MISRA violation I can see is moving the
add_discovered_pci_devicestoxen/arch/arm/pci/pci.cso it will only be compiled when used.
And pose a problem when e.g. RISC-V also wants the same.
Jan