diff mbox

KVM: ARM: arch_timer: Initialize cntvoff at vcpu_init

Message ID 1380377113-15183-1-git-send-email-christoffer.dall@linaro.org
State New
Headers show

Commit Message

Christoffer Dall Sept. 28, 2013, 2:05 p.m. UTC
Initialize the cntvoff at vcpu_init time, not before running the VCPUs
at the first time because that will overwrite any potentially restored
values from user space.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 virt/kvm/arm/arch_timer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marc Zyngier Sept. 30, 2013, 7:41 a.m. UTC | #1
Hi Christoffer,

On 28/09/13 15:05, Christoffer Dall wrote:
> Initialize the cntvoff at vcpu_init time, not before running the VCPUs
> at the first time because that will overwrite any potentially restored
> values from user space.
> 
> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
>  virt/kvm/arm/arch_timer.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
> index 8168437..2f6b5fe 100644
> --- a/virt/kvm/arm/arch_timer.c
> +++ b/virt/kvm/arm/arch_timer.c
> @@ -181,6 +181,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
>  	INIT_WORK(&timer->expired, kvm_timer_inject_irq_work);
>  	hrtimer_init(&timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
>  	timer->timer.function = kvm_timer_expire;
> +	vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read();
>  }
>  
>  static void kvm_timer_init_interrupt(void *info)
> @@ -282,7 +283,6 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
>  int kvm_timer_init(struct kvm *kvm)
>  {
>  	if (timecounter && wqueue) {
> -		kvm->arch.timer.cntvoff = kvm_phys_timer_read();
>  		kvm->arch.timer.enabled = 1;
>  	}
>  
> 

I'm not exactly fond of this change. CNTVOFF is a per-VM property. Here,
we end-up recomputing it as we initialize VCPUs, which is very
counter-intuitive.

If anything, I'd move the call of kvm_timer_init out of kvm_vgic_init
into kvm_arch_init_vm.

What do you think?

	M.
Christoffer Dall Sept. 30, 2013, 1:57 p.m. UTC | #2
On Mon, Sep 30, 2013 at 08:41:06AM +0100, Marc Zyngier wrote:
> Hi Christoffer,
> 
> On 28/09/13 15:05, Christoffer Dall wrote:
> > Initialize the cntvoff at vcpu_init time, not before running the VCPUs
> > at the first time because that will overwrite any potentially restored
> > values from user space.
> > 
> > Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> > ---
> >  virt/kvm/arm/arch_timer.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
> > index 8168437..2f6b5fe 100644
> > --- a/virt/kvm/arm/arch_timer.c
> > +++ b/virt/kvm/arm/arch_timer.c
> > @@ -181,6 +181,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
> >  	INIT_WORK(&timer->expired, kvm_timer_inject_irq_work);
> >  	hrtimer_init(&timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
> >  	timer->timer.function = kvm_timer_expire;
> > +	vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read();
> >  }
> >  
> >  static void kvm_timer_init_interrupt(void *info)
> > @@ -282,7 +283,6 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
> >  int kvm_timer_init(struct kvm *kvm)
> >  {
> >  	if (timecounter && wqueue) {
> > -		kvm->arch.timer.cntvoff = kvm_phys_timer_read();
> >  		kvm->arch.timer.enabled = 1;
> >  	}
> >  
> > 
> 
> I'm not exactly fond of this change. CNTVOFF is a per-VM property. Here,
> we end-up recomputing it as we initialize VCPUs, which is very
> counter-intuitive.
> 
> If anything, I'd move the call of kvm_timer_init out of kvm_vgic_init
> into kvm_arch_init_vm.
> 
> What do you think?
> 

I think as for the anything part, we need to move it, otherwise
migration won't work.

Calling this from kvm_arch_init_vm sounds much cleaner actually, so I'll
do that.

Thanks,
-Christoffer
diff mbox

Patch

diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 8168437..2f6b5fe 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -181,6 +181,7 @@  void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
 	INIT_WORK(&timer->expired, kvm_timer_inject_irq_work);
 	hrtimer_init(&timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
 	timer->timer.function = kvm_timer_expire;
+	vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read();
 }
 
 static void kvm_timer_init_interrupt(void *info)
@@ -282,7 +283,6 @@  void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
 int kvm_timer_init(struct kvm *kvm)
 {
 	if (timecounter && wqueue) {
-		kvm->arch.timer.cntvoff = kvm_phys_timer_read();
 		kvm->arch.timer.enabled = 1;
 	}