PCI devices passthrough on Arm
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 9 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +5
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (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. +*/
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 769
Quoted 10 lines
xen/drivers/passthrough/pci.c +8
-0+ ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif + ret =0 ;if ( !pdev->domain )
Elsewhere I did point out that you need to be careful wrt pdev->domain being NULL. As the code in context clearly documents, you're now adding handlers before that field was set. In comments to a prior version I did already suggest to consider placing the new code inside the if() in question (albeit at the time this was mainly to make clear that error cleanup may not fiddle with things not put in place by the iommu_enable_device() alternative path). This would have the further benefit of making is crystal clear that here only handlers for Dom0 would get put in place (and hence their installing for DomU-s would need to be looked for elsewhere).
xen/drivers/passthrough/pci.c out: · line 801
Quoted 6 lines
xen/drivers/passthrough/pci.c +2
-0@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);
Have you thoroughly checked that this call is benign on x86? There's no wording to that effect in the description afaics, and I can't easily convince myself that it would be correct when the iommu_enable_device() path was taken. (I'm also not going to exclude that it should have been there even prior to your work, albeit then adding this would want to be a separate bugfix patch.)
xen/drivers/vpci/header.c static void bar_write(const struct pci_dev *pdev, unsigned int reg, · line 378
Quoted 9 lines
xen/drivers/vpci/header.c +2
-1@@ -374,7 +374,8 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,if ( val != (uint32_t )(bar->addr >> (hi ?32 :0 )) )gprintk (XENLOG_WARNING ,"%pp: ignored BAR %lu write with memory decoding enabled\n" , - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + &pdev->sbdf, + (unsigned long )(bar - pdev->vpci->header.bars + hi));
This looks like an entirely unrelated change which I'm afraid I don't even understand why it needs making. The description says this is for Arm32, but it remains unclear what the compilation error would have been. My best guess is that perhaps you really mean to change the format specifier to %zu (really this should be %td, but our vsprintf() doesn't support 't' for whatever reason).
Please recall that we try to avoid casts where possible.
xen/drivers/vpci/vpci.c int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len, · line 510
Quoted 8 lines
xen/drivers/vpci/vpci.c +1
-1@@ -507,7 +507,7 @@ int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,vpci_write (sbdf, reg,min (4u , len), data);if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +vpci_write (sbdf, reg +4 ,4 , (uint64_t )data >>32 );
I assume the need for this change will go away with the use of CONFIG_64BIT in the earlier patch.
xen/include/xen/pci.h line 44
Quoted 8 lines
xen/include/xen/pci.h +2
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_REG_OFFSET (addr) ((addr) & 0x00000fff)
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move to xen/vpci.h and then perhaps also be named VPCI_ECAM_BDF().
Also, as already pointed out on a much earlier version, while the blank following the opening parenthesis was warranted in asm-x86/pci.h for alignment reasons, it is no longer warranted here. It was certainly gone in v4 and v5.
And one final nit: I don't think we commonly use full stops in patch titles. (Personally I therefore also think titles shouldn't start with a capital letter, but I know others think differently.)
Jan
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Bertrand MarquisQuoted 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 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_write
Quoted 7 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)
Isn't the series missing a revert of XEN_DOMCTL_CDF_vpci? I think that's what we agreed would be the way forward.
Quoted 122 lines
- rename
REGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +38
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
xen/arch/arm/vpci.c line 48
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+ register_t r, void *p) +{ + pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + +return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +}
I'm not sure returning an error value here is helpful, as I'm not sure how native Arm behaves and how this error is propagated into the guest. FWIWreturning ~0 or dropping writes is what we do in x86 when vPCI is not capable of handling the access.
Quoted 87 lines
xen/arch/arm/vpci.c new file +26
-0+ +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +3
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev); +#ifdef CONFIG_ARM +/*
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+* 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); + goto out; + } +#endif
I think vpci_add_handlers should be called after checking that pdev->domain is != NULL, so I would move this chunk a bit below.
xen/drivers/passthrough/pci.c out: · line 801
Quoted 10 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);
I'm slightly lost at why you add this chunk, is this strictly related to the patch?
Quoted 78 lines
xen/drivers/passthrough/pci.c +0
-0return ret; }xen/drivers/vpci/header.c +2
-1@@ -374,7 +374,8 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,if ( val != (uint32_t )(bar->addr >> (hi ?32 :0 )) )gprintk (XENLOG_WARNING ,"%pp: ignored BAR %lu write with memory decoding enabled\n" , - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + &pdev->sbdf, + (unsigned long )(bar - pdev->vpci->header.bars + hi));return ; }xen/drivers/vpci/vpci.c +1
-1@@ -507,7 +507,7 @@ int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,vpci_write (sbdf, reg,min (4u , len), data);if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +vpci_write (sbdf, reg +4 ,4 , (uint64_t )data >>32 );return 1 ; }xen/include/asm-arm/domain.h +1
-0@@ -263,6 +263,7 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) +/* vPCI is not available on Arm */ #define has_vpci (d) ({ (void)(d); false; })#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 ECAM_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 43
Quoted 4 lines
xen/include/xen/pci.h +1
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12)
^ extra space?
Thanks, Roger.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 29 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_writeQuoted 7 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)
Quoted 3 lines
Isn't the series missing a revert of
XEN_DOMCTL_CDF_vpci? I think that's what we agreed would be the way forward.
The revert patch has already been merged.
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=9516d01ac3015f522528ed6dafb3f584eaa7ed2c
Quoted 339 lines
Quoted 122 lines
- rename
REGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +38
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,xen/arch/arm/vpci.c line 48
Quoted 10 lines
xen/arch/arm/vpci.c new file +10
-0+ register_t r, void *p) +{ + pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + +return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +}I'm not sure returning an error value here is helpful, as I'm not sure how native Arm behaves and how this error is propagated into the guest. FWIWreturning ~0 or dropping writes is what we do in x86 when vPCI is not capable of handling the access.
Quoted 87 lines
xen/arch/arm/vpci.c new file +26
-0+ +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +3
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev); +#ifdef CONFIG_ARM +/* xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+* 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); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.xen/drivers/passthrough/pci.c out: · line 801
Quoted 10 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
Quoted 78 lines
xen/drivers/passthrough/pci.c +0
-0return ret; }xen/drivers/vpci/header.c +2
-1@@ -374,7 +374,8 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,if ( val != (uint32_t )(bar->addr >> (hi ?32 :0 )) )gprintk (XENLOG_WARNING ,"%pp: ignored BAR %lu write with memory decoding enabled\n" , - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + &pdev->sbdf, + (unsigned long )(bar - pdev->vpci->header.bars + hi));return ; }xen/drivers/vpci/vpci.c +1
-1@@ -507,7 +507,7 @@ int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,vpci_write (sbdf, reg,min (4u , len), data);if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +vpci_write (sbdf, reg +4 ,4 , (uint64_t )data >>32 );return 1 ; }xen/include/asm-arm/domain.h +1
-0@@ -263,6 +263,7 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) +/* vPCI is not available on Arm */ #define has_vpci (d) ({ (void)(d); false; })#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 ECAM_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
-0xen/include/xen/pci.h line 43
Quoted 4 lines
xen/include/xen/pci.h +1
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12)^ extra space?
Thanks, Roger.
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Michal OrzelHi Michal,
Quoted 9 lines · Michal Orzel
Do you agree on the following approach:
1. Modify argument oflibxl__arch_domain_init_hw_descriptiontolibxl_domain_config(patch 1)
2. Modify argument oflibxl__prepare_dtbtolibxl_domain_config(patch 2)
3. Remove arch_arm.vpci completely and inlibxl__prepare_dtbadd a check (patch 3):
if (d_config->num_pcidevs)FDT( make_vpci_node(gc, fdt, ainfo, dom) );+
make_vpci_nodeimplementationDoes it sound ok for you?
This sounds ok to me.
Cheers,
Signature · 1 line
Julien Grall
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 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Roger Pau MonnéHi Roger,
Quoted 31 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_writeQuoted 7 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)
Quoted 2 lines
Isn't the series missing a revert of
XEN_DOMCTL_CDF_vpci? I think that's what we agreed would be the way forward.
A separate reverse patch for that has already been merged:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=9516d01ac3015f522528ed6dafb3f584eaa7ed2c
Quoted 130 lines
Quoted 130 lines
- rename
REGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +45
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); +
Quoted 8 lines
xen/arch/arm/vpci.c line 48
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +}I'm not sure returning an error value here is helpful, as I'm not sure how native Arm behaves and how this error is propagated into the guest. FWIWreturning ~0 or dropping writes is what we do in x86 when vPCI is not capable of handling the access.
Mmio handlers can take a return code on arm if something did not work so I think this is the right way to do it on arm.
Now has agreed with Jan, we will change the return type of vpci_ecam_write (also renamed) to be a boolean.
Quoted 86 lines
Quoted 86 lines
xen/arch/arm/vpci.c new file +26
-0+ +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +1
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);
Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Quoted 14 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 11 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
[1] https://patchwork.kernel.org/project/xen-devel/patch/9bdca2cda5d2e83f94dc2423e55714273539760a.1633540842.git.rahul.singh@arm.com/
[2] https://patchwork.kernel.org/project/xen-devel/patch/f093de681c2560a7196895bcd666ef8840885c1d.1633340795.git.rahul.singh@arm.com/
Regards
Bertrand
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Bertrand MarquisQuoted 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 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichJan Beulich writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 8 lines · Stefano Stabellini
Quoted 2 lines
Replacing the 3 characters with 'x' solves the problem.
https://gitlab.com/xen-project/people/sstabellini/xen/-/pipelines/388721262Interesting. I thought we permit UTF-8 in the sources; see e.g.
tools/tests/x86_emulator/simd-sha.cusing Σ. Ismkheader.pyin need of adjustment? Of course I can see that right now the easiest is to use ASCII x, but I think it was deliberate to use × here.
I think in general we should permit UTF-8 in sources.
But:
Quoted 4 lines
Then again, with the goal of the public headers being usable with pretty old compilers as well (C89 being the assumed baseline), excluding them from the permission to use UTF-8 may also be quite reasonable.
This is a good reason to do otherwise for the public headers. Maybe this should be documented in CODING_STYLE (can be done after feature freeze obviously).
That python has such botched unicode handling is a bug of course but we could decide we think it's a feature :-). In which case maybe mkheaders should be adjusted to explicitly set IO to ascii so that this will fail in local builds too.
Anyway, for now we need to replace the UTF-8 in this patch.
Thanks,
Ian.
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Julien GrallJulien Grall writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 1 line · Ian Jackson
...
Quoted 8 lines
Quoted 3 lines
That is, as I understand it on ARM vpci should be enabled if passthrough is enabled and not otherwise. That is precisely what the variable
c_info->passthroughis.On Arm,
c_info->passthroughis also set when assigning platform devives (e.g. a non-PCI network card). At least for now, we don't want to create a node for vCPI in the Device-Tree because we don't enable the emulation. So...
Oh.
Quoted 5 lines
Quoted 3 lines
3. Now you can use
d_config->c_info.passthroughto gate the addition of the additional stuff to the DT. Ie, that is a respin of this patch 3/3.... we will need to check
d_config->num_pcidevsfor the time being.
OK.
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of num_pcidevs ? That might save someone some future confusion.
Thanks,
Ian.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichHi Jan,
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +5
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (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. +*/ xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 769
Quoted 10 lines
xen/drivers/passthrough/pci.c +8
-0+ ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif + ret =0 ;if ( !pdev->domain )Elsewhere I did point out that you need to be careful wrt
pdev->domainbeing NULL. As the code in context clearly documents, you're now
Quoted 8 lines
adding handlers before that field was set. In comments to a prior version I did already suggest to consider placing the new code inside the
if()in question (albeit at the time this was mainly to make clear that error cleanup may not fiddle with things not put in place by theiommu_enable_device()alternative path). This would have the further benefit of making is crystal clear that here only handlers for Dom0 would get put in place (and hence their installing for DomU-s would need to be looked for elsewhere).
I asked Oleksandr for confirmation here but on arm there will be 2 other use cases:
- PCI own by a DomD so device enumeration done from there
- dom0less with devices detection done inside Xen
Quoted 14 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 7 lines
xen/drivers/passthrough/pci.c +2
-0@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);Have you thoroughly checked that this call is benign on x86? There's no wording to that effect in the description afaics, and I can't easily convince myself that it would be correct when the
iommu_enable_device()path was taken. (I'm also not going to exclude that it should have been there even prior to your work, albeit then adding this would want to be a separate bugfix patch.)
This was not in the original serie and requested by Stefano. I must admit I am not completely sure on the details here so I am really ok to remove this but this would go against what was requested on the previous versions (4 and 5).
Quoted 17 lines
xen/drivers/vpci/header.c static void bar_write(const struct pci_dev *pdev, unsigned int reg, · line 378
Quoted 10 lines
xen/drivers/vpci/header.c +2
-1@@ -374,7 +374,8 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,if ( val != (uint32_t )(bar->addr >> (hi ?32 :0 )) )gprintk (XENLOG_WARNING ,"%pp: ignored BAR %lu write with memory decoding enabled\n" , - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + &pdev->sbdf, + (unsigned long )(bar - pdev->vpci->header.bars + hi));This looks like an entirely unrelated change which I'm afraid I don't even understand why it needs making. The description says this is for Arm32, but it remains unclear what the compilation error would have been. My best guess is that perhaps you really mean to change the format specifier to %zu (really this should be %td, but our
vsprintf()doesn't support 't' for whatever reason).
Compilation error is about an invalid %lu print for an unsigned int value when compiled for arm32.
I will use zu instead in the next version and remove the cast.
Quoted 2 lines
Please recall that we try to avoid casts where possible.
Sure I will.
Quoted 5 lines
Quoted 5 lines
xen/drivers/vpci/vpci.c +0
-0@@ -507,7 +507,7 @@ int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,
Quoted 7 lines
xen/drivers/vpci/vpci.c int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len, · line 510
Quoted 4 lines
xen/drivers/vpci/vpci.c +1
-1vpci_write (sbdf, reg,min (4u , len), data);if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +vpci_write (sbdf, reg +4 ,4 , (uint64_t )data >>32 );I assume the need for this change will go away with the use of
CONFIG_64BITin the earlier patch.
Yes
Quoted 7 lines
Quoted 7 lines
xen/include/xen/pci.h +0
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) })
Quoted 13 lines
xen/include/xen/pci.h line 44
Quoted 2 lines
xen/include/xen/pci.h +2
-0+#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_REG_OFFSET (addr) ((addr) & 0x00000fff)The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
Also if I have to do this I will do the same for REG_OFFSET of course.
Quoted 5 lines
Also, as already pointed out on a much earlier version, while the blank following the opening parenthesis was warranted in
asm-x86/pci.hfor alignment reasons, it is no longer warranted here. It was certainly gone in v4 and v5.
Yes my mistake during the process I did a copy and paste from the original one and did not modify. I will fix that.
Quoted 4 lines
And one final nit: I don't think we commonly use full stops in patch titles. (Personally I therefore also think titles shouldn't start with a capital letter, but I know others think differently.)
Ok I will fix the patch name.
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Stefano StabelliniHi Stefano,
Quoted 365 lines · Stefano Stabellini
Quoted 12 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.
Quoted 7 lines
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_writeThank you for these! Strictly speaking they are not required now but they are welcome. I would also be OK if they were removed from this patch but it is fine to have them in here.
There is an issues with this patch, see below at the bottom
Quoted 308 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)
- renameREGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +74
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + +return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +} + +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +17
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (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); + goto out; + } +#endif + ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev); +return ret; }xen/drivers/vpci/header.c +2
-1@@ -374,7 +374,8 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,if ( val != (uint32_t )(bar->addr >> (hi ?32 :0 )) )gprintk (XENLOG_WARNING ,"%pp: ignored BAR %lu write with memory decoding enabled\n" , - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + &pdev->sbdf, + (unsigned long )(bar - pdev->vpci->header.bars + hi));return ; }xen/drivers/vpci/vpci.c +1
-1@@ -507,7 +507,7 @@ int vpci_ecam_mmio_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,vpci_write (sbdf, reg,min (4u , len), data);if ( len ==8 ) -vpci_write (sbdf, reg +4 ,4 , data >>32 ); +vpci_write (sbdf, reg +4 ,4 , (uint64_t )data >>32 );return 1 ; }xen/include/asm-arm/domain.h +1
-0@@ -263,6 +263,7 @@ static inline void arch_vcpu_block(struct vcpu *v) {}#define arch_vm_assist_valid_mask (d) (1UL << VMASST_TYPE_runstate_update_flag) +/* vPCI is not available on Arm */ #define has_vpci (d) ({ (void)(d); false; })#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 ECAM_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 +0
-0xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 424
Quoted 7 lines
xen/include/public/arch-arm.h +4
-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 +*/ Somehow 3 non-ascii characters sneaked into this patch. The 'x' are not 'x' but are
0xc3and cause the following errors in a few gitlab-ci builds:python3
mkheader.pyarm32 arm32.h.tmp /builds/xen-project/people/sstabellini/xen/tools/include/xen-foreign/../../../xen/include/public/arch-arm.h /builds/xen-project/people/sstabellini/xen/tools/include/xen-foreign/../../../xen/include/public/xen.h Traceback (most recent call last):
File "mkheader.py", line 120, in <module>
input +=f.read();
File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
returncodecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte0xc3in position 14641: ordinal not in range(128)
Makefile:28: recipe for target 'arm32.h' failed
make[2]: *** [arm32.h] Error 1Full logs here:
https://gitlab.com/xen-project/people/sstabellini/xen/-/pipelines/38855078
https://gitlab.com/xen-project/people/sstabellini/xen/-/jobs/16810108756
Quoted 7 lines
Replacing the 3 characters with 'x' solves the problem.
https://gitlab.com/xen-project/people/sstabellini/xen/-/pipelines/388721262With the three 'x' changed to ascii:
Reviewed-by Stefano Stabellini <[email protected]>
I will fix that but sadly seeing all other changes to be done I do not think I can keep your R-b.
Thanks
Bertrand
Quoted 25 lines
Quoted 25 lines
xen/include/public/arch-arm.h +3
-0+#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 +3
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) +#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_REG_OFFSET (addr) ((addr) & 0x00000fff) + typedef union { uint32_t sbdf; struct {Signature · 1 line
2.25.1
Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code
In reply to Roger Pau Monné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 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 289 lines · Bertrand Marquis
Hi Roger,
Quoted 31 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_writeQuoted 7 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)Quoted 2 lines
Isn't the series missing a revert of
XEN_DOMCTL_CDF_vpci? I think that's what we agreed would be the way forward.A separate reverse patch for that has already been merged:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=9516d01ac3015f522528ed6dafb3f584eaa7ed2cQuoted 130 lines
Quoted 130 lines
- rename
REGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +45
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); +Quoted 8 lines
xen/arch/arm/vpci.c line 48
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +}I'm not sure returning an error value here is helpful, as I'm not sure how native Arm behaves and how this error is propagated into the guest. FWIWreturning ~0 or dropping writes is what we do in x86 when vPCI is not capable of handling the access.
Mmio handlers can take a return code on arm if something did not work so I think this is the right way to do it on arm.
Now has agreed with Jan, we will change the return type ofvpci_ecam_write(also renamed) to be a boolean.Quoted 86 lines
Quoted 86 lines
xen/arch/arm/vpci.c new file +26
-0+ +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +1
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.
Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
For my understanding, as also Jan pointed out, this should be put inside the If ( !pdev->domain ) because also as the comment suggests, this operation should be performed only when there is a Dom0 and when we are using a dom0less setup the pdev->domain should be NULL if I’m not wrong. @oleksandr maybe can confirm
Quoted 29 lines
Quoted 15 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 12 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
[1] https://patchwork.kernel.org/project/xen-devel/patch/9bdca2cda5d2e83f94dc2423e55714273539760a.1633540842.git.rahul.singh@arm.com/
[2] https://patchwork.kernel.org/project/xen-devel/patch/f093de681c2560a7196895bcd666ef8840885c1d.1633340795.git.rahul.singh@arm.com/Regards
Bertrand
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisBertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().
Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Jan, would that approach be OK with you ?
Ian.
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
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Luca FancelluHi Luca,
Quoted 296 lines · Luca Fancellu
Quoted 290 lines · Bertrand Marquis
Hi Roger,
Quoted 31 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
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.This patch is also doing some small fixes to fix compilation errors on arm32 of vpci:
- add a cast to unsigned long in print inheader.c
- add a cast touint64_tinvpci_ecam_mmio_writeQuoted 7 lines
Signed-off-by Rahul Singh <[email protected]>Signed-off-by Bertrand Marquis <[email protected]>---
Changes in v6:
- Use newvpci_ecam_helpers for PCI access
- Do not setXEN_DOMCTL_CDF_vpcifor dom0 for now (will be done in a future patch once everything is ready)Quoted 2 lines
Isn't the series missing a revert of
XEN_DOMCTL_CDF_vpci? I think that's what we agreed would be the way forward.A separate reverse patch for that has already been merged:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=9516d01ac3015f522528ed6dafb3f584eaa7ed2cQuoted 130 lines
Quoted 130 lines
- rename
REGISTER_OFFSETtoECAM_REG_OFFSETand move it topci.h
- remove not needed local variables invpci_mmio_write, the one in read has been kept to ensure proper compilation on arm32
- move call tovpci_add_handlersbefore iommu init to simplify exit path
- move call topci_cleanup_msiin the out section ofpci_add_deviceif pdev is not NULL and on error
- initialize pdev to NULL to handle properly exit path call ofpci_cleanup_msi
- keephas_vpcito return false for now asCFG_vpcihas been removed. Added a comment on top of the definition.
- fix compilation errors on arm32 (print inheader.c, cast missing inmmio_write.
- local variable was kept invpci_mmio_readon arm to prevent a cast error in arm32.
Change in v5:
- Addpci_cleanup_msi(pdev)incleanup 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/vpci.c | 74 +++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 +++++++++++++++++ xen/drivers/passthrough/pci.c | 18 ++++++++- xen/drivers/vpci/header.c | 3 +- xen/drivers/vpci/vpci.c | 2 +- xen/include/asm-arm/domain.h | 1 + xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 11 files changed, 146 insertions(+), 5 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);@@ -773,6 +774,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/vpci.c new file +45
-0@@ -0,0 +1,74 @@ +/* +* 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 <xen/vpci.h> + +#include <asm/mmio.h> + +static int vpci_mmio_read (struct vcpu *v,mmio_info_t *info, +register_t *r,void *p) +{ +pci_sbdf_t sbdf; +/* data is needed to prevent a pointer cast on 32bit */ +unsigned long data = ~0ul ; +int ret; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); + + ret =vpci_ecam_mmio_read (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, &data); + + *r = data; + +return ret; +} + +static int vpci_mmio_write (struct vcpu *v,mmio_info_t *info, +register_t r,void *p) +{ +pci_sbdf_t sbdf; + +/* We ignore segment part and always handle segment 0 */ + sbdf.sbdf =ECAM_BDF (info->gpa); +Quoted 8 lines
xen/arch/arm/vpci.c line 48
Quoted 3 lines
xen/arch/arm/vpci.c new file +3
-0+return vpci_ecam_mmio_write (sbdf,ECAM_REG_OFFSET (info->gpa), +1U << info->dabt.size, r); +}I'm not sure returning an error value here is helpful, as I'm not sure how native Arm behaves and how this error is propagated into the guest. FWIWreturning ~0 or dropping writes is what we do in x86 when vPCI is not capable of handling the access.
Mmio handlers can take a return code on arm if something did not work so I think this is the right way to do it on arm.
Now has agreed with Jan, we will change the return type ofvpci_ecam_write(also renamed) to be a boolean.Quoted 86 lines
Quoted 86 lines
xen/arch/arm/vpci.c new file +26
-0+ +static const struct mmio_handler_ops vpci_mmio_handler = { + .read = vpci_mmio_read, + .write = vpci_mmio_write, +}; + +int domain_vpci_init (struct domain *d) +{ +if ( !has_vpci (d) ) +return 0 ; + +register_mmio_handler (d, &vpci_mmio_handler, +GUEST_VPCI_ECAM_BASE ,GUEST_VPCI_ECAM_SIZE ,NULL ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ +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 +1
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Quoted 5 lines
For my understanding, as also Jan pointed out, this should be put inside the If ( !pdev->domain ) because also as the comment suggests, this operation should be performed only when there is a Dom0 and when we are using a dom0less setup the
pdev->domainshould be NULL if I’m not wrong. @oleksandr maybe can confirm
You are right.
I will fix that and move that into an if.
Regards
Bertrand
Quoted 30 lines
Quoted 30 lines
Quoted 16 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 13 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
[1] https://patchwork.kernel.org/project/xen-devel/patch/9bdca2cda5d2e83f94dc2423e55714273539760a.1633540842.git.rahul.singh@arm.com/
[2] https://patchwork.kernel.org/project/xen-devel/patch/f093de681c2560a7196895bcd666ef8840885c1d.1633340795.git.rahul.singh@arm.com/Regards
Bertrand
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Ian JacksonQuoted 29 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
Quoted 4 lines
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 39 lines · Bertrand Marquis
Hi Roger,
Quoted 21 lines · Roger Pau Monné
Quoted 18 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
xen/drivers/passthrough/pci.c +1
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.
Quoted 2 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
vpci_add_handlers will try to access pdev->domain, so passing a pdev without domain being set is wrong.
Quoted 18 lines
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Quoted 14 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 11 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
Quoted 7 lines
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
pci_add_device being solely used by trusted domains, I think it would be fine to require that the domain doesn't poke the PCI config space until the call to pci_add_device has finished. Else it's likely to get inconsistent results, or mess up with the device state.
In any case, such addition needs some kind of reasoning added to the commit message if it's really required.
Thanks, Roger.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.
Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
Quoted 18 lines
Quoted 9 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 6 lines
xen/drivers/passthrough/pci.c +2
-0@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
Quoted 2 lines
[1] https://patchwork.kernel.org/project/xen-devel/patch/9bdca2cda5d2e83f94dc2423e55714273539760a.1633540842.git.rahul.singh@arm.com/
[2] https://patchwork.kernel.org/project/xen-devel/patch/f093de681c2560a7196895bcd666ef8840885c1d.1633340795.git.rahul.singh@arm.com/
The addition of this call has repeatedly raised questions. This is a good indication that sufficient discussion thereof has been lacking from the patch description.
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Roger Pau MonnéHi,
Quoted 42 lines · Roger Pau Monné
Quoted 39 lines · Bertrand Marquis
Hi Roger,
Quoted 36 lines · Roger Pau Monné
Quoted 20 lines · Bertrand Marquis
From: Rahul Singh <[email protected]>
xen/drivers/passthrough/pci.c +3
-1@@ -658,7 +658,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node) { struct pci_seg *pseg; -struct pci_dev *pdev; +struct pci_dev *pdev =NULL ;unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn);const char *pdev_type;int ret;@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev); +#ifdef CONFIG_ARM +/* xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+* 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); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.
Quoted 5 lines
Quoted 2 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
vpci_add_handlerswill try to accesspdev->domain, so passing a pdev without domain being set is wrong.
Right and the initial comment from Rahul in the code is saying so. I will move the block inside the if.
Quoted 27 lines
Quoted 19 lines
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Quoted 14 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 11 lines
xen/drivers/passthrough/pci.c +3
-0+ ret =0 ;if ( !pdev->domain ) {@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
Quoted 7 lines
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
Quoted 4 lines
pci_add_devicebeing solely used by trusted domains, I think it would be fine to require that the domain doesn't poke the PCI config space until the call topci_add_devicehas finished. Else it's likely to get inconsistent results, or mess up with the device state.
Ack.
Quoted 3 lines
In any case, such addition needs some kind of reasoning added to the commit message if it's really required.
With the code moving inside the following else and pci_cleanup_msi being empty for now on arm, I will remove the pci_cleanup_msi as it does not related directly to this change for now and might change the behaviour on x86.
If this is needed at some point due to arm, this will be done once msi support will be added.
Regards
Bertrand
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichQuoted 32 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?
Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guest
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 7 lines
xen/drivers/passthrough/pci.c +2
-0@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev ) +pci_cleanup_msi (pdev);I'm slightly lost at why you add this chunk, is this strictly related to the patch?
This was discussed a lot in previous version of the patch and requested by Stefano. The idea here is that as soon as handlers are added some bits might be modified in the PCI config space leading possibly to msi interrupts. So it is safer to cleanup on the error path. For references please see discussion on v4 and v5 where this was actually added (to much references as the discussion was long so here [1] and [2] are the patchwork thread).
Quoted 6 lines
Quoted 2 lines
[1] https://patchwork.kernel.org/project/xen-devel/patch/9bdca2cda5d2e83f94dc2423e55714273539760a.1633540842.git.rahul.singh@arm.com/
[2] https://patchwork.kernel.org/project/xen-devel/patch/f093de681c2560a7196895bcd666ef8840885c1d.1633340795.git.rahul.singh@arm.com/The addition of this call has repeatedly raised questions. This is a good indication that sufficient discussion thereof has been lacking from the patch description.
Yes and I will remove it as it only impacts x86 right now.
If this is needed, we will have to do it while adding MSI support on Arm.
Regards
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 33 lines · Bertrand Marquis
Quoted 24 lines · Jan Beulich
Quoted 9 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +5
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (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. +*/ xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 769
Quoted 10 lines
xen/drivers/passthrough/pci.c +8
-0+ ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif + ret =0 ;if ( !pdev->domain )Elsewhere I did point out that you need to be careful wrt
pdev->domainbeing NULL. As the code in context clearly documents, you're nowQuoted 8 lines
adding handlers before that field was set. In comments to a prior version I did already suggest to consider placing the new code inside the
if()in question (albeit at the time this was mainly to make clear that error cleanup may not fiddle with things not put in place by theiommu_enable_device()alternative path). This would have the further benefit of making is crystal clear that here only handlers for Dom0 would get put in place (and hence their installing for DomU-s would need to be looked for elsewhere).
Quoted 3 lines
I asked Oleksandr for confirmation here but on arm there will be 2 other use cases:
- PCI own by a DomD so device enumeration done from there
- dom0less with devices detection done inside Xen
Question is whether at this time you mean to handle all these cases. Installing handlers when device detection happens in Xen might need to be done differently, for example - e.g. more along the lines of what x86 PVH Dom0 has done.
Anything you don't mean to handle (and is safe to be left out, i.e. without breaking existing cases) will want spelling out in the description.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/pci.c +1
-0@@ -784,6 +797,9 @@ out: &PCI_SBDF(seg, bus, slot, func)); } } +else if ( pdev )Quoted 8 lines
xen/drivers/passthrough/pci.c out: · line 801
Quoted 1 line
xen/drivers/passthrough/pci.c +1
-0+pci_cleanup_msi (pdev);Have you thoroughly checked that this call is benign on x86? There's no wording to that effect in the description afaics, and I can't easily convince myself that it would be correct when the
iommu_enable_device()path was taken. (I'm also not going to exclude that it should have been there even prior to your work, albeit then adding this would want to be a separate bugfix patch.)
Quoted 3 lines
This was not in the original serie and requested by Stefano. I must admit I am not completely sure on the details here so I am really ok to remove this but this would go against what was requested on the previous versions (4 and 5).
I understand this, but a request to add something still requires that it be checked that the addition can't have bad effects in other cases. A compromise here (which I wouldn't like very much) might be to add another #ifdef CONFIG_ARM, solely to leave the existing x86 case undisturbed. Yet then, with the called function doing nothing on Arm, not adding the code here might as well be an option (which it looked like Stefano would be amenable to). A TODO item would then perhaps best be left here in a comment.
Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/pci.h +0
-0@@ -40,6 +40,9 @@#define PCI_SBDF3 (s,b,df) \ ((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) })Quoted 13 lines
xen/include/xen/pci.h line 44
Quoted 2 lines
xen/include/xen/pci.h +2
-0+#define ECAM_BDF (addr) ( ((addr) & 0x0ffff000) >> 12) +#define ECAM_REG_OFFSET (addr) ((addr) & 0x00000fff)The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().
Quoted 4 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
A final confirmation is, unfortunately, only as final as it can be at the very moment it is given. It was the MCFG vs ECAM naming discussion which made me pull out again the section in the spec, reminding me of aspects I didn't previously take into consideration. I'm sorry for this, but it's an iterative process on all sides.
So, FTAOD, as a maintainer of this headed I will continue to object to a non-spec-compliant construct to be put into here. It'll be Roger, being the vPCI maintainer, to confirm that putting it in xen/vpci.h is fine.
Quoted 1 line
Also if I have to do this I will do the same for
REG_OFFSETof course.
As said - that one, being in line with the PCI spec, is fine to remain as and where you have it.
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 36 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
Quoted 7 lines
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestAnyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
xen/drivers/passthrough/pci.c +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,check_pdev (pdev);Quoted 15 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
xen/drivers/passthrough/pci.c +12
-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. +*/ + ret =vpci_add_handlers (pdev); +if ( ret ) + { +printk (XENLOG_ERR "Setup of vPCI failed: %d\n" , ret); + goto out; + } +#endif I think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guest
Quoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)
We are only lacking some actual testing on arm32 internally.
Regards
Bertrand
Quoted 2 lines
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 56 lines · Bertrand Marquis
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
(quoted diff) +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, check_pdev(pdev);Quoted 15 lines
Review int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
(quoted diff) +12
-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. + */ + ret = vpci_add_handlers(pdev); + if ( ret ) + { + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + goto out; + } +#endifI think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestQuoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
Quoted 5 lines
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)
But somehow in the testing done you must have avoided the code path in question, or else you would have observed a crash.
Jan
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Ian JacksonHi,
Quoted 18 lines · Ian Jackson
Julien Grall writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 1 line · Ian Jackson
...
Quoted 8 lines
Quoted 3 lines
That is, as I understand it on ARM vpci should be enabled if passthrough is enabled and not otherwise. That is precisely what the variable
c_info->passthroughis.On Arm,
c_info->passthroughis also set when assigning platform devives (e.g. a non-PCI network card). At least for now, we don't want to create a node for vCPI in the Device-Tree because we don't enable the emulation. So...Oh.
Quoted 4 lines
Quoted 3 lines
3. Now you can use
d_config->c_info.passthroughto gate the addition of the additional stuff to the DT. Ie, that is a respin of this patch 3/3.
Quoted 8 lines
Quoted 1 line
... we will need to check
d_config->num_pcidevsfor the time being.OK.
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of
num_pcidevs? That might save someone some future confusion.
Here, c_info->passthrough is set to enabled if either d_config->num_pcidevs or d_config->num_dtdevs is set. Do you think we need to add there additional comment? If so can you please help with what should I write there?
BTW. None of the patch I'm preparing with regards to this discussion modifies libxl_create where c_info.passthrough i set. Do you still want me to add some comment there?
Quoted 3 lines
Thanks,
Ian.
Cheers,
Michal
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
Quoted 25 lines · Michal Orzel
Hi,
Quoted 22 lines · Ian Jackson
Julien Grall writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 1 line · Ian Jackson
...
Quoted 8 lines
Quoted 3 lines
That is, as I understand it on ARM vpci should be enabled if passthrough is enabled and not otherwise. That is precisely what the variable
c_info->passthroughis.On Arm,
c_info->passthroughis also set when assigning platform devives (e.g. a non-PCI network card). At least for now, we don't want to create a node for vCPI in the Device-Tree because we don't enable the emulation. So...Oh.
Quoted 5 lines
Quoted 3 lines
3. Now you can use
d_config->c_info.passthroughto gate the addition of the additional stuff to the DT. Ie, that is a respin of this patch 3/3.... we will need to check
d_config->num_pcidevsfor the time being.OK.
Quoted 8 lines
Quoted 4 lines
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of
num_pcidevs? That might save someone some future confusion.Here,
c_info->passthroughis set to enabled if eitherd_config->num_pcidevsord_config->num_dtdevsis set. Do you think we need to add there additional comment? If so can you please help with what should I write there?
I forgot to add a link:
https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libs/light/libxl_create.c;h=6ebb2bfc768d060fb898619be907fc973375cce5;hb=HEAD#l1099
Quoted 8 lines
BTW. None of the patch I'm preparing with regards to this discussion modifies
libxl_createwhere c_info.passthrough i set. Do you still want me to add some comment there?Quoted 3 lines
Thanks,
Ian.Cheers,
Michal
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichHi,
Quoted 59 lines · Jan Beulich
Quoted 56 lines · Bertrand Marquis
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
(quoted diff) +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, check_pdev(pdev);Quoted 15 lines
Review int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
(quoted diff) +12
-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. + */ + ret = vpci_add_handlers(pdev); + if ( ret ) + { + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + goto out; + } +#endifI think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestQuoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
Quoted 8 lines
Quoted 5 lines
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)But somehow in the testing done you must have avoided the code path in question, or else you would have observed a crash.
Device_add is always called by dom0 so we did not have issues here. Dom0less PCI passthrough implementation is not done right now.
So yes we did not go through this path.
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Jan BeulichQuoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using MMCFG_BDF was original requested by Julien, not myself I think:
https://lore.kernel.org/xen-devel/[email protected]/
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
Thanks, Roger.
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Michal OrzelMichal Orzel writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 11 lines · Ian Jackson
Quoted 3 lines
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of
num_pcidevs? That might save someone some future confusion.Here,
c_info->passthroughis set to enabled if eitherd_config->num_pcidevsord_config->num_dtdevsis set. Do you think we need to add there additional comment? If so can you please help with what should I write there?BTW. None of the patch I'm preparing with regards to this discussion modifies
libxl_createwhere c_info.passthrough i set. Do you still want me to add some comment there?
Yes, I think so. I won't insisting on it if you feel it doesn't make sense.
Maybe something like
// NB, on ARM, libxl__arch_blah directly examines num_pcidevs to // decide whether to enable vpci, rather than using c_info->passthrough. // This will be insufficient if and when ARM does PCI hotplug.
?
Ian.
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
Quoted 13 lines · Ian Jackson
Michal Orzel writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 11 lines · Ian Jackson
Quoted 3 lines
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of
num_pcidevs? That might save someone some future confusion.Here,
c_info->passthroughis set to enabled if eitherd_config->num_pcidevsord_config->num_dtdevsis set. Do you think we need to add there additional comment? If so can you please help with what should I write there?BTW. None of the patch I'm preparing with regards to this discussion modifies
libxl_createwhere c_info.passthrough i set. Do you still want me to add some comment there?
Quoted 9 lines
Yes, I think so. I won't insisting on it if you feel it doesn't make sense.
Maybe something like
// NB, on ARM,
libxl__arch_blahdirectly examinesnum_pcidevsto // decide whether to enable vpci, rather than usingc_info->passthrough. // This will be insufficient if and when ARM does PCI hotplug.
Well we are not enabling vpci. We are creating a DT node for it. So either I will write:
/*
* Note: libxl_arm directly examines num_pcidevs to decide whether
* to create a vPCI DT node, rather than using c_info->passthrough.
* This will be insufficient if and when ARM does PCI hotplug. */
or I will not add any comment (it can be add in the future when "enabling" vpci). @Julien?
Quoted 4 lines
?
Ian.
Cheers,
Michal
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
Hi Michal,
Quoted 33 lines · Michal Orzel
Quoted 13 lines · Ian Jackson
Michal Orzel writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 11 lines · Ian Jackson
Quoted 3 lines
Can you leave a comment somewhere (near where c_info.passthrough is set) pointing to this use of
num_pcidevs? That might save someone some future confusion.Here,
c_info->passthroughis set to enabled if eitherd_config->num_pcidevsord_config->num_dtdevsis set. Do you think we need to add there additional comment? If so can you please help with what should I write there?BTW. None of the patch I'm preparing with regards to this discussion modifies
libxl_createwhere c_info.passthrough i set. Do you still want me to add some comment there?Quoted 9 lines
Yes, I think so. I won't insisting on it if you feel it doesn't make sense.
Maybe something like
// NB, on ARM, libxl__arch_blah directly examines num_pcidevs to // decide whether to enable vpci, rather than using c_info->passthrough. // This will be insufficient if and when ARM does PCI hotplug.Well we are not enabling vpci. We are creating a DT node for it. So either I will write:
/*
* Note:libxl_armdirectly examinesnum_pcidevsto decide whether
* to create a vPCI DT node, rather than usingc_info->passthrough.
* This will be insufficient if and when ARM does PCI hotplug. */
Quoted 2 lines
or I will not add any comment (it can be add in the future when "enabling" vpci). @Julien?
I would prefer if we had a comment. Your proposal makes more sense as we only create the DT.
Long term, I would expect a similar check to be necessary to set the vCPI flag at the domain creation. So it would be best to introduce an internal field 'vpci' to avoid duplicating that check. (Note I am not requesting this change for Xen 4.16).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Michal OrzelMichal Orzel writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 7 lines · Ian Jackson
Quoted 5 lines
Maybe something like
// NB, on ARM,
libxl__arch_blahdirectly examinesnum_pcidevsto // decide whether to enable vpci, rather than usingc_info->passthrough. // This will be insufficient if and when ARM does PCI hotplug.
Quoted 7 lines
Well we are not enabling vpci. We are creating a DT node for it. So either I will write:
/*
* Note:libxl_armdirectly examinesnum_pcidevsto decide whether
* to create a vPCI DT node, rather than usingc_info->passthrough.
* This will be insufficient if and when ARM does PCI hotplug. */
That sounds good to me. Thank you for correcting me :-).
Ian.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Roger Pau MonnéHi Roger,
Quoted 45 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using
MMCFG_BDFwas original requested by Julien, not myself I think:
Quoted 7 lines
https://lore.kernel.org/xen-devel/[email protected]/
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
At the end my patch will add in xen/pci.h:
#define ECAM_BDF(addr) (((addr) & 0x0ffff000) >> 12)
#define ECAM_REG_OFFSET(addr) ((addr) & 0x00000fff)
Now seeing the comment the question is should those be renamed with a VPCI prefix and be moved to xen/vpci.h.
So far ECAM_BDF is only used in vpci_mmcfg_decode_addr which is only called before calling vpci_ecam_{read/write}.
ECAM_REG_OFFSET is only used in arm vpci code.
Do you think the current state is ok of the renaming + moving should be done ?
Cheers
Bertrand
Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]
In reply to Julien GrallJulien Grall writes ("Re: [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages]"):
Quoted 4 lines
Long term, I would expect a similar check to be necessary to set the vCPI flag at the domain creation. So it would be best to introduce an internal field 'vpci' to avoid duplicating that check. (Note I am not requesting this change for Xen 4.16).
Yes, I agree with all of that.
Ian.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 49 lines · Bertrand Marquis
Hi Roger,
Quoted 47 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using
MMCFG_BDFwas original requested by Julien, not myself I think:
Quoted 8 lines
Quoted 5 lines
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
At the end my patch will add in
xen/pci.h:
#defineECAM_BDF(addr)(((addr) &0x0ffff000) >> 12)
Since you still make this proposal, once again: I'm not going to accept such a macro in this header, whatever the name. Its prior placement was wrong as well. Only ...
Quoted 1 line
#define
ECAM_REG_OFFSET(addr)((addr) &0x00000fff)
... this one is fine to live here (and presumably it could gain uses elsewhere).
Jan
Quoted 13 lines
Now seeing the comment the question is should those be renamed with a VPCI prefix and be moved to
xen/vpci.h.So far
ECAM_BDFis only used invpci_mmcfg_decode_addrwhich is only called before calling vpci_ecam_{read/write}.
ECAM_REG_OFFSETis only used in arm vpci code.Do you think the current state is ok of the renaming + moving should be done ?
Cheers
Bertrand
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 61 lines · Jan Beulich
Quoted 49 lines · Bertrand Marquis
Hi Roger,
Quoted 47 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using
MMCFG_BDFwas original requested by Julien, not myself I think:Quoted 8 lines
Quoted 5 lines
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
At the end my patch will add in
xen/pci.h:
#defineECAM_BDF(addr)(((addr) &0x0ffff000) >> 12)
Quoted 8 lines
Since you still make this proposal, once again: I'm not going to accept such a macro in this header, whatever the name. Its prior placement was wrong as well. Only ...
Quoted 1 line
#define
ECAM_REG_OFFSET(addr)((addr) &0x00000fff)... this one is fine to live here (and presumably it could gain uses elsewhere).
So you would agree if they are both moved to vpci.h with a VPCI_ prefix ?
Bertrand
Quoted 15 lines
Jan
Quoted 12 lines
Now seeing the comment the question is should those be renamed with a VPCI prefix and be moved to
xen/vpci.h.So far
ECAM_BDFis only used invpci_mmcfg_decode_addrwhich is only called before calling vpci_ecam_{read/write}.
ECAM_REG_OFFSETis only used in arm vpci code.Do you think the current state is ok of the renaming + moving should be done ?
Cheers
Bertrand
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 61 lines · Bertrand Marquis
Quoted 61 lines · Jan Beulich
Quoted 46 lines · Bertrand Marquis
Quoted 46 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using
MMCFG_BDFwas original requested by Julien, not myself I think:Quoted 8 lines
Quoted 5 lines
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
At the end my patch will add in
xen/pci.h:
#defineECAM_BDF(addr)(((addr) &0x0ffff000) >> 12)Since you still make this proposal, once again: I'm not going to accept such a macro in this header, whatever the name. Its prior placement was wrong as well. Only ...
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
#define
ECAM_REG_OFFSET(addr)((addr) &0x00000fff)... this one is fine to live here (and presumably it could gain uses elsewhere).
So you would agree if they are both moved to
vpci.hwith aVPCI_prefix ?
I wouldn't object, but as said several times before I see no reason to also move and rename ECAM_REG_OFFSET(). If you moved it and if later we find a use for it outside of vPCI, we'd need to rename and move it again.
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Hi Jan,
Quoted 69 lines · Jan Beulich
Quoted 66 lines · Bertrand Marquis
Quoted 65 lines · Jan Beulich
Quoted 46 lines · Bertrand Marquis
Quoted 46 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 32 lines · Ian Jackson
Bertrand Marquis writes ("Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM."):
Quoted 12 lines
Quoted 11 lines · Jan Beulich
The latter is fine to be put here (i.e. FTAOD I'm fine with it staying here). For the former I even question its original placement in
asm-x86/pci.h: It's not generally correct as per the PCI spec, as the bus portion of the address can be anywhere from 1 to 8 bits. And in fact there is a reason why this macro was/is used in only a single place, but not e.g. in x86'es handling of physical MCFG. It is merely an implementation choice in vPCI that the entire segment 0 has a linear address range covering all 256 buses. Hence I think this wants to move toxen/vpci.hand then perhaps also be namedVPCI_ECAM_BDF().Quoted 5 lines
On previous version it was request to renamed this to ECAM and agreed to put is here. Now you want me to rename it to VPCI and move it again. I would like to have a confirmation that this is ok and the final move if possible.
@Roger can you confirm this is what is wanted ?
I think Roger is not available today I'm afraid.
Bertrand, can you give me a link to the comment from Roger ? Assuming that it says what I think it will say:
I think the best thing to do will be to leave the name as it was in the most recent version of your series. I don't think it makes sense to block this patch over a naming disagreement. And it would be best to minimise unnecessary churn.
I would be happy to release-ack a name change (perhaps proposed bo Jan or Roger) supposing that that is the ultimate maintainer consensus.
Quoted 6 lines
Quoted 1 line
Jan, would that approach be OK with you ?
Well, yes, if a subsequent name change is okay, then I could live with that. I'd still find it odd to rename a function immediately after it already got renamed. As expressed elsewhere, I suspect in his request Roger did not pay attention to a use of the function in non-ECAM code.
Using
MMCFG_BDFwas original requested by Julien, not myself I think:Quoted 8 lines
Quoted 5 lines
I'm slightly loss in so many messages. On x86 we subtract the MCFG start address from the passed one before getting the BDF, and then we add the startting bus address passed in the ACPI table. This is so far not need on Arm AFAICT because of the fixed nature of the selected virtual ECAM region.
At the end my patch will add in
xen/pci.h:
#defineECAM_BDF(addr)(((addr) &0x0ffff000) >> 12)Since you still make this proposal, once again: I'm not going to accept such a macro in this header, whatever the name. Its prior placement was wrong as well. Only ...
Quoted 1 line
#define
ECAM_REG_OFFSET(addr)((addr) &0x00000fff)... this one is fine to live here (and presumably it could gain uses elsewhere).
Quoted 6 lines
Quoted 1 line
So you would agree if they are both moved to
vpci.hwith aVPCI_prefix ?I wouldn't object, but as said several times before I see no reason to also move and rename
ECAM_REG_OFFSET(). If you moved it and if later we find a use for it outside of vPCI, we'd need to rename and move it again.
I will move BDF to vpci.h and had VPCI prefix and keep REG_OFFSET as it is and where it is then.
Cheers
Bertrand
Quoted 3 lines
Jan
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
In reply to Bertrand MarquisQuoted 56 lines · Bertrand Marquis
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
(quoted diff) +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, check_pdev(pdev);Quoted 15 lines
Review int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
(quoted diff) +12
-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. + */ + ret = vpci_add_handlers(pdev); + if ( ret ) + { + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + goto out; + } +#endifI think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestQuoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
Quoted 5 lines
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)
I thinks it's unlikely, but since I haven't checked myself, could you see if the vpci user-space test harness (tools/tests/vpci) still builds and functions properly?
Thanks, Roger.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 67 lines · Roger Pau Monné
Quoted 56 lines · Bertrand Marquis
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
(quoted diff) +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, check_pdev(pdev);Quoted 15 lines
Review int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
(quoted diff) +12
-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. + */ + ret = vpci_add_handlers(pdev); + if ( ret ) + { + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + goto out; + } +#endifI think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestQuoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
Quoted 5 lines
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)
Quoted 3 lines
I thinks it's unlikely, but since I haven't checked myself, could you see if the vpci user-space test harness (
tools/tests/vpci) still builds and functions properly?
Hi Roger,
Bertrand is going to send the v7, however I’m keen to do this test but unfortunately I’ve never used it before and I don’t have an x86 environment, do you have any resource that I can read or some guidance?
Cheers,
Luca
Quoted 3 lines
Thanks, Roger.
Re: [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Quoted 71 lines · Luca Fancellu
Quoted 67 lines · Roger Pau Monné
Quoted 56 lines · Bertrand Marquis
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 41 lines · Bertrand Marquis
Quoted 29 lines · Jan Beulich
Quoted 22 lines · Bertrand Marquis
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Bertrand Marquis
(quoted diff) +0
-0@@ -752,6 +752,19 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, check_pdev(pdev);Quoted 15 lines
Review int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 766
Quoted 12 lines
(quoted diff) +12
-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. + */ + ret = vpci_add_handlers(pdev); + if ( ret ) + { + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + goto out; + } +#endifI think
vpci_add_handlersshould be called after checking thatpdev->domainis != NULL, so I would move this chunk a bit below.Quoted 4 lines
On arm this would prevent the dom0less use case or to have the PCI bus enumerated from an other domain.
@oleksandr: can you comment on this one, you might have a better answer than me on this ?Quoted 6 lines
Well, without Xen doing the enumeration, some other entity would need to do so, including the reporting to Xen. Obviously without a Dom0 it would be ambiguous which domain to assign the device to; perhaps it should be the caller in this case? That would make that caller domain a pseudo-hwdom though, as far as PCI is concerned, which may not be desirable according to my (limited) understanding of dom0less.
This is not really related to this patch but the plan is the following:
- enumeration would have to be done by the firmware or boot loader before
- xen will have some code to detect PCI devices
- dom0less can be used to assign PCI devices to guestQuoted 5 lines
Quoted 2 lines
Anyway does not change the fact that this must be called when domain is not NULL and I will fix that.
Since we now all seem to agree that the NULL would have been a problem, may I ask in how far any of this has actually been tested?
With the whole serie currently on gitlab we have extensively tested passing through PCI devices on Arm in several configuration (number of device, MSI, MSI-X) and check that PCI was still functional on x86.
Quoted 5 lines
With the patches pushed to Xen right now it was checked that:
- xen compiles properly on arm32, arm64 and x86
- xen compiles properly with VPCI activated (using a patch) on arm32 and arm64
- xen on x86 is functionnal (using basic test on QEMU)
- xen on arm64 is functionnal (with some extensive tests on different targets)Quoted 3 lines
I thinks it's unlikely, but since I haven't checked myself, could you see if the vpci user-space test harness (
tools/tests/vpci) still builds and functions properly?
Quoted 5 lines
Hi Roger,
Bertrand is going to send the v7, however I’m keen to do this test but unfortunately I’ve never used it before and I don’t have an x86 environment, do you have any resource that I can read or some guidance?
Oh, you just need to build it (make) and then run it (make run). If it returns success everything is fine.
Regards, Roger.
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