aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>2012-02-07 22:59:10 -0500
committerAvi Kivity <avi@redhat.com>2012-03-08 07:10:19 -0500
commitfb03cb6f44236f4bef62a0dda8e025ff5ca51417 (patch)
treefdece464add97210435bb4d778f7b09a852f61e3
parent9eed0735ca6a5cf386a4998ad4b6d52d1e29353f (diff)
KVM: Introduce gfn_to_index() which returns the index for a given level
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> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--arch/x86/kvm/mmu.c3
-rw-r--r--include/linux/kvm_host.h7
-rw-r--r--virt/kvm/kvm_main.c7
3 files changed, 9 insertions, 8 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index ae76cc3392e1..37e7f100a0e0 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,
688{ 688{
689 unsigned long idx; 689 unsigned long idx;
690 690
691 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - 691 idx = gfn_to_index(gfn, slot->base_gfn, level);
692 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
693 return &slot->lpage_info[level - 2][idx]; 692 return &slot->lpage_info[level - 2][idx];
694} 693}
695 694
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9698080c902b..7a08496b974a 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -681,6 +681,13 @@ static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
681 return gfn_to_memslot(kvm, gfn)->id; 681 return gfn_to_memslot(kvm, gfn)->id;
682} 682}
683 683
684static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
685{
686 /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
687 return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
688 (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
689}
690
684static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, 691static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot,
685 gfn_t gfn) 692 gfn_t gfn)
686{ 693{
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 470e30520fe8..415fe816fc15 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -784,15 +784,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
784 int lpages; 784 int lpages;
785 int level = i + 2; 785 int level = i + 2;
786 786
787 /* Avoid unused variable warning if no large pages */
788 (void)level;
789
790 if (new.lpage_info[i]) 787 if (new.lpage_info[i])
791 continue; 788 continue;
792 789
793 lpages = 1 + ((base_gfn + npages - 1) 790 lpages = gfn_to_index(base_gfn + npages - 1, base_gfn, level) + 1;
794 >> KVM_HPAGE_GFN_SHIFT(level));
795 lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level);
796 791
797 new.lpage_info[i] = vzalloc(lpages * sizeof(*new.lpage_info[i])); 792 new.lpage_info[i] = vzalloc(lpages * sizeof(*new.lpage_info[i]));
798 793