Skip to contentSkip to conversation

arm64: Support GICv5-based guests

PATCH In review Sascha Bischoff 2 participants 25 messages Nov 27

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v7 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 creates a vGICv5 device and the latter adds a GICv5 ITS. The GICv5 specification can be found at [1].

The GICv5 support in KVM needed by --irqchip=gicv5 is available as of Linux v7.4-rc1. The GICv5 ITS support is described in [2]; using --irqchip=gicv5-its requires a KVM build with those changes.

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. The IRS support is built and exposed before the ITS support, so the GICv5 irqchip support can be merged separately from the ITS changes.

Compared with v6 [3]:

* Rebased onto kvmtool upstream at 2f3abe56 as requested.
* Adapted patch 16 to the upstream FDT helper that generates multiple interrupts for a device. Use the selected GIC's SPI type and base for each interrupt in the list.

The v7.4-rc1 header sync includes GICv5 IRS UAPI, but not GICv5 ITS UAPI. Patch 19 mirrors the ITS definitions from [2]. Once that UAPI lands upstream, the headers should be resynced against the latest Linux headers before merging the ITS support.

Thanks,
Sascha

[1] https://developer.arm.com/documentation/aes0070/latest
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

Sascha Bischoff (23):
arm64: Propagate IRQ routing initialisation errors
arm64: Close the ITS descriptor when setup fails
arm64: Split GIC device setup
Sync kernel UAPI headers with v7.4-rc1
arm64: Add GICv5 irqchip device support
arm64: Configure GIC interrupt bases
irq: Allow the initial interrupt line number to be set
arm64: Start GICv5 SPI line allocation at zero
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
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: Add proposed GICv5 ITS UAPI definitions
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                         |   7 +-
 arm64/gic.c                         | 359 ++++++++++++++++++++++++----
 arm64/include/asm/kvm.h             |  18 ++
 arm64/include/kvm/fdt-arch.h        |   1 +
 arm64/include/kvm/gic.h             |  15 ++
 arm64/include/kvm/kvm-arch.h        |  16 ++
 arm64/include/kvm/kvm-config-arch.h |   2 +-
 arm64/pci.c                         |  24 +-
 arm64/pmu.c                         |  13 +-
 arm64/timer.c                       |   8 +-
 include/kvm/irq.h                   |   1 +
 include/linux/kvm.h                 |  23 ++
 include/linux/virtio_console.h      |   2 +-
 include/linux/virtio_ids.h          |   1 +
 irq.c                               |  15 +-
 powerpc/include/asm/kvm.h           |  18 ++
 riscv/include/asm/kvm.h             |  17 ++
 x86/include/asm/kvm.h               |   4 +-
 18 files changed, 478 insertions(+), 66 deletions(-)

base-commit: 2f3abe56dcd2658dc6dae3eeeb4996dc4b518bcf

Signature · 1 line
2.34.1
#1 lore raw

PATCH v7 1/23 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
index 1e400962..debb0381 100644
@@ -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
#2 lore raw

PATCH v7 2/23 arm64: Close the ITS descriptor when setup fails

In reply to 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.

---
 arm64/gic.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
arm64/gic.c +12 -7
index debb0381..f8371f50 100644
@@ -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
#3 lore raw

PATCH v7 3/23 arm64: Split GIC device setup

In reply to Sascha Bischoff

Separate the CPU interface, redistributor and distributor address setup from GIC device creation. Keep the per-GIC address handling in small helpers.

Have the existing MSI frame helper use the global MSI base instead of passing it as an argument.

Use the irqchip enum order to omit the GICv2 PPI CPU mask for GICv3 and later generations.

---
 arm64/gic.c | 94 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 62 insertions(+), 32 deletions(-)
arm64/gic.c +62 -32
index f8371f50..57f3fa02 100644
@@ -142,52 +142,90 @@ out_close:
 	return err;
 }
 
-static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type,
-				 u64 msi_frame_addr)
+static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type)
 {
 	switch (type) {
 	case IRQCHIP_GICV2M:
-		return gic__create_gicv2m_frame(kvm, msi_frame_addr);
+		return gic__create_gicv2m_frame(kvm, gic_msi_base);
 	case IRQCHIP_GICV3_ITS:
-		return gic__create_its_frame(kvm, msi_frame_addr);
+		return gic__create_its_frame(kvm, gic_msi_base);
 	default:	/* No MSI frame needed */
 		return 0;
 	}
 }
 
-static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
+static int gic__set_cpu_if(enum irqchip_type type)
 {
-	int err;
 	u64 cpu_if_addr = ARM_GIC_CPUI_BASE;
-	u64 dist_addr = ARM_GIC_DIST_BASE;
-	struct kvm_create_device gic_device = {
-		.flags	= 0,
-	};
 	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,
 	};
-	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:
+		return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
+	default:	/* No CPU interface 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:
+	case IRQCHIP_GICV3_ITS:
+		return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr);
+	default:	/* No redistributor 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:
+	case IRQCHIP_GICV3_ITS:
+		dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST;
+		return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
+	default:	/* No distributor needed */
+		return 0;
+	}
+}
+
+static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
+{
+	int err;
+	struct kvm_create_device gic_device = {
+		.flags	= 0,
+	};
+
 	switch (type) {
 	case IRQCHIP_GICV2M:
 	case IRQCHIP_GICV2:
 		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V2;
-		dist_attr.attr  = KVM_VGIC_V2_ADDR_TYPE_DIST;
 		break;
 	case IRQCHIP_GICV3:
 	case IRQCHIP_GICV3_ITS:
 		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V3;
-		dist_attr.attr  = KVM_VGIC_V3_ADDR_TYPE_DIST;
 		break;
 	case IRQCHIP_AUTO:
 		return -ENODEV;
@@ -199,26 +237,19 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 
 	gic_fd = gic_device.fd;
 
-	switch (type) {
-	case IRQCHIP_GICV2M:
-	case IRQCHIP_GICV2:
-		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
-		break;
-	case IRQCHIP_GICV3_ITS:
-	case IRQCHIP_GICV3:
-		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr);
-		break;
-	case IRQCHIP_AUTO:
-		return -ENODEV;
-	}
+	err = gic__set_cpu_if(type);
+	if (err)
+		goto out_err;
+
+	err = gic__set_redist(type);
 	if (err)
 		goto out_err;
 
-	err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
+	err = gic__set_dist(type);
 	if (err)
 		goto out_err;
 
-	err = gic__create_msi_frame(kvm, type, gic_msi_base);
+	err = gic__create_msi_frame(kvm, type);
 	if (err)
 		goto out_err;
 
@@ -439,8 +470,7 @@ void gic__generate_fdt_nodes(void *fdt, struct kvm *kvm)
 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)
+	if (kvm->cfg.arch.irqchip >= IRQCHIP_GICV3)
 		return 0;
 
 	if (kvm->nrcpus > 8)
Signature · 1 line
2.34.1
#4 lore raw

PATCH v7 4/23 Sync kernel UAPI headers with v7.4-rc1

In reply to Sascha Bischoff

Synchronise the headers to pull in the support for the GICv5 IRS that was added in v7.4-rc1. These changes do not include the GICv5 ITS changes which are still under review at the time of writing.

---
 arm64/include/asm/kvm.h        | 16 ++++++++++++++++
 include/linux/kvm.h            | 21 +++++++++++++++++++++
 include/linux/virtio_console.h |  2 +-
 include/linux/virtio_ids.h     |  1 +
 powerpc/include/asm/kvm.h      | 18 ++++++++++++++++++
 riscv/include/asm/kvm.h        | 17 +++++++++++++++++
 x86/include/asm/kvm.h          |  4 ++--
 7 files changed, 76 insertions(+), 3 deletions(-)
arm64/include/asm/kvm.h +16 -0
index 1c13bfa2..65ee09bd 100644
@@ -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 */
@@ -106,6 +111,7 @@ struct kvm_regs {
 #define KVM_ARM_VCPU_PTRAUTH_GENERIC	6 /* VCPU uses generic authentication */
 #define KVM_ARM_VCPU_HAS_EL2		7 /* Support nested virtualization */
 #define KVM_ARM_VCPU_HAS_EL2_E2H0	8 /* Limit NV support to E2H RES0 */
+#define KVM_ARM_VCPU_PMU_V3_STRICT	9 /* No default PMU creation */
 
 struct kvm_vcpu_init {
 	__u32 target;
@@ -417,6 +423,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)
include/linux/kvm.h +21 -0
index 6c8afa20..8dff2fc1 100644
@@ -996,6 +996,10 @@ struct kvm_enable_cap {
 #define KVM_CAP_S390_USER_OPEREXEC 246
 #define KVM_CAP_S390_KEYOP 247
 #define KVM_CAP_S390_VSIE_ESAMODE 248
+#define KVM_CAP_S390_HPAGE_2G 249
+#define KVM_CAP_PPC_COMPAT_CAPS 250
+#define KVM_CAP_ARM_PMU_V3_STRICT 251
+#define KVM_CAP_GUEST_MEMFD_MEMORY_ATTRIBUTES 252
 
 struct kvm_irq_routing_irqchip {
 	__u32 irqchip;
@@ -1340,6 +1344,8 @@ struct kvm_s390_keyop {
 /* Available with KVM_CAP_COUNTER_OFFSET */
 #define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO,  0xb5, struct kvm_arm_counter_offset)
 #define KVM_ARM_GET_REG_WRITABLE_MASKS _IOR(KVMIO,  0xb6, struct reg_mask_range)
+/* Available with KVM_CAP_PPC_COMPAT_CAPS */
+#define KVM_PPC_GET_COMPAT_CAPS	_IO(KVMIO,  0xb8)
 
 /* ioctl for vm fd */
 #define KVM_CREATE_DEVICE	  _IOWR(KVMIO,  0xe0, struct kvm_create_device)
@@ -1648,6 +1654,21 @@ struct kvm_memory_attributes {
 	__u64 flags;
 };
 
+/* Available with KVM_CAP_GUEST_MEMFD_MEMORY_ATTRIBUTES */
+#define KVM_SET_MEMORY_ATTRIBUTES2              _IOWR(KVMIO,  0xd2, struct kvm_memory_attributes2)
+
+struct kvm_memory_attributes2 {
+	union {
+		__u64 address;
+		__u64 offset;
+	};
+	__u64 size;
+	__u64 attributes;
+	__u64 flags;
+	__u64 error_offset;
+	__u64 reserved[11];
+};
+
 #define KVM_MEMORY_ATTRIBUTE_PRIVATE           (1ULL << 3)
 
 #define KVM_CREATE_GUEST_MEMFD	_IOWR(KVMIO,  0xd4, struct kvm_create_guest_memfd)
include/linux/virtio_console.h +1 -1
index 7e6ec2ff..0506539e 100644
@@ -44,7 +44,7 @@
 #define VIRTIO_CONSOLE_BAD_ID		(~(__u32)0)
 
 struct virtio_console_config {
-	/* colums of the screens */
+	/* columns of the screens */
 	__virtio16 cols;
 	/* rows of the screens */
 	__virtio16 rows;
include/linux/virtio_ids.h +1 -0
index 6c12db16..f9056af0 100644
@@ -69,6 +69,7 @@
 #define VIRTIO_ID_BT			40 /* virtio bluetooth */
 #define VIRTIO_ID_GPIO			41 /* virtio gpio */
 #define VIRTIO_ID_SPI			45 /* virtio spi */
+#define VIRTIO_ID_MEDIA			48 /* virtio media */
 
 /*
  * Virtio Transitional IDs
powerpc/include/asm/kvm.h +18 -0
index 077c5437..913a64b9 100644
@@ -437,6 +437,24 @@ struct kvm_ppc_cpu_char {
 	__u64	behaviour_mask;		/* valid bits in behaviour */
 };
 
+/* For KVM_PPC_GET_COMPAT_CAPS */
+struct kvm_ppc_compat_caps {
+	__u64	size;			/* Size of this structure */
+	__u64	flags;			/* Reserved for future use */
+	__u64	compat_capabilities;	/* Capabilities supported by the host */
+};
+#define KVM_PPC_COMPAT_CAPS_SIZE_VER0	24 /* sizeof first published struct */
+
+/*
+ * Capability bits for compat_capabilities field in kvm_ppc_compat_caps.
+ * These bits indicate which processor compatibility modes are supported.
+ */
+#define KVM_PPC_COMPAT_CAP_POWER9	(1ULL << 62)
+#define KVM_PPC_COMPAT_CAP_POWER10	(1ULL << 61)
+#define KVM_PPC_COMPAT_CAP_POWER11	(1ULL << 60)
+#define KVM_PPC_COMPAT_BITMASK		(KVM_PPC_COMPAT_CAP_POWER9 | \
+					 KVM_PPC_COMPAT_CAP_POWER10 | \
+					 KVM_PPC_COMPAT_CAP_POWER11)
 /*
  * Values for character and character_mask.
  * These are identical to the values used by H_GET_CPU_CHARACTERISTICS.
riscv/include/asm/kvm.h +17 -0
index 504e7330..39b0f3f1 100644
@@ -102,6 +102,11 @@ struct kvm_riscv_smstateen_csr {
 	unsigned long sstateen0;
 };
 
+/* Zicfiss CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
+struct kvm_riscv_zicfiss_csr {
+	unsigned long ssp;
+};
+
 /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
 struct kvm_riscv_timer {
 	__u64 frequency;
@@ -199,6 +204,12 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_ZCLSD,
 	KVM_RISCV_ISA_EXT_ZILSD,
 	KVM_RISCV_ISA_EXT_ZALASR,
+	KVM_RISCV_ISA_EXT_ZICFILP,
+	KVM_RISCV_ISA_EXT_ZICFISS,
+	KVM_RISCV_ISA_EXT_ZICCLSM,
+	KVM_RISCV_ISA_EXT_ZICCAMOA,
+	KVM_RISCV_ISA_EXT_ZICCIF,
+	KVM_RISCV_ISA_EXT_ZA64RS,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
@@ -240,6 +251,9 @@ struct kvm_riscv_sbi_fwft_feature {
 struct kvm_riscv_sbi_fwft {
 	struct kvm_riscv_sbi_fwft_feature misaligned_deleg;
 	struct kvm_riscv_sbi_fwft_feature pointer_masking;
+	struct kvm_riscv_sbi_fwft_feature pte_ad_hw_updating;
+	struct kvm_riscv_sbi_fwft_feature landing_pad;
+	struct kvm_riscv_sbi_fwft_feature shadow_stack;
 };
 
 /* If you need to interpret the index values, here is the key: */
@@ -263,12 +277,15 @@ struct kvm_riscv_sbi_fwft {
 #define KVM_REG_RISCV_CSR_GENERAL	(0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_AIA		(0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_SMSTATEEN	(0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_CSR_ZICFISS	(0x3 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_REG(name)	\
 		(offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
 #define KVM_REG_RISCV_CSR_AIA_REG(name)	\
 	(offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long))
 #define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name)  \
 	(offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long))
+#define KVM_REG_RISCV_CSR_ZICFISS_REG(name)  \
+	(offsetof(struct kvm_riscv_zicfiss_csr, name) / sizeof(unsigned long))
 
 /* Timer registers are mapped as type 4 */
 #define KVM_REG_RISCV_TIMER		(0x04 << KVM_REG_RISCV_TYPE_SHIFT)
x86/include/asm/kvm.h +2 -2
index 5f2b30d0..00ce2653 100644
@@ -45,9 +45,7 @@
 #define __KVM_HAVE_PIT
 #define __KVM_HAVE_IOAPIC
 #define __KVM_HAVE_IRQ_LINE
-#define __KVM_HAVE_MSI
 #define __KVM_HAVE_USER_NMI
-#define __KVM_HAVE_MSIX
 #define __KVM_HAVE_MCE
 #define __KVM_HAVE_PIT_STATE2
 #define __KVM_HAVE_XEN_HVM
@@ -477,6 +475,7 @@ struct kvm_sync_regs {
 #define KVM_X86_QUIRK_STUFF_FEATURE_MSRS	(1 << 8)
 #define KVM_X86_QUIRK_IGNORE_GUEST_PAT		(1 << 9)
 #define KVM_X86_QUIRK_VMCS12_ALLOW_FREEZE_IN_SMM (1 << 10)
+#define KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT	(1 << 11)
 
 #define KVM_STATE_NESTED_FORMAT_VMX	0
 #define KVM_STATE_NESTED_FORMAT_SVM	1
@@ -532,6 +531,7 @@ struct kvm_svm_nested_state_data {
 
 struct kvm_svm_nested_state_hdr {
 	__u64 vmcb_pa;
+	__u64 gpat;
 };
 
 /* for KVM_CAP_NESTED_STATE */
Signature · 1 line
2.34.1
#5 lore raw

PATCH v7 5/23 arm64: Add GICv5 irqchip device support

In reply to Sascha Bischoff

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.

---
 arm64/gic.c             | 5 +++++
 arm64/include/kvm/gic.h | 1 +
 2 files changed, 6 insertions(+)
arm64/gic.c +5 -0
index 57f3fa02..51a32159 100644
@@ -227,6 +227,9 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 	case IRQCHIP_GICV3_ITS:
 		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V3;
 		break;
+	case IRQCHIP_GICV5:
+		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V5;
+		break;
 	case IRQCHIP_AUTO:
 		return -ENODEV;
 	}
@@ -321,6 +324,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/include/kvm/gic.h +1 -0
index 8490cca6..630f0bbd 100644
@@ -29,6 +29,7 @@ enum irqchip_type {
 	IRQCHIP_GICV2M,
 	IRQCHIP_GICV3,
 	IRQCHIP_GICV3_ITS,
+	IRQCHIP_GICV5,
 };
 
 struct kvm;
Signature · 1 line
2.34.1
#6 lore raw

PATCH v7 6/23 arm64: Configure GIC interrupt bases

In reply to Sascha Bischoff

Record the SPI and PPI bases for the selected irqchip and expose getters to code that does not receive the irqchip type. Configure the bases after the GIC device and MSI frame have been created.

---
 arm64/gic.c             | 48 +++++++++++++++++++++++++++++++++++++++++
 arm64/include/kvm/gic.h |  4 ++++
 2 files changed, 52 insertions(+)
arm64/gic.c +48 -0
index 51a32159..df5689a7 100644
@@ -21,6 +21,18 @@ static u64 gic_redists_size;
 static u64 gic_msi_base;
 static u64 gic_msi_size = 0;
 static bool vgic_is_init = false;
+static int gic_spi_base = GIC_SPI_IRQ_BASE;
+static int gic_ppi_base = GIC_PPI_IRQ_BASE;
+
+int gic__get_spi_base(void)
+{
+	return gic_spi_base;
+}
+
+int gic__get_ppi_base(void)
+{
+	return gic_ppi_base;
+}
 
 struct kvm_irqfd_line {
 	unsigned int		gsi;
@@ -211,6 +223,34 @@ static int gic__set_dist(enum irqchip_type type)
 	}
 }
 
+static int gic__set_spi(enum irqchip_type type)
+{
+	switch (type) {
+	case IRQCHIP_GICV5:
+		gic_spi_base = GICV5_SPI_IRQ_BASE;
+		break;
+	default:
+		gic_spi_base = GIC_SPI_IRQ_BASE;
+		break;
+	}
+
+	return 0;
+}
+
+static int gic__set_ppi(enum irqchip_type type)
+{
+	switch (type) {
+	case IRQCHIP_GICV5:
+		gic_ppi_base = GICV5_PPI_IRQ_BASE;
+		break;
+	default:
+		gic_ppi_base = GIC_PPI_IRQ_BASE;
+		break;
+	}
+
+	return 0;
+}
+
 static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 {
 	int err;
@@ -256,6 +296,14 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 	if (err)
 		goto out_err;
 
+	err = gic__set_spi(type);
+	if (err)
+		goto out_err;
+
+	err = gic__set_ppi(type);
+	if (err)
+		goto out_err;
+
 	return 0;
 
 out_err:
arm64/include/kvm/gic.h +4 -0
index 630f0bbd..c4f78cde 100644
@@ -4,6 +4,8 @@
 #define GIC_SGI_IRQ_BASE		0
 #define GIC_PPI_IRQ_BASE		16
 #define GIC_SPI_IRQ_BASE		32
+#define GICV5_PPI_IRQ_BASE		0
+#define GICV5_SPI_IRQ_BASE		0
 
 #define GIC_FDT_IRQ_NUM_CELLS		3
 
@@ -34,6 +36,8 @@ enum irqchip_type {
 
 struct kvm;
 
+int gic__get_spi_base(void);
+int gic__get_ppi_base(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
#7 lore raw

PATCH v7 7/23 irq: Allow the initial interrupt line number to be set

In reply to Sascha Bischoff

Allow callers to select the initial IRQ line number before allocating any lines. Track the selected offset when reporting the number of allocated lines.

---
 include/kvm/irq.h |  1 +
 irq.c             | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
include/kvm/irq.h +1 -0
index 2a3f8c9d..17113979 100644
@@ -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
index cdcf9923..7c4bfec4 100644
@@ -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
#8 lore raw

PATCH v7 8/23 arm64: Start GICv5 SPI line allocation at zero

In reply to Sascha Bischoff

GICv5 SPIs start at zero, while earlier GICs use an offset of 32. Select the zero offset before allocating any interrupt lines.

---
 arm64/gic.c | 3 +++
 1 file changed, 3 insertions(+)
arm64/gic.c +3 -0
index df5689a7..58644036 100644
@@ -234,6 +234,9 @@ static int gic__set_spi(enum irqchip_type type)
 		break;
 	}
 
+	if (gic_spi_base == GICV5_SPI_IRQ_BASE)
+		return irq__init_irq_offset(gic_spi_base);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
#9 lore raw

PATCH v7 9/23 arm64: Configure the GICv5 IRS

In reply to Sascha Bischoff

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.

---
 arm64/gic.c                  | 30 ++++++++++++++++++++++++++++--
 arm64/include/kvm/kvm-arch.h |  8 ++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
arm64/gic.c +28 -2
index 58644036..5034b034 100644
@@ -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;
@@ -201,6 +202,22 @@ static int gic__set_redist(enum irqchip_type type)
 	}
 }
 
+static int gic__set_irs(enum irqchip_type type)
+{
+	struct kvm_device_attr 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_GICV5:
+		return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &irs_attr);
+	default:	/* No IRS needed */
+		return 0;
+	}
+}
+
 static int gic__set_dist(enum irqchip_type type)
 {
 	u64 dist_addr = ARM_GIC_DIST_BASE;
@@ -291,6 +308,10 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 	if (err)
 		goto out_err;
 
+	err = gic__set_irs(type);
+	if (err)
+		goto out_err;
+
 	err = gic__set_dist(type);
 	if (err)
 		goto out_err;
@@ -376,6 +397,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;
@@ -397,8 +419,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,
@@ -412,6 +435,8 @@ static int gic__init_gic(struct kvm *kvm)
 		.attr	= KVM_DEV_ARM_VGIC_CTRL_INIT,
 	};
 
+	nr_irqs += gic__get_spi_base();
+
 	/*
 	 * If we didn't use the KVM_CREATE_DEVICE method, KVM will
 	 * give us some default number of interrupts. The GIC initialization
@@ -540,12 +565,13 @@ u32 gic__get_fdt_irq_cpumask(struct kvm *kvm)
 
 void kvm__irq_line(struct kvm *kvm, int irq, int level)
 {
+	int spi_base = gic__get_spi_base();
 	struct kvm_irq_level irq_level = {
 		.irq	= KVM_IRQCHIP_IRQ(irq),
 		.level	= !!level,
 	};
 
-	if (irq < GIC_SPI_IRQ_BASE || irq > GIC_MAX_IRQ)
+	if (irq < spi_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
index 83e4cd29..d40dce35 100644
@@ -59,6 +59,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
#10 lore raw

PATCH v7 10/23 arm64: Define GICv5 interrupt types

In reply to 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. Give the FDT type values distinct names while retaining the same numeric values.

---
 arm64/gic.c             | 42 +++++++++++++++++++++++++++++++++++++----
 arm64/include/kvm/gic.h |  9 +++++++++
 2 files changed, 47 insertions(+), 4 deletions(-)
arm64/gic.c +38 -4
index 5034b034..83b034e3 100644
@@ -24,6 +24,8 @@ static u64 gic_msi_size = 0;
 static bool vgic_is_init = false;
 static int gic_spi_base = GIC_SPI_IRQ_BASE;
 static int gic_ppi_base = GIC_PPI_IRQ_BASE;
+static int gic_spi_fdt_type = GIC_FDT_IRQ_TYPE_SPI;
+static int gic_ppi_fdt_type = GIC_FDT_IRQ_TYPE_PPI;
 
 int gic__get_spi_base(void)
 {
@@ -35,6 +37,26 @@ 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;
+}
+
+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;
+	}
+}
+
 struct kvm_irqfd_line {
 	unsigned int		gsi;
 	int			trigger_fd;
@@ -242,18 +264,28 @@ static int gic__set_dist(enum irqchip_type type)
 
 static int gic__set_spi(enum irqchip_type type)
 {
+	int spi_base, fdt_type;
+	int err;
+
 	switch (type) {
 	case IRQCHIP_GICV5:
-		gic_spi_base = GICV5_SPI_IRQ_BASE;
+		spi_base = GICV5_SPI_IRQ_BASE;
+		fdt_type = GICV5_FDT_IRQ_TYPE_SPI;
 		break;
 	default:
-		gic_spi_base = GIC_SPI_IRQ_BASE;
+		spi_base = GIC_SPI_IRQ_BASE;
+		fdt_type = GIC_FDT_IRQ_TYPE_SPI;
 		break;
 	}
 
-	if (gic_spi_base == GICV5_SPI_IRQ_BASE)
-		return irq__init_irq_offset(gic_spi_base);
+	if (spi_base == GICV5_SPI_IRQ_BASE) {
+		err = irq__init_irq_offset(spi_base);
+		if (err)
+			return err;
+	}
 
+	gic_spi_base = spi_base;
+	gic_spi_fdt_type = fdt_type;
 	return 0;
 }
 
@@ -262,9 +294,11 @@ 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;
 	}
 
arm64/include/kvm/gic.h +9 -0
index c4f78cde..9f1a3a25 100644
@@ -12,6 +12,12 @@
 #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 GICV5_FDT_IRQ_TYPE_PPI		GICV5_IRQ_TYPE_PPI
+#define GICV5_FDT_IRQ_TYPE_SPI		GICV5_IRQ_TYPE_SPI
+
 #define GIC_FDT_IRQ_PPI_CPU_SHIFT	8
 #define GIC_FDT_IRQ_PPI_CPU_MASK	(0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT)
 
@@ -38,6 +44,9 @@ struct kvm;
 
 int gic__get_spi_base(void);
 int gic__get_ppi_base(void);
+int gic__get_spi_fdt_type(void);
+int gic__get_ppi_fdt_type(void);
+int gic__encode_ppi_irq(enum irqchip_type type, int irq);
 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
#11 lore raw

PATCH v7 11/23 arm64: Describe the PMU interrupt for GICv5

In reply to Sascha Bischoff

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.

---
 arm64/pmu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arm64/pmu.c +8 -5
index bd3f2258..a190652a 100644
@@ -232,16 +232,17 @@ out_free:
 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;
 
+	irq_prop[0] = cpu_to_fdt32(gic__get_ppi_fdt_type());
+	irq_prop[1] = cpu_to_fdt32(irq - gic__get_ppi_base());
+	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)));
@@ -266,6 +267,8 @@ int pmu__init(struct kvm *kvm)
 		}
 	}
 
+	irq = gic__encode_ppi_irq(kvm->cfg.arch.irqchip, irq);
+
 	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
#12 lore raw

PATCH v7 12/23 arm64: Describe timer PPIs for GICv5

In reply to Sascha Bischoff

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.

---
 arm64/timer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arm64/timer.c +5 -3
index 2ac6144f..5eff1e48 100644
@@ -9,16 +9,18 @@ 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 = gic__get_ppi_fdt_type();
+	int ppi_base = gic__get_ppi_base();
 
 	if (!kvm->cfg.arch.nested_virt)
 		nr--;
 
 	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] - ppi_base);
 		irq_prop[i * 3 + 2] = cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW);
 	}
 
Signature · 1 line
2.34.1
#13 lore raw

PATCH v7 13/23 arm64: Assign CPU DT phandles

In reply to Sascha Bischoff

Assign stable phandles to all arm64 CPU nodes. The GICv5 IRS DT node uses them to map IAFFIDs to CPUs; they remain unreferenced for earlier GIC models.

---
 arm64/fdt.c                  | 1 +
 arm64/include/kvm/fdt-arch.h | 1 +
 2 files changed, 2 insertions(+)
arm64/fdt.c +1 -0
index b7324848..363b3ace 100644
@@ -54,6 +54,7 @@ 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));
+		_FDT(fdt_property_cell(fdt, "phandle", PHANDLE_CPU_BASE + cpu));
 		_FDT(fdt_end_node(fdt));
 	}
 
arm64/include/kvm/fdt-arch.h +1 -0
index 8a0a460e..2b667c53 100644
@@ -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
#14 lore raw

PATCH v7 14/23 arm64: Describe the GICv5 CPU interface in the DT

In reply to Sascha Bischoff

Emit 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
index 83b034e3..9a8f9916 100644
@@ -519,6 +519,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;
@@ -549,6 +551,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;
 	}
@@ -582,6 +586,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
#15 lore raw

PATCH v7 15/23 arm64: Describe the GICv5 IRS in the DT

In reply to Sascha Bischoff

Describe the IRS CONFIG frame and associate each CPU phandle with its IAFFID. This lets the guest discover and configure the IRS for shared interrupts.

KVM reserves address space for the adjacent SETLPI frame but does not currently emulate it, so leave it out of the guest DT.

---
 arm64/gic.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
arm64/gic.c +33 -0
index 9a8f9916..955eeb5f 100644
@@ -588,6 +588,15 @@ 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];
+	/* KVM reserves the SETLPI frame but does not emulate it. */
+	u64 irs_reg_prop[] = {
+		cpu_to_fdt64(ARM_GICV5_IRS_CONFIG_BASE),
+		cpu_to_fdt64(ARM_GICV5_IRS_CONFIG_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));
@@ -599,6 +608,30 @@ 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_string(fdt, "reg-names", "ns-config"));
+
+	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
#16 lore raw

PATCH v7 16/23 arm64: Generate GICv5 SPI specifiers for platform devices

In reply to Sascha Bischoff

Use the GICv5 interrupt type and absolute SPI number for platform devices. Preserve the legacy GICv2/v3 DT encoding for other VMs.

---
 arm64/fdt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arm64/fdt.c +4 -2
index 363b3ace..b6f268a5 100644
@@ -67,6 +67,8 @@ static void generate_irq_prop(void *fdt, const u8 *irqs,
 {
 	unsigned int i;
 	u32 *irq_prop;
+	u32 type = gic__get_spi_fdt_type();
+	int spi_base = gic__get_spi_base();
 
 	if (!num_irqs)
 		return;
@@ -76,8 +78,8 @@ static void generate_irq_prop(void *fdt, const u8 *irqs,
 		die("Failed to allocate the interrupts property");
 
 	for (i = 0; i < num_irqs; i++) {
-		irq_prop[3 * i] = cpu_to_fdt32(GIC_FDT_IRQ_TYPE_SPI);
-		irq_prop[3 * i + 1] = cpu_to_fdt32(irqs[i] - GIC_SPI_IRQ_BASE);
+		irq_prop[3 * i] = cpu_to_fdt32(type);
+		irq_prop[3 * i + 1] = cpu_to_fdt32(irqs[i] - spi_base);
 		irq_prop[3 * i + 2] = cpu_to_fdt32(irq_types[i]);
 	}
 
Signature · 1 line
2.34.1
#17 lore raw

PATCH v7 17/23 arm64: Generate GICv5 PCI INTx specifiers

In reply to Sascha Bischoff

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.

---
 arm64/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arm64/pci.c +4 -2
index db87db8b..91265f67 100644
@@ -84,6 +84,8 @@ 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 = gic__get_spi_fdt_type();
+		u32 int_id = irq - gic__get_spi_base();
 
 		/*
 		 * Avoid adding entries in "interrupt-map" for devices that
@@ -108,8 +110,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
#18 lore raw

PATCH v7 18/23 arm64: Expose the GICv5 irqchip option

In reply to 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.

---
 arm64/gic.c                         | 4 +++-
 arm64/include/kvm/kvm-config-arch.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
arm64/gic.c +3 -1
index 955eeb5f..c1408502 100644
@@ -78,6 +78,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;
@@ -405,7 +407,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
index adda6403..a1a9336a 100644
@@ -54,7 +54,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
#19 lore raw

PATCH v7 19/23 arm64: Add proposed GICv5 ITS UAPI definitions

In reply to Sascha Bischoff

Mirror the GICv5 ITS device type, address type and size from the posted KVM GICv5 ITS series. These definitions are not part of the v7.4-rc1 UAPI header sync.

---
 arm64/include/asm/kvm.h | 2 ++
 include/linux/kvm.h     | 2 ++
 2 files changed, 4 insertions(+)
arm64/include/asm/kvm.h +2 -0
index 65ee09bd..8c701173 100644
@@ -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
index 8dff2fc1..c0e11993 100644
@@ -1239,6 +1239,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
#20 lore raw

PATCH v7 20/23 arm64: Add GICv5 ITS device support

In reply to Sascha Bischoff

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.

---
 arm64/gic.c                  | 24 ++++++++++++++++++------
 arm64/include/kvm/gic.h      |  1 +
 arm64/include/kvm/kvm-arch.h |  8 ++++++++
 3 files changed, 27 insertions(+), 6 deletions(-)
arm64/gic.c +18 -6
index c1408502..2a59ca2e 100644
@@ -51,6 +51,7 @@ int gic__encode_ppi_irq(enum irqchip_type type, int irq)
 {
 	switch (type) {
 	case IRQCHIP_GICV5:
+	case IRQCHIP_GICV5_ITS:
 		return irq | (GICV5_IRQ_TYPE_PPI << GICV5_IRQ_TYPE_SHIFT);
 	default:
 		return irq;
@@ -136,15 +137,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 = {
@@ -155,8 +156,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;
 	}
 
@@ -185,7 +187,9 @@ static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type)
 	case IRQCHIP_GICV2M:
 		return gic__create_gicv2m_frame(kvm, gic_msi_base);
 	case IRQCHIP_GICV3_ITS:
-		return gic__create_its_frame(kvm, gic_msi_base);
+		return gic__create_its_frame(kvm, gic_msi_base, false);
+	case IRQCHIP_GICV5_ITS:
+		return gic__create_its_frame(kvm, gic_msi_base, true);
 	default:	/* No MSI frame needed */
 		return 0;
 	}
@@ -236,6 +240,7 @@ static int gic__set_irs(enum irqchip_type type)
 
 	switch (type) {
 	case IRQCHIP_GICV5:
+	case IRQCHIP_GICV5_ITS:
 		return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &irs_attr);
 	default:	/* No IRS needed */
 		return 0;
@@ -271,6 +276,7 @@ static int gic__set_spi(enum irqchip_type type)
 
 	switch (type) {
 	case IRQCHIP_GICV5:
+	case IRQCHIP_GICV5_ITS:
 		spi_base = GICV5_SPI_IRQ_BASE;
 		fdt_type = GICV5_FDT_IRQ_TYPE_SPI;
 		break;
@@ -295,6 +301,7 @@ static int gic__set_ppi(enum irqchip_type type)
 {
 	switch (type) {
 	case IRQCHIP_GICV5:
+	case IRQCHIP_GICV5_ITS:
 		gic_ppi_base = GICV5_PPI_IRQ_BASE;
 		gic_ppi_fdt_type = GICV5_FDT_IRQ_TYPE_PPI;
 		break;
@@ -323,6 +330,7 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
 	case IRQCHIP_GICV3_ITS:
 		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V3;
 		break;
+	case IRQCHIP_GICV5_ITS:
 	case IRQCHIP_GICV5:
 		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V5;
 		break;
@@ -432,6 +440,10 @@ 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;
+		/* fall through */
 	case IRQCHIP_GICV5:
 		gicv5_irs_base = ARM_GICV5_IRS_BASE;
 		break;
arm64/include/kvm/gic.h +1 -0
index 9f1a3a25..0a5c70a1 100644
@@ -38,6 +38,7 @@ enum irqchip_type {
 	IRQCHIP_GICV3,
 	IRQCHIP_GICV3_ITS,
 	IRQCHIP_GICV5,
+	IRQCHIP_GICV5_ITS,
 };
 
 struct kvm;
arm64/include/kvm/kvm-arch.h +8 -0
index d40dce35..12850351 100644
@@ -67,6 +67,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
#21 lore raw

PATCH v7 21/23 arm64: Describe the GICv5 ITS in the DT

In reply to Sascha Bischoff

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.

---
 arm64/gic.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arm64/gic.c +41 -0
index 2a59ca2e..2b24f5b6 100644
@@ -565,6 +565,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:
@@ -611,6 +612,16 @@ static void gic__generate_gicv5_fdt_nodes(void *fdt, struct kvm *kvm)
 		cpu_to_fdt64(ARM_GICV5_IRS_CONFIG_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));
@@ -644,6 +655,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
#22 lore raw

PATCH v7 22/23 arm64: Map PCI MSI requester IDs to the GICv5 ITS

In reply to Sascha Bischoff

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.

---
 arm64/pci.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
arm64/pci.c +17 -1
index 91265f67..69e180b5 100644
@@ -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,8 +76,18 @@ 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)
+	switch (irqchip) {
+	case IRQCHIP_GICV2M:
+	case IRQCHIP_GICV3_ITS:
 		_FDT(fdt_property_cell(fdt, "msi-parent", PHANDLE_MSI));
+		break;
+	case IRQCHIP_GICV5_ITS:
+		_FDT(fdt_property(fdt, "msi-map", msi_map, sizeof(msi_map)));
+		break;
+	default:
+		/* No MSI */
+		break;
+	}
 
 	generate_dma_region_prop(fdt);
 
Signature · 1 line
2.34.1
#23 lore raw

PATCH v7 23/23 arm64: Expose the GICv5 ITS irqchip option

In reply to Sascha Bischoff

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.

---
 arm64/gic.c                         | 4 +++-
 arm64/include/kvm/kvm-config-arch.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
arm64/gic.c +3 -1
index 2b24f5b6..230448e8 100644
@@ -81,6 +81,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;
@@ -415,7 +417,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
index a1a9336a..15cbd7c4 100644
@@ -54,7 +54,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
#24 lore raw
In reply to Sascha Bischoff
Quoted 10 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 creates a vGICv5 device and the latter adds a GICv5 ITS. The GICv5 specification can be found at [1].

The GICv5 support in KVM needed by --irqchip=gicv5 is available as of Linux v7.4-rc1. The GICv5 ITS support is described in [2]; using --irqchip=gicv5-its requires a KVM build with those changes.

[...]

Applied first 18 (i.e. sans ITS) to kvmtool (master), thanks!

[01/23] arm64: Propagate IRQ routing initialisation errors

        https://git.kernel.org/will/kvmtool/c/643c84fcabdf
[02/23] arm64: Close the ITS descriptor when setup fails
        https://git.kernel.org/will/kvmtool/c/fd4073f5e2e7
[03/23] arm64: Split GIC device setup
        https://git.kernel.org/will/kvmtool/c/c97b9ac472c4
[04/23] Sync kernel UAPI headers with v7.4-rc1
        https://git.kernel.org/will/kvmtool/c/31cacdfe9610
[05/23] arm64: Add GICv5 irqchip device support
        https://git.kernel.org/will/kvmtool/c/ebcac904ebc9
[06/23] arm64: Configure GIC interrupt bases
        https://git.kernel.org/will/kvmtool/c/3eda0ae06c3f
[07/23] irq: Allow the initial interrupt line number to be set
        https://git.kernel.org/will/kvmtool/c/2ec8a3ef3529
[08/23] arm64: Start GICv5 SPI line allocation at zero
        https://git.kernel.org/will/kvmtool/c/217760904a04
[09/23] arm64: Configure the GICv5 IRS
        https://git.kernel.org/will/kvmtool/c/94a57e57620e
[10/23] arm64: Define GICv5 interrupt types
        https://git.kernel.org/will/kvmtool/c/bb395ae93047
[11/23] arm64: Describe the PMU interrupt for GICv5
        https://git.kernel.org/will/kvmtool/c/886ac67b5f4b
[12/23] arm64: Describe timer PPIs for GICv5
        https://git.kernel.org/will/kvmtool/c/c6f9c988b76b
[13/23] arm64: Assign CPU DT phandles
        https://git.kernel.org/will/kvmtool/c/6794fb727311
[14/23] arm64: Describe the GICv5 CPU interface in the DT
        https://git.kernel.org/will/kvmtool/c/265b478fc159
[15/23] arm64: Describe the GICv5 IRS in the DT
        https://git.kernel.org/will/kvmtool/c/93d7111bc83e
[16/23] arm64: Generate GICv5 SPI specifiers for platform devices
        https://git.kernel.org/will/kvmtool/c/5ac92cbe187a
[17/23] arm64: Generate GICv5 PCI INTx specifiers
        https://git.kernel.org/will/kvmtool/c/a21cd5dababc
[18/23] arm64: Expose the GICv5 irqchip option
        https://git.kernel.org/will/kvmtool/c/c5b95e85d3c4

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev