Skip to contentSkip to conversation

qemu-kvm cleanup

PATCH In review Glauber Costa 2 participants 8 messages Jun 10, 2009 – Jun 11, 2009 KVM

lore
Share & tools
lore
#0 lore raw

cover qemu-kvm cleanup

This series do some more cleanups in qemu-kvm.c
I decided it is better to clean it up in place a little bit before merging it to kvm-all.c

it is dependant on my previous patch:
"move libkvm-all.c code to qemu-kvm.c"

#1 lore raw

PATCH 1/4 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 09cf203..2c2d46f 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)
@@ -2408,9 +2362,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;
@@ -2487,13 +2440,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;
@@ -2815,18 +2761,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 126b8f3..0dfbcd1 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);
 
@@ -198,14 +194,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.5.6.6
#2 lore raw

PATCH 2/4 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 2c2d46f..e01f8b0 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;
 
@@ -2773,27 +2775,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 0dfbcd1..4db1763 100644
@@ -111,11 +111,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.5.6.6
#3 lore raw

PATCH 3/4 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   |  380 +++++++++++++++++++++++++++-------------------------------
 2 files changed, 175 insertions(+), 209 deletions(-)
libkvm-all.h +1 -3
index 4f7b9a3..be8c855 100644
@@ -177,12 +177,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 +174 -206

510 lines not on this page · raw message

Signature · 1 line
1.5.6.6
#4 lore raw

PATCH 4/4 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   |   77 ++++++++++++++-------------------------------------------
 2 files changed, 22 insertions(+), 61 deletions(-)
libkvm-all.h +3 -3
index be8c855..851901d 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 +19 -58

116 lines not on this page · raw message

Signature · 1 line
1.5.6.6
#5 lore raw

Re: [PATCH 2/4] cleanup mmio coalescing functions

In reply to Glauber Costa

qemu-kvm.c int kvm_init_coalesced_mmio(kvm_context_t kvm) · line 1105

Quoted 10 lines · Glauber Costa

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

qemu-kvm.c +2 -1
-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;

While all this code is doomed, please maintain consistent indentation while it lives.

qemu-kvm.c int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr, uint32_t size) · line 1129

Quoted 13 lines
qemu-kvm.c +2 -1
 	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;
 

Here too.

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

This series do some more cleanups in qemu-kvm.c
I decided it is better to clean it up in place a little bit before merging it to kvm-all.c

it is dependant on my previous patch:
"move libkvm-all.c code to qemu-kvm.c"

I don't see that patch. Where is it?

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

This series do some more cleanups in qemu-kvm.c
I decided it is better to clean it up in place a little bit before merging it to kvm-all.c

it is dependant on my previous patch:
"move libkvm-all.c code to qemu-kvm.c"

I don't see that patch. Where is it?

Apart from my little comment and the missing prerequisite, this series looks good.

Signature · 1 line
error compiling committee.c: too many arguments to function