From: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
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
Date: Mon, 6 Dec 2010 01:13:54 +0900 [thread overview]
Message-ID: <20101206011354.1321d3fa.takuya.yoshikawa@gmail.com> (raw)
In-Reply-To: <20101206011133.e5487868.takuya.yoshikawa@gmail.com>
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Index calculation to access lpage_info appears three times.
A helper is worthwhile.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/mmu.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
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);
--
1.7.1
next prev parent reply other threads:[~2010-12-05 16:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-05 16:11 [PATCH 1/2 rebased] KVM: MMU: Avoid dropping accessed bit while removing write access Takuya Yoshikawa
2010-12-05 16:13 ` Takuya Yoshikawa [this message]
2010-12-06 6:37 ` [PATCH 2/2 rebased] KVM: MMU: Introduce a helper to access lpage_info Xiao Guangrong
2010-12-06 7:55 ` Takuya Yoshikawa
2010-12-06 8:57 ` Takuya Yoshikawa
2010-12-06 13:07 ` Avi Kivity
2010-12-07 3:59 ` [PATCH 2/2 v2] KVM: MMU: Make the way of accessing lpage_info more generic Takuya Yoshikawa
2010-12-07 13:55 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101206011354.1321d3fa.takuya.yoshikawa@gmail.com \
--to=takuya.yoshikawa@gmail.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=yoshikawa.takuya@oss.ntt.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox