From: Marcelo Tosatti <mtosatti@redhat.com>
To: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Cc: Avi Kivity <avi@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
KVM <kvm@vger.kernel.org>
Subject: Re: [PATCH v2 08/12] KVM: MMU: fast prefetch spte on invlpg path
Date: Tue, 2 Aug 2011 15:36:57 -0300 [thread overview]
Message-ID: <20110802183657.GA6813@amt.cnet> (raw)
In-Reply-To: <4E37DB3E.2040306@cn.fujitsu.com>
On Tue, Aug 02, 2011 at 07:10:54PM +0800, Xiao Guangrong wrote:
> Fast prefetch spte for the unsync shadow page on invlpg path
>
> Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
> ---
> arch/x86/include/asm/kvm_host.h | 3 +--
> arch/x86/kvm/mmu.c | 37 +++++++++++++++----------------------
> arch/x86/kvm/paging_tmpl.h | 23 ++++++++++-------------
> arch/x86/kvm/x86.c | 4 ++--
> 4 files changed, 28 insertions(+), 39 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index b256660..2c08458 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -456,7 +456,6 @@ struct kvm_arch {
> unsigned int n_requested_mmu_pages;
> unsigned int n_max_mmu_pages;
> unsigned int indirect_shadow_pages;
> - atomic_t invlpg_counter;
> struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
> /*
> * Hash table of struct kvm_mmu_page.
> @@ -749,7 +748,7 @@ int fx_init(struct kvm_vcpu *vcpu);
> void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
> void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
> const u8 *new, int bytes,
> - bool guest_initiated, bool page_table_written);
> + bool page_table_written);
> int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
> void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
> int kvm_mmu_load(struct kvm_vcpu *vcpu);
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 8e97ffa..5517115 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -3526,7 +3526,7 @@ static bool last_updated_pte_accessed(struct kvm_vcpu *vcpu)
>
> void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
> const u8 *new, int bytes,
> - bool guest_initiated, bool page_table_written)
> + bool page_table_written)
> {
> gfn_t gfn = gpa >> PAGE_SHIFT;
> union kvm_mmu_page_role mask = { .word = 0 };
> @@ -3535,7 +3535,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
> LIST_HEAD(invalid_list);
> u64 entry, gentry, *spte;
> unsigned pte_size, page_offset, misaligned, quadrant, offset;
> - int level, npte, invlpg_counter, r, flooded = 0;
> + int level, npte, r, flooded = 0;
> bool remote_flush, local_flush, zap_page;
>
> /*
> @@ -3550,19 +3550,16 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
>
> pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
>
> - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
> -
> /*
> * Assume that the pte write on a page table of the same type
> * as the current vcpu paging mode since we update the sptes only
> * when they have the same mode.
> */
> - if ((is_pae(vcpu) && bytes == 4) || !new) {
> + if (is_pae(vcpu) && bytes == 4) {
> /* Handle a 32-bit guest writing two halves of a 64-bit gpte */
> - if (is_pae(vcpu)) {
> - gpa &= ~(gpa_t)7;
> - bytes = 8;
> - }
> + gpa &= ~(gpa_t)7;
> + bytes = 8;
> +
> r = kvm_read_guest(vcpu->kvm, gpa, &gentry, min(bytes, 8));
> if (r)
> gentry = 0;
> @@ -3588,22 +3585,18 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
> */
> mmu_topup_memory_caches(vcpu);
> spin_lock(&vcpu->kvm->mmu_lock);
> - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
> - gentry = 0;
> kvm_mmu_free_some_pages(vcpu);
> ++vcpu->kvm->stat.mmu_pte_write;
> trace_kvm_mmu_audit(vcpu, AUDIT_PRE_PTE_WRITE);
> - if (guest_initiated) {
> - if (gfn == vcpu->arch.last_pt_write_gfn
> - && !last_updated_pte_accessed(vcpu)) {
> - ++vcpu->arch.last_pt_write_count;
> - if (vcpu->arch.last_pt_write_count >= 3)
> - flooded = 1;
> - } else {
> - vcpu->arch.last_pt_write_gfn = gfn;
> - vcpu->arch.last_pt_write_count = 1;
> - vcpu->arch.last_pte_updated = NULL;
> - }
> + if (gfn == vcpu->arch.last_pt_write_gfn
> + && !last_updated_pte_accessed(vcpu)) {
> + ++vcpu->arch.last_pt_write_count;
> + if (vcpu->arch.last_pt_write_count >= 3)
> + flooded = 1;
> + } else {
> + vcpu->arch.last_pt_write_gfn = gfn;
> + vcpu->arch.last_pt_write_count = 1;
> + vcpu->arch.last_pte_updated = NULL;
> }
>
> mask.cr0_wp = mask.cr4_pae = mask.nxe = 1;
> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
> index 0f915b5..3466229 100644
> --- a/arch/x86/kvm/paging_tmpl.h
> +++ b/arch/x86/kvm/paging_tmpl.h
> @@ -666,20 +666,22 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
> {
> struct kvm_shadow_walk_iterator iterator;
> struct kvm_mmu_page *sp;
> - gpa_t pte_gpa = -1;
> int level;
> u64 *sptep;
>
> vcpu_clear_mmio_info(vcpu, gva);
> + mmu_topup_memory_caches(vcpu);
Should handle failure.
next prev parent reply other threads:[~2011-08-02 19:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 11:06 [PATCH v2 01/12] KVM: MMU: avoid pte_list_desc run out in kvm_mmu_pte_write Xiao Guangrong
2011-08-02 11:07 ` [PATCH v2 02/12] KVM: x86: tag the instructions which are used to write page table Xiao Guangrong
2011-08-02 12:20 ` Avi Kivity
2011-08-03 6:02 ` Xiao Guangrong
2011-08-03 8:09 ` Avi Kivity
2011-08-03 9:24 ` Xiao Guangrong
2011-08-03 9:25 ` Avi Kivity
2011-08-03 9:41 ` Xiao Guangrong
2011-08-03 9:40 ` Avi Kivity
2011-08-02 11:08 ` [PATCH v2 03/12] zap sp if it is written by unaware instructions Xiao Guangrong
2011-08-02 11:08 ` [PATCH v2 04/12] KVM: x86: cleanup port-in/port-out emulated Xiao Guangrong
2011-08-02 11:09 ` [PATCH v2 05/12] KVM: x86: fast emulate repeat string write instructions Xiao Guangrong
2011-08-03 8:10 ` Avi Kivity
2011-08-03 9:31 ` Xiao Guangrong
2011-08-02 11:09 ` [PATCH v2 06/12] KVM: MMU: do not mark access bit on pte write path Xiao Guangrong
2011-08-02 11:10 ` [PATCH v2 07/12] KVM: MMU: cleanup FNAME(invlpg) Xiao Guangrong
2011-08-02 11:10 ` [PATCH v2 08/12] KVM: MMU: fast prefetch spte on invlpg path Xiao Guangrong
2011-08-02 18:36 ` Marcelo Tosatti [this message]
2011-08-03 6:03 ` Xiao Guangrong
2011-08-02 11:11 ` [PATCH v2 09/12] KVM: MMU: remove unnecessary kvm_mmu_free_some_pages Xiao Guangrong
2011-08-02 11:11 ` [PATCH v2 10/12] KVM: MMU: split kvm_mmu_pte_write function Xiao Guangrong
2011-08-02 11:12 ` [PATCH v2 11/12] KVM: MMU: fix detecting misaligned accessed Xiao Guangrong
2011-08-02 11:13 ` [PATCH v2 12/12] KVM: MMU: improve write flooding detected Xiao Guangrong
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=20110802183657.GA6813@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiaoguangrong@cn.fujitsu.com \
/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