public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: mtosatti@redhat.com
To: kvm@vger.kernel.org
Cc: Andrea Arcangeli <aarcange@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 1/4] KVM: MMU: protect kvm_mmu_change_mmu_pages with mmu_lock
Date: Mon, 27 Apr 2009 17:06:21 -0300	[thread overview]
Message-ID: <20090427200756.861005449@amt.cnet> (raw)
In-Reply-To: 20090427200620.389589459@amt.cnet

[-- Attachment #1: set-mem-lock --]
[-- Type: text/plain, Size: 2139 bytes --]

kvm_handle_hva, called by MMU notifiers, manipulates mmu data only with
the protection of mmu_lock.

Update kvm_mmu_change_mmu_pages callers to take mmu_lock, thus protecting
against kvm_handle_hva.

CC: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm/arch/x86/kvm/mmu.c
===================================================================
--- kvm.orig/arch/x86/kvm/mmu.c
+++ kvm/arch/x86/kvm/mmu.c
@@ -2732,7 +2732,6 @@ void kvm_mmu_slot_remove_write_access(st
 {
 	struct kvm_mmu_page *sp;
 
-	spin_lock(&kvm->mmu_lock);
 	list_for_each_entry(sp, &kvm->arch.active_mmu_pages, link) {
 		int i;
 		u64 *pt;
@@ -2747,7 +2746,6 @@ void kvm_mmu_slot_remove_write_access(st
 				pt[i] &= ~PT_WRITABLE_MASK;
 	}
 	kvm_flush_remote_tlbs(kvm);
-	spin_unlock(&kvm->mmu_lock);
 }
 
 void kvm_mmu_zap_all(struct kvm *kvm)
Index: kvm/arch/x86/kvm/x86.c
===================================================================
--- kvm.orig/arch/x86/kvm/x86.c
+++ kvm/arch/x86/kvm/x86.c
@@ -1647,10 +1647,12 @@ static int kvm_vm_ioctl_set_nr_mmu_pages
 		return -EINVAL;
 
 	down_write(&kvm->slots_lock);
+	spin_lock(&kvm->mmu_lock);
 
 	kvm_mmu_change_mmu_pages(kvm, kvm_nr_mmu_pages);
 	kvm->arch.n_requested_mmu_pages = kvm_nr_mmu_pages;
 
+	spin_unlock(&kvm->mmu_lock);
 	up_write(&kvm->slots_lock);
 	return 0;
 }
@@ -1826,7 +1828,9 @@ int kvm_vm_ioctl_get_dirty_log(struct kv
 
 	/* If nothing is dirty, don't bother messing with page tables. */
 	if (is_dirty) {
+		spin_lock(&kvm->mmu_lock);
 		kvm_mmu_slot_remove_write_access(kvm, log->slot);
+		spin_unlock(&kvm->mmu_lock);
 		kvm_flush_remote_tlbs(kvm);
 		memslot = &kvm->memslots[log->slot];
 		n = ALIGN(memslot->npages, BITS_PER_LONG) / 8;
@@ -4510,12 +4514,14 @@ int kvm_arch_set_memory_region(struct kv
 		}
 	}
 
+	spin_lock(&kvm->mmu_lock);
 	if (!kvm->arch.n_requested_mmu_pages) {
 		unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
 		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
 	}
 
 	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
+	spin_unlock(&kvm->mmu_lock);
 	kvm_flush_remote_tlbs(kvm);
 
 	return 0;



  reply	other threads:[~2009-04-27 20:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-27 20:06 [patch 0/4] set_memory_region locking fixes / vcpu->arch.cr3 + removal of memslots mtosatti
2009-04-27 20:06 ` mtosatti [this message]
2009-04-27 20:06 ` [patch 2/4] KVM: take mmu_lock when updating a deleted slot mtosatti
2009-04-27 20:06 ` [patch 3/4] KVM: introduce kvm_arch_can_free_memslot, disallow slot deletion if cached cr3 mtosatti
2009-05-07 14:16   ` Avi Kivity
2009-05-07 18:58     ` Marcelo Tosatti
2009-05-07 21:03     ` [patch 0/4] set_memory_region locking fixes / cr3 vs removal of memslots v2 mtosatti
2009-05-07 21:03       ` [patch 1/4] KVM: MMU: protect kvm_mmu_change_mmu_pages with mmu_lock mtosatti
2009-05-07 21:03       ` [patch 2/4] KVM: take mmu_lock when updating a deleted slot mtosatti
2009-05-07 21:03       ` [patch 3/4] KVM: introduce kvm_arch_can_free_memslot, disallow slot deletion if cached cr3 mtosatti
2009-05-10 16:40         ` Avi Kivity
2009-05-12 21:55           ` [patch 0/3] locking fixes / cr3 validation v3 mtosatti
2009-05-12 21:55             ` [patch 1/3] KVM: MMU: protect kvm_mmu_change_mmu_pages with mmu_lock mtosatti
2009-05-12 21:55             ` [patch 2/3] KVM: take mmu_lock when updating a deleted slot mtosatti
2009-05-12 21:55             ` [patch 3/3] KVM: x86: check for cr3 validity in mmu_alloc_roots mtosatti
2009-05-13  7:40             ` [patch 0/3] locking fixes / cr3 validation v3 Avi Kivity
2009-05-07 21:03       ` [patch 4/4] KVM: x86: disallow changing a slots size mtosatti
2009-04-27 20:06 ` mtosatti

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=20090427200756.861005449@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=aarcange@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