public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 3/3] KVM: Non-atomic interrupt injection
Date: Tue, 20 Jul 2010 21:55:33 -0300	[thread overview]
Message-ID: <20100721005533.GA9989@amt.cnet> (raw)
In-Reply-To: <1279631827-4016-4-git-send-email-avi@redhat.com>

On Tue, Jul 20, 2010 at 04:17:07PM +0300, Avi Kivity wrote:
> Change the interrupt injection code to work from preemptible, interrupts
> enabled context.  This works by adding a ->cancel_injection() operation
> that undoes an injection in case we were not able to actually enter the guest
> (this condition could never happen with atomic injection).
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  arch/x86/include/asm/kvm_host.h |    1 +
>  arch/x86/kvm/svm.c              |   12 ++++++++++++
>  arch/x86/kvm/vmx.c              |   11 +++++++++++
>  arch/x86/kvm/x86.c              |   27 ++++++++++++++-------------
>  4 files changed, 38 insertions(+), 13 deletions(-)
> 

> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4709,6 +4709,19 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  	if (unlikely(r))
>  		goto out;
>  
> +	inject_pending_event(vcpu);
> +
> +	/* enable NMI/IRQ window open exits if needed */
> +	if (vcpu->arch.nmi_pending)
> +		kvm_x86_ops->enable_nmi_window(vcpu);
> +	else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
> +		kvm_x86_ops->enable_irq_window(vcpu);
> +
> +	if (kvm_lapic_enabled(vcpu)) {
> +		update_cr8_intercept(vcpu);
> +		kvm_lapic_sync_to_vapic(vcpu);
> +	}
> +
>  	preempt_disable();
>  
>  	kvm_x86_ops->prepare_guest_switch(vcpu);
> @@ -4727,23 +4740,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  		smp_wmb();
>  		local_irq_enable();
>  		preempt_enable();
> +		kvm_x86_ops->cancel_injection(vcpu);
>  		r = 1;
>  		goto out;
>  	}
>  
> -	inject_pending_event(vcpu);
> -
> -	/* enable NMI/IRQ window open exits if needed */
> -	if (vcpu->arch.nmi_pending)
> -		kvm_x86_ops->enable_nmi_window(vcpu);
> -	else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
> -		kvm_x86_ops->enable_irq_window(vcpu);
> -
> -	if (kvm_lapic_enabled(vcpu)) {
> -		update_cr8_intercept(vcpu);
> -		kvm_lapic_sync_to_vapic(vcpu);
> -	}
> -
>  	srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
>  
>  	kvm_guest_enter();

This breaks

int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
{
        struct kvm_lapic *apic = vcpu->arch.apic;
        int highest_irr;

        /* This may race with setting of irr in __apic_accept_irq() and
         * value returned may be wrong, but kvm_vcpu_kick() in
         * __apic_accept_irq
         * will cause vmexit immediately and the value will be
         * recalculated
         * on the next vmentry.
         */

(also valid for nmi_pending and PIC). Can't simply move
atomic_set(guest_mode, 1) in preemptible section as that would make it
possible for kvm_vcpu_kick to IPI stale vcpu->cpu.

Also should undo vmx.rmode.* ?



  reply	other threads:[~2010-07-21  0:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-20 13:17 [PATCH v2 0/3] Nonatomic interrupt injection Avi Kivity
2010-07-20 13:17 ` [PATCH v2 1/3] KVM: VMX: Split up vmx_complete_interrupts() Avi Kivity
2010-07-20 13:17 ` [PATCH v2 2/3] KVM: VMX: Parameterize vmx_complete_interrupts() for both exit and entry Avi Kivity
2010-07-20 13:17 ` [PATCH v2 3/3] KVM: Non-atomic interrupt injection Avi Kivity
2010-07-21  0:55   ` Marcelo Tosatti [this message]
2010-07-21  5:37     ` Avi Kivity
2010-07-21 16:27       ` Marcelo Tosatti
2010-07-21 18:22         ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100721005533.GA9989@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox