public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kvm/x86: check KVM_REQ_TLB_FLUSH with irqs disabled
Date: Mon, 16 Mar 2009 19:44:54 +0100	[thread overview]
Message-ID: <20090316184454.GN6159@amd.com> (raw)
In-Reply-To: <20090316183000.GC3783@amt.cnet>

On Mon, Mar 16, 2009 at 03:30:00PM -0300, Marcelo Tosatti wrote:
> On Mon, Mar 16, 2009 at 03:12:52PM +0200, Avi Kivity wrote:
> > Joerg Roedel wrote:
> >> For KVM remote TLB flushes we need to check the KVM_REQ_TLB_FLUSH
> >> request flag when the irqs are already disabled. Otherwise there is a
> >> small window of time for a race condition where we may enter a guest
> >> without doing a requested TLB flush.
> >>
> >> @@ -3108,8 +3108,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> >>  			kvm_write_guest_time(vcpu);
> >>  		if (test_and_clear_bit(KVM_REQ_MMU_SYNC, &vcpu->requests))
> >>  			kvm_mmu_sync_roots(vcpu);
> >> -		if (test_and_clear_bit(KVM_REQ_TLB_FLUSH, &vcpu->requests))
> >> -			kvm_x86_ops->tlb_flush(vcpu);
> >>  		if (test_and_clear_bit(KVM_REQ_REPORT_TPR_ACCESS,
> >>  				       &vcpu->requests)) {
> >>  			kvm_run->exit_reason = KVM_EXIT_TPR_ACCESS;
> >> @@ -3133,6 +3131,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> >>   	local_irq_disable();
> >>  +	if (test_and_clear_bit(KVM_REQ_TLB_FLUSH, &vcpu->requests))
> >> +		kvm_x86_ops->tlb_flush(vcpu);
> >> +
> >>  	if (vcpu->requests || need_resched() || signal_pending(current)) {
> >>  		local_irq_enable();
> >>  		preempt_enable();
> >>   
> >
> > If we lost the race and someone sets a bit after the test, then the test  
> > immediately above will pick this up retry the bit tests.
> 
> BTW, I've wondered if the local_irq_enable in svm_vcpu_run is safe:
> 
>         clgi();
> 
>         local_irq_enable();

The reason behind this is that we have to allow the host to accept
interrupts. Interrupts are still blocked by clgi (together with
NMI, INIT, debug traps and SMI) until the global interrupt flag is
reenabled as a final step of VMRUN. If we don't enable interrupts here
they would be blocked and an external interrupt would not cause an
#VMEXIT.

Joerg

-- 
           | Advanced Micro Devices GmbH
 Operating | Karl-Hammerschmidt-Str. 34, 85609 Dornach bei München
 System    | 
 Research  | Geschäftsführer: Jochen Polster, Thomas M. McCoy, Giuliano Meroni
 Center    | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
           | Registergericht München, HRB Nr. 43632


      parent reply	other threads:[~2009-03-16 18:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-16 13:03 [PATCH] kvm/x86: check KVM_REQ_TLB_FLUSH with irqs disabled Joerg Roedel
2009-03-16 13:12 ` Avi Kivity
2009-03-16 14:11   ` Joerg Roedel
2009-03-16 18:30   ` Marcelo Tosatti
2009-03-16 18:32     ` Avi Kivity
2009-03-16 18:44     ` Joerg Roedel [this message]

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=20090316184454.GN6159@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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