public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: stable@vger.kernel.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: [PATCH 04/11] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock
Date: Wed,  9 May 2012 16:10:40 +0300	[thread overview]
Message-ID: <1336569047-23576-5-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1336569047-23576-1-git-send-email-avi@redhat.com>

From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>

Other threads may process the same page in that small window and skip
TLB flush and then return before these functions do flush.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 565f3be2174611f364405bbea2d86e153c2e7e78)
---
 virt/kvm/kvm_main.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c4ac57e..4c68c1e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -289,15 +289,15 @@ static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier *mn,
 	 */
 	idx = srcu_read_lock(&kvm->srcu);
 	spin_lock(&kvm->mmu_lock);
+
 	kvm->mmu_notifier_seq++;
 	need_tlb_flush = kvm_unmap_hva(kvm, address) | kvm->tlbs_dirty;
-	spin_unlock(&kvm->mmu_lock);
-	srcu_read_unlock(&kvm->srcu, idx);
-
 	/* we've to flush the tlb before the pages can be freed */
 	if (need_tlb_flush)
 		kvm_flush_remote_tlbs(kvm);
 
+	spin_unlock(&kvm->mmu_lock);
+	srcu_read_unlock(&kvm->srcu, idx);
 }
 
 static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn,
@@ -335,12 +335,12 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
 	for (; start < end; start += PAGE_SIZE)
 		need_tlb_flush |= kvm_unmap_hva(kvm, start);
 	need_tlb_flush |= kvm->tlbs_dirty;
-	spin_unlock(&kvm->mmu_lock);
-	srcu_read_unlock(&kvm->srcu, idx);
-
 	/* we've to flush the tlb before the pages can be freed */
 	if (need_tlb_flush)
 		kvm_flush_remote_tlbs(kvm);
+
+	spin_unlock(&kvm->mmu_lock);
+	srcu_read_unlock(&kvm->srcu, idx);
 }
 
 static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
@@ -378,13 +378,14 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
 
 	idx = srcu_read_lock(&kvm->srcu);
 	spin_lock(&kvm->mmu_lock);
-	young = kvm_age_hva(kvm, address);
-	spin_unlock(&kvm->mmu_lock);
-	srcu_read_unlock(&kvm->srcu, idx);
 
+	young = kvm_age_hva(kvm, address);
 	if (young)
 		kvm_flush_remote_tlbs(kvm);
 
+	spin_unlock(&kvm->mmu_lock);
+	srcu_read_unlock(&kvm->srcu, idx);
+
 	return young;
 }
 
-- 
1.7.10.1


  parent reply	other threads:[~2012-05-09 13:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
2012-05-09 13:10 ` [PATCH 01/11] KVM: s390: do store status after handling STOP_ON_STOP bit Avi Kivity
2012-05-09 13:10 ` [PATCH 02/11] KVM: s390: Sanitize fpc registers for KVM_SET_FPU Avi Kivity
2012-05-09 13:10 ` [PATCH 03/11] KVM: Fix write protection race during dirty logging Avi Kivity
2012-05-09 13:10 ` Avi Kivity [this message]
2012-05-09 13:10 ` [PATCH 05/11] KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction emulation Avi Kivity
2012-05-09 13:10 ` [PATCH 06/11] KVM: Ensure all vcpus are consistent with in-kernel irqchip settings Avi Kivity
2012-05-09 13:10 ` [PATCH 07/11] KVM: VMX: Fix delayed load of shared MSRs Avi Kivity
2012-05-09 13:10 ` [PATCH 08/11] KVM: nVMX: Fix erroneous exception bitmap check Avi Kivity
2012-05-09 13:10 ` [PATCH 09/11] KVM: VMX: vmx_set_cr0 expects kvm->srcu locked Avi Kivity
2012-05-09 13:10 ` [PATCH 10/11] KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context Avi Kivity
2012-05-09 13:10 ` [PATCH 11/11] KVM: lock slots_lock around device assignment Avi Kivity
2012-05-10 16:28 ` [PATCH 00/11] KVM fixes for 3.3.5 Greg KH
2012-05-12  0:35 ` Ben Hutchings
2012-05-13  9:23   ` Avi Kivity
2012-05-13 10:19     ` Ben Hutchings

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=1336569047-23576-5-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=stable@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