vpci/msix: separate out common MSI-X code
cover vpci/msix: separate out common MSI-X code
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only, while the MSI-X capability handling becomes common. No functional change intended.
This is a continuation of work done by Rahul from February 2022[1].
The approach is inverted, instead of moving out the x86 parts, move out the common ones that will be needed on Arm. Subsequent arm patches for reference can be found here[2].
[1] https://lore.kernel.org/xen-devel/[email protected]/T/#t
[2] https://github.com/stewdk/xen/tree/pcie-passthrough-arm-vpci-v26
Rahul Singh (1):
vpci/msix: move helpers to common
Stewart Hildebrand (2):
vpci/msix: move msix region removal to msix.c
vpci/msix: move common msix code to common file
xen/arch/x86/include/asm/msi.h | 21 --- xen/arch/x86/msi.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 2 +- xen/drivers/vpci/Makefile | 6 +- xen/drivers/vpci/header.c | 30 +---- xen/drivers/vpci/msi.c | 3 +- xen/drivers/vpci/msix.c | 197 ++++++--------------------- xen/drivers/vpci/msix_common.c | 202 ++++++++++++++++++++++++++++ xen/drivers/vpci/private.h | 2 + xen/include/xen/msi.h | 21 +++ xen/include/xen/vpci.h | 5 + 11 files changed, 282 insertions(+), 209 deletions(-) create mode 100644 xen/drivers/vpci/msix_common.c
Signature · 1 line
2.55.0
PATCH 1/3 vpci/msix: move helpers to common
From: Rahul Singh <[email protected]>
vPCI MSI-X helpers to be used on Arm are moved to a common header.
--- xen/arch/x86/include/asm/msi.h | 21 --------------------- xen/arch/x86/msi.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 2 +- xen/drivers/vpci/msi.c | 3 +-- xen/drivers/vpci/msix.c | 2 +- xen/include/xen/msi.h | 21 +++++++++++++++++++++ 6 files changed, 25 insertions(+), 26 deletions(-)
xen/arch/x86/include/asm/msi.h +0 -21
@@ -147,27 +147,6 @@ int msi_free_irq(struct msi_desc *entry);*/ #define NR_HP_RESERVED_VECTORS 20 -#define msi_control_reg (base) ((base) + PCI_MSI_FLAGS) -#define msi_lower_address_reg (base) ((base) + PCI_MSI_ADDRESS_LO) -#define msi_upper_address_reg (base) ((base) + PCI_MSI_ADDRESS_HI) -#define msi_data_reg (base, is64bit) \ - ((base) + ((is64bit) ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32)) -#define msi_mask_bits_reg (base, is64bit) \ - ((base) + PCI_MSI_MASK_BIT - ((is64bit) ? 0 : 4)) -#define msi_pending_bits_reg (base, is64bit) \ - ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) -#define multi_msi_capable (control) \ - (1U << MASK_EXTR(control, PCI_MSI_FLAGS_QMASK)) -#define multi_msi_enable (control, num) \ - ((control) |= MASK_INSR(fls(num) - 1, PCI_MSI_FLAGS_QSIZE)) -#define is_64bit_address (control) (!!((control) & PCI_MSI_FLAGS_64BIT)) -#define is_mask_bit_support (control) (!!((control) & PCI_MSI_FLAGS_MASKBIT)) - -#define msix_control_reg (base) ((base) + PCI_MSIX_FLAGS) -#define msix_table_offset_reg (base) ((base) + PCI_MSIX_TABLE) -#define msix_pba_offset_reg (base) ((base) + PCI_MSIX_PBA) -#define msix_table_size (control) (((control) & PCI_MSIX_FLAGS_QSIZE) + 1) -/* * MSI Defined Data Structures */
xen/arch/x86/msi.c +1 -1
@@ -21,6 +21,7 @@#include <xen/iocap.h> #include <xen/keyhandler.h> #include <xen/pfn.h> +#include <xen/msi.h> #include <asm/apic.h> #include <asm/genapic.h>
@@ -29,7 +30,6 @@#include <asm/irq-vectors.h> #include <asm/smp.h> #include <asm/desc.h> -#include <asm/msi.h> #include <asm/fixmap.h> #include <asm/p2m.h>
xen/drivers/passthrough/amd/iommu.h +1 -1
@@ -26,8 +26,8 @@#include <xen/tasklet.h> #include <xen/sched.h> #include <xen/domain_page.h> +#include <xen/msi.h> -#include <asm/msi.h> #include <asm/apicdef.h> #include "iommu-defs.h"
xen/drivers/vpci/msi.c +1 -2
@@ -18,11 +18,10 @@#include "private.h" +#include <xen/msi.h> #include <xen/sched.h> #include <xen/softirq.h> -#include <asm/msi.h> - static uint32_t cf_check control_read(const struct pci_dev *pdev,unsigned int reg,void *data) {
xen/drivers/vpci/msix.c +1 -1
@@ -21,9 +21,9 @@#include <xen/io.h> #include <xen/lib.h> +#include <xen/msi.h> #include <xen/sched.h> -#include <asm/msi.h> #include <asm/p2m.h> #include <asm/x86_emulate.h>
xen/include/xen/msi.h +21 -0
@@ -7,6 +7,27 @@#include <asm/msi.h> +#define msi_control_reg (base) ((base) + PCI_MSI_FLAGS) +#define msi_lower_address_reg (base) ((base) + PCI_MSI_ADDRESS_LO) +#define msi_upper_address_reg (base) ((base) + PCI_MSI_ADDRESS_HI) +#define msi_data_reg (base, is64bit) \ + ((base) + ((is64bit) ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32)) +#define msi_mask_bits_reg (base, is64bit) \ + ((base) + PCI_MSI_MASK_BIT - ((is64bit) ? 0 : 4)) +#define msi_pending_bits_reg (base, is64bit) \ + ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) +#define multi_msi_capable (control) \ + (1U << MASK_EXTR(control, PCI_MSI_FLAGS_QMASK)) +#define multi_msi_enable (control, num) \ + ((control) |= MASK_INSR(fls(num) - 1, PCI_MSI_FLAGS_QSIZE)) +#define is_64bit_address (control) (!!((control) & PCI_MSI_FLAGS_64BIT)) +#define is_mask_bit_support (control) (!!((control) & PCI_MSI_FLAGS_MASKBIT)) + +#define msix_control_reg (base) ((base) + PCI_MSIX_FLAGS) +#define msix_table_offset_reg (base) ((base) + PCI_MSIX_TABLE) +#define msix_pba_offset_reg (base) ((base) + PCI_MSIX_PBA) +#define msix_table_size (control) (((control) & PCI_MSIX_FLAGS_QSIZE) + 1) +int pdev_msix_assign (struct domain *d,struct pci_dev *pdev);int pdev_msi_init (struct pci_dev *pdev);void pdev_msi_deinit (struct pci_dev *pdev);
Signature · 1 line
2.55.0
PATCH 2/3 vpci/msix: move msix region removal to msix.c
In reply to Mykyta PoturaiFrom: Stewart Hildebrand <[email protected]>
This code won't be used on Arm.
--- xen/drivers/vpci/header.c | 30 +++++------------------------- xen/drivers/vpci/msix.c | 35 +++++++++++++++++++++++++++++++++++ xen/drivers/vpci/private.h | 2 ++ 3 files changed, 42 insertions(+), 25 deletions(-)
xen/drivers/vpci/header.c +5 -25
@@ -310,7 +310,6 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)struct vpci_header *header = &pdev->vpci->header;struct pci_dev *tmp;const struct domain *d; -const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i, j;int rc;
@@ -405,30 +404,11 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) } } -/* Remove any MSIX regions if present. */ -for ( i =0 ; msix && i <ARRAY_SIZE (msix->tables); i++ ) - { -unsigned long start =PFN_DOWN (vmsix_table_addr (pdev->vpci, i)); -unsigned long end =PFN_DOWN (vmsix_table_addr (pdev->vpci, i) + -vmsix_table_size (pdev->vpci, i) -1 ); - -for ( j =0 ; j <ARRAY_SIZE (header->bars); j++ ) - { -const struct vpci_bar *bar = &header->bars[j]; - -if (rangeset_is_empty (bar->mem) ) -continue ; - - rc =rangeset_remove_range (bar->mem, start, end); -if ( rc ) - { -gprintk (XENLOG_WARNING , -"%pp: failed to remove MSIX table [%lx, %lx]: %d\n" , - &pdev->sbdf, start, end, rc); -return rc; - } - } - } +#ifdef CONFIG_HAS_PCI_MSI + rc =vpci_remove_msix_regions (pdev); +if ( rc ) +return rc; +#endif /* * Check for overlaps with other BARs. Note that only BARs that are
xen/drivers/vpci/msix.c +35 -0
@@ -590,6 +590,41 @@ static const struct hvm_mmio_ops vpci_msix_table_ops = { .write = msix_write, }; +int vpci_remove_msix_regions (const struct pci_dev *pdev) +{ +const struct vpci_msix *msix = pdev->vpci->msix; +struct vpci_header *header = &pdev->vpci->header; +unsigned int i, j; +int rc; + +/* Remove any MSIX regions if present. */ +for ( i =0 ; msix && i <ARRAY_SIZE (msix->tables); i++ ) + { +unsigned long start =PFN_DOWN (vmsix_table_addr (pdev->vpci, i)); +unsigned long end =PFN_DOWN (vmsix_table_addr (pdev->vpci, i) + +vmsix_table_size (pdev->vpci, i) -1 ); + +for ( j =0 ; j <ARRAY_SIZE (header->bars); j++ ) + { +const struct vpci_bar *bar = &header->bars[j]; + +if (rangeset_is_empty (bar->mem) ) +continue ; + + rc =rangeset_remove_range (bar->mem, start, end); +if ( rc ) + { +gprintk (XENLOG_WARNING , +"%pp: failed to remove MSIX table [%lx, %lx]: %d\n" , + &pdev->sbdf, start, end, rc); +return rc; + } + } + } + +return 0 ; +} +int vpci_make_msix_hole (const struct pci_dev *pdev) {struct domain *d = pdev->domain;
xen/drivers/vpci/private.h +2 -0
@@ -87,6 +87,8 @@ void cf_check vpci_hw_write16( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data);#ifdef __XEN__ +int vpci_remove_msix_regions (const struct pci_dev *pdev); +/* Make sure there's a hole in the p2m for the MSIX mmio areas. */ int vpci_make_msix_hole (const struct pci_dev *pdev);
Signature · 1 line
2.55.0
PATCH 3/3 vpci/msix: move common msix code to common file
In reply to Mykyta PoturaiFrom: Stewart Hildebrand <[email protected]>
vPCI MSI-X code dealing with intercepting the MSI-X tables and PBA won't be used on Arm. Moving this code would result in a large diffstat, so instead we move the common code to a common msix file to achieve a smaller diffstat.
--- xen/drivers/vpci/Makefile | 6 +- xen/drivers/vpci/msix.c | 160 +------------------------- xen/drivers/vpci/msix_common.c | 202 +++++++++++++++++++++++++++++++++ xen/include/xen/vpci.h | 5 + 4 files changed, 215 insertions(+), 158 deletions(-) create mode 100644 xen/drivers/vpci/msix_common.c
xen/drivers/vpci/Makefile +5 -1
@@ -1,3 +1,7 @@ obj-y += cap.o obj-y += vpci.o header.o rebar.o -obj-$(CONFIG_HAS_PCI_MSI) += msi.o msix.o +obj-$(CONFIG_HAS_PCI_MSI) += msi.o +obj-$(CONFIG_HAS_PCI_MSI) += msix_common.o +ifeq ($(CONFIG_X86),y) +obj-$(CONFIG_HAS_PCI_MSI) += msix.o +endif
xen/drivers/vpci/msix.c +3 -157
206 lines not on this page · raw message
xen/drivers/vpci/msix_common.c new file +202 -0
202 lines not on this page · raw message
xen/include/xen/vpci.h +5 -0
@@ -199,6 +199,11 @@ bool vpci_ecam_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int len,bool vpci_ecam_read (pci_sbdf_t sbdf,unsigned int reg,unsigned int len,unsigned long *data); +void vpci_msix_arch_control_write ( +const struct pci_dev *pdev,unsigned int reg,uint32_t val,void *data); +void vpci_msix_arch_cleanup (struct vpci *vpci); +void vpci_msix_arch_register (struct vpci_msix *msix,struct domain *d); +#endif /* __XEN__ */ #else /* !CONFIG_HAS_VPCI */
Signature · 1 line
2.55.0
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
Quoted 19 lines
while the MSI-X capability handling becomes common. No functional change intended.
This is a continuation of work done by Rahul from February 2022[1].
The approach is inverted, instead of moving out the x86 parts, move out the common ones that will be needed on Arm. Subsequent arm patches for reference can be found here[2].
[1] https://lore.kernel.org/xen-devel/[email protected]/T/#t
[2] https://github.com/stewdk/xen/tree/pcie-passthrough-arm-vpci-v26Rahul Singh (1):
vpci/msix: move helpers to commonStewart Hildebrand (2):
vpci/msix: move msix region removal tomsix.c
vpci/msix: move common msix code to common file
Quoted 8 lines
xen/arch/x86/include/asm/msi.h | 21 --- xen/arch/x86/msi.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 2 +- xen/drivers/vpci/Makefile | 6 +- xen/drivers/vpci/header.c | 30 +---- xen/drivers/vpci/msi.c | 3 +- xen/drivers/vpci/msix.c | 197 ++++++--------------------- xen/drivers/vpci/msix_common.c | 202 ++++++++++++++++++++++++++++
Nit: New file's names want to use dashes in favor of underscores.
Jan
Re: [PATCH v1 1/3] vpci/msix: move helpers to common
In reply to Mykyta Poturaixen/arch/x86/msi.c line 24
Quoted 9 lines · Mykyta Poturai
xen/arch/x86/msi.c +1
-0@@ -21,6 +21,7 @@#include <xen/iocap.h> #include <xen/keyhandler.h> #include <xen/pfn.h> +#include <xen/msi.h>
Please keep the headers sorted.
Probably best fixed up on commit, by whomever takes this patch.
~Andrew
Re: [PATCH v1 3/3] vpci/msix: move common msix code to common file
In reply to Mykyta PoturaiQuoted 9 lines · Mykyta Poturai
From: Stewart Hildebrand <[email protected]>
vPCI MSI-X code dealing with intercepting the MSI-X tables and PBA won't be used on Arm. Moving this code would result in a large diffstat, so instead we move the common code to a common msix file to achieve a smaller diffstat.
Signed-off-by Stewart Hildebrand <[email protected]>Signed-off-by Mykyta Poturai <[email protected]>
Quoted 7 lines
--- xen/drivers/vpci/Makefile | 6 +- xen/drivers/vpci/msix.c | 160 +------------------------- xen/drivers/vpci/msix_common.c | 202 +++++++++++++++++++++++++++++++++ xen/include/xen/vpci.h | 5 + 4 files changed, 215 insertions(+), 158 deletions(-) create mode 100644 xen/drivers/vpci/msix_common.c
Please arrange things to make the best structural sense after the change, not to optimise for minimised diffstat.
The diffstat is an instantaneous review burden. Good longterm structure is far more important.
~Andrew
Quoted 9 lines · Jan Beulich
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
Hi,
On Arm most of the work is done by the ITS, so the only thing the device needs to write to the doorbell register is the EventID. Interrupt translation is fully configured in the ITS; it will reject invalid EventIDs and also has a sideband DeviceID, so misconfigured devices cannot trigger each other's interrupts. Memory-wise everything is gated by the IOMMU, so a wrong doorbell address would not pose any risk either.
So there is no need or benefit in translating anything here.
Quoted 31 lines
Quoted 19 lines
while the MSI-X capability handling becomes common. No functional change intended.
This is a continuation of work done by Rahul from February 2022[1].
The approach is inverted, instead of moving out the x86 parts, move out the common ones that will be needed on Arm. Subsequent arm patches for reference can be found here[2].
[1] https://lore.kernel.org/xen-devel/[email protected]/T/#t
[2] https://github.com/stewdk/xen/tree/pcie-passthrough-arm-vpci-v26Rahul Singh (1):
vpci/msix: move helpers to commonStewart Hildebrand (2):
vpci/msix: move msix region removal tomsix.cvpci/msix: move common msix code to common fileQuoted 8 lines
xen/arch/x86/include/asm/msi.h | 21 --- xen/arch/x86/msi.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 2 +- xen/drivers/vpci/Makefile | 6 +- xen/drivers/vpci/header.c | 30 +---- xen/drivers/vpci/msi.c | 3 +- xen/drivers/vpci/msix.c | 197 ++++++--------------------- xen/drivers/vpci/msix_common.c | 202 ++++++++++++++++++++++++++++Nit: New file's names want to use dashes in favor of underscores.
Jan
Quoted 10 lines · Mykyta Poturai
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
Quoted 6 lines
On Arm most of the work is done by the ITS, so the only thing the device needs to write to the doorbell register is the EventID. Interrupt translation is fully configured in the ITS; it will reject invalid EventIDs and also has a sideband DeviceID, so misconfigured devices cannot trigger each other's interrupts. Memory-wise everything is gated by the IOMMU, so a wrong doorbell address would not pose any risk either.
And a guest fiddling with the mask bits behind Xen's back isn't a problem either?
Jan
Quoted 18 lines · Jan Beulich
Quoted 10 lines · Mykyta Poturai
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
Quoted 6 lines
On Arm most of the work is done by the ITS, so the only thing the device needs to write to the doorbell register is the EventID. Interrupt translation is fully configured in the ITS; it will reject invalid EventIDs and also has a sideband DeviceID, so misconfigured devices cannot trigger each other's interrupts. Memory-wise everything is gated by the IOMMU, so a wrong doorbell address would not pose any risk either.
Quoted 4 lines
And a guest fiddling with the mask bits behind Xen's back isn't a problem either?
Jan
No. Masking/unmasking an interrupt the guest has already mapped is just the guest doing its own configuration. Unmasking an unmapped interrupt will result in it being discarded by the ITS. So I don't see a problem here either.
Quoted 19 lines · Mykyta Poturai
Quoted 18 lines · Jan Beulich
Quoted 16 lines · Mykyta Poturai
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
On Arm most of the work is done by the ITS, so the only thing the device needs to write to the doorbell register is the EventID. Interrupt translation is fully configured in the ITS; it will reject invalid EventIDs and also has a sideband DeviceID, so misconfigured devices cannot trigger each other's interrupts. Memory-wise everything is gated by the IOMMU, so a wrong doorbell address would not pose any risk either.
Quoted 7 lines
Quoted 2 lines
And a guest fiddling with the mask bits behind Xen's back isn't a problem either?
No. Masking/unmasking an interrupt the guest has already mapped is just the guest doing its own configuration. Unmasking an unmapped interrupt will result in it being discarded by the ITS. So I don't see a problem here either.
IOW unlike on x86, on Arm Xen never has a need to (transiently) mask an interrupt that the guest wants / considers unmasked?
Jan
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Mykyta Poturai
Quoted 20 lines · Jan Beulich
Quoted 10 lines · Mykyta Poturai
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Mykyta Poturai
This is preparatory work to make vPCI MSI-X functional on Arm. Split the vPCI MSI-X code so that intercepting the MSI-X table and PBA stays x86 only,
This likely is related to peculiarities of Arm's interrupt handling, yet on the surface I can't see why not intercepting MSI-X table accesses would be safe. Would it be possible to extend background here a little?
Quoted 6 lines
On Arm most of the work is done by the ITS, so the only thing the device needs to write to the doorbell register is the EventID. Interrupt translation is fully configured in the ITS; it will reject invalid EventIDs and also has a sideband DeviceID, so misconfigured devices cannot trigger each other's interrupts. Memory-wise everything is gated by the IOMMU, so a wrong doorbell address would not pose any risk either.
And a guest fiddling with the mask bits behind Xen's back isn't a problem either?
Quoted 7 lines
Quoted 4 lines
No. Masking/unmasking an interrupt the guest has already mapped is just the guest doing its own configuration. Unmasking an unmapped interrupt will result in it being discarded by the ITS. So I don't see a problem here either.
IOW unlike on x86, on Arm Xen never has a need to (transiently) mask an interrupt that the guest wants / considers unmasked?
When such a need arises, the interrupt can and should be masked in the ITS. On Arm the MSI-X entry carries almost nothing - everything related to routing, mapping and masking is done in the ITS, which Xen will fully emulate.