From patchwork Mon Sep 21 23:37:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 49135 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8LNgW1G002824 for ; Mon, 21 Sep 2009 23:42:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754534AbZIUXmZ (ORCPT ); Mon, 21 Sep 2009 19:42:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754431AbZIUXmY (ORCPT ); Mon, 21 Sep 2009 19:42:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38524 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754511AbZIUXmV (ORCPT ); Mon, 21 Sep 2009 19:42:21 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8LNgPL9005205 for ; Mon, 21 Sep 2009 19:42:25 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8LNgO0u022233; Mon, 21 Sep 2009 19:42:25 -0400 Received: from amt.cnet (vpn-10-8.str.redhat.com [10.32.10.8]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n8LNgLCe029410; Mon, 21 Sep 2009 19:42:23 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id E5FB5588070; Mon, 21 Sep 2009 20:41:49 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n8LNflDI028219; Mon, 21 Sep 2009 20:41:47 -0300 Message-Id: <20090921234124.120057342@amt.cnet> User-Agent: quilt/0.47-1 Date: Mon, 21 Sep 2009 20:37:13 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: avi@redhat.com, Marcelo Tosatti Subject: [patch 02/10] KVM: modify alias layout in x86s struct kvm_arch References: <20090921233711.213665413@amt.cnet> Content-Disposition: inline; filename=modify-alias-layout X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Have a pointer to an allocated region inside x86's kvm_arch. Signed-off-by: Marcelo Tosatti --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: kvm-slotslock/arch/x86/include/asm/kvm_host.h =================================================================== --- kvm-slotslock.orig/arch/x86/include/asm/kvm_host.h +++ kvm-slotslock/arch/x86/include/asm/kvm_host.h @@ -379,9 +379,13 @@ struct kvm_mem_alias { gfn_t target_gfn; }; -struct kvm_arch{ - int naliases; +struct kvm_mem_aliases { struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; + int naliases; +}; + +struct kvm_arch { + struct kvm_mem_aliases *aliases; unsigned int n_free_mmu_pages; unsigned int n_requested_mmu_pages; Index: kvm-slotslock/arch/x86/kvm/x86.c =================================================================== --- kvm-slotslock.orig/arch/x86/kvm/x86.c +++ kvm-slotslock/arch/x86/kvm/x86.c @@ -1959,9 +1959,10 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t { int i; struct kvm_mem_alias *alias; + struct kvm_mem_aliases *aliases = kvm->arch.aliases; - for (i = 0; i < kvm->arch.naliases; ++i) { - alias = &kvm->arch.aliases[i]; + for (i = 0; i < aliases->naliases; ++i) { + alias = &aliases->aliases[i]; if (gfn >= alias->base_gfn && gfn < alias->base_gfn + alias->npages) return alias->target_gfn + gfn - alias->base_gfn; @@ -1979,6 +1980,7 @@ static int kvm_vm_ioctl_set_memory_alias { int r, n; struct kvm_mem_alias *p; + struct kvm_mem_aliases *aliases; r = -EINVAL; /* General sanity checks */ @@ -1998,15 +2000,17 @@ static int kvm_vm_ioctl_set_memory_alias down_write(&kvm->slots_lock); spin_lock(&kvm->mmu_lock); - p = &kvm->arch.aliases[alias->slot]; + aliases = kvm->arch.aliases; + + p = &aliases->aliases[alias->slot]; p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; p->npages = alias->memory_size >> PAGE_SHIFT; p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; for (n = KVM_ALIAS_SLOTS; n > 0; --n) - if (kvm->arch.aliases[n - 1].npages) + if (aliases->aliases[n - 1].npages) break; - kvm->arch.naliases = n; + aliases->naliases = n; spin_unlock(&kvm->mmu_lock); kvm_mmu_zap_all(kvm); @@ -4780,6 +4784,12 @@ struct kvm *kvm_arch_create_vm(void) if (!kvm) return ERR_PTR(-ENOMEM); + kvm->arch.aliases = kzalloc(sizeof(struct kvm_mem_aliases), GFP_KERNEL); + if (!kvm->arch.aliases) { + kfree(kvm); + return ERR_PTR(-ENOMEM); + } + INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); @@ -4836,6 +4846,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm put_page(kvm->arch.apic_access_page); if (kvm->arch.ept_identity_pagetable) put_page(kvm->arch.ept_identity_pagetable); + kfree(kvm->arch.aliases); kfree(kvm); }