From: Marcelo Tosatti <marcelo-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 4/4] KVM: MMU: Switch to mmu spinlock
Date: Mon, 31 Dec 2007 10:06:56 -0500 [thread overview]
Message-ID: <20071231150656.GA16594@dmt> (raw)
In-Reply-To: <1199013439-2047-5-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
On Sun, Dec 30, 2007 at 01:17:19PM +0200, Avi Kivity wrote:
> From: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>
> Convert the synchronization of the shadow handling to a separate mmu_lock
> spinlock.
>
> Also guard fetch() by mmap_sem in read-mode to protect against alias
> and memslot changes.
>
> Signed-off-by: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
> ---
> arch/x86/kvm/mmu.c | 46 ++++++++++++++++++++++---------------------
> arch/x86/kvm/paging_tmpl.h | 10 +++++---
> arch/x86/kvm/vmx.c | 2 -
> include/linux/kvm_host.h | 3 +-
> virt/kvm/kvm_main.c | 3 +-
> 5 files changed, 33 insertions(+), 31 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 1b68f07..356e361 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -971,16 +971,12 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
> {
> }
>
> -static int __nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
> +static int __nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write,
> + gfn_t gfn, struct page *page)
> {
> int level = PT32E_ROOT_LEVEL;
> hpa_t table_addr = vcpu->arch.mmu.root_hpa;
> int pt_write = 0;
> - struct page *page;
> -
> - down_read(¤t->mm->mmap_sem);
> - page = gfn_to_page(vcpu->kvm, gfn);
> - up_read(¤t->mm->mmap_sem);
>
> for (; ; level--) {
> u32 index = PT64_INDEX(v, level);
> @@ -1022,9 +1018,15 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
> {
> int r;
>
> - mutex_lock(&vcpu->kvm->lock);
> - r = __nonpaging_map(vcpu, v, write, gfn);
> - mutex_unlock(&vcpu->kvm->lock);
> + struct page *page;
> +
> + down_read(¤t->mm->mmap_sem);
> + page = gfn_to_page(vcpu->kvm, gfn);
> + up_read(¤t->mm->mmap_sem);
> +
> + spin_lock(&vcpu->kvm->mmu_lock);
> + r = __nonpaging_map(vcpu, v, write, gfn, page);
> + spin_unlock(&vcpu->kvm->mmu_lock);
> return r;
> }
And its better to hold mmap_sem across __nonpaging_map() in similarity
to the paging fault path, to protect against memslot and alias changes.
--- mmu.c.orig 2007-12-31 09:34:50.000000000 -0500
+++ mmu.c 2007-12-31 09:59:46.000000000 -0500
@@ -1018,12 +1018,12 @@ static int nonpaging_map(struct kvm_vcpu
down_read(¤t->mm->mmap_sem);
page = gfn_to_page(vcpu->kvm, gfn);
- up_read(¤t->mm->mmap_sem);
spin_lock(&vcpu->kvm->mmu_lock);
kvm_mmu_free_some_pages(vcpu);
r = __nonpaging_map(vcpu, v, write, gfn, page);
spin_unlock(&vcpu->kvm->mmu_lock);
+ up_read(¤t->mm->mmap_sem);
return r;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
next prev parent reply other threads:[~2007-12-31 15:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-30 11:17 [PATCH 0/4] Updated kvm mmu scaling patch Avi Kivity
[not found] ` <1199013439-2047-1-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-30 11:17 ` [PATCH 1/4] KVM: MMU: Concurrent guest walkers Avi Kivity
[not found] ` <1199013439-2047-2-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-30 13:28 ` Avi Kivity
[not found] ` <47779CF8.1000408-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-30 14:39 ` Avi Kivity
2007-12-30 11:17 ` [PATCH 2/4] KVM: Add kvm_read_guest_atomic() Avi Kivity
2007-12-30 11:17 ` [PATCH 3/4] KVM: MMU: Avoid calling gfn_to_page() in mmu_set_spte() Avi Kivity
[not found] ` <1199013439-2047-4-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-31 14:50 ` Marcelo Tosatti
2007-12-31 14:55 ` Avi Kivity
2007-12-30 11:17 ` [PATCH 4/4] KVM: MMU: Switch to mmu spinlock Avi Kivity
[not found] ` <1199013439-2047-5-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-31 15:06 ` Marcelo Tosatti [this message]
2007-12-31 13:39 ` [PATCH 0/4] Updated kvm mmu scaling patch 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=20071231150656.GA16594@dmt \
--to=marcelo-bw31mazkks3ytjvyw6ydsg@public.gmane.org \
--cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.