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