diff mbox

[v3,1/6] KVM: Don't use KVM_REQ_PENDING_TIMER

Message ID 1341853545-3023-2-git-send-email-avi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Avi Kivity July 9, 2012, 5:05 p.m. UTC
It's a write-only bit, set by the timer and cleared by the main loop.
Remove it.  Retain the definition since ppc uses it.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/timer.c | 8 ++------
 arch/x86/kvm/x86.c   | 1 -
 2 files changed, 2 insertions(+), 7 deletions(-)

Comments

Gleb Natapov July 10, 2012, 8:50 a.m. UTC | #1
On Mon, Jul 09, 2012 at 08:05:40PM +0300, Avi Kivity wrote:
> It's a write-only bit, set by the timer and cleared by the main loop.
> Remove it.  Retain the definition since ppc uses it.
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  arch/x86/kvm/timer.c | 8 ++------
>  arch/x86/kvm/x86.c   | 1 -
>  2 files changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/timer.c b/arch/x86/kvm/timer.c
> index 6b85cc6..c28f838 100644
> --- a/arch/x86/kvm/timer.c
> +++ b/arch/x86/kvm/timer.c
> @@ -27,14 +27,10 @@ enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
>  	/*
>  	 * There is a race window between reading and incrementing, but we do
>  	 * not care about potentially losing timer events in the !reinject
> -	 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
> -	 * in vcpu_enter_guest.
So what about the part that says "KVM_REQ_PENDING_TIMER is implicitly
checked in vcpu_enter_guest"? This patch drops the check. So now if
timer triggers while vcpu is in userspace it will enter guest mode
without injecting timer interrupt on the next ioctl(KVM_RUN). Or do I
miss something here?

> +	 * case anyway.
>  	 */
> -	if (ktimer->reinject || !atomic_read(&ktimer->pending)) {
> +	if (ktimer->reinject || !atomic_read(&ktimer->pending))
>  		atomic_inc(&ktimer->pending);
> -		/* FIXME: this code should not know anything about vcpus */
> -		kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
> -	}
>  
>  	if (waitqueue_active(q))
>  		wake_up_interruptible(q);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index ff0b487..ae07ef2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5437,7 +5437,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
>  		if (r <= 0)
>  			break;
>  
> -		clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
>  		if (kvm_cpu_has_pending_timer(vcpu))
>  			kvm_inject_pending_timer_irqs(vcpu);
>  
> -- 
> 1.7.11
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
			Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Avi Kivity July 10, 2012, 9:13 a.m. UTC | #2
On 07/10/2012 11:50 AM, Gleb Natapov wrote:
> On Mon, Jul 09, 2012 at 08:05:40PM +0300, Avi Kivity wrote:
> > It's a write-only bit, set by the timer and cleared by the main loop.
> > Remove it.  Retain the definition since ppc uses it.
> > 
> > Signed-off-by: Avi Kivity <avi@redhat.com>
> > ---
> >  arch/x86/kvm/timer.c | 8 ++------
> >  arch/x86/kvm/x86.c   | 1 -
> >  2 files changed, 2 insertions(+), 7 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/timer.c b/arch/x86/kvm/timer.c
> > index 6b85cc6..c28f838 100644
> > --- a/arch/x86/kvm/timer.c
> > +++ b/arch/x86/kvm/timer.c
> > @@ -27,14 +27,10 @@ enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
> >  	/*
> >  	 * There is a race window between reading and incrementing, but we do
> >  	 * not care about potentially losing timer events in the !reinject
> > -	 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
> > -	 * in vcpu_enter_guest.
> So what about the part that says "KVM_REQ_PENDING_TIMER is implicitly
> checked in vcpu_enter_guest"? This patch drops the check. So now if
> timer triggers while vcpu is in userspace it will enter guest mode
> without injecting timer interrupt on the next ioctl(KVM_RUN). Or do I
> miss something here?

You're right, the bit appears to be write-only, but it isn't.  The check
inside the critical section for vcpu->requests reads it.

I guess we can make the check explicit by doing a 'goto out' if the bit
is set.
diff mbox

Patch

diff --git a/arch/x86/kvm/timer.c b/arch/x86/kvm/timer.c
index 6b85cc6..c28f838 100644
--- a/arch/x86/kvm/timer.c
+++ b/arch/x86/kvm/timer.c
@@ -27,14 +27,10 @@  enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
 	/*
 	 * There is a race window between reading and incrementing, but we do
 	 * not care about potentially losing timer events in the !reinject
-	 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
-	 * in vcpu_enter_guest.
+	 * case anyway.
 	 */
-	if (ktimer->reinject || !atomic_read(&ktimer->pending)) {
+	if (ktimer->reinject || !atomic_read(&ktimer->pending))
 		atomic_inc(&ktimer->pending);
-		/* FIXME: this code should not know anything about vcpus */
-		kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
-	}
 
 	if (waitqueue_active(q))
 		wake_up_interruptible(q);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ff0b487..ae07ef2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5437,7 +5437,6 @@  static int __vcpu_run(struct kvm_vcpu *vcpu)
 		if (r <= 0)
 			break;
 
-		clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
 		if (kvm_cpu_has_pending_timer(vcpu))
 			kvm_inject_pending_timer_irqs(vcpu);