From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH 5/7] KVM: MMU: Add validate_indirect_spte() helper Date: Mon, 12 Jul 2010 13:12:33 +0800 Message-ID: <4C3AA441.2090002@cn.fujitsu.com> References: <1278862955-6890-1-git-send-email-avi@redhat.com> <1278862955-6890-6-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:64882 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751603Ab0GLFQc (ORCPT ); Mon, 12 Jul 2010 01:16:32 -0400 In-Reply-To: <1278862955-6890-6-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Avi Kivity wrote: > Move the code to validate an indirect shadow page (by verifying that the gpte > has not changed since it was fetched) into a helper. > > Signed-off-by: Avi Kivity > --- > arch/x86/kvm/paging_tmpl.h | 29 ++++++++++++++++++++--------- > 1 files changed, 20 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h > index cacb4f2..72f54fe 100644 > --- a/arch/x86/kvm/paging_tmpl.h > +++ b/arch/x86/kvm/paging_tmpl.h > @@ -299,6 +299,23 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, > gpte_to_gfn(gpte), pfn, true, true); > } > > +static bool FNAME(validate_indirect_spte)(struct kvm_vcpu *vcpu, > + u64 *sptep, struct kvm_mmu_page *sp, > + struct guest_walker *gw, int level) > +{ > + int r; > + pt_element_t curr_pte; > + > + r = kvm_read_guest_atomic(vcpu->kvm, > + gw->pte_gpa[level - 2], > + &curr_pte, sizeof(curr_pte)); > + if (r || curr_pte != gw->ptes[level - 2]) { > + kvm_mmu_put_page(sp, sptep); > + return false; I think it's 'level - 1' here for checking 'level''s mapping