9ae3a8
From 0fb4264531471230dfe37f1c04d38cd46e38027a Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Mon, 12 Aug 2013 15:59:32 +0200
9ae3a8
Subject: cpu: Turn cpu_paging_enabled() into a CPUState hook
9ae3a8
9ae3a8
RH-Author: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Message-id: <1376323180-12863-3-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 53161
9ae3a8
O-Subject: [RHEL-7 qemu-kvm PATCH 02/10] cpu: Turn cpu_paging_enabled() 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
Relocate assignment of x86 get_arch_id to have all hooks in one place.
9ae3a8
9ae3a8
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
9ae3a8
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
Signed-off-by: Andreas Färber <afaerber@suse.de>
9ae3a8
(cherry picked from commit 444d55907871f88276a654fc7fdc8c7db95f4b59)
9ae3a8
9ae3a8
Conflicts (due to RHEL-7 commit c93d9248, "target-i386: Disable PMU CPUID
9ae3a8
leaf by default"):
9ae3a8
9ae3a8
	target-i386/cpu.c
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 46465e9..490f5f1 100644
9ae3a8
--- a/include/qom/cpu.h
9ae3a8
+++ b/include/qom/cpu.h
9ae3a8
@@ -48,6 +48,7 @@ typedef struct CPUState CPUState;
9ae3a8
  * @reset: Callback to reset the #CPUState to its initial state.
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
  * @vmsd: State description for migration.
9ae3a8
  *
9ae3a8
  * Represents a CPU family or model.
9ae3a8
@@ -62,6 +63,7 @@ typedef struct CPUClass {
9ae3a8
     void (*reset)(CPUState *cpu);
9ae3a8
     void (*do_interrupt)(CPUState *cpu);
9ae3a8
     int64_t (*get_arch_id)(CPUState *cpu);
9ae3a8
+    bool (*get_paging_enabled)(const CPUState *cpu);
9ae3a8
 
9ae3a8
     const struct VMStateDescription *vmsd;
9ae3a8
     int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
9ae3a8
@@ -138,6 +140,14 @@ struct CPUState {
9ae3a8
 };
9ae3a8
 
9ae3a8
 /**
9ae3a8
+ * cpu_paging_enabled:
9ae3a8
+ * @cpu: The CPU whose state is to be inspected.
9ae3a8
+ *
9ae3a8
+ * Returns: %true if paging is enabled, %false otherwise.
9ae3a8
+ */
9ae3a8
+bool cpu_paging_enabled(const CPUState *cpu);
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 1256125..6f01524 100644
9ae3a8
--- a/include/sysemu/memory_mapping.h
9ae3a8
+++ b/include/sysemu/memory_mapping.h
9ae3a8
@@ -31,7 +31,6 @@ typedef struct MemoryMappingList {
9ae3a8
 } MemoryMappingList;
9ae3a8
 
9ae3a8
 int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env);
9ae3a8
-bool cpu_paging_enabled(CPUArchState *env);
9ae3a8
 
9ae3a8
 /*
9ae3a8
  * add or merge the memory region [phys_addr, phys_addr + length) into the
9ae3a8
diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c
9ae3a8
index 24d5d67..6c0dfeb 100644
9ae3a8
--- a/memory_mapping-stub.c
9ae3a8
+++ b/memory_mapping-stub.c
9ae3a8
@@ -25,9 +25,3 @@ int cpu_get_memory_mapping(MemoryMappingList *list,
9ae3a8
 {
9ae3a8
     return -1;
9ae3a8
 }
9ae3a8
-
9ae3a8
-bool cpu_paging_enabled(CPUArchState *env)
9ae3a8
-{
9ae3a8
-    return true;
9ae3a8
-}
9ae3a8
-
9ae3a8
diff --git a/memory_mapping.c b/memory_mapping.c
9ae3a8
index ff45b3a..0790aac 100644
9ae3a8
--- a/memory_mapping.c
9ae3a8
+++ b/memory_mapping.c
9ae3a8
@@ -170,7 +170,7 @@ static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
9ae3a8
     CPUArchState *env;
9ae3a8
 
9ae3a8
     for (env = start_cpu; env != NULL; env = env->next_cpu) {
9ae3a8
-        if (cpu_paging_enabled(env)) {
9ae3a8
+        if (cpu_paging_enabled(ENV_GET_CPU(env))) {
9ae3a8
             return env;
9ae3a8
         }
9ae3a8
     }
9ae3a8
diff --git a/qom/cpu.c b/qom/cpu.c
9ae3a8
index 04aefbb..9f6da0f 100644
9ae3a8
--- a/qom/cpu.c
9ae3a8
+++ b/qom/cpu.c
9ae3a8
@@ -50,6 +50,18 @@ bool cpu_exists(int64_t id)
9ae3a8
     return data.found;
9ae3a8
 }
9ae3a8
 
9ae3a8
+bool cpu_paging_enabled(const CPUState *cpu)
9ae3a8
+{
9ae3a8
+    CPUClass *cc = CPU_GET_CLASS(cpu);
9ae3a8
+
9ae3a8
+    return cc->get_paging_enabled(cpu);
9ae3a8
+}
9ae3a8
+
9ae3a8
+static bool cpu_common_get_paging_enabled(const CPUState *cpu)
9ae3a8
+{
9ae3a8
+    return true;
9ae3a8
+}
9ae3a8
+
9ae3a8
 /* CPU hot-plug notifiers */
9ae3a8
 static NotifierList cpu_added_notifiers =
9ae3a8
     NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
9ae3a8
@@ -176,6 +188,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
9ae3a8
     k->class_by_name = cpu_common_class_by_name;
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->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 24884bd..39def3d 100644
9ae3a8
--- a/target-i386/arch_memory_mapping.c
9ae3a8
+++ b/target-i386/arch_memory_mapping.c
9ae3a8
@@ -241,7 +241,7 @@ static void walk_pml4e(MemoryMappingList *list,
9ae3a8
 
9ae3a8
 int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
9ae3a8
 {
9ae3a8
-    if (!cpu_paging_enabled(env)) {
9ae3a8
+    if (!cpu_paging_enabled(ENV_GET_CPU(env))) {
9ae3a8
         /* paging is disabled */
9ae3a8
         return 0;
9ae3a8
     }
9ae3a8
@@ -273,7 +273,3 @@ int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
-bool cpu_paging_enabled(CPUArchState *env)
9ae3a8
-{
9ae3a8
-    return env->cr[0] & CR0_PG_MASK;
9ae3a8
-}
9ae3a8
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
9ae3a8
index 2bcc21e..dfa2a86 100644
9ae3a8
--- a/target-i386/cpu.c
9ae3a8
+++ b/target-i386/cpu.c
9ae3a8
@@ -2509,11 +2509,19 @@ static int64_t x86_cpu_get_arch_id(CPUState *cs)
9ae3a8
     return env->cpuid_apic_id;
9ae3a8
 }
9ae3a8
 
9ae3a8
+
9ae3a8
 static Property x86_cpu_properties[] = {
9ae3a8
     DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
9ae3a8
     DEFINE_PROP_END_OF_LIST()
9ae3a8
 };
9ae3a8
 
9ae3a8
+static bool x86_cpu_get_paging_enabled(const CPUState *cs)
9ae3a8
+{
9ae3a8
+    X86CPU *cpu = X86_CPU(cs);
9ae3a8
+
9ae3a8
+    return cpu->env.cr[0] & CR0_PG_MASK;
9ae3a8
+}
9ae3a8
+
9ae3a8
 static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
9ae3a8
 {
9ae3a8
     X86CPUClass *xcc = X86_CPU_CLASS(oc);
9ae3a8
@@ -2529,6 +2537,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
9ae3a8
     cc->reset = x86_cpu_reset;
9ae3a8
 
9ae3a8
     cc->do_interrupt = x86_cpu_do_interrupt;
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->write_elf64_note = x86_cpu_write_elf64_note;
9ae3a8
     cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
9ae3a8
@@ -2536,8 +2546,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
9ae3a8
     cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
9ae3a8
 #endif
9ae3a8
     cpu_class_set_vmsd(cc, &vmstate_x86_cpu);
9ae3a8
-
9ae3a8
-    cc->get_arch_id = x86_cpu_get_arch_id;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static const TypeInfo x86_cpu_type_info = {