Patch "arm/arm64: KVM: Require in-kernel vgic for the arch timers" has been added to the 3.14-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
arm/arm64: KVM: Require in-kernel vgic for the arch timers
to the 3.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
arm-arm64-kvm-require-in-kernel-vgic-for-the-arch-timers.patch
and it can be found in the queue-3.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
05971120fca43e0357789a14b3386bb56eef2201Mon Sep 17 00:00:00 2001
From: Christoffer Dall <[email protected]>
Date: Fri, 12 Dec 2014 21:19:23 +0100
Subject: arm/arm64: KVM: Require in-kernel vgic for the arch timers
From: Christoffer Dall <[email protected]>
commit 05971120fca43e0357789a14b3386bb56eef2201 upstream.
[Note this patch is a bit different from the original one as the names of vgic_initialized and kvm_vgic_init are different.]
It is curently possible to run a VM with architected timers support without creating an in-kernel VGIC, which will result in interrupts from the virtual timer going nowhere.
To address this issue, move the architected timers initialization to the time when we run a VCPU for the first time, and then only initialize (and enable) the architected timers if we have a properly created and initialized in-kernel VGIC.
When injecting interrupts from the virtual timer to the vgic, the current setup should ensure that this never calls an on-demand init of the VGIC, which is the only call path that could return an error from kvm_vgic_inject_irq(), so capture the return value and raise a warning if there's an error there.
We also change the kvm_timer_init() function from returning an int to be a void function, since the function always succeeds.
--- arch/arm/kvm/arm.c | 13 +++++++++++-- include/kvm/arm_arch_timer.h | 10 ++++------ virt/kvm/arm/arch_timer.c | 30 ++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 16 deletions(-)
arch/arm/kvm/arm.c +11 -2
@@ -441,6 +441,7 @@ static void update_vttbr(struct kvm *kvmstatic int kvm_vcpu_first_run_init (struct kvm_vcpu *vcpu) { +struct kvm *kvm = vcpu->kvm;int ret;if (likely (vcpu->arch.has_run_once))
@@ -452,12 +453,20 @@ static int kvm_vcpu_first_run_init(struc* Initialize the VGIC before running a vcpu the first time on * this VM. */ -if (unlikely (!vgic_initialized (vcpu->kvm))) { - ret =kvm_vgic_init (vcpu->kvm); +if (unlikely (!vgic_initialized (kvm))) { + ret =kvm_vgic_init (kvm);if (ret)return ret; } +/* +* Enable the arch timers only if we have an in-kernel VGIC +* and it has been properly initialized, since we cannot handle +* interrupts from the virtual timer with a userspace gic. +*/ +if (irqchip_in_kernel (kvm) &&vgic_initialized (kvm)) +kvm_timer_enable (kvm); +return 0 ; }
include/kvm/arm_arch_timer.h +4 -6
@@ -60,7 +60,8 @@ struct arch_timer_cpu {#ifdef CONFIG_KVM_ARM_TIMER int kvm_timer_hyp_init (void ); -int kvm_timer_init (struct kvm *kvm); +void kvm_timer_enable (struct kvm *kvm); +void kvm_timer_init (struct kvm *kvm);void kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu,const struct kvm_irq_level *irq);void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu);
@@ -73,11 +74,8 @@ static inline int kvm_timer_hyp_init(voireturn 0 ; }; -static inline int kvm_timer_init (struct kvm *kvm) -{ -return 0 ; -} - +static inline void kvm_timer_enable (struct kvm *kvm) {} +static inline void kvm_timer_init (struct kvm *kvm) {}static inline void kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu,const struct kvm_irq_level *irq) {}static inline void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu) {}
virt/kvm/arm/arch_timer.c +22 -8
@@ -61,12 +61,14 @@ static void timer_disarm(struct arch_timstatic void kvm_timer_inject_irq (struct kvm_vcpu *vcpu) { +int ret;struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; timer->cntv_ctl |=ARCH_TIMER_CTRL_IT_MASK ; -kvm_vgic_inject_irq (vcpu->kvm, vcpu->vcpu_id, - timer->irq->irq, - timer->irq->level); + ret =kvm_vgic_inject_irq (vcpu->kvm, vcpu->vcpu_id, + timer->irq->irq, + timer->irq->level); +WARN_ON (ret); }static irqreturn_t kvm_arch_timer_handler (int irq,void *dev_id)
@@ -307,12 +309,24 @@ void kvm_timer_vcpu_terminate(struct kvmtimer_disarm (timer); } -int kvm_timer_init (struct kvm *kvm) +void kvm_timer_enable (struct kvm *kvm) { -if (timecounter && wqueue) { - kvm->arch.timer.cntvoff =kvm_phys_timer_read (); +if (kvm->arch.timer.enabled) +return ; + +/* +* There is a potential race here between VCPUs starting for the first +* time, which may be enabling the timer multiple times. That doesn't +* hurt though, because we're just setting a variable to the same +* variable that it already was. The important thing is that all +* VCPUs have the enabled variable set, before entering the guest, if +* the arch timers are enabled. +*/ +if (timecounter && wqueue) kvm->arch.timer.enabled =1 ; - } +} -return 0 ; +void kvm_timer_init (struct kvm *kvm) +{ + kvm->arch.timer.cntvoff =kvm_phys_timer_read (); }
Patches currently in stable-queue which might be from [email protected] are
queue-3.14/arm64-kvm-fix-hcr-setting-for-32bit-guests.patch queue-3.14/arm64-kvm-do-not-use-pgd_index-to-index-stage-2-pgd.patch queue-3.14/arm64-kvm-fix-tlb-invalidation-by-ipa-vmid.patch queue-3.14/arm-arm64-kvm-keep-elrsr-aisr-in-sync-with-software-model.patch queue-3.14/arm-arm64-kvm-require-in-kernel-vgic-for-the-arch-timers.patch