Re: [PATCH 04/04] qemu-kvm: other archs should maintain memory mapping

Jes Sorensen <[email protected]>
Newsgroups org.kernel.vger.kvm-ia64,org.kernel.vger.kvm,org.kernel.vger.kvm-ppc
Message-ID <[email protected]>
Avi Kivity wrote:
> Hollis, does this work for you?
> 
> If now, you can add a new define KVM_WANT_MAPPING or something, and 
> define it for I386 and IA64.


Hi,

This is the one implementing the KVM_WANT_MAPPING change.

Cheers,
Jes
0005-qemu-kvm-arch-mapping.patch (text/x-patch, 3 KB)
Introduce KVM_WANT_MAPPING define to switch on mapping code, instead
of relying on TARGET_<arch> defines.

Signed-off-by: Jes Sorensen <[email protected]>

---
 qemu-kvm.c                  |   42 ++++++++++++++++++++++++++----------------
 target-i386/qemu-kvm-arch.h |    2 ++
 target-ia64/qemu-kvm-arch.h |    2 ++
 3 files changed, 30 insertions(+), 16 deletions(-)

Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -824,7 +824,7 @@
     kvm_finalize(kvm_context);
 }
 
-#ifdef TARGET_I386
+#ifdef KVM_WANT_MAPPING
 static struct mapping {
     target_phys_addr_t phys;
     ram_addr_t ram;
@@ -863,6 +863,26 @@
     if (p)
         *p = mappings[--nr_mappings];
 }
+
+static inline void kvm_cpu_drop_mappings(target_phys_addr_t start_addr,
+                                         unsigned long size)
+{
+    struct mapping *p;
+
+    while (size > 0) {
+        p = find_mapping(start_addr);
+        if (p) {
+            kvm_unregister_memory_area(kvm_context, p->phys, p->len);
+            drop_mapping(p->phys);
+        }
+        start_addr += TARGET_PAGE_SIZE;
+        if (size > TARGET_PAGE_SIZE) {
+            size -= TARGET_PAGE_SIZE;
+        } else {
+            size = 0;
+        }
+    }
+}
 #endif
 
 void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
@@ -871,7 +891,7 @@
 {
     int r = 0;
     unsigned long area_flags;
-#ifdef TARGET_I386
+#ifdef KVM_WANT_MAPPING
     struct mapping *p;
 #endif
 
@@ -890,19 +910,9 @@
         if (kvm_arch_must_use_aliases_target(start_addr))
             return;
 
-        while (size > 0) {
-            p = find_mapping(start_addr);
-            if (p) {
-                kvm_unregister_memory_area(kvm_context, p->phys, p->len);
-                drop_mapping(p->phys);
-            }
-            start_addr += TARGET_PAGE_SIZE;
-            if (size > TARGET_PAGE_SIZE) {
-                size -= TARGET_PAGE_SIZE;
-            } else {
-                size = 0;
-            }
-        }
+#ifdef KVM_WANT_MAPPING
+        kvm_cpu_drop_mappings(start_addr, size);
+#endif
         return;
     }
 
@@ -930,7 +940,7 @@
         exit(1);
     }
 
-#ifdef TARGET_I386
+#ifdef KVM_WANT_MAPPING
     drop_mapping(start_addr);
     p = &mappings[nr_mappings++];
     p->phys = start_addr;
Index: qemu-kvm/target-i386/qemu-kvm-arch.h
===================================================================
--- qemu-kvm.orig/target-i386/qemu-kvm-arch.h
+++ qemu-kvm/target-i386/qemu-kvm-arch.h
@@ -14,4 +14,6 @@
 extern int kvm_arch_must_use_aliases_source(target_phys_addr_t addr);
 extern int kvm_arch_must_use_aliases_target(target_phys_addr_t addr);
 
+#define KVM_WANT_MAPPING	1
+
 #endif
Index: qemu-kvm/target-ia64/qemu-kvm-arch.h
===================================================================
--- qemu-kvm.orig/target-ia64/qemu-kvm-arch.h
+++ qemu-kvm/target-ia64/qemu-kvm-arch.h
@@ -19,4 +19,6 @@
     return 0;
 }
 
+#define KVM_WANT_MAPPING	1
+
 #endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.