kvmtool: arm64: GICv3 guest support
v5 cover kvmtool: arm64: GICv3 guest support
Hi,
only very minor changes (patch 7 and 10) compared to v4:
Any failure in instantiating a VCPU now makes kvmtool abort, so requesting more VCPUs than the selected kernel's VGIC emulation can handle will let the user know immediately ;-) Also I removed the unneeded initialization of the irqchip type to GICv2.
Will, can you apply this series?
Cheers,
Andre.
-----
Since Linux 3.19 the kernel can emulate a GICv3 for KVM guests. This allows more than 8 VCPUs in a guest and enables in-kernel irqchip for non-backwards-compatible GICv3 implementations.
This series updates kvmtool to support this feature.
The first half of the series is mostly from Marc and supports some newer features of the virtual GIC which we later depend on. The second part enables support for a guest GICv3 by adding a new command line parameter (--irqchip=).
We now use the KVM_CREATE_DEVICE interface to create a virtual GIC and only fall back to the now legacy KVM_CREATE_IRQCHIP call if the former is not supported by the kernel.
Also we use two new features the KVM_CREATE_DEVICE interface introduces:
* We now set the number of actually used interrupts to avoid allocating too many of them without ever using them.
* We tell the kernel explicitly that we are finished with the GIC initialisation. This is a requirement for future VGIC versions.
The final three patches introduce virtual GICv3 support, so on supported hardware (and given kernel support) the user can ask KVM to emulate a GICv3, lifting the 8 VCPU limit of KVM. This is done by specifying "--irqchip=gicv3" on the command line.
For the time being the kernel only supports a virtual GICv3 on ARM64, but as the GIC is shared in kvmtool, I had to add the macro definitions to not break the build on ARM.
This series goes on top of the new official stand-alone repo hosted on Will's kernel.org git [1].
Find a branch with those patches included at my repo [2].
[1] git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git
[2] git://linux-arm.org/kvmtool.git (branch gicv3/v5)
http://www.linux-arm.org/git?p=kvmtool.git;a=log;h=refs/heads/gicv3/v5
Andre Przywara (6):
arm: finish VGIC initialisation explicitly
arm: simplify MMIO dispatching
limit number of VCPUs on demand
arm: prepare for instantiating different IRQ chip devices
arm: add support for supplying GICv3 redistributor addresses
arm: use new irqchip parameter to create different vGIC types
Marc Zyngier (4):
AArch64: Reserve two 64k pages for GIC CPU interface AArch{32,64}: use KVM_CREATE_DEVICE & co to instanciate the GIC
irq: add irq__get_nr_allocated_lines
AArch{32,64}: dynamically configure the number of GIC interrupts
arm/aarch32/arm-cpu.c | 2 +- arm/aarch64/arm-cpu.c | 2 +- arm/aarch64/include/kvm/kvm-arch.h | 2 +- arm/gic.c | 189 +++++++++++++++++++++++++++++-- arm/include/arm-common/gic.h | 9 +- arm/include/arm-common/kvm-arch.h | 19 ++-- arm/include/arm-common/kvm-config-arch.h | 9 +- arm/include/arm-common/kvm-cpu-arch.h | 14 ++- arm/kvm-cpu.c | 16 --- arm/kvm.c | 6 +- include/kvm/irq.h | 1 + irq.c | 5 + 12 files changed, 225 insertions(+), 49 deletions(-)
Signature · 1 line
2.3.5
PATCH v5 1/10 AArch64: Reserve two 64k pages for GIC CPU interface
From: Marc Zyngier <[email protected]>
On AArch64 system with a GICv2, the GICC range can be aligned to the last 4k block of a 64k page, ending up straddling two 64k pages. In order not to conflict with the distributor mapping, allocate two 64k pages to the CPU interface.
--- arm/aarch64/include/kvm/kvm-arch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arm/aarch64/include/kvm/kvm-arch.h +1 -1
@@ -2,7 +2,7 @@#define KVM__KVM_ARCH_H #define ARM_GIC_DIST_SIZE 0x10000 -#define ARM_GIC_CPUI_SIZE 0x10000 +#define ARM_GIC_CPUI_SIZE 0x20000#define ARM_KERN_OFFSET (kvm) ((kvm)->cfg.arch.aarch32_guest ? \ 0x8000 : \
Signature · 1 line
2.3.5
PATCH v5 2/10 AArch{32, 64}: use KVM_CREATE_DEVICE & co to instanciate the GIC
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
As of 3.14, KVM/arm supports the creation/configuration of the GIC through a more generic device API, which is now the preferred way to do so.
Plumb the new API in, and allow the old code to be used as a fallback.
[Andre: Rename some functions on the way to differentiate between creation and initialisation more clearly and fix error path.]
--- arm/gic.c | 69 +++++++++++++++++++++++++++++++++++++++----- arm/include/arm-common/gic.h | 2 +- arm/kvm.c | 6 ++-- 3 files changed, 66 insertions(+), 11 deletions(-)
arm/gic.c +62 -7
@@ -7,7 +7,50 @@#include <linux/byteorder.h> #include <linux/kvm.h> -int gic__init_irqchip (struct kvm *kvm) +static int gic_fd =-1 ; + +static int gic__create_device (struct kvm *kvm) +{ +int err; +u64 cpu_if_addr =ARM_GIC_CPUI_BASE ; +u64 dist_addr =ARM_GIC_DIST_BASE ; +struct kvm_create_device gic_device = { + .type =KVM_DEV_TYPE_ARM_VGIC_V2 , + }; +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 , + .attr =KVM_VGIC_V2_ADDR_TYPE_DIST , + .addr = (u64 )(unsigned long )&dist_addr, + }; + + err =ioctl (kvm->vm_fd,KVM_CREATE_DEVICE , &gic_device); +if (err) +return err; + + gic_fd = gic_device.fd; + + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &cpu_if_attr); +if (err) + goto out_err; + + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &dist_attr); +if (err) + goto out_err; + +return 0 ; + +out_err: +close (gic_fd); + gic_fd =-1 ; +return err; +} + +static int gic__create_irqchip (struct kvm *kvm) {int err;struct kvm_arm_device_addr gic_addr[] = {
@@ -23,12 +66,6 @@ int gic__init_irqchip(struct kvm *kvm) } }; -if (kvm->nrcpus >GIC_MAX_CPUS ) { -pr_warning ("%d CPUS greater than maximum of %d -- truncating\n" , - kvm->nrcpus,GIC_MAX_CPUS ); - kvm->nrcpus =GIC_MAX_CPUS ; - } - err =ioctl (kvm->vm_fd,KVM_CREATE_IRQCHIP );if (err)return err;
@@ -41,6 +78,24 @@ int gic__init_irqchip(struct kvm *kvm)return err; } +int gic__create (struct kvm *kvm) +{ +int err; + +if (kvm->nrcpus >GIC_MAX_CPUS ) { +pr_warning ("%d CPUS greater than maximum of %d -- truncating\n" , + kvm->nrcpus,GIC_MAX_CPUS ); + kvm->nrcpus =GIC_MAX_CPUS ; + } + +/* Try the new way first, and fallback on legacy method otherwise */ + err =gic__create_device (kvm); +if (err) + err =gic__create_irqchip (kvm); + +return err; +} +void gic__generate_fdt_nodes (void *fdt,u32 phandle) {u64 reg_prop[] = {
arm/include/arm-common/gic.h +1 -1
@@ -24,7 +24,7 @@struct kvm ;int gic__alloc_irqnum (void ); -int gic__init_irqchip (struct kvm *kvm); +int gic__create (struct kvm *kvm);void gic__generate_fdt_nodes (void *fdt,u32 phandle);#endif /* ARM_COMMON__GIC_H */
arm/kvm.c +3 -3
@@ -81,7 +81,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)madvise (kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,MADV_MERGEABLE |MADV_HUGEPAGE ); -/* Initialise the virtual GIC. */ -if (gic__init_irqchip (kvm)) -die ("Failed to initialise virtual GIC" ); +/* Create the virtual GIC. */ +if (gic__create (kvm)) +die ("Failed to create virtual GIC" ); }
Signature · 1 line
2.3.5
PATCH v5 3/10 irq: add irq__get_nr_allocated_lines
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
The ARM GIC emulation needs to be told the number of interrupts it has to support. As commit 1c262fa1dc7bc ("kvm tools: irq: make irq__alloc_line generic") made the interrupt counter private, add a new accessor returning the number of interrupt lines we've allocated so far.
--- include/kvm/irq.h | 1 + irq.c | 5 +++++ 2 files changed, 6 insertions(+)
include/kvm/irq.h +1 -0
@@ -11,6 +11,7 @@struct kvm ;int irq__alloc_line (void ); +int irq__get_nr_allocated_lines (void );int irq__init (struct kvm *kvm);int irq__exit (struct kvm *kvm);
irq.c +5 -0
@@ -7,3 +7,8 @@ int irq__alloc_line(void) {return next_line++; } + +int irq__get_nr_allocated_lines (void ) +{ +return next_line -KVM_IRQ_OFFSET ; +}
Signature · 1 line
2.3.5
PATCH v5 4/10 AArch{32, 64}: dynamically configure the number of GIC interrupts
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
In order to reduce the memory usage of large guests (as well as improve performance), tell KVM about the number of interrupts we require.
To avoid synchronization with the various device creation, use a late_init callback to compute the GIC configuration. [Andre: rename to gic__init_gic() to ease future expansion]
--- arm/gic.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
arm/gic.c +25 -0
@@ -1,10 +1,12 @@#include "kvm/fdt.h" +#include "kvm/irq.h" #include "kvm/kvm.h" #include "kvm/virtio.h" #include "arm-common/gic.h" #include <linux/byteorder.h> +#include <linux/kernel.h> #include <linux/kvm.h> static int gic_fd =-1 ;
@@ -96,6 +98,29 @@ int gic__create(struct kvm *kvm)return err; } +static int gic__init_gic (struct kvm *kvm) +{ +int lines =irq__get_nr_allocated_lines (); +u32 nr_irqs =ALIGN (lines,32 ) +GIC_SPI_IRQ_BASE ; +struct kvm_device_attr nr_irqs_attr = { + .group =KVM_DEV_ARM_VGIC_GRP_NR_IRQS , + .addr = (u64 )(unsigned long )&nr_irqs, + }; + +/* +* If we didn't use the KVM_CREATE_DEVICE method, KVM will +* give us some default number of interrupts. +*/ +if (gic_fd <0 ) +return 0 ; + +if (!ioctl (gic_fd,KVM_HAS_DEVICE_ATTR , &nr_irqs_attr)) +return ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &nr_irqs_attr); + +return 0 ; +} +late_init (gic__init_gic) + void gic__generate_fdt_nodes(void *fdt, u32 phandle) {u64 reg_prop[] = {
Signature · 1 line
2.3.5
PATCH v5 5/10 arm: finish VGIC initialisation explicitly
In reply to Andre PrzywaraSince Linux 3.19-rc1 there is a new API to explicitly initialise the in-kernel GIC emulation by a userland KVM device call. Use that to tell the kernel we are finished with the GIC initialisation, since the automatic GIC init will only be provided as a legacy functionality in the future.
--- arm/gic.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
arm/gic.c +22 -3
@@ -98,24 +98,43 @@ int gic__create(struct kvm *kvm)return err; } +/* +* Sets the number of used interrupts and finalizes the GIC init explicitly. +*/ 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 ;struct kvm_device_attr nr_irqs_attr = { .group =KVM_DEV_ARM_VGIC_GRP_NR_IRQS , .addr = (u64 )(unsigned long )&nr_irqs, }; +struct kvm_device_attr vgic_init_attr = { + .group =KVM_DEV_ARM_VGIC_GRP_CTRL , + .attr =KVM_DEV_ARM_VGIC_CTRL_INIT , + };/* * If we didn't use the KVM_CREATE_DEVICE method, KVM will -* give us some default number of interrupts. +* give us some default number of interrupts. The GIC initialization +* will be done automatically in this case. */ if (gic_fd <0 )return 0 ; -if (!ioctl (gic_fd,KVM_HAS_DEVICE_ATTR , &nr_irqs_attr)) -return ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &nr_irqs_attr); +if (!ioctl (gic_fd,KVM_HAS_DEVICE_ATTR , &nr_irqs_attr)) { + ret =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &nr_irqs_attr); +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); +if (ret) +return ret; + }return 0 ; }
Signature · 1 line
2.3.5
PATCH v5 6/10 arm: simplify MMIO dispatching
In reply to Andre PrzywaraCurrently we separate any incoming MMIO request into one of the ARM memory map regions and take care to spare the GIC.
It turns out that this is unnecessary, as we only have one special region (the IO port area in the first 64 KByte). The MMIO rbtree takes care about unhandled MMIO ranges, so we can simply drop all the special range checking (except that for the IO range) in kvm_cpu__emulate_mmio().
As the GIC is handled in the kernel, a GIC MMIO access should never reach userland (and we don't know what to do with it anyway). This lets us delete some more code and simplifies future extensions (like expanding the GIC regions).
To be in line with the other architectures, move the now simpler code into a header file.
--- arm/include/arm-common/kvm-arch.h | 12 ------------ arm/include/arm-common/kvm-cpu-arch.h | 14 ++++++++++++-- arm/kvm-cpu.c | 16 ---------------- 3 files changed, 12 insertions(+), 30 deletions(-)
arm/include/arm-common/kvm-arch.h +0 -12
@@ -45,18 +45,6 @@ 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) -{ -u64 limit =KVM_VIRTIO_MMIO_AREA +ARM_VIRTIO_MMIO_SIZE ; -return phys_addr >=KVM_VIRTIO_MMIO_AREA && phys_addr < limit; -} - -static inline bool arm_addr_in_pci_region (u64 phys_addr) -{ -u64 limit =KVM_PCI_CFG_AREA +ARM_PCI_CFG_SIZE +ARM_PCI_MMIO_SIZE ; -return phys_addr >=KVM_PCI_CFG_AREA && phys_addr < limit; -} -struct kvm_arch {/* * We may have to align the guest memory for virtio, so keep the
arm/include/arm-common/kvm-cpu-arch.h +12 -2
@@ -44,8 +44,18 @@ static inline bool kvm_cpu__emulate_io(struct kvm_cpu *vcpu, u16 port, void *datreturn false; } -bool kvm_cpu__emulate_mmio (struct kvm_cpu *vcpu,u64 phys_addr,u8 *data, -u32 len,u8 is_write); +static inline bool kvm_cpu__emulate_mmio (struct kvm_cpu *vcpu,u64 phys_addr, +u8 *data,u32 len,u8 is_write) +{ +if (arm_addr_in_ioport_region (phys_addr)) { +int direction = is_write ?KVM_EXIT_IO_OUT :KVM_EXIT_IO_IN ; +u16 port = (phys_addr -KVM_IOPORT_AREA ) &USHRT_MAX ; + +return kvm__emulate_io (vcpu, port, data, direction, len,1 ); + } + +return kvm__emulate_mmio (vcpu, phys_addr, data, len, is_write); +}unsigned long kvm_cpu__get_vcpu_mpidr (struct kvm_cpu *vcpu);
arm/kvm-cpu.c +0 -16
@@ -139,22 +139,6 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)return false; } -bool kvm_cpu__emulate_mmio (struct kvm_cpu *vcpu,u64 phys_addr,u8 *data, -u32 len,u8 is_write) -{ -if (arm_addr_in_virtio_mmio_region (phys_addr)) { -return kvm__emulate_mmio (vcpu, 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 ; -u16 port = (phys_addr -KVM_IOPORT_AREA ) &USHRT_MAX ; -return kvm__emulate_io (vcpu, port, data, direction, len,1 ); - }else if (arm_addr_in_pci_region (phys_addr)) { -return kvm__emulate_mmio (vcpu, phys_addr, data, len, is_write); - } - -return false; -} -void kvm_cpu__show_page_tables (struct kvm_cpu *vcpu) { }
Signature · 1 line
2.3.5
PATCH v5 7/10 limit number of VCPUs on demand
In reply to Andre PrzywaraCurrently the ARM GIC checks the number of VCPUs against a fixed limit, which is GICv2 specific. Don't pretend we know better than the kernel and let's get rid of that explicit check.
We now fail if the number of requested VCPUs could not be instantiated instead of limiting the number of VCPUs.
--- arm/gic.c | 6 ------ 1 file changed, 6 deletions(-)
arm/gic.c +0 -6
@@ -84,12 +84,6 @@ int gic__create(struct kvm *kvm) {int err; -if (kvm->nrcpus >GIC_MAX_CPUS ) { -pr_warning ("%d CPUS greater than maximum of %d -- truncating\n" , - kvm->nrcpus,GIC_MAX_CPUS ); - kvm->nrcpus =GIC_MAX_CPUS ; - } -/* Try the new way first, and fallback on legacy method otherwise */ err =gic__create_device (kvm);if (err)
Signature · 1 line
2.3.5
PATCH v5 8/10 arm: prepare for instantiating different IRQ chip devices
In reply to Andre PrzywaraExtend the vGIC handling code to potentially deal with different IRQ chip devices instead of hard-coding the GICv2 in.
We extend most vGIC functions to take a type parameter, but still put GICv2 in at the top for the time being.
--- arm/aarch32/arm-cpu.c | 2 +- arm/aarch64/arm-cpu.c | 2 +- arm/gic.c | 44 +++++++++++++++++++++++++++++++++++--------- arm/include/arm-common/gic.h | 8 ++++++-- arm/kvm.c | 2 +- 5 files changed, 44 insertions(+), 14 deletions(-)
arm/aarch32/arm-cpu.c +1 -1
@@ -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,IRQCHIP_GICV2 );timer__generate_fdt_nodes (fdt, kvm, timer_interrupts); }
arm/aarch64/arm-cpu.c +1 -1
@@ -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,IRQCHIP_GICV2 );timer__generate_fdt_nodes (fdt, kvm, timer_interrupts); }
arm/gic.c +35 -9
93 lines not on this page · raw message
arm/include/arm-common/gic.h +6 -2
@@ -21,10 +21,14 @@#define GIC_MAX_CPUS 8#define GIC_MAX_IRQ 255 +enum irqchip_type { +IRQCHIP_GICV2 , +}; +struct kvm ;int gic__alloc_irqnum (void ); -int gic__create (struct kvm *kvm); -void gic__generate_fdt_nodes (void *fdt,u32 phandle); +int gic__create (struct kvm *kvm,enum irqchip_type type); +void gic__generate_fdt_nodes (void *fdt,u32 phandle,enum irqchip_type type);#endif /* ARM_COMMON__GIC_H */
arm/kvm.c +1 -1
@@ -82,6 +82,6 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) MADV_MERGEABLE | MADV_HUGEPAGE);/* Create the virtual GIC. */ -if (gic__create (kvm)) +if (gic__create (kvm,IRQCHIP_GICV2 ))die ("Failed to create virtual GIC" ); }
Signature · 1 line
2.3.5
PATCH v5 9/10 arm: add support for supplying GICv3 redistributor addresses
In reply to Andre PrzywaraInstead of the GIC virtual CPU interface an emulated GICv3 needs to have accesses to its emulated redistributors trapped in the guest. Add code to tell the kernel about the mapping if a GICv3 emulation was requested by the user.
This contains some defines which are not (yet) in the (32 bit) header files to allow compilation for ARM.
--- arm/gic.c | 36 +++++++++++++++++++++++++++++++++++- arm/include/arm-common/gic.h | 1 + arm/include/arm-common/kvm-arch.h | 7 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-)
arm/gic.c +35 -1
@@ -9,7 +9,18 @@#include <linux/kernel.h> #include <linux/kvm.h> +/* Those names are not defined for ARM (yet) */ +#ifndef KVM_VGIC_V3_ADDR_TYPE_DIST +#define KVM_VGIC_V3_ADDR_TYPE_DIST 2 +#endif + +#ifndef KVM_VGIC_V3_ADDR_TYPE_REDIST +#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 +#endif +static int gic_fd =-1 ; +static u64 gic_redists_base; +static u64 gic_redists_size;static int gic__create_device (struct kvm *kvm,enum irqchip_type type) {
@@ -28,12 +39,21 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) .group = KVM_DEV_ARM_VGIC_GRP_ADDR, .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 )&gic_redists_base, + };switch (type) {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 : + gic_device.type =KVM_DEV_TYPE_ARM_VGIC_V3 ; + dist_attr.attr =KVM_VGIC_V3_ADDR_TYPE_DIST ; +break ; } err =ioctl (kvm->vm_fd,KVM_CREATE_DEVICE , &gic_device);
@@ -46,6 +66,9 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)case IRQCHIP_GICV2 : err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &cpu_if_attr);break ; +case IRQCHIP_GICV3 : + err =ioctl (gic_fd,KVM_SET_DEVICE_ATTR , &redist_attr); +break ; }if (err) goto out_err;
@@ -97,6 +120,10 @@ int gic__create(struct kvm *kvm, enum irqchip_type type)switch (type) {case IRQCHIP_GICV2 :break ; +case IRQCHIP_GICV3 : + gic_redists_size = kvm->cfg.nrcpus *ARM_GIC_REDIST_SIZE ; + gic_redists_base =ARM_GIC_DIST_BASE - gic_redists_size; +break ;default :return -ENODEV ; }
@@ -156,12 +183,19 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, enum irqchip_type 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_CPUI_BASE ),cpu_to_fdt64 (ARM_GIC_CPUI_SIZE ), +0 ,0 ,/* to be filled */ };switch (type) {case IRQCHIP_GICV2 : compatible ="arm,cortex-a15-gic" ; + reg_prop[2 ] =cpu_to_fdt64 (ARM_GIC_CPUI_BASE ); + reg_prop[3 ] =cpu_to_fdt64 (ARM_GIC_CPUI_SIZE ); +break ; +case IRQCHIP_GICV3 : + compatible ="arm,gic-v3" ; + reg_prop[2 ] =cpu_to_fdt64 (gic_redists_base); + reg_prop[3 ] =cpu_to_fdt64 (gic_redists_size);break ;default :return ;
arm/include/arm-common/gic.h +1 -0
@@ -23,6 +23,7 @@enum irqchip_type {IRQCHIP_GICV2 , +IRQCHIP_GICV3 , };struct kvm ;
arm/include/arm-common/kvm-arch.h +7 -0
@@ -30,6 +30,13 @@#define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE)#define KVM_VIRTIO_MMIO_AREA ARM_MMIO_AREA +/* +* 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 KVM_IRQ_OFFSET GIC_SPI_IRQ_BASE#define KVM_VM_TYPE 0
Signature · 1 line
2.3.5
PATCH v5 10/10 arm: use new irqchip parameter to create different vGIC types
In reply to Andre PrzywaraCurrently we unconditionally create a virtual GICv2 in the guest. Add a --irqchip= parameter to let the user specify a different GIC type for the guest, when omitting this parameter it still defaults to --irqchip=gicv2.
For now the only other supported type is --irqchip=gicv3
--- arm/aarch64/arm-cpu.c | 2 +- arm/gic.c | 16 ++++++++++++++++ arm/include/arm-common/kvm-config-arch.h | 9 ++++++++- arm/kvm.c | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-)
arm/aarch64/arm-cpu.c +1 -1
@@ -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,IRQCHIP_GICV2 ); +gic__generate_fdt_nodes (fdt, gic_phandle, kvm->cfg.arch.irqchip);timer__generate_fdt_nodes (fdt, kvm, timer_interrupts); }
arm/gic.c +16 -0
@@ -22,6 +22,22 @@ static int gic_fd = -1;static u64 gic_redists_base;static u64 gic_redists_size; +int irqchip_parser (const struct option *opt,const char *arg,int unset) +{ +enum irqchip_type *type = opt->value; + +if (!strcmp (arg,"gicv2" )) { + *type =IRQCHIP_GICV2 ; + }else if (!strcmp (arg,"gicv3" )) { + *type =IRQCHIP_GICV3 ; + }else { +fprintf (stderr,"irqchip: unknown type \"%s\"\n" , arg); +return -1 ; + } + +return 0 ; +} +static int gic__create_device (struct kvm *kvm,enum irqchip_type type) {int err;
arm/include/arm-common/kvm-config-arch.h +8 -1
@@ -8,8 +8,11 @@ struct kvm_config_arch {unsigned int force_cntfrq;bool virtio_trans_pci;bool aarch32_guest; +enum irqchip_type irqchip; }; +int irqchip_parser (const struct option *opt,const char *arg,int unset); +#define OPT_ARCH_RUN (pfx, cfg) \ pfx, \ ARM_OPT_ARCH_RUN(cfg) \
@@ -21,6 +24,10 @@ struct kvm_config_arch { "updated to program CNTFRQ correctly*"), \OPT_BOOLEAN ('\0' ,"force-pci" , &(cfg)->virtio_trans_pci, \"Force virtio devices to use PCI as their default " \ - "transport"), +"transport" ), \ +OPT_CALLBACK ('\0' ,"irqchip" , &(cfg)->irqchip, \ +"[gicv2|gicv3]" , \ +"type of interrupt controller to emulate in the guest" , \ + irqchip_parser, NULL), #endif /* ARM_COMMON__KVM_CONFIG_ARCH_H */
arm/kvm.c +1 -1
@@ -82,6 +82,6 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) MADV_MERGEABLE | MADV_HUGEPAGE);/* Create the virtual GIC. */ -if (gic__create (kvm,IRQCHIP_GICV2 )) +if (gic__create (kvm, kvm->cfg.arch.irqchip))die ("Failed to create virtual GIC" ); }
Signature · 1 line
2.3.5