aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2009-12-23 11:35:17 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2010-03-01 10:35:43 -0500
commitfef9cce0eb28a67e688a411cc30b73625e49002b (patch)
tree280de299475453abda51e403f284194fb6e78710 /arch/x86/kvm/x86.c
parent46a26bf55714c1e2f17e34683292a389acb8e601 (diff)
KVM: modify alias layout in x86s struct kvm_arch
Have a pointer to an allocated region inside x86's kvm_arch. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c21
1 files changed, 16 insertions, 5 deletions
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