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>
This commit is contained in:
Takuya Yoshikawa 2012-02-08 12:59:10 +09:00 committed by Avi Kivity
parent 9eed0735ca
commit fb03cb6f44
3 changed files with 9 additions and 8 deletions

View file

@ -784,15 +784,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]));