KVM: arm/arm64: Route vtimer events to user space
Subsystems (5)
PATCH v2 1/1 KVM: arm/arm64: Route vtimer events to user space
We have 2 modes for dealing with interrupts in the ARM world. We can either handle them all using hardware acceleration through the vgic or we can emulate a gic in user space and only drive CPU IRQ pins from there.
Unfortunately, when driving IRQs from user space, we never tell user space about timer events that may result in interrupt line state changes, so we lose out on timer events if we run with user space gic emulation.
This patch set fixes that by routing vtimer expiration events to user space. With this patch I can successfully run edk2 and Linux with user space gic emulation.
---
A branch with WIP QEMU code can be found here:
https://github.com/agraf/qemu.git no-kvm-irqchip
v1 -> v2:
- Add back curly brace that got lost (and is very stubborn, sorry for the resubmit to actually add it back for real)
--- Documentation/virtual/kvm/api.txt | 28 ++++++++- arch/arm/include/asm/kvm_host.h | 3 + arch/arm/kvm/arm.c | 47 +++++++++++--- arch/arm64/include/asm/kvm_host.h | 3 + include/uapi/linux/kvm.h | 14 +++++ virt/kvm/arm/arch_timer.c | 126 ++++++++++++++++++++++++++++---------- 6 files changed, 178 insertions(+), 43 deletions(-)
Documentation/virtual/kvm/api.txt +26 -2
@@ -997,7 +997,9 @@ documentation when it pops into existence). Capability: KVM_CAP_ENABLE_CAP, KVM_CAP_ENABLE_CAP_VM Architectures: x86 (only KVM_CAP_ENABLE_CAP_VM), - mips (only KVM_CAP_ENABLE_CAP), ppc, s390 + mips (only KVM_CAP_ENABLE_CAP), ppc, s390, + arm (only KVM_CAP_ENABLE_CAP), + arm64 (only only KVM_CAP_ENABLE_CAP) Type: vcpu ioctl, vm ioctl (with KVM_CAP_ENABLE_CAP_VM) Parameters: struct kvm_enable_cap (in) Returns: 0 on success; -1 on error
@@ -3200,8 +3202,10 @@ struct kvm_run { /* in */ __u8 request_interrupt_window; -Request that KVM_RUN return when it becomes possible to inject external +[x86] Request that KVM_RUN return when it becomes possible to inject external interrupts into the guest. Useful in conjunction with KVM_INTERRUPT. +[arm*] Bits set to 1 in here mask IRQ lines that would otherwise potentially +trigger forever. Useful with KVM_CAP_ARM_TIMER. __u8 padding1[7];
@@ -3517,6 +3521,16 @@ Hyper-V SynIC state change. Notification is used to remap SynIC event/message pages and to enable/disable SynIC messages/events processing in userspace. + /* KVM_EXIT_ARM_TIMER */ + struct { + __u8 timesource; + } arm_timer; + +Indicates that a timer triggered that user space needs to handle and +potentially mask with vcpu->run->request_interrupt_window to allow the +guest to proceed. This only happens for timers that got enabled through +KVM_CAP_ARM_TIMER. + /* Fix the size of the union. */ char padding[256]; };
@@ -3737,6 +3751,16 @@ Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from the guest. +6.11 KVM_CAP_ARM_TIMER + +Architectures: arm, arm64 +Target: vcpu +Parameters: args[0] contains a bitmap of timers to enable + +This capability allows to route per-core timers into user space. When it's +enabled, the enabled timers trigger KVM_EXIT_ARM_TIMER guest exits when they +are pending, unless masked by vcpu->run->request_interrupt_window. + 7. Capabilities that can be enabled on VMs ------------------------------------------
arch/arm/include/asm/kvm_host.h +3 -0
@@ -180,6 +180,9 @@ struct kvm_vcpu_arch {/* Detect first run of a vcpu */ bool has_run_once; + +/* User space wants timer notifications */ +bool user_space_arm_timers; };struct kvm_vm_stat {
arch/arm/kvm/arm.c +40 -7
77 lines not on this page · raw message
arch/arm64/include/asm/kvm_host.h +3 -0
@@ -270,6 +270,9 @@ struct kvm_vcpu_arch {/* Detect first run of a vcpu */ bool has_run_once; + +/* User space wants timer notifications */ +bool user_space_arm_timers; };#define vcpu_gp_regs (v) (&(v)->arch.ctxt.gp_regs)
include/uapi/linux/kvm.h +14 -0
@@ -205,6 +205,7 @@ struct kvm_hyperv_exit {#define KVM_EXIT_S390_STSI 25#define KVM_EXIT_IOAPIC_EOI 26#define KVM_EXIT_HYPERV 27 +#define KVM_EXIT_ARM_TIMER 28/* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */
@@ -361,6 +362,10 @@ struct kvm_run { } eoi;/* KVM_EXIT_HYPERV */ struct kvm_hyperv_exit hyperv; +/* KVM_EXIT_ARM_TIMER */ +struct { +__u8 timesource; + } arm_timer;/* Fix the size of the union. */ char padding[256 ]; };
@@ -870,6 +875,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_S390_USER_INSTR0 130#define KVM_CAP_MSI_DEVID 131#define KVM_CAP_PPC_HTM 132 +#define KVM_CAP_ARM_TIMER 133#ifdef KVM_CAP_IRQ_ROUTING
@@ -1327,4 +1333,12 @@ struct kvm_assigned_msix_entry {#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) +/* Available with KVM_CAP_ARM_TIMER */ + +/* Bits for run->request_interrupt_window */ +#define KVM_IRQWINDOW_VTIMER (1 << 0) + +/* Bits for run->arm_timer.timesource */ +#define KVM_ARM_TIMER_VTIMER (1 << 0) +#endif /* __LINUX_KVM_H */
virt/kvm/arm/arch_timer.c +92 -34
168 lines not on this page · raw message
Signature · 1 line
2.6.6
Alex,
Quoted 11 lines · Alexander Graf
We have 2 modes for dealing with interrupts in the ARM world. We can either handle them all using hardware acceleration through the vgic or we can emulate a gic in user space and only drive CPU IRQ pins from there.
Unfortunately, when driving IRQs from user space, we never tell user space about timer events that may result in interrupt line state changes, so we lose out on timer events if we run with user space gic emulation.
This patch set fixes that by routing vtimer expiration events to user space. With this patch I can successfully run edk2 and Linux with user space gic emulation.
I have two versions of v2. Are there any differences or did it just go out twice or got duplicated somehow on my end?
Thanks,
-Christoffer
Quoted 14 lines · Christoffer Dall
Alex,
Quoted 8 lines · Alexander Graf
We have 2 modes for dealing with interrupts in the ARM world. We can either handle them all using hardware acceleration through the vgic or we can emulate a gic in user space and only drive CPU IRQ pins from there.
Unfortunately, when driving IRQs from user space, we never tell user space about timer events that may result in interrupt line state changes, so we lose out on timer events if we run with user space gic emulation.
Quoted 6 lines
Quoted 3 lines
This patch set fixes that by routing vtimer expiration events to user space. With this patch I can successfully run edk2 and Linux with user space gic emulation.
I have two versions of v2. Are there any differences or did it just go out twice or got duplicated somehow on my end?
Just ignore v2. I shouldn’t send emails that early in the morning. v3 is much better ;)
Alex
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm