ARM: KVM: Enable in-kernel timers with user space gic
PATCH v3 1/1 ARM: KVM: Enable in-kernel timers with user space gic
When running with KVM enabled, you can choose between emulating the gic in kernel or user space. If the kernel supports in-kernel virtualization of the interrupt controller, it will default to that. If not, if will default to user space emulation.
Unfortunately when running in user mode gic emulation, we miss out on interrupt events which are only available from kernel space, such as the timer. This patch leverages the new kernel/user space pending line synchronization for timer events. It does not handle PMU events yet.
---
v1 -> v2:
- whitespace fixes
- use !! to determine whether bit is set
- call in-kernel device IRQs out by their name everywhere
v2 -> v3:
- fix last occurence of calling out timer IRQs explicitly
--- accel/kvm/kvm-all.c | 5 +++++ accel/stubs/kvm-stub.c | 5 +++++ hw/intc/arm_gic.c | 7 +++++++ include/sysemu/kvm.h | 11 +++++++++++ target/arm/cpu.h | 3 +++ target/arm/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+)
accel/kvm/kvm-all.c +5 -0
@@ -2285,6 +2285,11 @@ int kvm_has_intx_set_mask(void)return kvm_state->intx_set_mask; } +bool kvm_arm_supports_user_irq (void ) +{ +return kvm_check_extension (kvm_state,KVM_CAP_ARM_USER_IRQ ); +} +#ifdef KVM_CAP_SET_GUEST_DEBUG struct kvm_sw_breakpoint *kvm_find_sw_breakpoint (CPUState *cpu,target_ulong pc)
accel/stubs/kvm-stub.c +5 -0
@@ -155,4 +155,9 @@ void kvm_init_cpu_signals(CPUState *cpu) {abort (); } + +bool kvm_arm_supports_user_irq (void ) +{ +return false; +}#endif
hw/intc/arm_gic.c +7 -0
@@ -25,6 +25,7 @@#include "qom/cpu.h" #include "qemu/log.h" #include "trace.h" +#include "sysemu/kvm.h" /* #define DEBUG_GIC */
@@ -1412,6 +1413,12 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)return ; } +if (kvm_enabled () && !kvm_arm_supports_user_irq ()) { +error_setg (errp,"KVM with user space irqchip only works when the " +"host kernel supports KVM_CAP_ARM_USER_IRQ" ); +return ; + } +/* This creates distributor and main CPU interface (s->cpuiomem[0]) */ gic_init_irqs_and_mmio (s, gic_set_irq, gic_ops);
include/sysemu/kvm.h +11 -0
@@ -227,6 +227,17 @@ int kvm_init_vcpu(CPUState *cpu);int kvm_cpu_exec (CPUState *cpu);int kvm_destroy_vcpu (CPUState *cpu); +/** +* kvm_arm_supports_user_irq +* +* Not all KVM implementations support notifications for kernel generated +* interrupt events to user space. This function indicates whether the current +* KVM implementation does support them. +* +* Returns: true if KVM supports using kernel generated IRQs from user space +*/ +bool kvm_arm_supports_user_irq (void ); +#ifdef NEED_CPU_H #include "cpu.h"
target/arm/cpu.h +3 -0
@@ -706,6 +706,9 @@ struct ARMCPU {void *el_change_hook_opaque;int32_t node_id;/* NUMA node this CPU belongs to */ + +/* Used to synchronize KVM and QEMU in-kernel device levels */ +uint8_t device_irq_level; };static inline ARMCPU *arm_env_get_cpu (CPUARMState *env)
target/arm/kvm.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
1.8.5.6
Quoted 24 lines · Alexander Graf
When running with KVM enabled, you can choose between emulating the gic in kernel or user space. If the kernel supports in-kernel virtualization of the interrupt controller, it will default to that. If not, if will default to user space emulation.
Unfortunately when running in user mode gic emulation, we miss out on interrupt events which are only available from kernel space, such as the timer. This patch leverages the new kernel/user space pending line synchronization for timer events. It does not handle PMU events yet.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
v1 -> v2:
- whitespace fixes
- use !! to determine whether bit is set
- call in-kernel device IRQs out by their name everywherev2 -> v3:
- fix last occurence of calling out timer IRQs explicitly
Quoted 9 lines
--- accel/kvm/kvm-all.c | 5 +++++ accel/stubs/kvm-stub.c | 5 +++++ hw/intc/arm_gic.c | 7 +++++++ include/sysemu/kvm.h | 11 +++++++++++ target/arm/cpu.h | 3 +++ target/arm/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+)
Tried testing this on a gicv3 machine, a ThunderX2. The guest kernel complains with
GICv3: GIC: unable to set SRE (disabled at EL2), panic ahead
but no panic occurs. Instead it hangs in cpu_do_idle(), waiting forever for an interrupt.
AAVMF also complains about SRE support, actually it asserts it.
ASSERT [ArmGicDxe] /builddir/build/BUILD/ovmf-c325e41585e3/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c(113): IccSre & (1 << 0)
I still haven't seen any problems with gicv2 though.
Thanks,
drew
Quoted 35 lines · Andrew Jones
Quoted 24 lines · Alexander Graf
When running with KVM enabled, you can choose between emulating the gic in kernel or user space. If the kernel supports in-kernel virtualization of the interrupt controller, it will default to that. If not, if will default to user space emulation.
Unfortunately when running in user mode gic emulation, we miss out on interrupt events which are only available from kernel space, such as the timer. This patch leverages the new kernel/user space pending line synchronization for timer events. It does not handle PMU events yet.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
v1 -> v2:
- whitespace fixes
- use !! to determine whether bit is set
- call in-kernel device IRQs out by their name everywherev2 -> v3:
- fix last occurence of calling out timer IRQs explicitly
Quoted 9 lines
--- accel/kvm/kvm-all.c | 5 +++++ accel/stubs/kvm-stub.c | 5 +++++ hw/intc/arm_gic.c | 7 +++++++ include/sysemu/kvm.h | 11 +++++++++++ target/arm/cpu.h | 3 +++ target/arm/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+)
Quoted 1 line
Tried testing this on a gicv3 machine, a ThunderX2. The guest kernel
Did you patch QEMU to automatically choose the gic version? The upstream default is to have gicv2 as the guest gic type. And gicv2 should work just fine.
I have seen issues with gicv3 emulation in user space, yes. I guess we don't have a channel to properly trap the MSRs into user space yet.
Alex
Quoted 38 lines · Alexander Graf
Quoted 35 lines · Andrew Jones
Quoted 33 lines · Alexander Graf
When running with KVM enabled, you can choose between emulating the gic in kernel or user space. If the kernel supports in-kernel virtualization of the interrupt controller, it will default to that. If not, if will default to user space emulation.
Unfortunately when running in user mode gic emulation, we miss out on interrupt events which are only available from kernel space, such as the timer. This patch leverages the new kernel/user space pending line synchronization for timer events. It does not handle PMU events yet.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Andrew Jones <[email protected]>---
v1 -> v2:
- whitespace fixes
- use !! to determine whether bit is set
- call in-kernel device IRQs out by their name everywherev2 -> v3:
- fix last occurence of calling out timer IRQs explicitly
--- accel/kvm/kvm-all.c | 5 +++++ accel/stubs/kvm-stub.c | 5 +++++ hw/intc/arm_gic.c | 7 +++++++ include/sysemu/kvm.h | 11 +++++++++++ target/arm/cpu.h | 3 +++ target/arm/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+)
Quoted 3 lines
Quoted 1 line
Tried testing this on a gicv3 machine, a ThunderX2. The guest kernel
Did you patch QEMU to automatically choose the gic version?
Nope, I was just trying to use a pre-existing guest config on that host, which had gic-version=3 on its command line.
Quoted 3 lines
The upstream
default is to have gicv2 as the guest gic type. And gicv2 should work just fine.
Yup, works for me now (with its limitations - had to reduce the number of cpus the pre-existing guest config had configured to 8.)
Thanks,
drew
Peter Maydell
AppliedQuoted 5 lines · Alexander Graf
When running with KVM enabled, you can choose between emulating the gic in kernel or user space. If the kernel supports in-kernel virtualization of the interrupt controller, it will default to that. If not, if will default to user space emulation.
Quoted 7 lines
Unfortunately when running in user mode gic emulation, we miss out on interrupt events which are only available from kernel space, such as the timer. This patch leverages the new kernel/user space pending line synchronization for timer events. It does not handle PMU events yet.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Applied to target-arm.next, thanks.
-- PMM