aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/ia64/include/asm/kvm_host.h1
-rw-r--r--arch/powerpc/include/asm/kvm_host.h1
-rw-r--r--arch/s390/include/asm/kvm_host.h3
-rw-r--r--arch/x86/include/asm/kvm_host.h3
-rw-r--r--arch/x86/kvm/mmu.c8
-rw-r--r--virt/kvm/kvm_main.c10
6 files changed, 15 insertions, 11 deletions
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index a362e67e0ca6..2f229e5de498 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -235,6 +235,7 @@ struct kvm_vm_data {
235#define KVM_REQ_PTC_G 32 235#define KVM_REQ_PTC_G 32
236#define KVM_REQ_RESUME 33 236#define KVM_REQ_RESUME 33
237 237
238#define KVM_HPAGE_GFN_SHIFT(x) 0
238#define KVM_NR_PAGE_SIZES 1 239#define KVM_NR_PAGE_SIZES 1
239#define KVM_PAGES_PER_HPAGE(x) 1 240#define KVM_PAGES_PER_HPAGE(x) 1
240 241
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index e004eafcd3f0..b0b23c007d6e 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -35,6 +35,7 @@
35#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 35#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
36 36
37/* We don't currently support large pages. */ 37/* We don't currently support large pages. */
38#define KVM_HPAGE_GFN_SHIFT(x) 0
38#define KVM_NR_PAGE_SIZES 1 39#define KVM_NR_PAGE_SIZES 1
39#define KVM_PAGES_PER_HPAGE(x) (1UL<<31) 40#define KVM_PAGES_PER_HPAGE(x) (1UL<<31)
40 41
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index b95710a1f5dd..cef7dbf69dfc 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -41,7 +41,8 @@ struct sca_block {
41} __attribute__((packed)); 41} __attribute__((packed));
42 42
43#define KVM_NR_PAGE_SIZES 2 43#define KVM_NR_PAGE_SIZES 2
44#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + ((x) - 1) * 8) 44#define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 8)
45#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
45#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) 46#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
46#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) 47#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
47#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) 48#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 2bda62485c4c..50c79b9f5c38 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -44,7 +44,8 @@
44 44
45/* KVM Hugepage definitions for x86 */ 45/* KVM Hugepage definitions for x86 */
46#define KVM_NR_PAGE_SIZES 3 46#define KVM_NR_PAGE_SIZES 3
47#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + (((x) - 1) * 9)) 47#define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9)
48#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
48#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) 49#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
49#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) 50#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
50#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) 51#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index ca07ed083b59..a20fd613acfe 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -423,8 +423,8 @@ static int *slot_largepage_idx(gfn_t gfn,
423{ 423{
424 unsigned long idx; 424 unsigned long idx;
425 425
426 idx = (gfn / KVM_PAGES_PER_HPAGE(level)) - 426 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
427 (slot->base_gfn / KVM_PAGES_PER_HPAGE(level)); 427 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
428 return &slot->lpage_info[level - 2][idx].write_count; 428 return &slot->lpage_info[level - 2][idx].write_count;
429} 429}
430 430
@@ -528,8 +528,8 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level)
528 if (likely(level == PT_PAGE_TABLE_LEVEL)) 528 if (likely(level == PT_PAGE_TABLE_LEVEL))
529 return &slot->rmap[gfn - slot->base_gfn]; 529 return &slot->rmap[gfn - slot->base_gfn];
530 530
531 idx = (gfn / KVM_PAGES_PER_HPAGE(level)) - 531 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
532 (slot->base_gfn / KVM_PAGES_PER_HPAGE(level)); 532 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
533 533
534 return &slot->lpage_info[level - 2][idx].rmap_pde; 534 return &slot->lpage_info[level - 2][idx].rmap_pde;
535} 535}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ec2e3c6ac7ed..a60b6b053b6f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -626,9 +626,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
626 if (new.lpage_info[i]) 626 if (new.lpage_info[i])
627 continue; 627 continue;
628 628
629 lpages = 1 + (base_gfn + npages - 1) / 629 lpages = 1 + ((base_gfn + npages - 1)
630 KVM_PAGES_PER_HPAGE(level); 630 >> KVM_HPAGE_GFN_SHIFT(level));
631 lpages -= base_gfn / KVM_PAGES_PER_HPAGE(level); 631 lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level);
632 632
633 new.lpage_info[i] = vmalloc(lpages * sizeof(*new.lpage_info[i])); 633 new.lpage_info[i] = vmalloc(lpages * sizeof(*new.lpage_info[i]));
634 634
@@ -638,9 +638,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
638 memset(new.lpage_info[i], 0, 638 memset(new.lpage_info[i], 0,
639 lpages * sizeof(*new.lpage_info[i])); 639 lpages * sizeof(*new.lpage_info[i]));
640 640
641 if (base_gfn % KVM_PAGES_PER_HPAGE(level)) 641 if (base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1))
642 new.lpage_info[i][0].write_count = 1; 642 new.lpage_info[i][0].write_count = 1;
643 if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE(level)) 643 if ((base_gfn+npages) & (KVM_PAGES_PER_HPAGE(level) - 1))
644 new.lpage_info[i][lpages - 1].write_count = 1; 644 new.lpage_info[i][lpages - 1].write_count = 1;
645 ugfn = new.userspace_addr >> PAGE_SHIFT; 645 ugfn = new.userspace_addr >> PAGE_SHIFT;
646 /* 646 /*