From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtIcG-0002CG-Ac for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YtIcF-000177-42 for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:40 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:36286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtIcE-00016v-Tg for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:39 -0400 Received: by wizk4 with SMTP id k4so294138010wiz.1 for ; Fri, 15 May 2015 09:37:38 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 15 May 2015 18:37:00 +0200 Message-Id: <1431707823-51230-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1431707823-51230-1-git-send-email-pbonzini@redhat.com> References: <1431707823-51230-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 4/7] kvm-all: add KVM address space List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, lersek@redhat.com, avi.kivity@gmail.com, kraxel@redhat.com Until now, KVM_SET_USER_MEMORY_REGION has been working on address_space_memory. However, KVM's memory slots are the CPU view of the memory, which does not exactly match address_space_memory. Let the architecture-specific code build the CPU view of the memory by combining address_space_memory and other MemoryRegions. Signed-off-by: Paolo Bonzini --- include/sysemu/kvm_int.h | 3 +++ kvm-all.c | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index d5f746f..5e4090d 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -60,6 +60,9 @@ struct KVMState QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE]; bool direct_msi; #endif + + AddressSpace kvm_as; + MemoryRegion kvm_as_root, kvm_as_mem; }; #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") diff --git a/kvm-all.c b/kvm-all.c index 215ed33..c70436e 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1401,6 +1401,7 @@ static int kvm_init(MachineState *ms) const char *kvm_type; s = KVM_STATE(ms->accelerator); + kvm_state = s; /* * On systems where the kernel can support different base page @@ -1578,9 +1579,21 @@ static int kvm_init(MachineState *ms) kvm_vm_attributes_allowed = (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES) > 0); + /* An outer container, with normal system memory inside. + * kvm_arch_init can add more. + */ + memory_region_init(&s->kvm_as_root, OBJECT(s), "mem-container", ~0ull); + memory_region_set_enabled(&s->kvm_as_root, true); + memory_region_init_alias(&s->kvm_as_mem, OBJECT(s), "memory", + get_system_memory(), 0, ~0ull); + memory_region_set_enabled(&s->kvm_as_mem, true); + memory_region_add_subregion_overlap(&s->kvm_as_root, 0, &s->kvm_as_mem, 0); + + address_space_init(&s->kvm_as, &s->kvm_as_root, "KVM"); + ret = kvm_arch_init(ms, s); if (ret < 0) { - goto err; + goto err_as_destroy; } ret = kvm_irqchip_create(ms, s); @@ -1588,8 +1601,7 @@ static int kvm_init(MachineState *ms) goto err; } - kvm_state = s; - memory_listener_register(&kvm_memory_listener, &address_space_memory); + memory_listener_register(&kvm_memory_listener, &s->kvm_as); memory_listener_register(&kvm_io_listener, &address_space_io); s->many_ioeventfds = kvm_check_many_ioeventfds(); @@ -1598,6 +1610,8 @@ static int kvm_init(MachineState *ms) return 0; +err_as_destroy: + address_space_destroy(&s->kvm_as); err: assert(ret < 0); if (s->vmfd >= 0) { @@ -1607,6 +1621,7 @@ err: close(s->fd); } g_free(s->slots); + kvm_state = NULL; return ret; } -- 1.8.3.1