Create ARM KVM VGIC with device control API
cover Create ARM KVM VGIC with device control API
This patch series adds generic support for issuing device control related ioctls and supports creating the ARM KVM-accelerated VGIC using the device control API while maintaining backwards compatibility for older kernels.
Christoffer Dall (4):
kvm: Update headers for device control api
kvm: Introduce kvm_arch_irqchip_create
kvm: Common device control API functions
arm: vgic device control api support
hw/intc/arm_gic_kvm.c | 23 ++++++++++++++++-- include/sysemu/kvm.h | 9 ++++++++ kvm-all.c | 50 +++++++++++++++++++++++++++++++++++++-- linux-headers/asm-arm/kvm.h | 8 +++++++ linux-headers/linux/kvm.h | 1 + target-arm/kvm.c | 54 +++++++++++++++++++++++++++++++++++++------ target-arm/kvm_arm.h | 18 ++++++++++----- target-i386/kvm.c | 5 ++++ target-ppc/kvm.c | 5 ++++ target-s390x/kvm.c | 5 ++++ trace-events | 1 + 11 files changed, 162 insertions(+), 17 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/4 kvm: Update headers for device control api
Update the KVM kernel headers to add support for the device control API on ARM used to create in-kernel devices and set and get attributes on these.
This is needed for VGIC save/restore with KVM ARM targets.
Headers are included from:git://git.linaro.org/people/cdall/linux-kvm-arm.git vgic-migrate
--- linux-headers/asm-arm/kvm.h | 8 ++++++++ linux-headers/linux/kvm.h | 1 + 2 files changed, 9 insertions(+)
linux-headers/asm-arm/kvm.h +8 -0
@@ -142,6 +142,14 @@ struct kvm_arch_memory_slot {#define KVM_REG_ARM_VFP_FPINST 0x1009#define KVM_REG_ARM_VFP_FPINST2 0x100A +/* Device Control API: ARM VGIC */ +#define KVM_DEV_ARM_VGIC_GRP_ADDR 0 +#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 +#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 +#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 +#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 +#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)/* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24
linux-headers/linux/kvm.h +1 -0
@@ -839,6 +839,7 @@ struct kvm_device_attr {#define KVM_DEV_TYPE_FSL_MPIC_20 1#define KVM_DEV_TYPE_FSL_MPIC_42 2#define KVM_DEV_TYPE_XICS 3 +#define KVM_DEV_TYPE_ARM_VGIC_V2 4/* * ioctls for VM fds
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 1/4] kvm: Update headers for device control api
Quoted 8 lines · Christoffer Dall
Update the KVM kernel headers to add support for the device control API on ARM used to create in-kernel devices and set and get attributes on these.
This is needed for VGIC save/restore with KVM ARM targets.
Headers are included from:
git://git.linaro.org/people/cdall/linux-kvm-arm.gitvgic-migrate
NB: this makes this an "RFC" patchset because we can't apply it until the kernel headers have been accepted upstream.
-- PMM
PATCH 2/4 kvm: Introduce kvm_arch_irqchip_create
In reply to Christoffer DallIntroduce kvm_arch_irqchip_create an arch-specific hook in preparation for architecture-specific use of the device control API to create IRQ chips.
Following patches will implement the ARM irqchip create method to prefer the device control API over the older KVM_CREATE_IRQCHIP API.
--- include/sysemu/kvm.h | 4 ++++ kvm-all.c | 11 +++++++++-- target-arm/kvm.c | 5 +++++ target-i386/kvm.c | 5 +++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 5 +++++ 6 files changed, 33 insertions(+), 2 deletions(-)
include/sysemu/kvm.h +4 -0
@@ -224,6 +224,10 @@ void kvm_arch_reset_vcpu(CPUState *cpu);int kvm_arch_on_sigbus_vcpu (CPUState *cpu,int code,void *addr);int kvm_arch_on_sigbus (int code,void *addr); +/* return negative error on error, 0 if irq chip was not created, and positive +* number if it was created */ +int kvm_arch_irqchip_create (KVMState *s); +void kvm_arch_init_irq_routing (KVMState *s);int kvm_set_irq (KVMState *s,int irq,int level);
kvm-all.c +9 -2
@@ -1295,10 +1295,17 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } - ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); +/* First probe and see if there's a arch-specific hook to create the +* in-kernel irqchip for us */ + ret =kvm_arch_irqchip_create (s);if (ret <0 ) { -fprintf (stderr,"Create kernel irqchip failed\n" );return ret; + }else if (ret ==0 ) { + ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); +if (ret <0 ) { +fprintf (stderr,"Create kernel irqchip failed\n" ); +return ret; + } } kvm_kernel_irqchip = true;
target-arm/kvm.c +5 -0
@@ -647,3 +647,8 @@ void kvm_arch_remove_all_hw_breakpoints(void)void kvm_arch_init_irq_routing (KVMState *s) { } + +int kvm_arch_irqchip_create (KVMState *s) +{ +return 0 ; +}
target-i386/kvm.c +5 -0
@@ -2188,6 +2188,11 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) ((env->segs[R_CS ].selector &3 ) !=3 ); } +int kvm_arch_irqchip_create (KVMState *s) +{ +return 0 ; +} +void kvm_arch_init_irq_routing (KVMState *s) {if (!kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) {
target-ppc/kvm.c +5 -0
@@ -1875,3 +1875,8 @@ int kvm_arch_on_sigbus(int code, void *addr)void kvm_arch_init_irq_routing (KVMState *s) { } + +int kvm_arch_irqchip_create (KVMState *s) +{ +return 0 ; +}
target-s390x/kvm.c +5 -0
@@ -893,6 +893,11 @@ void kvm_arch_init_irq_routing(KVMState *s) { } +int kvm_arch_irqchip_create (KVMState *s) +{ +return 0 ; +} +int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch,int vq,bool assign) {
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/4] kvm: Introduce kvm_arch_irqchip_create
Quoted 22 lines · Christoffer Dall
Introduce
kvm_arch_irqchip_createan arch-specific hook in preparation for architecture-specific use of the device control API to create IRQ chips.Following patches will implement the ARM irqchip create method to prefer the device control API over the older
KVM_CREATE_IRQCHIPAPI.Signed-off-by Christoffer Dall <[email protected]>--- include/sysemu/kvm.h | 4 ++++ kvm-all.c | 11 +++++++++-- target-arm/kvm.c | 5 +++++ target-i386/kvm.c | 5 +++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 5 +++++ 6 files changed, 33 insertions(+), 2 deletions(-)include/sysemu/kvm.h +0
-0
include/sysemu/kvm.h void kvm_arch_reset_vcpu(CPUState *cpu); · line 229
Quoted 6 lines
include/sysemu/kvm.h +3
-0@@ -224,6 +224,10 @@ void kvm_arch_reset_vcpu(CPUState *cpu);int kvm_arch_on_sigbus_vcpu (CPUState *cpu,int code,void *addr);int kvm_arch_on_sigbus (int code,void *addr); +/* return negative error on error, 0 if irq chip was not created, and positive +* number if it was created */ +int kvm_arch_irqchip_create (KVMState *s);
Could you follow the doc-comment coding style for this, please? (The extract/deposit ops in include/qemu/bitops.h are the template I usually crib from.)
Quoted 33 lines
include/sysemu/kvm.h +1
-0+void kvm_arch_init_irq_routing (KVMState *s);int kvm_set_irq (KVMState *s,int irq,int level);kvm-all.c +9
-2@@ -1295,10 +1295,17 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } - ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); +/* First probe and see if there's a arch-specific hook to create the +* in-kernel irqchip for us */ + ret =kvm_arch_irqchip_create (s);if (ret <0 ) { -fprintf (stderr,"Create kernel irqchip failed\n" );return ret; + }else if (ret ==0 ) { + ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); +if (ret <0 ) { +fprintf (stderr,"Create kernel irqchip failed\n" ); +return ret; + } } kvm_kernel_irqchip = true;target-arm/kvm.c +0
-0
target-arm/kvm.c void kvm_arch_remove_all_hw_breakpoints(void) · line 654
Quoted 8 lines
target-arm/kvm.c +5
-0@@ -647,3 +647,8 @@ void kvm_arch_remove_all_hw_breakpoints(void)void kvm_arch_init_irq_routing (KVMState *s) { } + +int kvm_arch_irqchip_create (KVMState *s) +{ +return 0 ; +}
[ditto in s390/ppc/i386]
We can avoid all these identical stub versions of this function by using our stubs mechanism:
create a file stubs/kvm.c, put the dummy function definition in it, and add a line to stubs/Makefile.obj saying "stub-obj-$(CONFIG_KVM) += kvm.o"
Then only the targets which actually need a real implementation of this function have to provide one; everybody else gets the stub version automatically.
In fact you could have the stub version's implementation be to call kvm_vm_ioctl(s, KVM_CREATE_IRQCHIP), which would then simplify the kvm-all.c code a little.
(There are probably a few other kvm target functions we could provide stubs for, but that's a later cleanup.)
-- PMM
PATCH 3/4 kvm: Common device control API functions
In reply to Christoffer DallIntroduces two simple functions:
int kvm_device_ioctl(int fd, int type, ...);
int kvm_create_device(KVMState *s, uint64_t type, bool test);These functions wrap the basic ioctl-based interactions with KVM in a way similar to other KVM ioctl wrappers.
--- include/sysemu/kvm.h | 5 +++++ kvm-all.c | 39 +++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 3 files changed, 45 insertions(+)
include/sysemu/kvm.h +5 -0
@@ -190,6 +190,11 @@ int kvm_vm_ioctl(KVMState *s, int type, ...);int kvm_vcpu_ioctl (CPUState *cpu,int type, ...); +int kvm_device_ioctl (int fd,int type, ...); + +int kvm_create_device (KVMState *s,uint64_t type,bool test); + +/* Arch specific hooks */ extern const KVMCapabilityInfo kvm_arch_required_capabilities[];
kvm-all.c +39 -0
@@ -1770,6 +1770,24 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)return ret; } +int kvm_device_ioctl (int fd,int type, ...) +{ +int ret; +void *arg; +va_list ap; + +va_start (ap, type); + arg = va_arg(ap, void *); +va_end (ap); + +trace_kvm_device_ioctl (fd, type, arg); + ret =ioctl (fd, type, arg); +if (ret ==-1 ) { + ret = -errno; + } +return ret; +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );
@@ -2064,3 +2082,24 @@ int kvm_on_sigbus(int code, void *addr) {return kvm_arch_on_sigbus (code, addr); } + +int kvm_create_device (KVMState *s,uint64_t type,bool test) +{ +int ret; +struct kvm_create_device create_dev; + + create_dev.type = type; + create_dev.fd =-1 ; + create_dev.flags = (test) ?KVM_CREATE_DEVICE_TEST :0 ; + +if (!kvm_check_extension (s,KVM_CAP_DEVICE_CTRL )) { +return -1 ; + } + + ret =kvm_vm_ioctl (s,KVM_CREATE_DEVICE , &create_dev); +if (ret) { +return ret; + } + +return (test) ?0 : create_dev.fd; +}
trace-events +1 -0
@@ -1163,6 +1163,7 @@ migrate_set_state(int new_state) "new state %d" kvm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type %d, arg %p" +kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type %d, arg %p" kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" # memory.c
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 3/4] kvm: Common device control API functions
Quoted 19 lines · Christoffer Dall
Introduces two simple functions:
int kvm_device_ioctl(int fd, int type, ...); int kvm_create_device(KVMState *s, uint64_t type, bool test);These functions wrap the basic ioctl-based interactions with KVM in a way similar to other KVM ioctl wrappers.
Signed-off-by Christoffer Dall <[email protected]>--- include/sysemu/kvm.h | 5 +++++ kvm-all.c | 39 +++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 3 files changed, 45 insertions(+)include/sysemu/kvm.h +0
-0
include/sysemu/kvm.h int kvm_vm_ioctl(KVMState *s, int type, ...); · line 195
Quoted 6 lines
include/sysemu/kvm.h +3
-0@@ -190,6 +190,11 @@ int kvm_vm_ioctl(KVMState *s, int type, ...);int kvm_vcpu_ioctl (CPUState *cpu,int type, ...); +int kvm_device_ioctl (int fd,int type, ...); + +int kvm_create_device (KVMState *s,uint64_t type,bool test);
Could we have doc comments for these, please?
Quoted 37 lines
include/sysemu/kvm.h +2
-0+ +/* Arch specific hooks */ extern const KVMCapabilityInfo kvm_arch_required_capabilities[];kvm-all.c +18
-0@@ -1770,6 +1770,24 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)return ret; } +int kvm_device_ioctl (int fd,int type, ...) +{ +int ret; +void *arg; +va_list ap; + +va_start (ap, type); + arg = va_arg(ap, void *); +va_end (ap); + +trace_kvm_device_ioctl (fd, type, arg); + ret =ioctl (fd, type, arg); +if (ret ==-1 ) { + ret = -errno; + } +return ret; +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );@@ -2064,3 +2082,24 @@ int kvm_on_sigbus(int code, void *addr) {return kvm_arch_on_sigbus (code, addr);
kvm-all.c int kvm_on_sigbus(int code, void *addr) · line 2093
Quoted 10 lines
kvm-all.c +9
-0} + +int kvm_create_device (KVMState *s,uint64_t type,bool test) +{ +int ret; +struct kvm_create_device create_dev; + + create_dev.type = type; + create_dev.fd =-1 ; + create_dev.flags = (test) ?KVM_CREATE_DEVICE_TEST :0 ;
Why the brackets round 'test' ?
kvm-all.c int kvm_on_sigbus(int code, void *addr) · line 2096
Quoted 3 lines
kvm-all.c +3
-0+ +if (!kvm_check_extension (s,KVM_CAP_DEVICE_CTRL )) { +return -1 ;
We should probably return -$some_errno here, since we pass through a -errno return from kvm_vm_ioctl below.
kvm-all.c int kvm_on_sigbus(int code, void *addr) · line 2105
Quoted 9 lines
kvm-all.c +9
-0+ } + + ret =kvm_vm_ioctl (s,KVM_CREATE_DEVICE , &create_dev); +if (ret) { +return ret; + } + +return (test) ?0 : create_dev.fd; +}
thanks
-- PMM
PATCH 4/4 arm: vgic device control api support
In reply to Christoffer DallSupport creating the ARM vgic device through the device control API and setting the base address for the distributor and cpu interfaces in KVM VMs using this API.
Because the older KVM_CREATE_IRQCHIP interface needs the irq chip to be created prior to creating the VCPUs, we first test if if can use the device control API in kvm_arch_irqchip_create (using the test flag from the device control API). If we cannot, it means we have to fall back to KVM_CREATE_IRQCHIP and use the older ioctl at this point in time. If however, we can use the device control API, we don't do anything and wait until the arm_gic_kvm driver initializes and let that use the device control API.
--- hw/intc/arm_gic_kvm.c | 23 +++++++++++++++++++++-- target-arm/kvm.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- target-arm/kvm_arm.h | 18 ++++++++++++------ 3 files changed, 75 insertions(+), 15 deletions(-)
hw/intc/arm_gic_kvm.c +21 -2
@@ -35,6 +35,7 @@ typedef struct KVMARMGICClass {ARMGICCommonClass parent_class;DeviceRealize parent_realize;void (*parent_reset)(DeviceState *dev); +int dev_fd; } KVMARMGICClass;static void kvm_arm_gic_set_irq (void *opaque,int irq,int level)
@@ -97,6 +98,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)GICState *s =KVM_ARM_GIC (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev);KVMARMGICClass *kgc =KVM_ARM_GIC_GET_CLASS (s); +int ret; kgc->parent_realize (dev, errp);if (error_is_set (errp)) {
@@ -119,13 +121,27 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < s->num_cpu; i++) {sysbus_init_irq (sbd, &s->parent_irq[i]); } + +/* Try to create the device via the device control API */ + kgc->dev_fd =-1 ; + ret =kvm_create_device (kvm_state,KVM_DEV_TYPE_ARM_VGIC_V2 , false); +if (ret >=0 ) { + kgc->dev_fd = ret; + }else if (ret != -ENODEV ) { +fprintf (stderr,"Error creating in-kernel VGIC: %d\n" , ret); +abort (); + } +/* Distributor */ memory_region_init_reservation (&s->iomem,OBJECT (s),"kvm-gic_dist" ,0x1000 );sysbus_init_mmio (sbd, &s->iomem);kvm_arm_register_device (&s->iomem, (KVM_ARM_DEVICE_VGIC_V2 <<KVM_ARM_DEVICE_ID_SHIFT ) - |KVM_VGIC_V2_ADDR_TYPE_DIST ); + |KVM_VGIC_V2_ADDR_TYPE_DIST , +KVM_DEV_ARM_VGIC_GRP_ADDR , +KVM_VGIC_V2_ADDR_TYPE_DIST , + kgc->dev_fd);/* CPU interface for current core. Unlike arm_gic, we don't * provide the "interface for core #N" memory regions, because * cores with a VGIC don't have those.
@@ -135,7 +151,10 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (sbd, &s->cpuiomem[0 ]);kvm_arm_register_device (&s->cpuiomem[0 ], (KVM_ARM_DEVICE_VGIC_V2 <<KVM_ARM_DEVICE_ID_SHIFT ) - |KVM_VGIC_V2_ADDR_TYPE_CPU ); + |KVM_VGIC_V2_ADDR_TYPE_CPU , +KVM_DEV_ARM_VGIC_GRP_ADDR , +KVM_VGIC_V2_ADDR_TYPE_CPU , + kgc->dev_fd); }static void kvm_arm_gic_class_init (ObjectClass *klass,void *data)
target-arm/kvm.c +42 -7
86 lines not on this page · raw message
target-arm/kvm_arm.h +12 -6
@@ -18,16 +18,22 @@* kvm_arm_register_device: * @mr: memory region for this device * @devid: the KVM device ID +* @type: device control API device type +* @group: device control API group for setting addresses +* @attr: device control API address type +* @dev_fd: device control device file descriptor (or -1 if not supported) * * Remember the memory region @mr, and when it is mapped by the * machine model, tell the kernel that base address using the -* KVM_SET_DEVICE_ADDRESS ioctl. @devid should be the ID of -* the device as defined by KVM_SET_DEVICE_ADDRESS. -* The machine model may map and unmap the device multiple times; -* the kernel will only be told the final address at the point -* where machine init is complete. +* KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid +* should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or +* the arm-vgic device in the device control API. +* The machine model may map +* and unmap the device multiple times; the kernel will only be told the final +* address at the point where machine init is complete. */ -void kvm_arm_register_device (MemoryRegion *mr,uint64_t devid); +void kvm_arm_register_device (MemoryRegion *mr,uint64_t devid,uint64_t group, +uint64_t attr,int dev_fd);/** * write_list_to_kvmstate:
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 4/4] arm: vgic device control api support
Quoted 6 lines · Christoffer Dall
Support creating the ARM vgic device through the device control API and setting the base address for the distributor and cpu interfaces in KVM VMs using this API.
Because the older
KVM_CREATE_IRQCHIPinterface needs the irq chip to be created prior to creating the VCPUs, we first test if if can use the
"if we"
Quoted 19 lines
device control API in
kvm_arch_irqchip_create(using the test flag from the device control API). If we cannot, it means we have to fall back toKVM_CREATE_IRQCHIPand use the older ioctl at this point in time. If however, we can use the device control API, we don't do anything and wait until thearm_gic_kvmdriver initializes and let that use the device control API.Signed-off-by Christoffer Dall <[email protected]>--- hw/intc/arm_gic_kvm.c | 23 +++++++++++++++++++++-- target-arm/kvm.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- target-arm/kvm_arm.h | 18 ++++++++++++------ 3 files changed, 75 insertions(+), 15 deletions(-)hw/intc/arm_gic_kvm.c +0
-0
hw/intc/arm_gic_kvm.c typedef struct KVMARMGICClass { · line 39
Quoted 5 lines
hw/intc/arm_gic_kvm.c +1
-0@@ -35,6 +35,7 @@ typedef struct KVMARMGICClass {ARMGICCommonClass parent_class;DeviceRealize parent_realize;void (*parent_reset)(DeviceState *dev); +int dev_fd; } KVMARMGICClass;
This looks wrong -- surely we should have a dev_fd per instance of KVMARMGIC, not just one in the class struct?
Quoted 12 lines
hw/intc/arm_gic_kvm.c +1
-0static void kvm_arm_gic_set_irq (void *opaque,int irq,int level)@@ -97,6 +98,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)GICState *s =KVM_ARM_GIC (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev);KVMARMGICClass *kgc =KVM_ARM_GIC_GET_CLASS (s); +int ret; kgc->parent_realize (dev, errp);if (error_is_set (errp)) {@@ -119,13 +121,27 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < s->num_cpu; i++) {sysbus_init_irq (sbd, &s->parent_irq[i]);
hw/intc/arm_gic_kvm.c static void kvm_arm_gic_realize(DeviceState *dev, Error **errp) · line 132
Quoted 10 lines
hw/intc/arm_gic_kvm.c +9
-0} + +/* Try to create the device via the device control API */ + kgc->dev_fd =-1 ; + ret =kvm_create_device (kvm_state,KVM_DEV_TYPE_ARM_VGIC_V2 , false); +if (ret >=0 ) { + kgc->dev_fd = ret; + }else if (ret != -ENODEV ) { +fprintf (stderr,"Error creating in-kernel VGIC: %d\n" , ret); +abort ();
We shouldn't abort here, we can just report our failure back to the caller via the Error** it passed us:
error_setg_errno(errp, -ret, "error creating in-kernel VGIC");
return;(there's also an error_setg() if there's no errno involved; both versions use a printf-style format string and can take extra args accordingly.)
Quoted 44 lines
hw/intc/arm_gic_kvm.c +10
-2+ } +/* Distributor */ memory_region_init_reservation (&s->iomem,OBJECT (s),"kvm-gic_dist" ,0x1000 );sysbus_init_mmio (sbd, &s->iomem);kvm_arm_register_device (&s->iomem, (KVM_ARM_DEVICE_VGIC_V2 <<KVM_ARM_DEVICE_ID_SHIFT ) - |KVM_VGIC_V2_ADDR_TYPE_DIST ); + |KVM_VGIC_V2_ADDR_TYPE_DIST , +KVM_DEV_ARM_VGIC_GRP_ADDR , +KVM_VGIC_V2_ADDR_TYPE_DIST , + kgc->dev_fd);/* CPU interface for current core. Unlike arm_gic, we don't * provide the "interface for core #N" memory regions, because * cores with a VGIC don't have those. @@ -135,7 +151,10 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (sbd, &s->cpuiomem[0 ]);kvm_arm_register_device (&s->cpuiomem[0 ], (KVM_ARM_DEVICE_VGIC_V2 <<KVM_ARM_DEVICE_ID_SHIFT ) - |KVM_VGIC_V2_ADDR_TYPE_CPU ); + |KVM_VGIC_V2_ADDR_TYPE_CPU , +KVM_DEV_ARM_VGIC_GRP_ADDR , +KVM_VGIC_V2_ADDR_TYPE_CPU , + kgc->dev_fd); }static void kvm_arm_gic_class_init (ObjectClass *klass,void *data)target-arm/kvm.c +2
-0@@ -184,8 +184,10 @@ out:*/ typedef struct KVMDevice {struct kvm_arm_device_addr kda; +struct kvm_device_attr kdattr;MemoryRegion *mr;QSLIST_ENTRY (KVMDevice) entries; +int dev_fd; }KVMDevice ; static QSLIST_HEAD(kvm_devices_head, KVMDevice) kvm_devices_head;
target-arm/kvm.c static MemoryListener devlistener = { · line 230
Quoted 10 lines
target-arm/kvm.c +7
-0@@ -219,6 +221,28 @@ static MemoryListener devlistener = { .region_del = kvm_arm_devlistener_del, }; +static void kvm_arm_set_device_addr (KVMDevice *kd) +{ +struct kvm_device_attr *attr = &kd->kdattr; +int ret; + +/* If the device control API is available and we have a device fd on the +* KVMDevice struct, let's use the newer API */
putting the closing */ on a line of its own fits the style in the rest of this file (and looks nicer imho ;-))
target-arm/kvm.c static MemoryListener devlistener = { · line 233
Quoted 3 lines
target-arm/kvm.c +3
-0+if (kd->dev_fd >=0 ) { +uint64_t addr = kd->kda.addr; + attr->addr = (uint64_t )(long )&addr;
why (uint64_t)(long)? Other places (like the get/put register code) where we need to fill in an address into a uint64_t field in a kernel struct we do with a simple
attr->addr = (uintptr_t)&addr;
target-arm/kvm.c static MemoryListener devlistener = { · line 241
Quoted 8 lines
target-arm/kvm.c +8
-0+ ret =kvm_device_ioctl (kd->dev_fd,KVM_SET_DEVICE_ATTR , attr); + }else { + ret =kvm_vm_ioctl (kvm_state,KVM_ARM_SET_DEVICE_ADDR , &kd->kda); + } + +if (ret <0 ) { +fprintf (stderr,"Failed to set device address: %s\n" , +strerror (errno));
Your error code is in -ret here, not in errno.
target-arm/kvm.c static MemoryListener devlistener = { · line 244
Quoted 3 lines
target-arm/kvm.c +3
-0+abort (); + } +}
Otherwise looks OK.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 4/4] arm: vgic device control api support
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Christoffer Dall
Support creating the ARM vgic device through the device control API and setting the base address for the distributor and cpu interfaces in KVM VMs using this API.
Because the older
KVM_CREATE_IRQCHIPinterface needs the irq chip to be created prior to creating the VCPUs, we first test if if can use the"if we"
Peter,
Thanks for your review comments and pointers on how to fix. Much appreciated. I've addressed your comments and will get a new series out asap.
-Christoffer