Skip to contentSkip to conversation

Further cleanups to qemu-kvm.c

PATCH Applied Glauber Costa 2 participants 8 messages Jun 18, 2009 – Jun 21, 2009

Subsystems (2)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Further cleanups to qemu-kvm.c

Avi,

This is the patch set that should be applied. It is comprised of
4 patches. It however, depends on "[PATCH 1/5] get rid of target-i386/libkvm.c", so I'm sending it again, since it does not seem to be already applied by you.

Thanks.

#1 lore raw

PATCH v2 1/5 get rid of target-i386/libkvm.c

Same spirit of what has already been done for the generic code. Fold libkvm.c into qemu-kvm-x86.c. handle_tpr_access becomes kvm_handle_tpr_access, to avoid name clash.

---
 Makefile.target      |    2 +-
 qemu-kvm-x86.c       |  652 ++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/libkvm.c |  666 --------------------------------------------------
 3 files changed, 653 insertions(+), 667 deletions(-)
 delete mode 100644 target-i386/libkvm.c
Makefile.target +1 -1
index 6637d9b..08121a9 100644
@@ -162,7 +162,7 @@ CPPFLAGS+=-I$(SRC_PATH)/tcg/sparc
 endif
 
 ifeq ($(USE_KVM), 1)
-LIBOBJS+=qemu-kvm.o libkvm.o
+LIBOBJS+=qemu-kvm.o
 endif
 ifdef CONFIG_SOFTFLOAT
 LIBOBJS+=fpu/softfloat.o
qemu-kvm-x86.c +652 -0

667 lines not on this page · raw message

target-i386/libkvm.c deleted +0 -666

666 lines not on this page · raw message

Signature · 1 line
1.6.2.2
#2 lore raw

PATCH v2 2/5 qemu-kvm.c memory cleanup

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.

---
 qemu-kvm.c |   70 +----------------------------------------------------------
 qemu-kvm.h |   16 +------------
 2 files changed, 4 insertions(+), 82 deletions(-)
qemu-kvm.c +2 -68
index a2131b7..d061e0a 100644
@@ -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);
qemu-kvm.h +2 -14
index 68a5b40..c51566c 100644
@@ -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);
Signature · 1 line
1.6.2.2
#3 lore raw

PATCH v2 3/5 cleanup mmio coalescing functions

remove wrappers that existed only due to qemu/libkvm separation. Use qemu types for function definitions.

---
 qemu-kvm.c |   27 ++++-----------------------
 qemu-kvm.h |    5 -----
 2 files changed, 4 insertions(+), 28 deletions(-)
qemu-kvm.c +4 -23
index d061e0a..609f992 100644
@@ -1099,9 +1099,10 @@ int kvm_init_coalesced_mmio(kvm_context_t kvm)
 	return r;
 }
 
-int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr, uint32_t size)
+int kvm_coalesce_mmio_region(target_phys_addr_t addr, ram_addr_t size)
 {
 #ifdef KVM_CAP_COALESCED_MMIO
+	kvm_context_t kvm = kvm_context;
 	struct kvm_coalesced_mmio_zone zone;
 	int r;
 
@@ -1121,9 +1122,10 @@ int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr, uint32_t size)
 	return -ENOSYS;
 }
 
-int kvm_unregister_coalesced_mmio(kvm_context_t kvm, uint64_t addr, uint32_t size)
+int kvm_uncoalesce_mmio_region(target_phys_addr_t addr, ram_addr_t size)
 {
 #ifdef KVM_CAP_COALESCED_MMIO
+	kvm_context_t kvm = kvm_context;
 	struct kvm_coalesced_mmio_zone zone;
 	int r;
 
@@ -2792,27 +2794,6 @@ void kvm_mutex_lock(void)
     cpu_single_env = NULL;
 }
 
-int qemu_kvm_register_coalesced_mmio(target_phys_addr_t addr, unsigned int size)
-{
-    return kvm_register_coalesced_mmio(kvm_context, addr, size);
-}
-
-int qemu_kvm_unregister_coalesced_mmio(target_phys_addr_t addr,
-				       unsigned int size)
-{
-    return kvm_unregister_coalesced_mmio(kvm_context, addr, size);
-}
-
-int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
-{
-    return kvm_register_coalesced_mmio(kvm_context, start, size);
-}
-
-int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
-{
-    return kvm_unregister_coalesced_mmio(kvm_context, start, size);
-}
-
 #ifdef USE_KVM_DEVICE_ASSIGNMENT
 void kvm_add_ioperm_data(struct ioperm_data *data)
 {
qemu-kvm.h +0 -5
index c51566c..982e448 100644
@@ -113,11 +113,6 @@ void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
 void kvm_tpr_vcpu_start(CPUState *env);
 
 int qemu_kvm_get_dirty_pages(unsigned long phys_addr, void *buf);
-int qemu_kvm_register_coalesced_mmio(target_phys_addr_t addr,
-				     unsigned int size);
-int qemu_kvm_unregister_coalesced_mmio(target_phys_addr_t addr,
-				       unsigned int size);
-
 int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
 int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
 
Signature · 1 line
1.6.2.2
#4 lore raw

PATCH v2 4/5 remove callbacks structure

The purpose of that was only to allow the user of libkvm to register functions pointers that corresponded to possible actions. We don't need that anymore.

---
 libkvm-all.h |    4 +-
 qemu-kvm.c   |  370 +++++++++++++++++++++++++++-------------------------------
 2 files changed, 171 insertions(+), 203 deletions(-)
libkvm-all.h +1 -3
index 47855be..c538f9f 100644
@@ -173,12 +173,10 @@ struct kvm_callbacks {
  * holds information about the KVM instance that gets created by this call.\n
  * This should always be your first call to KVM.
  *
- * \param callbacks Pointer to a valid kvm_callbacks structure
  * \param opaque Not used
  * \return NULL on failure
  */
-kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
-		       void *opaque);
+kvm_context_t kvm_init(void *opaque);
 
 /*!
  * \brief Cleanup the KVM context
qemu-kvm.c +170 -200

500 lines not on this page · raw message

Signature · 1 line
1.6.2.2
#5 lore raw

PATCH v2 5/5 remove wrappers around ex-libkvm functions

Some functions in qemu existed only to call libkvm counterparts. Merge some of them

---
 libkvm-all.h |    6 ++--
 qemu-kvm.c   |   75 ++++++++++++++--------------------------------------------
 2 files changed, 21 insertions(+), 60 deletions(-)
libkvm-all.h +3 -3
index c538f9f..e2d1d4f 100644
@@ -96,9 +96,9 @@ int kvm_arch_run(kvm_vcpu_context_t vcpu);
 void kvm_show_code(kvm_vcpu_context_t vcpu);
 
 int handle_halt(kvm_vcpu_context_t vcpu);
-int handle_shutdown(kvm_context_t kvm, void *env);
-void post_kvm_run(kvm_context_t kvm, void *env);
-int pre_kvm_run(kvm_context_t kvm, void *env);
+int handle_shutdown(kvm_context_t kvm, CPUState *env);
+void post_kvm_run(kvm_context_t kvm, CPUState *env);
+int pre_kvm_run(kvm_context_t kvm, CPUState *env);
 int handle_io_window(kvm_context_t kvm);
 int handle_debug(kvm_vcpu_context_t vcpu, void *env);
 int try_push_interrupts(kvm_context_t kvm);
qemu-kvm.c +18 -57

111 lines not on this page · raw message

Signature · 1 line
1.6.2.2
Applied
#6 lore raw
In reply to Glauber Costa
Quoted 7 lines · Glauber Costa

Avi,

This is the patch set that should be applied. It is comprised of
4 patches. It however, depends on "[PATCH 1/5] get rid of target-i386/libkvm.c", so I'm sending it again, since it does not seem to be already applied by you.

Applied all, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw
Quoted 10 lines · Avi Kivity
Quoted 6 lines · Glauber Costa

Avi,

This is the patch set that should be applied. It is comprised of
4 patches. It however, depends on "[PATCH 1/5] get rid of target-i386/libkvm.c", so I'm sending it again, since it does not seem to be already applied by you.

Applied all, thanks.

Unapplied 2-5, segfaults:

(gdb) bt

#0  0x0000000000553fde in kvm_handle_tpr_access () at /home/avi/qemu-kvm/qemu-kvm-x86.c:123
#1  kvm_arch_run (vcpu=0x1fa5400) at /home/avi/qemu-kvm/qemu-kvm-x86.c:160
#2  0x000000000052f67d in kvm_run (vcpu=0x1fa5400, env=0x1f90e90) at /home/avi/qemu-kvm/qemu-kvm.c:1112
#3  0x000000000052fa56 in kvm_cpu_exec (env=0x1f58ca0) at /home/avi/qemu-kvm/qemu-kvm.c:1777
#4  0x000000000052fe69 in kvm_main_loop_cpu () at /home/avi/qemu-kvm/qemu-kvm.c:1986
#5  ap_main_loop (_env=<value optimized out>) at /home/avi/qemu-kvm/qemu-kvm.c:2021
#6  0x00000000010c73da in start_thread () from /lib64/libpthread.so.0
#7  0x0000000007a9a2bd in clone () from /lib64/libc.so.6
Signature · 1 line
error compiling committee.c: too many arguments to function