From patchwork Mon Jun 20 14:34:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 897552 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5KEYX53029941 for ; Mon, 20 Jun 2011 14:34:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755033Ab1FTOeU (ORCPT ); Mon, 20 Jun 2011 10:34:20 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:60619 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755005Ab1FTOeQ (ORCPT ); Mon, 20 Jun 2011 10:34:16 -0400 Received: by pvg12 with SMTP id 12so763640pvg.19 for ; Mon, 20 Jun 2011 07:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding; bh=qRANl4J5lZDRzuAEaA3qyuJ2O2Byfu4PaiJZdam/cOo=; b=eLvtiSg3utfUwYFWqO2c4dTQ3tpiTckJtJY6eyG7x8MsnoyRT4EoPDONPOnE+AN4cO 76ymbDOaiPlchuhM096fkCVK0StoEjJaGOIs0+uKIxuHUv1YDNceEq1nvfcmlwYlcKwu hIE2omfQeETwg8AjSzcvoNhuemn+TPr6APKr4= DomainKey-Signature: a=rsa-sha1; c=nofws; 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; b=B6Y+IGs4s5uFe/aCSNnMY0ps8vsseNUSqzW0s43PqEgIVL40JmItwEzm+jL4xw4yZl opUImPIHohSr0QWVWmM9/z/bhrsmb77ar49lY6Zw1noWQiT756dzpOjTWseJ/6TouN4J soo5p1KDGlTrQJnqkdBXoBevPwSPnXgRPL5Ts= Received: by 10.68.30.36 with SMTP id p4mr2103837pbh.308.1308580456164; Mon, 20 Jun 2011 07:34:16 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id i7sm3148409pbj.42.2011.06.20.07.34.13 (version=SSLv3 cipher=OTHER); Mon, 20 Jun 2011 07:34:15 -0700 (PDT) Date: Mon, 20 Jun 2011 23:34:12 +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 v3 3/3] KVM: MMU: Introduce is_last_gpte() to clean up walk_addr_generic() Message-Id: <20110620233412.ab1b056e.takuya.yoshikawa@gmail.com> In-Reply-To: <20110620232947.83d016d3.takuya.yoshikawa@gmail.com> References: <20110620232947.83d016d3.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 (demeter1.kernel.org [140.211.167.41]); Mon, 20 Jun 2011 14:34:34 +0000 (UTC) From: Takuya Yoshikawa Suggested by Ingo and Avi. Cc: Ingo Molnar Signed-off-by: Takuya Yoshikawa --- v2-v3: dropped set_accessed_bit() 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 92fe275..e9243c8 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 */ @@ -232,13 +250,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;