From patchwork Thu Jun 18 19:37:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 31232 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 n5IJcHde004786 for ; Thu, 18 Jun 2009 19:38:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753772AbZFRTiL (ORCPT ); Thu, 18 Jun 2009 15:38:11 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754176AbZFRTiK (ORCPT ); Thu, 18 Jun 2009 15:38:10 -0400 Received: from mx2.redhat.com ([66.187.237.31]:34275 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751068AbZFRTiI (ORCPT ); Thu, 18 Jun 2009 15:38:08 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5IJcBZu008347 for ; Thu, 18 Jun 2009 15:38:11 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5IJcAjE026463; Thu, 18 Jun 2009 15:38:10 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5IJc9ng030668; Thu, 18 Jun 2009 15:38:10 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 2/5] qemu-kvm.c memory cleanup Date: Thu, 18 Jun 2009 15:37:55 -0400 Message-Id: <1245353878-13512-3-git-send-email-glommer@redhat.com> In-Reply-To: <1245353878-13512-2-git-send-email-glommer@redhat.com> References: <1245353878-13512-1-git-send-email-glommer@redhat.com> <1245353878-13512-2-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that libkvm is merged into this file, there is a lot of things we don't need. kvm_create_phys_mem() is only used by user/ files, and so can be removed from this implementation. kvm_cpu_register_physical_memory() morphs into kvm_set_phys_mem(), and uses qemu types. Signed-off-by: Glauber Costa --- qemu-kvm.c | 70 +---------------------------------------------------------- qemu-kvm.h | 16 +------------ 2 files changed, 4 insertions(+), 82 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index a2131b7..d061e0a 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -534,52 +534,6 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem) } -void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len, int log, int writable) -{ - int r; - int prot = PROT_READ; - void *ptr; - struct kvm_userspace_memory_region memory = { - .memory_size = len, - .guest_phys_addr = phys_start, - .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0, - }; - - if (writable) - prot |= PROT_WRITE; - -#if !defined(__s390__) - ptr = mmap(NULL, len, prot, MAP_ANONYMOUS | MAP_SHARED, -1, 0); -#else - ptr = mmap(LIBKVM_S390_ORIGIN, len, prot | PROT_EXEC, - MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, -1, 0); -#endif - if (ptr == MAP_FAILED) { - fprintf(stderr, "%s: %s", __func__, strerror(errno)); - return 0; - } - - memset(ptr, 0, len); - - memory.userspace_addr = (unsigned long)ptr; - memory.slot = get_free_slot(kvm); - DPRINTF("slot %d start %llx len %llx flags %x\n", - memory.slot, - memory.guest_phys_addr, - memory.memory_size, - memory.flags); - r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory); - if (r == -1) { - fprintf(stderr, "%s: %s", __func__, strerror(errno)); - return 0; - } - register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size, - memory.userspace_addr, memory.flags); - - return ptr; -} - int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start, void *userspace_addr, unsigned long len, int log) @@ -2427,9 +2381,8 @@ static void drop_mapping(target_phys_addr_t start_addr) } #endif -void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr, - unsigned long size, - unsigned long phys_offset) +void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size, + ram_addr_t phys_offset) { int r = 0; unsigned long area_flags; @@ -2506,13 +2459,6 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr, return; } -void kvm_cpu_unregister_physical_memory(target_phys_addr_t start_addr, - target_phys_addr_t size, - unsigned long phys_offset) -{ - kvm_unregister_memory_area(kvm_context, start_addr, size); -} - int kvm_setup_guest_memory(void *area, unsigned long size) { int ret = 0; @@ -2834,18 +2780,6 @@ int qemu_kvm_get_dirty_pages(unsigned long phys_addr, void *buf) return kvm_get_dirty_pages(kvm_context, phys_addr, buf); } -void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, - unsigned long size, int log, int writable) -{ - return kvm_create_phys_mem(kvm_context, start_addr, size, log, writable); -} - -void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr, - unsigned long size) -{ - kvm_destroy_phys_mem(kvm_context, start_addr, size); -} - void kvm_mutex_unlock(void) { assert(!cpu_single_env); diff --git a/qemu-kvm.h b/qemu-kvm.h index 68a5b40..c51566c 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -46,12 +46,8 @@ void qemu_kvm_cpuid_on_env(CPUState *env); void kvm_inject_interrupt(CPUState *env, int mask); void kvm_update_after_sipi(CPUState *env); void kvm_update_interrupt_request(CPUState *env); -void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr, - unsigned long size, - unsigned long phys_offset); -void kvm_cpu_unregister_physical_memory(target_phys_addr_t start_addr, - target_phys_addr_t size, - unsigned long phys_offset); +void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size, + ram_addr_t phys_offset); void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size, int log, int writable); @@ -195,14 +191,6 @@ static inline void kvm_sleep_end(void) kvm_mutex_lock(); } -static inline void kvm_set_phys_mem(target_phys_addr_t start_addr, - ram_addr_t size, - ram_addr_t phys_offset) -{ - kvm_cpu_register_physical_memory(start_addr, size, phys_offset); -} - - int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_addr_t end_addr); int kvm_log_start(target_phys_addr_t phys_addr, target_phys_addr_t len);