From patchwork Tue Jun 9 21:30:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 29096 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n59LZ3BG016078 for ; Tue, 9 Jun 2009 21:35:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755953AbZFIVe6 (ORCPT ); Tue, 9 Jun 2009 17:34:58 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756863AbZFIVe5 (ORCPT ); Tue, 9 Jun 2009 17:34:57 -0400 Received: from mx2.redhat.com ([66.187.237.31]:42290 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756790AbZFIVe4 (ORCPT ); Tue, 9 Jun 2009 17:34:56 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n59LYwkf014209; Tue, 9 Jun 2009 17:34:58 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n59LYvQv001275; Tue, 9 Jun 2009 17:34:57 -0400 Received: from amt.cnet (vpn-10-71.str.redhat.com [10.32.10.71]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n59LYt0M020568; Tue, 9 Jun 2009 17:34:56 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 98AB1274FD5; Tue, 9 Jun 2009 18:34:20 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n59LYI0I002992; Tue, 9 Jun 2009 18:34:18 -0300 Message-Id: <20090609213312.838419569@amt.cnet> User-Agent: quilt/0.47-1 Date: Tue, 09 Jun 2009 18:30:12 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: avi@redhat.com, sheng.yang@intel.com, Marcelo Tosatti Subject: [patch 3/5] KVM: MMU: add kvm_mmu_shadow_walk helper References: <20090609213009.436123773@amt.cnet> Content-Disposition: inline; filename=kvm_mmu_walk_shadow X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Required by EPT misconfiguration handler. Signed-off-by: Marcelo Tosatti --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: kvm/arch/x86/kvm/mmu.c =================================================================== --- kvm.orig/arch/x86/kvm/mmu.c +++ kvm/arch/x86/kvm/mmu.c @@ -3013,6 +3013,26 @@ out: return r; } +void kvm_mmu_shadow_walk(struct kvm_vcpu *vcpu, u64 addr, + struct mmu_shadow_walk *walk) +{ + struct kvm_shadow_walk_iterator iterator; + + spin_lock(&vcpu->kvm->mmu_lock); + for_each_shadow_entry(vcpu, addr, iterator) { + int err; + + err = walk->fn(vcpu, iterator.sptep, iterator.level, walk); + if (err) + break; + + if (!is_shadow_present_pte(*iterator.sptep)) + break; + } + spin_unlock(&vcpu->kvm->mmu_lock); +} +EXPORT_SYMBOL(kvm_mmu_shadow_walk); + #ifdef AUDIT static const char *audit_msg; Index: kvm/arch/x86/kvm/mmu.h =================================================================== --- kvm.orig/arch/x86/kvm/mmu.h +++ kvm/arch/x86/kvm/mmu.h @@ -37,6 +37,14 @@ #define PT32_ROOT_LEVEL 2 #define PT32E_ROOT_LEVEL 3 +struct mmu_shadow_walk { + int (*fn) (struct kvm_vcpu *vcpu, u64 *sptep, int level, + struct mmu_shadow_walk *walk); +}; + +void kvm_mmu_shadow_walk(struct kvm_vcpu *vcpu, u64 addr, + struct mmu_shadow_walk *walk); + static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu) { if (unlikely(vcpu->kvm->arch.n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))