aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2009-06-19 09:16:23 -0400
committerAvi Kivity <avi@redhat.com>2009-09-10 01:33:02 -0400
commitec04b2604c3707a46db1d26d98f82b11d0844669 (patch)
treea7332c98d61b08b95ff4dc769f87c5861845ffe5 /arch
parentf340ca0f065ecf3e7549687e763370106dacb2c2 (diff)
KVM: Prepare memslot data structures for multiple hugepage sizes
[avi: fix build on non-x86] Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/ia64/include/asm/kvm_host.h3
-rw-r--r--arch/powerpc/include/asm/kvm_host.h3
-rw-r--r--arch/s390/include/asm/kvm_host.h6
-rw-r--r--arch/x86/include/asm/kvm_host.h12
-rw-r--r--arch/x86/kvm/mmu.c30
-rw-r--r--arch/x86/kvm/paging_tmpl.h3
6 files changed, 33 insertions, 24 deletions
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index 9cf1c4b1f92..d9b6325a932 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -235,7 +235,8 @@ 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_PAGES_PER_HPAGE 1 238#define KVM_NR_PAGE_SIZES 1
239#define KVM_PAGES_PER_HPAGE(x) 1
239 240
240struct kvm; 241struct kvm;
241struct kvm_vcpu; 242struct kvm_vcpu;
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index d4caa6127f5..c9c930ed11d 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -34,7 +34,8 @@
34#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 34#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
35 35
36/* We don't currently support large pages. */ 36/* We don't currently support large pages. */
37#define KVM_PAGES_PER_HPAGE (1UL << 31) 37#define KVM_NR_PAGE_SIZES 1
38#define KVM_PAGES_PER_HPAGE(x) (1UL<<31)
38 39
39struct kvm; 40struct kvm;
40struct kvm_run; 41struct kvm_run;
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 75535d4d7a0..78e07a622b4 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -40,7 +40,11 @@ struct sca_block {
40 struct sca_entry cpu[64]; 40 struct sca_entry cpu[64];
41} __attribute__((packed)); 41} __attribute__((packed));
42 42
43#define KVM_PAGES_PER_HPAGE 256 43#define KVM_NR_PAGE_SIZES 2
44#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + ((x) - 1) * 8)
45#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
46#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
47#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
44 48
45#define CPUSTAT_HOST 0x80000000 49#define CPUSTAT_HOST 0x80000000
46#define CPUSTAT_WAIT 0x10000000 50#define CPUSTAT_WAIT 0x10000000
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 19027ab2041..30b625d8e5f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -54,12 +54,12 @@
54#define INVALID_PAGE (~(hpa_t)0) 54#define INVALID_PAGE (~(hpa_t)0)
55#define UNMAPPED_GVA (~(gpa_t)0) 55#define UNMAPPED_GVA (~(gpa_t)0)
56 56
57/* shadow tables are PAE even on non-PAE hosts */ 57/* KVM Hugepage definitions for x86 */
58#define KVM_HPAGE_SHIFT 21 58#define KVM_NR_PAGE_SIZES 2
59#define KVM_HPAGE_SIZE (1UL << KVM_HPAGE_SHIFT) 59#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + (((x) - 1) * 9))
60#define KVM_HPAGE_MASK (~(KVM_HPAGE_SIZE - 1)) 60#define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
61 61#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
62#define KVM_PAGES_PER_HPAGE (KVM_HPAGE_SIZE / PAGE_SIZE) 62#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
63 63
64#define DE_VECTOR 0 64#define DE_VECTOR 0
65#define DB_VECTOR 1 65#define DB_VECTOR 1
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 12974de88aa..b67585c1ef0 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -394,9 +394,9 @@ static int *slot_largepage_idx(gfn_t gfn, struct kvm_memory_slot *slot)
394{ 394{
395 unsigned long idx; 395 unsigned long idx;
396 396
397 idx = (gfn / KVM_PAGES_PER_HPAGE) - 397 idx = (gfn / KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL)) -
398 (slot->base_gfn / KVM_PAGES_PER_HPAGE); 398 (slot->base_gfn / KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL));
399 return &slot->lpage_info[idx].write_count; 399 return &slot->lpage_info[0][idx].write_count;
400} 400}
401 401
402static void account_shadowed(struct kvm *kvm, gfn_t gfn) 402static void account_shadowed(struct kvm *kvm, gfn_t gfn)
@@ -485,10 +485,10 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int lpage)
485 if (!lpage) 485 if (!lpage)
486 return &slot->rmap[gfn - slot->base_gfn]; 486 return &slot->rmap[gfn - slot->base_gfn];
487 487
488 idx = (gfn / KVM_PAGES_PER_HPAGE) - 488 idx = (gfn / KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL)) -
489 (slot->base_gfn / KVM_PAGES_PER_HPAGE); 489 (slot->base_gfn / KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL));
490 490
491 return &slot->lpage_info[idx].rmap_pde; 491 return &slot->lpage_info[0][idx].rmap_pde;
492} 492}
493 493
494/* 494/*
@@ -731,11 +731,11 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
731 end = start + (memslot->npages << PAGE_SHIFT); 731 end = start + (memslot->npages << PAGE_SHIFT);
732 if (hva >= start && hva < end) { 732 if (hva >= start && hva < end) {
733 gfn_t gfn_offset = (hva - start) >> PAGE_SHIFT; 733 gfn_t gfn_offset = (hva - start) >> PAGE_SHIFT;
734 int idx = gfn_offset /
735 KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL);
734 retval |= handler(kvm, &memslot->rmap[gfn_offset]); 736 retval |= handler(kvm, &memslot->rmap[gfn_offset]);
735 retval |= handler(kvm, 737 retval |= handler(kvm,
736 &memslot->lpage_info[ 738 &memslot->lpage_info[0][idx].rmap_pde);
737 gfn_offset /
738 KVM_PAGES_PER_HPAGE].rmap_pde);
739 } 739 }
740 } 740 }
741 741
@@ -1876,8 +1876,9 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
1876 pfn_t pfn; 1876 pfn_t pfn;
1877 unsigned long mmu_seq; 1877 unsigned long mmu_seq;
1878 1878
1879 if (is_largepage_backed(vcpu, gfn & ~(KVM_PAGES_PER_HPAGE-1))) { 1879 if (is_largepage_backed(vcpu, gfn &
1880 gfn &= ~(KVM_PAGES_PER_HPAGE-1); 1880 ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1))) {
1881 gfn &= ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1);
1881 largepage = 1; 1882 largepage = 1;
1882 } 1883 }
1883 1884
@@ -2082,8 +2083,9 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa,
2082 if (r) 2083 if (r)
2083 return r; 2084 return r;
2084 2085
2085 if (is_largepage_backed(vcpu, gfn & ~(KVM_PAGES_PER_HPAGE-1))) { 2086 if (is_largepage_backed(vcpu, gfn &
2086 gfn &= ~(KVM_PAGES_PER_HPAGE-1); 2087 ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1))) {
2088 gfn &= ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1);
2087 largepage = 1; 2089 largepage = 1;
2088 } 2090 }
2089 mmu_seq = vcpu->kvm->mmu_notifier_seq; 2091 mmu_seq = vcpu->kvm->mmu_notifier_seq;
@@ -2485,7 +2487,7 @@ static void mmu_guess_page_from_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
2485 gfn = (gpte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT; 2487 gfn = (gpte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
2486 2488
2487 if (is_large_pte(gpte) && is_largepage_backed(vcpu, gfn)) { 2489 if (is_large_pte(gpte) && is_largepage_backed(vcpu, gfn)) {
2488 gfn &= ~(KVM_PAGES_PER_HPAGE-1); 2490 gfn &= ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1);
2489 vcpu->arch.update_pte.largepage = 1; 2491 vcpu->arch.update_pte.largepage = 1;
2490 } 2492 }
2491 vcpu->arch.update_pte.mmu_seq = vcpu->kvm->mmu_notifier_seq; 2493 vcpu->arch.update_pte.mmu_seq = vcpu->kvm->mmu_notifier_seq;
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 322e8113aee..53e129cec5f 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -401,7 +401,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
401 401
402 if (walker.level == PT_DIRECTORY_LEVEL) { 402 if (walker.level == PT_DIRECTORY_LEVEL) {
403 gfn_t large_gfn; 403 gfn_t large_gfn;
404 large_gfn = walker.gfn & ~(KVM_PAGES_PER_HPAGE-1); 404 large_gfn = walker.gfn &
405 ~(KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL) - 1);
405 if (is_largepage_backed(vcpu, large_gfn)) { 406 if (is_largepage_backed(vcpu, large_gfn)) {
406 walker.gfn = large_gfn; 407 walker.gfn = large_gfn;
407 largepage = 1; 408 largepage = 1;