From patchwork Thu Jun 30 16:37:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 933022 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5UGbXwn029272 for ; Thu, 30 Jun 2011 16:37:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753099Ab1F3Qha (ORCPT ); Thu, 30 Jun 2011 12:37:30 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:36611 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100Ab1F3Qh3 (ORCPT ); Thu, 30 Jun 2011 12:37:29 -0400 Received: by pzk9 with SMTP id 9so1877810pzk.19 for ; Thu, 30 Jun 2011 09:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; bh=UvPYcuq0MJ8X4EQ5tK9uqS3snyHbXIpne3kLIGcKres=; b=qTMKbfaePFHHjZZXBvOZ25ITkrnLkWr/kLS4WUCMynNXZkSl36POmUIZ0VUfzN+3K/ bSFg5+Agluh6bq//RBwbEv1j8c+Z0cwaSCqQNzfT7zXDc+nTmAxTb45OfQYLpGMobTmJ D8YKdlXpl1Ki9mqUjkjfCHBVCILzHaS52WNs4= Received: by 10.68.50.161 with SMTP id d1mr2655862pbo.439.1309451848947; Thu, 30 Jun 2011 09:37:28 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id u6sm1546930pbh.80.2011.06.30.09.37.26 (version=SSLv3 cipher=OTHER); Thu, 30 Jun 2011 09:37:28 -0700 (PDT) Date: Fri, 1 Jul 2011 01:37:24 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, mingo@elte.hu Subject: [PATCH 3/3] KVM: MMU: Introduce is_last_gpte() to clean up walk_addr_generic() Message-Id: <20110701013724.75362a04.takuya.yoshikawa@gmail.com> In-Reply-To: <20110701013320.977cdfea.takuya.yoshikawa@gmail.com> References: <20110701013320.977cdfea.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 30 Jun 2011 16:37:34 +0000 (UTC) From: Takuya Yoshikawa Suggested by Ingo and Avi. Cc: Ingo Molnar Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/paging_tmpl.h | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 9c0afba..1e1c244 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -113,6 +113,24 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) return access; } +static bool FNAME(is_last_gpte)(struct guest_walker *walker, + struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, + pt_element_t gpte) +{ + if (walker->level == PT_PAGE_TABLE_LEVEL) + return true; + + if ((walker->level == PT_DIRECTORY_LEVEL) && is_large_pte(gpte) && + (PTTYPE == 64 || is_pse(vcpu))) + return true; + + if ((walker->level == PT_PDPE_LEVEL) && is_large_pte(gpte) && + (mmu->root_level == PT64_ROOT_LEVEL)) + return true; + + return false; +} + /* * Fetch a guest pte for a guest virtual address */ @@ -221,13 +239,7 @@ retry_walk: walker->ptes[walker->level - 1] = pte; - if ((walker->level == PT_PAGE_TABLE_LEVEL) || - ((walker->level == PT_DIRECTORY_LEVEL) && - is_large_pte(pte) && - (PTTYPE == 64 || is_pse(vcpu))) || - ((walker->level == PT_PDPE_LEVEL) && - is_large_pte(pte) && - mmu->root_level == PT64_ROOT_LEVEL)) { + if (FNAME(is_last_gpte)(walker, vcpu, mmu, pte)) { int lvl = walker->level; gpa_t real_gpa; gfn_t gfn;