From patchwork Sun Dec 5 16:13:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 380981 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oB5GE2p5003726 for ; Sun, 5 Dec 2010 16:14:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756259Ab0LEQN7 (ORCPT ); Sun, 5 Dec 2010 11:13:59 -0500 Received: from mail-gx0-f180.google.com ([209.85.161.180]:44865 "EHLO mail-gx0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756245Ab0LEQN6 (ORCPT ); Sun, 5 Dec 2010 11:13:58 -0500 Received: by gxk19 with SMTP id 19so6112078gxk.11 for ; Sun, 05 Dec 2010 08:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=wubtDN+h5dnYNSMLIrn6yxS8x87F2ySKL3KMpCKSbY0=; b=KDFY6m6MamuJF/vvyaH5oj6R57uwXTxPB0LC+DRSMkb/VQ7awM+hLmyE8LjcHi1FDq N1gbcAjwqm9nBBrVnCoHXC+/dKuWh+PFpFXLC7xPx+qiZ4sLzRbGueeVeaPOFf1ZKKCZ iA3FpVQqqr9j/yh0xdHG8dBcs5DfDs36iRvww= 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=Hen0s1ky/QftPfV9gjbYdi9lV3nMV0YyrK7CWvKvlT02wUfbtHUoxiBC4x31M4hdcE 0jzQ0NQYgKeINjG41eohyFum0DJAFwzDm3AEVkDLoYCn3WyiHIa3VdZ9uxd08GucN1RC AsSBQ9VD3Sdtn3SZZfyp7425uO8AKLVIm6XKc= Received: by 10.100.238.8 with SMTP id l8mr3200160anh.119.1291565638351; Sun, 05 Dec 2010 08:13:58 -0800 (PST) Received: from amd (x097031.dynamic.ppp.asahi-net.or.jp [122.249.97.31]) by mx.google.com with ESMTPS id d15sm4347526ana.35.2010.12.05.08.13.55 (version=SSLv3 cipher=RC4-MD5); Sun, 05 Dec 2010 08:13:57 -0800 (PST) Date: Mon, 6 Dec 2010 01:13:54 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp Subject: [PATCH 2/2 rebased] KVM: MMU: Introduce a helper to access lpage_info Message-Id: <20101206011354.1321d3fa.takuya.yoshikawa@gmail.com> In-Reply-To: <20101206011133.e5487868.takuya.yoshikawa@gmail.com> References: <20101206011133.e5487868.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0beta2 (GTK+ 2.22.0; 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.3 (demeter1.kernel.org [140.211.167.41]); Sun, 05 Dec 2010 16:14:03 +0000 (UTC) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index d75ba1e..e434503 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -476,6 +476,12 @@ static void kvm_mmu_page_set_gfn(struct kvm_mmu_page *sp, int index, gfn_t gfn) sp->gfns[index] = gfn; } +static unsigned long lpage_idx(gfn_t gfn, gfn_t base_gfn, int level) +{ + return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - + (base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); +} + /* * Return the pointer to the largepage write count for a given * gfn, handling slots that are not large page aligned. @@ -484,10 +490,8 @@ static int *slot_largepage_idx(gfn_t gfn, struct kvm_memory_slot *slot, int level) { - unsigned long idx; + unsigned long idx = lpage_idx(gfn, slot->base_gfn, level); - idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - - (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); return &slot->lpage_info[level - 2][idx].write_count; } @@ -591,8 +595,7 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level) if (likely(level == PT_PAGE_TABLE_LEVEL)) return &slot->rmap[gfn - slot->base_gfn]; - idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - - (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); + idx = lpage_idx(gfn, slot->base_gfn, level); return &slot->lpage_info[level - 2][idx].rmap_pde; } @@ -887,11 +890,10 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva, for (j = 0; j < KVM_NR_PAGE_SIZES - 1; ++j) { unsigned long idx; - int sh; - sh = KVM_HPAGE_GFN_SHIFT(PT_DIRECTORY_LEVEL+j); - idx = ((memslot->base_gfn+gfn_offset) >> sh) - - (memslot->base_gfn >> sh); + idx = lpage_idx(memslot->base_gfn + gfn_offset, + memslot->base_gfn, + PT_DIRECTORY_LEVEL + j); ret |= handler(kvm, &memslot->lpage_info[j][idx].rmap_pde, data);