diff options
author | Zhang Xiantao <xiantao.zhang@intel.com> | 2007-12-13 20:54:20 -0500 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:58:10 -0500 |
commit | d69fb81f0554fb980e4b1d3db4e44351c2c4a4a2 (patch) | |
tree | c2b6f6081ceb31fba9c37401f0cc81afaa3b6d1f | |
parent | 77b4c255af34e73ea1efd1c3384bbe91361c81e6 (diff) |
KVM: Portability: Move memslot aliases to new struct kvm_arch
This patches create kvm_arch to hold arch-specific kvm fileds
and moves fields naliases and aliases to kvm_arch.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | drivers/kvm/kvm.h | 10 | ||||
-rw-r--r-- | drivers/kvm/x86.c | 10 | ||||
-rw-r--r-- | drivers/kvm/x86.h | 13 |
3 files changed, 19 insertions, 14 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index 9ea7149e741d..bf5b85c1f094 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -25,7 +25,6 @@ | |||
25 | #include "x86.h" | 25 | #include "x86.h" |
26 | 26 | ||
27 | #define KVM_MAX_VCPUS 4 | 27 | #define KVM_MAX_VCPUS 4 |
28 | #define KVM_ALIAS_SLOTS 4 | ||
29 | #define KVM_MEMORY_SLOTS 8 | 28 | #define KVM_MEMORY_SLOTS 8 |
30 | /* memory slots that does not exposed to userspace */ | 29 | /* memory slots that does not exposed to userspace */ |
31 | #define KVM_PRIVATE_MEM_SLOTS 4 | 30 | #define KVM_PRIVATE_MEM_SLOTS 4 |
@@ -94,12 +93,6 @@ struct kvm_vcpu { | |||
94 | struct kvm_vcpu_arch arch; | 93 | struct kvm_vcpu_arch arch; |
95 | }; | 94 | }; |
96 | 95 | ||
97 | struct kvm_mem_alias { | ||
98 | gfn_t base_gfn; | ||
99 | unsigned long npages; | ||
100 | gfn_t target_gfn; | ||
101 | }; | ||
102 | |||
103 | struct kvm_memory_slot { | 96 | struct kvm_memory_slot { |
104 | gfn_t base_gfn; | 97 | gfn_t base_gfn; |
105 | unsigned long npages; | 98 | unsigned long npages; |
@@ -123,8 +116,6 @@ struct kvm_vm_stat { | |||
123 | struct kvm { | 116 | struct kvm { |
124 | struct mutex lock; /* protects everything except vcpus */ | 117 | struct mutex lock; /* protects everything except vcpus */ |
125 | struct mm_struct *mm; /* userspace tied to this vm */ | 118 | struct mm_struct *mm; /* userspace tied to this vm */ |
126 | int naliases; | ||
127 | struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; | ||
128 | int nmemslots; | 119 | int nmemslots; |
129 | struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS + | 120 | struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS + |
130 | KVM_PRIVATE_MEM_SLOTS]; | 121 | KVM_PRIVATE_MEM_SLOTS]; |
@@ -147,6 +138,7 @@ struct kvm { | |||
147 | unsigned int tss_addr; | 138 | unsigned int tss_addr; |
148 | struct page *apic_access_page; | 139 | struct page *apic_access_page; |
149 | struct kvm_vm_stat stat; | 140 | struct kvm_vm_stat stat; |
141 | struct kvm_arch arch; | ||
150 | }; | 142 | }; |
151 | 143 | ||
152 | /* The guest did something we don't support. */ | 144 | /* The guest did something we don't support. */ |
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index 60f9722a06ba..7e1bd526bd5c 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c | |||
@@ -1191,8 +1191,8 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) | |||
1191 | int i; | 1191 | int i; |
1192 | struct kvm_mem_alias *alias; | 1192 | struct kvm_mem_alias *alias; |
1193 | 1193 | ||
1194 | for (i = 0; i < kvm->naliases; ++i) { | 1194 | for (i = 0; i < kvm->arch.naliases; ++i) { |
1195 | alias = &kvm->aliases[i]; | 1195 | alias = &kvm->arch.aliases[i]; |
1196 | if (gfn >= alias->base_gfn | 1196 | if (gfn >= alias->base_gfn |
1197 | && gfn < alias->base_gfn + alias->npages) | 1197 | && gfn < alias->base_gfn + alias->npages) |
1198 | return alias->target_gfn + gfn - alias->base_gfn; | 1198 | return alias->target_gfn + gfn - alias->base_gfn; |
@@ -1228,15 +1228,15 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm, | |||
1228 | 1228 | ||
1229 | mutex_lock(&kvm->lock); | 1229 | mutex_lock(&kvm->lock); |
1230 | 1230 | ||
1231 | p = &kvm->aliases[alias->slot]; | 1231 | p = &kvm->arch.aliases[alias->slot]; |
1232 | p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; | 1232 | p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; |
1233 | p->npages = alias->memory_size >> PAGE_SHIFT; | 1233 | p->npages = alias->memory_size >> PAGE_SHIFT; |
1234 | p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; | 1234 | p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; |
1235 | 1235 | ||
1236 | for (n = KVM_ALIAS_SLOTS; n > 0; --n) | 1236 | for (n = KVM_ALIAS_SLOTS; n > 0; --n) |
1237 | if (kvm->aliases[n - 1].npages) | 1237 | if (kvm->arch.aliases[n - 1].npages) |
1238 | break; | 1238 | break; |
1239 | kvm->naliases = n; | 1239 | kvm->arch.naliases = n; |
1240 | 1240 | ||
1241 | kvm_mmu_zap_all(kvm); | 1241 | kvm_mmu_zap_all(kvm); |
1242 | 1242 | ||
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h index 4ca848536365..be84f2b89095 100644 --- a/drivers/kvm/x86.h +++ b/drivers/kvm/x86.h | |||
@@ -54,6 +54,8 @@ | |||
54 | 54 | ||
55 | #define IOPL_SHIFT 12 | 55 | #define IOPL_SHIFT 12 |
56 | 56 | ||
57 | #define KVM_ALIAS_SLOTS 4 | ||
58 | |||
57 | #define KVM_PERMILLE_MMU_PAGES 20 | 59 | #define KVM_PERMILLE_MMU_PAGES 20 |
58 | #define KVM_MIN_ALLOC_MMU_PAGES 64 | 60 | #define KVM_MIN_ALLOC_MMU_PAGES 64 |
59 | #define KVM_NUM_MMU_PAGES 1024 | 61 | #define KVM_NUM_MMU_PAGES 1024 |
@@ -255,6 +257,17 @@ struct kvm_vcpu_arch { | |||
255 | struct x86_emulate_ctxt emulate_ctxt; | 257 | struct x86_emulate_ctxt emulate_ctxt; |
256 | }; | 258 | }; |
257 | 259 | ||
260 | struct kvm_mem_alias { | ||
261 | gfn_t base_gfn; | ||
262 | unsigned long npages; | ||
263 | gfn_t target_gfn; | ||
264 | }; | ||
265 | |||
266 | struct kvm_arch{ | ||
267 | int naliases; | ||
268 | struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; | ||
269 | }; | ||
270 | |||
258 | struct kvm_vcpu_stat { | 271 | struct kvm_vcpu_stat { |
259 | u32 pf_fixed; | 272 | u32 pf_fixed; |
260 | u32 pf_guest; | 273 | u32 pf_guest; |