From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 0/4] Updated kvm mmu scaling patch
Date: Mon, 31 Dec 2007 15:39:58 +0200 [thread overview]
Message-ID: <4778F12E.8040001@qumranet.com> (raw)
In-Reply-To: <1199013439-2047-1-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
Avi Kivity wrote:
> The following patchset, based on Marcelo's original mmu scaling patch,
> allows the kvm guest walker to run concurrently. Shadow pagetable
> manipulation is still single threaded.
>
> Handling pte writes is similar to an early version of the patchset: the page
> is derived from the guest pte being written. Unlike the original version,
> we only "guess" the gfn (based on the current paging mode), and if we are
> wrong, we just throw the page away.
>
The attached patch is needed as well.
--
error compiling committee.c: too many arguments to function
[-- Attachment #2: 0001-KVM-MMU-Move-kvm_free_some_pages-into-critical-s.patch --]
[-- Type: text/x-patch, Size: 3446 bytes --]
>From 53015fc9df345a58f96375e082083a108eaaf1da Mon Sep 17 00:00:00 2001
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Date: Mon, 31 Dec 2007 15:27:49 +0200
Subject: [PATCH] KVM: MMU: Move kvm_free_some_pages() into critical section
If some other cpu steals mmu pages between our check and an attempt to
allocate, we can run out of mmu pages. Fix by moving the check into the
same critical section as the allocation.
Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
---
arch/x86/kvm/mmu.c | 9 +++------
arch/x86/kvm/paging_tmpl.h | 1 +
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 356e361..1e6d928 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -291,7 +291,6 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
{
int r;
- kvm_mmu_free_some_pages(vcpu);
r = mmu_topup_memory_cache(&vcpu->arch.mmu_pte_chain_cache,
pte_chain_cache, 4);
if (r)
@@ -569,9 +568,6 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu,
{
struct kvm_mmu_page *sp;
- if (!vcpu->kvm->arch.n_free_mmu_pages)
- return NULL;
-
sp = mmu_memory_cache_alloc(&vcpu->arch.mmu_page_header_cache, sizeof *sp);
sp->spt = mmu_memory_cache_alloc(&vcpu->arch.mmu_page_cache, PAGE_SIZE);
sp->gfns = mmu_memory_cache_alloc(&vcpu->arch.mmu_page_cache, PAGE_SIZE);
@@ -1025,6 +1021,7 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t 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);
return r;
@@ -1273,6 +1270,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu)
if (r)
goto out;
spin_lock(&vcpu->kvm->mmu_lock);
+ kvm_mmu_free_some_pages(vcpu);
mmu_alloc_roots(vcpu);
spin_unlock(&vcpu->kvm->mmu_lock);
kvm_x86_ops->set_cr3(vcpu, vcpu->arch.mmu.root_hpa);
@@ -1414,6 +1412,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
pgprintk("%s: gpa %llx bytes %d\n", __FUNCTION__, gpa, bytes);
mmu_guess_page_from_pte_write(vcpu, gpa, new, bytes);
spin_lock(&vcpu->kvm->mmu_lock);
+ kvm_mmu_free_some_pages(vcpu);
++vcpu->kvm->stat.mmu_pte_write;
kvm_mmu_audit(vcpu, "pre pte write");
if (gfn == vcpu->arch.last_pt_write_gfn
@@ -1506,7 +1505,6 @@ int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
{
- spin_lock(&vcpu->kvm->mmu_lock);
while (vcpu->kvm->arch.n_free_mmu_pages < KVM_REFILL_PAGES) {
struct kvm_mmu_page *sp;
@@ -1515,7 +1513,6 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
kvm_mmu_zap_page(vcpu->kvm, sp);
++vcpu->kvm->stat.mmu_recycled;
}
- spin_unlock(&vcpu->kvm->mmu_lock);
}
int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 73ff66b..6208325 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -404,6 +404,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
up_read(¤t->mm->mmap_sem);
spin_lock(&vcpu->kvm->mmu_lock);
+ kvm_mmu_free_some_pages(vcpu);
shadow_pte = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
&write_pt, page);
pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __FUNCTION__,
--
1.5.3.7
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
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/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
prev parent reply other threads:[~2007-12-31 13:39 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
2007-12-31 13:39 ` Avi Kivity [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=4778F12E.8040001@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=mtosatti-H+wXaHxf7aLQT0dZR+AlfA@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox