Blame SOURCES/kvm-cpu-Turn-cpu_get_memory_mapping-into-a-CPUState-hook.patch

218e99
From 4a8aa152fc7244b36cae10a64759ec1c50bc9c87 Mon Sep 17 00:00:00 2001
218e99
From: Laszlo Ersek <lersek@redhat.com>
218e99
Date: Mon, 12 Aug 2013 15:59:34 +0200
218e99
Subject: cpu: Turn cpu_get_memory_mapping() into a CPUState hook
218e99
218e99
RH-Author: Laszlo Ersek <lersek@redhat.com>
218e99
Message-id: <1376323180-12863-5-git-send-email-lersek@redhat.com>
218e99
Patchwork-id: 53163
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH 04/10] cpu: Turn cpu_get_memory_mapping() into a CPUState hook
218e99
Bugzilla: 981582
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Radim Krcmar <rkrcmar@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Andreas Färber <afaerber@suse.de>
218e99
218e99
Change error reporting from return value to Error argument.
218e99
218e99
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
218e99
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
218e99
[AF: Fixed cpu_get_memory_mapping() documentation]
218e99
Signed-off-by: Andreas Färber <afaerber@suse.de>
218e99
(cherry picked from commit a23bbfda75118eb738acce84afd64965934828f0)
218e99
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
218e99
218e99
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
218e99
index 490f5f1..b555c22 100644
218e99
--- a/include/qom/cpu.h
218e99
+++ b/include/qom/cpu.h
218e99
@@ -23,6 +23,7 @@
218e99
 #include <signal.h>
218e99
 #include "hw/qdev-core.h"
218e99
 #include "qemu/thread.h"
218e99
+#include "qemu/typedefs.h"
218e99
 
218e99
 typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaque);
218e99
 
218e99
@@ -49,6 +50,7 @@ typedef struct CPUState CPUState;
218e99
  * @do_interrupt: Callback for interrupt handling.
218e99
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
218e99
  * @get_paging_enabled: Callback for inquiring whether paging is enabled.
218e99
+ * @get_memory_mapping: Callback for obtaining the memory mappings.
218e99
  * @vmsd: State description for migration.
218e99
  *
218e99
  * Represents a CPU family or model.
218e99
@@ -64,6 +66,8 @@ typedef struct CPUClass {
218e99
     void (*do_interrupt)(CPUState *cpu);
218e99
     int64_t (*get_arch_id)(CPUState *cpu);
218e99
     bool (*get_paging_enabled)(const CPUState *cpu);
218e99
+    void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
218e99
+                               Error **errp);
218e99
 
218e99
     const struct VMStateDescription *vmsd;
218e99
     int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
218e99
@@ -148,6 +152,15 @@ struct CPUState {
218e99
 bool cpu_paging_enabled(const CPUState *cpu);
218e99
 
218e99
 /**
218e99
+ * cpu_get_memory_mapping:
218e99
+ * @cpu: The CPU whose memory mappings are to be obtained.
218e99
+ * @list: Where to write the memory mappings to.
218e99
+ * @errp: Pointer for reporting an #Error.
218e99
+ */
218e99
+void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
218e99
+                            Error **errp);
218e99
+
218e99
+/**
218e99
  * cpu_write_elf64_note:
218e99
  * @f: pointer to a function that writes memory to a file
218e99
  * @cpu: The CPU whose memory is to be dumped
218e99
diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h
218e99
index 1f71c32..c47e6ee 100644
218e99
--- a/include/sysemu/memory_mapping.h
218e99
+++ b/include/sysemu/memory_mapping.h
218e99
@@ -31,8 +31,6 @@ struct MemoryMappingList {
218e99
     QTAILQ_HEAD(, MemoryMapping) head;
218e99
 };
218e99
 
218e99
-int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env);
218e99
-
218e99
 /*
218e99
  * add or merge the memory region [phys_addr, phys_addr + length) into the
218e99
  * memory mapping's list. The region's virtual address starts with virt_addr,
218e99
diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c
218e99
index 6c0dfeb..989dc00 100644
218e99
--- a/memory_mapping-stub.c
218e99
+++ b/memory_mapping-stub.c
218e99
@@ -19,9 +19,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
218e99
 {
218e99
     return -2;
218e99
 }
218e99
-
218e99
-int cpu_get_memory_mapping(MemoryMappingList *list,
218e99
-					                                          CPUArchState *env)
218e99
-{
218e99
-    return -1;
218e99
-}
218e99
diff --git a/memory_mapping.c b/memory_mapping.c
218e99
index 0790aac..9bd24ce 100644
218e99
--- a/memory_mapping.c
218e99
+++ b/memory_mapping.c
218e99
@@ -183,13 +183,14 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
218e99
     CPUArchState *env, *first_paging_enabled_cpu;
218e99
     RAMBlock *block;
218e99
     ram_addr_t offset, length;
218e99
-    int ret;
218e99
 
218e99
     first_paging_enabled_cpu = find_paging_enabled_cpu(first_cpu);
218e99
     if (first_paging_enabled_cpu) {
218e99
         for (env = first_paging_enabled_cpu; env != NULL; env = env->next_cpu) {
218e99
-            ret = cpu_get_memory_mapping(list, env);
218e99
-            if (ret < 0) {
218e99
+            Error *err = NULL;
218e99
+            cpu_get_memory_mapping(ENV_GET_CPU(env), list, &err;;
218e99
+            if (err) {
218e99
+                error_free(err);
218e99
                 return -1;
218e99
             }
218e99
         }
218e99
diff --git a/qom/cpu.c b/qom/cpu.c
218e99
index 9f6da0f..b25fbc9 100644
218e99
--- a/qom/cpu.c
218e99
+++ b/qom/cpu.c
218e99
@@ -62,6 +62,21 @@ static bool cpu_common_get_paging_enabled(const CPUState *cpu)
218e99
     return true;
218e99
 }
218e99
 
218e99
+void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
218e99
+                            Error **errp)
218e99
+{
218e99
+    CPUClass *cc = CPU_GET_CLASS(cpu);
218e99
+
218e99
+    return cc->get_memory_mapping(cpu, list, errp);
218e99
+}
218e99
+
218e99
+static void cpu_common_get_memory_mapping(CPUState *cpu,
218e99
+                                          MemoryMappingList *list,
218e99
+                                          Error **errp)
218e99
+{
218e99
+    error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
218e99
+}
218e99
+
218e99
 /* CPU hot-plug notifiers */
218e99
 static NotifierList cpu_added_notifiers =
218e99
     NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
218e99
@@ -189,6 +204,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
218e99
     k->reset = cpu_common_reset;
218e99
     k->get_arch_id = cpu_common_get_arch_id;
218e99
     k->get_paging_enabled = cpu_common_get_paging_enabled;
218e99
+    k->get_memory_mapping = cpu_common_get_memory_mapping;
218e99
     k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
218e99
     k->write_elf32_note = cpu_common_write_elf32_note;
218e99
     k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
218e99
diff --git a/target-i386/arch_memory_mapping.c b/target-i386/arch_memory_mapping.c
218e99
index 39def3d..ca47970 100644
218e99
--- a/target-i386/arch_memory_mapping.c
218e99
+++ b/target-i386/arch_memory_mapping.c
218e99
@@ -239,11 +239,15 @@ static void walk_pml4e(MemoryMappingList *list,
218e99
 }
218e99
 #endif
218e99
 
218e99
-int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
218e99
+void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list,
218e99
+                                Error **errp)
218e99
 {
218e99
-    if (!cpu_paging_enabled(ENV_GET_CPU(env))) {
218e99
+    X86CPU *cpu = X86_CPU(cs);
218e99
+    CPUX86State *env = &cpu->env;
218e99
+
218e99
+    if (!cpu_paging_enabled(cs)) {
218e99
         /* paging is disabled */
218e99
-        return 0;
218e99
+        return;
218e99
     }
218e99
 
218e99
     if (env->cr[4] & CR4_PAE_MASK) {
218e99
@@ -269,7 +273,5 @@ int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
218e99
         pse = !!(env->cr[4] & CR4_PSE_MASK);
218e99
         walk_pde2(list, pde_addr, env->a20_mask, pse);
218e99
     }
218e99
-
218e99
-    return 0;
218e99
 }
218e99
 
218e99
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
218e99
index 5231005..12c7bea 100644
218e99
--- a/target-i386/cpu-qom.h
218e99
+++ b/target-i386/cpu-qom.h
218e99
@@ -105,4 +105,7 @@ int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
218e99
 int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
218e99
                                  void *opaque);
218e99
 
218e99
+void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
218e99
+                                Error **errp);
218e99
+
218e99
 #endif
218e99
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
218e99
index dfa2a86..e915157 100644
218e99
--- a/target-i386/cpu.c
218e99
+++ b/target-i386/cpu.c
218e99
@@ -2540,6 +2540,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
218e99
     cc->get_arch_id = x86_cpu_get_arch_id;
218e99
     cc->get_paging_enabled = x86_cpu_get_paging_enabled;
218e99
 #ifndef CONFIG_USER_ONLY
218e99
+    cc->get_memory_mapping = x86_cpu_get_memory_mapping;
218e99
     cc->write_elf64_note = x86_cpu_write_elf64_note;
218e99
     cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
218e99
     cc->write_elf32_note = x86_cpu_write_elf32_note;