public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org
Subject: [PATCH 1/4] KVM: Introduce gfn_to_index() which returns the index for a given level
Date: Sun, 29 Jan 2012 21:27:52 +0900	[thread overview]
Message-ID: <20120129212752.b760e974d2bd3fa5531dbbde@gmail.com> (raw)
In-Reply-To: <20120129212630.3986589f898100bbbd312c63@gmail.com>

From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>

This patch cleans up the code and removes the "(void)level;" warning
suppressor.

Note that we can also use this for PT_PAGE_TABLE_LEVEL to treat every
level uniformly later.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
 arch/x86/kvm/mmu.c       |    3 +--
 include/linux/kvm_host.h |    7 +++++++
 virt/kvm/kvm_main.c      |    7 +------
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index ae76cc3..37e7f10 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -688,8 +688,7 @@ static struct kvm_lpage_info *lpage_info_slot(gfn_t gfn,
 {
 	unsigned long idx;
 
-	idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
-	      (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
+	idx = gfn_to_index(gfn, slot->base_gfn, level);
 	return &slot->lpage_info[level - 2][idx];
 }
 
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index eada8e6..06d4e41 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -656,6 +656,13 @@ static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
 	return gfn_to_memslot(kvm, gfn)->id;
 }
 
+static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
+{
+	/* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
+	return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
+		(base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
+}
+
 static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot,
 					       gfn_t gfn)
 {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9f32bff..e483ae4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -797,15 +797,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
 		int lpages;
 		int level = i + 2;
 
-		/* Avoid unused variable warning if no large pages */
-		(void)level;
-
 		if (new.lpage_info[i])
 			continue;
 
-		lpages = 1 + ((base_gfn + npages - 1)
-			     >> KVM_HPAGE_GFN_SHIFT(level));
-		lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level);
+		lpages = gfn_to_index(base_gfn + npages - 1, base_gfn, level) + 1;
 
 		new.lpage_info[i] = vzalloc(lpages * sizeof(*new.lpage_info[i]));
 
-- 
1.7.5.4


  reply	other threads:[~2012-01-29 12:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29 12:26 [PATCH 0/4] KVM: Introduce kvm_memory_slot::arch Takuya Yoshikawa
2012-01-29 12:27 ` Takuya Yoshikawa [this message]
2012-01-29 12:28 ` [PATCH 2/4] KVM: Split lpage_info creation out from __kvm_set_memory_region() Takuya Yoshikawa
2012-01-29 12:30 ` [PATCH 3/4] KVM: Simplify ifndef conditional usage in __kvm_set_memory_region() Takuya Yoshikawa
2012-01-29 16:09   ` Avi Kivity
2012-01-29 12:31 ` [PATCH 4/4] KVM: Introduce kvm_memory_slot::arch and move lpage_info into it Takuya Yoshikawa
  -- strict thread matches above, loose matches on Subject: below --
2012-01-30  3:48 [PATCH 0/4] KVM: Introduce kvm_memory_slot::arch Takuya Yoshikawa
2012-01-30  3:50 ` [PATCH 1/4] KVM: Introduce gfn_to_index() which returns the index for a given level Takuya Yoshikawa
2012-02-08  3:58 [PATCH 0/4 v4] KVM: Introduce kvm_memory_slot::arch Takuya Yoshikawa
2012-02-08  3:59 ` [PATCH 1/4] KVM: Introduce gfn_to_index() which returns the index for a given level Takuya Yoshikawa

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=20120129212752.b760e974d2bd3fa5531dbbde@gmail.com \
    --to=takuya.yoshikawa@gmail.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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