diff options
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 8 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 21 |
2 files changed, 22 insertions, 7 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fe4df464fb39..7cdcb3d0f770 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -370,9 +370,13 @@ struct kvm_mem_alias { | |||
370 | gfn_t target_gfn; | 370 | gfn_t target_gfn; |
371 | }; | 371 | }; |
372 | 372 | ||
373 | struct kvm_arch{ | 373 | struct kvm_mem_aliases { |
374 | int naliases; | ||
375 | struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; | 374 | struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; |
375 | int naliases; | ||
376 | }; | ||
377 | |||
378 | struct kvm_arch { | ||
379 | struct kvm_mem_aliases *aliases; | ||
376 | 380 | ||
377 | unsigned int n_free_mmu_pages; | 381 | unsigned int n_free_mmu_pages; |
378 | unsigned int n_requested_mmu_pages; | 382 | unsigned int n_requested_mmu_pages; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3b81cb9da8b8..1ce833191430 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2227,9 +2227,10 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) | |||
2227 | { | 2227 | { |
2228 | int i; | 2228 | int i; |
2229 | struct kvm_mem_alias *alias; | 2229 | struct kvm_mem_alias *alias; |
2230 | struct kvm_mem_aliases *aliases = kvm->arch.aliases; | ||
2230 | 2231 | ||
2231 | for (i = 0; i < kvm->arch.naliases; ++i) { | 2232 | for (i = 0; i < aliases->naliases; ++i) { |
2232 | alias = &kvm->arch.aliases[i]; | 2233 | alias = &aliases->aliases[i]; |
2233 | if (gfn >= alias->base_gfn | 2234 | if (gfn >= alias->base_gfn |
2234 | && gfn < alias->base_gfn + alias->npages) | 2235 | && gfn < alias->base_gfn + alias->npages) |
2235 | return alias->target_gfn + gfn - alias->base_gfn; | 2236 | return alias->target_gfn + gfn - alias->base_gfn; |
@@ -2247,6 +2248,7 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm, | |||
2247 | { | 2248 | { |
2248 | int r, n; | 2249 | int r, n; |
2249 | struct kvm_mem_alias *p; | 2250 | struct kvm_mem_alias *p; |
2251 | struct kvm_mem_aliases *aliases; | ||
2250 | 2252 | ||
2251 | r = -EINVAL; | 2253 | r = -EINVAL; |
2252 | /* General sanity checks */ | 2254 | /* General sanity checks */ |
@@ -2266,15 +2268,17 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm, | |||
2266 | down_write(&kvm->slots_lock); | 2268 | down_write(&kvm->slots_lock); |
2267 | spin_lock(&kvm->mmu_lock); | 2269 | spin_lock(&kvm->mmu_lock); |
2268 | 2270 | ||
2269 | p = &kvm->arch.aliases[alias->slot]; | 2271 | aliases = kvm->arch.aliases; |
2272 | |||
2273 | p = &aliases->aliases[alias->slot]; | ||
2270 | p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; | 2274 | p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; |
2271 | p->npages = alias->memory_size >> PAGE_SHIFT; | 2275 | p->npages = alias->memory_size >> PAGE_SHIFT; |
2272 | p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; | 2276 | p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; |
2273 | 2277 | ||
2274 | for (n = KVM_ALIAS_SLOTS; n > 0; --n) | 2278 | for (n = KVM_ALIAS_SLOTS; n > 0; --n) |
2275 | if (kvm->arch.aliases[n - 1].npages) | 2279 | if (aliases->aliases[n - 1].npages) |
2276 | break; | 2280 | break; |
2277 | kvm->arch.naliases = n; | 2281 | aliases->naliases = n; |
2278 | 2282 | ||
2279 | spin_unlock(&kvm->mmu_lock); | 2283 | spin_unlock(&kvm->mmu_lock); |
2280 | kvm_mmu_zap_all(kvm); | 2284 | kvm_mmu_zap_all(kvm); |
@@ -5158,6 +5162,12 @@ struct kvm *kvm_arch_create_vm(void) | |||
5158 | if (!kvm) | 5162 | if (!kvm) |
5159 | return ERR_PTR(-ENOMEM); | 5163 | return ERR_PTR(-ENOMEM); |
5160 | 5164 | ||
5165 | kvm->arch.aliases = kzalloc(sizeof(struct kvm_mem_aliases), GFP_KERNEL); | ||
5166 | if (!kvm->arch.aliases) { | ||
5167 | kfree(kvm); | ||
5168 | return ERR_PTR(-ENOMEM); | ||
5169 | } | ||
5170 | |||
5161 | INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); | 5171 | INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); |
5162 | INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); | 5172 | INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); |
5163 | 5173 | ||
@@ -5214,6 +5224,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) | |||
5214 | put_page(kvm->arch.apic_access_page); | 5224 | put_page(kvm->arch.apic_access_page); |
5215 | if (kvm->arch.ept_identity_pagetable) | 5225 | if (kvm->arch.ept_identity_pagetable) |
5216 | put_page(kvm->arch.ept_identity_pagetable); | 5226 | put_page(kvm->arch.ept_identity_pagetable); |
5227 | kfree(kvm->arch.aliases); | ||
5217 | kfree(kvm); | 5228 | kfree(kvm); |
5218 | } | 5229 | } |
5219 | 5230 | ||