Re: [PATCH] kvm/x86: check KVM_REQ_TLB_FLUSH with irqs disabled

From: Joerg Roedel
Date: Mon Mar 16 2009 - 10:13:08 EST


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.
>

Ah true. Sorry for the noise.

--
| 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/