All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] kvmtool: Add GICv3 emulation support
@ 2014-06-19 12:44 Andre Przywara
  2014-06-19 12:44 ` [PATCH 1/4] kvmtool: public header definitions from GICv3 emulation patch series Andre Przywara
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andre Przywara @ 2014-06-19 12:44 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: will.deacon, marc.zyngier

This is a first version of the kvmtool changes needed for GICv3
emulation. Allows testing of the GICv3 emulation code and allows
creating guests with more than 8 VCPUs (given that in the host
CONFIG_KVM_ARM_MAX_VCPUS and in the guest CONFIG_NR_CPUS have been
raised accordingly).
Use --gicv3 to create a GICv3 IRQ chip in the guest.

This goes on top of Marc's kvmtool-vgic-dyn branch on kernel.org:
https://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/kvmtool-vgic-dyn

This is not meant for merging right now, as it eventually needs to
be rebased on a more recent kvmtool version first.

Cheers,
Andre

Andre Przywara (4):
  kvmtool: public header definitions from GICv3 emulation patch series
  kvmtool: prepare for instantiating different IRQ chip devices
  kvmtool: add support for supplying GICv3 redistributor addresses
  kvmtool: add command line parameter to instantiate a vGICv3

 arch/arm64/include/uapi/asm/kvm.h                  |    6 ++
 include/uapi/linux/kvm.h                           |    1 +
 tools/kvm/arm/aarch64/arm-cpu.c                    |    5 +-
 tools/kvm/arm/aarch64/include/kvm/kvm-arch.h       |    6 ++
 .../kvm/arm/aarch64/include/kvm/kvm-config-arch.h  |    4 +-
 tools/kvm/arm/gic.c                                |  101 +++++++++++++++++---
 tools/kvm/arm/include/arm-common/gic.h             |    4 +-
 tools/kvm/arm/include/arm-common/kvm-arch.h        |   11 ++-
 tools/kvm/arm/include/arm-common/kvm-config-arch.h |    1 +
 tools/kvm/arm/kvm-cpu.c                            |    4 +-
 tools/kvm/arm/kvm.c                                |    4 +-
 tools/kvm/virtio/mmio.c                            |    2 +-
 12 files changed, 123 insertions(+), 26 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] kvmtool: public header definitions from GICv3 emulation patch series
  2014-06-19 12:44 [PATCH 0/4] kvmtool: Add GICv3 emulation support Andre Przywara
@ 2014-06-19 12:44 ` Andre Przywara
  2014-06-19 12:44 ` [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices Andre Przywara
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Andre Przywara @ 2014-06-19 12:44 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: will.deacon, marc.zyngier

This pulls the necessary defines for the GICv3 constants from the
Linux tree into kvmtool for now. Should be obsolete as soon as
the vGICv3 patches are upstream and kvmtool is rebased on top of
it.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 arch/arm64/include/uapi/asm/kvm.h |    6 ++++++
 include/uapi/linux/kvm.h          |    1 +
 2 files changed, 7 insertions(+)

diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 0dc731d..2c26821 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -75,6 +75,12 @@ struct kvm_regs {
 #define KVM_VGIC_V2_DIST_SIZE		0x1000
 #define KVM_VGIC_V2_CPU_SIZE		0x2000
 
+#define KVM_VGIC_V3_ADDR_TYPE_DIST	2
+#define KVM_VGIC_V3_ADDR_TYPE_REDIST	3
+
+#define KVM_VGIC_V3_DIST_SIZE		0x10000
+#define KVM_VGIC_V3_REDIST_SIZE		0x20000
+
 #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/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 932d7f2..3af4b60 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -855,6 +855,7 @@ struct kvm_device_attr {
 #define   KVM_DEV_VFIO_GROUP_ADD			1
 #define   KVM_DEV_VFIO_GROUP_DEL			2
 #define KVM_DEV_TYPE_ARM_VGIC_V2	5
+#define KVM_DEV_TYPE_ARM_VGIC_V3	7
 
 /*
  * ioctls for VM fds
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices
  2014-06-19 12:44 [PATCH 0/4] kvmtool: Add GICv3 emulation support Andre Przywara
  2014-06-19 12:44 ` [PATCH 1/4] kvmtool: public header definitions from GICv3 emulation patch series Andre Przywara
@ 2014-06-19 12:44 ` Andre Przywara
  2014-06-20 17:55   ` Will Deacon
  2014-06-19 12:44 ` [PATCH 3/4] kvmtool: add support for supplying GICv3 redistributor addresses Andre Przywara
  2014-06-19 12:44 ` [PATCH 4/4] kvmtool: add command line parameter to instantiate a vGICv3 Andre Przywara
  3 siblings, 1 reply; 6+ messages in thread
From: Andre Przywara @ 2014-06-19 12:44 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: will.deacon, marc.zyngier

Extend the vGIC handling code to deal with different IRQ chip devices
instead of hard-coding the GICv2 in.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 tools/kvm/arm/aarch64/arm-cpu.c        |    2 +-
 tools/kvm/arm/gic.c                    |   59 ++++++++++++++++++++++++--------
 tools/kvm/arm/include/arm-common/gic.h |    4 +--
 tools/kvm/arm/kvm.c                    |    2 +-
 tools/kvm/virtio/mmio.c                |    2 +-
 5 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c
index ce5ea2f..35771e0 100644
--- a/tools/kvm/arm/aarch64/arm-cpu.c
+++ b/tools/kvm/arm/aarch64/arm-cpu.c
@@ -12,7 +12,7 @@
 static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 {
 	int timer_interrupts[4] = {13, 14, 11, 10};
-	gic__generate_fdt_nodes(fdt, gic_phandle);
+	gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2);
 	timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
 }
 
diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c
index c92deaa..770c6e7 100644
--- a/tools/kvm/arm/gic.c
+++ b/tools/kvm/arm/gic.c
@@ -22,13 +22,13 @@ int gic__alloc_irqnum(void)
 	return irq;
 }
 
-static int gic__create_device(struct kvm *kvm)
+static int gic__create_device(struct kvm *kvm, u32 type)
 {
 	int err;
 	u32 offset = 0;
 	u64 dist_addr = ARM_GIC_DIST_BASE;
 	struct kvm_create_device gic_device = {
-		.type	= KVM_DEV_TYPE_ARM_VGIC_V2,
+		.type	= type,
 	};
 	struct kvm_device_attr offset_attr = {
 		.group	= KVM_DEV_ARM_VGIC_GRP_ADDR_OFFSET,
@@ -51,19 +51,28 @@ static int gic__create_device(struct kvm *kvm)
 
 	gic_fd = gic_device.fd;
 
-	if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &offset_attr)) {
-		err = ioctl(gic_fd, KVM_GET_DEVICE_ATTR, &offset_attr);
+	switch (type) {
+	case KVM_DEV_TYPE_ARM_VGIC_V2:
+		if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &offset_attr)) {
+			err = ioctl(gic_fd, KVM_GET_DEVICE_ATTR, &offset_attr);
+			if (err)
+				return err;
+		}
+
+		cpu_if_addr += offset;
+
+		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
 		if (err)
 			return err;
+		pr_info("creating GICv2 KVM device");
+		break;
+	default:
+		return -ENODEV;
 	}
 
-	cpu_if_addr += offset;
+	err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
 
-	err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
-	if (err)
-		return err;
-
-	return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
+	return err;
 }
 
 static int gic__create_irqchip(struct kvm *kvm)
@@ -94,7 +103,7 @@ static int gic__create_irqchip(struct kvm *kvm)
 	return err;
 }
 
-int gic__init_irqchip(struct kvm *kvm)
+static int gicv2__init_irqchip(struct kvm *kvm)
 {
 	int err;
 	int psz;
@@ -113,13 +122,22 @@ int gic__init_irqchip(struct kvm *kvm)
 	}
 
 	/* Try the new way first, and fallback on legacy method otherwise */
-	err = gic__create_device(kvm);
+	err = gic__create_device(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
 	if (err)
 		err = gic__create_irqchip(kvm);
 
 	return err;
 }
 
+int gic__init_irqchip(struct kvm *kvm, u32 type)
+{
+	switch (type) {
+	case KVM_DEV_TYPE_ARM_VGIC_V2:
+		return gicv2__init_irqchip(kvm);
+	}
+	return -ENODEV;
+}
+
 static int gic__init_max_irq(struct kvm *kvm)
 {
 	u32 nr_irqs = ALIGN(irq_ids, 32) + GIC_SPI_IRQ_BASE;
@@ -142,15 +160,26 @@ static int gic__init_max_irq(struct kvm *kvm)
 }
 late_init(gic__init_max_irq)
 
-void gic__generate_fdt_nodes(void *fdt, u32 phandle)
+void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type)
 {
+	const char *compatible;
 	u64 reg_prop[] = {
-		cpu_to_fdt64(ARM_GIC_DIST_BASE), cpu_to_fdt64(ARM_GIC_DIST_SIZE),
+		cpu_to_fdt64(ARM_GIC_DIST_BASE),
+		cpu_to_fdt64(ARM_GIC_DIST_SIZE),
 		cpu_to_fdt64(cpu_if_addr), cpu_to_fdt64(ARM_GIC_CPUI_SIZE),
 	};
 
+	switch (type) {
+	case KVM_DEV_TYPE_ARM_VGIC_V2:
+		compatible = "arm,cortex-a15-gic";
+		pr_info("creating FDT for a GICv2");
+		break;
+	default:
+		return;
+	}
+
 	_FDT(fdt_begin_node(fdt, "intc"));
-	_FDT(fdt_property_string(fdt, "compatible", "arm,cortex-a15-gic"));
+	_FDT(fdt_property_string(fdt, "compatible", compatible));
 	_FDT(fdt_property_cell(fdt, "#interrupt-cells", GIC_FDT_IRQ_NUM_CELLS));
 	_FDT(fdt_property(fdt, "interrupt-controller", NULL, 0));
 	_FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop)));
diff --git a/tools/kvm/arm/include/arm-common/gic.h b/tools/kvm/arm/include/arm-common/gic.h
index 850edc7..ac6bdb6 100644
--- a/tools/kvm/arm/include/arm-common/gic.h
+++ b/tools/kvm/arm/include/arm-common/gic.h
@@ -29,7 +29,7 @@
 struct kvm;
 
 int gic__alloc_irqnum(void);
-int gic__init_irqchip(struct kvm *kvm);
-void gic__generate_fdt_nodes(void *fdt, u32 phandle);
+int gic__init_irqchip(struct kvm *kvm, u32 type);
+void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type);
 
 #endif /* ARM_COMMON__GIC_H */
diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c
index 008b7fe..faf4702 100644
--- a/tools/kvm/arm/kvm.c
+++ b/tools/kvm/arm/kvm.c
@@ -80,6 +80,6 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 		MADV_MERGEABLE);
 
 	/* Initialise the virtual GIC. */
-	if (gic__init_irqchip(kvm))
+	if (gic__init_irqchip(kvm, KVM_DEV_TYPE_ARM_VGIC_V2))
 		die("Failed to initialise virtual GIC");
 }
diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c
index afae6a7..35dc113 100644
--- a/tools/kvm/virtio/mmio.c
+++ b/tools/kvm/virtio/mmio.c
@@ -293,7 +293,7 @@ int virtio_mmio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
 	 *
 	 * virtio_mmio.devices=0x200@0xd2000000:5,0x200@0xd2000200:6
 	 */
-	pr_info("virtio-mmio.devices=0x%x@0x%x:%d\n", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line);
+	pr_info("virtio-mmio.devices=0x%x@0x%x:%d", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line);
 
 	return 0;
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] kvmtool: add support for supplying GICv3 redistributor addresses
  2014-06-19 12:44 [PATCH 0/4] kvmtool: Add GICv3 emulation support Andre Przywara
  2014-06-19 12:44 ` [PATCH 1/4] kvmtool: public header definitions from GICv3 emulation patch series Andre Przywara
  2014-06-19 12:44 ` [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices Andre Przywara
@ 2014-06-19 12:44 ` Andre Przywara
  2014-06-19 12:44 ` [PATCH 4/4] kvmtool: add command line parameter to instantiate a vGICv3 Andre Przywara
  3 siblings, 0 replies; 6+ messages in thread
From: Andre Przywara @ 2014-06-19 12:44 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: will.deacon, marc.zyngier

The code currently is assuming fixed sized memory regions for the
distributor and CPU interface. GICv3 needs a dynamic allocation of
it's redistributor region, since it's size depends on the number of
vCPUs.
Also add the necessary code to create a GICv3 IRQ chip instance.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 tools/kvm/arm/aarch64/include/kvm/kvm-arch.h |    6 ++++++
 tools/kvm/arm/gic.c                          |   29 ++++++++++++++++++++++++--
 tools/kvm/arm/include/arm-common/kvm-arch.h  |   11 ++++++----
 tools/kvm/arm/kvm-cpu.c                      |    4 +++-
 4 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/arm/aarch64/include/kvm/kvm-arch.h b/tools/kvm/arm/aarch64/include/kvm/kvm-arch.h
index 4925736..42d0fd6 100644
--- a/tools/kvm/arm/aarch64/include/kvm/kvm-arch.h
+++ b/tools/kvm/arm/aarch64/include/kvm/kvm-arch.h
@@ -3,6 +3,12 @@
 
 #define ARM_GIC_DIST_SIZE	0x10000
 #define ARM_GIC_CPUI_SIZE	0x20000
+/*
+ * On a GICv3 there must be one redistributor per vCPU.
+ * The value here is the size for one, we multiply this at runtime with
+ * the number of requested vCPUs to get the actual size.
+ */
+#define ARM_GIC_REDIST_SIZE	0x20000
 
 #define ARM_KERN_OFFSET(kvm)	((kvm)->cfg.arch.aarch32_guest	?	\
 				0x8000				:	\
diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c
index 770c6e7..5141868 100644
--- a/tools/kvm/arm/gic.c
+++ b/tools/kvm/arm/gic.c
@@ -11,6 +11,7 @@
 static int irq_ids;
 static int gic_fd = -1;
 static u64 cpu_if_addr = ARM_GIC_CPUI_BASE;
+static int nr_redists = 0;
 
 int gic__alloc_irqnum(void)
 {
@@ -27,6 +28,7 @@ static int gic__create_device(struct kvm *kvm, u32 type)
 	int err;
 	u32 offset = 0;
 	u64 dist_addr = ARM_GIC_DIST_BASE;
+	u64 redist_addr;
 	struct kvm_create_device gic_device = {
 		.type	= type,
 	};
@@ -41,9 +43,13 @@ static int gic__create_device(struct kvm *kvm, u32 type)
 	};
 	struct kvm_device_attr dist_attr = {
 		.group	= KVM_DEV_ARM_VGIC_GRP_ADDR,
-		.attr	= KVM_VGIC_V2_ADDR_TYPE_DIST,
 		.addr	= (u64)(unsigned long)&dist_addr,
 	};
+	struct kvm_device_attr redist_attr = {
+		.group	= KVM_DEV_ARM_VGIC_GRP_ADDR,
+		.attr	= KVM_VGIC_V3_ADDR_TYPE_REDIST,
+		.addr	= (u64)(unsigned long)&redist_addr,
+	};
 
 	err = ioctl(kvm->vm_fd, KVM_CREATE_DEVICE, &gic_device);
 	if (err)
@@ -64,13 +70,23 @@ static int gic__create_device(struct kvm *kvm, u32 type)
 		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
 		if (err)
 			return err;
+		dist_attr.attr = KVM_VGIC_V2_ADDR_TYPE_DIST;
 		pr_info("creating GICv2 KVM device");
 		break;
+	case KVM_DEV_TYPE_ARM_VGIC_V3:
+		dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST;
+		redist_addr = dist_addr - nr_redists * ARM_GIC_REDIST_SIZE;
+		break;
 	default:
 		return -ENODEV;
 	}
 
 	err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr);
+	if (err)
+		return err;
+
+	if (type == KVM_DEV_TYPE_ARM_VGIC_V3)
+		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr);
 
 	return err;
 }
@@ -166,17 +182,26 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type)
 	u64 reg_prop[] = {
 		cpu_to_fdt64(ARM_GIC_DIST_BASE),
 		cpu_to_fdt64(ARM_GIC_DIST_SIZE),
-		cpu_to_fdt64(cpu_if_addr), cpu_to_fdt64(ARM_GIC_CPUI_SIZE),
+		0, 0,				/* to be filled */
 	};
 
 	switch (type) {
 	case KVM_DEV_TYPE_ARM_VGIC_V2:
 		compatible = "arm,cortex-a15-gic";
+		reg_prop[2] = cpu_if_addr;
+		reg_prop[3] = ARM_GIC_CPUI_SIZE;
 		pr_info("creating FDT for a GICv2");
 		break;
+	case KVM_DEV_TYPE_ARM_VGIC_V3:
+		compatible = "arm,gic-v3";
+		reg_prop[2] = ARM_GIC_DIST_BASE - nr_redists * ARM_GIC_REDIST_SIZE;
+		reg_prop[3] = ARM_GIC_REDIST_SIZE * nr_redists;
+		break;
 	default:
 		return;
 	}
+	reg_prop[2] = cpu_to_fdt64(reg_prop[2]);
+	reg_prop[3] = cpu_to_fdt64(reg_prop[3]);
 
 	_FDT(fdt_begin_node(fdt, "intc"));
 	_FDT(fdt_property_string(fdt, "compatible", compatible));
diff --git a/tools/kvm/arm/include/arm-common/kvm-arch.h b/tools/kvm/arm/include/arm-common/kvm-arch.h
index 72b204f..c7bfd9a 100644
--- a/tools/kvm/arm/include/arm-common/kvm-arch.h
+++ b/tools/kvm/arm/include/arm-common/kvm-arch.h
@@ -15,10 +15,8 @@
 
 #define ARM_GIC_DIST_BASE	(ARM_AXI_AREA - ARM_GIC_DIST_SIZE)
 #define ARM_GIC_CPUI_BASE	(ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE)
-#define ARM_GIC_SIZE		(ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE)
 
 #define ARM_IOPORT_SIZE		(ARM_MMIO_AREA - ARM_IOPORT_AREA)
-#define ARM_VIRTIO_MMIO_SIZE	(ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE))
 #define ARM_PCI_MMIO_SIZE	(ARM_MEMORY_AREA - ARM_AXI_AREA)
 
 #define KVM_IOPORT_AREA		ARM_IOPORT_AREA
@@ -33,9 +31,14 @@ static inline bool arm_addr_in_ioport_region(u64 phys_addr)
 	return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit;
 }
 
-static inline bool arm_addr_in_virtio_mmio_region(u64 phys_addr)
+static inline bool arm_addr_in_virtio_mmio_region(int nr_redists, u64 phys_addr)
 {
-	u64 limit = KVM_VIRTIO_MMIO_AREA + ARM_VIRTIO_MMIO_SIZE;
+	u64 limit = ARM_AXI_AREA - ARM_GIC_DIST_SIZE;
+
+	if (nr_redists)
+		limit -= ARM_GIC_REDIST_SIZE * nr_redists;
+	else
+		limit -= ARM_GIC_CPUI_SIZE;
 	return phys_addr >= KVM_VIRTIO_MMIO_AREA && phys_addr < limit;
 }
 
diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c
index d31e7b1..30fe702 100644
--- a/tools/kvm/arm/kvm-cpu.c
+++ b/tools/kvm/arm/kvm-cpu.c
@@ -101,7 +101,9 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
 bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len,
 			   u8 is_write)
 {
-	if (arm_addr_in_virtio_mmio_region(phys_addr)) {
+	int nr_redists = kvm->cfg.arch.gicv3 ? kvm->nrcpus : 0;
+
+	if (arm_addr_in_virtio_mmio_region(nr_redists, phys_addr)) {
 		return kvm__emulate_mmio(kvm, phys_addr, data, len, is_write);
 	} else if (arm_addr_in_ioport_region(phys_addr)) {
 		int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] kvmtool: add command line parameter to instantiate a vGICv3
  2014-06-19 12:44 [PATCH 0/4] kvmtool: Add GICv3 emulation support Andre Przywara
                   ` (2 preceding siblings ...)
  2014-06-19 12:44 ` [PATCH 3/4] kvmtool: add support for supplying GICv3 redistributor addresses Andre Przywara
@ 2014-06-19 12:44 ` Andre Przywara
  3 siblings, 0 replies; 6+ messages in thread
From: Andre Przywara @ 2014-06-19 12:44 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: will.deacon, marc.zyngier

Add the command line parameter "--gicv3" to request GICv3 emulation
in the kernel. Connect that to the already existing GICv3 code.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 tools/kvm/arm/aarch64/arm-cpu.c                    |    5 ++++-
 .../kvm/arm/aarch64/include/kvm/kvm-config-arch.h  |    4 +++-
 tools/kvm/arm/gic.c                                |   17 +++++++++++++++++
 tools/kvm/arm/include/arm-common/kvm-config-arch.h |    1 +
 tools/kvm/arm/kvm.c                                |    4 +++-
 5 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c
index 35771e0..e3514ea 100644
--- a/tools/kvm/arm/aarch64/arm-cpu.c
+++ b/tools/kvm/arm/aarch64/arm-cpu.c
@@ -12,7 +12,10 @@
 static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle)
 {
 	int timer_interrupts[4] = {13, 14, 11, 10};
-	gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2);
+	gic__generate_fdt_nodes(fdt, gic_phandle,
+				kvm->cfg.arch.gicv3 ?
+					KVM_DEV_TYPE_ARM_VGIC_V3 :
+					KVM_DEV_TYPE_ARM_VGIC_V2);
 	timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
 }
 
diff --git a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h
index 89860ae..780a6d1 100644
--- a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h
+++ b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h
@@ -3,7 +3,9 @@
 
 #define ARM_OPT_ARCH_RUN(cfg)						\
 	OPT_BOOLEAN('\0', "aarch32", &(cfg)->aarch32_guest,		\
-			"Run AArch32 guest"),
+			"Run AArch32 guest"),				\
+	OPT_BOOLEAN('\0', "gicv3", &(cfg)->gicv3,			\
+			"use a GICv3 interrupt controller in the guest"),
 
 #include "arm-common/kvm-config-arch.h"
 
diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c
index 5141868..15dc99d 100644
--- a/tools/kvm/arm/gic.c
+++ b/tools/kvm/arm/gic.c
@@ -76,6 +76,7 @@ static int gic__create_device(struct kvm *kvm, u32 type)
 	case KVM_DEV_TYPE_ARM_VGIC_V3:
 		dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST;
 		redist_addr = dist_addr - nr_redists * ARM_GIC_REDIST_SIZE;
+		pr_info("creating GICv3 KVM device");
 		break;
 	default:
 		return -ENODEV;
@@ -119,6 +120,17 @@ static int gic__create_irqchip(struct kvm *kvm)
 	return err;
 }
 
+static int gicv3__init_irqchip(struct kvm *kvm)
+{
+	if (kvm->nrcpus > 255) {
+		pr_warning("%d CPUS greater than maximum of %d -- truncating\n",
+				kvm->nrcpus, 255);
+		kvm->nrcpus = 255;
+	}
+
+	return gic__create_device(kvm, KVM_DEV_TYPE_ARM_VGIC_V3);
+}
+
 static int gicv2__init_irqchip(struct kvm *kvm)
 {
 	int err;
@@ -150,6 +162,9 @@ int gic__init_irqchip(struct kvm *kvm, u32 type)
 	switch (type) {
 	case KVM_DEV_TYPE_ARM_VGIC_V2:
 		return gicv2__init_irqchip(kvm);
+	case KVM_DEV_TYPE_ARM_VGIC_V3:
+		nr_redists = kvm->cfg.nrcpus;
+		return gicv3__init_irqchip(kvm);
 	}
 	return -ENODEV;
 }
@@ -196,6 +211,8 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type)
 		compatible = "arm,gic-v3";
 		reg_prop[2] = ARM_GIC_DIST_BASE - nr_redists * ARM_GIC_REDIST_SIZE;
 		reg_prop[3] = ARM_GIC_REDIST_SIZE * nr_redists;
+		pr_info("creating FDT for a GICv3 with %d redistributors",
+			nr_redists);
 		break;
 	default:
 		return;
diff --git a/tools/kvm/arm/include/arm-common/kvm-config-arch.h b/tools/kvm/arm/include/arm-common/kvm-config-arch.h
index f3baf39..088b012 100644
--- a/tools/kvm/arm/include/arm-common/kvm-config-arch.h
+++ b/tools/kvm/arm/include/arm-common/kvm-config-arch.h
@@ -7,6 +7,7 @@ struct kvm_config_arch {
 	const char *dump_dtb_filename;
 	unsigned int force_cntfrq;
 	bool aarch32_guest;
+	bool gicv3;
 };
 
 #define OPT_ARCH_RUN(pfx, cfg)							\
diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c
index faf4702..3858170 100644
--- a/tools/kvm/arm/kvm.c
+++ b/tools/kvm/arm/kvm.c
@@ -80,6 +80,8 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 		MADV_MERGEABLE);
 
 	/* Initialise the virtual GIC. */
-	if (gic__init_irqchip(kvm, KVM_DEV_TYPE_ARM_VGIC_V2))
+	if (gic__init_irqchip(kvm, kvm->cfg.arch.gicv3 ?
+				   KVM_DEV_TYPE_ARM_VGIC_V3 :
+				   KVM_DEV_TYPE_ARM_VGIC_V2))
 		die("Failed to initialise virtual GIC");
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices
  2014-06-19 12:44 ` [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices Andre Przywara
@ 2014-06-20 17:55   ` Will Deacon
  0 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2014-06-20 17:55 UTC (permalink / raw)
  To: Andre Przywara; +Cc: kvmarm, kvm, Marc Zyngier

Hi Andre,

On Thu, Jun 19, 2014 at 01:44:37PM +0100, Andre Przywara wrote:
> Extend the vGIC handling code to deal with different IRQ chip devices
> instead of hard-coding the GICv2 in.

Minor comment, but there are a few stray pr_infos in here which I don't
think are especially useful.

> +		if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &offset_attr)) {
> +			err = ioctl(gic_fd, KVM_GET_DEVICE_ATTR, &offset_attr);
> +			if (err)
> +				return err;
> +		}
> +
> +		cpu_if_addr += offset;
> +
> +		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr);
>  		if (err)
>  			return err;
> +		pr_info("creating GICv2 KVM device");

One here...

> +	switch (type) {
> +	case KVM_DEV_TYPE_ARM_VGIC_V2:
> +		compatible = "arm,cortex-a15-gic";
> +		pr_info("creating FDT for a GICv2");

... and here.

> diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c
> index afae6a7..35dc113 100644
> --- a/tools/kvm/virtio/mmio.c
> +++ b/tools/kvm/virtio/mmio.c
> @@ -293,7 +293,7 @@ int virtio_mmio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
>  	 *
>  	 * virtio_mmio.devices=0x200@0xd2000000:5,0x200@0xd2000200:6
>  	 */
> -	pr_info("virtio-mmio.devices=0x%x@0x%x:%d\n", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line);
> +	pr_info("virtio-mmio.devices=0x%x@0x%x:%d", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line);

Huh?

Anyway, the general idea looks ok to me.

Will

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-20 17:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19 12:44 [PATCH 0/4] kvmtool: Add GICv3 emulation support Andre Przywara
2014-06-19 12:44 ` [PATCH 1/4] kvmtool: public header definitions from GICv3 emulation patch series Andre Przywara
2014-06-19 12:44 ` [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices Andre Przywara
2014-06-20 17:55   ` Will Deacon
2014-06-19 12:44 ` [PATCH 3/4] kvmtool: add support for supplying GICv3 redistributor addresses Andre Przywara
2014-06-19 12:44 ` [PATCH 4/4] kvmtool: add command line parameter to instantiate a vGICv3 Andre Przywara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.