From patchwork Thu Jun 11 14:02:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 29561 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 n5BE5Tbm023312 for ; Thu, 11 Jun 2009 14:05:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751851AbZFKOFZ (ORCPT ); Thu, 11 Jun 2009 10:05:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751636AbZFKOFZ (ORCPT ); Thu, 11 Jun 2009 10:05:25 -0400 Received: from mx2.redhat.com ([66.187.237.31]:55347 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751302AbZFKOFX (ORCPT ); Thu, 11 Jun 2009 10:05:23 -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 n5BE5Q5C026889 for ; Thu, 11 Jun 2009 10:05:26 -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 n5BE5Okr023731; Thu, 11 Jun 2009 10:05:25 -0400 Received: from amt.cnet (vpn-10-91.str.redhat.com [10.32.10.91]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5BE5MJ9021773; Thu, 11 Jun 2009 10:05:23 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7CBD2275009; Thu, 11 Jun 2009 11:04:57 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n5BE4uUK005930; Thu, 11 Jun 2009 11:04:56 -0300 Message-Id: <20090611140416.759106501@localhost.localdomain> References: <20090611140224.457657937@localhost.localdomain> In-Reply-To: <4A307819.6010503@redhat.com> User-Agent: quilt/0.46-1 Date: Thu, 11 Jun 2009 11:02:27 -0300 From: Marcelo Tosatti To: avi@redhat.com Cc: kvm@vger.kernel.org, Marcelo Tosatti Subject: [patch 3/5] KVM: MMU: add kvm_mmu_get_spte_hierarchy helper 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 Index: kvm/arch/x86/kvm/mmu.c =================================================================== --- kvm.orig/arch/x86/kvm/mmu.c +++ kvm/arch/x86/kvm/mmu.c @@ -3013,6 +3013,24 @@ out: return r; } +int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes[4]) +{ + struct kvm_shadow_walk_iterator iterator; + int nr_sptes = 0; + + spin_lock(&vcpu->kvm->mmu_lock); + for_each_shadow_entry(vcpu, addr, iterator) { + sptes[iterator.level-1] = iterator.sptep; + nr_sptes++; + if (!is_shadow_present_pte(*iterator.sptep)) + break; + } + spin_unlock(&vcpu->kvm->mmu_lock); + + return nr_sptes; +} +EXPORT_SYMBOL_GPL(kvm_mmu_get_spte_hierarchy); + #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,8 @@ #define PT32_ROOT_LEVEL 2 #define PT32E_ROOT_LEVEL 3 +int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes[4]); + 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))