vGICv3 support
v14 cover vGICv3 support
This series introduces support for GICv3 by KVM. Software emulation is currently not supported.
v13 => v14
- Rebased on the latest master, fixed conflicts in hw/arm/virt.c
v12 => v13
- Many stylistic fixes
- Fixed up ACPI data for virt machine
- Added gic-version=host value which probes for best possible vGIC version
- Reserved regions for memory-mapped CPU/vCPU/HYP interfaces
- Maximum number of CPUs for virt machine dropped to 123 (memory map limitation)
v11 => v12
- Do not set timer PPI CPU mask in device tree for GICv3
- Fixed small styling issues in hw/arm/virt.c
- Completely untied kvm_gic_access() from GIC and turned into kvm_device_access(). Attribute mapping is now handled in gicd/gicc wrapper macros.
v11 => v10
- Fixed minor issues with checkpatch and comments, reported by Eric Auger
- Make reusable kvm_gic_supports_attr(), moved to kvm-all.c and renamed as kvm_device_check_attr(). Useful for future live migration.
v9 => v10
- Renamed "gicversion" option to "gic-version" (was forgotten in v9)
- Data pointer in kvm_gic_access() is now void * because in case of vGICv3 this function is expected to operate on 64-bit registers too (GICD_IROUTER for instance)
v8 => v9
- Removed all limitations on CPU and IRQ number from the base class
- Added back missing properties, interface is now the same as in GICv2
- Refactored reusable parts of vGICv2 code, decreased number of changes
- Removed GIC type check from kvm_arch_irqchip_create(), no more need to specify GIC type early
- Fixed up all commit messages / logs
- Removed 'nvic' field assignment in virt machine (was forgotten in v8)
- CPU number limitation for 'virt' machine now comes from memory map (how many redistributors can be placed). With current layout it appears to be 126.
v7 => v8
- Removed all unused SW emulation code
- Removed unnecessary attributes from common class
- Set "unmigratable" flag for GICv3 device
- Removed unnecessary conditions from kvm_arm_gicv3_realize()
- Fixed GIC type setting in vexpress model, was done in wrong place
- Fixed condition style in hw/intc/Makefile.objs
- Cleaned up virt machine memory map
v6 => v7
- Wrap own GIC type definitions on top of KVM ones. Fixed build on non-ARM-Linux hosts
v5 => v6
- Fixed various checkpatch.pl style warnings
- Removed TODO in gicv3_init_irqs_and_mmio(), relevant memory API patch included
- gicv3_init_irqs_and_mmio() now takes 3 arguments instead of 4. It is more convenient to pass MMIO descriptors as array
v4 => v5
- Do not reintroduce several constants shared with GICv2, reuse them instead.
- Added gicv3_init_irqs_and_mmio() in base class, to be used by both software emulation and KVM code. Avoids code duplication.
- Do not add NULL msi-parent phandle to PCI device in the FDT
- Removed a couple of stale things from virt.c
v3 => v4
- Fixed stupid build breakage in patch 0002
- Rebased on top of current master, patch 0003 adjusted according to kvm_irqchip_create() changes
- Added assertion against uninitialized kernel_irqchip_type
- Removed kernel_irqchip_type initialization from models which do not use KVM vGIC
v2 => v3
- Removed some unrelated and unnecessary changes from virt machine, occasionally slipped in; some of them caused qemu to crash on ARM32.
- Fixed build for ARM32; vGICv3 code requires definitions which are present only in ARM64 kernel
v1 => v2
- Base class included, taken from the series by Shlomo Pongratz:
http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg01512.html
The code is refactored as little as possible in order to simplify further addition of software emulation:
- Minor fixes in code style and comments, according to old reviews
- Removed REV_V3 definition because it's currently not used, and it does not add any meaning to number 3.
- Removed reserved regions for MBI and ITS (except for 'virt' machine memory map). These should go to separate classes when implemented.
- Improved commit messages
- vGIC patches restructured
- Use 'gicversion' option instead of virt-v3 machine
Pavel Fedin (4):
intc/gic: Extract some reusable vGIC code
arm_kvm: Do not assume particular GIC type in
kvm_arch_irqchip_create()
hw/intc: Initial implementation of vGICv3 hw/arm/virt: Add gic-version option to virt machine
Shlomo Pongratz (1):
hw/intc: Implement GIC-500 base class
hw/arm/virt-acpi-build.c | 54 ++++++++------ hw/arm/virt.c | 124 ++++++++++++++++++++++++------ hw/intc/Makefile.objs | 2 + hw/intc/arm_gic_kvm.c | 98 ++++++++---------------- hw/intc/arm_gicv3_common.c | 140 ++++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_kvm.c | 149 +++++++++++++++++++++++++++++++++++++ hw/intc/vgic_common.h | 35 +++++++++ include/hw/acpi/acpi-defs.h | 9 +++ include/hw/arm/virt-acpi-build.h | 1 + include/hw/arm/virt.h | 4 +- include/hw/intc/arm_gicv3_common.h | 68 +++++++++++++++++ include/sysemu/kvm.h | 26 +++++++ kvm-all.c | 34 +++++++++ target-arm/kvm.c | 19 +++-- target-arm/kvm_arm.h | 19 +++++ target-arm/machine.c | 18 +++++ 16 files changed, 682 insertions(+), 118 deletions(-) create mode 100644 hw/intc/arm_gicv3_common.c create mode 100644 hw/intc/arm_gicv3_kvm.c create mode 100644 hw/intc/vgic_common.h create mode 100644 include/hw/intc/arm_gicv3_common.h
Signature · 1 line
2.4.4
PATCH v14 3/5 arm_kvm: Do not assume particular GIC type in kvm_arch_irqchip_create()
This allows us to use different GIC types from v2. There are no kernels which could advertise KVM_CAP_DEVICE_CTRL without the actual ability to create GIC with it.
GIC version probe code moved to kvm_arm_vgic_probe() which will be used later.
--- target-arm/kvm.c | 19 ++++++++++++------- target-arm/kvm_arm.h | 9 +++++++++ 2 files changed, 21 insertions(+), 7 deletions(-)
target-arm/kvm.c +12 -7
@@ -585,18 +585,23 @@ void kvm_arch_init_irq_routing(KVMState *s)int kvm_arch_irqchip_create (KVMState *s) { -int ret; -/* If we can create the VGIC using the newer device control API, we * let the device do this when it initializes itself, otherwise we * fall back to the old API */ +return kvm_check_extension (s,KVM_CAP_DEVICE_CTRL ); +} - ret =kvm_create_device (s,KVM_DEV_TYPE_ARM_VGIC_V2 , true); -if (ret ==0 ) { -return 1 ; +int kvm_arm_vgic_probe (void ) +{ +if (kvm_create_device (kvm_state, +KVM_DEV_TYPE_ARM_VGIC_V3 , true) ==0 ) { +return 3 ; + }else if (kvm_create_device (kvm_state, +KVM_DEV_TYPE_ARM_VGIC_V2 , true) ==0 ) { +return 2 ; + }else { +return 0 ; } - -return 0 ; } int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
target-arm/kvm_arm.h +9 -0
@@ -189,6 +189,15 @@ int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);*/ int kvm_arm_sync_mpstate_to_qemu (ARMCPU *cpu); +int kvm_arm_vgic_probe (void ); + +#else + +static inline int kvm_arm_vgic_probe (void ) +{ +return 0 ; +} +#endif static inline const char *gic_class_name (void )
Signature · 1 line
2.4.4
PATCH v14 1/5 hw/intc: Implement GIC-500 base class
In reply to Pavel FedinFrom: Shlomo Pongratz <[email protected]>
This class is to be used by both software and KVM implementations of GICv3
Currently it is mostly a placeholder, but in future it is supposed to hold qemu's representation of GICv3 state, which is necessary for migration.
The interface of this class is fully compatible with GICv2 one. This is done in order to simplify integration with existing code.
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3_common.c | 140 +++++++++++++++++++++++++++++++++++++ include/hw/intc/arm_gicv3_common.h | 68 ++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 hw/intc/arm_gicv3_common.c create mode 100644 include/hw/intc/arm_gicv3_common.h
hw/intc/Makefile.objs +1 -0
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gic.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv2m.o +common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_common.o common-obj-$(CONFIG_OPENPIC) += openpic.o obj-$(CONFIG_APIC) += apic.o apic_common.o
hw/intc/arm_gicv3_common.c new file +140 -0
140 lines not on this page · raw message
include/hw/intc/arm_gicv3_common.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.4.4
PATCH v14 2/5 intc/gic: Extract some reusable vGIC code
In reply to Pavel FedinSome functions previously used only by vGICv2 are useful also for vGICv3 implementation. Untie them from GICState and make accessible from within other modules:
- kvm_arm_gic_set_irq()
- kvm_gic_supports_attr() - moved to common code and renamed to kvm_device_check_attr()
- kvm_gic_access() - turned into GIC-independent kvm_device_access(). Data pointer changed to void * because some GICv3 registers are 64-bit wide
Some of these changes are not used right now, but they will be helpful for implementing live migration.
Actually kvm_dist_get() and kvm_dist_put() could also be made reusable, but they would require two extra parameters (s->dev_fd and s->num_cpu) as well as lots of typecasts of 's' to DeviceState * and back to GICState *. This makes the code very ugly so i decided to stop at this point. I tried also an approach with making a base class for all possible GICs, but it would contain only three variables (dev_fd, cpu_num and irq_num), and accessing them through the rest of the code would be again tedious (either ugly casts or qemu-style separate object pointer). So i disliked it too.
--- hw/intc/arm_gic_kvm.c | 98 +++++++++++++++++---------------------------------- hw/intc/vgic_common.h | 35 ++++++++++++++++++ include/sysemu/kvm.h | 26 ++++++++++++++ kvm-all.c | 34 ++++++++++++++++++ 4 files changed, 128 insertions(+), 65 deletions(-) create mode 100644 hw/intc/vgic_common.h
hw/intc/arm_gic_kvm.c +33 -65
@@ -23,6 +23,7 @@#include "sysemu/kvm.h" #include "kvm_arm.h" #include "gic_internal.h" +#include "vgic_common.h" //#define DEBUG_GIC_KVM
@@ -52,7 +53,7 @@ typedef struct KVMARMGICClass {void (*parent_reset)(DeviceState *dev); } KVMARMGICClass; -static void kvm_arm_gic_set_irq (void *opaque,int irq,int level) +void kvm_arm_gic_set_irq (uint32_t num_irq,int irq,int level) {/* Meaning of the 'irq' parameter: * [0..N-1] : external interrupts
@@ -63,10 +64,9 @@ static void kvm_arm_gic_set_irq(void *opaque, int irq, int level)* has separate fields in the irq number for type, * CPU number and interrupt number. */ -GICState *s = (GICState *)opaque;int kvm_irq, irqtype, cpu; -if (irq < (s->num_irq -GIC_INTERNAL )) { +if (irq < (num_irq -GIC_INTERNAL )) {/* External interrupt. The kernel numbers these like the GIC * hardware, with external interrupt IDs starting after the * internal ones.
@@ -77,7 +77,7 @@ static void kvm_arm_gic_set_irq(void *opaque, int irq, int level) }else {/* Internal interrupt: decode into (cpu, interrupt id) */ irqtype =KVM_ARM_IRQ_TYPE_PPI ; - irq -= (s->num_irq -GIC_INTERNAL ); + irq -= (num_irq -GIC_INTERNAL ); cpu = irq /GIC_INTERNAL ; irq %=GIC_INTERNAL ; }
@@ -87,69 +87,36 @@ static void kvm_arm_gic_set_irq(void *opaque, int irq, int level)kvm_set_irq (kvm_state, kvm_irq, !!level); } -static bool kvm_arm_gic_can_save_restore (GICState *s) -{ -return s->dev_fd >=0 ; -} - -static bool kvm_gic_supports_attr (GICState *s,int group,int attrnum) +static void kvm_arm_gicv2_set_irq (void *opaque,int irq,int level) { -struct kvm_device_attr attr = { - .group = group, - .attr = attrnum, - .flags =0 , - }; - -if (s->dev_fd ==-1 ) { -return false; - } +GICState *s = (GICState *)opaque; -return kvm_device_ioctl (s->dev_fd,KVM_HAS_DEVICE_ATTR , &attr) ==0 ; +kvm_arm_gic_set_irq (s->num_irq, irq, level); } -static void kvm_gic_access (GICState *s,int group,int offset, -int cpu,uint32_t *val,bool write) +static bool kvm_arm_gic_can_save_restore (GICState *s) { -struct kvm_device_attr attr; -int type; -int err; - - cpu = cpu &0xff ; - - attr.flags =0 ; - attr.group = group; - attr.attr = (((uint64_t )cpu <<KVM_DEV_ARM_VGIC_CPUID_SHIFT ) & -KVM_DEV_ARM_VGIC_CPUID_MASK ) | - (((uint64_t )offset <<KVM_DEV_ARM_VGIC_OFFSET_SHIFT ) & -KVM_DEV_ARM_VGIC_OFFSET_MASK ); - attr.addr = (uintptr_t )val; - -if (write) { - type =KVM_SET_DEVICE_ATTR ; - }else { - type =KVM_GET_DEVICE_ATTR ; - } - - err =kvm_device_ioctl (s->dev_fd, type, &attr); -if (err <0 ) { -fprintf (stderr,"KVM_{SET/GET}_DEVICE_ATTR failed: %s\n" , -strerror (-err)); -abort (); - } +return s->dev_fd >=0 ; } +#define KVM_VGIC_ATTR (offset, cpu) \ + ((((uint64_t)(cpu) << KVM_DEV_ARM_VGIC_CPUID_SHIFT) & \ + KVM_DEV_ARM_VGIC_CPUID_MASK) | \ + (((uint64_t)(offset) << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) & \ + KVM_DEV_ARM_VGIC_OFFSET_MASK)) +static void kvm_gicd_access (GICState *s,int offset,int cpu,uint32_t *val,bool write) { -kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_DIST_REGS , - offset, cpu, val, write); +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_DIST_REGS , +KVM_VGIC_ATTR (offset, cpu), val, write); }static void kvm_gicc_access (GICState *s,int offset,int cpu,uint32_t *val,bool write) { -kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_CPU_REGS , - offset, cpu, val, write); +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CPU_REGS , +KVM_VGIC_ATTR (offset, cpu), val, write); }#define for_each_irq_reg (_ctr, _max_irq, _field_width) \
@@ -559,7 +526,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)return ; } -gic_init_irqs_and_mmio (s, kvm_arm_gic_set_irq,NULL ); +gic_init_irqs_and_mmio (s, kvm_arm_gicv2_set_irq,NULL );for (i =0 ; i < s->num_irq -GIC_INTERNAL ; i++) {qemu_irq irq =qdev_get_gpio_in (dev, i);
@@ -571,23 +538,24 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp) ret =kvm_create_device (kvm_state,KVM_DEV_TYPE_ARM_VGIC_V2 , false);if (ret >=0 ) { s->dev_fd = ret; + +/* Newstyle API is used, we may have attributes */ +if (kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 )) { +uint32_t numirqs = s->num_irq; +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 , + &numirqs, true); + } +/* Tell the kernel to complete VGIC initialization now */ +if (kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT )) { +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true); + } }else if (ret != -ENODEV && ret != -ENOTSUP ) {error_setg_errno (errp, -ret,"error creating in-kernel VGIC" );return ; } -if (kvm_gic_supports_attr (s,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 )) { -uint32_t numirqs = s->num_irq; -kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 ,0 , &numirqs,1 ); - } - -/* Tell the kernel to complete VGIC initialization now */ -if (kvm_gic_supports_attr (s,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_CTRL_INIT )) { -kvm_gic_access (s,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_CTRL_INIT ,0 ,0 ,1 ); - } -/* Distributor */ kvm_arm_register_device (&s->iomem, (KVM_ARM_DEVICE_VGIC_V2 << KVM_ARM_DEVICE_ID_SHIFT)
hw/intc/vgic_common.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* ARM KVM vGIC utility functions +* +* Copyright (c) 2015 Samsung Electronics +* Written by Pavel Fedin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_ARM_VGIC_COMMON_H +#define QEMU_ARM_VGIC_COMMON_H + +/** +* kvm_arm_gic_set_irq - Send an IRQ to the in-kernel vGIC +* @num_irq: Total number of IRQs configured for the GIC instance +* @irq: qemu internal IRQ line number: +* [0..N-1] : external interrupts +* [N..N+31] : PPI (internal) interrupts for CPU 0 +* [N+32..N+63] : PPI (internal interrupts for CPU 1 +* @level: level of the IRQ line. +*/ +void kvm_arm_gic_set_irq (uint32_t num_irq,int irq,int level); + +#endif
include/sysemu/kvm.h +26 -0
@@ -240,6 +240,32 @@ int kvm_device_ioctl(int fd, int type, ...);int kvm_vm_check_attr (KVMState *s,uint32_t group,uint64_t attr);/** +* kvm_device_check_attr - check for existence of a specific device attribute +* @fd: The device file descriptor +* @group: the group +* @attr: the attribute of that group to query for +* +* Returns: 1 if the attribute exists +* 0 if the attribute either does not exist or if the vm device +* interface is unavailable +*/ +int kvm_device_check_attr (int fd,uint32_t group,uint64_t attr); + +/** +* kvm_device_access - set or get value of a specific vm attribute +* @fd: The device file descriptor +* @group: the group +* @attr: the attribute of that group to set or get +* @val: pointer to a storage area for the value +* @write: true for set and false for get operation +* +* This function is not allowed to fail. Use kvm_device_check_attr() +* in order to check for the availability of optional attributes. +*/ +void kvm_device_access (int fd,int group,uint64_t attr, +void *val,bool write); + +/** * kvm_create_device - create a KVM device for the device control API * @KVMState: The KVMState pointer * @type: The KVM device type (see Documentation/virtual/kvm/devices in the
kvm-all.c +34 -0
@@ -24,6 +24,7 @@#include "qemu/atomic.h" #include "qemu/option.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" #include "hw/hw.h" #include "hw/pci/msi.h" #include "hw/s390x/adapter.h"
@@ -2002,6 +2003,39 @@ int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr)return ret ?0 :1 ; } +int kvm_device_check_attr (int dev_fd,uint32_t group,uint64_t attr) +{ +struct kvm_device_attr attribute = { + .group = group, + .attr = attr, + .flags =0 , + }; + +return kvm_device_ioctl (dev_fd,KVM_HAS_DEVICE_ATTR , &attribute) ?0 :1 ; +} + +void kvm_device_access (int fd,int group,uint64_t attr, +void *val,bool write) +{ +struct kvm_device_attr kvmattr; +int err; + + kvmattr.flags =0 ; + kvmattr.group = group; + kvmattr.attr = attr; + kvmattr.addr = (uintptr_t )val; + + err =kvm_device_ioctl (fd, + write ?KVM_SET_DEVICE_ATTR :KVM_GET_DEVICE_ATTR , + &kvmattr); +if (err <0 ) { +error_report ("KVM_%s_DEVICE_ATTR failed: %s\n" +"Group %d attr 0x%016zX" , write ?"SET" :"GET" , +strerror (-err), group, attr); +abort (); + } +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );
Signature · 1 line
2.4.4
PATCH v14 4/5 hw/intc: Initial implementation of vGICv3
In reply to Pavel FedinThis is the initial version of KVM-accelerated GICv3 support. State load and save are not yet supported, live migration is not possible.
In order to get correct class name in a simpler way, gicv3_class_name() function is implemented, similar to gic_class_name().
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3_kvm.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ target-arm/kvm_arm.h | 10 ++++ target-arm/machine.c | 18 ++++++ 4 files changed, 178 insertions(+) create mode 100644 hw/intc/arm_gicv3_kvm.c
hw/intc/Makefile.objs +1 -0
@@ -17,6 +17,7 @@ common-obj-$(CONFIG_OPENPIC) += openpic.o obj-$(CONFIG_APIC) += apic.o apic_common.o obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o +obj-$(call land,$(CONFIG_ARM_GIC_KVM),$(TARGET_AARCH64)) += arm_gicv3_kvm.o obj-$(CONFIG_STELLARIS) += armv7m_nvic.o obj-$(CONFIG_EXYNOS4) += exynos4210_gic.o exynos4210_combiner.o obj-$(CONFIG_GRLIB) += grlib_irqmp.o
hw/intc/arm_gicv3_kvm.c new file +149 -0
149 lines not on this page · raw message
target-arm/kvm_arm.h +10 -0
@@ -205,4 +205,14 @@ static inline const char *gic_class_name(void) return kvm_irqchip_in_kernel() ? "kvm-arm-gic" : "arm_gic"; } +/** +* gicv3_class_name +* +* Return name of GICv3 class to use depending on whether KVM acceleration is +* in use. May throw an error if the chosen implementation is not available. +* +* Returns: class name to use +*/ +const char *gicv3_class_name (void ); +#endif
target-arm/machine.c +18 -0
@@ -1,5 +1,6 @@#include "hw/hw.h" #include "hw/boards.h" +#include "qemu/error-report.h" #include "sysemu/kvm.h" #include "kvm_arm.h" #include "internals.h"
@@ -328,3 +329,20 @@ const VMStateDescription vmstate_arm_cpu = { NULL } }; + +const char *gicv3_class_name (void ) +{ +if (kvm_irqchip_in_kernel ()) { +#ifdef TARGET_AARCH64 +return "kvm-arm-gicv3" ; +#else +error_report ("KVM GICv3 acceleration is not supported on this " +"platform\n" ); +#endif + }else { +/* TODO: Software emulation is not implemented yet */ +error_report ("KVM is currently required for GICv3 emulation\n" ); + } + +exit (1 ); +}
Signature · 1 line
2.4.4
PATCH v14 5/5 hw/arm/virt: Add gic-version option to virt machine
In reply to Pavel FedinAdd gic_version to VirtMachineState, set it to value of the option and pass it around where necessary. Instantiate devices and fdt nodes according to the choice.
max_cpus for virt machine increased to 123 (calculated from redistributor space available in the memory map). GICv2 compatibility check happens inside arm_gic_common_realize().
ITS region is added to the memory map too, however currently it not used, just reserved.
--- hw/arm/virt-acpi-build.c | 54 ++++++++++------- hw/arm/virt.c | 124 +++++++++++++++++++++++++++++++-------- include/hw/acpi/acpi-defs.h | 9 +++ include/hw/arm/virt-acpi-build.h | 1 + include/hw/arm/virt.h | 4 +- 5 files changed, 146 insertions(+), 46 deletions(-)
hw/arm/virt-acpi-build.c +32 -22
@@ -443,33 +443,43 @@ build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info, madt =acpi_data_push (table_data,sizeof *madt); -for (i =0 ; i < guest_info->smp_cpus; i++) { -AcpiMadtGenericInterrupt *gicc =acpi_data_push (table_data, -sizeof *gicc); - gicc->type =ACPI_APIC_GENERIC_INTERRUPT ; - gicc->length =sizeof (*gicc); - gicc->base_address = memmap[VIRT_GIC_CPU ].base; - gicc->cpu_interface_number = i; - gicc->arm_mpidr = i; - gicc->uid = i; -if (test_bit (i, cpuinfo->found_cpus)) { - gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); - } - } - gicd =acpi_data_push (table_data,sizeof *gicd); gicd->type =ACPI_APIC_GENERIC_DISTRIBUTOR ; gicd->length =sizeof (*gicd); gicd->base_address = memmap[VIRT_GIC_DIST ].base; - gic_msi =acpi_data_push (table_data,sizeof *gic_msi); - gic_msi->type =ACPI_APIC_GENERIC_MSI_FRAME ; - gic_msi->length =sizeof (*gic_msi); - gic_msi->gic_msi_frame_id =0 ; - gic_msi->base_address =cpu_to_le64 (memmap[VIRT_GIC_V2M ].base); - gic_msi->flags =cpu_to_le32 (1 ); - gic_msi->spi_count =cpu_to_le16 (NUM_GICV2M_SPIS ); - gic_msi->spi_base =cpu_to_le16 (irqmap[VIRT_GIC_V2M ] +ARM_SPI_BASE ); +if (guest_info->gic_version ==3 ) { +AcpiMadtGenericRedistributor *gicr =acpi_data_push (table_data, +sizeof *gicr); + + gicr->type =ACPI_APIC_GENERIC_REDISTRIBUTOR ; + gicr->length =sizeof (*gicr); + gicr->base_address = memmap[VIRT_GIC_REDIST ].base; + gicr->range_length = memmap[VIRT_GIC_REDIST ].size; + }else { +for (i =0 ; i < guest_info->smp_cpus; i++) { +AcpiMadtGenericInterrupt *gicc =acpi_data_push (table_data, +sizeof *gicc); + gicc->type =ACPI_APIC_GENERIC_INTERRUPT ; + gicc->length =sizeof (*gicc); + gicc->base_address = memmap[VIRT_GIC_CPU ].base; + gicc->cpu_interface_number = i; + gicc->arm_mpidr = i; + gicc->uid = i; +if (test_bit (i, cpuinfo->found_cpus)) { + gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); + } + } + + gic_msi =acpi_data_push (table_data,sizeof *gic_msi); + gic_msi->type =ACPI_APIC_GENERIC_MSI_FRAME ; + gic_msi->length =sizeof (*gic_msi); + gic_msi->gic_msi_frame_id =0 ; + gic_msi->base_address =cpu_to_le64 (memmap[VIRT_GIC_V2M ].base); + gic_msi->flags =cpu_to_le32 (1 ); + gic_msi->spi_count =cpu_to_le16 (NUM_GICV2M_SPIS ); + gic_msi->spi_base =cpu_to_le16 (irqmap[VIRT_GIC_V2M ] +ARM_SPI_BASE ); + } build_header(linker, table_data, (void *)(table_data->data + madt_start), "APIC",
hw/arm/virt.c +101 -23
251 lines not on this page · raw message
include/hw/acpi/acpi-defs.h +9 -0
@@ -384,6 +384,15 @@ struct AcpiMadtGenericMsiFrame {typedef struct AcpiMadtGenericMsiFrame AcpiMadtGenericMsiFrame ; +struct AcpiMadtGenericRedistributor { +ACPI_SUB_HEADER_DEF + uint16_t reserved; +uint64_t base_address; +uint32_t range_length; +}QEMU_PACKED ; + +typedef struct AcpiMadtGenericRedistributor AcpiMadtGenericRedistributor ; +/* * Generic Timer Description Table (GTDT) */
include/hw/arm/virt-acpi-build.h +1 -0
@@ -32,6 +32,7 @@ typedef struct VirtGuestInfo {const MemMapEntry *memmap;const int *irqmap;bool use_highmem; +int gic_version; } VirtGuestInfo;
include/hw/arm/virt.h +3 -1
@@ -46,6 +46,9 @@ enum {VIRT_CPUPERIPHS ,VIRT_GIC_DIST ,VIRT_GIC_CPU , +VIRT_GIC_V2M , +VIRT_GIC_ITS , +VIRT_GIC_REDIST ,VIRT_UART ,VIRT_MMIO , VIRT_RTC,
@@ -54,7 +57,6 @@ enum {VIRT_PCIE_MMIO ,VIRT_PCIE_PIO ,VIRT_PCIE_ECAM , -VIRT_GIC_V2M ,VIRT_PLATFORM_BUS , VIRT_PCIE_MMIO_HIGH, };
Signature · 1 line
2.4.4
Hello everybody! Just want to inform that i'm leaving for 2 weeks long vacation, so i won't respond
during this time.
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia
Quoted 142 lines
-----Original Message-----
From: [email protected] [mailto:qemu-devel- [email protected]] On Behalf Of Pavel Fedin
Sent: Wednesday, September 09, 2015 10:49 AM
To: [email protected]
Cc: Peter Maydell; Shlomo Pongratz; Shlomo Pongratz
Subject: [Qemu-devel] [PATCH v14 0/5] vGICv3 supportThis series introduces support for GICv3 by KVM. Software emulation is currently not supported.
v13 => v14
- Rebased on the latest master, fixed conflicts in
hw/arm/virt.cv12 => v13
- Many stylistic fixes
- Fixed up ACPI data for virt machine
- Added gic-version=host value which probes for best possible vGIC version
- Reserved regions for memory-mapped CPU/vCPU/HYP interfaces
- Maximum number of CPUs for virt machine dropped to 123 (memory map limitation)v11 => v12
- Do not set timer PPI CPU mask in device tree for GICv3
- Fixed small styling issues inhw/arm/virt.c
- Completely untiedkvm_gic_access()from GIC and turned intokvm_device_access(). Attribute mapping is now handled in gicd/gicc wrapper macros.v11 => v10
- Fixed minor issues with checkpatch and comments, reported by Eric Auger
- Make reusablekvm_gic_supports_attr(), moved tokvm-all.cand renamed askvm_device_check_attr(). Useful for future live migration.v9 => v10
- Renamed "gicversion" option to "gic-version" (was forgotten in v9)
- Data pointer inkvm_gic_access()is now void * because in case of vGICv3 this function is expected to operate on 64-bit registers too (GICD_IROUTERfor instance)v8 => v9
- Removed all limitations on CPU and IRQ number from the base class
- Added back missing properties, interface is now the same as in GICv2
- Refactored reusable parts of vGICv2 code, decreased number of changes
- Removed GIC type check fromkvm_arch_irqchip_create(), no more need to specify GIC type early
- Fixed up all commit messages / logs
- Removed 'nvic' field assignment in virt machine (was forgotten in v8)
- CPU number limitation for 'virt' machine now comes from memory map (how many redistributors can be placed). With current layout it appears to be 126.v7 => v8
- Removed all unused SW emulation code
- Removed unnecessary attributes from common class
- Set "unmigratable" flag for GICv3 device
- Removed unnecessary conditions fromkvm_arm_gicv3_realize()
- Fixed GIC type setting in vexpress model, was done in wrong place
- Fixed condition style in hw/intc/Makefile.objs
- Cleaned up virt machine memory mapv6 => v7
- Wrap own GIC type definitions on top of KVM ones. Fixed build on non-ARM-Linux hostsv5 => v6
- Fixed various checkpatch.pl style warnings
- Removed TODO ingicv3_init_irqs_and_mmio(), relevant memory API patch included
-gicv3_init_irqs_and_mmio()now takes 3 arguments instead of 4. It is more convenient to pass MMIO descriptors as arrayv4 => v5
- Do not reintroduce several constants shared with GICv2, reuse them instead.
- Addedgicv3_init_irqs_and_mmio()in base class, to be used by both software emulation and KVM code. Avoids code duplication.
- Do not add NULL msi-parent phandle to PCI device in the FDT
- Removed a couple of stale things fromvirt.cv3 => v4
- Fixed stupid build breakage in patch 0002
- Rebased on top of current master, patch 0003 adjusted according tokvm_irqchip_create()changes
- Added assertion against uninitializedkernel_irqchip_type
- Removedkernel_irqchip_typeinitialization from models which do not use KVM vGICv2 => v3
- Removed some unrelated and unnecessary changes from virt machine, occasionally slipped in; some of them caused qemu to crash on ARM32.
- Fixed build for ARM32; vGICv3 code requires definitions which are present only in ARM64 kernelv1 => v2
- Base class included, taken from the series by Shlomo Pongratz:
http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg01512.html
The code is refactored as little as possible in order to simplify further addition of software emulation:
- Minor fixes in code style and comments, according to old reviews
- RemovedREV_V3definition because it's currently not used, and it does not add any meaning to number 3.
- Removed reserved regions for MBI and ITS (except for 'virt' machine memory map). These should go to separate classes when implemented.
- Improved commit messages
- vGIC patches restructured
- Use 'gicversion' option instead of virt-v3 machinePavel Fedin (4):
intc/gic: Extract some reusable vGIC code
arm_kvm: Do not assume particular GIC type in
kvm_arch_irqchip_create()
hw/intc: Initial implementation of vGICv3 hw/arm/virt: Add gic-version option to virt machineShlomo Pongratz (1):
hw/intc: Implement GIC-500 base classhw/arm/virt-acpi-build.c | 54 ++++++++------ hw/arm/virt.c | 124 ++++++++++++++++++++++++------ hw/intc/Makefile.objs | 2 + hw/intc/arm_gic_kvm.c | 98 ++++++++---------------- hw/intc/arm_gicv3_common.c | 140 ++++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_kvm.c | 149 +++++++++++++++++++++++++++++++++++++ hw/intc/vgic_common.h | 35 +++++++++ include/hw/acpi/acpi-defs.h | 9 +++ include/hw/arm/virt-acpi-build.h | 1 + include/hw/arm/virt.h | 4 +- include/hw/intc/arm_gicv3_common.h | 68 +++++++++++++++++ include/sysemu/kvm.h | 26 +++++++ kvm-all.c | 34 +++++++++ target-arm/kvm.c | 19 +++-- target-arm/kvm_arm.h | 19 +++++ target-arm/machine.c | 18 +++++ 16 files changed, 682 insertions(+), 118 deletions(-) create mode 100644 hw/intc/arm_gicv3_common.c create mode 100644 hw/intc/arm_gicv3_kvm.c create mode 100644 hw/intc/vgic_common.h create mode 100644 include/hw/intc/arm_gicv3_common.h--
2.4.4
Re: [Qemu-devel] [PATCH v14 2/5] intc/gic: Extract some reusable vGIC code
In reply to Pavel FedinQuoted 22 lines · Pavel Fedin
Some functions previously used only by vGICv2 are useful also for vGICv3 implementation. Untie them from GICState and make accessible from within other modules:
-kvm_arm_gic_set_irq()
-kvm_gic_supports_attr()- moved to common code and renamed tokvm_device_check_attr()
-kvm_gic_access()- turned into GIC-independentkvm_device_access(). Data pointer changed to void * because some GICv3 registers are 64-bit wideSome of these changes are not used right now, but they will be helpful for implementing live migration.
Actually
kvm_dist_get()andkvm_dist_put()could also be made reusable, but they would require two extra parameters (s->dev_fdands->num_cpu) as well as lots of typecasts of 's' to DeviceState * and back to GICState *. This makes the code very ugly so i decided to stop at this point. I tried also an approach with making a base class for all possible GICs, but it would contain only three variables (dev_fd,cpu_numandirq_num), and accessing them through the rest of the code would be again tedious (either ugly casts or qemu-style separate object pointer). So i disliked it too.
Quoted 2 lines
Signed-off-by Pavel Fedin <[email protected]>Tested-by Ashok kumar <[email protected]>
thanks
-- PMM
Quoted 7 lines · Pavel Fedin
This series introduces support for GICv3 by KVM. Software emulation is currently not supported.
v13 => v14
- Rebased on the latest master, fixed conflicts in
hw/arm/virt.c
You'll need to fix the acpi related bits Shannon has review comments on in patch 5, but otherwise this looks good to me.
I'm going to put patches 1..4 into target-arm.next since they've all been reviewed, to save you having to send those out again for v15.
thanks
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 7 lines · Pavel Fedin
This series introduces support for GICv3 by KVM. Software emulation is currently not supported.
v13 => v14
- Rebased on the latest master, fixed conflicts in
hw/arm/virt.cYou'll need to fix the acpi related bits Shannon has review comments on in patch 5, but otherwise this looks good to me.
Having discussed this with Shannon yesterday, the fixes required are trivial. Shannon kindly sent me this tiny patch, so I'm just going to squash that into your patch 5 and put the whole lot into target-arm.next, rather than make you have to go through another round.
hw/arm/virt-acpi-build.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
@@ -454,8 +454,8 @@ build_madt(GArray *table_data, GArray *linker,
VirtGuestInfo *guest_info,
gicr->type = ACPI_APIC_GENERIC_REDISTRIBUTOR;
gicr->length = sizeof(*gicr);
- gicr->base_address = memmap[VIRT_GIC_REDIST].base;
- gicr->range_length = memmap[VIRT_GIC_REDIST].size;
+ gicr->base_address = cpu_to_le64(memmap[VIRT_GIC_REDIST].base);
+ gicr->range_length = cpu_to_le32(memmap[VIRT_GIC_REDIST].size);
} else {
for (i = 0; i < guest_info->smp_cpus; i++) {
AcpiMadtGenericInterrupt *gicc = acpi_data_push(table_data,thanks
-- PMM