PCI devices passthrough on Arm
v5 cover PCI devices passthrough on Arm
Hello All,
The purpose of this patch series is to add PCI passthrough support to Xen on Arm. PCI passthrough support on ARM is the collaboration work between EPAM and ARM. ARM submitted the partial RFC [1][2] last year to get early feedback. We tried to fix all the comments and added more features to this patch series.
Working POC with all the features can be found at [3]. Working POC is tested on x86 so that there will be no regression on x86. Design presentation can be found at [4]
PCI passthrough support is divided into different patches. This patch series includes following features:
Preparatory work to implement the PCI passthrough support for the ARM:
- Refactor MSI code.
- Fixed compilation error when HAS_PCI enabled for ARM.
Discovering PCI Host Bridge in XEN:
- PCI init to initialize the PCI driver.
- PCI host bridge discovery in XEN and map the PCI ECAM configuration space to the XEN memory.
- PCI access functions.
Discovering PCI devices:
- To support the PCI passthrough, XEN should be aware of the PCI devices.
- Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then communicate to the XEN via a hypercall to add the PCI devices in XEN.
Enable the existing x86 virtual PCI support for ARM:
- Add VPCI trap handler for each of the PCI device added for config space access.
- Register the trap handler in XEN for each of the host bridge PCI ECAM config space access.
Emulated PCI device tree node in libxl:
- Create a virtual PCI device tree node in libxl to enable the guest OS to discover the virtual PCI during guest boot.
This patch series does not inlcude the following features. Following features will be send for review in the next version of the patch series once initial patch series merged.
- VPCI support for DOMU guests (Non-identity mappings guest view of the BARs)
- Virtual bus topology implementation
- IOMMU related changes (generic, SMMUv2, SMMUv3)
- MSI support for DOMU guests.
- Virual ITS support for DOMU guests
[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg01184.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-07/threads.html#01184
[3] https://gitlab.com/rahsingh/xen-integration/-/tree/arm_pci_v4_integrate
[4] https://static.sched.com/hosted_files/xen2021/e4/PCI_Device_Passthrough_On_Arm.pdf
Oleksandr Andrushchenko (1):
xen/arm: Add support for Xilinx ZynqMP PCI host controller
Rahul Singh (10):
xen/arm: xc_domain_ioport_permission(..) not supported on ARM. xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" xen/arm: PCI host bridge discovery within XEN on ARM xen/arm: Implement pci access functions
xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
xen/arm: Enable the existing x86 virtual PCI support for ARM. xen/arm: Transitional change to build HAS_VPCI on ARM. arm/libxl: Emulated PCI device tree node in libxl xen/arm: Add linux,pci-domain property for hwdom if not available.
docs/misc/xen-command-line.pandoc | 7 + tools/include/libxl.h | 6 + tools/libs/ctrl/xc_domain.c | 9 + tools/libs/light/libxl_arm.c | 111 +++++++++++ tools/libs/light/libxl_types.idl | 1 + tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 8 +- xen/arch/arm/domain_build.c | 19 ++ xen/arch/arm/pci/Makefile | 5 + xen/arch/arm/pci/ecam.c | 61 ++++++ xen/arch/arm/pci/pci-access.c | 140 ++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 287 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 48 +++++ xen/arch/arm/pci/pci-host-zynqmp.c | 65 +++++++ xen/arch/arm/pci/pci.c | 12 ++ xen/arch/arm/physdev.c | 6 +- xen/arch/arm/vpci.c | 102 ++++++++++ xen/arch/arm/vpci.h | 36 ++++ xen/arch/x86/domain.c | 6 + xen/arch/x86/physdev.c | 52 +---- xen/arch/x86/x86_64/physdev.c | 2 +- xen/common/domain.c | 2 +- xen/drivers/passthrough/pci.c | 18 ++ xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 86 +++++++++ xen/drivers/vpci/Makefile | 3 +- xen/drivers/vpci/header.c | 2 + xen/include/asm-arm/domain.h | 7 +- xen/include/asm-arm/pci.h | 85 ++++++++ xen/include/asm-x86/pci.h | 8 +- xen/include/public/arch-arm.h | 21 +- xen/include/public/domctl.h | 4 +- xen/include/xen/hypercall.h | 4 + xen/include/xen/pci.h | 2 + 36 files changed, 1168 insertions(+), 61 deletions(-) create mode 100644 xen/arch/arm/pci/ecam.c create mode 100644 xen/arch/arm/pci/pci-access.c create mode 100644 xen/arch/arm/pci/pci-host-common.c create mode 100644 xen/arch/arm/pci/pci-host-generic.c create mode 100644 xen/arch/arm/pci/pci-host-zynqmp.c create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.h create mode 100644 xen/drivers/pci/physdev.c
Signature · 1 line
2.25.1
PATCH v5 1/11 xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return -ENOSYS.
---
Change in v5: none
Change in v4:
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3: Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v2:
- Instead of returning success in XEN, ignored the call in xl.
---
--- tools/libs/ctrl/xc_domain.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/libs/ctrl/xc_domain.c +9 -0
@@ -1348,6 +1348,14 @@ int xc_domain_ioport_permission(xc_interface *xch, uint32_t nr_ports, uint32_t allow_access) { +#if defined(__arm__) || defined(__aarch64__) +/* +* The ARM architecture does not implement I/O ports. +* Avoid the overhead of making a hypercall just for Xen to return -ENOSYS. +* It is safe to ignore this call on ARM so we just return 0. +*/ +return 0 ; +#else DECLARE_DOMCTL ; domctl.cmd = XEN_DOMCTL_ioport_permission;
@@ -1357,6 +1365,7 @@ int xc_domain_ioport_permission(xc_interface *xch, domctl.u.ioport_permission.allow_access = allow_access;return do_domctl (xch, &domctl); +#endif } int xc_availheap(xc_interface *xch,
Signature · 1 line
2.25.1
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call xc_domain_ioport_permission if there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.
Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.
PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
But the IO space does appear when BARs are listed even on Arm.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 16 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.
Quoted 6 lines
PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
IMO instead of faking a successful return value from xc_domain_ioport_permission we should avoid the call completely in the first place, specially if we need to instead issue a call to xc_domain_iomem_permission.
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 24 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
Quoted 7 lines
Quoted 1 line
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
Quoted 5 lines
IMO instead of faking a successful return value from
xc_domain_ioport_permissionwe should avoid the call completely in the first place, specially if we need to instead issue a call toxc_domain_iomem_permission.
At the end we will never have to issue this because this will never be a matter of “iomem” permission as there would not be any way to cut on something under the page. If this is to be supported one day, it will probably have to be fully emulated to keep the isolation.
Right now on arm you can just make the more simple assumption that ioports are just not supported.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 46 lines · Bertrand Marquis
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 24 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
Quoted 7 lines
Quoted 1 line
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
Quoted 5 lines
IMO instead of faking a successful return value from
xc_domain_ioport_permissionwe should avoid the call completely in the first place, specially if we need to instead issue a call toxc_domain_iomem_permission.
Quoted 4 lines
At the end we will never have to issue this because this will never be a matter of “iomem” permission as there would not be any way to cut on something under the page. If this is to be supported one day, it will probably have to be fully emulated to keep the isolation.
So you have a set of memory pages that map accesses from MMIO into IO space but it's not possible to isolate specific IO port regions as they are all contiguous in the same page(s).
Quoted 2 lines
Right now on arm you can just make the more simple assumption that ioports are just not supported.
Would it make sense in the future to provide a memory region to guests in order to use for IO port accesses, and call xc_domain_ioport_permission to set which ports would be allowed?
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Roger,
Quoted 49 lines · Roger Pau Monné
Quoted 46 lines · Bertrand Marquis
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 24 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
Quoted 7 lines
Quoted 1 line
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
Quoted 5 lines
IMO instead of faking a successful return value from
xc_domain_ioport_permissionwe should avoid the call completely in the first place, specially if we need to instead issue a call toxc_domain_iomem_permission.
Quoted 8 lines
Quoted 4 lines
At the end we will never have to issue this because this will never be a matter of “iomem” permission as there would not be any way to cut on something under the page. If this is to be supported one day, it will probably have to be fully emulated to keep the isolation.
So you have a set of memory pages that map accesses from MMIO into IO space but it's not possible to isolate specific IO port regions as they are all contiguous in the same page(s).
Exact.
Quoted 7 lines
Quoted 3 lines
Right now on arm you can just make the more simple assumption that ioports are just not supported.
Would it make sense in the future to provide a memory region to guests in order to use for IO port accesses, and call
xc_domain_ioport_permissionto set which ports would be allowed?
Right now we do not plan to support this at all and we will have to figure this out if we do this one day.
Quoted 5 lines
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
I can add the following to the commit message:
I/O ports accessible through MMIO are currently not supported by Xen.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 74 lines · Bertrand Marquis
Hi Roger,
Quoted 49 lines · Roger Pau Monné
Quoted 46 lines · Bertrand Marquis
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 24 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
Quoted 7 lines
Quoted 1 line
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
Quoted 5 lines
IMO instead of faking a successful return value from
xc_domain_ioport_permissionwe should avoid the call completely in the first place, specially if we need to instead issue a call toxc_domain_iomem_permission.Quoted 8 lines
Quoted 4 lines
At the end we will never have to issue this because this will never be a matter of “iomem” permission as there would not be any way to cut on something under the page. If this is to be supported one day, it will probably have to be fully emulated to keep the isolation.
So you have a set of memory pages that map accesses from MMIO into IO space but it's not possible to isolate specific IO port regions as they are all contiguous in the same page(s).
Exact.
Quoted 7 lines
Quoted 3 lines
Right now on arm you can just make the more simple assumption that ioports are just not supported.
Would it make sense in the future to provide a memory region to guests in order to use for IO port accesses, and call
xc_domain_ioport_permissionto set which ports would be allowed?Right now we do not plan to support this at all and we will have to figure this out if we do this one day.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Roger,
Quoted 86 lines · Roger Pau Monné
Quoted 74 lines · Bertrand Marquis
Hi Roger,
Quoted 49 lines · Roger Pau Monné
Quoted 46 lines · Bertrand Marquis
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 24 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
Hi Roger,
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
Quoted 7 lines
Quoted 1 line
But the IO space does appear when BARs are listed even on Arm.
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
Quoted 5 lines
IMO instead of faking a successful return value from
xc_domain_ioport_permissionwe should avoid the call completely in the first place, specially if we need to instead issue a call toxc_domain_iomem_permission.Quoted 8 lines
Quoted 4 lines
At the end we will never have to issue this because this will never be a matter of “iomem” permission as there would not be any way to cut on something under the page. If this is to be supported one day, it will probably have to be fully emulated to keep the isolation.
So you have a set of memory pages that map accesses from MMIO into IO space but it's not possible to isolate specific IO port regions as they are all contiguous in the same page(s).
Exact.
Quoted 7 lines
Quoted 3 lines
Right now on arm you can just make the more simple assumption that ioports are just not supported.
Would it make sense in the future to provide a memory region to guests in order to use for IO port accesses, and call
xc_domain_ioport_permissionto set which ports would be allowed?Right now we do not plan to support this at all and we will have to figure this out if we do this one day.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
So in the current state I think the way to do it is right.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 20 lines · Bertrand Marquis
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
Quoted 5 lines
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 23 lines · Bertrand Marquis
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 8 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).
A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
Regards
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 37 lines · Bertrand Marquis
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 23 lines · Bertrand Marquis
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 8 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
Quoted 7 lines
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 38 lines · Jan Beulich
Quoted 37 lines · Bertrand Marquis
Hi Jan,
Quoted 23 lines · Jan Beulich
Quoted 20 lines · Bertrand Marquis
Quoted 10 lines · Roger Pau Monné
Quoted 8 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 7 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).
Quoted 5 lines
Quoted 2 lines
A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
If we have the same, but baremetal then which entity disallows those BARs to shine? I mean that if guest wants to crash... why should we stop it and try emulating something special for it?
Quoted 3 lines
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 36 lines · Oleksandr Andrushchenko
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Bertrand Marquis
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Bertrand Marquis
Quoted 10 lines · Roger Pau Monné
Quoted 8 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 7 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
If we have the same, but baremetal then which entity disallows those BARs to shine?
I'm sorry, but I don't understand what you're trying to say.
Quoted 2 lines
I mean that if guest wants to crash... why
should we stop it and try emulating something special for it?
This isn't about a guest "wanting to crash", but a driver potentially getting mislead into thinking that it can driver a device a certain way.
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 44 lines · Jan Beulich
Quoted 36 lines · Oleksandr Andrushchenko
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Bertrand Marquis
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Bertrand Marquis
Quoted 10 lines · Roger Pau Monné
Quoted 8 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 7 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
If we have the same, but baremetal then which entity disallows those BARs to shine?
Quoted 7 lines
I'm sorry, but I don't understand what you're trying to say.
Quoted 2 lines
I mean that if guest wants to crash... why
should we stop it and try emulating something special for it?This isn't about a guest "wanting to crash", but a driver potentially getting mislead into thinking that it can driver a device a certain way.
Well, for the guest, as we do not advertise IO in the emulated host bridge, the driver won't be able to allocate any IO at all. Thus, even if we have a BAR with PCI_BASE_ADDRESS_SPACE_IO bit set, the driver won't get anything. So, I think this is equivalent to a baremetal use-case where we have no IO supported by the host bridge and a device with IO BAR.
Quoted 3 lines
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 15 lines · Oleksandr Andrushchenko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksandr Andrushchenko
Quoted 3 lines · Jan Beulich
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
If we have the same, but baremetal then which entity disallows those BARs to shine?
Quoted 7 lines
I'm sorry, but I don't understand what you're trying to say.
Quoted 2 lines
I mean that if guest wants to crash... why
should we stop it and try emulating something special for it?This isn't about a guest "wanting to crash", but a driver potentially getting mislead into thinking that it can driver a device a certain way.
Quoted 6 lines
Well, for the guest, as we do not advertise IO in the emulated host bridge, the driver won't be able to allocate any IO at all. Thus, even if we have a BAR with
PCI_BASE_ADDRESS_SPACE_IObit set, the driver won't get anything. So, I think this is equivalent to a baremetal use-case where we have no IO supported by the host bridge and a device with IO BAR.
Oh, now I follow. Fair enough.
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Jan,
Quoted 18 lines · Jan Beulich
Quoted 15 lines · Oleksandr Andrushchenko
Quoted 14 lines · Jan Beulich
Quoted 6 lines · Oleksandr Andrushchenko
Quoted 3 lines · Jan Beulich
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
If we have the same, but baremetal then which entity disallows those BARs to shine?
I'm sorry, but I don't understand what you're trying to say.
Quoted 2 lines
I mean that if guest wants to crash... why
should we stop it and try emulating something special for it?This isn't about a guest "wanting to crash", but a driver potentially getting mislead into thinking that it can driver a device a certain way.
Quoted 8 lines
Quoted 6 lines
Well, for the guest, as we do not advertise IO in the emulated host bridge, the driver won't be able to allocate any IO at all. Thus, even if we have a BAR with
PCI_BASE_ADDRESS_SPACE_IObit set, the driver won't get anything. So, I think this is equivalent to a baremetal use-case where we have no IO supported by the host bridge and a device with IO BAR.Oh, now I follow. Fair enough.
So there is no comment remaining on this patch ?
Would it possible to get an ack on it ?
Thanks
Bertrand
Quoted 2 lines
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 1 line · Bertrand Marquis
So there is no comment remaining on this patch ?
No, but the comments weren't on the patch anyway, but on a question raised in the course of the discussion.
Quoted 1 line
Would it possible to get an ack on it ?
No, as I can't ack this patch: I'm not a maintainer of the file being changed. And I don't feel qualified to give an R-b.
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
In reply to Bertrand MarquisBertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM."):
Quoted 1 line
So there is no comment remaining on this patch ?
I have been following this thread. I think I have a notion of why this is needed but I'm not 100% clear on it. The commit message says this:
Quoted 3 lines
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.
which implies it's a performance improvement. But the change also suppresses an error return, so this commit message is false. I think that the thread has concluded something different, but it should be explained in the commit message. The purpose of a commit message is precisely to capture the kind of considerations and discussion that occurred in this thread.
If the overall outcome implied by this patch is correct (as I *think* the thread has concluded) then I don't think the #ifdefery is appropriate. This should be done with a new arch-specific function in libxl_x86.c and libxl_arm.c. I'm not sure precisely what that function should be called, but maybe something like
libxl_ioports_supported
?
I see that the fact that we avoid #ifdefs wasn't documented in CODING_STYLE, so I have sent a patch to add that. Sorry about that.
Thanks,
Ian.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Hi Ian,
Quoted 13 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm:
xc_domain_ioport_permission(..)not supported on ARM."):Quoted 1 line
So there is no comment remaining on this patch ?
I have been following this thread. I think I have a notion of why this is needed but I'm not 100% clear on it. The commit message says this:
Quoted 3 lines
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.
Quoted 6 lines
which implies it's a performance improvement. But the change also suppresses an error return, so this commit message is false. I think that the thread has concluded something different, but it should be explained in the commit message. The purpose of a commit message is precisely to capture the kind of considerations and discussion that occurred in this thread.
I can add something in the commit message about the fact that we improve performance and prevent to do a call that is and will not be supported in Xen.
Quoted 11 lines
If the overall outcome implied by this patch is correct (as I *think* the thread has concluded) then I don't think the #ifdefery is appropriate. This should be done with a new arch-specific function in
libxl_x86.candlibxl_arm.c. I'm not sure precisely what that function should be called, but maybe something like
libxl_ioports_supported
?I see that the fact that we avoid #ifdefs wasn't documented in
CODING_STYLE, so I have sent a patch to add that. Sorry about that.
I saw your change in CODING_STYLE and I understand the request. I will try to see if we can handle this change before the feature freeze.
Regards
Bertrand
Quoted 3 lines
Thanks,
Ian.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Bertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM."):
Quoted 2 lines
I can add something in the commit message about the fact that we improve performance and prevent to do a call that is and will not be supported in Xen.
Thanks but I'm afraid I don't think that is a correct summary of the thread. Nor would it be an adequate justification for the change. At least, not unless you plan to write something considerably longer (and more precise).
Firstly, I'm not convinced this change would be justified by the performance impact. This is a small number of hypercalls during domain startup. Usually none, I think ? If someone wants to optimise domain startup speed then I am very open to that but I think this change will make negligible change in practice. Unless someone wants to tell me I'm wrong about that ? And if I am wrong about that then an explanation of why my suppositions are wrong ought to go in the commit message.
Secondly, there is no justification there for the change in error status.
Why is this change needed ? (What goes wrong if it is omitted ?) That is what the commit message ought to answer.
Plus, given that it stubs out a function to make it into a no-op, that itself requires an explanation. Why is it OK for this function which is supposed to do a thing, to in fact not do anything at all and return successfully saying "yes I did that" ?
I think (having read the thread) that I know the answers to these questions but it needs to be clearly and explicitly written down.
Quoted 2 lines
I saw your change in
CODING_STYLEand I understand the request. I will try to see if we can handle this change before the feature freeze.
Thanks. I doubt that this will be hard. I am more worried about the commit message.
Indeed, since we haven't had the rationale for this change explicitly written down, there is a risk that when we do so, we will discover some problem with the approach that we had previously overlooked.
Discovering that kind of thing is one reason to explicitly write down why we are doing what we are doing, but this situation does mean we shouldn't feel we've yet achieved confidence that this patch is right.
Sorry,
Ian.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 38 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm:
xc_domain_ioport_permission(..)not supported on ARM."):Quoted 2 lines
I can add something in the commit message about the fact that we improve performance and prevent to do a call that is and will not be supported in Xen.
Thanks but I'm afraid I don't think that is a correct summary of the thread. Nor would it be an adequate justification for the change. At least, not unless you plan to write something considerably longer (and more precise).
Firstly, I'm not convinced this change would be justified by the performance impact. This is a small number of hypercalls during domain startup. Usually none, I think ? If someone wants to optimise domain startup speed then I am very open to that but I think this change will make negligible change in practice. Unless someone wants to tell me I'm wrong about that ? And if I am wrong about that then an explanation of why my suppositions are wrong ought to go in the commit message.
Secondly, there is no justification there for the change in error status.
Why is this change needed ? (What goes wrong if it is omitted ?) That is what the commit message ought to answer.
Plus, given that it stubs out a function to make it into a no-op, that itself requires an explanation. Why is it OK for this function which is supposed to do a thing, to in fact not do anything at all and return successfully saying "yes I did that" ?
I think (having read the thread) that I know the answers to these questions but it needs to be clearly and explicitly written down.
Quoted 2 lines
I saw your change in
CODING_STYLEand I understand the request. I will try to see if we can handle this change before the feature freeze.Thanks. I doubt that this will be hard. I am more worried about the commit message.
Quoted 7 lines
Indeed, since we haven't had the rationale for this change explicitly written down, there is a risk that when we do so, we will discover some problem with the approach that we had previously overlooked.
Discovering that kind of thing is one reason to explicitly write down why we are doing what we are doing, but this situation does mean we shouldn't feel we've yet achieved confidence that this patch is right.
I don't think it is about performance. From a performance point of view, we could make as many (unneeded) hypercalls as required. It is mostly about minimizing unwanted changes to common libxl code. Let me explain.
IO ports on ARM don't exist so all IO ports related hypercalls are going to fail. This is expected. Today, a failure of xc_domain_ioport_permission would turn into a critical failure at domain creation. We need to avoid this outcome; instead we want to continue with domain creation as normal even if xc_domain_ioport_permission fails. (FYI the underlying hypercall XEN_DOMCTL_ioport_permission is not implemented on ARM so it would return -ENOSYS.)
We have a few options to achieve this goal:
1) No xc_domain_ioport_permission calls on ARM
Use #ifdefs or similar checks in libxl_pci.c to avoid calling xc_domain_ioport_permission on ARM. This could be best but it would cause some churn in arch-neutral libxl code.
2) Handle xc_domain_ioport_permission errors in libxl
Introduce checks on the return value of xc_domain_ioport_permission and ignore specific errors on ARM in libxl_pci.c.
For instance: if (ARM && rc == -ENOSYS) continue.
This might cause less churn than 1) but still requires a few changes in arch-neutral libxl code.
3) Force XEN_DOMCTL_ioport_permission to return zero on ARM
Force the hypercall to return success even if it did nothing. Currently it returns -ENOSYS.
This is possible but it wasn't chosen for the implementation as we felt that the hypercall should reflect what was actually done (nothing) and it should be userspace to handle the error. I guess this could be argued either way.
4) Force xc_domain_ioport_permission to return zero on ARM
Force xc_domain_ioport_permission to return success even if the hypercall would return -ENOSYS. This way there are no changes to libxl.
This is what the patch currently implements by using #ifdef in xc_domain_ioport_permission. It could also have achieved the same goal by making the implementation of xc_domain_ioport_permission arch-specific, and in the ARM implementation returning 0.
All options above achieve the goal of a successful domain creation with PCI device assigned on ARM. You might be able to think of other options as well. I think noone here is really set on using one option over the other -- as long as xc_domain_ioport_permission failures don't turn into domain creation failures on ARM we are good.
Let us know what you think.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 105 lines · Stefano Stabellini
Quoted 38 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm:
xc_domain_ioport_permission(..)not supported on ARM."):Quoted 2 lines
I can add something in the commit message about the fact that we improve performance and prevent to do a call that is and will not be supported in Xen.
Thanks but I'm afraid I don't think that is a correct summary of the thread. Nor would it be an adequate justification for the change. At least, not unless you plan to write something considerably longer (and more precise).
Firstly, I'm not convinced this change would be justified by the performance impact. This is a small number of hypercalls during domain startup. Usually none, I think ? If someone wants to optimise domain startup speed then I am very open to that but I think this change will make negligible change in practice. Unless someone wants to tell me I'm wrong about that ? And if I am wrong about that then an explanation of why my suppositions are wrong ought to go in the commit message.
Secondly, there is no justification there for the change in error status.
Why is this change needed ? (What goes wrong if it is omitted ?) That is what the commit message ought to answer.
Plus, given that it stubs out a function to make it into a no-op, that itself requires an explanation. Why is it OK for this function which is supposed to do a thing, to in fact not do anything at all and return successfully saying "yes I did that" ?
I think (having read the thread) that I know the answers to these questions but it needs to be clearly and explicitly written down.
Quoted 2 lines
I saw your change in
CODING_STYLEand I understand the request. I will try to see if we can handle this change before the feature freeze.Thanks. I doubt that this will be hard. I am more worried about the commit message.
Quoted 7 lines
Indeed, since we haven't had the rationale for this change explicitly written down, there is a risk that when we do so, we will discover some problem with the approach that we had previously overlooked.
Discovering that kind of thing is one reason to explicitly write down why we are doing what we are doing, but this situation does mean we shouldn't feel we've yet achieved confidence that this patch is right.
I don't think it is about performance. From a performance point of view, we could make as many (unneeded) hypercalls as required. It is mostly about minimizing unwanted changes to common libxl code. Let me explain.
IO ports on ARM don't exist so all IO ports related hypercalls are going to fail. This is expected. Today, a failure of
xc_domain_ioport_permissionwould turn into a critical failure at domain creation. We need to avoid this outcome; instead we want to continue with domain creation as normal even ifxc_domain_ioport_permissionfails. (FYI the underlying hypercallXEN_DOMCTL_ioport_permissionis not implemented on ARM so it would return-ENOSYS.)We have a few options to achieve this goal:
1) No
xc_domain_ioport_permissioncalls on ARMUse #ifdefs or similar checks in
libxl_pci.cto avoid callingxc_domain_ioport_permissionon ARM. This could be best but it would cause some churn in arch-neutral libxl code.2) Handle
xc_domain_ioport_permissionerrors in libxlIntroduce checks on the return value of
xc_domain_ioport_permissionand ignore specific errors on ARM inlibxl_pci.c.
For instance: if (ARM && rc ==-ENOSYS) continue.This might cause less churn than 1) but still requires a few changes in arch-neutral libxl code.
3) Force
XEN_DOMCTL_ioport_permissionto return zero on ARMForce the hypercall to return success even if it did nothing. Currently it returns
-ENOSYS.This is possible but it wasn't chosen for the implementation as we felt that the hypercall should reflect what was actually done (nothing) and it should be userspace to handle the error. I guess this could be argued either way.
4) Force
xc_domain_ioport_permissionto return zero on ARMForce
xc_domain_ioport_permissionto return success even if the hypercall would return-ENOSYS. This way there are no changes to libxl.This is what the patch currently implements by using #ifdef in
xc_domain_ioport_permission. It could also have achieved the same goal by making the implementation ofxc_domain_ioport_permissionarch-specific, and in the ARM implementation returning 0.
Quoted 6 lines
All options above achieve the goal of a successful domain creation with PCI device assigned on ARM. You might be able to think of other options as well. I think noone here is really set on using one option over the other -- as long as
xc_domain_ioport_permissionfailures don't turn into domain creation failures on ARM we are good.
I think having a libxl_arch_io_ports_supported helper could be the cleaner way to do this. For x86 it will unconditionally return true, while for Arm you could consider poking at XEN_DOMCTL_ioport_permission and see if it returns ENOSYS or otherwise.
I guess it's possible that in the future we allow IO ports access on Arm guests using some kind of emulated mechanism if the need arises, at which point the hypercall will be implemented.
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Roger Pau Monné writes ("Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM."):
Quoted 4 lines · Stefano Stabellini
Quoted 3 lines
I don't think it is about performance. From a performance point of view, we could make as many (unneeded) hypercalls as required. It is mostly about minimizing unwanted changes to common libxl code. Let me explain.
Thanks. This summary is helpful And, pleasingly, it matches what I had thought I had gleaned from the thread.
Quoted 12 lines
Quoted 5 lines
All options above achieve the goal of a successful domain creation with PCI device assigned on ARM. You might be able to think of other options as well. I think noone here is really set on using one option over the other -- as long as
xc_domain_ioport_permissionfailures don't turn into domain creation failures on ARM we are good.I think having a
libxl_arch_io_ports_supportedhelper could be the cleaner way to do this. For x86 it will unconditionally return true, while for Arm you could consider poking atXEN_DOMCTL_ioport_permissionand see if it returns ENOSYS or otherwise.
Quoted 3 lines
I guess it's possible that in the future we allow IO ports access on Arm guests using some kind of emulated mechanism if the need arises, at which point the hypercall will be implemented.
I agree with Roger.
So I think I would like to see a version of this patch which
* Introduces libxl_arch_io_ports_supported. (I am fine with it just returning false, unconditionally on Arm, ie in libxl_arm.c.)
* Has a commit message explaining what is actually going on. Cutting and pasting liberally from your email seems like it would be a very good starting point. Even discussion of rejected alternatives is fine, if it seems like it fits. I'm quite unlikely to object to a commit message on grounds that it's too long.
Thanks,
Ian.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
In reply to Bertrand MarquisQuoted 22 lines · Bertrand Marquis
Hi Ian,
Quoted 13 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v5 01/11] xen/arm:
xc_domain_ioport_permission(..)not supported on ARM."):Quoted 1 line
So there is no comment remaining on this patch ?
I have been following this thread. I think I have a notion of why this is needed but I'm not 100% clear on it. The commit message says this:
Quoted 3 lines
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
which implies it's a performance improvement. But the change also suppresses an error return, so this commit message is false. I think that the thread has concluded something different, but it should be explained in the commit message. The purpose of a commit message is precisely to capture the kind of considerations and discussion that occurred in this thread.
Quoted 2 lines
I can add something in the commit message about the fact that we improve performance and prevent to do a call that is and will not be supported in Xen.
IMO it would be good to modify the commit message so it covers the fact that the emulated host bridge on Arm does not advertise IO port support, so the guest is capable of realizing IO BARs are not supported.
Otherwise it seems like the toolstack is ignoring a failure which could cause a device to malfunction when passed though (which is still the case, but the guest will be able to notice).
Thanks, Roger.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Roger Pau Monné writes ("Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM."):
Quoted 4 lines
IMO it would be good to modify the commit message so it covers the fact that the emulated host bridge on Arm does not advertise IO port support, so the guest is capable of realizing IO BARs are not supported.
Yes.
Quoted 3 lines
Otherwise it seems like the toolstack is ignoring a failure which could cause a device to malfunction when passed though (which is still the case, but the guest will be able to notice).
Quite.
Thanks,
Ian.
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
In reply to Jan BeulichHi Jan,
Quoted 45 lines · Jan Beulich
Quoted 42 lines · Bertrand Marquis
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 23 lines · Bertrand Marquis
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 8 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).
Quoted 6 lines
Quoted 2 lines
A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
We are emulating an ECAM PCI which does not support I/O ports so I do not think we are (and can) expose those to guests.
Anyway I will mark this as a point to check for Rahul when he is back.
Cheers
Bertrand
Quoted 2 lines
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
Quoted 50 lines · Bertrand Marquis
Hi Jan,
Quoted 48 lines · Jan Beulich
Quoted 44 lines · Bertrand Marquis
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 23 lines · Bertrand Marquis
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
I think the commit message needs to at least be expanded in order to contain the information provided here. It might also be helpful to figure out whether we would have to handle IO port accesses in the future on Arm, or if it's fine to just ignore them.
All our investigations and tests have been done without supporting it without any issues so this is not a critical feature (most devices can be operated without using the I/O ports).
Quoted 7 lines
IMO we should let the users know they attempted to use a device with BARs in the IO space, and that those BARs won't be accessible which could make the device not function as expected.
Do you think it would be reasonable to attempt the hypercall on Arm also, and in case of error (on Arm) just print a warning message and continue operations as normal?
I think this would lead to a warning printed on lots of devices where in fact there would be no issues.
Quoted 8 lines
Quoted 2 lines
If this is an issue for a device driver because it cannot operate without I/O ports, this will be raised by the driver inside the guest.
On what basis would the driver complain? The kernel might know of the MMIO equivalent for ports, and hence might allow the driver to properly obtain whatever is needed to later access the ports. Just that the port accesses then wouldn't work (possibly crashing the guest, or making it otherwise misbehave).
As ECAM and Arm does not support I/O ports, a driver requesting access to them would get an error back.
So in practice it is not possible to try to access the ioports as there is no way on arm to use them (no instructions).A driver could misbehave by ignoring the fact that ioports are not there but I am not quite sure how we could solve that as it would be a bug in the driver.
Quoted 6 lines
Quoted 3 lines
The minimal thing I'd suggest (or maybe you're doing this already) would be to expose such BARs to the guest as r/o zero, rather than letting their port nature "shine through".
We are emulating an ECAM PCI which does not support I/O ports so I do not think we are (and can) expose those to guests.
I'm afraid I don't follow: What do you mean by "expose to guests" in relation to what I've said? I did specifically suggest to hide the real nature of such BARs, and instead surface them such that the guest would have to conclude the BAR is actually not in use at all.
Jan
Re: [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM.
In reply to Bertrand MarquisHi, all
Quoted 27 lines · Bertrand Marquis
Hi Roger,
+ Oleksandr to have a better PCI expert then me.
Quoted 23 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
Hi Roger,
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return
-ENOSYS.Quoted 6 lines
What is the cal trace of this function actually on Arm?
AFAICT libxl will only call
xc_domain_ioport_permissionif there are IO ports explicitly defined in the guest configuration, or if any of the BARs of the PCI device is in the IO space, which is not possible on Arm.PCI devices BARs can be in the IO space as the PCI devices are not Arm specific. There is not ioports on arm so to be used those can be in some cases remapped and accessed as MMIOs or are not possible to use at all.
But the IO space does appear when BARs are listed even on Arm.
Quoted 9 lines
Quoted 5 lines
Urg, I wonder whether those devices with IO BARs will work correctly under Arm then.
How do you know whether the BAR has been remapped from IO space into MMIO?
We cannot, I think the platform will define if this is the case and where. @oleksandr: I remember that this was discussed during some of our meetings but I have no idea of the details here, can you help ?
For the guest domains we emulate a host bridge without IO, so the guest won't be able to assign any IO memory at all.
PATCH v5 2/11 xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM
In reply to Rahul SinghHardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call PHYSDEVOP_pci_device_add(..) to add the PCI devices in XEN.
Also implement PHYSDEVOP_pci_device_remove(..) to remove the PCI device.
As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication.
There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implemented PHYSDEVOP_pci_device_remove(..) and PHYSDEVOP_pci_device_add(..) only as those are minimum required to support PCI passthrough on ARM.
---
Change in v5:
- Move the pci_physdev_op() stub to xen/arch/arm/physdev.c. Change in v4:
- Move file commom/physdev.c to drivers/pci/physdev.c
- minor comments.
Change in v3: Fixed minor comment.
Change in v2:
- Add support for PHYSDEVOP_pci_device_remove()
- Move code to common code
---
--- xen/arch/arm/physdev.c | 6 ++- xen/arch/x86/physdev.c | 52 +---------------------- xen/arch/x86/x86_64/physdev.c | 2 +- xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 80 +++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 +- xen/include/xen/hypercall.h | 4 ++ 7 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 xen/drivers/pci/physdev.c
xen/arch/arm/physdev.c +5 -1
@@ -8,13 +8,17 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { +#ifdef CONFIG_HAS_PCI +return pci_physdev_op (cmd, arg); +#else gdprintk (XENLOG_DEBUG ,"PHYSDEVOP cmd=%d: not implemented\n" , cmd);return -ENOSYS ; +#endif }/*
xen/arch/x86/physdev.c +2 -50
70 lines not on this page · raw message
xen/arch/x86/x86_64/physdev.c +1 -1
@@ -9,7 +9,7 @@ EMIT_FILE;#include <compat/xen.h> #include <compat/event_channel.h> #include <compat/physdev.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #define do_physdev_op compat_physdev_op
xen/drivers/pci/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += pci.o +obj-y += physdev.o
xen/drivers/pci/physdev.c new file +80 -0
80 lines not on this page · raw message
xen/include/public/arch-arm.h +3 -1
@@ -107,7 +107,9 @@* All generic sub-operations * * HYPERVISOR_physdev_op -* No sub-operations are currenty supported +* Exactly these sub-operations are supported: +* PHYSDEVOP_pci_device_add +* PHYSDEVOP_pci_device_remove * * HYPERVISOR_sysctl * All generic sub-operations, with the exception of:
xen/include/xen/hypercall.h +4 -0
@@ -45,6 +45,10 @@ extern longdo_platform_op (XEN_GUEST_HANDLE_PARAM (xen_platform_op_t ) u_xenpf_op); +extern long +pci_physdev_op ( +int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +/* * To allow safe resume of do_memory_op() after preemption, we need to know * at what point in the page list to resume. For this purpose I steal the
Signature · 1 line
2.25.1
Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM
Quoted 9 lines · Rahul Singh
Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call
PHYSDEVOP_pci_device_add(..)to add the PCI devices in XEN.Also implement
PHYSDEVOP_pci_device_remove(..)to remove the PCI device.As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication.
Quoted 6 lines
There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implemented
PHYSDEVOP_pci_device_remove(..)andPHYSDEVOP_pci_device_add(..)only as those are minimum required to support PCI passthrough on ARM.Signed-off-by Rahul Singh <[email protected]>
Quoted 261 lines
---
Change in v5:
- Move thepci_physdev_op()stub toxen/arch/arm/physdev.c. Change in v4:
- Move filecommom/physdev.ctodrivers/pci/physdev.c
- minor comments.
Change in v3: Fixed minor comment.
Change in v2:
- Add support forPHYSDEVOP_pci_device_remove()
- Move code to common code
------ xen/arch/arm/physdev.c | 6 ++- xen/arch/x86/physdev.c | 52 +---------------------- xen/arch/x86/x86_64/physdev.c | 2 +- xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 80 +++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 +- xen/include/xen/hypercall.h | 4 ++ 7 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 xen/drivers/pci/physdev.cxen/arch/arm/physdev.c +5
-1@@ -8,13 +8,17 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { +#ifdef CONFIG_HAS_PCI +return pci_physdev_op (cmd, arg); +#else gdprintk (XENLOG_DEBUG ,"PHYSDEVOP cmd=%d: not implemented\n" , cmd);return -ENOSYS ; +#endif }/* xen/arch/x86/physdev.c +2
-50@@ -12,7 +12,7 @@#include <asm/io_apic.h> #include <asm/msi.h> #include <asm/hvm/irq.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #include <public/xen.h> #include <public/physdev.h> #include <xsm/xsm.h> @@ -480,54 +480,6 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } -case PHYSDEVOP_pci_device_add: { -struct physdev_pci_device_add add; -struct pci_dev_info pdev_info; -nodeid_t node; - - ret = -EFAULT ; -if (copy_from_guest (&add, arg,1 ) !=0 ) -break ; - - pdev_info.is_extfn = !!(add.flags &XEN_PCI_DEV_EXTFN ); -if ( add.flags &XEN_PCI_DEV_VIRTFN ) - { - pdev_info.is_virtfn =1 ; - pdev_info.physfn.bus = add.physfn.bus; - pdev_info.physfn.devfn = add.physfn.devfn; - } -else - pdev_info.is_virtfn =0 ; - -if ( add.flags &XEN_PCI_DEV_PXM ) - { -uint32_t pxm; -size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / -sizeof (add.optarr[0 ]); - -if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) -break ; - - node =pxm_to_node (pxm); - } -else - node =NUMA_NO_NODE ; - - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); -break ; - } - -case PHYSDEVOP_pci_device_remove: { -struct physdev_pci_device dev; - - ret = -EFAULT ; -if (copy_from_guest (&dev, arg,1 ) !=0 ) -break ; - - ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); -break ; - } -case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev;@@ -663,7 +615,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }default : - ret = -ENOSYS ; + ret =pci_physdev_op (cmd, arg);break ; }xen/arch/x86/x86_64/physdev.c +1
-1@@ -9,7 +9,7 @@ EMIT_FILE;#include <compat/xen.h> #include <compat/event_channel.h> #include <compat/physdev.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #define do_physdev_op compat_physdev_opxen/drivers/pci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += pci.o +obj-y += physdev.oxen/drivers/pci/physdev.c new file +80
-0@@ -0,0 +1,80 @@ + +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <xen/init.h> + +#ifndef COMPAT +typedef long ret_t ; +#endif + +ret_t pci_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +ret_t ret; + +switch ( cmd ) + { +case PHYSDEVOP_pci_device_add: { +struct physdev_pci_device_add add; +struct pci_dev_info pdev_info; +nodeid_t node =NUMA_NO_NODE ; + + ret = -EFAULT ; +if (copy_from_guest (&add, arg,1 ) !=0 ) +break ; + + pdev_info.is_extfn = (add.flags &XEN_PCI_DEV_EXTFN ); +if ( add.flags &XEN_PCI_DEV_VIRTFN ) + { + pdev_info.is_virtfn = true; + pdev_info.physfn.bus = add.physfn.bus; + pdev_info.physfn.devfn = add.physfn.devfn; + } +else + pdev_info.is_virtfn = false; + +#ifdef CONFIG_NUMA +if ( add.flags &XEN_PCI_DEV_PXM ) + { +uint32_t pxm; +size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / +sizeof (add.optarr[0 ]); + +if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) +break ; + + node =pxm_to_node (pxm); + } +#endif + + ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); +break ; + } + +case PHYSDEVOP_pci_device_remove: { +struct physdev_pci_device dev; + + ret = -EFAULT ; +if (copy_from_guest (&dev, arg,1 ) !=0 ) +break ; + + ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); +break ; + } + +default : + ret = -ENOSYS ; +break ; + } + +return ret; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +3
-1@@ -107,7 +107,9 @@* All generic sub-operations * * HYPERVISOR_physdev_op -* No sub-operations are currenty supported +* Exactly these sub-operations are supported: +* PHYSDEVOP_pci_device_add +* PHYSDEVOP_pci_device_remove * * HYPERVISOR_sysctl * All generic sub-operations, with the exception of: xen/include/xen/hypercall.h +4
-0@@ -45,6 +45,10 @@ extern longdo_platform_op (XEN_GUEST_HANDLE_PARAM (xen_platform_op_t ) u_xenpf_op); +extern long +pci_physdev_op ( +int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +/* * To allow safe resume of do_memory_op() after preemption, we need to know * at what point in the page list to resume. For this purpose I steal the Signature · 1 line
2.25.1
Jan Beulich
Acked-byRe: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Rahul Singh
Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call
PHYSDEVOP_pci_device_add(..)to add the PCI devices in XEN.Also implement
PHYSDEVOP_pci_device_remove(..)to remove the PCI device.As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication.
Quoted 8 lines
Quoted 6 lines
There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implemented
PHYSDEVOP_pci_device_remove(..)andPHYSDEVOP_pci_device_add(..)only as those are minimum required to support PCI passthrough on ARM.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>
xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM)
In reply to Rahul SinghHi all,
While going through the passthrough code. I noticed that we don't have a common lock for the IOMMU between the PCI and DT code.
This is going to be an issue given it would technically be possible to add a PCI device while assigning a DT.
Rahul, Bertrand, Oleksandr, can you have a look at the issue?
Cheers,
Quoted 274 lines · Rahul Singh
Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call
PHYSDEVOP_pci_device_add(..)to add the PCI devices in XEN.Also implement
PHYSDEVOP_pci_device_remove(..)to remove the PCI device.As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication.
There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implemented
PHYSDEVOP_pci_device_remove(..)andPHYSDEVOP_pci_device_add(..)only as those are minimum required to support PCI passthrough on ARM.Signed-off-by Rahul Singh <[email protected]>---
Change in v5:
- Move thepci_physdev_op()stub toxen/arch/arm/physdev.c. Change in v4:
- Move filecommom/physdev.ctodrivers/pci/physdev.c
- minor comments.
Change in v3: Fixed minor comment.
Change in v2:
- Add support forPHYSDEVOP_pci_device_remove()
- Move code to common code
------ xen/arch/arm/physdev.c | 6 ++- xen/arch/x86/physdev.c | 52 +---------------------- xen/arch/x86/x86_64/physdev.c | 2 +- xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 80 +++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 +- xen/include/xen/hypercall.h | 4 ++ 7 files changed, 96 insertions(+), 53 deletions(-)create mode 100644
xen/drivers/pci/physdev.cxen/arch/arm/physdev.c +5
-1@@ -8,13 +8,17 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { +#ifdef CONFIG_HAS_PCI +return pci_physdev_op (cmd, arg); +#else gdprintk (XENLOG_DEBUG ,"PHYSDEVOP cmd=%d: not implemented\n" , cmd);return -ENOSYS ; +#endif }/* xen/arch/x86/physdev.c +2
-50@@ -12,7 +12,7 @@#include <asm/io_apic.h> #include <asm/msi.h> #include <asm/hvm/irq.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #include <public/xen.h> #include <public/physdev.h> #include <xsm/xsm.h> @@ -480,54 +480,6 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } -case PHYSDEVOP_pci_device_add: { -struct physdev_pci_device_add add; -struct pci_dev_info pdev_info; -nodeid_t node; - - ret = -EFAULT ; -if (copy_from_guest (&add, arg,1 ) !=0 ) -break ; - - pdev_info.is_extfn = !!(add.flags &XEN_PCI_DEV_EXTFN ); -if ( add.flags &XEN_PCI_DEV_VIRTFN ) - { - pdev_info.is_virtfn =1 ; - pdev_info.physfn.bus = add.physfn.bus; - pdev_info.physfn.devfn = add.physfn.devfn; - } -else - pdev_info.is_virtfn =0 ; - -if ( add.flags &XEN_PCI_DEV_PXM ) - { -uint32_t pxm; -size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / -sizeof (add.optarr[0 ]); - -if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) -break ; - - node =pxm_to_node (pxm); - } -else - node =NUMA_NO_NODE ; - - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); -break ; - } - -case PHYSDEVOP_pci_device_remove: { -struct physdev_pci_device dev; - - ret = -EFAULT ; -if (copy_from_guest (&dev, arg,1 ) !=0 ) -break ; - - ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); -break ; - } -case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev;@@ -663,7 +615,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }default : - ret = -ENOSYS ; + ret =pci_physdev_op (cmd, arg);break ; }xen/arch/x86/x86_64/physdev.c +1
-1@@ -9,7 +9,7 @@ EMIT_FILE;#include <compat/xen.h> #include <compat/event_channel.h> #include <compat/physdev.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #define do_physdev_op compat_physdev_opxen/drivers/pci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += pci.o +obj-y += physdev.oxen/drivers/pci/physdev.c new file +80
-0@@ -0,0 +1,80 @@ + +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <xen/init.h> + +#ifndef COMPAT +typedef long ret_t ; +#endif + +ret_t pci_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +ret_t ret; + +switch ( cmd ) + { +case PHYSDEVOP_pci_device_add: { +struct physdev_pci_device_add add; +struct pci_dev_info pdev_info; +nodeid_t node =NUMA_NO_NODE ; + + ret = -EFAULT ; +if (copy_from_guest (&add, arg,1 ) !=0 ) +break ; + + pdev_info.is_extfn = (add.flags &XEN_PCI_DEV_EXTFN ); +if ( add.flags &XEN_PCI_DEV_VIRTFN ) + { + pdev_info.is_virtfn = true; + pdev_info.physfn.bus = add.physfn.bus; + pdev_info.physfn.devfn = add.physfn.devfn; + } +else + pdev_info.is_virtfn = false; + +#ifdef CONFIG_NUMA +if ( add.flags &XEN_PCI_DEV_PXM ) + { +uint32_t pxm; +size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / +sizeof (add.optarr[0 ]); + +if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) +break ; + + node =pxm_to_node (pxm); + } +#endif + + ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); +break ; + } + +case PHYSDEVOP_pci_device_remove: { +struct physdev_pci_device dev; + + ret = -EFAULT ; +if (copy_from_guest (&dev, arg,1 ) !=0 ) +break ; + + ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); +break ; + } + +default : + ret = -ENOSYS ; +break ; + } + +return ret; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +3
-1@@ -107,7 +107,9 @@* All generic sub-operations * * HYPERVISOR_physdev_op -* No sub-operations are currenty supported +* Exactly these sub-operations are supported: +* PHYSDEVOP_pci_device_add +* PHYSDEVOP_pci_device_remove * * HYPERVISOR_sysctl * All generic sub-operations, with the exception of: xen/include/xen/hypercall.h +4
-0@@ -45,6 +45,10 @@ extern longdo_platform_op (XEN_GUEST_HANDLE_PARAM (xen_platform_op_t ) u_xenpf_op); +extern long +pci_physdev_op ( +int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +/* * To allow safe resume of do_memory_op() after preemption, we need to know * at what point in the page list to resume. For this purpose I steal the
Signature · 1 line
Julien Grall
Re: xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM)
Hi Julien,
Quoted 9 lines · Julien Grall
Hi all,
While going through the passthrough code. I noticed that we don't have a common lock for the IOMMU between the PCI and DT code.
This is going to be an issue given it would technically be possible to add a PCI device while assigning a DT.
Rahul, Bertrand, Oleksandr, can you have a look at the issue?
Yes we can have a look at this.
Right now pci device add is done by dom0 so I do not think we have an issue in practice unless I wrongly understood something. But for sure in theory yes we need to look at this.
Cheers
Bertrand
Quoted 266 lines
Cheers,
Quoted 259 lines · Rahul Singh
Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call
PHYSDEVOP_pci_device_add(..)to add the PCI devices in XEN. Also implementPHYSDEVOP_pci_device_remove(..)to remove the PCI device. As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication. There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implementedPHYSDEVOP_pci_device_remove(..)andPHYSDEVOP_pci_device_add(..)only as those are minimum required to support PCI passthrough on ARM.Signed-off-by Rahul Singh <[email protected]>---
Change in v5:
- Move thepci_physdev_op()stub toxen/arch/arm/physdev.c. Change in v4:
- Move filecommom/physdev.ctodrivers/pci/physdev.c
- minor comments.
Change in v3: Fixed minor comment.
Change in v2:
- Add support forPHYSDEVOP_pci_device_remove()
- Move code to common code
------ xen/arch/arm/physdev.c | 6 ++- xen/arch/x86/physdev.c | 52 +---------------------- xen/arch/x86/x86_64/physdev.c | 2 +- xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 80 +++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 +- xen/include/xen/hypercall.h | 4 ++ 7 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 xen/drivers/pci/physdev.cxen/arch/arm/physdev.c +5
-1@@ -8,13 +8,17 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { +#ifdef CONFIG_HAS_PCI +return pci_physdev_op (cmd, arg); +#else gdprintk (XENLOG_DEBUG ,"PHYSDEVOP cmd=%d: not implemented\n" , cmd);return -ENOSYS ; +#endif }/* xen/arch/x86/physdev.c +2
-49@@ -12,7 +12,7 @@#include <asm/io_apic.h> #include <asm/msi.h> #include <asm/hvm/irq.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #include <public/xen.h> #include <public/physdev.h> #include <xsm/xsm.h> @@ -480,54 +480,6 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } - case PHYSDEVOP_pci_device_add: { -struct physdev_pci_device_add add; -struct pci_dev_info pdev_info; -nodeid_t node; - - ret = -EFAULT ; -if (copy_from_guest (&add, arg,1 ) !=0 ) -break ; - - pdev_info.is_extfn = !!(add.flags &XEN_PCI_DEV_EXTFN ); -if ( add.flags &XEN_PCI_DEV_VIRTFN ) - { - pdev_info.is_virtfn =1 ; - pdev_info.physfn.bus = add.physfn.bus; - pdev_info.physfn.devfn = add.physfn.devfn; - } -else - pdev_info.is_virtfn =0 ; - -if ( add.flags &XEN_PCI_DEV_PXM ) - { -uint32_t pxm; -size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / -sizeof (add.optarr[0 ]); - -if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) -break ; - - node =pxm_to_node (pxm); - } -else - node =NUMA_NO_NODE ; - - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); -break ; - } - -case PHYSDEVOP_pci_device_remove: { -struct physdev_pci_device dev; - - ret = -EFAULT ; -if (copy_from_guest (&dev, arg,1 ) !=0 ) -break ; - - ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); -break ; - } -case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev;@@ -663,7 +615,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }default : - ret = -ENOSYS ; + ret =pci_physdev_op (cmd, arg);break ; } diff --git a/xen/arch/x86/x86_64/physdev.c b/xen/arch/x86/x86_64/physdev.cindex
0a50cbd4d8..e3cbd5ebcb100644xen/arch/x86/x86_64/physdev.c +1
-1@@ -9,7 +9,7 @@ EMIT_FILE;#include <compat/xen.h> #include <compat/event_channel.h> #include <compat/physdev.h> -#include <asm/hypercall.h> +#include <xen/hypercall.h> #define do_physdev_op compat_physdev_op diff --git a/xen/drivers/pci/Makefile b/xen/drivers/pci/Makefileindex
a98035df4c..972c923db0100644xen/drivers/pci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += pci.o +obj-y += physdev.oxen/drivers/pci/physdev.c new file +80
-0@@ -0,0 +1,80 @@ + +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <xen/init.h> + +#ifndef COMPAT +typedef long ret_t ; +#endif + +ret_t pci_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +ret_t ret; + +switch ( cmd ) + { +case PHYSDEVOP_pci_device_add: { +struct physdev_pci_device_add add; +struct pci_dev_info pdev_info; +nodeid_t node =NUMA_NO_NODE ; + + ret = -EFAULT ; +if (copy_from_guest (&add, arg,1 ) !=0 ) +break ; + + pdev_info.is_extfn = (add.flags &XEN_PCI_DEV_EXTFN ); +if ( add.flags &XEN_PCI_DEV_VIRTFN ) + { + pdev_info.is_virtfn = true; + pdev_info.physfn.bus = add.physfn.bus; + pdev_info.physfn.devfn = add.physfn.devfn; + } +else + pdev_info.is_virtfn = false; + +#ifdef CONFIG_NUMA +if ( add.flags &XEN_PCI_DEV_PXM ) + { +uint32_t pxm; +size_t optarr_off = offsetof(struct physdev_pci_device_add , optarr) / +sizeof (add.optarr[0 ]); + +if (copy_from_guest_offset (&pxm, arg, optarr_off,1 ) ) +break ; + + node =pxm_to_node (pxm); + } +#endif + + ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); +break ; + } + +case PHYSDEVOP_pci_device_remove: { +struct physdev_pci_device dev; + + ret = -EFAULT ; +if (copy_from_guest (&dev, arg,1 ) !=0 ) +break ; + + ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); +break ; + } + +default : + ret = -ENOSYS ; +break ; + } + +return ret; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +3
-1@@ -107,7 +107,9 @@* All generic sub-operations * * HYPERVISOR_physdev_op -* No sub-operations are currenty supported +* Exactly these sub-operations are supported: +* PHYSDEVOP_pci_device_add +* PHYSDEVOP_pci_device_remove * * HYPERVISOR_sysctl * All generic sub-operations, with the exception of: xen/include/xen/hypercall.h +3
-0@@ -45,6 +45,10 @@ extern longdo_platform_op (XEN_GUEST_HANDLE_PARAM (xen_platform_op_t ) u_xenpf_op); +extern long +pci_physdev_op ( +int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +/* * To allow safe resume of do_memory_op() after preemption, we need to know * at what point in the page list to resume. For this purpose I steal the Signature · 1 line
Julien Grall
Re: xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM)
Quoted 1 line · Bertrand Marquis
Hi Julien,
Hi Bertand,
Quoted 6 lines
Quoted 6 lines · Julien Grall
Hi all,
While going through the passthrough code. I noticed that we don't have a common lock for the IOMMU between the PCI and DT code.
Quoted 7 lines
Quoted 3 lines
This is going to be an issue given it would technically be possible to add a PCI device while assigning a DT.
Rahul, Bertrand, Oleksandr, can you have a look at the issue?
Yes we can have a look at this.
Right now pci device add is done by dom0 so I do not think we have an issue in practice unless I wrongly understood something
This will depend on the XSM policy. With the default one, then yes I agree that only dom0 (we don't support hardware domain) can add PCI device.
However, this restriction doesn't really matter here. You would be relying on dom0 to do the locking and AFAIK this doesn't exist. Instead, the admin would have to ensure that two don't happen at the same time.
Anyway, I think Xen should take care of preventing concurrent IOMMU operations rather than relying on external subsystem (e.g. dom0) to do it. At least the Arm SMMU driver will rely the generic locking to modify atomically internal list.
Cheers,
Signature · 1 line
Julien Grall
Re: xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM)
Hi Julien,
Quoted 17 lines · Julien Grall
Quoted 1 line · Bertrand Marquis
Hi Julien,
Hi Bertand,
Quoted 8 lines
Quoted 8 lines · Julien Grall
Hi all,
While going through the passthrough code. I noticed that we don't have a common lock for the IOMMU between the PCI and DT code.
This is going to be an issue given it would technically be possible to add a PCI device while assigning a DT.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Rahul, Bertrand, Oleksandr, can you have a look at the issue?
Yes we can have a look at this.
Right now pci device add is done by dom0 so I do not think we have an issue in practice unless I wrongly understood somethingThis will depend on the XSM policy. With the default one, then yes I agree that only dom0 (we don't support hardware domain) can add PCI device.
However, this restriction doesn't really matter here. You would be relying on dom0 to do the locking and AFAIK this doesn't exist. Instead, the admin would have to ensure that two don't happen at the same time.
Anyway, I think Xen should take care of preventing concurrent IOMMU operations rather than relying on external subsystem (e.g. dom0) to do it. At least the Arm SMMU driver will rely the generic locking to modify atomically internal list.
Agree, was just trying to make sure I understood the problem correctly. We will check that.
Cheers
Bertrand
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 3/11 xen/arm: Add cmdline boot option "pci-passthrough = <boolean>"
In reply to Rahul SinghAdd cmdline boot option "pci-passthrough = = <boolean>" to enable or disable the PCI passthrough support on ARM.
---
Change in v5: none
Change in v4:
- Fixe minor comments
- Added Reviewed-by: Bertrand Marquis <[email protected]>
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v3:
- Remove "define pci_passthrough_enabled (false)"
- Fixed coding style and minor comment
Change in v2:
- Add option in xen-command-line.pandoc
- Change pci option to pci-passthrough
- modify option from custom_param to boolean param
---
--- docs/misc/xen-command-line.pandoc | 7 +++++++ xen/arch/arm/pci/pci.c | 12 ++++++++++++ xen/drivers/pci/physdev.c | 6 ++++++ xen/include/asm-arm/pci.h | 11 +++++++++++ xen/include/asm-x86/pci.h | 6 ++++++ 5 files changed, 42 insertions(+)
docs/misc/xen-command-line.pandoc +7 -0
@@ -1819,6 +1819,13 @@ All numbers specified must be hexadecimal ones. This option can be specified more than once (up to 8 times at present). +### pci-passthrough (arm) +> `= <boolean>` + +> Default: `false` + +Flag to enable or disable support for PCI passthrough + ### pcid (x86) > `= <boolean> | xpti=<bool>`
xen/arch/arm/pci/pci.c +12 -0
@@ -16,6 +16,7 @@#include <xen/device_tree.h> #include <xen/errno.h> #include <xen/init.h> +#include <xen/param.h> #include <xen/pci.h> /*
@@ -62,8 +63,19 @@ static int __init acpi_pci_init(void) }#endif +/* By default pci passthrough is disabled. */ +bool __read_mostly pci_passthrough_enabled; +boolean_param ("pci-passthrough" , pci_passthrough_enabled); +static int __init pci_init (void ) { +/* +* Enable PCI passthrough when has been enabled explicitly +* (pci-passthrough=on). +*/ +if ( !pci_passthrough_enabled ) +return 0 ; +pci_segments_init ();if ( acpi_disabled )
xen/drivers/pci/physdev.c +6 -0
@@ -18,6 +18,9 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)struct pci_dev_info pdev_info;nodeid_t node =NUMA_NO_NODE ; +if ( !is_pci_passthrough_enabled () ) +return -EOPNOTSUPP ; + ret = -EFAULT ;if (copy_from_guest (&add, arg,1 ) !=0 )break ;
@@ -53,6 +56,9 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case PHYSDEVOP_pci_device_remove: {struct physdev_pci_device dev; +if ( !is_pci_passthrough_enabled () ) +return -EOPNOTSUPP ; + ret = -EFAULT ;if (copy_from_guest (&dev, arg,1 ) !=0 )break ;
xen/include/asm-arm/pci.h +11 -0
@@ -19,14 +19,25 @@#define pci_to_dev (pcidev) (&(pcidev)->arch.dev) +extern bool_t pci_passthrough_enabled; +/* Arch pci dev struct */ struct arch_pci_dev {struct device dev; }; +static always_inline bool is_pci_passthrough_enabled(void) +{ +return pci_passthrough_enabled; +}#else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { }; +static always_inline bool is_pci_passthrough_enabled(void) +{ +return false; +} +#endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */
xen/include/asm-x86/pci.h +6 -0
@@ -32,4 +32,10 @@ bool_t pci_ro_mmcfg_decode(unsigned long mfn, unsigned int *seg,extern int pci_mmcfg_config_num;extern struct acpi_mcfg_allocation *pci_mmcfg_config; +/* Unlike ARM, PCI passthrough is always enabled for x86. */ +static always_inline bool is_pci_passthrough_enabled(void) +{ +return true; +} +#endif /* __X86_PCI_H__ */
Signature · 1 line
2.25.1
Re: [PATCH v5 03/11] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>"
xen/arch/arm/pci/pci.c static int __init acpi_pci_init(void) · line 67
Quoted 6 lines · Rahul Singh
xen/arch/arm/pci/pci.c +2
-0@@ -62,8 +63,19 @@ static int __init acpi_pci_init(void) }#endif +/* By default pci passthrough is disabled. */ +bool __read_mostly pci_passthrough_enabled;
You properly use "bool " here. Why ...
xen/include/asm-arm/pci.h line 22
Quoted 7 lines
xen/include/asm-arm/pci.h +1
-0@@ -19,14 +19,25 @@#define pci_to_dev (pcidev) (&(pcidev)->arch.dev) +extern bool_t pci_passthrough_enabled;
... the being phased out "bool_t" here?
Jan
Re: [PATCH v5 03/11] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>"
Hi Jan,
Quoted 16 lines · Jan Beulich
xen/arch/arm/pci/pci.c static int __init acpi_pci_init(void) · line 67
Quoted 6 lines · Rahul Singh
xen/arch/arm/pci/pci.c +2
-0@@ -62,8 +63,19 @@ static int __init acpi_pci_init(void) }#endif +/* By default pci passthrough is disabled. */ +bool __read_mostly pci_passthrough_enabled;You properly use "bool " here. Why ...
Quoted 4 lines
xen/include/asm-arm/pci.h +0
-0@@ -19,14 +19,25 @@
Quoted 5 lines
xen/include/asm-arm/pci.h line 22
Quoted 3 lines
xen/include/asm-arm/pci.h +1
-0#define pci_to_dev (pcidev) (&(pcidev)->arch.dev) +extern bool_t pci_passthrough_enabled;... the being phased out "
bool_t" here?
I missed that I will fix this.
Regards,
Rahul
Quoted 3 lines
Jan
Re: [PATCH v5 03/11] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>"
In reply to Rahul SinghQuoted 6 lines · Rahul Singh
Add cmdline boot option "pci-passthrough = = <boolean>" to enable or disable the PCI passthrough support on ARM.
Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
PATCH v5 4/11 xen/arm: PCI host bridge discovery within XEN on ARM
In reply to Rahul SinghXEN during boot will read the PCI device tree node “reg” property and will map the PCI config space to the XEN memory.
As of now only "pci-host-ecam-generic" compatible board is supported.
"linux,pci-domain" device tree property assigns a fixed PCI domain number to a host bridge, otherwise an unstable (across boots) unique number will be assigned by Linux. XEN access the PCI devices based on Segment:Bus:Device:Function. A Segment number in the XEN is same as a domain number in Linux. Segment number and domain number has to be in sync to access the correct PCI devices.
XEN will read the “linux,pci-domain” property from the device tree node and configure the host bridge segment number accordingly. If this property is not available XEN will allocate the unique segment number to the host bridge.
---
Chane in v5:
- Added Reviewed-by: Stefano Stabellini <[email protected]> Chane in v4:
- Move "#include <asm/pci.h>" in "xen/pci.h" after pci_sbdf_t sbdf declaration change to separate patch.
- Make gen_pci_dt_match as __initconstrel
- Make pci_host_generic_probe as __init
Change in v3:
- Modify commit msg based on received comments.
- Remove added struct match_table{} struct in struct device{}
- Replace uint32_t sbdf to pci_sbdf_t sbdf to avoid typecast
- Remove bus_start,bus_end and void *sysdata from struct pci_host_bridge{}
- Move "#include <asm/pci.h>" in "xen/pci.h" after pci_sbdf_t sbdf declaration
- Add pci_host_generic_probe() function
Change in v2:
- Add more info in commit msg
- Add callback to parse register index.
- Merge patch pci_ecam_operation into this patch to avoid confusion
- Add new struct in struct device for match table
---
--- xen/arch/arm/pci/Makefile | 4 + xen/arch/arm/pci/ecam.c | 61 +++++++ xen/arch/arm/pci/pci-access.c | 83 ++++++++++ xen/arch/arm/pci/pci-host-common.c | 247 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 48 ++++++ xen/include/asm-arm/pci.h | 56 +++++++ 6 files changed, 499 insertions(+) create mode 100644 xen/arch/arm/pci/ecam.c create mode 100644 xen/arch/arm/pci/pci-access.c create mode 100644 xen/arch/arm/pci/pci-host-common.c create mode 100644 xen/arch/arm/pci/pci-host-generic.c
xen/arch/arm/pci/Makefile +4 -0
@@ -1 +1,5 @@ obj-y += pci.o +obj-y += pci-access.o +obj-y += pci-host-generic.o +obj-y += pci-host-common.o +obj-y += ecam.o
xen/arch/arm/pci/ecam.c new file +61 -0
61 lines not on this page · raw message
xen/arch/arm/pci/pci-access.c new file +83 -0
83 lines not on this page · raw message
xen/arch/arm/pci/pci-host-common.c new file +247 -0
247 lines not on this page · raw message
xen/arch/arm/pci/pci-host-generic.c new file +48 -0
48 lines not on this page · raw message
xen/include/asm-arm/pci.h +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 5/11 xen/arm: Add support for Xilinx ZynqMP PCI host controller
In reply to Rahul SinghFrom: Oleksandr Andrushchenko <[email protected]>
Add support for Xilinx ZynqMP PCI host controller to map the PCI config space to the XEN memory.
Patch helps to understand how the generic infrastructure for PCI host-bridge discovery will be used for future references.
---
Change in v5:
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Add __initconstrel and __init for struct and functions
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3:
- nwl_cfg_reg_index(..) as static function
- Add support for pci_host_generic_probe()
Change in v2:
- Add more info in commit msg
---
--- xen/arch/arm/pci/Makefile | 1 + xen/arch/arm/pci/pci-host-zynqmp.c | 65 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 xen/arch/arm/pci/pci-host-zynqmp.c
xen/arch/arm/pci/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-y += pci-access.o obj-y += pci-host-generic.o obj-y += pci-host-common.o obj-y += ecam.o +obj-y += pci-host-zynqmp.o
xen/arch/arm/pci/pci-host-zynqmp.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 6/11 xen/arm: Implement pci access functions
In reply to Rahul SinghImplement generic pci access functions to read/write the configuration space.
---
Change in v5: none
Change in v4:
- Added Reviewed-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3:
- Remove PRI_pci as not used.
- Replace uint32_t sbdf to pci_sbdf_t sbdf to avoid typecast Change in v2: Fixed comments
---
--- xen/arch/arm/pci/pci-access.c | 57 ++++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 19 ++++++++++ xen/include/asm-arm/pci.h | 1 + 3 files changed, 77 insertions(+)
xen/arch/arm/pci/pci-access.c +57 -0
@@ -16,6 +16,7 @@#include <asm/io.h> #define INVALID_VALUE (~0U) +#define PCI_ERR_VALUE (len) GENMASK(0, len * 8)int pci_generic_config_read (struct pci_host_bridge *bridge,pci_sbdf_t sbdf,uint32_t reg,uint32_t len,uint32_t *value)
@@ -72,6 +73,62 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,return 0 ; } +static uint32_t pci_config_read (pci_sbdf_t sbdf,unsigned int reg, +unsigned int len) +{ +uint32_t val =PCI_ERR_VALUE (len); +struct pci_host_bridge *bridge =pci_find_host_bridge (sbdf.seg, sbdf.bus); + +if (unlikely (!bridge) ) +return val; + +if (unlikely (!bridge->ops->read) ) +return val; + + bridge->ops->read (bridge, sbdf, reg, len, &val); + +return val; +} + +static void pci_config_write (pci_sbdf_t sbdf,unsigned int reg, +unsigned int len,uint32_t val) +{ +struct pci_host_bridge *bridge =pci_find_host_bridge (sbdf.seg, sbdf.bus); + +if (unlikely (!bridge) ) +return ; + +if (unlikely (!bridge->ops->write) ) +return ; + + bridge->ops->write (bridge, sbdf, reg, len, val); +} + +/* +* Wrappers for all PCI configuration access functions. +*/ + +#define PCI_OP_WRITE (size, type) \ + void pci_conf_write##size(pci_sbdf_t sbdf, \ + unsigned int reg, type val) \ +{ \ + pci_config_write(sbdf, reg, size / 8, val); \ +} + +#define PCI_OP_READ (size, type) \ + type pci_conf_read##size(pci_sbdf_t sbdf, \ + unsigned int reg) \ +{ \ + return pci_config_read(sbdf, reg, size / 8); \ +} + +PCI_OP_READ(8, uint8_t) +PCI_OP_READ(16, uint16_t) +PCI_OP_READ(32, uint32_t) +PCI_OP_WRITE(8, uint8_t) +PCI_OP_WRITE(16, uint16_t) +PCI_OP_WRITE (32 , uint32_t) +/* * Local variables: * mode: C
xen/arch/arm/pci/pci-host-common.c +19 -0
@@ -236,6 +236,25 @@ err_exit:return err; } +/* +* This function will lookup an hostbridge based on the segment and bus +* number. +*/ +struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus) +{ +struct pci_host_bridge *bridge; + +list_for_each_entry ( bridge, &pci_host_bridges, node ) + { +if ( bridge->segment != segment ) +continue ; +if ( (bus < bridge->cfg->busn_start) || (bus > bridge->cfg->busn_end) ) +continue ; +return bridge; + } + +return NULL ; +}/* * Local variables: * mode: C
xen/include/asm-arm/pci.h +1 -0
@@ -81,6 +81,7 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t reg, uint32_t len, uint32_t value);void __iomem *pci_ecam_map_bus (struct pci_host_bridge *bridge,pci_sbdf_t sbdf,uint32_t where); +struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); static always_inline bool is_pci_passthrough_enabled(void) {
Signature · 1 line
2.25.1
PATCH v5 7/11 xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Rahul SinghIntroduce XEN_DOMCTL_CDF_vpci flag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.
---
Change in v5:
- Added Acked-by: Christian Lindig <[email protected]>
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4: Added in this version
---
--- tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/arch/arm/domain.c | 4 ++-- xen/arch/x86/domain.c | 6 ++++++ xen/common/domain.c | 2 +- xen/include/public/domctl.h | 4 +++- 6 files changed, 14 insertions(+), 4 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +1 -0
@@ -69,6 +69,7 @@ type domain_create_flag = | CDF_XS_DOMAIN | CDF_IOMMU | CDF_NESTED_VIRT + | CDF_VPCI type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -62,6 +62,7 @@ type domain_create_flag = | CDF_XS_DOMAIN | CDF_IOMMU | CDF_NESTED_VIRT + | CDF_VPCI type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
xen/arch/arm/domain.c +2 -2
@@ -622,8 +622,8 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) {unsigned int max_vcpus; -/* HVM and HAP must be set. IOMMU may or may not be */ -if ( (config->flags & ~XEN_DOMCTL_CDF_iommu) != +/* HVM and HAP must be set. IOMMU and VPCI may or may not be */ +if ( (config->flags & ~XEN_DOMCTL_CDF_iommu & ~XEN_DOMCTL_CDF_vpci) != (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap) ) { dprintk(XENLOG_INFO, "Unsupported configuration %#x\n",
xen/arch/x86/domain.c +6 -0
@@ -662,6 +662,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)return -EINVAL ; } +if ( config->flags & XEN_DOMCTL_CDF_vpci ) + { +dprintk (XENLOG_INFO ,"vPCI cannot be enabled yet\n" ); +return -EINVAL ; + } +if ( config->vmtrace_size ) {unsigned int size = config->vmtrace_size;
xen/common/domain.c +1 -1
@@ -483,7 +483,7 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) ~(XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | XEN_DOMCTL_CDF_xs_domain | XEN_DOMCTL_CDF_iommu | - XEN_DOMCTL_CDF_nested_virt) ) + XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_vpci) ) {dprintk (XENLOG_INFO ,"Unknown CDF flags %#x\n" , config->flags);return -EINVAL ;
xen/include/public/domctl.h +3 -1
@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_vpci 7 +#define XEN_DOMCTL_CDF_vpci (1U << _XEN_DOMCTL_CDF_vpci)/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_vpciuint32_t flags;
Signature · 1 line
2.25.1
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 8 lines · Rahul Singh
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_vpci 7 +#define XEN_DOMCTL_CDF_vpci (1U << _XEN_DOMCTL_CDF_vpci)
Like said in [1] here I similarly don't see the need for two constants. Preferably with the former of the two dropped
Jan
[1] https://lists.xen.org/archives/html/xen-devel/2021-10/msg00266.html
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Rahul SinghQuoted 7 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Acked-by Christian Lindig <[email protected]>
I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether XEN_DOMCTL_CDF_vpci will be accepted or not. The usual way of doing this is with a physinfo_cap field.
This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
~Andrew
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi Andrew,
Quoted 9 lines · On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
Quoted 7 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Acked-by Christian Lindig <[email protected]>
Quoted 6 lines
I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.
I am slightly puzzled by this. I am assuming you are referring to XENVER_get_features which AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?
Quoted 3 lines
This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 3 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
Cheers,
Quoted 3 lines
~Andrew
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 30 lines · Julien Grall
Hi Andrew,
On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
On 06/10/2021 18:40, Rahul Singh wrote:
> IntroduceXEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. > Reject the use of this new flag for x86 as VPCI is not supported for > DOMU guests for x86.
>
> Signed-off-by: Rahul Singh <[email protected]>
> Reviewed-by: Stefano Stabellini <[email protected]> > Acked-by: Christian Lindig <[email protected]>I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.I am slightly puzzled by this. I am assuming you are referring to
XENVER_get_featureswhich AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 6 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
After chatting with Andrew on IRC, this is my understanding.
Today if pci=[] is specified in the VM config file then XEN_DOMCTL_CDF_vpci is added. If Xen doesn't support it, Xen returns an error but libxl/xl won't be able to tell exactly why it fails. So xl will end up printing a generic VM creation failure. Andrew would like to see something like the following in libxl:
if ( PCI_devices && !cap.vcpi )
error("Sorry - PCI not supported")
So that the user gets a clear informative error back rather than a generic VM creation failure. Also, this is a requirement for the stable hypercall interface.
I think that's fine and we can implement this request easily by adding XEN_SYSCTL_PHYSCAP_vpci. Rahul or Bertrand, are you guys happy with doing that? Otherwise I could take it on.
As a side note, given that PCI passthrough support is actually not yet complete on ARM, we could even just do the following in xl/libxl:
if ( PCI_devices )
error("Sorry - PCI not supported")
or temporarily remove XEN_DOMCTL_CDF_vpci until PCI passthrough gets finalized.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi Stefano,
Quoted 47 lines · Stefano Stabellini
Quoted 30 lines · Julien Grall
Hi Andrew,
On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
On 06/10/2021 18:40, Rahul Singh wrote:
> IntroduceXEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. > Reject the use of this new flag for x86 as VPCI is not supported for > DOMU guests for x86.
>
> Signed-off-by: Rahul Singh <[email protected]>
> Reviewed-by: Stefano Stabellini <[email protected]> > Acked-by: Christian Lindig <[email protected]>I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.I am slightly puzzled by this. I am assuming you are referring to
XENVER_get_featureswhich AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 6 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
After chatting with Andrew on IRC, this is my understanding.
Today if pci=[] is specified in the VM config file then
XEN_DOMCTL_CDF_vpciis added. If Xen doesn't support it, Xen returns an error but libxl/xl won't be able to tell exactly why it fails. So xl will end up printing a generic VM creation failure. Andrew would like to see something like the following in libxl:
Quoted 5 lines
if (
PCI_devices&& !cap.vcpi )
error("Sorry - PCI not supported")So that the user gets a clear informative error back rather than a generic VM creation failure.
I can understand this request. However...
Also, this is a requirement for the stable
Quoted 1 line
hypercall interface.
... leaving aside the fact that domctl is clearly not stable today, the flag would be rejected on hypervisor not supporting vPCI. So I don't really see how this is a requirement for the stable hypercall interface.
Would you mind providing more details?
Quoted 7 lines
I think that's fine and we can implement this request easily by adding
XEN_SYSCTL_PHYSCAP_vpci. Rahul or Bertrand, are you guys happy with doing that? Otherwise I could take it on.
Quoted 8 lines
As a side note, given that PCI passthrough support is actually not yet complete on ARM, we could even just do the following in xl/libxl:
if (
PCI_devices)
error("Sorry - PCI not supported")or temporarily remove
XEN_DOMCTL_CDF_vpciuntil PCI passthrough gets finalized.
Cheers,
Quoted 1 line
Signature · 1 line
Julien Grall
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Stefano StabelliniHi Stefano,
Quoted 60 lines · Stefano Stabellini
Quoted 30 lines · Julien Grall
Hi Andrew,
On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
On 06/10/2021 18:40, Rahul Singh wrote:
> IntroduceXEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. > Reject the use of this new flag for x86 as VPCI is not supported for > DOMU guests for x86.
>
> Signed-off-by: Rahul Singh <[email protected]>
> Reviewed-by: Stefano Stabellini <[email protected]> > Acked-by: Christian Lindig <[email protected]>I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.I am slightly puzzled by this. I am assuming you are referring to
XENVER_get_featureswhich AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 6 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
After chatting with Andrew on IRC, this is my understanding.
Today if pci=[] is specified in the VM config file then
XEN_DOMCTL_CDF_vpciis added. If Xen doesn't support it, Xen returns an error but libxl/xl won't be able to tell exactly why it fails. So xl will end up printing a generic VM creation failure. Andrew would like to see something like the following in libxl:if (
PCI_devices&& !cap.vcpi )
error("Sorry - PCI not supported")So that the user gets a clear informative error back rather than a generic VM creation failure. Also, this is a requirement for the stable hypercall interface.
I think that's fine and we can implement this request easily by adding
XEN_SYSCTL_PHYSCAP_vpci. Rahul or Bertrand, are you guys happy with doing that? Otherwise I could take it on.
Quoted 9 lines
As a side note, given that PCI passthrough support is actually not yet complete on ARM, we could even just do the following in xl/libxl:
if (
PCI_devices)
error("Sorry - PCI not supported")or temporarily remove
XEN_DOMCTL_CDF_vpciuntil PCI passthrough gets finalized.
As Rahul is on leave:
I'm ok to introduce XEN_SYSCTL_PHYSCAP_vpci. I did the same for vpmu so it's ok. However the problem I have is about setting this cap.
On arm it is easy as we are not supporting vpci at the moment so the cap can be set to false. But how to deal with this cap in x86 code? I'm not familiar with x86 so I'm asking for advice.
Cheers,
Michal
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 65 lines · Michal Orzel
Quoted 64 lines · Stefano Stabellini
Quoted 28 lines · Julien Grall
On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
On 06/10/2021 18:40, Rahul Singh wrote:
> IntroduceXEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. > Reject the use of this new flag for x86 as VPCI is not supported for > DOMU guests for x86.
>
> Signed-off-by: Rahul Singh <[email protected]>
> Reviewed-by: Stefano Stabellini <[email protected]> > Acked-by: Christian Lindig <[email protected]>I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.I am slightly puzzled by this. I am assuming you are referring to
XENVER_get_featureswhich AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 6 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
After chatting with Andrew on IRC, this is my understanding.
Today if pci=[] is specified in the VM config file then
XEN_DOMCTL_CDF_vpciis added. If Xen doesn't support it, Xen returns an error but libxl/xl won't be able to tell exactly why it fails. So xl will end up printing a generic VM creation failure. Andrew would like to see something like the following in libxl:if (
PCI_devices&& !cap.vcpi )
error("Sorry - PCI not supported")So that the user gets a clear informative error back rather than a generic VM creation failure. Also, this is a requirement for the stable hypercall interface.
I think that's fine and we can implement this request easily by adding
XEN_SYSCTL_PHYSCAP_vpci. Rahul or Bertrand, are you guys happy with doing that? Otherwise I could take it on.As a side note, given that PCI passthrough support is actually not yet complete on ARM, we could even just do the following in xl/libxl:
if (
PCI_devices)
error("Sorry - PCI not supported")
Quoted 8 lines
Quoted 3 lines
or temporarily remove
XEN_DOMCTL_CDF_vpciuntil PCI passthrough gets finalized.As Rahul is on leave:
I'm ok to introduceXEN_SYSCTL_PHYSCAP_vpci. I did the same for vpmu so it's ok. However the problem I have is about setting this cap.
On arm it is easy as we are not supporting vpci at the moment so the cap can be set to false. But how to deal with this cap in x86 code? I'm not familiar with x86 so I'm asking for advice.
As the sysctl is mainly from tool stacks to drive guests (DomU-s), I'd set it to false for x86 as well. Roger - do you see any reason this could be needed to express anything Dom0-related?
Jan
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 75 lines · Jan Beulich
Quoted 65 lines · Michal Orzel
Quoted 64 lines · Stefano Stabellini
Quoted 28 lines · Julien Grall
On Fri, 8 Oct 2021, 20:07 Andrew Cooper, <[email protected]> wrote:
On 06/10/2021 18:40, Rahul Singh wrote:
> IntroduceXEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. > Reject the use of this new flag for x86 as VPCI is not supported for > DOMU guests for x86.
>
> Signed-off-by: Rahul Singh <[email protected]>
> Reviewed-by: Stefano Stabellini <[email protected]> > Acked-by: Christian Lindig <[email protected]>I'm afraid this logic is broken.
There's no matching feature to indicate to the toolstack whether
XEN_DOMCTL_CDF_vpciwill be accepted or not. The usual way of doing this is with aphysinfo_capfield.I am slightly puzzled by this. I am assuming you are referring to
XENVER_get_featureswhich AFAICT is a stable interface. So why should we use it to describe the presence of an unstable interface?This flag needs using in Patch 10 to reject attempts to create a VM with devices when passthrough support is unavailable.
May I ask why we can't rely on the hypervisor to reject the flag when suitable?
Quoted 6 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I fail to see how the interface would be broken... Would you mind to describe a bit more what could go wrong with this interface?
After chatting with Andrew on IRC, this is my understanding.
Today if pci=[] is specified in the VM config file then
XEN_DOMCTL_CDF_vpciis added. If Xen doesn't support it, Xen returns an error but libxl/xl won't be able to tell exactly why it fails. So xl will end up printing a generic VM creation failure. Andrew would like to see something like the following in libxl:if (
PCI_devices&& !cap.vcpi )
error("Sorry - PCI not supported")So that the user gets a clear informative error back rather than a generic VM creation failure. Also, this is a requirement for the stable hypercall interface.
I think that's fine and we can implement this request easily by adding
XEN_SYSCTL_PHYSCAP_vpci. Rahul or Bertrand, are you guys happy with doing that? Otherwise I could take it on.As a side note, given that PCI passthrough support is actually not yet complete on ARM, we could even just do the following in xl/libxl:
if (
PCI_devices)
error("Sorry - PCI not supported")Quoted 8 lines
Quoted 3 lines
or temporarily remove
XEN_DOMCTL_CDF_vpciuntil PCI passthrough gets finalized.As Rahul is on leave:
I'm ok to introduceXEN_SYSCTL_PHYSCAP_vpci. I did the same for vpmu so it's ok. However the problem I have is about setting this cap.
On arm it is easy as we are not supporting vpci at the moment so the cap can be set to false. But how to deal with this cap in x86 code? I'm not familiar with x86 so I'm asking for advice.
Quoted 3 lines
As the sysctl is mainly from tool stacks to drive guests (DomU-s), I'd set it to false for x86 as well. Roger - do you see any reason this could be needed to express anything Dom0-related?
I agree, I don't think we should set it to true unless we also support vPCI for domUs on x86, or else it's just going to confuse the toolstack.
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Andrew CooperAndrew Cooper writes ("Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag"):
Quoted 3 lines
Ian, for the 4.16 release, this series either needs completing with the additional flag implemented, or this patch needs reverting to avoid us shipping a broken interface.
I have caught up on this thread. I think (hope?) it's converging. If not please let me know and maybe I can help.
Can I ask to please be CC'd on the whole series for the patch(es) to sort this out. Please also make sure that those who commented are CC'd. I want the fixes that ultimately get committed to be the final fixes (probably that means they should have consensus).
FTAOD, from a formal release management point of view: I regard those putative fixes as bugfixes so they can go in after the feature freeze (which is this Friday). But if suitable fixes don't make it in within the first few weeks of the freeze (and, as I expect, the maintainers or I still regard this as an RC bug) then a revert of the new feature will be the only option.
Ian.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Rahul SinghQuoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.
I don't like this approach, XEN_DOMCTL_CDF_vpci should be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.
Things like PVH vs PV get translated into CDF flags by create_dom0, and processed normally by the sanitise_domain_config logic, vPCI should be handled that way.
Do you think you could see about fixing this?
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.
Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
As Rahul is on leave:
I agree with you. XEN_DOMCTL_CDF_vpci should be set in dom0_cfg.flags in create_dom0 for pvh. We can do such fix in a new patch together with adding physcap for vpci.
Cheers,
Michal
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Roger Pau MonnéHi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.
Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
I have one question about this fix.
If I set XEN_DOMCTL_CDF_vpci for dom0 pvh in create_dom0, then in sanitise_domain_config or arch_sanitise_domain_config I have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.
Any ideas?
Cheers,
Michal
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 20 lines · Michal Orzel
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
Quoted 7 lines
I have one question about this fix.
If I setXEN_DOMCTL_CDF_vpcifor dom0 pvh increate_dom0, then insanitise_domain_configorarch_sanitise_domain_configI have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.Any ideas?
I've just realized this is more wrong that I thought. vPCI is signaled on x86 in xen_arch_domainconfig.emulation_flags, so introducing a top level option for it without removing the arch specific one is wrong, as then on x86 we have a duplicated option.
Then I'm also not sure whether we want to move it from emulation_flags, it seems like the more natural place for it to live on x86.
If we really want to make vPCI a CDF option we must deal with the removal of XEN_X86_EMU_VPCI, or else you could introduce an arch specific flag for vPCI on Arm.
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi Roger,
Quoted 36 lines · Roger Pau Monné
Quoted 20 lines · Michal Orzel
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
Quoted 7 lines
I have one question about this fix.
If I setXEN_DOMCTL_CDF_vpcifor dom0 pvh increate_dom0, then insanitise_domain_configorarch_sanitise_domain_configI have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.Any ideas?
I've just realized this is more wrong that I thought. vPCI is signaled on x86 in xen_arch_domainconfig.emulation_flags, so introducing a top level option for it without removing the arch specific one is wrong, as then on x86 we have a duplicated option.
Quoted 7 lines
Then I'm also not sure whether we want to move it from
emulation_flags, it seems like the more natural place for it to live on x86.If we really want to make vPCI a CDF option we must deal with the removal of
XEN_X86_EMU_VPCI, or else you could introduce an arch specific flag for vPCI on Arm.
First issue that we have here is that there is no emulation_flags right now on arm.
So I think there are 2 solutions:
- introduce PHYSCAP. The problem here is that it is not a physical capacity and I think that will hit us in the future for example if we want to use vpci for VIRTIO even if there is not physical PCI on the platform.
- introduce an emulation flag on arm. The problem here is that there is no emulation flag right now on arm so adding this feature will require a change of interface in arch-arm.h and in xen domctl interface. But if we introduce one on Arm, it would allow the tools to check if CDF_vpci can be set or not which would solve current issues.
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.
Can we agree on keep the DOMCTL_CDF_vpci flag and introduce the emulation flag on Arm after 4.16 release ?
Cheers
Bertrand
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 42 lines · Bertrand Marquis
Hi Roger,
Quoted 40 lines · Roger Pau Monné
Quoted 20 lines · Michal Orzel
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
Quoted 7 lines
I have one question about this fix.
If I setXEN_DOMCTL_CDF_vpcifor dom0 pvh increate_dom0, then insanitise_domain_configorarch_sanitise_domain_configI have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.Any ideas?
I've just realized this is more wrong that I thought. vPCI is signaled on x86 in xen_arch_domainconfig.emulation_flags, so introducing a top level option for it without removing the arch specific one is wrong, as then on x86 we have a duplicated option.
Then I'm also not sure whether we want to move it from
emulation_flags, it seems like the more natural place for it to live on x86.
Quoted 5 lines
Quoted 3 lines
If we really want to make vPCI a CDF option we must deal with the removal of
XEN_X86_EMU_VPCI, or else you could introduce an arch specific flag for vPCI on Arm.First issue that we have here is that there is no
emulation_flagsright now on arm.
You don't explicitly need an emulation_flags field, you could add a uint8_t vpci or some such to xen_arch_domainconfig for Arm if you don't think there's a need to select more emulation. That's up to Arm folks.
Quoted 5 lines
So I think there are 2 solutions:
- introduce PHYSCAP. The problem here is that it is not a physical capacity and I think that will hit us in the future for example if we want to use vpci for VIRTIO even if there is not physical PCI on the platform.
Hm, PHYSCAP is a bit weird, for example Xen signals shadow paging support using PHYSCAP which doesn't depend on any hardware feature.
I think you could signal vPCI regardless of whether the underlying platform has PCI devices or not, as vPCI is purely a software component.
Regarding VirtIO, won't it be implemented using ioreqs in user-space, and thus won't depend on vPCI?
Quoted 4 lines
- introduce an emulation flag on arm. The problem here is that there is no emulation flag right now on arm so adding this feature will require a change of interface in
arch-arm.hand in xen domctl interface. But if we introduce one on Arm, it would allow the tools to check ifCDF_vpcican be set or not which would solve current issues.
I'm not sure I follow. If we go the emulation flags route this will all be set in xen_arch_domainconfig, and CDF_vpci will completely go away.
Quoted 11 lines
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.Can we agree on keep the
DOMCTL_CDF_vpciflag and introduce the emulation flag on Arm after 4.16 release ?
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
I think we need to at least settle on whether we want to keep CDF_vpci or use an arch specific signal mechanism in order to decide what to do regarding the release.
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi Roger,
Quoted 49 lines · Roger Pau Monné
Quoted 46 lines · Bertrand Marquis
Hi Roger,
Quoted 43 lines · Roger Pau Monné
Quoted 20 lines · Michal Orzel
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
Quoted 7 lines
I have one question about this fix.
If I setXEN_DOMCTL_CDF_vpcifor dom0 pvh increate_dom0, then insanitise_domain_configorarch_sanitise_domain_configI have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.Any ideas?
I've just realized this is more wrong that I thought. vPCI is signaled on x86 in xen_arch_domainconfig.emulation_flags, so introducing a top level option for it without removing the arch specific one is wrong, as then on x86 we have a duplicated option.
Then I'm also not sure whether we want to move it from
emulation_flags, it seems like the more natural place for it to live on x86.If we really want to make vPCI a CDF option we must deal with the removal of
XEN_X86_EMU_VPCI, or else you could introduce an arch specific flag for vPCI on Arm.
Quoted 6 lines
Quoted 1 line
First issue that we have here is that there is no
emulation_flagsright now on arm.You don't explicitly need an
emulation_flagsfield, you could add auint8_tvpci or some such toxen_arch_domainconfigfor Arm if you don't think there's a need to select more emulation. That's up to Arm folks.
One way or an other it is still changing the interface.
Quoted 7 lines
Quoted 6 lines
So I think there are 2 solutions:
- introduce PHYSCAP. The problem here is that it is not a physical capacity and I think that will hit us in the future for example if we want to use vpci for VIRTIO even if there is not physical PCI on the platform.
Quoted 6 lines
Hm, PHYSCAP is a bit weird, for example Xen signals shadow paging support using PHYSCAP which doesn't depend on any hardware feature.
I think you could signal vPCI regardless of whether the underlying platform has PCI devices or not, as vPCI is purely a software component.
But in the x86 case this is something not supported in all cases and actually only by dom0 pvh. So having something like that defined as a PHYSCAP is a bit weird.
Quoted 3 lines
Regarding VirtIO, won't it be implemented using ioreqs in user-space, and thus won't depend on vPCI?
Yes that’s a solution but you can list them through a PCI interface to let a guest discover them.
I am not saying that we will do that but that was an example of case where we could use vPCI without hardware PCI present.
Quoted 8 lines
Quoted 5 lines
- introduce an emulation flag on arm. The problem here is that there is no emulation flag right now on arm so adding this feature will require a change of interface in
arch-arm.hand in xen domctl interface. But if we introduce one on Arm, it would allow the tools to check ifCDF_vpcican be set or not which would solve current issues.I'm not sure I follow. If we go the emulation flags route this will all be set in
xen_arch_domainconfig, andCDF_vpciwill completely go away.
This is a mistake on my side. You are right using emulation flags will require to remove CDF_vpci.
Quoted 10 lines
Quoted 10 lines
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.
Quoted 7 lines
Quoted 2 lines
Can we agree on keep the
DOMCTL_CDF_vpciflag and introduce the emulation flag on Arm after 4.16 release ?If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
Quoted 4 lines
I think we need to at least settle on whether we want to keep
CDF_vpcior use an arch specific signal mechanism in order to decide what to do regarding the release.
Agree and I have no definitive idea on this so but switching will require to revert the patch adding CDF_vpci and change the subsequent patches.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 5 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
+1
Quoted 3 lines
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
5 versions for a series like this one was to be expected. Imo it has been wrong in the past to rush in new features (even if experimental ones) very close to the freeze, and it has mislead people to think they can delay work until very (too?) late a point in time.
In fact I'm getting somewhat angry seeing how much effort is put into getting this work in (including myself doing reviews there), when at the same time far older series of mine aren't given any chance to make any progress. Not your fault, sure, but an observation.
Jan
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
+1
Quoted 8 lines
Quoted 3 lines
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
5 versions for a series like this one was to be expected. Imo it has been wrong in the past to rush in new features (even if experimental ones) very close to the freeze, and it has mislead people to think they can delay work until very (too?) late a point in time.
Hi Roger, Jan,
Let me take a few minutes to clarify and provide context for this work.
I don't think anyone "pushed hard" any of the ARM series close to the release. I sent "one" email in public as a reminder of things that need reviewing:
https://marc.info/?l=xen-devel&m=163373776611154
I did send a couple of private emails to Jan but they were to synchronize ourselves rather than push; Jan, I hope you didn't take them the wrong way.
At the same time it is certainly true that all the people involved here worked very hard to get these series ready for 4.16. Oct 15 is the Xen Project feature freeze. It is also the deadline for many of us working with upstream Xen Project to upstream features and report back to our management. I know it doesn't affect you guys directly, but you can imagine that as employees of our respective companies we feel pressure to complete our objectives in the given timeframe. Of course we need to make sure to do that without compromising quality and without overextending upstream review capacity.
The ARM PCI series are public since Dec 2020, pushed to a gitlab branch
for testing: https://gitlab.com/xen-project/fusa/xen-integration/-/tree/integration/pci-passthrough
I helped creating, managing and testing the branch.
So, I can see why Bertrand feels like they have been around for a while:
we have been dealing with these patches for almost a year, even if from a xen-devel perspective we are "only" at version 5.
In the past there have been contributors dropping a large half-broken series at the last minute before the code freeze, asking for it to be committed, promising it will be improved later, and then disappearing right after the release, leaving the code half-broken forever.
It is easy to draw comparisons between that kind of behavior and what is happening in this thread. We have all been burned by it at some point.
However, that is really *not* what is happening this week.
PCI Passthrough for ARM is a difficult feature to implement. We have been discussing it for 5+ years, close to 10 years. I know it sounds unbelievable but it is true. For one reason or the other it never materialized. Until now.
Even with all the outstanding series committed, PCI Passthrough for ARM is not fully functional, but it is a lot closer to the objective. Rahul, Oleksandr and their teams have been already "sticking around" for almost a year making improvements and without their help going forward it is not going to get finished anyway. We still don't have MSI support.
Given that Rahul, Oleksandr and the others are required to finish the work anyway, and they are not at risk of disappearing, I think we can deal with one or two TODO left by Oct 15 [1].
My suggestion is to accept the TODO for patch #8 [1] but I agree with Roger that we shouldn't introduce bad interfaces, especially as they impact x86 which is not "tech preview". So I think we should revert patch #7 (this patch.) I'll reply with more details in separate shorter email.
[1] https://marc.info/?l=xen-devel&m=163412120531248
Quoted 4 lines
In fact I'm getting somewhat angry seeing how much effort is put into getting this work in (including myself doing reviews there), when at the same time far older series of mine aren't given any chance to make any progress. Not your fault, sure, but an observation.
Jan,
Let me start by pointing out that without your help we would never have managed to get so many ARM patches committed for 4.16. Not just PCI related, but also EFI too. You should really get credit for that.
I can imagine it is frustrating helping so much somebody else but not getting help for your own series. In a way it happened to me too as the only Xilinx series outstanding didn't make any progress:
https://marc.info/?l=xen-devel&m=163056545414965
The only way to solve this problem is by growing the review capacity of the community. You'll be happy to know that (without naming names) I have heard from multiple people, new members of the community, that they are going to commit time to do reviews during the next months. We are growing the community again and some of the new contributors will become good reviewers and maintainers over time. I am positive that the next 12 months will be a lot better than the last 12 months from that perspective.
Thanks Jan, Roger, the two Oleksandr, Rahul, Michal, Bertrand, Luca and everyone else that stayed up late these last few weeks to push Xen forward with new groundbreaking features and pushing the project forward in new directions. I do think 4.16 is going to be a great release and the both CI-loops are still fully working with staging very close to master, further proof of the great work of this community.
Cheers,
Stefano
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 25 lines · Stefano Stabellini
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
+1
Quoted 8 lines
Quoted 3 lines
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
5 versions for a series like this one was to be expected. Imo it has been wrong in the past to rush in new features (even if experimental ones) very close to the freeze, and it has mislead people to think they can delay work until very (too?) late a point in time.
Hi Roger, Jan,
Let me take a few minutes to clarify and provide context for this work.
Quoted 8 lines
I don't think anyone "pushed hard" any of the ARM series close to the release. I sent "one" email in public as a reminder of things that need reviewing:
https://marc.info/?l=xen-devel&m=163373776611154I did send a couple of private emails to Jan but they were to synchronize ourselves rather than push; Jan, I hope you didn't take them the wrong way.
Definitely not, no worries.
Quoted 11 lines
At the same time it is certainly true that all the people involved here worked very hard to get these series ready for 4.16. Oct 15 is the Xen Project feature freeze. It is also the deadline for many of us working with upstream Xen Project to upstream features and report back to our management. I know it doesn't affect you guys directly, but you can imagine that as employees of our respective companies we feel pressure to complete our objectives in the given timeframe. Of course we need to make sure to do that without compromising quality and without overextending upstream review capacity.
Quoted 7 lines
The ARM PCI series are public since Dec 2020, pushed to a gitlab branch
for testing: https://gitlab.com/xen-project/fusa/xen-integration/-/tree/integration/pci-passthrough
I helped creating, managing and testing the branch.So, I can see why Bertrand feels like they have been around for a while:
we have been dealing with these patches for almost a year, even if from a xen-devel perspective we are "only" at version 5.
I'm afraid that anything not on xen-devel doesn't really count; the list is the only "official" channel. ISTR that for certain aspects there's a plan George has to make this more pronounced / formal in some of the docs we have.
Making internally set deadlines is a fully understandable aspect. But starting to post in September for a mid-October deadline is putting oneself at risk, I would say, for a (set of) series this involved. I see no problem with anyone doing so, as long as they accept that risk rather than expecting to get away by either extraordinary efforts by others (reviewers) or relaxation of what is permitted to go in.
Of course there's the opposite problem of feedback taking unusually (I'm inclined to say unduly) long to arrive, like with the gpaddr_bits addition still facing vague / unclear opposition by Andrew.
Quoted 7 lines
My suggestion is to accept the TODO for patch #8 [1] but I agree with Roger that we shouldn't introduce bad interfaces, especially as they impact x86 which is not "tech preview". So I think we should revert patch #7 (this patch.) I'll reply with more details in separate shorter email.
FWIW I agree with both proposals (acceptance of TODO and revert).
Jan
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Hi,
Quoted 80 lines · Jan Beulich
Quoted 25 lines · Stefano Stabellini
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Bertrand Marquis
Quoted 5 lines · Roger Pau Monné
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
+1
Quoted 8 lines
Quoted 3 lines
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
5 versions for a series like this one was to be expected. Imo it has been wrong in the past to rush in new features (even if experimental ones) very close to the freeze, and it has mislead people to think they can delay work until very (too?) late a point in time.
Hi Roger, Jan,
Let me take a few minutes to clarify and provide context for this work.
Quoted 8 lines
I don't think anyone "pushed hard" any of the ARM series close to the release. I sent "one" email in public as a reminder of things that need reviewing:
https://marc.info/?l=xen-devel&m=163373776611154I did send a couple of private emails to Jan but they were to synchronize ourselves rather than push; Jan, I hope you didn't take them the wrong way.
Definitely not, no worries.
Quoted 11 lines
At the same time it is certainly true that all the people involved here worked very hard to get these series ready for 4.16. Oct 15 is the Xen Project feature freeze. It is also the deadline for many of us working with upstream Xen Project to upstream features and report back to our management. I know it doesn't affect you guys directly, but you can imagine that as employees of our respective companies we feel pressure to complete our objectives in the given timeframe. Of course we need to make sure to do that without compromising quality and without overextending upstream review capacity.
Quoted 7 lines
The ARM PCI series are public since Dec 2020, pushed to a gitlab branch
for testing: https://gitlab.com/xen-project/fusa/xen-integration/-/tree/integration/pci-passthrough
I helped creating, managing and testing the branch.So, I can see why Bertrand feels like they have been around for a while:
we have been dealing with these patches for almost a year, even if from a xen-devel perspective we are "only" at version 5.I'm afraid that anything not on xen-devel doesn't really count; the list is the only "official" channel. ISTR that for certain aspects there's a plan George has to make this more pronounced / formal in some of the docs we have.
Making internally set deadlines is a fully understandable aspect. But starting to post in September for a mid-October deadline is putting oneself at risk, I would say, for a (set of) series this involved. I see no problem with anyone doing so, as long as they accept that risk rather than expecting to get away by either extraordinary efforts by others (reviewers) or relaxation of what is permitted to go in.
Of course there's the opposite problem of feedback taking unusually (I'm inclined to say unduly) long to arrive, like with the
gpaddr_bitsaddition still facing vague / unclear opposition by Andrew.Quoted 6 lines
My suggestion is to accept the TODO for patch #8 [1] but I agree with Roger that we shouldn't introduce bad interfaces, especially as they impact x86 which is not "tech preview". So I think we should revert patch #7 (this patch.) I'll reply with more details in separate shorter email.
Quoted 3 lines
Quoted 1 line
FWIW I agree with both proposals (acceptance of TODO and revert).
I want to say again that nothing I said was meant as a critic and I am very grateful of all reviews and comments that we have (even if some of them are implying work or pushing stuff in the future) as we want to do this right.
We will do the following before the end of the day today:
- send a reverting patch for patch 7
- send updated version of patch 8 handling all pending comments
We will try to (not sure as some changes might be more complex)
- send an updated version of patch 10
- try to find a solution acceptable for patch 1
Thanks everyone for the support here and the huge amount of time spent on reviewing all patches that was pushed (and there was a lot of them).
Over the next month Arm is committed to put a lot more effort in reviewing and testing patches pushed to xen-devel. We now have an internal CI that will help us a lot and all people in Arm Xen team will start to have dedicated time to review upstream patches and help the community.
Xen is a big part of Arm strategy around automotive as the reference Type 1 hypervisor and we will not disappear soon :-)
If there are any outstanding serie or patches for which you would like us to help On review, please do not hesitate to ping me and I will see how we can help (even if it is only to do some testing).
Thanks again everyone for the help.
Cheers
Bertrand
PS: I will stay connected on IRC if someone needs to contact me.
Quoted 2 lines
Jan
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Bertrand MarquisQuoted 51 lines · Bertrand Marquis
Hi Roger,
Quoted 49 lines · Roger Pau Monné
Quoted 46 lines · Bertrand Marquis
Hi Roger,
Quoted 43 lines · Roger Pau Monné
Quoted 20 lines · Michal Orzel
Hi Roger,
Quoted 8 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Quoted 8 lines
Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Thanks, Roger.
Quoted 7 lines
I have one question about this fix.
If I setXEN_DOMCTL_CDF_vpcifor dom0 pvh increate_dom0, then insanitise_domain_configorarch_sanitise_domain_configI have no knowledge on whether I am dom0 or not. I can check if I'm PVH but not if dom0. This would be needed to add a warning if this flag is set but we are not dom0 pvh.Any ideas?
I've just realized this is more wrong that I thought. vPCI is signaled on x86 in xen_arch_domainconfig.emulation_flags, so introducing a top level option for it without removing the arch specific one is wrong, as then on x86 we have a duplicated option.
Then I'm also not sure whether we want to move it from
emulation_flags, it seems like the more natural place for it to live on x86.If we really want to make vPCI a CDF option we must deal with the removal of
XEN_X86_EMU_VPCI, or else you could introduce an arch specific flag for vPCI on Arm.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
First issue that we have here is that there is no
emulation_flagsright now on arm.You don't explicitly need an
emulation_flagsfield, you could add auint8_tvpci or some such toxen_arch_domainconfigfor Arm if you don't think there's a need to select more emulation. That's up to Arm folks.One way or an other it is still changing the interface.
Well, I don't want to sound rude, but you already changed the interface first and very recently by introducing CDF_vpci. Complaining that you don't want to change it anymore just after that seems slightly weird.
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
So I think there are 2 solutions:
- introduce PHYSCAP. The problem here is that it is not a physical capacity and I think that will hit us in the future for example if we want to use vpci for VIRTIO even if there is not physical PCI on the platform.
Hm, PHYSCAP is a bit weird, for example Xen signals shadow paging support using PHYSCAP which doesn't depend on any hardware feature.
Quoted 6 lines
Quoted 3 lines
I think you could signal vPCI regardless of whether the underlying platform has PCI devices or not, as vPCI is purely a software component.
But in the x86 case this is something not supported in all cases and actually only by dom0 pvh. So having something like that defined as a PHYSCAP is a bit weird.
Well, even if vPCI was fully supported on x86 for both domU and dom0 it would only apply to PVH and maybe HVM guests, but classic PV will never get vPCI. It's kind of trying to create a PV guest with HAP support.
One option would be to defer the introduction of the CDF_vpci flag until the vpci work has been finished - then we could decide if the current code can also be used by x86 so maybe it could be enabled for both arches, and there would be no problem in setting the PHYSCAP.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.Can we agree on keep the
DOMCTL_CDF_vpciflag and introduce the emulation flag on Arm after 4.16 release ?
Quoted 8 lines
Quoted 4 lines
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
We did not push that fast, those have been on the mailing list for a while (this is the 5th version of the serie). PCI passthrough is a big change requiring lots of patches and we decided to push it piece by piece to make the review easier.
First version of this patch I have on my inbox is from 23rd of September, that's less than 3 weeks ago.
Quoted 7 lines
Quoted 4 lines
I think we need to at least settle on whether we want to keep
CDF_vpcior use an arch specific signal mechanism in order to decide what to do regarding the release.Agree and I have no definitive idea on this so but switching will require to revert the patch adding
CDF_vpciand change the subsequent patches.
I think it's fair to expect changes to the interface when things are reviewed, that's part of the review process, changes to subsequent patches can be painful, but we have all been there and dealt with them.
I'm not saying we must remove the CDF_vpci flag. I have to admit I was fine using emulation_flags, but I could also be fine using CDF_vpci if the x86 side is fixed and XEN_X86_EMU_VPCI is removed.
Thanks, Roger.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Roger Pau MonnéQuoted 12 lines · Roger Pau Monné
Quoted 11 lines
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.Can we agree on keep the
DOMCTL_CDF_vpciflag and introduce the emulation flag on Arm after 4.16 release ?
Quoted 8 lines
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
I think we need to at least settle on whether we want to keep
CDF_vpcior use an arch specific signal mechanism in order to decide what to do regarding the release.
I wrote a longer separate email to provide more context about the "pushing fast" comment.
I agree that we don't want to introduce a bad interface.
In regards to a way forward for 4.16, my suggestion is the following:
- revert this patch: do not change the interface in this series
- do not change anything related to CDF_vpci for x86
- for ARM, leave has_vpci(d) to { false } and do not set XEN_DOMCTL_CDF_vpci
- we can discuss it in depth later on, no rush
- in patch #10, in libxl_arm.c:libxl__arch_domain_prepare_config
- do not set XEN_DOMCTL_CDF_vpci
- do not set b_info.arch_arm.vpci
- do not define LIBXL_HAVE_BUILDINFO_ARM_VPCI in libxl.h
- keep make_vpci_node and arch_arm.vpci
The other patches (#1, #8, #10), which don't change any interfaces, can still make it for 4.16 if the review feedback is addressed on time, with one open TODO item [1].
This way, we get all the essential infrastructure we are trying to introduce without making any compromises on the external interfaces. Still it is good to have patches #1 #8 #10 so that with a trival oneliner patch on top of 4.16 we can enable PCI for ARM and do testing in the community, in gitlab-ci, and OSSTest too. (We have been discussing special OSSTest flights to valide PCI passthrough as we complete development.)
If we think we need a snap decision on this topic, I am available for a quick sync-up call or IRC meeting between 8AM and 10AM tomorrow (Oct 14).
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 46 lines · Stefano Stabellini
Quoted 12 lines · Roger Pau Monné
Quoted 11 lines
I think the second solution is the right one but it cannot be done so near from the feature freeze.
The CDF flag as introduced right now is not creating any issue and will be used once the emulation flag will be introduce. We will be able at this stage to set this properly also on x86 (for dom0 pvh).
Moreover keeping it will allow to continue to merge the remaining part of the PCI passthrough which are otherwise not possible to be done as they are dependent on this flag.Can we agree on keep the
DOMCTL_CDF_vpciflag and introduce the emulation flag on Arm after 4.16 release ?Quoted 8 lines
If vPCI for Arm on 4.16 is not going to be functional, why so much pressure in pushing those patches so fast? I understand the need to remove stuff from the queue, but I don't think it's worth the cost of introducing a broken interface deliberately on a release.
I think we need to at least settle on whether we want to keep
CDF_vpcior use an arch specific signal mechanism in order to decide what to do regarding the release.I wrote a longer separate email to provide more context about the "pushing fast" comment.
I agree that we don't want to introduce a bad interface.
In regards to a way forward for 4.16, my suggestion is the following:
- revert this patch: do not change the interface in this series
- do not change anything related toCDF_vpcifor x86
- for ARM, leavehas_vpci(d)to { false } and do not setXEN_DOMCTL_CDF_vpci
- we can discuss it in depth later on, no rush- in patch #10, in libxl_arm.c:libxl__arch_domain_prepare_config
- do not setXEN_DOMCTL_CDF_vpci
- do not set b_info.arch_arm.vpci
- do not defineLIBXL_HAVE_BUILDINFO_ARM_VPCIinlibxl.h
- keepmake_vpci_nodeand arch_arm.vpciThe other patches (#1, #8, #10), which don't change any interfaces, can still make it for 4.16 if the review feedback is addressed on time, with one open TODO item [1].
Quoted 7 lines
This way, we get all the essential infrastructure we are trying to introduce without making any compromises on the external interfaces. Still it is good to have patches #1 #8 #10 so that with a trival oneliner patch on top of 4.16 we can enable PCI for ARM and do testing in the community, in gitlab-ci, and OSSTest too. (We have been discussing special OSSTest flights to valide PCI passthrough as we complete development.)
One more thing: I would really like to get at least patch #8 committed because it would help with making progress with part 2 and part 3 of the PCI enablement series. My preference would also be to get #1 and #10 in as well but I feel less strongly about it.
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
In reply to Roger Pau MonnéQuoted 5 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.
Quoted 8 lines
I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Andrew suggested to use XEN_SYSCTL_PHYSCAP_vpci to check whether we can set XEN_DOMCTL_CDF_vpci in libxl and it looks like we have consensus on this approach. [1][2]
So it makes sense that XEN_DOMCTL_CDF_vpci is only set when XEN_SYSCTL_PHYSCAP_vpci is also set, i.e. XEN_SYSCTL_PHYSCAP_vpci == XEN_DOMCTL_CDF_vpci.
From [2], XEN_SYSCTL_PHYSCAP_vpci is not going to be set on x86, so then XEN_DOMCTL_CDF_vpci should also be left unset?
If you think XEN_DOMCTL_CDF_vpci should be set for x86 PVH Dom0, then XEN_SYSCTL_PHYSCAP_vpci should also be set for x86 PVH Dom0.
[1] https://marc.info/?l=xen-devel&m=163372953907637
[2] https://marc.info/?l=xen-devel&m=163395821428850
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 23 lines · Stefano Stabellini
Quoted 5 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.Quoted 8 lines
I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Andrew suggested to use
XEN_SYSCTL_PHYSCAP_vpcito check whether we can setXEN_DOMCTL_CDF_vpciin libxl and it looks like we have consensus on this approach. [1][2]So it makes sense that
XEN_DOMCTL_CDF_vpciis only set whenXEN_SYSCTL_PHYSCAP_vpciis also set, i.e.XEN_SYSCTL_PHYSCAP_vpci==XEN_DOMCTL_CDF_vpci.
Quoted 5 lines
From [2],
XEN_SYSCTL_PHYSCAP_vpciis not going to be set on x86, so thenXEN_DOMCTL_CDF_vpcishould also be left unset?If you think
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH Dom0, thenXEN_SYSCTL_PHYSCAP_vpcishould also be set for x86 PVH Dom0.
Except that XEN_SYSCTL_PHYSCAP_vpci is not a domain specific attribute, but a host-wide one.
Jan
Re: [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Stefano Stabellini
Quoted 5 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
Introduce
XEN_DOMCTL_CDF_vpciflag to enable VPCI support in XEN. Reject the use of this new flag for x86 as VPCI is not supported for DOMU guests for x86.Quoted 8 lines
I don't like this approach,
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH dom0, like we do for any other CDF flags when Xen builds dom0.Things like PVH vs PV get translated into CDF flags by
create_dom0, and processed normally by thesanitise_domain_configlogic, vPCI should be handled that way.Do you think you could see about fixing this?
Andrew suggested to use
XEN_SYSCTL_PHYSCAP_vpcito check whether we can setXEN_DOMCTL_CDF_vpciin libxl and it looks like we have consensus on this approach. [1][2]So it makes sense that
XEN_DOMCTL_CDF_vpciis only set whenXEN_SYSCTL_PHYSCAP_vpciis also set, i.e.XEN_SYSCTL_PHYSCAP_vpci==XEN_DOMCTL_CDF_vpci.From [2],
XEN_SYSCTL_PHYSCAP_vpciis not going to be set on x86, so thenXEN_DOMCTL_CDF_vpcishould also be left unset?
Quoted 9 lines
Quoted 2 lines
If you think
XEN_DOMCTL_CDF_vpcishould be set for x86 PVH Dom0, thenXEN_SYSCTL_PHYSCAP_vpcishould also be set for x86 PVH Dom0.Except that
XEN_SYSCTL_PHYSCAP_vpciis not a domain specific attribute, but a host-wide one.Jan
I already prepared a patch introducing XEN_SYSCTL_PHYSCAP_vpci. We agreed
that the cap_vpci should not be set neither for x86 nor ARM. This means that
the flag vpci_is_available, which tells us about vPCI platform support (and is used in condition to set cap_vpci) is set to false by default. Later on it should be set by vPCI driver. For me it does not make sense for XEN_SYSCTL_PHYSCAP_vpci saying that platform does not support vPCI but setting XEN_DOMCTL_CDF_vpci for dom0 pvh.
I would prefer not setting XEN_DOMCTL_CDF_vpci for now at all. This way we have a chance to merge Rahul's series until friday.
Cheers,
Michal
PATCH v5 8/11 xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Rahul SinghThe existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems scan_pci_devices() would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.
---
Change in v5:
- Add pci_cleanup_msi(pdev) in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition of XEN_DOMCTL_CDF_vpci flag to separate patch Change in v3:
- Use is_pci_passthrough_enabled() in place of pci_passthrough_enabled variable
- Reject XEN_DOMCTL_CDF_vpci for x86 in arch_sanitise_domain_config()
- Remove IS_ENABLED(CONFIG_HAS_VPCI) from has_vpci()
Change in v2:
- Add new XEN_DOMCTL_CDF_vpci flag
- modify has_vpci() to include XEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.h
xen/arch/arm/Makefile +1 -0
@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ +obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.o
xen/arch/arm/domain.c +4 -0
@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ; fail:
xen/arch/arm/domain_build.c +3 -0
@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );
xen/arch/arm/vpci.c new file +102 -0
102 lines not on this page · raw message
xen/arch/arm/vpci.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* xen/arch/arm/vpci.h +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __ARCH_ARM_VPCI_H__ +#define __ARCH_ARM_VPCI_H__ + +#ifdef CONFIG_HAS_VPCI +int domain_vpci_init (struct domain *d); +#else +static inline int domain_vpci_init (struct domain *d) +{ +return 0 ; +} +#endif + +#endif /* __ARCH_ARM_VPCI_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/drivers/passthrough/pci.c +18 -0
@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev); +#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev); + goto out; + } +#endif +pci_enable_acs (pdev); out:
xen/include/asm-arm/domain.h +6 -1
@@ -2,6 +2,7 @@#define __ASM_DOMAIN_H__#include <xen/cache.h> +#include <xen/nospec.h> #include <xen/timer.h> #include <asm/page.h> #include <asm/p2m.h>
@@ -262,7 +263,11 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) -#define has_vpci (d) ({ (void)(d); false; }) +/* +* For X86 VPCI is enabled and tested for PVH DOM0 only but +* for ARM we enable support VPCI for guest domain also. +*/ +#define has_vpci (d) evaluate_nospec((d)->options & XEN_DOMCTL_CDF_vpci)#endif /* __ASM_DOMAIN_H__ */
xen/include/asm-x86/pci.h +0 -2
@@ -6,8 +6,6 @@#define CF8_ADDR_HI (cf8) ( ((cf8) & 0x0f000000) >> 16)#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) -#define MMCFG_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) -#define IS_SNB_GFX (id) (id == 0x01068086 || id == 0x01168086 \ || id == 0x01268086 || id == 0x01028086 \ || id == 0x01128086 || id == 0x01228086 \
xen/include/public/arch-arm.h +7 -0
@@ -418,6 +418,13 @@ typedef uint64_t xen_callback_t;#define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000)/* vCPU0..127 */ #define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000) +/* +* 256 MB is reserved for VPCI configuration space based on calculation +* 256 buses × 32 devices × 8 functions × 4 KB = 256 MB +*/ +#define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000) +#define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000) +/* ACPI tables physical address */ #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000)#define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000)
xen/include/xen/pci.h +2 -0
@@ -40,6 +40,8 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define MMCFG_BDF (addr) (((addr) & 0x0ffff000) >> 12) + typedef union { uint32_t sbdf; struct {
Signature · 1 line
2.25.1
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 11 lines · Rahul Singh
xen/arch/arm/vpci.c new file +8
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*
xen/arch/arm/vpci.c line 18
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)
Nit: Stray blank (like you had in an earlier version for MMCFG_BDF()). Also isn't this effectively part of the public interface (along with MMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?
xen/arch/arm/vpci.c line 25
Quoted 6 lines
xen/arch/arm/vpci.c new file +6
-0+/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false;
struct hsr_dabt's size field doesn't allow len to be above 8. I could see that you may want to sanity check things, but that's not helpful if done incompletely. Elsewhere you assume the value to be non-zero, and ...
xen/arch/arm/vpci.c line 28
Quoted 2 lines
xen/arch/arm/vpci.c new file +2
-0+/* Check that access is size aligned. */ +if ( (reg & (len -1 )) )
... right here you assume the value to be a power of 2. While I'm not a maintainer, I'd still like to suggest consistency: Do all pertinent checks or none of them (relying on the caller).
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
xen/arch/arm/vpci.c line 39
Quoted 6 lines
xen/arch/arm/vpci.c new file +6
-0+static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ;
What use is this initializer? The error path further down doesn't forward the value into *r, and subsequently the value gets fully overwritten.
xen/arch/arm/vpci.c line 42
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa);
This implies segment to be zero. While probably fine for now, I wonder if this wouldn't warrant a comment.
xen/arch/arm/vpci.c line 50
Quoted 8 lines
xen/arch/arm/vpci.c new file +8
-0+ reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ;
Throughout this series I haven't been able to spot where the HAS_VPCI Kconfig symbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.
xen/arch/arm/vpci.c line 62
Quoted 6 lines
xen/arch/arm/vpci.c new file +6
-0+static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r;
A little like in the read function - what use is this local variable? Can't you use r directly?
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 5 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);
Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN.
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);
... you unconditionally undo the if() part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into that if() could be an option.
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as vpci_add_handlers() is idempotent. And it would likely simplify error cleanup.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
As Rahul is on leave, I will answer you and make the changes needed.
Quoted 20 lines · Jan Beulich
Quoted 17 lines · Rahul Singh
xen/arch/arm/vpci.c new file +14
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h>
Quoted 8 lines
xen/arch/arm/vpci.c line 18
Quoted 4 lines
xen/arch/arm/vpci.c new file +4
-0+ +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?
I will move that in the next version to xen/pci.h and rename it MMCFG_REG_OFFSET. Would that be ok ?
Quoted 13 lines
xen/arch/arm/vpci.c line 25
Quoted 7 lines
xen/arch/arm/vpci.c new file +6
-0+/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false;struct hsr_dabt's size field doesn't allow len to be above 8. I could see that you may want to sanity check things, but that's not helpful if done incompletely. Elsewhere you assume the value to be non-zero, and ...
Quoted 6 lines
xen/arch/arm/vpci.c line 28
Quoted 2 lines
xen/arch/arm/vpci.c new file +2
-0+/* Check that access is size aligned. */ +if ( (reg & (len -1 )) )... right here you assume the value to be a power of 2. While I'm not a maintainer, I'd still like to suggest consistency: Do all pertinent checks or none of them (relying on the caller).
I will remove the check for len > 8 as dabt.size cannot have a value greater than 3.
But I will have to introduce a check for len > 4 on 32 bit systems (see after).
Quoted 4 lines
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
Unaligned IO access could be synthesise also on arm to but I would rather not make such a change now without testing it (and there is also a question of it making sense).
So if it is ok with you I will keep that check and discuss it with Rahul when he is back. I will add a comment in the code to make that clear.
Quoted 11 lines
xen/arch/arm/vpci.c line 39
Quoted 7 lines
xen/arch/arm/vpci.c new file +6
-0+static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ;What use is this initializer? The error path further down doesn't forward the value into *r, and subsequently the value gets fully overwritten.
Right I will remove it.
Quoted 7 lines
xen/arch/arm/vpci.c line 42
Quoted 4 lines
xen/arch/arm/vpci.c new file +3
-0+unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa);This implies segment to be zero. While probably fine for now, I wonder if this wouldn't warrant a comment.
I will add the following comment just before:
/* We ignore segment part and always handle segment 0 */
Quoted 14 lines
xen/arch/arm/vpci.c line 50
Quoted 9 lines
xen/arch/arm/vpci.c new file +8
-0+ reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ;Throughout this series I haven't been able to spot where the
HAS_VPCIKconfigsymbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.
Dabt.size could be 3 even on ARM32 but we should not allow 64bit access on mmio regions on arm32.
So I will surround this code with ifdef CONFIG_ARM_64 and add a test for len > 4 to prevent this case on 32bit.
To be completely right we should disable this also for 32bit guests but this change would be a bit more invasive.
Quoted 10 lines
xen/arch/arm/vpci.c line 62
Quoted 7 lines
xen/arch/arm/vpci.c new file +6
-0+static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r;A little like in the read function - what use is this local variable? Can't you use r directly?
We can and I will remove the data variable.
Quoted 31 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 6 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.
Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
- msi_cleanup was done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ? Same could also go for the free_pdev ?
- cleanup code was exactly the same as pci_remove_device code. Should the question about the path also be checked there ?
Regards
Bertrand
Quoted 4 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 28 lines · Bertrand Marquis
Quoted 19 lines · Jan Beulich
Quoted 17 lines · Rahul Singh
xen/arch/arm/vpci.c new file +14
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> Quoted 8 lines
xen/arch/arm/vpci.c line 18
Quoted 4 lines
xen/arch/arm/vpci.c new file +4
-0+ +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?
Quoted 2 lines
I will move that in the next version to
xen/pci.hand rename itMMCFG_REG_OFFSET. Would that be ok ?
That would be okay and make sense when put next to MMCFG_BDF(), but it would not address my comment: That still wouldn't be the public interface. Otoh you only mimic hardware behavior, so perhaps the splitting of the address isn't as relevant to put there as would be GUEST_VPCI_ECAM_{BASE,SIZE}.
Quoted 35 lines
Quoted 30 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 5 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.
Quoted 6 lines
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?
Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
But I'd also like to further defer to Stefano.
Quoted 1 line
Same could also go for the
free_pdev?
I think it's wrong to free_pdev() here. We want to internally keep record of the device, even if the device ends up unusable. The only place where free_pdev() ought to be called is imo pci_remove_device().
Quoted 2 lines
- cleanup code was exactly the same as
pci_remove_devicecode. Should the question about the path also be checked there ?
I'm sorry, but I'm afraid I don't see what "the path" refers to here. You can't mean the conditional in pci_add_device() selecting between iommu_add_device() and iommu_enable_device(), as "remove" can only mean "remove", never "disable".
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 31 lines · Jan Beulich
Quoted 28 lines · Bertrand Marquis
Quoted 27 lines · Jan Beulich
Quoted 11 lines · Rahul Singh
xen/arch/arm/vpci.c new file +8
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* xen/arch/arm/vpci.c line 18
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?
Quoted 8 lines
Quoted 2 lines
I will move that in the next version to
xen/pci.hand renameitMMCFG_REG_OFFSET. Would that be ok ?That would be okay and make sense when put next to
MMCFG_BDF(), but it would not address my comment: That still wouldn't be the public interface. Otoh you only mimic hardware behavior, so perhaps the splitting of the address isn't as relevant to put there as would be GUEST_VPCI_ECAM_{BASE,SIZE}.
Ok now I get what you wanted.
You would actually like both MMCFG_BDF and MMCFG_REG_OFFSET to be moved to arch-arm.h.
Then I am not quite sure to follow why.
Those are not macros coming out of a way we have to define this but from how it works in standard PCI.
The base and size are needed to know where the PCI bus will be.
So why should those be needed in public headers ?
Quoted 43 lines
Quoted 36 lines
Quoted 31 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 6 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.Quoted 6 lines
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?
Quoted 6 lines
Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
Quoted 6 lines
Quoted 2 lines
Same could also go for the
free_pdev?I think it's wrong to
free_pdev()here. We want to internally keep record of the device, even if the device ends up unusable. The only place wherefree_pdev()ought to be called is imopci_remove_device().
Ok.
Quoted 8 lines
Quoted 3 lines
- cleanup code was exactly the same as
pci_remove_devicecode. Should the question about the path also be checked there ?I'm sorry, but I'm afraid I don't see what "the path" refers to here. You can't mean the conditional in
pci_add_device()selecting betweeniommu_add_device()andiommu_enable_device(), as "remove" can only mean "remove", never "disable".
I will try to explain: when we just enable we do not add an entry in the list but we still remove an entry from the list every time (as the condition becomes always true because pdev->domain is at the end always set)
Regards
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 44 lines · Bertrand Marquis
Quoted 30 lines · Jan Beulich
Quoted 28 lines · Bertrand Marquis
Quoted 27 lines · Jan Beulich
Quoted 11 lines · Rahul Singh
xen/arch/arm/vpci.c new file +8
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* xen/arch/arm/vpci.c line 18
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?Quoted 8 lines
Quoted 2 lines
I will move that in the next version to
xen/pci.hand renameitMMCFG_REG_OFFSET. Would that be ok ?That would be okay and make sense when put next to
MMCFG_BDF(), but it would not address my comment: That still wouldn't be the public interface. Otoh you only mimic hardware behavior, so perhaps the splitting of the address isn't as relevant to put there as would be GUEST_VPCI_ECAM_{BASE,SIZE}.Ok now I get what you wanted.
You would actually like both
MMCFG_BDFandMMCFG_REG_OFFSETto be moved toarch-arm.h.
Quoted 6 lines
Then I am not quite sure to follow why.
Those are not macros coming out of a way we have to define this but from how it works in standard PCI.
The base and size are needed to know where the PCI bus will be.So why should those be needed in public headers ?
Well, see my "Otoh ..." in the earlier reply. Keeping the two address splitting macros out of there is okay.
Quoted 66 lines
Quoted 42 lines
Quoted 35 lines
Quoted 30 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 5 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.Quoted 6 lines
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Quoted 6 lines
Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
Quoted 6 lines
Quoted 2 lines
Same could also go for the
free_pdev?I think it's wrong to
free_pdev()here. We want to internally keep record of the device, even if the device ends up unusable. The only place wherefree_pdev()ought to be called is imopci_remove_device().Ok.
Quoted 4 lines
Quoted 3 lines
- cleanup code was exactly the same as
pci_remove_devicecode. Should the question about the path also be checked there ?
Quoted 8 lines
Quoted 4 lines
I'm sorry, but I'm afraid I don't see what "the path" refers to here. You can't mean the conditional in
pci_add_device()selecting betweeniommu_add_device()andiommu_enable_device(), as "remove" can only mean "remove", never "disable".I will try to explain: when we just enable we do not add an entry in the list but we still remove an entry from the list every time (as the condition becomes always true because
pdev->domainis at the end always set)
Well, that anomaly is what I did point out in my review remarks to Rahul. We shouldn't remove an entry from the list if we didn't add one. But quite likely, if we don't free the pdev, we shouldn't be removing the list entry in either case.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 52 lines · Jan Beulich
Quoted 49 lines · Bertrand Marquis
Quoted 30 lines · Jan Beulich
Quoted 28 lines · Bertrand Marquis
Quoted 27 lines · Jan Beulich
Quoted 11 lines · Rahul Singh
xen/arch/arm/vpci.c new file +8
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* xen/arch/arm/vpci.c line 18
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?Quoted 8 lines
Quoted 2 lines
I will move that in the next version to
xen/pci.hand renameitMMCFG_REG_OFFSET. Would that be ok ?That would be okay and make sense when put next to
MMCFG_BDF(), but it would not address my comment: That still wouldn't be the public interface. Otoh you only mimic hardware behavior, so perhaps the splitting of the address isn't as relevant to put there as would be GUEST_VPCI_ECAM_{BASE,SIZE}.Ok now I get what you wanted.
You would actually like both
MMCFG_BDFandMMCFG_REG_OFFSETto be moved toarch-arm.h.Then I am not quite sure to follow why.
Those are not macros coming out of a way we have to define this but from how it works in standard PCI.
The base and size are needed to know where the PCI bus will be.
Quoted 4 lines
Quoted 1 line
So why should those be needed in public headers ?
Well, see my "Otoh ..." in the earlier reply. Keeping the two address splitting macros out of there is okay.
Ok.
Quoted 72 lines
Quoted 72 lines
Quoted 43 lines
Quoted 36 lines
Quoted 31 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 6 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.Quoted 6 lines
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Quoted 6 lines
Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
Quoted 6 lines
Quoted 2 lines
Same could also go for the
free_pdev?I think it's wrong to
free_pdev()here. We want to internally keep record of the device, even if the device ends up unusable. The only place wherefree_pdev()ought to be called is imopci_remove_device().Ok.
Quoted 8 lines
Quoted 3 lines
- cleanup code was exactly the same as
pci_remove_devicecode. Should the question about the path also be checked there ?I'm sorry, but I'm afraid I don't see what "the path" refers to here. You can't mean the conditional in
pci_add_device()selecting betweeniommu_add_device()andiommu_enable_device(), as "remove" can only mean "remove", never "disable".
Quoted 8 lines
Quoted 3 lines
I will try to explain: when we just enable we do not add an entry in the list but we still remove an entry from the list every time (as the condition becomes always true because
pdev->domainis at the end always set)Well, that anomaly is what I did point out in my review remarks to Rahul. We shouldn't remove an entry from the list if we didn't add one. But quite likely, if we don't free the pdev, we shouldn't be removing the list entry in either case.
This problem will not exist anymore when I will move the code up but I will add to adapt the error case in iommu to also remove the vpci handlers. To be coherent I will do the same in the pci_remove_device code.
I will do all those in the v6 of the serie.
Thanks a lot for the answers.
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichQuoted 50 lines · Jan Beulich
Quoted 49 lines · Bertrand Marquis
Quoted 30 lines · Jan Beulich
Quoted 28 lines · Bertrand Marquis
Quoted 27 lines · Jan Beulich
Quoted 11 lines · Rahul Singh
xen/arch/arm/vpci.c new file +8
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* xen/arch/arm/vpci.c line 18
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff)Nit: Stray blank (like you had in an earlier version for
MMCFG_BDF()). Also isn't this effectively part of the public interface (along withMMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?Quoted 8 lines
Quoted 2 lines
I will move that in the next version to
xen/pci.hand renameitMMCFG_REG_OFFSET. Would that be ok ?That would be okay and make sense when put next to
MMCFG_BDF(), but it would not address my comment: That still wouldn't be the public interface. Otoh you only mimic hardware behavior, so perhaps the splitting of the address isn't as relevant to put there as would be GUEST_VPCI_ECAM_{BASE,SIZE}.Ok now I get what you wanted.
You would actually like both
MMCFG_BDFandMMCFG_REG_OFFSETto be moved toarch-arm.h.Then I am not quite sure to follow why.
Those are not macros coming out of a way we have to define this but from how it works in standard PCI.
The base and size are needed to know where the PCI bus will be.
Quoted 57 lines
Quoted 1 line
So why should those be needed in public headers ?
Well, see my "Otoh ..." in the earlier reply. Keeping the two address splitting macros out of there is okay.
Quoted 52 lines
Quoted 42 lines
Quoted 35 lines
Quoted 30 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 767
Quoted 5 lines
xen/drivers/passthrough/pci.c +0
-0@@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else iommu_enable_device (pdev);Please note the context above; ...
Quoted 4 lines
xen/drivers/passthrough/pci.c +4
-0+#ifdef CONFIG_ARM +/* +* On ARM PCI devices discovery will be done by Dom0. Add vpci handler when +* Dom0 inform XEN to add the PCI devices in XEN. xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 782
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "setup of vPCI failed: %d\n" , ret); +pci_cleanup_msi (pdev); + ret =iommu_remove_device (pdev); +if ( pdev->domain ) +list_del (&pdev->domain_list); +free_pdev (pseg, pdev);... you unconditionally undo the
if()part of the earlier conditional; is there any guarantee that the other path can't ever be taken, now and forever? If it can't be taken now (which I think is the case as long as Dom0 wouldn't report the same device twice), then at least some precaution wants taking. Maybe moving your addition into thatif()could be an option.Quoted 4 lines
Furthermore I continue to wonder whether this ordering is indeed preferable over doing software setup before hardware arrangements. This would address the above issue as well as long as
vpci_add_handlers()is idempotent. And it would likely simplify error cleanup.Quoted 6 lines
I agree with you so I will move this code block before iommu part.
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Quoted 6 lines
Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
I know that MSIs are not supported yet on ARM (pci_cleanup_msi does nothing). But I wanted to make sure that the pci_cleanup_msi() calls are present anywhere necessary, especially on the error paths. So that once we add MSI support, we don't need to search through the code to find all the error paths missing a pci_cleanup_msi() call.
To answer your first question: you are right, we are also missing a pci_cleanup_msi() call in the case of IOMMU error. So it might be better to move the call to pci_cleanup_msi() under the "out" label so that we can do it once for both cases.
To answer your second point about whether it is necessary at all: if MSIs and MSI-Xs cannot be already setup at this point at all (not even the enable bit), then we don't need any call to pci_cleanup_msi() in pci_add_device.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 31 lines · Stefano Stabellini
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Bertrand Marquis
Quoted 12 lines · Jan Beulich
Quoted 4 lines · Bertrand Marquis
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
I know that MSIs are not supported yet on ARM (
pci_cleanup_msidoes nothing). But I wanted to make sure that thepci_cleanup_msi()calls are present anywhere necessary, especially on the error paths. So that once we add MSI support, we don't need to search through the code to find all the error paths missing apci_cleanup_msi()call.To answer your first question: you are right, we are also missing a
pci_cleanup_msi()call in the case of IOMMU error. So it might be better to move the call topci_cleanup_msi()under the "out" label so that we can do it once for both cases.
Quoted 4 lines
To answer your second point about whether it is necessary at all: if MSIs and MSI-Xs cannot be already setup at this point at all (not even the enable bit), then we don't need any call to
pci_cleanup_msi()inpci_add_device.
Well, at the very least MSI can't be set up ahead of the traps getting put in place. Whether partial success of putting traps in place may allow a cunning guest to set up MSI may depend on further aspects.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 32 lines · Jan Beulich
Quoted 31 lines · Stefano Stabellini
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Bertrand Marquis
Quoted 12 lines · Jan Beulich
Quoted 4 lines · Bertrand Marquis
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
I know that MSIs are not supported yet on ARM (
pci_cleanup_msidoes nothing). But I wanted to make sure that thepci_cleanup_msi()calls are present anywhere necessary, especially on the error paths. So that once we add MSI support, we don't need to search through the code to find all the error paths missing apci_cleanup_msi()call.To answer your first question: you are right, we are also missing a
pci_cleanup_msi()call in the case of IOMMU error. So it might be better to move the call topci_cleanup_msi()under the "out" label so that we can do it once for both cases.
Quoted 8 lines
Quoted 4 lines
To answer your second point about whether it is necessary at all: if MSIs and MSI-Xs cannot be already setup at this point at all (not even the enable bit), then we don't need any call to
pci_cleanup_msi()inpci_add_device.Well, at the very least MSI can't be set up ahead of the traps getting put in place. Whether partial success of putting traps in place may allow a cunning guest to set up MSI may depend on further aspects.
Good point about MSIs not being setup before the traps. We should remove the call to pci_cleanup_msi() in the error path then.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 38 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Stefano Stabellini
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Bertrand Marquis
Quoted 12 lines · Jan Beulich
Quoted 4 lines · Bertrand Marquis
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
I know that MSIs are not supported yet on ARM (
pci_cleanup_msidoes nothing). But I wanted to make sure that thepci_cleanup_msi()calls are present anywhere necessary, especially on the error paths. So that once we add MSI support, we don't need to search through the code to find all the error paths missing apci_cleanup_msi()call.To answer your first question: you are right, we are also missing a
pci_cleanup_msi()call in the case of IOMMU error. So it might be better to move the call topci_cleanup_msi()under the "out" label so that we can do it once for both cases.To answer your second point about whether it is necessary at all: if MSIs and MSI-Xs cannot be already setup at this point at all (not even the enable bit), then we don't need any call to
pci_cleanup_msi()inpci_add_device.
Quoted 6 lines
Quoted 3 lines
Well, at the very least MSI can't be set up ahead of the traps getting put in place. Whether partial success of putting traps in place may allow a cunning guest to set up MSI may depend on further aspects.
Good point about MSIs not being setup before the traps. We should remove the call to
pci_cleanup_msi()in the error path then.
Your reply makes me fear you didn't pay enough attention to the "partial" in my earlier reply. The traps for the various registers can't all be set up atomically, so there may be a transient period where enough traps are already in place for a cunning guest to arrange for setup. Unless, as said, there are further setup steps needed before a guest could succeed in doing so.
But even if partial trap setup alone was sufficient, I think the cleaning up of MSI then might still better go on the error path there than on that of pci_add_device().
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 55 lines · Jan Beulich
Quoted 38 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Stefano Stabellini
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Bertrand Marquis
Quoted 12 lines · Jan Beulich
Quoted 4 lines · Bertrand Marquis
But digging deeper into this, I would have 2 questions:
-
msi_cleanupwas done there after a request from Stefano, but is not done in case or iommu error, is there an issue to solve here ?Maybe, but I'm not sure. This very much depends on what a domain could in principle do with a partly set-up device. Plus let's not forget that we're talking of only Dom0 here (for now at least, i.e. not considering the dom0less case).
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
But I'd also like to further defer to Stefano.
Ok, I must admit I do not really see at that stage why doing an MSI cleanup could be needed so I will wait for Stefano to know if I need to keep this when moving the block up (at the end it is theoretical right now as this is empty).
I know that MSIs are not supported yet on ARM (
pci_cleanup_msidoes nothing). But I wanted to make sure that thepci_cleanup_msi()calls are present anywhere necessary, especially on the error paths. So that once we add MSI support, we don't need to search through the code to find all the error paths missing apci_cleanup_msi()call.To answer your first question: you are right, we are also missing a
pci_cleanup_msi()call in the case of IOMMU error. So it might be better to move the call topci_cleanup_msi()under the "out" label so that we can do it once for both cases.To answer your second point about whether it is necessary at all: if MSIs and MSI-Xs cannot be already setup at this point at all (not even the enable bit), then we don't need any call to
pci_cleanup_msi()inpci_add_device.Quoted 6 lines
Quoted 3 lines
Well, at the very least MSI can't be set up ahead of the traps getting put in place. Whether partial success of putting traps in place may allow a cunning guest to set up MSI may depend on further aspects.
Good point about MSIs not being setup before the traps. We should remove the call to
pci_cleanup_msi()in the error path then.Your reply makes me fear you didn't pay enough attention to the "partial" in my earlier reply. The traps for the various registers can't all be set up atomically, so there may be a transient period where enough traps are already in place for a cunning guest to arrange for setup. Unless, as said, there are further setup steps needed before a guest could succeed in doing so.
Quoted 3 lines
But even if partial trap setup alone was sufficient, I think the cleaning up of MSI then might still better go on the error path there than on that of
pci_add_device().
I think I should put the msi_cleanup in the exit path if pdev is not null but we got a non null ret (in an else if ( pdev ) ).
This would cover all exit paths, especially as I will move the add_handler before the iommu init.
Would that be ok for everyone ?
Cheers
Bertrand
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 16 lines · Bertrand Marquis
Quoted 12 lines · Jan Beulich
Quoted 2 lines · Stefano Stabellini
Good point about MSIs not being setup before the traps. We should remove the call to
pci_cleanup_msi()in the error path then.Your reply makes me fear you didn't pay enough attention to the "partial" in my earlier reply. The traps for the various registers can't all be set up atomically, so there may be a transient period where enough traps are already in place for a cunning guest to arrange for setup. Unless, as said, there are further setup steps needed before a guest could succeed in doing so.
Quoted 3 lines
But even if partial trap setup alone was sufficient, I think the cleaning up of MSI then might still better go on the error path there than on that of
pci_add_device().
Quoted 6 lines
I think I should put the
msi_cleanupin the exit path if pdev is not null but we got a non null ret (in an else if ( pdev ) ).
This would cover all exit paths, especially as I will move theadd_handlerbefore the iommu init.Would that be ok for everyone ?
Sounds reasonable at the first glance.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 1 line · Bertrand Marquis
Hi Jan,
Hi Bertrand,
Quoted 10 lines
As Rahul is on leave, I will answer you and make the changes needed.
Quoted 4 lines · Jan Beulich
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
Unaligned IO access could be synthesise also on arm to but I would rather not make such a change now without testing it (and there is also a question of it making sense).
Yes it makes sense. I actually have an item in my TODO list to forbid unaligned access because they should not happen on any device we currently emulate.
Although, I am not aware of any issue other than the guest would shoot itself in the foot if this happens.
Quoted 3 lines
So if it is ok with you I will keep that check and discuss it with Rahul when he is back. I will add a comment in the code to make that clear.
I am OK with it.
[...]
Quoted 7 lines
Quoted 4 lines
Throughout this series I haven't been able to spot where the
HAS_VPCIKconfigsymbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.Dabt.size could be 3 even on ARM32 but we should not allow 64bit access on mmio regions on arm32.
Hmmm... Looking at the Armv7 and Armv8 spec, ldrd/strd (64-bit read) would not present a valid ISV. So I think it is not be possible to have dabt.size = 3 for 32-bit domain. But I agree we probably want to harden the code.
Quoted 6 lines
So I will surround this code with ifdef
CONFIG_ARM_64and add a test for len > 4 to prevent this case on 32bit.To be completely right we should disable this also for 32bit guests but this change would be a bit more invasive.
I think the following should be sufficient:
if ( is_domain_32bit_domain() && len > 4 )
return ...;
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Julien,
Quoted 41 lines · Julien Grall
Quoted 1 line · Bertrand Marquis
Hi Jan,
Hi Bertrand,
Quoted 8 lines
As Rahul is on leave, I will answer you and make the changes needed.
Quoted 4 lines · Jan Beulich
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
Unaligned IO access could be synthesise also on arm to but I would rather not make such a change now without testing it (and there is also a question of it making sense).
Yes it makes sense. I actually have an item in my TODO list to forbid unaligned access because they should not happen on any device we currently emulate.
Although, I am not aware of any issue other than the guest would shoot itself in the foot if this happens.
Quoted 2 lines
So if it is ok with you I will keep that check and discuss it with Rahul when he is back. I will add a comment in the code to make that clear.
I am OK with it.
[...]
Quoted 6 lines
Quoted 4 lines
Throughout this series I haven't been able to spot where the
HAS_VPCIKconfigsymbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.Dabt.size could be 3 even on ARM32 but we should not allow 64bit access on mmio regions on arm32.
Hmmm... Looking at the Armv7 and Armv8 spec, ldrd/strd (64-bit read) would not present a valid ISV. So I think it is not be possible to have dabt.size = 3 for 32-bit domain. But I agree we probably want to harden the code.
Quoted 4 lines
So I will surround this code with ifdef
CONFIG_ARM_64and add a test for len > 4 to prevent this case on 32bit.
To be completely right we should disable this also for 32bit guests but this change would be a bit more invasive.
Quoted 4 lines
I think the following should be sufficient:
if (
is_domain_32bit_domain()&& len > 4 )
return ...;
With the last request from Roger to use the function implemented in arch/x86/hw/io.c, the function will move to vpci.h so using is_32bit_domain will not be possible without ifdefery CONFIG_ARM. Also I have no access to the domain there.
So the best I can do for now would be something like:
#ifdef CONFIG_ARM_32
If (len == 8)
return false
#endif
A 32bit guest on 64bit xen would not be checked.
Would that be ok for now ?
I could add a comment in the code to warn about the limitation.
Cheers
Bertrand
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 57 lines · Bertrand Marquis
Hi Julien,
Quoted 41 lines · Julien Grall
Quoted 1 line · Bertrand Marquis
Hi Jan,
Hi Bertrand,
Quoted 8 lines
As Rahul is on leave, I will answer you and make the changes needed.
Quoted 4 lines · Jan Beulich
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
Unaligned IO access could be synthesise also on arm to but I would rather not make such a change now without testing it (and there is also a question of it making sense).
Yes it makes sense. I actually have an item in my TODO list to forbid unaligned access because they should not happen on any device we currently emulate.
Although, I am not aware of any issue other than the guest would shoot itself in the foot if this happens.
Quoted 2 lines
So if it is ok with you I will keep that check and discuss it with Rahul when he is back. I will add a comment in the code to make that clear.
I am OK with it.
[...]
Quoted 6 lines
Quoted 4 lines
Throughout this series I haven't been able to spot where the
HAS_VPCIKconfigsymbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.Dabt.size could be 3 even on ARM32 but we should not allow 64bit access on mmio regions on arm32.
Hmmm... Looking at the Armv7 and Armv8 spec, ldrd/strd (64-bit read) would not present a valid ISV. So I think it is not be possible to have dabt.size = 3 for 32-bit domain. But I agree we probably want to harden the code.
Quoted 4 lines
So I will surround this code with ifdef
CONFIG_ARM_64and add a test for len > 4 to prevent this case on 32bit.
To be completely right we should disable this also for 32bit guests but this change would be a bit more invasive.Quoted 4 lines
I think the following should be sufficient:
if (
is_domain_32bit_domain()&& len > 4 )
return ...;With the last request from Roger to use the function implemented in
arch/x86/hw/io.c, the function will move tovpci.hso usingis_32bit_domainwill not be possible without ifdeferyCONFIG_ARM. Also I have no access to the domain there.So the best I can do for now would be something like:
#ifdefCONFIG_ARM_32
If (len == 8)
return false
#endif
Quoted 3 lines
A 32bit guest on 64bit xen would not be checked.
Would that be ok for now ?
I think the #ifdef is a bit pointless. My preference would be to not add the #ifdef but instead add...
Quoted 2 lines
I could add a comment in the code to warn about the limitation.
.. a comment for now as this is only an hardening problem.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Julien,
Quoted 61 lines · Julien Grall
Quoted 46 lines · Bertrand Marquis
Hi Julien,
Quoted 41 lines · Julien Grall
Quoted 1 line · Bertrand Marquis
Hi Jan,
Hi Bertrand,
Quoted 8 lines
As Rahul is on leave, I will answer you and make the changes needed.
Quoted 4 lines · Jan Beulich
Independent of this - is bare metal Arm enforcing this same alignment restriction (unconditionally)? Iirc on x86 we felt we'd better synthesize misaligned accesses.
Unaligned IO access could be synthesise also on arm to but I would rather not make such a change now without testing it (and there is also a question of it making sense).
Yes it makes sense. I actually have an item in my TODO list to forbid unaligned access because they should not happen on any device we currently emulate.
Although, I am not aware of any issue other than the guest would shoot itself in the foot if this happens.
Quoted 2 lines
So if it is ok with you I will keep that check and discuss it with Rahul when he is back. I will add a comment in the code to make that clear.
I am OK with it.
[...]
Quoted 6 lines
Quoted 4 lines
Throughout this series I haven't been able to spot where the
HAS_VPCIKconfigsymbol would get selected. Hence I cannot tell whether all of this is Arm64-specific. Otherwise I wonder whether size 8 actually can occur on Arm32.Dabt.size could be 3 even on ARM32 but we should not allow 64bit access on mmio regions on arm32.
Hmmm... Looking at the Armv7 and Armv8 spec, ldrd/strd (64-bit read) would not present a valid ISV. So I think it is not be possible to have dabt.size = 3 for 32-bit domain. But I agree we probably want to harden the code.
Quoted 4 lines
So I will surround this code with ifdef
CONFIG_ARM_64and add a test for len > 4 to prevent this case on 32bit.
To be completely right we should disable this also for 32bit guests but this change would be a bit more invasive.Quoted 4 lines
I think the following should be sufficient:
if (
is_domain_32bit_domain()&& len > 4 )
return ...;Quoted 9 lines
With the last request from Roger to use the function implemented in
arch/x86/hw/io.c, the function will move tovpci.hso usingis_32bit_domainwill not be possible without ifdeferyCONFIG_ARM. Also I have no access to the domain there.
So the best I can do for now would be something like:
#ifdefCONFIG_ARM_32
If (len == 8)
return false
#endif
A 32bit guest on 64bit xen would not be checked.
Would that be ok for now ?
Quoted 5 lines
I think the #ifdef is a bit pointless. My preference would be to not add the #ifdef but instead add...
Quoted 1 line
I could add a comment in the code to warn about the limitation.
.. a comment for now as this is only an hardening problem.
Agree I will do that.
Cheers
Bertrand
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Rahul SinghQuoted 84 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
------ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.hxen/arch/arm/Makefile +1
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ +obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ; fail:xen/arch/arm/domain_build.c +0
-0
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;
I think I'm confused with this. You seem to enable vPCI for dom0, but then domain_vpci_init will setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.
Quoted 32 lines
xen/arch/arm/domain_build.c +1
-0+ dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +22
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{
xen/arch/arm/vpci.c line 32
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +}
There's a vpci_access_allowed which I think you could generalize and use here, there's no need to have this duplicated code.
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Roger,
Quoted 90 lines · Roger Pau Monné
Quoted 87 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
Quoted 6 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.
I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Quoted 38 lines
Quoted 38 lines
xen/arch/arm/domain_build.c +1
-0+ dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +27
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */
Quoted 8 lines
xen/arch/arm/vpci.c line 32
Quoted 5 lines
xen/arch/arm/vpci.c new file +5
-0+if ( (reg & (len -1 )) ) +return false; + +return true; +}There's a
vpci_access_allowedwhich I think you could generalize and use here, there's no need to have this duplicated code.
It definitely looks exactly like what we want to do.
I would need to turn this into a static inline and put it in some global header. It is currently in arch/x86/hvm/io.c, any suggestion on the header to move it to ?
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 92 lines · Bertrand Marquis
Hi Roger,
Quoted 90 lines · Roger Pau Monné
Quoted 87 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
Quoted 8 lines
Quoted 5 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Thank you,
Oleksandr
[1] https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 100 lines · Oleksandr Andrushchenko
Quoted 97 lines · Bertrand Marquis
Hi Roger,
Quoted 95 lines · Roger Pau Monné
Quoted 84 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.
Quoted 5 lines
Quoted 3 lines
I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Then I don't think we should set XEN_DOMCTL_CDF_vpci for dom0 here, it should instead be done in the patch where dom0 support is introduced.
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Roger,
Quoted 103 lines · Roger Pau Monné
Quoted 100 lines · Oleksandr Andrushchenko
Quoted 97 lines · Bertrand Marquis
Hi Roger,
Quoted 95 lines · Roger Pau Monné
Quoted 84 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Then I don't think we should set
XEN_DOMCTL_CDF_vpcifor dom0 here, it should instead be done in the patch where dom0 support is introduced.
Ok I will check to remove this and include the change in v6.
Cheers
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 104 lines · Bertrand Marquis
Hi Roger,
Quoted 102 lines · Roger Pau Monné
Quoted 99 lines · Oleksandr Andrushchenko
Quoted 97 lines · Bertrand Marquis
Hi Roger,
Quoted 95 lines · Roger Pau Monné
Quoted 84 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Then I don't think we should set
XEN_DOMCTL_CDF_vpcifor dom0 here, it should instead be done in the patch where dom0 support is introduced.Ok I will check to remove this and include the change in v6.
Just to make it clear: do we want to remove this piece from this patch and instead have a dedicated patch on top of my series, so it is enabled right after we have the code that sets up the trap handlers for Dom0? If so, then do we want that patch to be chained in my series or sent as a follow up right after it separately?
Thanks,
Oleksandr
Quoted 5 lines
Cheers
BertrandQuoted 1 line
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 110 lines · Oleksandr Andrushchenko
Quoted 109 lines · Bertrand Marquis
Hi Roger,
Quoted 107 lines · Roger Pau Monné
Quoted 104 lines · Oleksandr Andrushchenko
Quoted 92 lines · Bertrand Marquis
Hi Roger,
Quoted 90 lines · Roger Pau Monné
Quoted 87 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;Quoted 8 lines
Quoted 5 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Then I don't think we should set
XEN_DOMCTL_CDF_vpcifor dom0 here, it should instead be done in the patch where dom0 support is introduced.Ok I will check to remove this and include the change in v6.
Just to make it clear: do we want to remove this piece from this patch and instead have a dedicated patch on top of my series, so it is enabled right after we have the code that sets up the trap handlers for Dom0? If so, then do we want that patch to be chained in my series or sent as a follow up right after it separately?
I think we want to remove the XEN_DOMCTL_CDF_vpci chunk from this patch.
Where exactly it should be introduced, I am not sure. I think it would be OK as a separate single patch at the end. I doesn't have to be part of the outstanding series, considering that we are also missing the patch to add "select HAS_PCI" for ARM.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 118 lines · Stefano Stabellini
Quoted 109 lines · Oleksandr Andrushchenko
Quoted 108 lines · Bertrand Marquis
Hi Roger,
Quoted 106 lines · Roger Pau Monné
Quoted 103 lines · Oleksandr Andrushchenko
Quoted 92 lines · Bertrand Marquis
Hi Roger,
Quoted 90 lines · Roger Pau Monné
Quoted 87 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;Quoted 8 lines
Quoted 5 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Then I don't think we should set
XEN_DOMCTL_CDF_vpcifor dom0 here, it should instead be done in the patch where dom0 support is introduced.Ok I will check to remove this and include the change in v6.
Just to make it clear: do we want to remove this piece from this patch and instead have a dedicated patch on top of my series, so it is enabled right after we have the code that sets up the trap handlers for Dom0? If so, then do we want that patch to be chained in my series or sent as a follow up right after it separately?
Quoted 6 lines
I think we want to remove the
XEN_DOMCTL_CDF_vpcichunk from this patch.Where exactly it should be introduced, I am not sure. I think it would be OK as a separate single patch at the end. I doesn't have to be part of the outstanding series, considering that we are also missing the patch to add "select
HAS_PCI" for ARM.
Yes, makes sense
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Stefano StabelliniHi Stefano,
Quoted 122 lines · Stefano Stabellini
Quoted 110 lines · Oleksandr Andrushchenko
Quoted 109 lines · Bertrand Marquis
Hi Roger,
Quoted 107 lines · Roger Pau Monné
Quoted 104 lines · Oleksandr Andrushchenko
Quoted 92 lines · Bertrand Marquis
Hi Roger,
Quoted 90 lines · Roger Pau Monné
Quoted 87 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +0
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;Quoted 8 lines
Quoted 5 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3057
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci;I think I'm confused with this. You seem to enable vPCI for dom0, but then
domain_vpci_initwill setup traps for the guest virtual ECAM layout, not the native one that dom0 will be using.I think after the last discussions, it was decided to also installed the vpci handler for dom0. I will have to look into this and come back to you. @Oleksandr: Could you comment on this.
Yes, we do trap Dom0 as well. The Dom0 traps are not in this series, but are in mine as it needs more preparatory work for that. Please see [1]
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Then I don't think we should set
XEN_DOMCTL_CDF_vpcifor dom0 here, it should instead be done in the patch where dom0 support is introduced.Ok I will check to remove this and include the change in v6.
Just to make it clear: do we want to remove this piece from this patch and instead have a dedicated patch on top of my series, so it is enabled right after we have the code that sets up the trap handlers for Dom0? If so, then do we want that patch to be chained in my series or sent as a follow up right after it separately?
Quoted 6 lines
I think we want to remove the
XEN_DOMCTL_CDF_vpcichunk from this patch.Where exactly it should be introduced, I am not sure. I think it would be OK as a separate single patch at the end. I doesn't have to be part of the outstanding series, considering that we are also missing the patch to add "select
HAS_PCI" for ARM.
Agree, I will remove that from v6.
Cheers
Bertrand
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Rahul SinghHi Rahul,
Quoted 13 lines · Rahul Singh
xen/include/asm-arm/domain.h +1
-0@@ -2,6 +2,7 @@#define __ASM_DOMAIN_H__#include <xen/cache.h> +#include <xen/nospec.h> #include <xen/timer.h> #include <asm/page.h> #include <asm/p2m.h>
xen/include/asm-arm/domain.h static inline void arch_vcpu_block(struct vcpu *v) {} · line 269
Quoted 8 lines
xen/include/asm-arm/domain.h +4
-1@@ -262,7 +263,11 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) -#define has_vpci (d) ({ (void)(d); false; }) +/* +* For X86 VPCI is enabled and tested for PVH DOM0 only but +* for ARM we enable support VPCI for guest domain also. +*/
This is the sort of comment that will easily get rot if we change the behavior on x86. But I find a bit odd to justify the implementation based on x86. Can we simply avoid to mention x86?
Quoted 41 lines
xen/include/asm-arm/domain.h +1
-0+#define has_vpci (d) evaluate_nospec((d)->options & XEN_DOMCTL_CDF_vpci)#endif /* __ASM_DOMAIN_H__ */ xen/include/asm-x86/pci.h +0
-2@@ -6,8 +6,6 @@#define CF8_ADDR_HI (cf8) ( ((cf8) & 0x0f000000) >> 16)#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) -#define MMCFG_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) -#define IS_SNB_GFX (id) (id == 0x01068086 || id == 0x01168086 \ || id == 0x01268086 || id == 0x01028086 \ || id == 0x01128086 || id == 0x01228086 \xen/include/public/arch-arm.h +7
-0@@ -418,6 +418,13 @@ typedef uint64_t xen_callback_t;#define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000)/* vCPU0..127 */ #define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000) +/* +* 256 MB is reserved for VPCI configuration space based on calculation +* 256 buses × 32 devices × 8 functions × 4 KB = 256 MB +*/ +#define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000) +#define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000) +/* ACPI tables physical address */ #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000)#define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000)xen/include/xen/pci.h +0
-0
xen/include/xen/pci.h line 47
Quoted 8 lines
xen/include/xen/pci.h +2
-0@@ -40,6 +40,8 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define MMCFG_BDF (addr) (((addr) & 0x0ffff000) >> 12) + typedef union { uint32_t sbdf; struct {
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Julien,
Quoted 17 lines · Julien Grall
Hi Rahul,
Quoted 12 lines · Rahul Singh
xen/include/asm-arm/domain.h +1
-0@@ -2,6 +2,7 @@#define __ASM_DOMAIN_H__#include <xen/cache.h> +#include <xen/nospec.h> #include <xen/timer.h> #include <asm/page.h> #include <asm/p2m.h> @@ -262,7 +263,11 @@ static inline void arch_vcpu_block(struct vcpu *v) {}
Quoted 8 lines
xen/include/asm-arm/domain.h static inline void arch_vcpu_block(struct vcpu *v) {} · line 269
Quoted 6 lines
xen/include/asm-arm/domain.h +4
-0#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) -#define has_vpci(d) ({ (void)(d); false; }) +/* +* For X86 VPCI is enabled and tested for PVH DOM0 only but +* for ARM we enable support VPCI for guest domain also. +*/ This is the sort of comment that will easily get rot if we change the behavior on x86. But I find a bit odd to justify the implementation based on x86. Can we simply avoid to mention x86?
Yes I will remove the x86 part of it.
Cheers
Bertrand
Quoted 49 lines
Quoted 37 lines
xen/include/asm-arm/domain.h +1
-0+#define has_vpci (d) evaluate_nospec((d)->options & XEN_DOMCTL_CDF_vpci)#endif /* __ASM_DOMAIN_H__ */ diff --git a/xen/include/asm-x86/pci.h b/xen/include/asm-x86/pci.hindex
e076951032..c4a4fdcbc2100644xen/include/asm-x86/pci.h +0
-1@@ -6,8 +6,6 @@#define CF8_ADDR_HI (cf8) ( ((cf8) & 0x0f000000) >> 16)#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) -#define MMCFG_BDF(addr) ( ((addr) & 0x0ffff000) >> 12) -#define IS_SNB_GFX (id) (id == 0x01068086 || id == 0x01168086 \ || id == 0x01268086 || id == 0x01028086 \ || id == 0x01128086 || id == 0x01228086 \xen/include/public/arch-arm.h +6
-0@@ -418,6 +418,13 @@ typedef uint64_t xen_callback_t;#define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000)/* vCPU0..127 */ #define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000) +/* +* 256 MB is reserved for VPCI configuration space based on calculation +* 256 buses × 32 devices × 8 functions × 4 KB = 256 MB +*/ +#define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000) +#define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000) +/* ACPI tables physical address */ #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000)#define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000)xen/include/xen/pci.h +0
-0xen/include/xen/pci.h line 46
Quoted 7 lines
xen/include/xen/pci.h +1
-0@@ -40,6 +40,8 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define MMCFG_BDF(addr) (((addr) & 0x0ffff000) >> 12) + typedef union { uint32_t sbdf; struct {Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Rahul SinghQuoted 162 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
------ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.hxen/arch/arm/Makefile +1
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ +obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ; fail:xen/arch/arm/domain_build.c +3
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +63
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size;
xen/arch/arm/vpci.c line 73
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+ + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );
I think those two helpers (and vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code to vpci.c as vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Roger,
Quoted 173 lines · Roger Pau Monné
Quoted 170 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +3
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +71
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , size), data);
Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 2 lines
xen/arch/arm/vpci.c new file +2
-0+if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Would it be ok to have ecam specific code in the vpci common code ?
This is an optimisation and we could do that later on as this is an other change to be done and tested which will start to make things very challenging with the friday deadline.
Cheers
Bertrand
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 184 lines · Bertrand Marquis
Hi Roger,
Quoted 173 lines · Roger Pau Monné
Quoted 170 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
---
---xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +0
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y)obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.oobj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ;fail:
xen/arch/arm/domain_build.c +3
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +71
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , size), data);Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 2 lines
xen/arch/arm/vpci.c new file +2
-0+if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Quoted 1 line
Would it be ok to have ecam specific code in the vpci common code ?
I think so, ECAM is part of the PCI specification and architecture agnostic, so fine to place in common code.
Quoted 3 lines
This is an optimisation and we could do that later on as this is an other change to be done and tested which will start to make things very challenging with the friday deadline.
I guess this could be done, by adding a TODO note that the handlers should be unified with the x86 ones and placed in common code.
I however get the feeling that such work would ultimately be ignored, as there's always more pressing stuff to be done, and people tend to forget about those cleanups once things get committed.
Thanks, Roger.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Roger Pau MonnéQuoted 171 lines · Roger Pau Monné
Quoted 170 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
------ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.hxen/arch/arm/Makefile +1
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ +obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ; fail:xen/arch/arm/domain_build.c +3
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +71
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , size), data);
Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 2 lines
xen/arch/arm/vpci.c new file +2
-0+if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 179 lines · Jan Beulich
Quoted 170 lines · Roger Pau Monné
Quoted 169 lines · Rahul Singh
The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call “PHYSDEVOP_pci_device_add”, VPCI handler for the config space access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware.
For Dom0less systems
scan_pci_devices()would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Change in v5:
- Addpci_cleanup_msi(pdev)in cleanup part.
- Added Reviewed-by: Stefano Stabellini <[email protected]> Change in v4:
- Move addition ofXEN_DOMCTL_CDF_vpciflag to separate patch Change in v3:
- Useis_pci_passthrough_enabled()in place ofpci_passthrough_enabledvariable
- RejectXEN_DOMCTL_CDF_vpcifor x86 inarch_sanitise_domain_config()
- RemoveIS_ENABLED(CONFIG_HAS_VPCI)fromhas_vpci()
Change in v2:
- Add newXEN_DOMCTL_CDF_vpciflag
- modifyhas_vpci()to includeXEN_DOMCTL_CDF_vpci
- enable vpci support when pci-passthough option is enabled.
------ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++ xen/include/asm-arm/domain.h | 7 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/xen/pci.h | 2 + 10 files changed, 179 insertions(+), 3 deletions(-)create mode 100644
xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.hxen/arch/arm/Makefile +1
-0@@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ +obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +4
-0@@ -39,6 +39,7 @@#include <asm/vgic.h> #include <asm/vtimer.h> +#include "vpci.h" #include "vuart.h" DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d,if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =domain_vpci_init (d)) !=0 ) + goto fail; +return 0 ; fail:xen/arch/arm/domain_build.c +3
-0@@ -3053,6 +3053,9 @@ void __init create_dom0(void)if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; +if (is_pci_passthrough_enabled () ) + dom0_cfg.flags |= XEN_DOMCTL_CDF_vpci; + dom0 =domain_create (0 , &dom0_cfg, true);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0\n" );xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Quoted 4 lines
Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
At least for the new code
Quoted 3 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 84 lines · Oleksandr Andrushchenko
Quoted 83 lines · Jan Beulich
Quoted 82 lines · Roger Pau Monné
Quoted 66 lines · Rahul Singh
xen/arch/arm/vpci.c new file +63
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size;xen/arch/arm/vpci.c line 73
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+ + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.
Quoted 7 lines
Quoted 4 lines
Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 89 lines · Jan Beulich
Quoted 88 lines · Oleksandr Andrushchenko
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Roger Pau Monné
Quoted 73 lines · Rahul Singh
xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Quoted 6 lines
Quoted 3 lines
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
My understanding is that "MCFG" is the name of the ACPI table that describes the PCI config space [1]. The underlying PCI standard for the memory mapped layout of the PCI config space is called ECAM. Here, it makes sense to call it ECAM as it is firmware independent.
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 97 lines · Stefano Stabellini
Quoted 89 lines · Jan Beulich
Quoted 88 lines · Oleksandr Andrushchenko
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Roger Pau Monné
Quoted 73 lines · Rahul Singh
xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Quoted 6 lines
Quoted 3 lines
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
Quoted 6 lines
My understanding is that "MCFG" is the name of the ACPI table that describes the PCI config space [1]. The underlying PCI standard for the memory mapped layout of the PCI config space is called ECAM. Here, it makes sense to call it ECAM as it is firmware independent.
Okay, I can accept this, but then I'd expect all existing uses of MCFG / MMCFG in the code which aren't directly ACPI-related to get replaced. Otherwise it's needlessly harder to identify that one piece of code relates to certain other pieces.
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi,
Quoted 105 lines · Jan Beulich
Quoted 102 lines · Stefano Stabellini
Quoted 89 lines · Jan Beulich
Quoted 88 lines · Oleksandr Andrushchenko
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Roger Pau Monné
Quoted 73 lines · Rahul Singh
xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Quoted 6 lines
Quoted 3 lines
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
My understanding is that "MCFG" is the name of the ACPI table that describes the PCI config space [1]. The underlying PCI standard for the memory mapped layout of the PCI config space is called ECAM. Here, it makes sense to call it ECAM as it is firmware independent.
Quoted 6 lines
Quoted 1 line
Okay, I can accept this, but then I'd expect all existing uses of MCFG / MMCFG in the code which aren't directly ACPI-related to get replaced. Otherwise it's needlessly harder to identify that one piece of code relates to certain other pieces.
To sum up on this subject, here what I will do in version 6:
- move vpci_ecam_{read/write} to vpci.c and rename them
- same for access allowed and I will rename it to vpci_ecam_access_allowed
I will work on this and try to push v6 before the end of the day (also handling other remarks on this patch).
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichHi Jan,
Quoted 105 lines · Jan Beulich
Quoted 102 lines · Stefano Stabellini
Quoted 89 lines · Jan Beulich
Quoted 88 lines · Oleksandr Andrushchenko
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Roger Pau Monné
Quoted 73 lines · Rahul Singh
xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Quoted 6 lines
Quoted 3 lines
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
My understanding is that "MCFG" is the name of the ACPI table that describes the PCI config space [1]. The underlying PCI standard for the memory mapped layout of the PCI config space is called ECAM. Here, it makes sense to call it ECAM as it is firmware independent.
Quoted 6 lines
Quoted 1 line
Okay, I can accept this, but then I'd expect all existing uses of MCFG / MMCFG in the code which aren't directly ACPI-related to get replaced. Otherwise it's needlessly harder to identify that one piece of code relates to certain other pieces.
If that is ok with I will:
- move function from x86/hw/io.c to vpci.c renaming them to ECAM
- rename MMCFG_{BDF/REG_OFFSET) to ECAM_{BDF/REG_OFFSET}
For the rest of the occurrences in x86 I will not modify any of them as some are related to ACPI so using (M)MCFG is right and for the others I am not 100% sure.
Do you agree ?
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 118 lines · Bertrand Marquis
Hi Jan,
Quoted 105 lines · Jan Beulich
Quoted 102 lines · Stefano Stabellini
Quoted 89 lines · Jan Beulich
Quoted 88 lines · Oleksandr Andrushchenko
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Roger Pau Monné
Quoted 73 lines · Rahul Singh
xen/arch/arm/vpci.c new file +70
-0@@ -0,0 +1,102 @@ +/* +* xen/arch/arm/vpci.c +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <xen/sched.h> + +#include <asm/mmio.h> + +#define REGISTER_OFFSET (addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed (unsigned int reg,unsigned int len) +{ +/* Check access size. */ +if ( len >8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = ~0UL ; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; + + data =vpci_read (sbdf, reg,min (4u , size)); +if ( size ==8 ) + data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + + *r = data; + +return 1 ; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +unsigned int reg; +pci_sbdf_t sbdf; +unsigned long data = r; +unsigned int size =1U << info->dabt.size; + + sbdf.sbdf =MMCFG_BDF (info->gpa); + reg =REGISTER_OFFSET (info->gpa); + +if ( !vpci_mmio_access_allowed (reg, size) ) +return 0 ; +Quoted 8 lines
xen/arch/arm/vpci.c line 73
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+vpci_write (sbdf, reg,min (4u , size), data); +if ( size ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 );I think those two helpers (and
vpci_mmio_access_allowed) are very similar to the existing x86 ones (see vpci_mmcfg_{read,write}), up to the point where I would consider moving the shared code tovpci.cas vpci_ecam_{read,write} and call them from the arch specific trap handlers.Except that please can we stick to mcfg or mmcfg instead of ecam in names, as that's how the thing has been named in Xen from its introduction? I've just grep-ed the code base (case insensitively) and found no mention of ECAM. There are only a few "became".
Quoted 6 lines
Quoted 3 lines
I do understand that this is historically that we do not have ECAM in Xen, but PCI is not about Xen. Thus, I think it is also acceptable to use a commonly known ECAM for the code that works with ECAM.
ACPI, afaik, also doesn't call this ECAM. That's where MCFG / MMCFG actually come from, I believe.
My understanding is that "MCFG" is the name of the ACPI table that describes the PCI config space [1]. The underlying PCI standard for the memory mapped layout of the PCI config space is called ECAM. Here, it makes sense to call it ECAM as it is firmware independent.
Quoted 6 lines
Quoted 1 line
Okay, I can accept this, but then I'd expect all existing uses of MCFG / MMCFG in the code which aren't directly ACPI-related to get replaced. Otherwise it's needlessly harder to identify that one piece of code relates to certain other pieces.
If that is ok with I will:
- move function fromx86/hw/io.ctovpci.crenaming them to ECAM
- rename MMCFG_{BDF/REG_OFFSET) to ECAM_{BDF/REG_OFFSET}
Quoted 5 lines
For the rest of the occurrences in x86 I will not modify any of them as some are related to ACPI so using (M)MCFG is right and for the others I am not 100% sure.
Do you agree ?
Probably not, but I don't want to put time into checking existing names right now. Yet I'm getting the impression that I'm being overruled here anyway, so there may be little point in investing any time here in the first place.
Jan
PATCH v5 9/11 xen/arm: Transitional change to build HAS_VPCI on ARM.
In reply to Rahul SinghThis patch will be reverted once we add support for VPCI MSI/MSIX support on ARM.
---
Change in v5: none
Change in v4:
- Added Acked-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3: none
Change in v2: Patch introduced in v2
---
--- xen/drivers/vpci/Makefile | 3 ++- xen/drivers/vpci/header.c | 2 ++ xen/include/asm-arm/pci.h | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
xen/drivers/vpci/Makefile +2 -1
@@ -1 +1,2 @@ -obj-y += vpci.o header.o msi.o msix.o +obj-y += vpci.o header.o +obj-$(CONFIG_HAS_PCI_MSI) += msi.o msix.o
xen/drivers/vpci/header.c +2 -0
@@ -96,8 +96,10 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd,* FIXME: punching holes after the p2m has been set up might be racy for * DomU usage, needs to be revisited. */ +#ifdef CONFIG_HAS_PCI_MSI if ( map && !rom_only &&vpci_make_msix_hole (pdev) )return ; +#endif for ( i =0 ; i <ARRAY_SIZE (header->bars); i++ ) {
xen/include/asm-arm/pci.h +8 -0
@@ -26,6 +26,14 @@ struct arch_pci_dev {struct device dev; }; +/* Arch-specific MSI data for vPCI. */ +struct vpci_arch_msi { +}; + +/* Arch-specific MSI-X entry data for vPCI. */ +struct vpci_arch_msix_entry { +}; +/* * struct to hold the mappings of a config space window. This * is expected to be used as sysdata for PCI controllers that
Signature · 1 line
2.25.1
Re: [PATCH v5 09/11] xen/arm: Transitional change to build HAS_VPCI on ARM.
Quoted 6 lines · Rahul Singh
This patch will be reverted once we add support for VPCI MSI/MSIX support on ARM.
Signed-off-by Rahul Singh <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
Quoted 27 lines
---
Change in v5: none
Change in v4:
- Added Acked-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3: none
Change in v2: Patch introduced in v2
------ xen/drivers/vpci/Makefile | 3 ++- xen/drivers/vpci/header.c | 2 ++ xen/include/asm-arm/pci.h | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)xen/drivers/vpci/Makefile +2
-1@@ -1 +1,2 @@ -obj-y += vpci.o header.o msi.o msix.o +obj-y += vpci.o header.o +obj-$(CONFIG_HAS_PCI_MSI) += msi.o msix.oxen/drivers/vpci/header.c +0
-0
xen/drivers/vpci/header.c static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, · line 102
Quoted 7 lines
xen/drivers/vpci/header.c +2
-0@@ -96,8 +96,10 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd,* FIXME: punching holes after the p2m has been set up might be racy for * DomU usage, needs to be revisited. */ +#ifdef CONFIG_HAS_PCI_MSI if ( map && !rom_only &&vpci_make_msix_hole (pdev) )return ; +#endif
FWIW, I would also be fine with providing a dummy inline function for vpci_make_msix_hole when !CONFIG_HAS_PCI_MSI, but I assume this is a temporary workaround until MSI is implemented for Arm.
Thanks, Roger.
Re: [PATCH v5 09/11] xen/arm: Transitional change to build HAS_VPCI on ARM.
Hi Roger,
Quoted 11 lines · Roger Pau Monné
Quoted 6 lines · Rahul Singh
This patch will be reverted once we add support for VPCI MSI/MSIX support on ARM.
Signed-off-by Rahul Singh <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Thanks
Quoted 31 lines
Quoted 31 lines
---
Change in v5: none
Change in v4:
- Added Acked-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3: none
Change in v2: Patch introduced in v2
---
---xen/drivers/vpci/Makefile | 3 ++- xen/drivers/vpci/header.c | 2 ++ xen/include/asm-arm/pci.h | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)xen/drivers/vpci/Makefile +2
-1@@ -1 +1,2 @@ -obj-y += vpci.o header.o msi.o msix.o +obj-y += vpci.o header.o +obj-$(CONFIG_HAS_PCI_MSI) += msi.o msix.oxen/drivers/vpci/header.c +0
-0@@ -96,8 +96,10 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd,* FIXME: punching holes after the p2m has been set up might be racy for * DomU usage, needs to be revisited. */
Quoted 8 lines
xen/drivers/vpci/header.c static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, · line 102
Quoted 4 lines
xen/drivers/vpci/header.c +2
-0+#ifdef CONFIG_HAS_PCI_MSI if ( map && !rom_only &&vpci_make_msix_hole (pdev) )return ; +#endif FWIW, I would also be fine with providing a dummy inline function for
vpci_make_msix_holewhen !CONFIG_HAS_PCI_MSI, but I assume this is a temporary workaround until MSI is implemented for Arm.
Yes this is temporary and MSI support will be added on Arm.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v5 09/11] xen/arm: Transitional change to build HAS_VPCI on ARM.
Quoted 8 lines · Bertrand Marquis
Hi Roger,
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Rahul Singh
This patch will be reverted once we add support for VPCI MSI/MSIX support on ARM.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Signed-off-by Rahul Singh <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Thanks
Thanks! I committed this patch.
PATCH v5 10/11 arm/libxl: Emulated PCI device tree node in libxl
In reply to Rahul Singhlibxl will create an emulated PCI device tree node in the device tree to enable the guest OS to discover the virtual PCI during guest boot. Emulated PCI device tree node will only be created when there is any device assigned to guest.
A new area has been reserved in the arm guest physical map at which the VPCI bus is declared in the device tree (reg and ranges parameters of the node).
---
Change in v5:
- Move setting the arch_arm.vpci and XEN_DOMCTL_CDF_vpci to libxl_arm.c Change in v4:
- Gate code for x86 for setting the XEN_DOMCTL_CDF_vpci for x86. Change in v3:
- Make GUEST_VPCI_MEM_ADDR address 2MB aligned
Change in v2:
- enable doamin_vpci_init() when XEN_DOMCTL_CDF_vpci is set for domain.
---
--- tools/include/libxl.h | 6 ++ tools/libs/light/libxl_arm.c | 111 +++++++++++++++++++++++++++++++ tools/libs/light/libxl_types.idl | 1 + xen/include/public/arch-arm.h | 10 +++ 4 files changed, 128 insertions(+)
tools/include/libxl.h +6 -0
@@ -358,6 +358,12 @@*/ #define LIBXL_HAVE_BUILDINFO_ARM_VUART 1 +/* +* LIBXL_HAVE_BUILDINFO_ARM_VPCI indicates that the toolstack supports virtual +* PCI for ARM. +*/ +#define LIBXL_HAVE_BUILDINFO_ARM_VPCI 1 +/* * LIBXL_HAVE_BUILDINFO_GRANT_LIMITS indicates that libxl_domain_build_info * has the max_grant_frames and max_maptrack_frames fields.
tools/libs/light/libxl_arm.c +111 -0
141 lines not on this page · raw message
tools/libs/light/libxl_types.idl +1 -0
@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool), ])), ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool), ])),
xen/include/public/arch-arm.h +10 -0
@@ -433,6 +433,11 @@ typedef uint64_t xen_callback_t;#define GUEST_PL011_BASE xen_mk_ullong(0x22000000)#define GUEST_PL011_SIZE xen_mk_ullong(0x00001000) +/* Guest PCI-PCIe memory space where config space and BAR will be available.*/ +#define GUEST_VPCI_ADDR_TYPE_MEM xen_mk_ullong(0x02000000) +#define GUEST_VPCI_MEM_ADDR xen_mk_ullong(0x23000000) +#define GUEST_VPCI_MEM_SIZE xen_mk_ullong(0x10000000) +/* * 16MB == 4096 pages reserved for guest to use as a region to map its * grant table in.
@@ -448,6 +453,11 @@ typedef uint64_t xen_callback_t;#define GUEST_RAM0_BASE xen_mk_ullong(0x40000000)/* 3GB of low RAM @ 1GB */ #define GUEST_RAM0_SIZE xen_mk_ullong(0xc0000000) +/* 4GB @ 4GB Prefetch Memory for VPCI */ +#define GUEST_VPCI_ADDR_TYPE_PREFETCH_MEM xen_mk_ullong(0x42000000) +#define GUEST_VPCI_PREFETCH_MEM_ADDR xen_mk_ullong(0x100000000) +#define GUEST_VPCI_PREFETCH_MEM_SIZE xen_mk_ullong(0x100000000) +#define GUEST_RAM1_BASE xen_mk_ullong(0x0200000000)/* 1016GB of RAM @ 8GB */ #define GUEST_RAM1_SIZE xen_mk_ullong(0xfe00000000)
Signature · 1 line
2.25.1
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Hi Rahul,
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 647
Quoted 9 lines · Rahul Singh
tools/libs/light/libxl_types.idl +1
-0@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool),
I have posted some comments regarding the field in v4. To summarize, AFAICT, this option is meant to be only set by libxl but you still let the toolstack (e.g. xl, libvirt) to set it.
If you still want to expose to the toolstack, then I think the option should be outside of arch_arm. Otherwise, this should be moved in an internal structure (Ian, do you have any suggestion?).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Quoted 17 lines · Julien Grall
Hi Rahul,
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 646
Quoted 9 lines · Rahul Singh
tools/libs/light/libxl_types.idl +1
-0@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool),I have posted some comments regarding the field in v4. To summarize, AFAICT, this option is meant to be only set by libxl but you still let the toolstack (e.g. xl, libvirt) to set it.
Quoted 3 lines
If you still want to expose to the toolstack, then I think the option should be outside of
arch_arm. Otherwise, this should be moved in an internal structure (Ian, do you have any suggestion?).
First let me premise that the patch is much better already and Rahul addessed my request well. However, Julien's point about not wanting to make a potentially breaking ABI change in libxl is a good one. FYI we had a few libvirt breakages due to this kind of changes in the past and I would certainly be happier if we didn't cause another one. And in general, it is better to avoid changes to the libxl ABI if we can.
I think in this case we can: I looked at the patch and b_info.arch_arm.vpci is only used within tools/libs/light/libxl_arm.c. Also, we don't need b_info.arch_arm.vpci if we can access d_config->num_pcidevs given that the check is just based on d_config->num_pcidevs.
So the only issue is how to check on d_config->num_pcidevs in libxl__prepare_dtb. libxl__prepare_dtb takes libxl_domain_build_info as parameter but with container_of we can retrieve libxl_domain_config and from there check on num_pcidevs.
Something like the appended (untested). It doesn't need any libxl struct changes but it requires the introduction of container_of (which is a simple macro). Alternatively, it would be just as simple to change libxl__arch_domain_init_hw_description and libxl__prepare_dtb to take a libxl_domain_config *d_config parameter instead of a libxl_domain_build_info *info parameter.
Ian, any thoughts?
tools/libs/light/libxl_arm.c +3 -4
@@ -102,10 +102,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, }/* Enable VPCI support. */ -if (d_config->num_pcidevs) { +if (d_config->num_pcidevs) config->flags |= XEN_DOMCTL_CDF_vpci; -libxl_defbool_set (&d_config->b_info.arch_arm.vpci, true); - }return 0 ; }
@@ -976,6 +974,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_build_info *info,const libxl_version_info *vers;const struct arch_info *ainfo; +libxl_domain_config *d_config =container_of (info, libxl_domain_config, b_info); vers =libxl_get_version_info (CTX );if (vers ==NULL )return ERROR_FAIL ;
@@ -1076,7 +1075,7 @@ next_resize:if (info->tee ==LIBXL_TEE_TYPE_OPTEE )FDT (make_optee_node (gc, fdt) ); -if (libxl_defbool_val (info->arch_arm.vpci)) +if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) );if (pfdt)
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Hi Stefano,
Quoted 43 lines · Stefano Stabellini
Quoted 17 lines · Julien Grall
Hi Rahul,
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 646
Quoted 9 lines · Rahul Singh
tools/libs/light/libxl_types.idl +1
-0@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool),I have posted some comments regarding the field in v4. To summarize, AFAICT, this option is meant to be only set by libxl but you still let the toolstack (e.g. xl, libvirt) to set it.
Quoted 3 lines
If you still want to expose to the toolstack, then I think the option should be outside of
arch_arm. Otherwise, this should be moved in an internal structure (Ian, do you have any suggestion?).First let me premise that the patch is much better already and Rahul addessed my request well. However, Julien's point about not wanting to make a potentially breaking ABI change in libxl is a good one. FYI we had a few libvirt breakages due to this kind of changes in the past and I would certainly be happier if we didn't cause another one. And in general, it is better to avoid changes to the libxl ABI if we can.
I think in this case we can: I looked at the patch and b_info.arch_arm.vpci is only used within
tools/libs/light/libxl_arm.c. Also, we don't need b_info.arch_arm.vpci if we can accessd_config->num_pcidevsgiven that the check is just based ond_config->num_pcidevs.So the only issue is how to check on
d_config->num_pcidevsinlibxl__prepare_dtb.libxl__prepare_dtbtakeslibxl_domain_build_infoas parameter but withcontainer_ofwe can retrievelibxl_domain_configand from there check onnum_pcidevs.
Quoted 6 lines
Something like the appended (untested). It doesn't need any libxl struct changes but it requires the introduction of
container_of(which is a simple macro). Alternatively, it would be just as simple to changelibxl__arch_domain_init_hw_descriptionandlibxl__prepare_dtbto take alibxl_domain_config*d_configparameter instead of alibxl_domain_build_info*info parameter.
Thanks for sharing the ideas to remove the arch_arm.vpci field.
I am ok with any options, but I feel second option is simple and better to avoid introduction of container_of(). I tested the second option and is working fine. If everyone agree that we don’t need vpci option I will send the patch for review In next version.
Regards,
Rahul
Quoted 37 lines
Ian, any thoughts?
tools/libs/light/libxl_arm.c +3
-4@@ -102,10 +102,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, }/* Enable VPCI support. */ -if (d_config->num_pcidevs) { +if (d_config->num_pcidevs) config->flags |= XEN_DOMCTL_CDF_vpci; -libxl_defbool_set (&d_config->b_info.arch_arm.vpci, true); - }return 0 ; }@@ -976,6 +974,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_build_info *info,const libxl_version_info *vers;const struct arch_info *ainfo; +libxl_domain_config *d_config =container_of (info, libxl_domain_config, b_info); vers =libxl_get_version_info (CTX );if (vers ==NULL )return ERROR_FAIL ;@@ -1076,7 +1075,7 @@ next_resize:if (info->tee ==LIBXL_TEE_TYPE_OPTEE )FDT (make_optee_node (gc, fdt) ); -if (libxl_defbool_val (info->arch_arm.vpci)) +if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) );if (pfdt)
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
In reply to Julien GrallJulien Grall writes ("Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 15 lines · Rahul Singh
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 647
Quoted 9 lines
tools/libs/light/libxl_types.idl +1
-0@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool),I have posted some comments regarding the field in v4. To summarize, AFAICT, this option is meant to be only set by libxl but you still let the toolstack (e.g. xl, libvirt) to set it.
Quoted 3 lines
If you still want to expose to the toolstack, then I think the option should be outside of
arch_arm. Otherwise, this should be moved in an internal structure (Ian, do you have any suggestion?).
If it should be in an internal structure, probably the libxl create context.
But I'm not convinced yet. In particular, if enabling VPCI is necessary on ARM for hotplugged PCI devices[1], then there has to be a way for the admin to say "while this domain may not have any PCI devices right now, I may wish to hotplug some". That's what the "passthrough=" option is for.
See my other mail.
[1] I think this is all true even if PCI hotplug for ARM is not currently implemented.
Ian.
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Hi Ian,
Quoted 18 lines · Ian Jackson
Julien Grall writes ("Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 15 lines · Rahul Singh
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 647
Quoted 9 lines
tools/libs/light/libxl_types.idl +1
-0@@ -644,6 +644,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool),I have posted some comments regarding the field in v4. To summarize, AFAICT, this option is meant to be only set by libxl but you still let the toolstack (e.g. xl, libvirt) to set it.
Quoted 6 lines
Quoted 3 lines
If you still want to expose to the toolstack, then I think the option should be outside of
arch_arm. Otherwise, this should be moved in an internal structure (Ian, do you have any suggestion?).If it should be in an internal structure, probably the libxl create context.
As Stefano suggested in another email that we can remove the vpci option, if we reach to conclusion that we need vpci option I will move it to internal structure.
Quoted 6 lines
But I'm not convinced yet. In particular, if enabling VPCI is necessary on ARM for hotplugged PCI devices[1], then there has to be a way for the admin to say "while this domain may not have any PCI devices right now, I may wish to hotplug some". That's what the "passthrough=" option is for.
Yes I agree with you VPCI is necessary for hot plugged PCI device and once we implement the hotplug in future we will use the passthrough= option to enable VPCI.
Regards,
Rahul
Quoted 7 lines
See my other mail.
[1] I think this is all true even if PCI hotplug for ARM is not currently implemented.
Ian.
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Rahul Singh writes ("Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 3 lines
As Stefano suggested in another email that we can remove the vpci option, if we reach to conclusion that we need vpci option I will move it to internal structure.
...
Quoted 3 lines
Yes I agree with you VPCI is necessary for hot plugged PCI device and once we implement the hotplug in future we will use the passthrough= option to enable VPCI.
So, to summarise, I think the situation is:
* VCPI is necessry for passthrough on ARM, whether coldplug or hotplug. It's part of the way that PCI-PT works on ARM.
* Hotplug is not yet implemented.
* VPCI is not necessary on x86 (evidently, since we don't have it there but we do have passthrough).
So when hotplug is added, vpci will need to be turned on when passthrough=yes is selected. I don't fully understand the other possible values for passthrough= but maybe we can defer the question of whether they apply to ARM ?
I think that means that yes, this should be an internal variable. Probably in libxl__domain_create_state. We don't currently arrange to elide arch-specific state in there, so perhaps it's fine just to invent a member called arm_vpci.
Maybe you could leave a comment somewhere so that if and when PCI PT hotplug is implemented for ARM, the implementor remembers to wire this up.
Ian.
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
Quoted 24 lines · Ian Jackson
Rahul Singh writes ("Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 3 lines
As Stefano suggested in another email that we can remove the vpci option, if we reach to conclusion that we need vpci option I will move it to internal structure.
...
Quoted 3 lines
Yes I agree with you VPCI is necessary for hot plugged PCI device and once we implement the hotplug in future we will use the passthrough= option to enable VPCI.
So, to summarise, I think the situation is:
* VCPI is necessry for passthrough on ARM, whether coldplug or hotplug. It's part of the way that PCI-PT works on ARM.
* Hotplug is not yet implemented.
* VPCI is not necessary on x86 (evidently, since we don't have it there but we do have passthrough).
So when hotplug is added, vpci will need to be turned on when passthrough=yes is selected. I don't fully understand the other possible values for passthrough= but maybe we can defer the question of whether they apply to ARM ?
Quoted 4 lines
I think that means that yes, this should be an internal variable. Probably in
libxl__domain_create_state. We don't currently arrange to elide arch-specific state in there, so perhaps it's fine just to invent a member calledarm_vpci.
Seeing as we might want to also use this on x86, I wonder whether we should allow to specify a backend to use for each passthrough device, ie:
pci = [ '36:00.0,backend=vpci',
'36:01.0,backend=qemu', ... ]
In principle we should support different backends on a per-device basis, albeit if not currently possible.
Iff we have to introduce a new struct member for vPCI it should be shared between all arches, as it's likely x86 will also want to at least have the option to use vPCI for passthrough.
Thanks, Roger.
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
In reply to Ian JacksonHi Ian,
Quoted 26 lines · Ian Jackson
Rahul Singh writes ("Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 3 lines
As Stefano suggested in another email that we can remove the vpci option, if we reach to conclusion that we need vpci option I will move it to internal structure.
...
Quoted 3 lines
Yes I agree with you VPCI is necessary for hot plugged PCI device and once we implement the hotplug in future we will use the passthrough= option to enable VPCI.
So, to summarise, I think the situation is:
* VCPI is necessry for passthrough on ARM, whether coldplug or hotplug. It's part of the way that PCI-PT works on ARM.
* Hotplug is not yet implemented.
* VPCI is not necessary on x86 (evidently, since we don't have it there but we do have passthrough).
So when hotplug is added, vpci will need to be turned on when passthrough=yes is selected. I don't fully understand the other possible values for passthrough= but maybe we can defer the question of whether they apply to ARM ?
Quoted 8 lines
I think that means that yes, this should be an internal variable. Probably in
libxl__domain_create_state. We don't currently arrange to elide arch-specific state in there, so perhaps it's fine just to invent a member calledarm_vpci.Maybe you could leave a comment somewhere so that if and when PCI PT hotplug is implemented for ARM, the implementor remembers to wire this up.
Sorry for missing this on the v6 serie.
Now you suggest to add a new field arm_vpci in libxl__domain_create_state.
Once we have done that I will need to access this structure to know if I need to add the DT part and somehow to give it a value depending something which for now would the number of pcidevs as there will be no user parameter anymore.
I had quite an understanding of the solution using libxl_domain_config and changing The arguments of libxl__arch_domain_init_hw_description and libxl__prepare_dtb Suggested by Stefano but I am a bit lost in this solution.
The following might be a stupid question but I did not dig a lot in libxl so:
If we add a parameter in the state structure how should we access it ?
Thank
Bertrand
Quoted 2 lines
Ian.
Re: [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl
In reply to Rahul SinghRahul Singh writes ("[PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl"):
Quoted 8 lines
libxl will create an emulated PCI device tree node in the device tree to enable the guest OS to discover the virtual PCI during guest boot. Emulated PCI device tree node will only be created when there is any device assigned to guest.
A new area has been reserved in the arm guest physical map at which the VPCI bus is declared in the device tree (reg and ranges parameters of the node).
I think this series is targeted for 4.16. Stefano drew this patch to my attention. I have read the thread on this patch and it is not clear to me that it has converged. Code freeze is imminent.
Is there some way I can help here ?
Ian.
PATCH v5 11/11 xen/arm: Add linux,pci-domain property for hwdom if not available.
In reply to Rahul SinghIf the property is not present in the device tree node for host bridge, XEN while creating the dtb for hwdom will create this property and assigns the already allocated segment to the host bridge
so that XEN and linux will have the same segment for the host bridges.
---
Change in v5: none
Change in v4:
- Added Reviewed-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3:
- Use is_pci_passthrough_enabled()
Change in v2:
- Add linux,pci-domain only when pci-passthrough command line option is enabeld
---
--- xen/arch/arm/domain_build.c | 16 ++++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 21 +++++++++++++++++++++ xen/include/asm-arm/pci.h | 9 +++++++++ 3 files changed, 46 insertions(+)
xen/arch/arm/domain_build.c +16 -0
@@ -747,6 +747,22 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,return res; } +if (is_pci_passthrough_enabled () &&dt_device_type_is_equal (node,"pci" ) ) + { +if ( !dt_find_property (node,"linux,pci-domain" ,NULL ) ) + { +uint16_t segment; + + res =pci_get_host_bridge_segment (node, &segment); +if ( res <0 ) +return res; + + res =fdt_property_cell (kinfo->fdt,"linux,pci-domain" , segment); +if ( res ) +return res; + } + } +/* * Override the property "status" to disable the device when it's * marked for passthrough.
xen/arch/arm/pci/pci-host-common.c +21 -0
@@ -255,6 +255,27 @@ struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus)return NULL ; } + +/* +* This function will lookup an hostbridge based on config space address. +*/ +int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment) +{ +struct pci_host_bridge *bridge; + +list_for_each_entry ( bridge, &pci_host_bridges, node ) + { +if ( bridge->dt_node != node ) +continue ; + + *segment = bridge->segment; +return 0 ; + } + +return -EINVAL ; +} +/* * Local variables: * mode: C
xen/include/asm-arm/pci.h +9 -0
@@ -90,6 +90,8 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,void __iomem *pci_ecam_map_bus (struct pci_host_bridge *bridge,pci_sbdf_t sbdf,uint32_t where);struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); +int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment); static always_inline bool is_pci_passthrough_enabled(void) {
@@ -104,5 +106,12 @@ static always_inline bool is_pci_passthrough_enabled(void)return false; } +static inline int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment) +{ +ASSERT_UNREACHABLE (); +return -EINVAL ; +} +#endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */
Signature · 1 line
2.25.1
Re: [PATCH v5 11/11] xen/arm: Add linux,pci-domain property for hwdom if not available.
Quoted 8 lines · Rahul Singh
If the property is not present in the device tree node for host bridge, XEN while creating the dtb for hwdom will create this property and assigns the already allocated segment to the host bridge
so that XEN and linux will have the same segment for the host bridges.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>
I committed this patch
Quoted 104 lines
---
Change in v5: none
Change in v4:
- Added Reviewed-by: Stefano Stabellini <[email protected]>
- Added Reviewed-by: Bertrand Marquis <[email protected]> Change in v3:
- Useis_pci_passthrough_enabled()
Change in v2:
- Add linux,pci-domain only when pci-passthrough command line option is enabeld
------ xen/arch/arm/domain_build.c | 16 ++++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 21 +++++++++++++++++++++ xen/include/asm-arm/pci.h | 9 +++++++++ 3 files changed, 46 insertions(+)xen/arch/arm/domain_build.c +16
-0@@ -747,6 +747,22 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo,return res; } +if (is_pci_passthrough_enabled () &&dt_device_type_is_equal (node,"pci" ) ) + { +if ( !dt_find_property (node,"linux,pci-domain" ,NULL ) ) + { +uint16_t segment; + + res =pci_get_host_bridge_segment (node, &segment); +if ( res <0 ) +return res; + + res =fdt_property_cell (kinfo->fdt,"linux,pci-domain" , segment); +if ( res ) +return res; + } + } +/* * Override the property "status" to disable the device when it's * marked for passthrough. xen/arch/arm/pci/pci-host-common.c +21
-0@@ -255,6 +255,27 @@ struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus)return NULL ; } + +/* +* This function will lookup an hostbridge based on config space address. +*/ +int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment) +{ +struct pci_host_bridge *bridge; + +list_for_each_entry ( bridge, &pci_host_bridges, node ) + { +if ( bridge->dt_node != node ) +continue ; + + *segment = bridge->segment; +return 0 ; + } + +return -EINVAL ; +} +/* * Local variables: * mode: C xen/include/asm-arm/pci.h +9
-0@@ -90,6 +90,8 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,void __iomem *pci_ecam_map_bus (struct pci_host_bridge *bridge,pci_sbdf_t sbdf,uint32_t where);struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); +int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment); static always_inline bool is_pci_passthrough_enabled(void) {@@ -104,5 +106,12 @@ static always_inline bool is_pci_passthrough_enabled(void)return false; } +static inline int pci_get_host_bridge_segment (const struct dt_device_node *node, +uint16_t *segment) +{ +ASSERT_UNREACHABLE (); +return -EINVAL ; +} +#endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */ Signature · 1 line
2.25.1
I committed patches 2-7.
I made two small adjustments on commit:
- patch #3: bool_t/bool
- patch #7: drop _XEN_DOMCTL_CDF_vpci
Cheers,
Stefano
Quoted 120 lines · Rahul Singh
Hello All,
The purpose of this patch series is to add PCI passthrough support to Xen on Arm. PCI passthrough support on ARM is the collaboration work between EPAM and ARM. ARM submitted the partial RFC [1][2] last year to get early feedback. We tried to fix all the comments and added more features to this patch series.
Working POC with all the features can be found at [3]. Working POC is tested on x86 so that there will be no regression on x86. Design presentation can be found at [4]
PCI passthrough support is divided into different patches. This patch series includes following features:
Preparatory work to implement the PCI passthrough support for the ARM:
- Refactor MSI code.
- Fixed compilation error whenHAS_PCIenabled for ARM.Discovering PCI Host Bridge in XEN:
- PCI init to initialize the PCI driver.
- PCI host bridge discovery in XEN and map the PCI ECAM configuration space to the XEN memory.
- PCI access functions.Discovering PCI devices:
- To support the PCI passthrough, XEN should be aware of the PCI devices.
- Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then communicate to the XEN via a hypercall to add the PCI devices in XEN.Enable the existing x86 virtual PCI support for ARM:
- Add VPCI trap handler for each of the PCI device added for config space access.
- Register the trap handler in XEN for each of the host bridge PCI ECAM config space access.Emulated PCI device tree node in libxl:
- Create a virtual PCI device tree node in libxl to enable the guest OS to discover the virtual PCI during guest boot.This patch series does not inlcude the following features. Following features will be send for review in the next version of the patch series once initial patch series merged.
- VPCI support for DOMU guests (Non-identity mappings guest view of the BARs)
- Virtual bus topology implementation
- IOMMU related changes (generic, SMMUv2, SMMUv3)
- MSI support for DOMU guests.
- Virual ITS support for DOMU guests[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg01184.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-07/threads.html#01184
[3] https://gitlab.com/rahsingh/xen-integration/-/tree/arm_pci_v4_integrate
[4] https://static.sched.com/hosted_files/xen2021/e4/PCI_Device_Passthrough_On_Arm.pdfOleksandr Andrushchenko (1):
xen/arm: Add support for Xilinx ZynqMP PCI host controllerRahul Singh (10):
xen/arm:xc_domain_ioport_permission(..)not supported on ARM. xen/arm: AddPHYSDEVOP_pci_device_(*add/remove)support for ARM xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" xen/arm: PCI host bridge discovery within XEN on ARM xen/arm: Implement pci access functions
xen/domctl: IntroduceXEN_DOMCTL_CDF_vpciflag
xen/arm: Enable the existing x86 virtual PCI support for ARM. xen/arm: Transitional change to buildHAS_VPCIon ARM. arm/libxl: Emulated PCI device tree node in libxl xen/arm: Add linux,pci-domain property for hwdom if not available.docs/misc/xen-command-line.pandoc | 7 + tools/include/libxl.h | 6 + tools/libs/ctrl/xc_domain.c | 9 + tools/libs/light/libxl_arm.c | 111 +++++++++++ tools/libs/light/libxl_types.idl | 1 + tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 8 +- xen/arch/arm/domain_build.c | 19 ++ xen/arch/arm/pci/Makefile | 5 + xen/arch/arm/pci/ecam.c | 61 ++++++ xen/arch/arm/pci/pci-access.c | 140 ++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 287 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 48 +++++ xen/arch/arm/pci/pci-host-zynqmp.c | 65 +++++++ xen/arch/arm/pci/pci.c | 12 ++ xen/arch/arm/physdev.c | 6 +- xen/arch/arm/vpci.c | 102 ++++++++++ xen/arch/arm/vpci.h | 36 ++++ xen/arch/x86/domain.c | 6 + xen/arch/x86/physdev.c | 52 +---- xen/arch/x86/x86_64/physdev.c | 2 +- xen/common/domain.c | 2 +- xen/drivers/passthrough/pci.c | 18 ++ xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 86 +++++++++ xen/drivers/vpci/Makefile | 3 +- xen/drivers/vpci/header.c | 2 + xen/include/asm-arm/domain.h | 7 +- xen/include/asm-arm/pci.h | 85 ++++++++ xen/include/asm-x86/pci.h | 8 +- xen/include/public/arch-arm.h | 21 +- xen/include/public/domctl.h | 4 +- xen/include/xen/hypercall.h | 4 + xen/include/xen/pci.h | 2 + 36 files changed, 1168 insertions(+), 61 deletions(-) create mode 100644 xen/arch/arm/pci/ecam.c create mode 100644 xen/arch/arm/pci/pci-access.c create mode 100644 xen/arch/arm/pci/pci-host-common.c create mode 100644 xen/arch/arm/pci/pci-host-generic.c create mode 100644 xen/arch/arm/pci/pci-host-zynqmp.c create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.h create mode 100644 xen/drivers/pci/physdev.cSignature · 1 line
2.25.1
Hi Stefano,
Quoted 7 lines · Stefano Stabellini
I committed patches 2-7.
I made two small adjustments on commit:
- patch #3: bool_t/bool
- patch #7: drop_XEN_DOMCTL_CDF_vpci
Thank you very much. I will be on leave from tomorrow. Someone from my team will take care of the rest of the patch and reply to the comments.
Regards,
Rahul
Quoted 127 lines
Cheers,
Stefano
Quoted 120 lines · Rahul Singh
Hello All,
The purpose of this patch series is to add PCI passthrough support to Xen on Arm. PCI passthrough support on ARM is the collaboration work between EPAM and ARM. ARM submitted the partial RFC [1][2] last year to get early feedback. We tried to fix all the comments and added more features to this patch series.
Working POC with all the features can be found at [3]. Working POC is tested on x86 so that there will be no regression on x86. Design presentation can be found at [4]
PCI passthrough support is divided into different patches. This patch series includes following features:
Preparatory work to implement the PCI passthrough support for the ARM:
- Refactor MSI code.
- Fixed compilation error whenHAS_PCIenabled for ARM.Discovering PCI Host Bridge in XEN:
- PCI init to initialize the PCI driver.
- PCI host bridge discovery in XEN and map the PCI ECAM configuration space to the XEN memory.
- PCI access functions.Discovering PCI devices:
- To support the PCI passthrough, XEN should be aware of the PCI devices.
- Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then communicate to the XEN via a hypercall to add the PCI devices in XEN.Enable the existing x86 virtual PCI support for ARM:
- Add VPCI trap handler for each of the PCI device added for config space access.
- Register the trap handler in XEN for each of the host bridge PCI ECAM config space access.Emulated PCI device tree node in libxl:
- Create a virtual PCI device tree node in libxl to enable the guest OS to discover the virtual PCI during guest boot.This patch series does not inlcude the following features. Following features will be send for review in the next version of the patch series once initial patch series merged.
- VPCI support for DOMU guests (Non-identity mappings guest view of the BARs)
- Virtual bus topology implementation
- IOMMU related changes (generic, SMMUv2, SMMUv3)
- MSI support for DOMU guests.
- Virual ITS support for DOMU guests[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg01184.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-07/threads.html#01184
[3] https://gitlab.com/rahsingh/xen-integration/-/tree/arm_pci_v4_integrate
[4] https://static.sched.com/hosted_files/xen2021/e4/PCI_Device_Passthrough_On_Arm.pdfOleksandr Andrushchenko (1):
xen/arm: Add support for Xilinx ZynqMP PCI host controllerRahul Singh (10):
xen/arm:xc_domain_ioport_permission(..)not supported on ARM. xen/arm: AddPHYSDEVOP_pci_device_(*add/remove)support for ARM xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" xen/arm: PCI host bridge discovery within XEN on ARM xen/arm: Implement pci access functions
xen/domctl: IntroduceXEN_DOMCTL_CDF_vpciflag
xen/arm: Enable the existing x86 virtual PCI support for ARM. xen/arm: Transitional change to buildHAS_VPCIon ARM. arm/libxl: Emulated PCI device tree node in libxl xen/arm: Add linux,pci-domain property for hwdom if not available.docs/misc/xen-command-line.pandoc | 7 + tools/include/libxl.h | 6 + tools/libs/ctrl/xc_domain.c | 9 + tools/libs/light/libxl_arm.c | 111 +++++++++++ tools/libs/light/libxl_types.idl | 1 + tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 8 +- xen/arch/arm/domain_build.c | 19 ++ xen/arch/arm/pci/Makefile | 5 + xen/arch/arm/pci/ecam.c | 61 ++++++ xen/arch/arm/pci/pci-access.c | 140 ++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 287 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 48 +++++ xen/arch/arm/pci/pci-host-zynqmp.c | 65 +++++++ xen/arch/arm/pci/pci.c | 12 ++ xen/arch/arm/physdev.c | 6 +- xen/arch/arm/vpci.c | 102 ++++++++++ xen/arch/arm/vpci.h | 36 ++++ xen/arch/x86/domain.c | 6 + xen/arch/x86/physdev.c | 52 +---- xen/arch/x86/x86_64/physdev.c | 2 +- xen/common/domain.c | 2 +- xen/drivers/passthrough/pci.c | 18 ++ xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 86 +++++++++ xen/drivers/vpci/Makefile | 3 +- xen/drivers/vpci/header.c | 2 + xen/include/asm-arm/domain.h | 7 +- xen/include/asm-arm/pci.h | 85 ++++++++ xen/include/asm-x86/pci.h | 8 +- xen/include/public/arch-arm.h | 21 +- xen/include/public/domctl.h | 4 +- xen/include/xen/hypercall.h | 4 + xen/include/xen/pci.h | 2 + 36 files changed, 1168 insertions(+), 61 deletions(-)create mode 100644
xen/arch/arm/pci/ecam.ccreate mode 100644xen/arch/arm/pci/pci-access.ccreate mode 100644xen/arch/arm/pci/pci-host-common.ccreate mode 100644xen/arch/arm/pci/pci-host-generic.ccreate mode 100644xen/arch/arm/pci/pci-host-zynqmp.ccreate mode 100644xen/arch/arm/vpci.c
create mode 100644xen/arch/arm/vpci.h
create mode 100644xen/drivers/pci/physdev.cSignature · 1 line
2.25.1
v6 cover PCI devices passthrough on Arm
Hello All,
This serie is a follow up on Rahul serie where we included various fixes required after review on the mailing list and a new patch to move some of the x86 ecam related code to the common vpci code.
Most of the patches of the original serie have been merged and this serie includes only 2 of the original patches reworked and 1 new patch:
Move some ECAM related functions from x86 to generic vpci implementation:
- move vcpi mmcfg_{read/write} and vpci_access_allowed to common vpci.c.
- use ecam instead of mmcfg in common code.
Enable the existing x86 virtual PCI support for ARM:
- Add VPCI trap handler for each of the PCI device added for config space access.
- Register the trap handler in XEN for each of the host bridge PCI ECAM config space access.
Emulated PCI device tree node in libxl:
- Create a virtual PCI device tree node in libxl to enable the guest OS to discover the virtual PCI during guest boot.
The patch modifying xc_domain_ioport_permission has been removed from the serie.
Bertrand Marquis (1):
xen/vpci: Move ecam access functions to common code
Rahul Singh (2):
xen/arm: Enable the existing x86 virtual PCI support for ARM. arm/libxl: Emulated PCI device tree node in libxl
tools/libs/light/libxl_arm.c | 105 +++++++++++++++++++++++++++++++ tools/libs/light/libxl_types.idl | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 4 ++ xen/arch/arm/vpci.c | 74 ++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++ xen/arch/x86/hvm/io.c | 50 +++------------ xen/drivers/passthrough/pci.c | 18 +++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 60 ++++++++++++++++++ xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 17 +++++ xen/include/xen/pci.h | 3 + xen/include/xen/vpci.h | 10 +++ 15 files changed, 338 insertions(+), 47 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.h
Signature · 1 line
2.25.1
PATCH v6 1/3 xen/vpci: Move ecam access functions to common code
PCI standard is using ECAM and not MCFG which is coming from ACPI[1]. Use ECAM/ecam instead of MCFG in common code and in new functions added in common vpci code by this patch.
Rename vpci_access_allowed to vpci_ecam_access_allowed and move it from arch/x86/hvm/io.c to drivers/vpci/vpci.c.
Create vpci_ecam_mmio_{read,write} in drivers/vpci/vpci.c that contains the common code to perform these operations, changed vpci_mmcfg_{read,write} accordingly to make use of these functions.
The vpci_ecam_mmio_{read,write} functions are returning 0 on error and 1 on success. As the x86 code was previously always returning X86EMUL_OKAY the return code is ignored. A comment has been added in the code to show that this is intentional.
Those functions will be used in a following patch inside by arm vpci implementation.
Rename MMCFG_SBDF to ECAM_SBDF.
Not functional change intended with this patch.
[1] https://wiki.osdev.org/PCI_Express
---
Changes in v6: Patch added
--- xen/arch/x86/hvm/io.c | 50 +++++--------------------------- xen/drivers/vpci/vpci.c | 60 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pci.h | 2 +- xen/include/xen/vpci.h | 10 +++++++ 4 files changed, 78 insertions(+), 44 deletions(-)
xen/arch/x86/hvm/io.c +7 -43
@@ -260,20 +260,6 @@ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr,return CF8_ADDR_LO (cf8) | (addr &3 ); } -/* Do some sanity checks. */ -static bool vpci_access_allowed (unsigned int reg,unsigned int len) -{ -/* Check access size. */ -if ( len !=1 && len !=2 && len !=4 && len !=8 ) -return false; - -/* Check that access is size aligned. */ -if ( (reg & (len -1 )) ) -return false; - -return true; -} -/* vPCI config space IO ports handlers (0xcf8/0xcfc). */ static bool vpci_portio_accept (const struct hvm_io_handler *handler,const ioreq_t *p)
@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);
@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);
@@ -394,7 +380,7 @@ static unsigned int vpci_mmcfg_decode_addr(const struct hvm_mmcfg *mmcfg, paddr_t addr, pci_sbdf_t *sbdf) { addr -= mmcfg->addr; - sbdf->bdf =MMCFG_BDF (addr); + sbdf->bdf =ECAM_BDF (addr); sbdf->bus += mmcfg->start_bus; sbdf->seg = mmcfg->segment;
@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses -* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);return X86EMUL_OKAY ; }
@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);return X86EMUL_OKAY ; }
xen/drivers/vpci/vpci.c +60 -0
66 lines not on this page · raw message
xen/include/asm-x86/pci.h +1 -1
@@ -6,7 +6,7 @@#define CF8_ADDR_HI (cf8) ( ((cf8) & 0x0f000000) >> 16)#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) -#define MMCFG_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12)#define IS_SNB_GFX (id) (id == 0x01068086 || id == 0x01168086 \ || id == 0x01268086 || id == 0x01028086 \
xen/include/xen/vpci.h +10 -0
@@ -208,6 +208,16 @@ static inline unsigned int vmsix_entry_nr(const struct vpci_msix *msix, {return entry - msix->entries; } + +/* ECAM mmio read/write helpers */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len); + +int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data); + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data); +#endif /* __XEN__ */ #else /* !CONFIG_HAS_VPCI */
Signature · 1 line
2.25.1
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Quoted 10 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);
xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 8 lines
xen/arch/x86/hvm/io.c +1
-1@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);
Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;
While I assume this earlier behavior is the reason for ...
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for vpci_ecam_mmio_read() to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).
xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 13 lines
xen/arch/x86/hvm/io.c +2
-7@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);
Here ignoring is fine imo, but if you feel it is important to comment on this, then I think you need to prefer "why" over "what".
Quoted 8 lines
xen/drivers/vpci/vpci.c +2
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); } +/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len)
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 492
Quoted 10 lines
xen/drivers/vpci/vpci.c +10
-0+{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code. +*/ +if ( len !=1 && len !=2 && len !=4 && len !=8 ) +return false;
I'm not convinced talking about Arm specifically here is warranted, unless there's something there that's clearly different from all other architectures. Otherwise the comment should imo be written in more general terms.
Quoted 29 lines
xen/drivers/vpci/vpci.c +29
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 10 lines
xen/drivers/vpci/vpci.c +10
-0+* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 ) + *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}
Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
Also both of these functions will silently misbehave on 32-bit due to the use of unsigned long in the parameter types. I think you want e.g. CONFIG_64BIT conditionals here as well as in vpci_access_allowed() (omitting the questionable "ecam" part of the name) to reject len == 8 there in that case.
Finally, to me, having both "ecam" and "mmio" in the names feels redundant - the PCI spec doesn't mention any non-MMIO mechanism there afaics.
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Hi Jan,
Quoted 16 lines · Jan Beulich
Quoted 13 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf);
Quoted 8 lines
xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 5 lines
xen/arch/x86/hvm/io.c +1
-1-if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
The function was global before.
Quoted 10 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;While I assume this earlier behavior is the reason for ...
Yes :-)
Quoted 19 lines
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);
Quoted 6 lines
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for
vpci_ecam_mmio_read()to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).
I am not sure in the first place why this is actually ignored and just returning a -1 value.
If an access is not right, an exception should be generated to the Guest instead.
When we do that on arm the function is returning an error to the upper layer in that case, that’s why I did keep a generic function informing the caller.
So I think it is right for the function to return an error if the access is not allowed but I agree the comment on x86 could get a better justification. @Roger: could you help finding one here as I do not quite understand why it is ok to ignore this case ?
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/io.c +0
-0@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock);
Quoted 12 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 9 lines
xen/arch/x86/hvm/io.c +2
-7-if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);Here ignoring is fine imo, but if you feel it is important to comment on this, then I think you need to prefer "why" over "what".
Agree I would just need some help on the why.
Now there was no comment before to explain why so I could also remove the comment altogether.
Quoted 16 lines
Quoted 16 lines
xen/drivers/vpci/vpci.c +9
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); } +/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len) +{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code.
Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 492
Quoted 3 lines
xen/drivers/vpci/vpci.c +3
-0+*/ +if ( len !=1 && len !=2 && len !=4 && len !=8 ) +return false;I'm not convinced talking about Arm specifically here is warranted, unless there's something there that's clearly different from all other architectures. Otherwise the comment should imo be written in more general terms.
Other architectures might allow this case. So this is specific to Arm.
Quoted 36 lines
Quoted 36 lines
xen/drivers/vpci/vpci.c +35
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 )
Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 4 lines
xen/drivers/vpci/vpci.c +4
-0+ *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
This is what the mmio handlers should return to say that an access was ok or not so the function stick to this standard.
Quoted 6 lines
Also both of these functions will silently misbehave on 32-bit due to the use of unsigned long in the parameter types. I think you want e.g.
CONFIG_64BITconditionals here as well as invpci_access_allowed()(omitting the questionable "ecam" part of the name) to reject len == 8 there in that case.
Right using CONFIG_64BIT is a good idea here in fact. I can do that in the next version.
Quoted 4 lines
Finally, to me, having both "ecam" and "mmio" in the names feels redundant - the PCI spec doesn't mention any non-MMIO mechanism there afaics.
I was thinking the mmio here stands more for “mmio handler” as to function handling emulation through mmio access.
I have no objection to remove the mmio part though.
Regards
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Quoted 19 lines · Bertrand Marquis
Quoted 19 lines · Jan Beulich
Quoted 17 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +2
-2@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;
Quoted 6 lines
Quoted 4 lines
xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 1 line
xen/arch/x86/hvm/io.c +0
-0vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
The function was global before.
I'm not objecting to the function being global, but to the "ecam" in its name.
Quoted 38 lines
Quoted 9 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;While I assume this earlier behavior is the reason for ...
Yes :-)
Quoted 19 lines
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);Quoted 6 lines
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for
vpci_ecam_mmio_read()to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).
Quoted 4 lines
I am not sure in the first place why this is actually ignored and just returning a -1 value.
If an access is not right, an exception should be generated to the Guest instead.
No. That's also not what happens on bare metal, at least not on x86. Faults cannot be raised for reasons outside of the CPU; such errors (if these are errors in the first place) need to be dealt with differently. Signaling an error on the PCI bus would be possible, but would leave open how that's actually to be dealt with. Instead bad reads return all ones, while bad writes simply get dropped.
Quoted 3 lines
When we do that on arm the function is returning an error to the upper layer in that case, that’s why I did keep a generic function informing the caller.
While you're the Arm expert, with the above in mind I wonder what the actual action in that case ought to be there. Would you explain to me how, say, a misaligned 2-byte read that the CPU permits but the PCI subsystem doesn't like would be dealt with by bare metal?
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/io.c +0
-0@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock);Quoted 12 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 9 lines
xen/arch/x86/hvm/io.c +2
-7-if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);Here ignoring is fine imo, but if you feel it is important to comment on this, then I think you need to prefer "why" over "what".
Quoted 3 lines
Agree I would just need some help on the why.
Now there was no comment before to explain why so I could also remove the comment altogether.
The latter would be my preference.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
xen/drivers/vpci/vpci.c +9
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); } +/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len) +{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code. Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 492
Quoted 3 lines
xen/drivers/vpci/vpci.c +3
-0+*/ +if ( len !=1 && len !=2 && len !=4 && len !=8 ) +return false;I'm not convinced talking about Arm specifically here is warranted, unless there's something there that's clearly different from all other architectures. Otherwise the comment should imo be written in more general terms.
Quoted 1 line
Other architectures might allow this case. So this is specific to Arm.
If it really is, I consider it wrong to live in common code. If per-arch tweaking is necessary, and if earlier handling of the intercepted access doesn't already exclude "bad" cases, then a per-arch hook would imo be the way to go here. Given the size of the function I would then wonder why it doesn't remain per- arch in the first place.
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
xen/drivers/vpci/vpci.c +35
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 )Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 4 lines
xen/drivers/vpci/vpci.c +4
-0+ *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
Quoted 2 lines
This is what the mmio handlers should return to say that an access was ok or not so the function stick to this standard.
Sticking to this would be okay if the functions here needed their address taken, such that they can be installed as hooks for a more general framework to invoke. The functions, however, only get called directly. Hence there's no reason to mirror what is in need of cleaning up elsewhere. I'm sure you're aware there we're in the (slow going) process of improving which types get used where. While the functions you refer to may not have undergone such cleanup yet, we generally expect new code to conform to the new model.
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Hi Jan,
Quoted 27 lines · Jan Beulich
Quoted 24 lines · Bertrand Marquis
Quoted 23 lines · Jan Beulich
Quoted 10 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 8 lines
xen/arch/x86/hvm/io.c +1
-1@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
Quoted 4 lines
Quoted 1 line
The function was global before.
I'm not objecting to the function being global, but to the "ecam" in its name.
Adding ecam in the name was a request from Roger.
This is just a consequence of this.
One suggestion here could be to turn vpci_ecam_access_allowed into vpci_access_allowed and maybe put this into vpci.h as a static inline ?
Quoted 44 lines
Quoted 39 lines
Quoted 10 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;While I assume this earlier behavior is the reason for ...
Yes :-)
Quoted 19 lines
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);Quoted 6 lines
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for
vpci_ecam_mmio_read()to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).Quoted 4 lines
I am not sure in the first place why this is actually ignored and just returning a -1 value.
If an access is not right, an exception should be generated to the Guest instead.
Quoted 6 lines
No. That's also not what happens on bare metal, at least not on x86. Faults cannot be raised for reasons outside of the CPU; such errors (if these are errors in the first place) need to be dealt with differently. Signaling an error on the PCI bus would be possible, but would leave open how that's actually to be dealt with. Instead bad reads return all ones, while bad writes simply get dropped.
So that behaviour is kept here on x86 and I think as the function is generic it is right for it to return an error here. It is up to the caller to ignore it or not.
To make this more generic I could return 0 on success and -EACCESS, the caller would then handle it as he wants.
Quoted 9 lines
Quoted 4 lines
When we do that on arm the function is returning an error to the upper layer in that case, that’s why I did keep a generic function informing the caller.
While you're the Arm expert, with the above in mind I wonder what the actual action in that case ought to be there. Would you explain to me how, say, a misaligned 2-byte read that the CPU permits but the PCI subsystem doesn't like would be dealt with by bare metal?
The hardware will probably return a BUS error as the access did not work. But the CPU might just prevent unaligned mmio access on the first place.
@julien: Maybe you know that one ? Otherwise I can dig to make sure I answer that right.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
xen/arch/x86/hvm/io.c +0
-0@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock);xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-7-if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);Here ignoring is fine imo, but if you feel it is important to comment on this, then I think you need to prefer "why" over "what".
Quoted 5 lines
Quoted 3 lines
Agree I would just need some help on the why.
Now there was no comment before to explain why so I could also remove the comment altogether.The latter would be my preference.
Ok I will do that.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 9 lines
xen/drivers/vpci/vpci.c +2
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); } +/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len)xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 492
Quoted 10 lines
xen/drivers/vpci/vpci.c +10
-0+{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code. +*/ +if ( len !=1 && len !=2 && len !=4 && len !=8 ) +return false;I'm not convinced talking about Arm specifically here is warranted, unless there's something there that's clearly different from all other architectures. Otherwise the comment should imo be written in more general terms.
Quoted 8 lines
Quoted 1 line
Other architectures might allow this case. So this is specific to Arm.
If it really is, I consider it wrong to live in common code. If per-arch tweaking is necessary, and if earlier handling of the intercepted access doesn't already exclude "bad" cases, then a per-arch hook would imo be the way to go here. Given the size of the function I would then wonder why it doesn't remain per- arch in the first place.
To have this in common code was a request from Roger and as The code is the same I think that is ok.
I suggested before to turn this into a static inline and remove “ecam” from the name.
For the comment this was a request from Julien in the first place but before this was moved to the common code.
I can remove the comment from the common code and put it in the Arm vpci code instead.
@Julien: would that be acceptable for you now ?
Otherwise I can remove it all together.
Quoted 48 lines
Quoted 45 lines
Quoted 36 lines
Quoted 36 lines
xen/drivers/vpci/vpci.c +35
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 )Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 4 lines
xen/drivers/vpci/vpci.c +4
-0+ *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
Quoted 2 lines
This is what the mmio handlers should return to say that an access was ok or not so the function stick to this standard.
Quoted 9 lines
Sticking to this would be okay if the functions here needed their address taken, such that they can be installed as hooks for a more general framework to invoke. The functions, however, only get called directly. Hence there's no reason to mirror what is in need of cleaning up elsewhere. I'm sure you're aware there we're in the (slow going) process of improving which types get used where. While the functions you refer to may not have undergone such cleanup yet, we generally expect new code to conform to the new model.
I am ok to rename those to vpci_ecam_{read/write}. Is it what you want ?
Regards
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Quoted 26 lines · Bertrand Marquis
Quoted 26 lines · Jan Beulich
Quoted 24 lines · Bertrand Marquis
Quoted 23 lines · Jan Beulich
Quoted 10 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 8 lines
xen/arch/x86/hvm/io.c +1
-1@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
The function was global before.
I'm not objecting to the function being global, but to the "ecam" in its name.
Adding ecam in the name was a request from Roger.
This is just a consequence of this.
Roger - did you have in mind the uses here when asking for the addition of "ecam"?
Quoted 2 lines
One suggestion here could be to turn
vpci_ecam_access_allowedintovpci_access_allowed
That's what I'm asking for.
Quoted 1 line
and maybe put this into
vpci.has a static inline ?
I'm not overly fussed here.
Quoted 50 lines
Quoted 43 lines
Quoted 38 lines
Quoted 9 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;While I assume this earlier behavior is the reason for ...
Yes :-)
Quoted 19 lines
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);Quoted 6 lines
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for
vpci_ecam_mmio_read()to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).Quoted 4 lines
I am not sure in the first place why this is actually ignored and just returning a -1 value.
If an access is not right, an exception should be generated to the Guest instead.Quoted 6 lines
No. That's also not what happens on bare metal, at least not on x86. Faults cannot be raised for reasons outside of the CPU; such errors (if these are errors in the first place) need to be dealt with differently. Signaling an error on the PCI bus would be possible, but would leave open how that's actually to be dealt with. Instead bad reads return all ones, while bad writes simply get dropped.
Quoted 5 lines
So that behaviour is kept here on x86 and I think as the function is generic it is right for it to return an error here. It is up to the caller to ignore it or not.
To make this more generic I could return 0 on success and-EACCESS, the caller would then handle it as he wants.
I think boolean is sufficient here, but I wouldn't object to errno- style return values. All I do object to is int when boolean is meant.
Quoted 57 lines
Quoted 47 lines
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
xen/drivers/vpci/vpci.c +35
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 )Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 4 lines
xen/drivers/vpci/vpci.c +4
-0+ *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
Quoted 2 lines
This is what the mmio handlers should return to say that an access was ok or not so the function stick to this standard.
Quoted 9 lines
Sticking to this would be okay if the functions here needed their address taken, such that they can be installed as hooks for a more general framework to invoke. The functions, however, only get called directly. Hence there's no reason to mirror what is in need of cleaning up elsewhere. I'm sure you're aware there we're in the (slow going) process of improving which types get used where. While the functions you refer to may not have undergone such cleanup yet, we generally expect new code to conform to the new model.
Quoted 2 lines
I am ok to rename those to vpci_ecam_{read/write}. Is it what you want ?
Yes, that's what I've been asking for, and I just saw Roger requesting the same. (I'm a little puzzled about the context though, as you reply looks disconnected here.)
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Hi Jan,
Quoted 37 lines · Jan Beulich
Quoted 26 lines · Bertrand Marquis
Quoted 26 lines · Jan Beulich
Quoted 24 lines · Bertrand Marquis
Quoted 23 lines · Jan Beulich
Quoted 10 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 8 lines
xen/arch/x86/hvm/io.c +1
-1@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
The function was global before.
I'm not objecting to the function being global, but to the "ecam" in its name.
Adding ecam in the name was a request from Roger.
This is just a consequence of this.
Quoted 7 lines
Roger - did you have in mind the uses here when asking for the addition of "ecam"?
Quoted 2 lines
One suggestion here could be to turn
vpci_ecam_access_allowedintovpci_access_allowedThat's what I'm asking for.
Will do
Quoted 4 lines
Quoted 2 lines
and maybe put this into
vpci.has a static inline ?I'm not overly fussed here.
Was just a suggestion, I am ok to just rename it and keep it where it is.
Quoted 51 lines
Quoted 51 lines
Quoted 50 lines
Quoted 39 lines
Quoted 10 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 439
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-3@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ;While I assume this earlier behavior is the reason for ...
Yes :-)
Quoted 19 lines
Quoted 8 lines
xen/arch/x86/hvm/io.c +0
-7-/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);Quoted 6 lines
... the commented-upon ignoring of the return value, I don't think that's a good way to deal with things anymore. Instead I think *data should be written to ~0 upon failure, unless it is intended for
vpci_ecam_mmio_read()to take care of that case (in which case I'm not sure I would see why it needs to return an error indicator in the first place).Quoted 4 lines
I am not sure in the first place why this is actually ignored and just returning a -1 value.
If an access is not right, an exception should be generated to the Guest instead.No. That's also not what happens on bare metal, at least not on x86. Faults cannot be raised for reasons outside of the CPU; such errors (if these are errors in the first place) need to be dealt with differently. Signaling an error on the PCI bus would be possible, but would leave open how that's actually to be dealt with. Instead bad reads return all ones, while bad writes simply get dropped.
Quoted 8 lines
Quoted 5 lines
So that behaviour is kept here on x86 and I think as the function is generic it is right for it to return an error here. It is up to the caller to ignore it or not.
To make this more generic I could return 0 on success and-EACCESS, the caller would then handle it as he wants.I think boolean is sufficient here, but I wouldn't object to errno- style return values. All I do object to is int when boolean is meant.
Boolean sounds right as there is only one error case. I will use that.
Quoted 58 lines
Quoted 58 lines
Quoted 57 lines
Quoted 45 lines
Quoted 36 lines
Quoted 36 lines
xen/drivers/vpci/vpci.c +35
-0+int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 )Quoted 8 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 539
Quoted 4 lines
xen/drivers/vpci/vpci.c +4
-0+ *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +}Why do these two functions return int/0/1 instead of bool/false/true (assuming, as per above, that them returning non- void is warranted at all)?
Quoted 2 lines
This is what the mmio handlers should return to say that an access was ok or not so the function stick to this standard.
Sticking to this would be okay if the functions here needed their address taken, such that they can be installed as hooks for a more general framework to invoke. The functions, however, only get called directly. Hence there's no reason to mirror what is in need of cleaning up elsewhere. I'm sure you're aware there we're in the (slow going) process of improving which types get used where. While the functions you refer to may not have undergone such cleanup yet, we generally expect new code to conform to the new model.
Quoted 6 lines
Quoted 2 lines
I am ok to rename those to vpci_ecam_{read/write}. Is it what you want ?
Yes, that's what I've been asking for, and I just saw Roger requesting the same. (I'm a little puzzled about the context though, as you reply looks disconnected here.)
Oups sorry.
Anyway if we agree on naming scheme and bool return type I think all your comments here are covered ?
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Quoted 2 lines · Bertrand Marquis
Anyway if we agree on naming scheme and bool return type I think all your comments here are covered ?
Probably, but I have to admit I've lost track ...
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Jan BeulichQuoted 29 lines · Jan Beulich
Quoted 28 lines · Bertrand Marquis
Quoted 28 lines · Jan Beulich
Quoted 25 lines · Bertrand Marquis
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +1
-1@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf);Quoted 8 lines
xen/arch/x86/hvm/io.c static int vpci_portio_write(const struct hvm_io_handler *handler, · line 327
Quoted 5 lines
xen/arch/x86/hvm/io.c +1
-1-if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);Why would port I/O functions call an ECAM helper? And in how far is that helper actually ECAM-specific?
The function was global before.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I'm not objecting to the function being global, but to the "ecam" in its name.
Adding ecam in the name was a request from Roger.
This is just a consequence of this.Roger - did you have in mind the uses here when asking for the addition of "ecam"?
I didn't realize it was also used by the IO ports accessors. Strictly speaking 64bit accesses (lenght == 8) shouldn't be possible/allowed from IO ports, but that's a red herring.
Thanks, Roger.
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Bertrand MarquisQuoted 19 lines · Bertrand Marquis
PCI standard is using ECAM and not MCFG which is coming from ACPI[1]. Use ECAM/ecam instead of MCFG in common code and in new functions added in common vpci code by this patch.
Rename
vpci_access_allowedtovpci_ecam_access_allowedand move it fromarch/x86/hvm/io.ctodrivers/vpci/vpci.c.Create vpci_ecam_mmio_{read,write} in
drivers/vpci/vpci.cthat contains the common code to perform these operations, changed vpci_mmcfg_{read,write} accordingly to make use of these functions.The vpci_ecam_mmio_{read,write} functions are returning 0 on error and 1 on success. As the x86 code was previously always returning
X86EMUL_OKAYthe return code is ignored. A comment has been added in the code to show that this is intentional.Those functions will be used in a following patch inside by arm vpci implementation.
Quoted 8 lines
Rename
MMCFG_SBDFtoECAM_SBDF.Not functional change intended with this patch.
[1] https://wiki.osdev.org/PCI_Express
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>
Everything checks out:
FYI I like the new naming scheme and I think it is the right one for us to use, but either way for me it wouldn't be a blocker for acceptance.
Quoted 214 lines
---
Changes in v6: Patch added--- xen/arch/x86/hvm/io.c | 50 +++++--------------------------- xen/drivers/vpci/vpci.c | 60 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pci.h | 2 +- xen/include/xen/vpci.h | 10 +++++++ 4 files changed, 78 insertions(+), 44 deletions(-)xen/arch/x86/hvm/io.c +7
-43@@ -260,20 +260,6 @@ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr,return CF8_ADDR_LO (cf8) | (addr &3 ); } -/* Do some sanity checks. */ -static bool vpci_access_allowed (unsigned int reg,unsigned int len) -{ -/* Check access size. */ -if ( len !=1 && len !=2 && len !=4 && len !=8 ) -return false; - -/* Check that access is size aligned. */ -if ( (reg & (len -1 )) ) -return false; - -return true; -} -/* vPCI config space IO ports handlers (0xcf8/0xcfc). */ static bool vpci_portio_accept (const struct hvm_io_handler *handler,const ioreq_t *p)@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);@@ -394,7 +380,7 @@ static unsigned int vpci_mmcfg_decode_addr(const struct hvm_mmcfg *mmcfg, paddr_t addr, pci_sbdf_t *sbdf) { addr -= mmcfg->addr; - sbdf->bdf =MMCFG_BDF (addr); + sbdf->bdf =ECAM_BDF (addr); sbdf->bus += mmcfg->start_bus; sbdf->seg = mmcfg->segment;@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses -* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);return X86EMUL_OKAY ; }@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);return X86EMUL_OKAY ; }xen/drivers/vpci/vpci.c +60
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); } +/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len) +{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code. +*/ +if ( len !=1 && len !=2 && len !=4 && len !=8 ) +return false; + +/* Check that access is size aligned. */ +if ( (reg & (len -1 )) ) +return false; + +return true; +} + +int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +vpci_write (sbdf, reg,min (4u , len), data); +if ( len ==8 ) +vpci_write (sbdf, reg +4 ,4 , data >>32 ); + +return 1 ; +} + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data) +{ +if ( !vpci_ecam_access_allowed (reg, len) || + (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) +return 0 ; + +/* +* According to the PCIe 3.1A specification: +* - Configuration Reads and Writes must usually be DWORD or smaller +* in size. +* - Because Root Complex implementations are not required to support +* accesses to a RCRB that cross DW boundaries [...] software +* should take care not to cause the generation of such accesses +* when accessing a RCRB unless the Root Complex will support the +* access. +* Xen however supports 8byte accesses by splitting them into two +* 4byte accesses. +*/ + *data =vpci_read (sbdf, reg,min (4u , len)); +if ( len ==8 ) + *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; + +return 1 ; +} +/* * Local variables: * mode: C xen/include/asm-x86/pci.h +1
-1@@ -6,7 +6,7 @@#define CF8_ADDR_HI (cf8) ( ((cf8) & 0x0f000000) >> 16)#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) -#define MMCFG_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12)#define IS_SNB_GFX (id) (id == 0x01068086 || id == 0x01168086 \ || id == 0x01268086 || id == 0x01028086 \xen/include/xen/vpci.h +10
-0@@ -208,6 +208,16 @@ static inline unsigned int vmsix_entry_nr(const struct vpci_msix *msix, {return entry - msix->entries; } + +/* ECAM mmio read/write helpers */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len); + +int vpci_ecam_mmio_write (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long data); + +int vpci_ecam_mmio_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len, +unsigned long *data); +#endif /* __XEN__ */ #else /* !CONFIG_HAS_VPCI */ Signature · 1 line
2.25.1
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Bertrand MarquisQuoted 103 lines · Bertrand Marquis
PCI standard is using ECAM and not MCFG which is coming from ACPI[1]. Use ECAM/ecam instead of MCFG in common code and in new functions added in common vpci code by this patch.
Rename
vpci_access_allowedtovpci_ecam_access_allowedand move it fromarch/x86/hvm/io.ctodrivers/vpci/vpci.c.Create vpci_ecam_mmio_{read,write} in
drivers/vpci/vpci.cthat contains the common code to perform these operations, changed vpci_mmcfg_{read,write} accordingly to make use of these functions.The vpci_ecam_mmio_{read,write} functions are returning 0 on error and 1 on success. As the x86 code was previously always returning
X86EMUL_OKAYthe return code is ignored. A comment has been added in the code to show that this is intentional.Those functions will be used in a following patch inside by arm vpci implementation.
Rename
MMCFG_SBDFtoECAM_SBDF.Not functional change intended with this patch.
[1] https://wiki.osdev.org/PCI_Express
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6: Patch added--- xen/arch/x86/hvm/io.c | 50 +++++--------------------------- xen/drivers/vpci/vpci.c | 60 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pci.h | 2 +- xen/include/xen/vpci.h | 10 +++++++ 4 files changed, 78 insertions(+), 44 deletions(-)xen/arch/x86/hvm/io.c +3
-28@@ -260,20 +260,6 @@ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr,return CF8_ADDR_LO (cf8) | (addr &3 ); } -/* Do some sanity checks. */ -static bool vpci_access_allowed (unsigned int reg,unsigned int len) -{ -/* Check access size. */ -if ( len !=1 && len !=2 && len !=4 && len !=8 ) -return false; - -/* Check that access is size aligned. */ -if ( (reg & (len -1 )) ) -return false; - -return true; -} -/* vPCI config space IO ports handlers (0xcf8/0xcfc). */ static bool vpci_portio_accept (const struct hvm_io_handler *handler,const ioreq_t *p)@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);@@ -394,7 +380,7 @@ static unsigned int vpci_mmcfg_decode_addr(const struct hvm_mmcfg *mmcfg, paddr_t addr, pci_sbdf_t *sbdf) { addr -= mmcfg->addr; - sbdf->bdf =MMCFG_BDF (addr); + sbdf->bdf =ECAM_BDF (addr); sbdf->bus += mmcfg->start_bus; sbdf->seg = mmcfg->segment;@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);
I think it would be better for vpci_ecam_mmio_read to just return the read value, or ~0 in case of error, at least that interface would be simpler and suitable for x86.
Also I would drop the mmio part from the function name.
Quoted 6 lines
xen/arch/x86/hvm/io.c +0
-0return X86EMUL_OKAY ; }@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock);
xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-7-if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);
Kind of likely here, x86 would be fine with this function return type being void.
If that's not good for Arm, I think the comment can be dropped as it's clear the return code is ignored. It would better to maybe add:
/* Failed writes are not propagated to the caller */
Quoted 10 lines
xen/arch/x86/hvm/io.c +0
-0return X86EMUL_OKAY ; }xen/drivers/vpci/vpci.c +0
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); }
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 489
Quoted 10 lines
xen/drivers/vpci/vpci.c +9
-0+/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len) +{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code.
It feels kind of weird to have an Arm specific comment in common code, but I guess there's no better place for it to live?
Thanks, Roger.
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Hi Roger,
Quoted 112 lines · Roger Pau Monné
Quoted 109 lines · Bertrand Marquis
PCI standard is using ECAM and not MCFG which is coming from ACPI[1]. Use ECAM/ecam instead of MCFG in common code and in new functions added in common vpci code by this patch.
Rename
vpci_access_allowedtovpci_ecam_access_allowedand move it fromarch/x86/hvm/io.ctodrivers/vpci/vpci.c.Create vpci_ecam_mmio_{read,write} in
drivers/vpci/vpci.cthat contains the common code to perform these operations, changed vpci_mmcfg_{read,write} accordingly to make use of these functions.The vpci_ecam_mmio_{read,write} functions are returning 0 on error and 1 on success. As the x86 code was previously always returning
X86EMUL_OKAYthe return code is ignored. A comment has been added in the code to show that this is intentional.Those functions will be used in a following patch inside by arm vpci implementation.
Rename
MMCFG_SBDFtoECAM_SBDF.Not functional change intended with this patch.
[1] https://wiki.osdev.org/PCI_Express
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6: Patch added
---xen/arch/x86/hvm/io.c | 50 +++++--------------------------- xen/drivers/vpci/vpci.c | 60 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pci.h | 2 +- xen/include/xen/vpci.h | 10 +++++++ 4 files changed, 78 insertions(+), 44 deletions(-)xen/arch/x86/hvm/io.c +3
-34@@ -260,20 +260,6 @@ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr,return CF8_ADDR_LO (cf8) | (addr &3 ); } -/* Do some sanity checks. */ -static bool vpci_access_allowed (unsigned int reg,unsigned int len) -{ -/* Check access size. */ -if ( len !=1 && len !=2 && len !=4 && len !=8 ) -return false; - -/* Check that access is size aligned. */ -if ( (reg & (len -1 )) ) -return false; - -return true; -} -/* vPCI config space IO ports handlers (0xcf8/0xcfc). */ static bool vpci_portio_accept (const struct hvm_io_handler *handler,const ioreq_t *p)@@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ; *data =vpci_read (sbdf, reg, size);@@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler *handler, reg =hvm_pci_decode_addr (cf8, addr, &sbdf); -if ( !vpci_access_allowed (reg, size) ) +if ( !vpci_ecam_access_allowed (reg, size) )return X86EMUL_OKAY ;vpci_write (sbdf, reg, size, data);@@ -394,7 +380,7 @@ static unsigned int vpci_mmcfg_decode_addr(const struct hvm_mmcfg *mmcfg, paddr_t addr, pci_sbdf_t *sbdf) { addr -= mmcfg->addr; - sbdf->bdf =MMCFG_BDF (addr); + sbdf->bdf =ECAM_BDF (addr); sbdf->bus += mmcfg->start_bus; sbdf->seg = mmcfg->segment;@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses -* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len));
Quoted 8 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 4 lines
xen/arch/x86/hvm/io.c +2
-2-if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);I think it would be better for
vpci_ecam_mmio_readto just return the read value, or ~0 in case of error, at least that interface would be simpler and suitable for x86.
I am not quite sure on this as on absolute to read ~0 is possible so the caller cannot distinguish between properly reading ~0 or an access allowed error.
Quoted 2 lines
Also I would drop the mmio part from the function name.
Ok I will do that.
Quoted 21 lines
Quoted 7 lines
xen/arch/x86/hvm/io.c +0
-0return X86EMUL_OKAY ; }@@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock);xen/arch/x86/hvm/io.c static int vpci_mmcfg_write(struct vcpu *v, unsigned long addr, · line 449
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-7-if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -vpci_write (sbdf, reg,min (4u , len), data); -if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +/* Ignore return code */ +vpci_ecam_mmio_write (sbdf, reg, len, data);Kind of likely here, x86 would be fine with this function return type being void.
Quoted 4 lines
If that's not good for Arm, I think the comment can be dropped as it's clear the return code is ignored. It would better to maybe add:
/* Failed writes are not propagated to the caller */
I will replace the current comment by this one.
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/io.c +0
-0return X86EMUL_OKAY ; }xen/drivers/vpci/vpci.c +0
-0@@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,spin_unlock (&pdev->vpci->lock); }
Quoted 12 lines
xen/drivers/vpci/vpci.c void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, · line 489
Quoted 9 lines
xen/drivers/vpci/vpci.c +9
-0+/* Helper function to check an access size and alignment on vpci space. */ +bool vpci_ecam_access_allowed (unsigned int reg,unsigned int len) +{ +/* +* Check access size. +* +* On arm32 or for 32bit guests on arm, 64bit accesses should be forbidden +* but as for those platform ISV register, which gives the access size, +* cannot have a value 3, checking this would just harden the code. It feels kind of weird to have an Arm specific comment in common code, but I guess there's no better place for it to live?
For now I think I can move it directly into arm vpci code even though it is not perfect.
Thanks for the comments
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Quoted 32 lines · Bertrand Marquis
Quoted 23 lines · Roger Pau Monné
Quoted 21 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +0
-17@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses -* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len));Quoted 8 lines
xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 4 lines
xen/arch/x86/hvm/io.c +2
-2-if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);I think it would be better for
vpci_ecam_mmio_readto just return the read value, or ~0 in case of error, at least that interface would be simpler and suitable for x86.
Quoted 2 lines
I am not quite sure on this as on absolute to read ~0 is possible so the caller cannot distinguish between properly reading ~0 or an access allowed error.
How do you report an access allowed error on Arm for the PCI config space?
At least on x86 I don't think we currently have a way to propagate such errors, neither a plan to do so that I'm aware.
Thanks, Roger.
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
Hi Roger,
Quoted 35 lines · Roger Pau Monné
Quoted 32 lines · Bertrand Marquis
Quoted 31 lines · Roger Pau Monné
Quoted 15 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +0
-11@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);I think it would be better for
vpci_ecam_mmio_readto just return the read value, or ~0 in case of error, at least that interface would be simpler and suitable for x86.
Quoted 5 lines
Quoted 2 lines
I am not quite sure on this as on absolute to read ~0 is possible so the caller cannot distinguish between properly reading ~0 or an access allowed error.
How do you report an access allowed error on Arm for the PCI config space?
This does not go that far. In the current case this is actually an unaligned access to mmio which will trigger and exception before reaching the PCI config space.
Quoted 3 lines
At least on x86 I don't think we currently have a way to propagate such errors, neither a plan to do so that I'm aware.
The behaviour on x86 will not change as we will ignore this.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Roger Pau MonnéQuoted 33 lines · Roger Pau Monné
Quoted 32 lines · Bertrand Marquis
Quoted 31 lines · Roger Pau Monné
Quoted 15 lines · Bertrand Marquis
xen/arch/x86/hvm/io.c +0
-11@@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, reg =vpci_mmcfg_decode_addr (mmcfg, addr, &sbdf);read_unlock (&d->arch.hvm.mmcfg_lock); -if ( !vpci_access_allowed (reg, len) || - (reg + len) >PCI_CFG_SPACE_EXP_SIZE ) -return X86EMUL_OKAY ; - -/* -* According to the PCIe 3.1A specification: -* - Configuration Reads and Writes must usually be DWORD or smaller -* in size. -* - Because Root Complex implementations are not required to support -* accesses to a RCRB that cross DW boundaries [...] software -* should take care not to cause the generation of such accesses xen/arch/x86/hvm/io.c static int vpci_mmcfg_read(struct vcpu *v, unsigned long addr, · line 424
Quoted 10 lines
xen/arch/x86/hvm/io.c +2
-8-* when accessing a RCRB unless the Root Complex will support the -* access. -* Xen however supports 8byte accesses by splitting them into two -* 4byte accesses. -*/ - *data =vpci_read (sbdf, reg,min (4u , len)); -if ( len ==8 ) - *data |= (uint64_t )vpci_read (sbdf, reg +4 ,4 ) <<32 ; +/* Ignore return code */ +vpci_ecam_mmio_read (sbdf, reg, len, data);I think it would be better for
vpci_ecam_mmio_readto just return the read value, or ~0 in case of error, at least that interface would be simpler and suitable for x86.
Quoted 8 lines
Quoted 2 lines
I am not quite sure on this as on absolute to read ~0 is possible so the caller cannot distinguish between properly reading ~0 or an access allowed error.
How do you report an access allowed error on Arm for the PCI config space?
At least on x86 I don't think we currently have a way to propagate such errors, neither a plan to do so that I'm aware.
I have to admit I can't even think of how such a plan could look like, give x86'es history.
Jan