arm64: Support GICv5-based guests
v3 cover arm64: Support GICv5-based guests
This series adds support for GICv5-based VMs to kvmtool. These are exposed as --irqchip=gicv5 and --irqchip=gicv5-its, where the former only creates a vGICv5 device and the latter adds in a GICv5 ITS. The GICv5 specification can be found at [1].
The GICv5 support in KVM needed by --irqchip=gicv5 is expected to land in Linux v7.4. KVM support for GICv5 ITS has yet to be posted, but should follow shortly. Thus, --irqchip=gicv5 works with the corresponding KVM changes, while --irqchip=gicv5-its cannot yet be used with upstream KVM.
The series teaches kvmtool to create the GICv5 irqchip and ITS KVM devices. It describes the GICv5 CPU interface, IRS and ITS in the guest DT, updates the timer and PMU interrupt descriptions, and generates GICv5 interrupt specifiers for platform devices and PCI. It also maps PCI MSI requester IDs to the ITS.
Compared with v2 [2], the work has been split into smaller patches to make the series easier to review. The IRS support is built up and exposed before the ITS support is added, as was the case previously.
Please do note: the kernel headers have not been fully synced. Only the definitions needed for this support have been added, in separate IRS and ITS patches. Before merging, the headers should be synced against the latest Linux headers.
Thanks,
Sascha
[1] https://developer.arm.com/documentation/aes0070/latest
[2] https://lore.kernel.org/all/[email protected]/
Sascha Bischoff (21):
arm64: Propagate IRQ routing initialisation errors
arm64: Close the ITS descriptor when setup fails
arm64: Sync KVM UAPI headers for GICv5 IRS
arm64: Add GICv5 irqchip device support
arm64: Track whether the VM uses GICv5
irq: Allow the initial interrupt line number to be set
arm64: Configure the GICv5 IRS
arm64: Define GICv5 interrupt types
arm64: Describe the PMU interrupt for GICv5
arm64: Describe timer PPIs for GICv5
arm64: Assign CPU DT phandles for GICv5
arm64: Describe the GICv5 CPU interface in the DT
arm64: Describe the GICv5 IRS in the DT
arm64: Generate GICv5 SPI specifiers for platform devices
arm64: Generate GICv5 PCI INTx specifiers
arm64: Expose the GICv5 irqchip option
arm64: Sync KVM UAPI headers for GICv5 ITS
arm64: Add GICv5 ITS device support
arm64: Describe the GICv5 ITS in the DT
arm64: Map PCI MSI requester IDs to the GICv5 ITS
arm64: Expose the GICv5 ITS irqchip option
arm64/fdt.c | 21 ++- arm64/gic.c | 196 +++++++++++++++++++++++++--- arm64/include/asm/kvm.h | 17 +++ arm64/include/kvm/fdt-arch.h | 1 + arm64/include/kvm/gic.h | 7 + arm64/include/kvm/kvm-arch.h | 16 +++ arm64/include/kvm/kvm-config-arch.h | 2 +- arm64/pci.c | 23 +++- arm64/pmu.c | 23 +++- arm64/timer.c | 21 ++- include/kvm/irq.h | 1 + include/linux/kvm.h | 2 + irq.c | 15 ++- 13 files changed, 306 insertions(+), 39 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/21 arm64: Propagate IRQ routing initialisation errors
irq__routing_init() can fail while allocating entries for the default routing table. gic__init_gic() currently ignores that error and continues with a partially populated table. Return the error before the VGIC is marked as initialised.
--- arm64/gic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arm64/gic.c +3 -1
@@ -344,7 +344,9 @@ static int gic__init_gic(struct kvm *kvm) } } -irq__routing_init (kvm); + ret =irq__routing_init (kvm); +if (ret) +return ret;if (!ioctl (gic_fd,KVM_HAS_DEVICE_ATTR , &vgic_init_attr)) { ret =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &vgic_init_attr);
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 01/21] arm64: Propagate IRQ routing initialisation errors
Quoted 17 lines · Sascha Bischoff
irq__routing_init()can fail while allocating entries for the default routing table.gic__init_gic()currently ignores that error and continues with a partially populated table. Return the error before the VGIC is marked as initialised.Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arm64/gic.c +0
-0@@ -344,7 +344,9 @@ static int gic__init_gic(struct kvm *kvm) }
arm64/gic.c static int gic__init_gic(struct kvm *kvm)
Quoted 10 lines
arm64/gic.c +3
-2} -irq__routing_init (kvm); + ret =irq__routing_init (kvm); +if (ret) +return ret;if (!ioctl (gic_fd,KVM_HAS_DEVICE_ATTR , &vgic_init_attr)) { ret =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &vgic_init_attr); -- 2.34.1
FWIW,
PATCH v3 2/21 arm64: Close the ITS descriptor when setup fails
In reply to Sascha Bischoffgic__create_its_frame() closes the device fd if the address attribute is unavailable, but returns without closing it if setting the address or initialising the ITS fails. Route all errors after device creation through the same close path.
--- arm64/gic.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
arm64/gic.c +12 -7
@@ -124,17 +124,22 @@ static int gic__create_its_frame(struct kvm *kvm, u64 its_frame_addr) } err =ioctl (its_device.fd,KVM_HAS_DEVICE_ATTR , &its_attr); -if (err) { -close (its_device.fd); - its_device.fd =-1 ; -return err; - } +if (err) + goto out_close; err =ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_attr);if (err) -return err; + goto out_close; -return ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_init_attr); + err =ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_init_attr); +if (err) + goto out_close; + +return 0 ; + +out_close: +close (its_device.fd); +return err; } static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type,
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 02/21] arm64: Close the ITS descriptor when setup fails
Quoted 36 lines · Sascha Bischoff
gic__create_its_frame()closes the device fd if the address attribute is unavailable, but returns without closing it if setting the address or initialising the ITS fails. Route all errors after device creation through the same close path.Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)arm64/gic.c +6
-7@@ -124,17 +124,22 @@ static int gic__create_its_frame(struct kvm *kvm, u64 its_frame_addr) } err =ioctl (its_device.fd,KVM_HAS_DEVICE_ATTR , &its_attr); -if (err) { -close (its_device.fd); - its_device.fd =-1 ; -return err; - } +if (err) + goto out_close; err =ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_attr);if (err) -return err; + goto out_close; -return ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_init_attr); + err =ioctl (its_device.fd,KVM_SET_DEVICE_ATTR , &its_init_attr); +if (err) + goto out_close;
arm64/gic.c static int gic__create_its_frame(struct kvm *kvm, u64 its_frame_addr)
Quoted 10 lines
arm64/gic.c +6
-1+ +return 0 ; + +out_close: +close (its_device.fd); +return err; } static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type, -- 2.34.1
FWIW,
PATCH v3 3/21 arm64: Sync KVM UAPI headers for GICv5 IRS
In reply to Sascha BischoffCopy the GICv5 IRS address type and size, the IRS register attribute group, and the IST attribute and descriptor from the Linux headers.
Keep the ITS UAPI out of this sync so the base GICv5 support uses only the IRS definitions already present in Linux.
--- arm64/include/asm/kvm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arm64/include/asm/kvm.h +15 -0
@@ -97,6 +97,11 @@ struct kvm_regs {#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K)#define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) +/* Supported VGICv5 address types */ +#define KVM_VGIC_V5_ADDR_TYPE_IRS 6 + +#define KVM_VGIC_V5_IRS_SIZE (2 * SZ_64K) +#define KVM_ARM_VCPU_POWER_OFF 0/* CPU is started in OFF state */ #define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2/* CPU uses PSCI v0.2 */
@@ -417,6 +422,16 @@ enum {#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ 9 +#define KVM_DEV_ARM_VGIC_GRP_IRS_REGS 10 +#define KVM_DEV_ARM_VGIC_GRP_IST 11 + +struct kvm_vgic_v5_ist { +__u64 spi_ist_addr; +__u64 spi_ist_size; +__u64 lpi_ist_addr; +__u64 lpi_ist_size; +}; +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 03/21] arm64: Sync KVM UAPI headers for GICv5 IRS
Quoted 36 lines · Sascha Bischoff
Copy the GICv5 IRS address type and size, the IRS register attribute group, and the IST attribute and descriptor from the Linux headers.
Keep the ITS UAPI out of this sync so the base GICv5 support uses only the IRS definitions already present in Linux.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/include/asm/kvm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arm64/include/asm/kvm.h +9
-0@@ -97,6 +97,11 @@ struct kvm_regs {#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K)#define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) +/* Supported VGICv5 address types */ +#define KVM_VGIC_V5_ADDR_TYPE_IRS 6 + +#define KVM_VGIC_V5_IRS_SIZE (2 * SZ_64K) +#define KVM_ARM_VCPU_POWER_OFF 0/* CPU is started in OFF state */ #define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2/* CPU uses PSCI v0.2 */ @@ -417,6 +422,16 @@ enum {#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ 9 +#define KVM_DEV_ARM_VGIC_GRP_IRS_REGS 10 +#define KVM_DEV_ARM_VGIC_GRP_IST 11 + +struct kvm_vgic_v5_ist {
arm64/include/asm/kvm.h enum {
Quoted 10 lines
arm64/include/asm/kvm.h +6
-1+__u64 spi_ist_addr; +__u64 spi_ist_size; +__u64 lpi_ist_addr; +__u64 lpi_ist_size; +}; +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) -- 2.34.1
That matches to what we expect in 7.4-rc1, so FWIW
Re: [PATCH kvmtool v3 03/21] arm64: Sync KVM UAPI headers for GICv5 IRS
Quoted 39 lines · Vladimir Murzin
Quoted 38 lines · Sascha Bischoff
Copy the GICv5 IRS address type and size, the IRS register attribute group, and the IST attribute and descriptor from the Linux headers.
Keep the ITS UAPI out of this sync so the base GICv5 support uses only the IRS definitions already present in Linux.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/include/asm/kvm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arm64/include/asm/kvm.h +12
-0@@ -97,6 +97,11 @@ struct kvm_regs {#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K)#define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) +/* Supported VGICv5 address types */ +#define KVM_VGIC_V5_ADDR_TYPE_IRS 6 + +#define KVM_VGIC_V5_IRS_SIZE (2 * SZ_64K) +#define KVM_ARM_VCPU_POWER_OFF 0/* CPU is started in OFF state */ #define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2/* CPU uses PSCI v0.2 */ @@ -417,6 +422,16 @@ enum {#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ 9 +#define KVM_DEV_ARM_VGIC_GRP_IRS_REGS 10 +#define KVM_DEV_ARM_VGIC_GRP_IST 11 + +struct kvm_vgic_v5_ist { +__u64 spi_ist_addr; +__u64 spi_ist_size; +__u64 lpi_ist_addr;
Quoted 9 lines
arm64/include/asm/kvm.h enum {
Quoted 8 lines
arm64/include/asm/kvm.h +3
-1+__u64 lpi_ist_size; +}; +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) -- 2.34.1
Hi Vladimir,
I've not added your tag here. For the new posting I'm replacing this commit with one that explicitly syncs the v7.4-rc1 headers (now that the GICv5 IRS support is in there) rather then just cherry-picking the GICv5 changes.
The ITS changes are kept separate, as before.
Quoted 3 lines
That matches to what we expect in 7.4-rc1, so FWIW
Reviewed-by Vladimir Murzin <[email protected]>
Thanks,
Sascha
PATCH v3 4/21 arm64: Add GICv5 irqchip device support
In reply to Sascha BischoffAdd IRQCHIP_GICV5 and create KVM_DEV_TYPE_ARM_VGIC_V5 for it. GICv5 has no distributor or redistributor MMIO frame, so omit those address attributes. Also omit the GICv2 PPI CPU mask from GICv5 interrupt specifiers.
--- arm64/gic.c | 19 +++++++++++++++---- arm64/include/kvm/gic.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-)
arm64/gic.c +15 -4
@@ -189,6 +189,9 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V3 ; dist_attr.attr =KVM_VGIC_V3_ADDR_TYPE_DIST ;break ; +case IRQCHIP_GICV5 : + gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V5 ; +break ;case IRQCHIP_AUTO :return -ENODEV ; }
@@ -208,15 +211,20 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)case IRQCHIP_GICV3 : err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr);break ; +case IRQCHIP_GICV5 : +break ;case IRQCHIP_AUTO :return -ENODEV ; }if (err) goto out_err; - err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); -if (err) - goto out_err; +/* Only set the dist_attr for non-GICv5 */ +if (type !=IRQCHIP_GICV5 ) { + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); +if (err) + goto out_err; + } err =gic__create_msi_frame (kvm, type, gic_msi_base);if (err)
@@ -290,6 +298,8 @@ int gic__create(struct kvm *kvm, enum irqchip_type type) gic_redists_base =ARM_GIC_DIST_BASE - gic_redists_size; gic_msi_base = gic_redists_base - gic_msi_size;break ; +case IRQCHIP_GICV5 : +break ;default :return -ENODEV ; }
@@ -440,7 +450,8 @@ u32 gic__get_fdt_irq_cpumask(struct kvm *kvm) {/* Only for GICv2 */ if (kvm->cfg.arch.irqchip ==IRQCHIP_GICV3 || - kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS ) + kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS || + kvm->cfg.arch.irqchip ==IRQCHIP_GICV5 )return 0 ;if (kvm->nrcpus >8 )
arm64/include/kvm/gic.h +1 -0
@@ -29,6 +29,7 @@ enum irqchip_type {IRQCHIP_GICV2M ,IRQCHIP_GICV3 ,IRQCHIP_GICV3_ITS , + IRQCHIP_GICV5, };struct kvm ;
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 04/21] arm64: Add GICv5 irqchip device support
Quoted 36 lines · Sascha Bischoff
Add
IRQCHIP_GICV5and createKVM_DEV_TYPE_ARM_VGIC_V5for it. GICv5 has no distributor or redistributor MMIO frame, so omit those address attributes. Also omit the GICv2 PPI CPU mask from GICv5 interrupt specifiers.Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 19 +++++++++++++++---- arm64/include/kvm/gic.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-)arm64/gic.c +5
-0@@ -189,6 +189,9 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V3 ; dist_attr.attr =KVM_VGIC_V3_ADDR_TYPE_DIST ;break ; +case IRQCHIP_GICV5 : + gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V5 ; +break ;case IRQCHIP_AUTO :return -ENODEV ; }@@ -208,15 +211,20 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)case IRQCHIP_GICV3 : err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr);break ; +case IRQCHIP_GICV5 : +break ;case IRQCHIP_AUTO :return -ENODEV ; }if (err) goto out_err;
arm64/gic.c static int gic__create_device(struct kvm *kvm, enum irqchip_type type) · line 227
Quoted 10 lines
arm64/gic.c +6
-3- err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); -if (err) - goto out_err; +/* Only set the dist_attr for non-GICv5 */ +if (type !=IRQCHIP_GICV5 ) { + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); +if (err) + goto out_err; + }
Given that we had two switch statement for irq type above, this if condition look like complete surprise to my eye :D. Asking for third switch statement is no go - gic__create_device() is already crowded. OTOH, I like approach of gic__create_msi_frame(), so what do you think about some refactoring (perhaps in separate patch), like
static int gic__set_cpu_if(enum irqchip_type type)
{
u64 cpu_if_addr = ARM_GIC_CPUI_BASE;
struct kvm_device_attr cpu_if_attr = {
.group = KVM_DEV_ARM_VGIC_GRP_ADDR,
.attr = KVM_VGIC_V2_ADDR_TYPE_CPU,
.addr = (u64)(unsigned long)&cpu_if_addr,
};
switch (type) {
case IRQCHIP_GICV2M:
case IRQCHIP_GICV2:
return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
default: /* No CPUIF needed */
return 0;
}
}static int gic__set_redist(enum irqchip_type type)
{
struct kvm_device_attr redist_attr = {
.group = KVM_DEV_ARM_VGIC_GRP_ADDR,
.attr = KVM_VGIC_V3_ADDR_TYPE_REDIST,
.addr = (u64)(unsigned long)&gic_redists_base,
};
switch (type) {
case IRQCHIP_GICV3_ITS:
case IRQCHIP_GICV3:
return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr);
default: /* No redist needed */
return 0;
}
}static int gic__set_dist(enum irqchip_type type)
{
u64 dist_addr = ARM_GIC_DIST_BASE;
struct kvm_device_attr dist_attr = {
.group = KVM_DEV_ARM_VGIC_GRP_ADDR,
.addr = (u64)(unsigned long)&dist_addr,
};
switch (type) {
case IRQCHIP_GICV2M:
case IRQCHIP_GICV2:
dist_attr.attr = KVM_VGIC_V2_ADDR_TYPE_DIST;
return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
case IRQCHIP_GICV3_ITS:
case IRQCHIP_GICV3:
dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST;
return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
default: /* No dist needed */
return 0;
}
}static int gic__create_device(struct kvm *kvm, enum irqchip_type type) {
...
gic_fd = gic_device.fd;
err = gic__set_cpu_if(type);
if (err)
goto out_err;
err = gic__set_redist(type);
if (err)
goto out_err;
err = gic__set_dist(type);
if (err)
goto out_err;
err = gic__create_msi_frame(kvm, type, gic_msi_base);
if (err)
goto out_err;...
}
You might also notice that gic_msi_base is global, so maybe there is no point keep it as function argument ;)
Quoted 13 lines
arm64/gic.c +2
-0err =gic__create_msi_frame (kvm, type, gic_msi_base);if (err)@@ -290,6 +298,8 @@ int gic__create(struct kvm *kvm, enum irqchip_type type) gic_redists_base =ARM_GIC_DIST_BASE - gic_redists_size; gic_msi_base = gic_redists_base - gic_msi_size;break ; +case IRQCHIP_GICV5 : +break ;default :return -ENODEV ; }
arm64/gic.c u32 gic__get_fdt_irq_cpumask(struct kvm *kvm) · line 455
Quoted 7 lines
arm64/gic.c +2
-1@@ -440,7 +450,8 @@ u32 gic__get_fdt_irq_cpumask(struct kvm *kvm) {/* Only for GICv2 */ if (kvm->cfg.arch.irqchip ==IRQCHIP_GICV3 || - kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS ) + kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS || + kvm->cfg.arch.irqchip ==IRQCHIP_GICV5 )return 0 ;
Nitpick: maybe we can take advantage of order of irqchip_type and do
/* Only for GICv2 */ if (kvm->cfg.arch.irqchip >= IRQCHIP_GICV3) return 0;
Thanks
Vladimir
Quoted 16 lines
arm64/gic.c +0
-0if (kvm->nrcpus >8 )arm64/include/kvm/gic.h +1
-1@@ -29,6 +29,7 @@ enum irqchip_type {IRQCHIP_GICV2M ,IRQCHIP_GICV3 ,IRQCHIP_GICV3_ITS , + IRQCHIP_GICV5, };struct kvm ; -- 2.34.1
Re: [PATCH kvmtool v3 04/21] arm64: Add GICv5 irqchip device support
Quoted 38 lines · Vladimir Murzin
Quoted 37 lines · Sascha Bischoff
Add
IRQCHIP_GICV5and createKVM_DEV_TYPE_ARM_VGIC_V5for it. GICv5 has no distributor or redistributor MMIO frame, so omit those address attributes. Also omit the GICv2 PPI CPU mask from GICv5 interrupt specifiers.Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 19 +++++++++++++++---- arm64/include/kvm/gic.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-)arm64/gic.c +5
-0@@ -189,6 +189,9 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V3 ; dist_attr.attr =KVM_VGIC_V3_ADDR_TYPE_DIST ;break ; +case IRQCHIP_GICV5 : + gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V5 ; +break ;case IRQCHIP_AUTO :return -ENODEV ; }@@ -208,15 +211,20 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)case IRQCHIP_GICV3 : err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr);break ; +case IRQCHIP_GICV5 : +break ;case IRQCHIP_AUTO :return -ENODEV ; }if (err) goto out_err;
Quoted 9 lines
arm64/gic.c static int gic__create_device(struct kvm *kvm, enum irqchip_type type) · line 227
Quoted 9 lines
arm64/gic.c +6
-3- err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); -if (err) - goto out_err; +/* Only set the dist_attr for non-GICv5 */ +if (type !=IRQCHIP_GICV5 ) { + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); +if (err) + goto out_err; + }
Hi Valdimir,
Quoted 84 lines
Given that we had two switch statement for irq type above, this if condition look like complete surprise to my eye :D. Asking for third switch statement is no go -
gic__create_device()is already crowded. OTOH, I like approach ofgic__create_msi_frame(), so what do you think about some refactoring (perhaps in separate patch), likestatic int
gic__set_cpu_if(enum irqchip_type type){ u64 cpu_if_addr = ARM_GIC_CPUI_BASE; struct kvm_device_attr cpu_if_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR, .attr = KVM_VGIC_V2_ADDR_TYPE_CPU, .addr = (u64)(unsigned long)&cpu_if_addr, }; switch (type) { case IRQCHIP_GICV2M: case IRQCHIP_GICV2: return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); default: /* No CPUIF needed */ return 0; } }static int
gic__set_redist(enum irqchip_type type){ struct kvm_device_attr redist_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR, .attr = KVM_VGIC_V3_ADDR_TYPE_REDIST, .addr = (u64)(unsigned long)&gic_redists_base, }; switch (type) { case IRQCHIP_GICV3_ITS: case IRQCHIP_GICV3: return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr); default: /* No redist needed */ return 0; } }static int
gic__set_dist(enum irqchip_type type){ u64 dist_addr = ARM_GIC_DIST_BASE; struct kvm_device_attr dist_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR, .addr = (u64)(unsigned long)&dist_addr, }; switch (type) { case IRQCHIP_GICV2M: case IRQCHIP_GICV2: dist_attr.attr = KVM_VGIC_V2_ADDR_TYPE_DIST; return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); case IRQCHIP_GICV3_ITS: case IRQCHIP_GICV3: dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST; return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); default: /* No dist needed */ return 0; } }static int
gic__create_device(struct kvm *kvm, enum irqchip_type type){
...gic_fd = gic_device.fd; err = gic__set_cpu_if(type); if (err) goto out_err; err = gic__set_redist(type); if (err) goto out_err; err = gic__set_dist(type); if (err) goto out_err; err = gic__create_msi_frame(kvm, type, gic_msi_base); if (err) goto out_err;
Quoted 5 lines
...
}Quoted 1 line
You might also notice that
gic_msi_baseis global, so maybe thereis no point keep it as function argument ;)
I think that this is a great suggestion. I've made the change and the series is so much better because of it. It is a lot more readable now, even if some of these gic__set_x() functions only do one thing, it helps to separate them out into something much more readable.
Thank you for suggesting this.
Quoted 23 lines
Quoted 13 lines
err = gic__create_msi_frame(kvm, type, gic_msi_base); if (err)arm64/gic.c +2
-0@@ -290,6 +298,8 @@ int gic__create(struct kvm *kvm, enum irqchip_type type) gic_redists_base =ARM_GIC_DIST_BASE - gic_redists_size; gic_msi_base = gic_redists_base - gic_msi_size;break ; +case IRQCHIP_GICV5 : +break ;default :return -ENODEV ; }arm64/gic.c u32 gic__get_fdt_irq_cpumask(struct kvm *kvm) · line 455
Quoted 7 lines
arm64/gic.c +2
-1@@ -440,7 +450,8 @@ u32 gic__get_fdt_irq_cpumask(struct kvm *kvm) {/* Only for GICv2 */ if (kvm->cfg.arch.irqchip ==IRQCHIP_GICV3 || - kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS ) + kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS || + kvm->cfg.arch.irqchip ==IRQCHIP_GICV5 )return 0 ;Nitpick: maybe we can take advantage of order of
irqchip_typeand do
Quoted 3 lines
/* Only for GICv2 */ if (kvm->cfg.arch.irqchip >= IRQCHIP_GICV3) return 0;
Done.
Quoted 17 lines
Thanks
VladimirQuoted 13 lines
arm64/gic.c +0
-0if (kvm->nrcpus >8 )arm64/include/kvm/gic.h +1
-0@@ -29,6 +29,7 @@ enum irqchip_type {IRQCHIP_GICV2M ,IRQCHIP_GICV3 ,IRQCHIP_GICV3_ITS , + IRQCHIP_GICV5, };
Quoted 4 lines
arm64/include/kvm/gic.h enum irqchip_type {
Quoted 3 lines
arm64/include/kvm/gic.h +0
-1struct kvm ; -- 2.34.1
Thanks,
Sascha
PATCH v3 5/21 arm64: Track whether the VM uses GICv5
In reply to Sascha BischoffExpose the selected GIC generation to interrupt and DT setup code that does not receive the irqchip type directly. Set the state only after the GIC device has been configured successfully.
--- arm64/gic.c | 7 +++++++ arm64/include/kvm/gic.h | 1 + 2 files changed, 8 insertions(+)
arm64/gic.c +7 -0
@@ -21,6 +21,12 @@ static u64 gic_redists_size;static u64 gic_msi_base;static u64 gic_msi_size =0 ;static bool vgic_is_init = false; +static bool vgic_is_v5; + +bool gic__is_v5 (void ) +{ +return vgic_is_v5; +}struct kvm_irqfd_line {unsigned int gsi;
@@ -230,6 +236,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; + vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ; out_err:
arm64/include/kvm/gic.h +1 -0
@@ -34,6 +34,7 @@ enum irqchip_type {struct kvm ; +bool gic__is_v5 (void );int gic__alloc_irqnum (void );int gic__create (struct kvm *kvm,enum irqchip_type type);int gic__create_gicv2m_frame (struct kvm *kvm,u64 msi_frame_addr);
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 05/21] arm64: Track whether the VM uses GICv5
Quoted 41 lines · Sascha Bischoff
Expose the selected GIC generation to interrupt and DT setup code that does not receive the irqchip type directly. Set the state only after the GIC device has been configured successfully.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 7 +++++++ arm64/include/kvm/gic.h | 1 + 2 files changed, 8 insertions(+)arm64/gic.c +7
-0@@ -21,6 +21,12 @@ static u64 gic_redists_size;static u64 gic_msi_base;static u64 gic_msi_size =0 ;static bool vgic_is_init = false; +static bool vgic_is_v5; + +bool gic__is_v5 (void ) +{ +return vgic_is_v5; +}struct kvm_irqfd_line {unsigned int gsi;@@ -230,6 +236,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; + vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ; out_err:arm64/include/kvm/gic.h +0
-0
arm64/include/kvm/gic.h enum irqchip_type {
Quoted 8 lines
arm64/include/kvm/gic.h +1
-1@@ -34,6 +34,7 @@ enum irqchip_type {struct kvm ; +bool gic__is_v5 (void );int gic__alloc_irqnum (void );int gic__create (struct kvm *kvm,enum irqchip_type type);int gic__create_gicv2m_frame (struct kvm *kvm,u64 msi_frame_addr); -- 2.34.1
I noticed that gic__is_v5() is used later on in places which, in theory, should not care about what exact gic type is in use. Those places are
1. adjustments for fdt generations
For that case, can we have some helpers, say
int gic__get_spi_base(void)
{
return gic_spi_base;
}int gic__get_ppi_base(void)
{
return gic_ppi_base;
}int gic__get_spi_fdt_type(void)
{
return gic_spi_fdt_type;
}int gic__get_ppi_fdt_type(void)
{
return gic_ppi_fdt_type;
}which we configure from
static int gic__create_device(struct kvm *kvm, enum irqchip_type type) {
...
err = gic__set_spi(type);
if (err)
goto out_err;
err = gic__set_ppi(type);
if (err)
goto out_err;...
}
where
static int gic__set_spi(enum irqchip_type type)
{
switch (type) {
case IRQCHIP_GICV5:
gic_spi_base = GICV5_SPI_IRQ_BASE;
gic_spi_fdt_type = GICV5_FDT_IRQ_TYPE_SPI;
break;
default:
gic_spi_base = GIC_SPI_IRQ_BASE;
gic_spi_fdt_type = GIC_FDT_IRQ_TYPE_SPI;
break;
}
return irq__init_irq_offset(gic_spi_base);
}static int gic__set_ppi(enum irqchip_type type)
{
switch (type) {
case IRQCHIP_GICV5:
gic_ppi_base = GICV5_PPI_IRQ_BASE;
gic_ppi_fdt_type = GICV5_FDT_IRQ_TYPE_PPI;
break;
default:
gic_ppi_base = GIC_PPI_IRQ_BASE;
gic_ppi_fdt_type = GIC_FDT_IRQ_TYPE_PPI;
break;
}
return 0;
}so
void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm) {
...
int_type = gic__get_spi_fdt_type();
int_id = irq - gic__get_spi_base();...
}
and
void pmu__generate_fdt_nodes(void *fdt, struct kvm *kvm) {
...
irq_prop[0] = cpu_to_fdt32(gic__get_ppi_fdt_type());
irq_prop[1] = cpu_to_fdt32(irq - gic__get_ppi_base());...
}
and
void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm) {
...
type = gic__get_ppi_fdt_type();
offset = gic__get_ppi_base();...
}
2. adjustment for IRQ line
With helpers introduced above
static int gic__init_gic(struct kvm *kvm)
{
...
nr_irqs += gic__get_spi_base();
...
}
and
void kvm__irq_line(struct kvm *kvm, int irq, int level) {
...
if (irq < gic__get_spi_base() || irq > GIC_MAX_IRQ)
...
}
}
3. PMU initialisation
Can we introduce another helper
int gic__encode_ppi_irq(enum irqchip_type type, int irq)
{
switch (type) {
case IRQCHIP_GICV5:
return irq | (GICV5_IRQ_TYPE_PPI << GICV5_IRQ_TYPE_SHIFT);
default:
return irq;
}
}so
int pmu__init(struct kvm *kvm)
{
...
irq = gic__encode_ppi_irq(kvm->cfg.arch.irqchip, irq);
...
}
4. phandle generation for CPU node(s)
We can either guard by kvm->cfg.arch.irqchip == IRQCHIP_GICV5 or, perhaps generate it unconditionally?
Cheers
Vladimir
Re: [PATCH kvmtool v3 05/21] arm64: Track whether the VM uses GICv5
Quoted 42 lines · Vladimir Murzin
Quoted 41 lines · Sascha Bischoff
Expose the selected GIC generation to interrupt and DT setup code that does not receive the irqchip type directly. Set the state only after the GIC device has been configured successfully.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 7 +++++++ arm64/include/kvm/gic.h | 1 + 2 files changed, 8 insertions(+)arm64/gic.c +7
-0@@ -21,6 +21,12 @@ static u64 gic_redists_size;static u64 gic_msi_base;static u64 gic_msi_size =0 ;static bool vgic_is_init = false; +static bool vgic_is_v5; + +bool gic__is_v5 (void ) +{ +return vgic_is_v5; +}struct kvm_irqfd_line {unsigned int gsi;@@ -230,6 +236,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; + vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ; out_err:arm64/include/kvm/gic.h +0
-0@@ -34,6 +34,7 @@ enum irqchip_type {
Quoted 8 lines
arm64/include/kvm/gic.h enum irqchip_type {
Quoted 8 lines
arm64/include/kvm/gic.h +1
-1struct kvm ; +bool gic__is_v5 (void );int gic__alloc_irqnum (void );int gic__create (struct kvm *kvm,enum irqchip_type type);int gic__create_gicv2m_frame (struct kvm *kvm,u64 msi_frame_addr); -- 2.34.1
Hi Vladimir,
I've made your suggested changes here. Thanks to making these changes, gic__is_v5() is now gone altogether, which makes me rather happy. I was always annoyed by the GICv5 tentacles throughout the code, so being able to make those things more generic is much better. Thanks again!
Quoted 100 lines
I noticed that
gic__is_v5()is used later on in places which, in theory, should not care about what exact gic type is in use. Those places are1. adjustments for fdt generations
For that case, can we have some helpers, say
int
gic__get_spi_base(void){ return gic_spi_base; }int
gic__get_ppi_base(void){ return gic_ppi_base; }int
gic__get_spi_fdt_type(void){ return gic_spi_fdt_type; }int
gic__get_ppi_fdt_type(void){ return gic_ppi_fdt_type; }which we configure from
static int
gic__create_device(struct kvm *kvm, enum irqchip_type type){
...err = gic__set_spi(type); if (err) goto out_err; err = gic__set_ppi(type); if (err) goto out_err;...
}where
static int
gic__set_spi(enum irqchip_type type){ switch (type) { case IRQCHIP_GICV5: gic_spi_base = GICV5_SPI_IRQ_BASE; gic_spi_fdt_type = GICV5_FDT_IRQ_TYPE_SPI; break; default: gic_spi_base = GIC_SPI_IRQ_BASE; gic_spi_fdt_type = GIC_FDT_IRQ_TYPE_SPI; break; } return irq__init_irq_offset(gic_spi_base); }static int
gic__set_ppi(enum irqchip_type type){ switch (type) { case IRQCHIP_GICV5: gic_ppi_base = GICV5_PPI_IRQ_BASE; gic_ppi_fdt_type = GICV5_FDT_IRQ_TYPE_PPI; break; default: gic_ppi_base = GIC_PPI_IRQ_BASE; gic_ppi_fdt_type = GIC_FDT_IRQ_TYPE_PPI; break; } return 0; }so
void
pci__generate_fdt_nodes(void *fdt, struct kvm *kvm){
...int_type = gic__get_spi_fdt_type(); int_id = irq - gic__get_spi_base();...
}and
void
pmu__generate_fdt_nodes(void *fdt, struct kvm *kvm){
...irq_prop[0] = cpu_to_fdt32(gic__get_ppi_fdt_type()); irq_prop[1] = cpu_to_fdt32(irq - gic__get_ppi_base());...
}and
Quoted 7 lines
void
timer__generate_fdt_nodes(void *fdt, struct kvm *kvm){
...type = gic__get_ppi_fdt_type(); offset = gic__get_ppi_base();...
}
Done.
Quoted 14 lines
2. adjustment for IRQ line
With helpers introduced above
static int
gic__init_gic(struct kvm *kvm)
{
...nr_irqs += gic__get_spi_base();...
}and
Quoted 8 lines
void
kvm__irq_line(struct kvm *kvm, int irq, int level){
...if (irq < gic__get_spi_base() || irq > GIC_MAX_IRQ)...
}}
Done.
Quoted 15 lines
3. PMU initialisation
Can we introduce another helper
int
gic__encode_ppi_irq(enum irqchip_type type, int irq){ switch (type) { case IRQCHIP_GICV5: return irq | (GICV5_IRQ_TYPE_PPI << GICV5_IRQ_TYPE_SHIFT); default: return irq; } }
Quoted 8 lines
so
int
pmu__init(struct kvm *kvm)
{
...irq = gic__encode_ppi_irq(kvm->cfg.arch.irqchip, irq);...
}
Done.
Quoted 5 lines
4. phandle generation for CPU node(s)
We can either guard by
kvm->cfg.arch.irqchip==IRQCHIP_GICV5or, perhaps generate it unconditionally?
And done - I've chosen to always emit them as they should not be harmful. However, if we are worried about changing existing VMs though this change, it might be better to omit them. IIRC, even unused phandles will affect the final FDT.
Quoted 4 lines
Cheers
Vladimir
Thanks,
Sascha
PATCH v3 6/21 irq: Allow the initial interrupt line number to be set
In reply to Sascha BischoffGICv5 SPIs start at zero, while earlier GICs use an offset of 32. Allow the offset to be changed before any line is allocated and set it to zero when creating a GICv5 VM.
--- arm64/gic.c | 6 ++++++ include/kvm/irq.h | 1 + irq.c | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)
arm64/gic.c +6 -0
@@ -236,6 +236,12 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; +/* GICv5 SPIs start at zero. Set this before allocating IRQs. */ +if (type ==IRQCHIP_GICV5 ) { + err =irq__init_irq_offset (0 ); +if (err) + goto out_err; + } vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ;
include/kvm/irq.h +1 -0
@@ -23,6 +23,7 @@ extern struct msi_routing_ops *msi_routing_ops;extern struct kvm_irq_routing *irq_routing;extern int next_gsi; +int irq__init_irq_offset (u8 offset);int irq__alloc_line (void );int irq__get_nr_allocated_lines (void );
irq.c +14 -1
@@ -8,6 +8,7 @@#include "kvm/irq.h" #include "kvm/kvm-arch.h" +static u8 irq_offset =KVM_IRQ_OFFSET ;static u8 next_line =KVM_IRQ_OFFSET ;static int allocated_gsis =0 ;
@@ -18,6 +19,18 @@ struct msi_routing_ops *msi_routing_ops = &irq__default_routing_ops;struct kvm_irq_routing *irq_routing =NULL ; +/* Override the default offset before the first IRQ allocation. */ +int irq__init_irq_offset (u8 offset) +{ +if (irq__get_nr_allocated_lines ()) +return -EBUSY ; + + irq_offset = offset; + next_line = offset; + +return 0 ; +} +int irq__alloc_line (void ) {return next_line++;
@@ -25,7 +38,7 @@ int irq__alloc_line(void)int irq__get_nr_allocated_lines (void ) { -return next_line -KVM_IRQ_OFFSET ; +return next_line - irq_offset; }int irq__allocate_routing_entry (void )
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 06/21] irq: Allow the initial interrupt line number to be set
Quoted 73 lines · Sascha Bischoff
GICv5 SPIs start at zero, while earlier GICs use an offset of 32. Allow the offset to be changed before any line is allocated and set it to zero when creating a GICv5 VM.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 6 ++++++ include/kvm/irq.h | 1 + irq.c | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)arm64/gic.c +6
-0@@ -236,6 +236,12 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; +/* GICv5 SPIs start at zero. Set this before allocating IRQs. */ +if (type ==IRQCHIP_GICV5 ) { + err =irq__init_irq_offset (0 ); +if (err) + goto out_err; + } vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ;include/kvm/irq.h +1
-0@@ -23,6 +23,7 @@ extern struct msi_routing_ops *msi_routing_ops;extern struct kvm_irq_routing *irq_routing;extern int next_gsi; +int irq__init_irq_offset (u8 offset);int irq__alloc_line (void );int irq__get_nr_allocated_lines (void );irq.c +13
-0@@ -8,6 +8,7 @@#include "kvm/irq.h" #include "kvm/kvm-arch.h" +static u8 irq_offset =KVM_IRQ_OFFSET ;static u8 next_line =KVM_IRQ_OFFSET ;static int allocated_gsis =0 ;@@ -18,6 +19,18 @@ struct msi_routing_ops *msi_routing_ops = &irq__default_routing_ops;struct kvm_irq_routing *irq_routing =NULL ; +/* Override the default offset before the first IRQ allocation. */ +int irq__init_irq_offset (u8 offset) +{ +if (irq__get_nr_allocated_lines ()) +return -EBUSY ; + + irq_offset = offset; + next_line = offset; + +return 0 ; +} +int irq__alloc_line (void ) {return next_line++;
irq.c int irq__alloc_line(void)
Quoted 9 lines
irq.c +1
-2@@ -25,7 +38,7 @@ int irq__alloc_line(void)int irq__get_nr_allocated_lines (void ) { -return next_line -KVM_IRQ_OFFSET ; +return next_line - irq_offset; }int irq__allocate_routing_entry (void ) -- 2.34.1
Perhaps should be split into:
- changes in generic infrastructure
- plumbing of GICv5
Cheers
Vladimir
Re: [PATCH kvmtool v3 06/21] irq: Allow the initial interrupt line number to be set
Quoted 80 lines · Vladimir Murzin
Quoted 79 lines · Sascha Bischoff
GICv5 SPIs start at zero, while earlier GICs use an offset of 32. Allow the offset to be changed before any line is allocated and set it to zero when creating a GICv5 VM.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 6 ++++++ include/kvm/irq.h | 1 + irq.c | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)arm64/gic.c +6
-0@@ -236,6 +236,12 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)if (err) goto out_err; +/* GICv5 SPIs start at zero. Set this before allocating IRQs. */ +if (type ==IRQCHIP_GICV5 ) { + err =irq__init_irq_offset (0 ); +if (err) + goto out_err; + } vgic_is_v5 = type ==IRQCHIP_GICV5 ;return 0 ;include/kvm/irq.h +1
-0@@ -23,6 +23,7 @@ extern struct msi_routing_ops *msi_routing_ops;extern struct kvm_irq_routing *irq_routing;extern int next_gsi; +int irq__init_irq_offset (u8 offset);int irq__alloc_line (void );int irq__get_nr_allocated_lines (void );irq.c +14
-1@@ -8,6 +8,7 @@#include "kvm/irq.h" #include "kvm/kvm-arch.h" +static u8 irq_offset =KVM_IRQ_OFFSET ;static u8 next_line =KVM_IRQ_OFFSET ;static int allocated_gsis =0 ;@@ -18,6 +19,18 @@ struct msi_routing_ops *msi_routing_ops = &irq__default_routing_ops;struct kvm_irq_routing *irq_routing =NULL ; +/* Override the default offset before the first IRQ allocation. */ +int irq__init_irq_offset (u8 offset) +{ +if (irq__get_nr_allocated_lines ()) +return -EBUSY ; + + irq_offset = offset; + next_line = offset; + +return 0 ; +} +int irq__alloc_line (void ) {return next_line++;@@ -25,7 +38,7 @@ int irq__alloc_line(void)int irq__get_nr_allocated_lines (void ) { -return next_line -KVM_IRQ_OFFSET ; +return next_line - irq_offset; }
Quoted 3 lines
irq.c int irq__alloc_line(void)
Quoted 3 lines
irq.c +0
-1int irq__allocate_routing_entry (void ) -- 2.34.1
Hi Vladimir,
Quoted 4 lines
Perhaps should be split into:
- changes in generic infrastructure
- plumbing of GICv5
I've created this split as you suggested.
Quoted 3 lines
Cheers
Vladimir
Thanks,
Sascha
PATCH v3 7/21 arm64: Configure the GICv5 IRS
In reply to Sascha BischoffPlace the IRS CONFIG and SETLPI frames in two 64 KiB regions below the guest AXI area, and pass the IRS base to KVM through KVM_VGIC_V5_ADDR_TYPE_IRS.
The GICv5 NR_IRQS attribute counts SPIs without the 32 SGI/PPI lines included for earlier GICs. Use that count for GICv5 while retaining the existing count for GICv2/v3. Allow zero-based GICv5 IRQ numbers when setting the level through KVM_IRQ_LINE.
--- arm64/gic.c | 16 ++++++++++++++-- arm64/include/kvm/kvm-arch.h | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-)
arm64/gic.c +14 -2
@@ -18,6 +18,7 @@static int gic_fd =-1 ;static u64 gic_redists_base;static u64 gic_redists_size; +static u64 gicv5_irs_base;static u64 gic_msi_base;static u64 gic_msi_size =0 ;static bool vgic_is_init = false;
@@ -183,6 +184,11 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) .attr = KVM_VGIC_V3_ADDR_TYPE_REDIST, .addr = (u64)(unsigned long)&gic_redists_base, }; +struct kvm_device_attr gicv5_irs_attr = { + .group =KVM_DEV_ARM_VGIC_GRP_ADDR , + .attr =KVM_VGIC_V5_ADDR_TYPE_IRS , + .addr = (u64 )(unsigned long )&gicv5_irs_base, + };switch (type) {case IRQCHIP_GICV2M :
@@ -218,6 +224,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr);break ;case IRQCHIP_GICV5 : + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &gicv5_irs_attr);break ;case IRQCHIP_AUTO :return -ENODEV ;
@@ -312,6 +319,7 @@ int gic__create(struct kvm *kvm, enum irqchip_type type) gic_msi_base = gic_redists_base - gic_msi_size;break ;case IRQCHIP_GICV5 : + gicv5_irs_base =ARM_GICV5_IRS_BASE ;break ;default :return -ENODEV ;
@@ -333,8 +341,9 @@ static int gic__init_gic(struct kvm *kvm)int ret;int lines =irq__get_nr_allocated_lines (); -u32 nr_irqs =ALIGN (lines,32 ) +GIC_SPI_IRQ_BASE ;u32 maint_irq =GIC_PPI_IRQ_BASE +GIC_MAINT_IRQ ; +u32 nr_irqs =max (ALIGN (lines,32 ),32 ); +struct kvm_device_attr nr_irqs_attr = { .group =KVM_DEV_ARM_VGIC_GRP_NR_IRQS , .addr = (u64 )(unsigned long )&nr_irqs,
@@ -348,6 +357,9 @@ static int gic__init_gic(struct kvm *kvm) .attr = KVM_DEV_ARM_VGIC_CTRL_INIT, }; +if (!gic__is_v5 ()) + nr_irqs +=GIC_SPI_IRQ_BASE ; +/* * If we didn't use the KVM_CREATE_DEVICE method, KVM will * give us some default number of interrupts. The GIC initialization
@@ -483,7 +495,7 @@ void kvm__irq_line(struct kvm *kvm, int irq, int level) .level = !!level, }; -if (irq <GIC_SPI_IRQ_BASE || irq >GIC_MAX_IRQ ) +if (!gic__is_v5 () && (irq <GIC_SPI_IRQ_BASE || irq >GIC_MAX_IRQ ))pr_warning ("Ignoring invalid GIC IRQ %d" , irq);else if (ioctl (kvm->vm_fd,KVM_IRQ_LINE , &irq_level) <0 )pr_warning ("Could not KVM_IRQ_LINE for irq %d" , irq);
arm64/include/kvm/kvm-arch.h +8 -0
@@ -57,6 +57,14 @@#define ARM_GIC_CPUI_SIZE 0x20000 +/* GICv5 IRS CONFIG and SETLPI frames occupy the end of the MMIO area. */ +#define ARM_GICV5_IRS_BASE (ARM_AXI_AREA - ARM_GICV5_IRS_SIZE) +#define ARM_GICV5_IRS_SIZE (ARM_GICV5_IRS_CONFIG_SIZE + ARM_GICV5_IRS_SETLPI_SIZE) +#define ARM_GICV5_IRS_CONFIG_BASE ARM_GICV5_IRS_BASE +#define ARM_GICV5_IRS_CONFIG_SIZE 0x10000 +#define ARM_GICV5_IRS_SETLPI_BASE (ARM_GICV5_IRS_CONFIG_BASE + ARM_GICV5_IRS_CONFIG_SIZE) +#define ARM_GICV5_IRS_SETLPI_SIZE 0x10000 +#define KVM_PCI_CFG_AREA ARM_AXI_AREA#define ARM_PCI_CFG_SIZE (1ULL << 28)#define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE)
Signature · 1 line
2.34.1
PATCH v3 8/21 arm64: Define GICv5 interrupt types
In reply to Sascha BischoffDefine the PPI and SPI type values used by GICv5 interrupt specifiers, and the type-field shift used to construct a full GICv5 INTID for KVM's PMU IRQ attribute.
--- arm64/include/kvm/gic.h | 4 ++++ 1 file changed, 4 insertions(+)
arm64/include/kvm/gic.h +4 -0
@@ -10,6 +10,10 @@#define GIC_FDT_IRQ_TYPE_SPI 0#define GIC_FDT_IRQ_TYPE_PPI 1 +#define GICV5_IRQ_TYPE_PPI 1 +#define GICV5_IRQ_TYPE_SPI 3 +#define GICV5_IRQ_TYPE_SHIFT 29 +#define GIC_FDT_IRQ_PPI_CPU_SHIFT 8#define GIC_FDT_IRQ_PPI_CPU_MASK (0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT)
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 08/21] arm64: Define GICv5 interrupt types
Quoted 14 lines · Sascha Bischoff
Define the PPI and SPI type values used by GICv5 interrupt specifiers, and the type-field shift used to construct a full GICv5 INTID for KVM's PMU IRQ attribute.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/include/kvm/gic.h | 4 ++++ 1 file changed, 4 insertions(+)arm64/include/kvm/gic.h +0
-0
arm64/include/kvm/gic.h line 16
Quoted 7 lines
arm64/include/kvm/gic.h +4
-0@@ -10,6 +10,10 @@#define GIC_FDT_IRQ_TYPE_SPI 0#define GIC_FDT_IRQ_TYPE_PPI 1 +#define GICV5_IRQ_TYPE_PPI 1 +#define GICV5_IRQ_TYPE_SPI 3 +#define GICV5_IRQ_TYPE_SHIFT 29 +
Can we also add
#define GICV5_FDT_IRQ_TYPE_PPI GICV5_IRQ_TYPE_PPI
#define GICV5_FDT_IRQ_TYPE_SPI GICV5_IRQ_TYPE_SPI
since seeing both GIC_FDT_IRQ_... and GICV5_IRQ_... back to back in FDT code is slightly confusing.
Cheers
Vladimir
Quoted 5 lines
arm64/include/kvm/gic.h +0
-1#define GIC_FDT_IRQ_PPI_CPU_SHIFT 8#define GIC_FDT_IRQ_PPI_CPU_MASK (0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT) -- 2.34.1
Re: [PATCH kvmtool v3 08/21] arm64: Define GICv5 interrupt types
Quoted 18 lines · Vladimir Murzin
Quoted 17 lines · Sascha Bischoff
Define the PPI and SPI type values used by GICv5 interrupt specifiers, and the type-field shift used to construct a full GICv5 INTID for KVM's PMU IRQ attribute.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/include/kvm/gic.h | 4 ++++ 1 file changed, 4 insertions(+)arm64/include/kvm/gic.h +0
-0@@ -10,6 +10,10 @@#define GIC_FDT_IRQ_TYPE_SPI 0#define GIC_FDT_IRQ_TYPE_PPI 1
Quoted 5 lines
arm64/include/kvm/gic.h line 16
Quoted 4 lines
arm64/include/kvm/gic.h +4
-0+#define GICV5_IRQ_TYPE_PPI 1 +#define GICV5_IRQ_TYPE_SPI 3 +#define GICV5_IRQ_TYPE_SHIFT 29 +
Hi Vladimir,
Quoted 5 lines
Can we also add
#define
GICV5_FDT_IRQ_TYPE_PPIGICV5_IRQ_TYPE_PPI
#defineGICV5_FDT_IRQ_TYPE_SPIGICV5_IRQ_TYPE_SPI
Yes, we can and I have.
Quoted 2 lines
since seeing both
GIC_FDT_IRQ_... andGICV5_IRQ_... back to back in FDT code is slightly confusing.
Yeah, agreed. For GICv5, they're both the same, but we might as well be explicit about how they are used and assuage any doubts that the reader might have.
I've made sure to use the _FDT_ variant when we're configuring the DT, and the non-_FDT_ variant otherwise.
Quoted 10 lines
Cheers
VladimirQuoted 5 lines
arm64/include/kvm/gic.h +0
-1#define GIC_FDT_IRQ_PPI_CPU_SHIFT 8#define GIC_FDT_IRQ_PPI_CPU_MASK (0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT) -- 2.34.1
Thanks,
Sascha
PATCH v3 9/21 arm64: Describe the PMU interrupt for GICv5
In reply to Sascha BischoffUse the GICv5 PPI specifier in the DT. KVM also expects the PMU IRQ attribute to contain the GICv5 interrupt type in the upper bits, so encode it before setting KVM_ARM_VCPU_PMU_V3_IRQ.
--- arm64/pmu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
arm64/pmu.c +18 -5
@@ -214,16 +214,22 @@ static int find_pmu(struct kvm *kvm)void pmu__generate_fdt_nodes (void *fdt,struct kvm *kvm) {const char compatible[] ="arm,armv8-pmuv3" ; +int irq = KVM_ARM_PMUv3_PPI; +u32 irq_prop[3 ];u32 cpu_mask =gic__get_fdt_irq_cpumask (kvm); -u32 irq_prop[] = { -cpu_to_fdt32 (GIC_FDT_IRQ_TYPE_PPI ), -cpu_to_fdt32 (KVM_ARM_PMUv3_PPI -16 ), -cpu_to_fdt32 (cpu_mask |IRQ_TYPE_LEVEL_HIGH ), - };if (!kvm->cfg.arch.has_pmuv3)return ; +if (gic__is_v5 ()) { + irq_prop[0 ] =cpu_to_fdt32 (GICV5_IRQ_TYPE_PPI ); + irq_prop[1 ] =cpu_to_fdt32 (irq); + }else { + irq_prop[0 ] =cpu_to_fdt32 (GIC_FDT_IRQ_TYPE_PPI ); + irq_prop[1 ] =cpu_to_fdt32 (irq -16 ); + } + irq_prop[2 ] =cpu_to_fdt32 (cpu_mask |IRQ_TYPE_LEVEL_HIGH ); +_FDT (fdt_begin_node (fdt,"pmu" ));_FDT (fdt_property (fdt,"compatible" , compatible,sizeof (compatible)));_FDT (fdt_property (fdt,"interrupts" , irq_prop,sizeof (irq_prop)));
@@ -248,6 +254,13 @@ int pmu__init(struct kvm *kvm) } } +/* +* For GICv5, we must encode the full IntID by adding the type (PPI) +* when setting the PMUIRQ. +*/ +if (gic__is_v5 ()) + irq |=GICV5_IRQ_TYPE_PPI <<GICV5_IRQ_TYPE_SHIFT ; +for (i =0 ; i < kvm->nrcpus; i++) { vcpu = kvm->cpus[i];set_pmu_attr (vcpu, &irq,KVM_ARM_VCPU_PMU_V3_IRQ );
Signature · 1 line
2.34.1
PATCH v3 10/21 arm64: Describe timer PPIs for GICv5
In reply to Sascha BischoffGICv5 DT specifiers use absolute PPI numbers due to having separate namespaces for the different interrupt types. Keep the existing GICv2/v3 specifiers by subtracting the legacy PPI base for those irqchips.
--- arm64/timer.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
arm64/timer.c +18 -3
@@ -9,16 +9,31 @@ void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm) {const char compatible[] ="arm,armv8-timer\0arm,armv7-timer" ;u32 cpu_mask =gic__get_fdt_irq_cpumask (kvm); -int irqs[5 ] = {13 ,14 ,11 ,10 ,12 }; +const int irqs[5 ] = {29 ,30 ,27 ,26 ,28 };int nr =ARRAY_SIZE (irqs);u32 irq_prop[nr *3 ]; +u32 type; +int offset;if (!kvm->cfg.arch.nested_virt) nr--; +/* +* For GICv5 guests, we can directly use the IRQs above in the FDT, but +* for older GICs one specifies the offset into the PPI range, which is +* adjusted using the offset below. +*/ +if (gic__is_v5 ()) { + type =GICV5_IRQ_TYPE_PPI ; + offset =0 ; + }else { + type =GIC_FDT_IRQ_TYPE_PPI ; + offset =-16 ; + } +for (int i =0 ; i < nr; i++) { - irq_prop[i *3 +0 ] =cpu_to_fdt32 (GIC_FDT_IRQ_TYPE_PPI ); - irq_prop[i *3 +1 ] =cpu_to_fdt32 (irqs[i]); + irq_prop[i *3 +0 ] =cpu_to_fdt32 (type); + irq_prop[i *3 +1 ] =cpu_to_fdt32 (irqs[i] + offset); irq_prop[i *3 +2 ] =cpu_to_fdt32 (cpu_mask |IRQ_TYPE_LEVEL_LOW ); }
Signature · 1 line
2.34.1
PATCH v3 11/21 arm64: Assign CPU DT phandles for GICv5
In reply to Sascha BischoffThe GICv5 IRS DT node maps IAFFIDs to CPU phandles. Assign stable phandles to CPU nodes when the VM uses GICv5 so the IRS node can reference them.
--- arm64/fdt.c | 2 ++ arm64/include/kvm/fdt-arch.h | 1 + 2 files changed, 3 insertions(+)
arm64/fdt.c +2 -0
@@ -54,6 +54,8 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_property_string (fdt,"enable-method" ,"psci" ));_FDT (fdt_property_cell (fdt,"reg" , mpidr)); +if (gic__is_v5 ()) +_FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_CPU_BASE + cpu));_FDT (fdt_end_node (fdt)); }
arm64/include/kvm/fdt-arch.h +1 -0
@@ -11,4 +11,5 @@ enum phandles {void generate_dma_region_prop (void *fdt); +#define PHANDLE_CPU_BASE PHANDLES_MAX#endif /* ARM__FDT_H */
Signature · 1 line
2.34.1
PATCH v3 12/21 arm64: Describe the GICv5 CPU interface in the DT
In reply to Sascha BischoffEmit an interrupt-controller node for the GICv5 CPU interface. This provides the interrupt parent and allows guests to use PPIs.
--- arm64/gic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
arm64/gic.c +20 -0
@@ -408,6 +408,8 @@ static int gic__init_gic(struct kvm *kvm) }late_init (gic__init_gic) +static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm); +void gic__generate_fdt_nodes (void *fdt,struct kvm *kvm) {const char *compatible, *msi_compatible =NULL ;
@@ -438,6 +440,8 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm) reg_prop[2 ] =cpu_to_fdt64 (gic_redists_base); reg_prop[3 ] =cpu_to_fdt64 (gic_redists_size);break ; +case IRQCHIP_GICV5 : +return gic__generate_gicv5_fdt_nodes (fdt, kvm);default :return ; }
@@ -471,6 +475,22 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_end_node (fdt)); } +static void gic__generate_gicv5_fdt_nodes (void *fdt,struct kvm *kvm) +{ +_FDT (fdt_begin_node (fdt,"gicv5-cpuif" )); +_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5" )); +_FDT (fdt_property_cell (fdt,"#interrupt-cells" ,GIC_FDT_IRQ_NUM_CELLS )); +_FDT (fdt_property (fdt,"interrupt-controller" ,NULL ,0 )); +_FDT (fdt_property_cell (fdt,"#address-cells" ,2 )); +_FDT (fdt_property_cell (fdt,"#size-cells" ,2 )); +_FDT (fdt_property (fdt,"ranges" ,NULL ,0 )); + +/* Use a hard-coded phandle for the GIC to help wire things up */ +_FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_GIC )); + +_FDT (fdt_end_node (fdt)); +} +u32 gic__get_fdt_irq_cpumask (struct kvm *kvm) {/* Only for GICv2 */
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 12/21] arm64: Describe the GICv5 CPU interface in the DT
Quoted 45 lines · Sascha Bischoff
Emit an interrupt-controller node for the GICv5 CPU interface. This provides the interrupt parent and allows guests to use PPIs.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)arm64/gic.c +14
-0@@ -408,6 +408,8 @@ static int gic__init_gic(struct kvm *kvm) }late_init (gic__init_gic) +static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm); +void gic__generate_fdt_nodes (void *fdt,struct kvm *kvm) {const char *compatible, *msi_compatible =NULL ;@@ -438,6 +440,8 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm) reg_prop[2 ] =cpu_to_fdt64 (gic_redists_base); reg_prop[3 ] =cpu_to_fdt64 (gic_redists_size);break ; +case IRQCHIP_GICV5 : +return gic__generate_gicv5_fdt_nodes (fdt, kvm);default :return ; }@@ -471,6 +475,22 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_end_node (fdt)); } +static void gic__generate_gicv5_fdt_nodes (void *fdt,struct kvm *kvm) +{ +_FDT (fdt_begin_node (fdt,"gicv5-cpuif" )); +_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5" )); +_FDT (fdt_property_cell (fdt,"#interrupt-cells" ,GIC_FDT_IRQ_NUM_CELLS )); +_FDT (fdt_property (fdt,"interrupt-controller" ,NULL ,0 )); +_FDT (fdt_property_cell (fdt,"#address-cells" ,2 )); +_FDT (fdt_property_cell (fdt,"#size-cells" ,2 )); +_FDT (fdt_property (fdt,"ranges" ,NULL ,0 )); +
arm64/gic.c void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm)
Quoted 10 lines
arm64/gic.c +6
-1+/* Use a hard-coded phandle for the GIC to help wire things up */ +_FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_GIC )); + +_FDT (fdt_end_node (fdt)); +} +u32 gic__get_fdt_irq_cpumask (struct kvm *kvm) {/* Only for GICv2 */ -- 2.34.1
FWIW,
PATCH v3 13/21 arm64: Describe the GICv5 IRS in the DT
In reply to Sascha BischoffDescribe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
--- arm64/gic.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
arm64/gic.c +35 -0
@@ -477,6 +477,16 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm)static void gic__generate_gicv5_fdt_nodes (void *fdt,struct kvm *kvm) { +char node_at_addr[64 ]; +u32 cpus[kvm->nrcpus]; +u16 iaffids[kvm->nrcpus]; +u64 irs_reg_prop[] = { +cpu_to_fdt64 (ARM_GICV5_IRS_CONFIG_BASE ), +cpu_to_fdt64 (ARM_GICV5_IRS_CONFIG_SIZE ), +cpu_to_fdt64 (ARM_GICV5_IRS_SETLPI_BASE ), +cpu_to_fdt64 (ARM_GICV5_IRS_SETLPI_SIZE ) + }; +_FDT (fdt_begin_node (fdt,"gicv5-cpuif" ));_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5" ));_FDT (fdt_property_cell (fdt,"#interrupt-cells" ,GIC_FDT_IRQ_NUM_CELLS ));
@@ -488,6 +498,31 @@ static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm)/* Use a hard-coded phandle for the GIC to help wire things up */ _FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_GIC )); +/* +* GICv5 IRS node +*/ +snprintf (node_at_addr,sizeof (node_at_addr),"irs@%llx" , + (unsigned long long )ARM_GICV5_IRS_CONFIG_BASE ); +_FDT (fdt_begin_node (fdt, node_at_addr)); +_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5-irs" )); +_FDT (fdt_property_cell (fdt,"#address-cells" ,2 )); +_FDT (fdt_property_cell (fdt,"#size-cells" ,2 )); +_FDT (fdt_property (fdt,"ranges" ,NULL ,0 )); + +_FDT (fdt_property (fdt,"reg" , irs_reg_prop,sizeof (irs_reg_prop))); +_FDT (fdt_property (fdt,"reg-names" ,"ns-config\0ns-setlpi" , +sizeof ("ns-config\0ns-setlpi" ))); + +for (int cpu =0 ; cpu < kvm->nrcpus; cpu++) { + cpus[cpu] =cpu_to_fdt32 (PHANDLE_CPU_BASE + cpu); + iaffids[cpu] =cpu_to_fdt16 (cpu); + } + +_FDT (fdt_property (fdt,"cpus" , cpus,sizeof (u32) * kvm->nrcpus)); +_FDT (fdt_property (fdt,"arm,iaffids" , iaffids,sizeof (u16) * kvm->nrcpus)); + +_FDT (fdt_end_node (fdt)); +_FDT (fdt_end_node (fdt)); }
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Out of curiosity why do we expose SETLPI frame to a guest?
Thanks
Vladimir
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Hi Vladimir,
Quoted 2 lines
Out of curiosity why do we expose SETLPI frame to a guest?
Frankly, in case we want to make use of it one day. The intent for the SETLPI frame is that is allows the injection of LPIs by a device without an ITS being present. Effectively, it gives MSI support without translation.
Rather than writing an EventID/DeviceID pair to the ITS_TRANSLATE_FRAME (specifically the ITS_TRANSLATER or ITS_RL_TRANSLATER) and having the (virtual) ITS translate them using the Device- and Interrupt-Translation-Tables, an implementation that includes the SETLPI_FRAME allows a device to directly write the LPI to make pending.
This isn't something intended for use on the physical side, so we don't strictly expect any physical implementations to include the SETLPI_FRAME (famous last words?). However, it is something that an emulated GICv5 implementation can go and do if it doesn't want the complexity of emulating an ITS.
When initially prototyping the GICv5 support, I did have a SETLPI driver that tested this mechanism, as software buy-in is also required for this to work. Instead of programming the DT/ITT with the translation, it just gives the device the desired LPI as the "event" instead.
Does that answer your question?
Quoted 3 lines
Thanks
Vladimir
Thanks,
Sascha
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Hi Sascha,
Quoted 13 lines · Sascha Bischoff
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Hi Vladimir,
Quoted 2 lines
Out of curiosity why do we expose SETLPI frame to a guest?
Frankly, in case we want to make use of it one day. The intent for the SETLPI frame is that is allows the injection of LPIs by a device without an ITS being present. Effectively, it gives MSI support without translation.
Quoted 8 lines
Rather than writing an EventID/DeviceID pair to the
ITS_TRANSLATE_FRAME(specifically theITS_TRANSLATERorITS_RL_TRANSLATER) and having the (virtual) ITS translate them using the Device- and Interrupt-Translation-Tables, an implementation that includes theSETLPI_FRAMEallows a device to directly write the LPI to make pending.This isn't something intended for use on the physical side, so we don't strictly expect any physical implementations to include the
SETLPI_FRAME(famous last words?). However, it is something that an emulated GICv5 implementation can go and do if it doesn't want the complexity of emulating an ITS.When initially prototyping the GICv5 support, I did have a SETLPI driver that tested this mechanism, as software buy-in is also required for this to work. Instead of programming the DT/ITT with the translation, it just gives the device the desired LPI as the "event" instead.
Does that answer your question?
Yes, I was mostly wondering if we are going to have any user for that, but now I realised that it could be user (selftest and/or kvm-unit-test) which make sure that SETLPI stays unimplemented :D
Cheers
Vladimir
Quoted 6 lines
Quoted 3 lines
Thanks
VladimirThanks,
Sascha
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Hi Sascha,
Quoted 17 lines · Vladimir Murzin
Hi Sascha,
Quoted 14 lines · Sascha Bischoff
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Hi Vladimir,
Quoted 1 line
Out of curiosity why do we expose SETLPI frame to a guest?
Frankly, in case we want to make use of it one day. The intent for the SETLPI frame is that is allows the injection of LPIs by a device without an ITS being present. Effectively, it gives MSI support without translation.
Rather than writing an EventID/DeviceID pair to the
ITS_TRANSLATE_FRAME(specifically theITS_TRANSLATERorITS_RL_TRANSLATER) and having the (virtual) ITS translate them using the Device- and Interrupt-Translation-Tables, an implementation that includes theSETLPI_FRAMEallows a device to directly write the LPI to make pending.This isn't something intended for use on the physical side, so we don't strictly expect any physical implementations to include the
SETLPI_FRAME(famous last words?). However, it is something that an emulated GICv5 implementation can go and do if it doesn't want the complexity of emulating an ITS.
Quoted 9 lines
Quoted 4 lines
When initially prototyping the GICv5 support, I did have a SETLPI driver that tested this mechanism, as software buy-in is also required for this to work. Instead of programming the DT/ITT with the translation, it just gives the device the desired LPI as the "event" instead.
Does that answer your question?
Yes, I was mostly wondering if we are going to have any user for that, but now I realised that it could be user (selftest and/or kvm-unit-test) which make sure that SETLPI stays unimplemented :D
Just checking, are we permitted to expose SETLPI frame with IRS_IDR0.SETLPI set to 0 (IIUC it is what KVM currently sets)?
Thanks
Vladimir
Quoted 8 lines
Cheers
VladimirQuoted 4 lines
Quoted 2 lines
Thanks
VladimirThanks,
Sascha
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Hey Vladimir,
I'm so sorry that I missed this.
Quoted 25 lines · Vladimir Murzin
Hi Sascha,
Quoted 22 lines · Vladimir Murzin
Hi Sascha,
Quoted 18 lines · Sascha Bischoff
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Hi Vladimir,
Quoted 1 line
Out of curiosity why do we expose SETLPI frame to a guest?
Frankly, in case we want to make use of it one day. The intent for the SETLPI frame is that is allows the injection of LPIs by a device without an ITS being present. Effectively, it gives MSI support without translation.
Rather than writing an EventID/DeviceID pair to the
ITS_TRANSLATE_FRAME(specifically theITS_TRANSLATERorITS_RL_TRANSLATER) and having the (virtual) ITS translate them using the Device- and Interrupt-Translation-Tables, an implementation that includes theSETLPI_FRAMEallows a device to directly write the LPI to make pending.This isn't something intended for use on the physical side, so we don't strictly expect any physical implementations to include the
SETLPI_FRAME(famous last words?). However, it is something that an emulated GICv5 implementation can go and do if it doesn't want the complexity of emulating an ITS.When initially prototyping the GICv5 support, I did have a SETLPI driver that tested this mechanism, as software buy-in is also required for this to work. Instead of programming the DT/ITT with the translation, it just gives the device the desired LPI as the "event" instead.
Does that answer your question?
Quoted 7 lines
Quoted 4 lines
Yes, I was mostly wondering if we are going to have any user for that, but now I realised that it could be user (selftest and/or kvm-unit-test) which make sure that SETLPI stays unimplemented :D
Just checking, are we permitted to expose SETLPI frame with IRS_IDR0.SETLPI set to 0 (IIUC it is what KVM currently sets)?
That's a really valid point, and I don't think I should do this. For whatever reason, this didn't click until just now.
I was thinking along the lines of "KVM carves out the memory for SETLPI so we should convey it in the DT", but that's silly. We shouldn't give the guest what is effectively a broken DT for the system it sees. KVM indeed doesn't expose the SETLPI feature to a guest via the emulated IRS's MMIO, so this would be a mismatch.
I'll drop the SETLPI frame part when I post a v6. Doh!
Thank you!
Sascha
Quoted 13 lines
Thanks
VladimirQuoted 8 lines
Cheers
VladimirQuoted 4 lines
Quoted 2 lines
Thanks
VladimirThanks,
Sascha
Re: [PATCH kvmtool v3 13/21] arm64: Describe the GICv5 IRS in the DT
Quoted 35 lines · Sascha Bischoff
Hey Vladimir,
I'm so sorry that I missed this.
Quoted 30 lines · Vladimir Murzin
Hi Sascha,
Quoted 26 lines · Vladimir Murzin
Hi Sascha,
Quoted 10 lines · Sascha Bischoff
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · Sascha Bischoff
Describe the IRS CONFIG and SETLPI frames and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.
Hi Vladimir,
Quoted 1 line
Out of curiosity why do we expose SETLPI frame to a guest?
Frankly, in case we want to make use of it one day. The intent for the SETLPI frame is that is allows the injection of LPIs by a device without an ITS being present. Effectively, it gives MSI support without translation.
Quoted 8 lines
Rather than writing an EventID/DeviceID pair to the
ITS_TRANSLATE_FRAME(specifically theITS_TRANSLATERorITS_RL_TRANSLATER) and having the (virtual) ITS translate them using the Device- and Interrupt-Translation-Tables, an implementation that includes theSETLPI_FRAMEallows a device to directly write the LPI to make pending.This isn't something intended for use on the physical side, so we don't strictly expect any physical implementations to include the
SETLPI_FRAME(famous last words?). However, it is something that an emulated GICv5 implementation can go and do if it doesn't want the complexity of emulating an ITS.When initially prototyping the GICv5 support, I did have a SETLPI driver that tested this mechanism, as software buy-in is also required for this to work. Instead of programming the DT/ITT with the translation, it just gives the device the desired LPI as the "event" instead.
Does that answer your question?
Yes, I was mostly wondering if we are going to have any user for that, but now I realised that it could be user (selftest and/or kvm-unit-test) which make sure that SETLPI stays unimplemented :D
Quoted 9 lines
Quoted 2 lines
Just checking, are we permitted to expose SETLPI frame with IRS_IDR0.SETLPI set to 0 (IIUC it is what KVM currently sets)?
That's a really valid point, and I don't think I should do this. For whatever reason, this didn't click until just now.
I was thinking along the lines of "KVM carves out the memory for SETLPI so we should convey it in the DT", but that's silly. We shouldn't give the guest what is effectively a broken DT for the system it sees. KVM indeed doesn't expose the SETLPI feature to a guest via the emulated IRS's MMIO, so this would be a mismatch.
I'll drop the SETLPI frame part when I post a v6. Doh!
Thanks! I'm glad we came to consensus on SETLPI, after all we can revisit if/when we really need it ;)
Cheers
Vladimir
Quoted 18 lines
Thank you!
SaschaQuoted 13 lines
Thanks
VladimirQuoted 8 lines
Cheers
VladimirQuoted 4 lines
Quoted 2 lines
Thanks
VladimirThanks,
Sascha
PATCH v3 14/21 arm64: Generate GICv5 SPI specifiers for platform devices
In reply to Sascha BischoffUse the GICv5 interrupt type and absolute SPI number for platform devices. Preserve the legacy GICv2/v3 DT encoding for other VMs.
--- arm64/fdt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
arm64/fdt.c +14 -5
@@ -64,11 +64,20 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)static void generate_irq_prop (void *fdt,u8 irq,enum irq_type irq_type) { -u32 irq_prop[] = { -cpu_to_fdt32 (GIC_FDT_IRQ_TYPE_SPI ), -cpu_to_fdt32 (irq -GIC_SPI_IRQ_BASE ), -cpu_to_fdt32 (irq_type) - }; +u32 irq_prop[3 ]; +u32 type, intid; + +if (gic__is_v5 ()) { + type =GICV5_IRQ_TYPE_SPI ; + intid = irq; + }else { + type =GIC_FDT_IRQ_TYPE_SPI ; + intid = irq -GIC_SPI_IRQ_BASE ; + } + + irq_prop[0 ] =cpu_to_fdt32 (type); + irq_prop[1 ] =cpu_to_fdt32 (intid); + irq_prop[2 ] =cpu_to_fdt32 (irq_type);_FDT (fdt_property (fdt,"interrupts" , irq_prop,sizeof (irq_prop))); }
Signature · 1 line
2.34.1
PATCH v3 15/21 arm64: Generate GICv5 PCI INTx specifiers
In reply to Sascha BischoffPCI interrupt-map entries currently use the GICv2/v3 SPI type and an IRQ number with the SPI base subtracted. GICv5 uses a different SPI type (matching the hardware) and zero-based SPI numbers. Use the GICv5 encoding for its INTx entries while retaining the existing encoding for other GICs.
--- arm64/pci.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arm64/pci.c +11 -2
@@ -84,6 +84,7 @@ void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm)u8 pin = pci_hdr->irq_pin;u8 irq = pci_hdr->irq_line;u32 irq_flags = pci_hdr->irq_type; +u32 int_type, int_id;/* * Avoid adding entries in "interrupt-map" for devices that
@@ -95,6 +96,14 @@ void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm)continue ; } +if (!gic__is_v5 ()) { + int_type =GIC_FDT_IRQ_TYPE_SPI ; + int_id = irq -GIC_SPI_IRQ_BASE ; + }else { + int_type =GICV5_IRQ_TYPE_SPI ; + int_id = irq; + } + *entry = (struct of_interrupt_map_entry ) { .pci_irq_mask = { .pci_addr = {
@@ -108,8 +117,8 @@ void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm) .gic_addr_hi = 0, .gic_addr_lo = 0, .gic_irq = { - .type = cpu_to_fdt32(GIC_FDT_IRQ_TYPE_SPI), - .num = cpu_to_fdt32(irq - GIC_SPI_IRQ_BASE), + .type = cpu_to_fdt32(int_type), + .num = cpu_to_fdt32(int_id), .flags = cpu_to_fdt32(irq_flags), }, };
Signature · 1 line
2.34.1
PATCH v3 16/21 arm64: Expose the GICv5 irqchip option
In reply to Sascha BischoffAllow --irqchip=gicv5 and prefer GICv5 for automatic irqchip selection when the kernel supports it. The IRS and guest DT support are now in place.
--- arm64/gic.c | 4 +++- arm64/include/kvm/kvm-config-arch.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
arm64/gic.c +3 -1
@@ -50,6 +50,8 @@ int irqchip_parser(const struct option *opt, const char *arg, int unset) *type =IRQCHIP_GICV3 ; }else if (!strcmp (arg,"gicv3-its" )) { *type =IRQCHIP_GICV3_ITS ; + }else if (!strcmp (arg,"gicv5" )) { + *type =IRQCHIP_GICV5 ; }else {pr_err ("irqchip: unknown type \"%s\"\n" , arg);return -1 ;
@@ -293,7 +295,7 @@ int gic__create(struct kvm *kvm, enum irqchip_type type)switch (type) {case IRQCHIP_AUTO : -for (try =IRQCHIP_GICV3_ITS ; try >=IRQCHIP_GICV2 ; try--) { +for (try =IRQCHIP_GICV5 ; try >=IRQCHIP_GICV2 ; try--) { err =gic__create (kvm, try);if (!err)break ;
arm64/include/kvm/kvm-config-arch.h +1 -1
@@ -59,7 +59,7 @@ int sve_vl_parser(const struct option *opt, const char *arg, int unset); "transport (Deprecated: Use --virtio-transport " \ "option instead)", virtio_transport_parser, kvm), \OPT_CALLBACK ('\0' ,"irqchip" , &(cfg)->irqchip, \ -"[gicv2|gicv2m|gicv3|gicv3-its]" , \ +"[gicv2|gicv2m|gicv3|gicv3-its|gicv5]" , \"Type of interrupt controller to emulate in the guest" , \ irqchip_parser,NULL ), \ OPT_U64('\0', "firmware-address", &(cfg)->fw_addr, \
Signature · 1 line
2.34.1
Re: [PATCH kvmtool v3 16/21] arm64: Expose the GICv5 irqchip option
Quoted 38 lines · Sascha Bischoff
Allow --irqchip=gicv5 and prefer GICv5 for automatic irqchip selection when the kernel supports it. The IRS and guest DT support are now in place.
Signed-off-by Sascha Bischoff <[email protected]>--- arm64/gic.c | 4 +++- arm64/include/kvm/kvm-config-arch.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)arm64/gic.c +3
-1@@ -50,6 +50,8 @@ int irqchip_parser(const struct option *opt, const char *arg, int unset) *type =IRQCHIP_GICV3 ; }else if (!strcmp (arg,"gicv3-its" )) { *type =IRQCHIP_GICV3_ITS ; + }else if (!strcmp (arg,"gicv5" )) { + *type =IRQCHIP_GICV5 ; }else {pr_err ("irqchip: unknown type \"%s\"\n" , arg);return -1 ;@@ -293,7 +295,7 @@ int gic__create(struct kvm *kvm, enum irqchip_type type)switch (type) {case IRQCHIP_AUTO : -for (try =IRQCHIP_GICV3_ITS ; try >=IRQCHIP_GICV2 ; try--) { +for (try =IRQCHIP_GICV5 ; try >=IRQCHIP_GICV2 ; try--) { err =gic__create (kvm, try);if (!err)break ;arm64/include/kvm/kvm-config-arch.h +0
-0
arm64/include/kvm/kvm-config-arch.h int sve_vl_parser(const struct option *opt, const char *arg, int unset);
Quoted 9 lines
arm64/include/kvm/kvm-config-arch.h +1
-2@@ -59,7 +59,7 @@ int sve_vl_parser(const struct option *opt, const char *arg, int unset); "transport (Deprecated: Use --virtio-transport " \ "option instead)", virtio_transport_parser, kvm), \OPT_CALLBACK ('\0' ,"irqchip" , &(cfg)->irqchip, \ - "[gicv2|gicv2m|gicv3|gicv3-its]", \ +"[gicv2|gicv2m|gicv3|gicv3-its|gicv5]" , \"Type of interrupt controller to emulate in the guest" , \ irqchip_parser,NULL ), \ OPT_U64('\0', "firmware-address", &(cfg)->fw_addr, \ -- 2.34.1
FWIW,
PATCH v3 17/21 arm64: Sync KVM UAPI headers for GICv5 ITS
In reply to Sascha BischoffCopy the GICv5 ITS device type, address type and size from the Linux headers.
--- arm64/include/asm/kvm.h | 2 ++ include/linux/kvm.h | 2 ++ 2 files changed, 4 insertions(+)
arm64/include/asm/kvm.h +2 -0
@@ -99,8 +99,10 @@ struct kvm_regs {/* Supported VGICv5 address types */ #define KVM_VGIC_V5_ADDR_TYPE_IRS 6 +#define KVM_VGIC_V5_ADDR_TYPE_ITS 7#define KVM_VGIC_V5_IRS_SIZE (2 * SZ_64K) +#define KVM_VGIC_V5_ITS_SIZE (2 * SZ_64K)#define KVM_ARM_VCPU_POWER_OFF 0/* CPU is started in OFF state */ #define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */
include/linux/kvm.h +2 -0
@@ -1235,6 +1235,8 @@ enum kvm_device_type {#define KVM_DEV_TYPE_LOONGARCH_DMSINTC KVM_DEV_TYPE_LOONGARCH_DMSINTC KVM_DEV_TYPE_ARM_VGIC_V5,#define KVM_DEV_TYPE_ARM_VGIC_V5 KVM_DEV_TYPE_ARM_VGIC_V5 + KVM_DEV_TYPE_ARM_VGIC_V5_ITS, +#define KVM_DEV_TYPE_ARM_VGIC_V5_ITS KVM_DEV_TYPE_ARM_VGIC_V5_ITS KVM_DEV_TYPE_MAX,
Signature · 1 line
2.34.1
PATCH v3 18/21 arm64: Add GICv5 ITS device support
In reply to Sascha BischoffAllow the GICv5 ITS irqchip to create a separate KVM ITS device and place its CONFIG and TRANSLATE frames immediately below the IRS. Reuse the ITS creation helper for GICv3 and GICv5, selecting the device and address types for each model.
At this stage, --irqchip=gicv5-its is not yet exposed, and automatic irqchip selection starts with GICv5.
--- arm64/gic.c | 31 +++++++++++++++++++++---------- arm64/include/kvm/gic.h | 1 + arm64/include/kvm/kvm-arch.h | 8 ++++++++ 3 files changed, 30 insertions(+), 10 deletions(-)
arm64/gic.c +21 -10
@@ -108,15 +108,15 @@ static int irq__routing_init(struct kvm *kvm)return 0 ; } -static int gic__create_its_frame (struct kvm *kvm,u64 its_frame_addr) +static int gic__create_its_frame (struct kvm *kvm,u64 its_frame_addr,const bool v5) {struct kvm_create_device its_device = { - .type =KVM_DEV_TYPE_ARM_VGIC_ITS , + .type = v5 ?KVM_DEV_TYPE_ARM_VGIC_V5_ITS :KVM_DEV_TYPE_ARM_VGIC_ITS , .flags =0 , };struct kvm_device_attr its_attr = { .group =KVM_DEV_ARM_VGIC_GRP_ADDR , - .attr =KVM_VGIC_ITS_ADDR_TYPE , + .attr = v5 ?KVM_VGIC_V5_ADDR_TYPE_ITS :KVM_VGIC_ITS_ADDR_TYPE , .addr = (u64 )(unsigned long )&its_frame_addr, };struct kvm_device_attr its_init_attr = {
@@ -127,8 +127,9 @@ static int gic__create_its_frame(struct kvm *kvm, u64 its_frame_addr) err =ioctl (kvm->vm_fd,KVM_CREATE_DEVICE , &its_device);if (err) { -pr_err ("GICv3 ITS requested, but kernel does not support it." ); -pr_err ("Try --irqchip=gicv3 instead" ); +pr_err ("GICv%c ITS requested, but kernel does not support it." , + v5 ?'5' :'3' ); +pr_err ("Try --irqchip=gicv%c instead" , v5 ?'5' :'3' );return err; }
@@ -158,7 +159,9 @@ static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type,case IRQCHIP_GICV2M :return gic__create_gicv2m_frame (kvm, msi_frame_addr);case IRQCHIP_GICV3_ITS : -return gic__create_its_frame (kvm, msi_frame_addr); +return gic__create_its_frame (kvm, msi_frame_addr, false); +case IRQCHIP_GICV5_ITS : +return gic__create_its_frame (kvm, msi_frame_addr, true);default :/* No MSI frame needed */ return 0 ; }
@@ -203,6 +206,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V3 ; dist_attr.attr =KVM_VGIC_V3_ADDR_TYPE_DIST ;break ; +case IRQCHIP_GICV5_ITS :case IRQCHIP_GICV5 : gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V5 ;break ;
@@ -226,6 +230,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr);break ;case IRQCHIP_GICV5 : +case IRQCHIP_GICV5_ITS : err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &gicv5_irs_attr);break ;case IRQCHIP_AUTO :
@@ -235,7 +240,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) goto out_err;/* Only set the dist_attr for non-GICv5 */ -if (type !=IRQCHIP_GICV5 ) { +if (type !=IRQCHIP_GICV5 && type !=IRQCHIP_GICV5_ITS ) { err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr);if (err) goto out_err;
@@ -246,12 +251,12 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) goto out_err;/* GICv5 SPIs start at zero. Set this before allocating IRQs. */ -if (type ==IRQCHIP_GICV5 ) { +if (type ==IRQCHIP_GICV5 || type ==IRQCHIP_GICV5_ITS ) { err =irq__init_irq_offset (0 );if (err) goto out_err; } - vgic_is_v5 = type ==IRQCHIP_GICV5 ; + vgic_is_v5 = type ==IRQCHIP_GICV5 || type ==IRQCHIP_GICV5_ITS ;return 0 ; out_err:
@@ -320,6 +325,11 @@ int gic__create(struct kvm *kvm, enum irqchip_type type) gic_redists_base =ARM_GIC_DIST_BASE - gic_redists_size; gic_msi_base = gic_redists_base - gic_msi_size;break ; +case IRQCHIP_GICV5_ITS : + gic_msi_base =ARM_GICV5_ITS_BASE ; + gic_msi_size =ARM_GICV5_ITS_SIZE ; + gicv5_irs_base =ARM_GICV5_IRS_BASE ; +break ;case IRQCHIP_GICV5 : gicv5_irs_base =ARM_GICV5_IRS_BASE ;break ;
@@ -533,7 +543,8 @@ u32 gic__get_fdt_irq_cpumask(struct kvm *kvm)/* Only for GICv2 */ if (kvm->cfg.arch.irqchip ==IRQCHIP_GICV3 || kvm->cfg.arch.irqchip ==IRQCHIP_GICV3_ITS || - kvm->cfg.arch.irqchip ==IRQCHIP_GICV5 ) + kvm->cfg.arch.irqchip ==IRQCHIP_GICV5 || + kvm->cfg.arch.irqchip ==IRQCHIP_GICV5_ITS )return 0 ;if (kvm->nrcpus >8 )
arm64/include/kvm/gic.h +1 -0
@@ -34,6 +34,7 @@ enum irqchip_type {IRQCHIP_GICV3 ,IRQCHIP_GICV3_ITS ,IRQCHIP_GICV5 , + IRQCHIP_GICV5_ITS, };struct kvm ;
arm64/include/kvm/kvm-arch.h +8 -0
@@ -65,6 +65,14 @@#define ARM_GICV5_IRS_SETLPI_BASE (ARM_GICV5_IRS_CONFIG_BASE + ARM_GICV5_IRS_CONFIG_SIZE)#define ARM_GICV5_IRS_SETLPI_SIZE 0x10000 +/* GICv5 ITS CONFIG and TRANSLATE frames precede the IRS frames. */ +#define ARM_GICV5_ITS_BASE (ARM_GICV5_IRS_BASE - ARM_GICV5_ITS_SIZE) +#define ARM_GICV5_ITS_SIZE (ARM_GICV5_ITS_CONFIG_SIZE + ARM_GICV5_ITS_TRANSL_SIZE) +#define ARM_GICV5_ITS_CONFIG_BASE ARM_GICV5_ITS_BASE +#define ARM_GICV5_ITS_CONFIG_SIZE 0x10000 +#define ARM_GICV5_ITS_TRANSL_BASE (ARM_GICV5_ITS_CONFIG_BASE + ARM_GICV5_ITS_CONFIG_SIZE) +#define ARM_GICV5_ITS_TRANSL_SIZE 0x10000 +#define KVM_PCI_CFG_AREA ARM_AXI_AREA#define ARM_PCI_CFG_SIZE (1ULL << 28)#define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE)
Signature · 1 line
2.34.1
PATCH v3 19/21 arm64: Describe the GICv5 ITS in the DT
In reply to Sascha BischoffAdd an ITS node below the GICv5 IRS node with the CONFIG frame as its register region. Add an MSI controller child node for the TRANSLATE frame, with a phandle and one MSI cell carrying the DeviceID.
--- arm64/gic.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
arm64/gic.c +41 -0
@@ -452,6 +452,7 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm) reg_prop[2 ] =cpu_to_fdt64 (gic_redists_base); reg_prop[3 ] =cpu_to_fdt64 (gic_redists_size);break ; +case IRQCHIP_GICV5_ITS :case IRQCHIP_GICV5 :return gic__generate_gicv5_fdt_nodes (fdt, kvm);default :
@@ -499,6 +500,16 @@ static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm)cpu_to_fdt64 (ARM_GICV5_IRS_SETLPI_SIZE) }; +u64 its_config_reg_prop[] = { +cpu_to_fdt64 (ARM_GICV5_ITS_CONFIG_BASE ), +cpu_to_fdt64 (ARM_GICV5_ITS_CONFIG_SIZE ), + }; + +u64 its_trans_reg_prop[] = { +cpu_to_fdt64 (ARM_GICV5_ITS_TRANSL_BASE ), +cpu_to_fdt64 (ARM_GICV5_ITS_TRANSL_SIZE ) + }; +_FDT (fdt_begin_node (fdt,"gicv5-cpuif" ));_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5" ));_FDT (fdt_property_cell (fdt,"#interrupt-cells" ,GIC_FDT_IRQ_NUM_CELLS ));
@@ -533,6 +544,36 @@ static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_property (fdt,"cpus" , cpus,sizeof (u32) * kvm->nrcpus));_FDT (fdt_property (fdt,"arm,iaffids" , iaffids,sizeof (u16) * kvm->nrcpus)); +if (kvm->cfg.arch.irqchip ==IRQCHIP_GICV5_ITS ) { +/* +* GICv5 ITS node +*/ +snprintf (node_at_addr,sizeof (node_at_addr),"its@%llx" , + (unsigned long long )ARM_GICV5_ITS_CONFIG_BASE ); +_FDT (fdt_begin_node (fdt, node_at_addr)); +_FDT (fdt_property_string (fdt,"compatible" ,"arm,gic-v5-its" )); +_FDT (fdt_property_cell (fdt,"#address-cells" ,2 )); +_FDT (fdt_property_cell (fdt,"#size-cells" ,2 )); +_FDT (fdt_property (fdt,"ranges" ,NULL ,0 )); + +_FDT (fdt_property (fdt,"reg" , its_config_reg_prop,sizeof (its_config_reg_prop))); +_FDT (fdt_property_string (fdt,"reg-names" ,"ns-config" )); + +snprintf (node_at_addr,sizeof (node_at_addr),"msi-controller@%llx" , + (unsigned long long )ARM_GICV5_ITS_TRANSL_BASE ); +_FDT (fdt_begin_node (fdt, node_at_addr)); +_FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_MSI )); +_FDT (fdt_property (fdt,"msi-controller" ,NULL ,0 )); +_FDT (fdt_property_cell (fdt,"#msi-cells" ,1 )); + +_FDT (fdt_property (fdt,"reg" , its_trans_reg_prop,sizeof (its_trans_reg_prop))); +_FDT (fdt_property_string (fdt,"reg-names" ,"ns-translate" )); + +_FDT (fdt_end_node (fdt)); + +_FDT (fdt_end_node (fdt)); + } +_FDT (fdt_end_node (fdt));_FDT (fdt_end_node (fdt));
Signature · 1 line
2.34.1
PATCH v3 20/21 arm64: Map PCI MSI requester IDs to the GICv5 ITS
In reply to Sascha BischoffThe GICv5 ITS MSI controller requires one MSI cell carrying the DeviceID. Describe an identity mapping from the 16-bit PCI requester ID to the ITS DeviceID with msi-map. Keep the existing msi-parent property for GICv2m and GICv3 ITS.
--- arm64/pci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arm64/pci.c +9 -1
@@ -32,6 +32,12 @@ void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm)unsigned nentries =0 ;/* Bus range */ u32 bus_range[] = {cpu_to_fdt32 (0 ),cpu_to_fdt32 (0 ), }; +u32 msi_map[] = { +cpu_to_fdt32 (0 ), +cpu_to_fdt32 (PHANDLE_MSI ), +cpu_to_fdt32 (0 ), +cpu_to_fdt32 (0x10000 ), + };/* Configuration Space */ u64 cfg_reg_prop[] = {cpu_to_fdt64 (KVM_PCI_CFG_AREA ),cpu_to_fdt64 (ARM_PCI_CFG_SIZE ), };
@@ -70,7 +76,9 @@ void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm)_FDT (fdt_property (fdt,"reg" , &cfg_reg_prop,sizeof (cfg_reg_prop)));_FDT (fdt_property (fdt,"ranges" , ranges,sizeof (ranges))); -if (irqchip ==IRQCHIP_GICV2M || irqchip ==IRQCHIP_GICV3_ITS ) +if (irqchip ==IRQCHIP_GICV5_ITS ) +_FDT (fdt_property (fdt,"msi-map" , msi_map,sizeof (msi_map))); +else if (irqchip ==IRQCHIP_GICV2M || irqchip ==IRQCHIP_GICV3_ITS )_FDT (fdt_property_cell (fdt,"msi-parent" ,PHANDLE_MSI ));generate_dma_region_prop (fdt);
Signature · 1 line
2.34.1
PATCH v3 21/21 arm64: Expose the GICv5 ITS irqchip option
In reply to Sascha BischoffAllow --irqchip=gicv5-its now that the ITS DT nodes and PCI MSI requester mapping are in place. Start automatic irqchip selection at GICv5 ITS so it is preferred ahead of base GICv5 and older models.
--- arm64/gic.c | 4 +++- arm64/include/kvm/kvm-config-arch.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
arm64/gic.c +3 -1
@@ -52,6 +52,8 @@ int irqchip_parser(const struct option *opt, const char *arg, int unset) *type =IRQCHIP_GICV3_ITS ; }else if (!strcmp (arg,"gicv5" )) { *type =IRQCHIP_GICV5 ; + }else if (!strcmp (arg,"gicv5-its" )) { + *type =IRQCHIP_GICV5_ITS ; }else {pr_err ("irqchip: unknown type \"%s\"\n" , arg);return -1 ;
@@ -300,7 +302,7 @@ int gic__create(struct kvm *kvm, enum irqchip_type type)switch (type) {case IRQCHIP_AUTO : -for (try =IRQCHIP_GICV5 ; try >=IRQCHIP_GICV2 ; try--) { +for (try =IRQCHIP_GICV5_ITS ; try >=IRQCHIP_GICV2 ; try--) { err =gic__create (kvm, try);if (!err)break ;
arm64/include/kvm/kvm-config-arch.h +1 -1
@@ -59,7 +59,7 @@ int sve_vl_parser(const struct option *opt, const char *arg, int unset); "transport (Deprecated: Use --virtio-transport " \ "option instead)", virtio_transport_parser, kvm), \OPT_CALLBACK ('\0' ,"irqchip" , &(cfg)->irqchip, \ -"[gicv2|gicv2m|gicv3|gicv3-its|gicv5]" , \ +"[gicv2|gicv2m|gicv3|gicv3-its|gicv5|gicv5-its]" , \"Type of interrupt controller to emulate in the guest" , \ irqchip_parser,NULL ), \ OPT_U64('\0', "firmware-address", &(cfg)->fw_addr, \
Signature · 1 line
2.34.1
Hi Sascha,
Quoted 11 lines · Sascha Bischoff
This series adds support for GICv5-based VMs to kvmtool. These are exposed as --irqchip=gicv5 and --irqchip=gicv5-its, where the former only creates a vGICv5 device and the latter adds in a GICv5 ITS. The GICv5 specification can be found at [1].
The GICv5 support in KVM needed by --irqchip=gicv5 is expected to land in Linux v7.4. KVM support for GICv5 ITS has yet to be posted, but should follow shortly. Thus, --irqchip=gicv5 works with the corresponding KVM changes, while --irqchip=gicv5-its cannot yet be used with upstream KVM.
I successfully booted a Linux guest on GICv5 FVP (with FEAT_GCIE_LEGACY) using both --irqchip=gicv5 and --irqchip=gicv3. I also used this series to boot a Linux guest on GICv3 FVP with kvmtool's automatic irqchip selection. Everything worked fine.
FWIW, feel free to add
for non-ITS parts.
Since --irqchip=gicv5 already provides a usable Linux guest and is aligned with upstream vGICv5 support, it would be nice to get these parts merged sooner (which would also reduce the series to just ITS support). So I'll do my best to review non-ITS bits.
Cheers
Vladimir
Hi Vladimir,
Quoted 15 lines · Vladimir Murzin
Hi Sascha,
Quoted 11 lines · Sascha Bischoff
This series adds support for GICv5-based VMs to kvmtool. These are exposed as --irqchip=gicv5 and --irqchip=gicv5-its, where the former only creates a vGICv5 device and the latter adds in a GICv5 ITS. The GICv5 specification can be found at [1].
The GICv5 support in KVM needed by --irqchip=gicv5 is expected to land in Linux v7.4. KVM support for GICv5 ITS has yet to be posted, but should follow shortly. Thus, --irqchip=gicv5 works with the corresponding KVM changes, while --irqchip=gicv5-its cannot yet be used with upstream KVM.
First of all, sorry for the delay on my part. Thanks a lot for the time you have spent reviewing and testing these changes. I really appreciate it.
Quoted 4 lines
I successfully booted a Linux guest on GICv5 FVP (with
FEAT_GCIE_LEGACY) using both --irqchip=gicv5 and --irqchip=gicv3. I also used this series to boot a Linux guest on GICv3 FVP with kvmtool's automatic irqchip selection. Everything worked fine.
Phew, that's good news!
Quoted 6 lines
FWIW, feel free to add
Tested-by Vladimir Murzin <[email protected]>for non-ITS parts.
Thanks, have done so!
Quoted 5 lines
Since --irqchip=gicv5 already provides a usable Linux guest and is aligned with upstream vGICv5 support, it would be nice to get these parts merged sooner (which would also reduce the series to just ITS support). So I'll do my best to review non-ITS bits.
Yeah, the IRS part is what I am keen to get in sooner rather than later. I'll post a new version of these changes soon. However, I will keep the ITS changes in there - they're already at the end and hence are easy to drop, and it is useful to be able to point people to a complete series for testing the GICv5 ITS support in KVM.
I hope that's OK! Feel free to completely ignore the ITS support for the time being.
Quoted 3 lines
Cheers
Vladimir
Thanks,
Sascha