Fixes: PCI devices passthrough on Arm
v2 cover Fixes: PCI devices passthrough on Arm
This patch serie is a follow-up after various findings on d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI support for ARM") as of agreed in [1].
It does the following:
- enable vpci_add_handlers on x86 and not only on arm
- remove __hwdom_init flag for vpci_add_handlers
- add missing vpci handler cleanup in error path during pci_device_add and pci_device_remove
[1] https://marc.info/?l=xen-devel&m=163455502020100&w=2
In the second version of the serie, the 3 patches have been merged into one single patch.
Bertrand Marquis (1):
xen/pci: Install vpci handlers on x86 and fix exit path
xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/1 xen/pci: Install vpci handlers on x86 and fix exit path
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use the PHYSDEVOP_pci_device_add to signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed during pci_device_add for x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).
So this patch is removing the ifdef protecting the call to vpci_add_handlers and the comment which was arm specific.
vpci_add_handlers is called on during pci_device_add which can be called at runtime through hypercall physdev_op.
Remove __hwdom_init as the call is not limited anymore to hardware domain init and fix linker script to only keep vpci_array in rodata section.
Add missing vpci handlers cleanup during pci_device_remove and in case of error with iommu during pci_device_add.
Add empty static inline for vpci_remove_device when CONFIG_VPCI is not defined.
for ARM")
---
Changes in v2
- add comment suggested by Jan on top of vpci_add_handlers call
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keep vpci_array in rodata and only when CONFIG_VPCI is set.
--- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)
xen/arch/arm/xen.lds.S +1 -8
@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))
@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);
xen/arch/x86/xen.lds.S +1 -8
@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))
@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);
xen/drivers/passthrough/pci.c +4 -4
@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )
@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }
@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);pci_cleanup_msi (pdev); ret =iommu_remove_device (pdev);if ( pdev->domain )
xen/drivers/vpci/vpci.c +1 -1
@@ -54,7 +54,7 @@ void vpci_remove_device(struct pci_dev *pdev) pdev->vpci =NULL ; } -int __hwdom_init vpci_add_handlers(struct pci_dev *pdev) +int vpci_add_handlers (struct pci_dev *pdev) {unsigned int i;int rc =0 ;
xen/include/xen/vpci.h +2 -0
@@ -230,6 +230,8 @@ static inline int vpci_add_handlers(struct pci_dev *pdev)return 0 ; } +static inline void vpci_remove_device (struct pci_dev *pdev) { } +static inline void vpci_dump_msi (void ) { } static inline uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg,
Signature · 1 line
2.25.1
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Quoted 21 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.
Quoted 7 lines
Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>
Quoted 134 lines
---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.--- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +4
-4@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);pci_cleanup_msi (pdev); ret =iommu_remove_device (pdev);if ( pdev->domain )xen/drivers/vpci/vpci.c +1
-1@@ -54,7 +54,7 @@ void vpci_remove_device(struct pci_dev *pdev) pdev->vpci =NULL ; } -int __hwdom_init vpci_add_handlers(struct pci_dev *pdev) +int vpci_add_handlers (struct pci_dev *pdev) {unsigned int i;int rc =0 ;xen/include/xen/vpci.h +2
-0@@ -230,6 +230,8 @@ static inline int vpci_add_handlers(struct pci_dev *pdev)return 0 ; } +static inline void vpci_remove_device (struct pci_dev *pdev) { } +static inline void vpci_dump_msi (void ) { } static inline uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg,Signature · 1 line
2.25.1
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
In reply to Bertrand MarquisQuoted 21 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.
Quoted 7 lines
Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>
I'm inclined to suggest s/exit/error/ in the title though (and maybe also s/path/paths/), which would be easy enough to do while committing. But first we need Roger's ack here anyway ...
Jan
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Hi,
Quoted 27 lines · Jan Beulich
Quoted 24 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.
Quoted 6 lines
Quoted 4 lines
Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thank.
Quoted 3 lines
I'm inclined to suggest s/exit/error/ in the title though (and maybe also s/path/paths/), which would be easy enough to do while committing.
@Ian: Please tell me if this is ok to be fixed during commit.
Quoted 1 line
But first we need Roger's ack here anyway ...
Yes.
Cheers
Bertrand
Quoted 2 lines
Jan
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Bertrand Marquis writes ("Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path"):
Quoted 5 lines
Quoted 3 lines · Jan Beulich
I'm inclined to suggest s/exit/error/ in the title though (and maybe also s/path/paths/), which would be easy enough to do while committing.
@Ian: Please tell me if this is ok to be fixed during commit.
It's academic now, since you need a respin anyway, but I would in any case have preferred a new version. I find that a much better workflow. Expecting to make changes on commit pushes work onto committers from submitters, which is less scaleable.
And it also ends up with committer making changes without any further human review of any kind. The committer must do so during an activity which is otherwise often shallow and administrative. This is not the best way to get good results.
I believe I have made these points before, but perhaps not so clearly and explicitly. They are IMO very general. (FTAOD I'm not saying that making changes on commit is never appropriate, but it ought to be exceptional.)
Thanks,
Ian.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Quoted 17 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path"):
Quoted 5 lines
Quoted 3 lines · Jan Beulich
I'm inclined to suggest s/exit/error/ in the title though (and maybe also s/path/paths/), which would be easy enough to do while committing.
@Ian: Please tell me if this is ok to be fixed during commit.
It's academic now, since you need a respin anyway, but I would in any case have preferred a new version. I find that a much better workflow. Expecting to make changes on commit pushes work onto committers from submitters, which is less scaleable.
And it also ends up with committer making changes without any further human review of any kind. The committer must do so during an activity which is otherwise often shallow and administrative. This is not the best way to get good results.
Quoted 4 lines
I believe I have made these points before, but perhaps not so clearly and explicitly. They are IMO very general. (FTAOD I'm not saying that making changes on commit is never appropriate, but it ought to be exceptional.)
Everything you wrote makes sense and your position is perfectly valid. At the same time let me write a different perspective on the issue. All the committers have slightly different workflows so it is natural that things that are better for one person might not be best for another.
When I commit a patch series often I don't simply take the patches (with all the necessary acks) and commit them. I typically do a number of other things:
1) check that the series has all the requested changes compared to the previous version
2) check that nothing else was changed unexpectedly
3) run a local build test in a variety of configurations
4) run a full gitlab-ci set of tests with the patches applied
All of the above take time. So if only a small change is required, it is much faster for me to make the change myself on commit rather than having to go through steps 1-4 one more time again. Of course this is only good for small changes with no impact, e.g. code style or in-code comments, I wouldn't want to do this for anything meaningful.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
In reply to Bertrand MarquisQuoted 126 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.--- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +3
-4@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }
xen/drivers/passthrough/pci.c int pci_remove_device(u16 seg, u8 bus, u8 devfn) · line 821
Quoted 4 lines
xen/drivers/passthrough/pci.c +1
-0@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);
vpci_remove_device is missing a check for has_vpci(pdev->domain), as it will unconditionally access pdev->vpci otherwise, and that would be wrong for domains not using vpci.
It might also be good to add an ASSERT(!pdev->vpci) to vpci_add_handlers in order to make sure there are no duplicated calls to vpci_add_handlers, but that can be done in a separate patch.
Thanks, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Hi Roger,
Quoted 138 lines · Roger Pau Monné
Quoted 126 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.
---xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +3
-4@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }xen/drivers/passthrough/pci.c int pci_remove_device(u16 seg, u8 bus, u8 devfn) · line 821
Quoted 4 lines
xen/drivers/passthrough/pci.c +1
-0@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);
vpci_remove_deviceis missing a check forhas_vpci(pdev->domain), as it will unconditionally accesspdev->vpciotherwise, and that would be wrong for domains not using vpci.
Quoted 3 lines
It might also be good to add an
ASSERT(!pdev->vpci)tovpci_add_handlersin order to make sure there are no duplicated calls tovpci_add_handlers, but that can be done in a separate patch.
I can do both in v3 (together with the change of in the patch name).
Unless you want the ASSERT in a different patch, in this case I do not think I can make a new patch for that.
Can you confirm if I should or not add the ASSERT directly in the patch ?
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Quoted 144 lines · Bertrand Marquis
Hi Roger,
Quoted 138 lines · Roger Pau Monné
Quoted 126 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.
---xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +3
-4@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }xen/drivers/passthrough/pci.c int pci_remove_device(u16 seg, u8 bus, u8 devfn) · line 821
Quoted 4 lines
xen/drivers/passthrough/pci.c +1
-0@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);
vpci_remove_deviceis missing a check forhas_vpci(pdev->domain), as it will unconditionally accesspdev->vpciotherwise, and that would be wrong for domains not using vpci.Quoted 3 lines
It might also be good to add an
ASSERT(!pdev->vpci)tovpci_add_handlersin order to make sure there are no duplicated calls tovpci_add_handlers, but that can be done in a separate patch.
Quoted 6 lines
I can do both in v3 (together with the change of in the patch name).
Unless you want the ASSERT in a different patch, in this case I do not think I can make a new patch for that.
Can you confirm if I should or not add the ASSERT directly in the patch ?
I'm fine with having the assert added here: in wasn't necessary previously as there was a single caller of vpci_add_handlers. Now that there are multiple ones we should make sure no duplicated calls can happen.
On a different note (and not something that should be solved here, just wanted to raise attention to it) there's an existing TODO about vpci_remove_device because it doesn't clean the 2nd stage mappings for BARs. At some point we need to solve this, or else the removal of the device is not complete.
Thanks, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Hi Roger,
Quoted 152 lines · Roger Pau Monné
Quoted 149 lines · Bertrand Marquis
Hi Roger,
Quoted 138 lines · Roger Pau Monné
Quoted 126 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.
---xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +3
-4@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )@@ -768,10 +767,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain =NULL ; goto out; } -#endif ret =iommu_add_device (pdev);if ( ret ) { +vpci_remove_device (pdev); pdev->domain =NULL ; goto out; }xen/drivers/passthrough/pci.c int pci_remove_device(u16 seg, u8 bus, u8 devfn) · line 821
Quoted 4 lines
xen/drivers/passthrough/pci.c +1
-0@@ -819,6 +818,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )if ( pdev->bus == bus && pdev->devfn == devfn ) { +vpci_remove_device (pdev);
vpci_remove_deviceis missing a check forhas_vpci(pdev->domain), as it will unconditionally accesspdev->vpciotherwise, and that would be wrong for domains not using vpci.Quoted 3 lines
It might also be good to add an
ASSERT(!pdev->vpci)tovpci_add_handlersin order to make sure there are no duplicated calls tovpci_add_handlers, but that can be done in a separate patch.I can do both in v3 (together with the change of in the patch name).
Unless you want the ASSERT in a different patch, in this case I do not think I can make a new patch for that.
Quoted 6 lines
Quoted 1 line
Can you confirm if I should or not add the ASSERT directly in the patch ?
I'm fine with having the assert added here: in wasn't necessary previously as there was a single caller of
vpci_add_handlers. Now that there are multiple ones we should make sure no duplicated calls can happen.
Ok I will add it then and send v3 this morning.
Quoted 6 lines
On a different note (and not something that should be solved here, just wanted to raise attention to it) there's an existing TODO about
vpci_remove_devicebecause it doesn't clean the 2nd stage mappings for BARs. At some point we need to solve this, or else the removal of the device is not complete.
I will try to keep that in mind.
Maybe adding a TODO in the code would be a good idea.
Thanks
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
In reply to Bertrand MarquisQuoted 103 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.--- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +0
-0@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) {
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 764
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )
Sorry to be a pain, but I think this placement of the call to vpci_add_handlers is bogus and should instead be done strictly after the device has been added to the hardware_domain->pdev_list list.
Otherwise the loop over domain->pdev_list (for_each_pdev) in modify_bars won't be able to find the device and hit the assert below it. That can happen in vpci_add_handlers as it will call init_bars which in turn will call into modify_bars if memory decoding is enabled for the device.
Regards, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Quoted 119 lines · Roger Pau Monné
Quoted 103 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.--- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +0
-0@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) {xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 764
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )Sorry to be a pain, but I think this placement of the call to
vpci_add_handlersis bogus and should instead be done strictly after the device has been added to thehardware_domain->pdev_listlist.
Quoted 5 lines
Otherwise the loop over
domain->pdev_list(for_each_pdev) inmodify_barswon't be able to find the device and hit the assert below it. That can happen invpci_add_handlersas it will callinit_barswhich in turn will call intomodify_barsif memory decoding is enabled for the device.
Oh, good point. And I should have thought of this myself, given that I did hit that ASSERT() recently with a hidden device. FTAOD I think this means that the list addition will need to move up (and then would need undoing on the error path(s)).
Jan
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Hi,
Quoted 128 lines · Jan Beulich
Quoted 119 lines · Roger Pau Monné
Quoted 103 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.
---xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +0
-0@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) {xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 764
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )Sorry to be a pain, but I think this placement of the call to
vpci_add_handlersis bogus and should instead be done strictly after the device has been added to thehardware_domain->pdev_listlist.Quoted 5 lines
Otherwise the loop over
domain->pdev_list(for_each_pdev) inmodify_barswon't be able to find the device and hit the assert below it. That can happen invpci_add_handlersas it will callinit_barswhich in turn will call intomodify_barsif memory decoding is enabled for the device.
Quoted 4 lines
Oh, good point. And I should have thought of this myself, given that I did hit that
ASSERT()recently with a hidden device. FTAOD I think this means that the list addition will need to move up (and then would need undoing on the error path(s)).
Agree, I just need to make sure that calling iommu_add_device is not impacted by this. It is probably not but a confirmation would be good.
Just to confirm, this specific change would look like that:
xen/drivers/passthrough/pci.c +4 -2
@@ -756,6 +756,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) { pdev->domain = hardware_domain; +list_add (&pdev->domain_list, &hardware_domain->pdev_list); +/* * For devices not discovered by Xen during boot, add vPCI handlers * when Dom0 first informs Xen about such devices.
@@ -764,6 +766,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( ret ) {printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); +list_del (&pdev->domain_list); pdev->domain =NULL ; goto out; }
@@ -771,11 +774,10 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( ret ) {vpci_remove_device (pdev); +list_del (&pdev->domain_list); pdev->domain =NULL ; goto out; } - -list_add (&pdev->domain_list, &hardware_domain->pdev_list); }else
Cheers
Bertrand
Quoted 4 lines
Jan
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
Quoted 130 lines · Bertrand Marquis
Hi,
Quoted 128 lines · Jan Beulich
Quoted 124 lines · Roger Pau Monné
Quoted 103 lines · Bertrand Marquis
Xen might not be able to discover at boot time all devices or some devices might appear after specific actions from dom0.
In this case dom0 can use thePHYSDEVOP_pci_device_addto signal some PCI devices to Xen.
As those devices where not known from Xen before, the vpci handlers must be properly installed duringpci_device_addfor x86 PVH Dom0, in the same way as what is done currently on arm (where Xen does not detect PCI devices but relies on Dom0 to declare them all the time).So this patch is removing the ifdef protecting the call to
vpci_add_handlersand the comment which was arm specific.
vpci_add_handlersis called on duringpci_device_addwhich can be called at runtime through hypercallphysdev_op.
Remove__hwdom_initas the call is not limited anymore to hardware domain init and fix linker script to only keepvpci_arrayin rodata section.Add missing vpci handlers cleanup during
pci_device_removeand in case of error with iommu duringpci_device_add.Add empty static inline for
vpci_remove_devicewhenCONFIG_VPCIis not defined.Fixes d59168dc05 ("xen/arm: Enable the existing x86 virtual PCI supportfor ARM")
Suggested-by Jan Beulich <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v2
- add comment suggested by Jan on top ofvpci_add_handlerscall
- merge the 3 patches of the serie in one patch and renamed it
- fix x86 and arm linker script to only keepvpci_arrayin rodata and only whenCONFIG_VPCIis set.
---xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/vpci/vpci.c | 2 +- xen/include/xen/vpci.h | 2 ++ 5 files changed, 9 insertions(+), 21 deletions(-)xen/arch/arm/xen.lds.S +1
-8@@ -60,7 +60,7 @@ SECTIONS *(.proc.info) __proc_info_end = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -189,13 +189,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } :text __init_end_efi = .; . = ALIGN(STACK_SIZE);xen/arch/x86/xen.lds.S +1
-8@@ -134,7 +134,7 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM) +#ifdef CONFIG_HAS_VPCI . = ALIGN(POINTER_ALIGN); __start_vpci_array = .; *(SORT(.data.vpci.*))@@ -247,13 +247,6 @@ SECTIONS *(.init_array) *(SORT(.init_array.*)) __ctors_end = .; - -#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM) - . = ALIGN(POINTER_ALIGN); - __start_vpci_array = .; - *(SORT(.data.vpci.*)) - __end_vpci_array = .; -#endif } PHDR(text) . = ALIGN(SECTION_ALIGN);xen/drivers/passthrough/pci.c +0
-0@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) {xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 764
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )Sorry to be a pain, but I think this placement of the call to
vpci_add_handlersis bogus and should instead be done strictly after the device has been added to thehardware_domain->pdev_listlist.Otherwise the loop over
domain->pdev_list(for_each_pdev) inmodify_barswon't be able to find the device and hit the assert below it. That can happen invpci_add_handlersas it will callinit_barswhich in turn will call intomodify_barsif memory decoding is enabled for the device.
Quoted 7 lines
Quoted 4 lines
Oh, good point. And I should have thought of this myself, given that I did hit that
ASSERT()recently with a hidden device. FTAOD I think this means that the list addition will need to move up (and then would need undoing on the error path(s)).Agree, I just need to make sure that calling
iommu_add_deviceis not impacted by this. It is probably not but a confirmation would be good.
LGTM. I've been looking but I don't think there's a need to do iommu_add_device before the call to vpci_add_handlers, so the proposed solution is fine.
Thanks, Roger.
Re: [PATCH v2 1/1] xen/pci: Install vpci handlers on x86 and fix exit path
In reply to Bertrand MarquisQuoted 29 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 5 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +0
-0@@ -756,10 +756,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->domain ) {xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 764
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3pdev->domain = hardware_domain; -#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. +* For devices not discovered by Xen during boot, add vPCI handlers +* when Dom0 first informs Xen about such devices. */ ret =vpci_add_handlers (pdev);if ( ret )Sorry to be a pain, but I think this placement of the call to
vpci_add_handlersis bogus and should instead be done strictly after the device has been added to thehardware_domain->pdev_listlist.Otherwise the loop over
domain->pdev_list(for_each_pdev) inmodify_barswon't be able to find the device and hit the assert below it. That can happen invpci_add_handlersas it will callinit_barswhich in turn will call intomodify_barsif memory decoding is enabled for the device.
Quoted 7 lines
Quoted 4 lines
Oh, good point. And I should have thought of this myself, given that I did hit that
ASSERT()recently with a hidden device. FTAOD I think this means that the list addition will need to move up (and then would need undoing on the error path(s)).Agree, I just need to make sure that calling
iommu_add_deviceis not impacted by this. It is probably not but a confirmation would be good.
Like Roger, I'm unaware of any issue there. It would be odd anyway for that (or about anything) to have a "is [not] on list" check. And the set of list iterations is pretty limited iirc.
Jan