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 --- arm64/gic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arm64/gic.c b/arm64/gic.c index 1e400962..debb0381 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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); -- 2.34.1 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 --- arm64/gic.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index debb0381..f8371f50 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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, -- 2.34.1 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 --- arm64/include/asm/kvm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arm64/include/asm/kvm.h b/arm64/include/asm/kvm.h index 1c13bfa2..9998252e 100644 --- a/arm64/include/asm/kvm.h +++ b/arm64/include/asm/kvm.h @@ -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) -- 2.34.1 Add 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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 19 +++++++++++++++---- arm64/include/kvm/gic.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index f8371f50..5c8a33b5 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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) diff --git a/arm64/include/kvm/gic.h b/arm64/include/kvm/gic.h index 8490cca6..630f0bbd 100644 --- a/arm64/include/kvm/gic.h +++ b/arm64/include/kvm/gic.h @@ -29,6 +29,7 @@ enum irqchip_type { IRQCHIP_GICV2M, IRQCHIP_GICV3, IRQCHIP_GICV3_ITS, + IRQCHIP_GICV5, }; struct kvm; -- 2.34.1 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 --- arm64/gic.c | 7 +++++++ arm64/include/kvm/gic.h | 1 + 2 files changed, 8 insertions(+) diff --git a/arm64/gic.c b/arm64/gic.c index 5c8a33b5..c1bd0771 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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: diff --git a/arm64/include/kvm/gic.h b/arm64/include/kvm/gic.h index 630f0bbd..991aa912 100644 --- a/arm64/include/kvm/gic.h +++ b/arm64/include/kvm/gic.h @@ -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 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 --- arm64/gic.c | 6 ++++++ include/kvm/irq.h | 1 + irq.c | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arm64/gic.c b/arm64/gic.c index c1bd0771..23c68862 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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; diff --git a/include/kvm/irq.h b/include/kvm/irq.h index 2a3f8c9d..17113979 100644 --- a/include/kvm/irq.h +++ b/include/kvm/irq.h @@ -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); diff --git a/irq.c b/irq.c index cdcf9923..7c4bfec4 100644 --- a/irq.c +++ b/irq.c @@ -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) -- 2.34.1 Place 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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 16 ++++++++++++++-- arm64/include/kvm/kvm-arch.h | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index 23c68862..5be71ba1 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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); diff --git a/arm64/include/kvm/kvm-arch.h b/arm64/include/kvm/kvm-arch.h index e7dd5269..94140364 100644 --- a/arm64/include/kvm/kvm-arch.h +++ b/arm64/include/kvm/kvm-arch.h @@ -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) -- 2.34.1 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 --- arm64/include/kvm/gic.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arm64/include/kvm/gic.h b/arm64/include/kvm/gic.h index 991aa912..bef871be 100644 --- a/arm64/include/kvm/gic.h +++ b/arm64/include/kvm/gic.h @@ -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) -- 2.34.1 Use 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. Signed-off-by: Sascha Bischoff --- arm64/pmu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arm64/pmu.c b/arm64/pmu.c index ef7faca1..bc52d5fc 100644 --- a/arm64/pmu.c +++ b/arm64/pmu.c @@ -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); -- 2.34.1 GICv5 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. Signed-off-by: Sascha Bischoff --- arm64/timer.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/arm64/timer.c b/arm64/timer.c index 2ac6144f..b791956b 100644 --- a/arm64/timer.c +++ b/arm64/timer.c @@ -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); } -- 2.34.1 The 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. Signed-off-by: Sascha Bischoff --- arm64/fdt.c | 2 ++ arm64/include/kvm/fdt-arch.h | 1 + 2 files changed, 3 insertions(+) diff --git a/arm64/fdt.c b/arm64/fdt.c index 3cbd36e2..d4cbcff3 100644 --- a/arm64/fdt.c +++ b/arm64/fdt.c @@ -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)); } diff --git a/arm64/include/kvm/fdt-arch.h b/arm64/include/kvm/fdt-arch.h index 8a0a460e..2b667c53 100644 --- a/arm64/include/kvm/fdt-arch.h +++ b/arm64/include/kvm/fdt-arch.h @@ -11,4 +11,5 @@ enum phandles { void generate_dma_region_prop(void *fdt); +#define PHANDLE_CPU_BASE PHANDLES_MAX #endif /* ARM__FDT_H */ -- 2.34.1 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 --- arm64/gic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arm64/gic.c b/arm64/gic.c index 5be71ba1..f4d446da 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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 */ -- 2.34.1 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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arm64/gic.c b/arm64/gic.c index f4d446da..fe6c2059 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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)); } -- 2.34.1 Use the GICv5 interrupt type and absolute SPI number for platform devices. Preserve the legacy GICv2/v3 DT encoding for other VMs. Signed-off-by: Sascha Bischoff --- arm64/fdt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arm64/fdt.c b/arm64/fdt.c index d4cbcff3..e9447b3f 100644 --- a/arm64/fdt.c +++ b/arm64/fdt.c @@ -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))); } -- 2.34.1 PCI 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. Signed-off-by: Sascha Bischoff --- arm64/pci.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arm64/pci.c b/arm64/pci.c index db87db8b..0ba2f9c9 100644 --- a/arm64/pci.c +++ b/arm64/pci.c @@ -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), }, }; -- 2.34.1 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 --- arm64/gic.c | 4 +++- arm64/include/kvm/kvm-config-arch.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index fe6c2059..02e55cd5 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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; diff --git a/arm64/include/kvm/kvm-config-arch.h b/arm64/include/kvm/kvm-config-arch.h index d8a8ef7f..46130663 100644 --- a/arm64/include/kvm/kvm-config-arch.h +++ b/arm64/include/kvm/kvm-config-arch.h @@ -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 Copy the GICv5 ITS device type, address type and size from the Linux headers. Signed-off-by: Sascha Bischoff --- arm64/include/asm/kvm.h | 2 ++ include/linux/kvm.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arm64/include/asm/kvm.h b/arm64/include/asm/kvm.h index 9998252e..3ec5a0b1 100644 --- a/arm64/include/asm/kvm.h +++ b/arm64/include/asm/kvm.h @@ -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 */ diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 6c8afa20..3ff33e49 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -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, -- 2.34.1 Allow 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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 31 +++++++++++++++++++++---------- arm64/include/kvm/gic.h | 1 + arm64/include/kvm/kvm-arch.h | 8 ++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index 02e55cd5..f09b3f5d 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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) diff --git a/arm64/include/kvm/gic.h b/arm64/include/kvm/gic.h index bef871be..36ca39ea 100644 --- a/arm64/include/kvm/gic.h +++ b/arm64/include/kvm/gic.h @@ -34,6 +34,7 @@ enum irqchip_type { IRQCHIP_GICV3, IRQCHIP_GICV3_ITS, IRQCHIP_GICV5, + IRQCHIP_GICV5_ITS, }; struct kvm; diff --git a/arm64/include/kvm/kvm-arch.h b/arm64/include/kvm/kvm-arch.h index 94140364..3b0ffead 100644 --- a/arm64/include/kvm/kvm-arch.h +++ b/arm64/include/kvm/kvm-arch.h @@ -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) -- 2.34.1 Add 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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arm64/gic.c b/arm64/gic.c index f09b3f5d..4ba626bf 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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)); -- 2.34.1 The 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. Signed-off-by: Sascha Bischoff --- arm64/pci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arm64/pci.c b/arm64/pci.c index 0ba2f9c9..912165ef 100644 --- a/arm64/pci.c +++ b/arm64/pci.c @@ -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); -- 2.34.1 Allow --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. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 4 +++- arm64/include/kvm/kvm-config-arch.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index 4ba626bf..34622850 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -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; diff --git a/arm64/include/kvm/kvm-config-arch.h b/arm64/include/kvm/kvm-config-arch.h index 46130663..936b142d 100644 --- a/arm64/include/kvm/kvm-config-arch.h +++ b/arm64/include/kvm/kvm-config-arch.h @@ -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, \ -- 2.34.1