dump: Build cleanups redone
v2 cover dump: Build cleanups redone
Hello,
This series is an alternative to patches previously queued or posted, based on virgin master.
As requested by Paolo, this replaces Kate's previous memory_mapping split and my follow-ups and instead goes directly for moving things to CPUState.
All knowledge about dump / memory mapping are moved away from configure.
Regards,
Andreas
v1 -> v2:
* Dropped Kate's memory_mapping split
* Dropped target_ulong cleanup and replaced with typedef
* Amended CPUArchState cleanups with introducing hooks in CPUClass
* Drop memory_memory stubs instead of moving them
Andreas Färber (6):
dump: Move stubs into libqemustub.a
cpu: Turn cpu_paging_enabled() into a CPUState hook
memory_mapping: Move MemoryMappingList typedef to qemu/typedefs.h
cpu: Turn cpu_get_memory_mapping() into a CPUState hook
memory_mapping: Drop qemu_get_memory_mapping() stub
dump: Unconditionally compile
Qiao Nuohan (1):
target-i386: Fix mask of pte index in memory mapping
Makefile.target | 8 ++------ configure | 8 -------- hmp-commands.hx | 2 -- include/qemu/typedefs.h | 2 ++ include/qom/cpu.h | 21 +++++++++++++++++++++ include/sysemu/memory_mapping.h | 8 +++----- memory_mapping-stub.c | 33 --------------------------------- memory_mapping.c | 4 ++-- qom/cpu.c | 27 +++++++++++++++++++++++++++ stubs/Makefile.objs | 1 + dump-stub.c => stubs/dump.c | 8 -------- target-i386/arch_memory_mapping.c | 13 ++++++------- target-i386/cpu-qom.h | 2 ++ target-i386/cpu.c | 12 ++++++++++-- 14 files changed, 76 insertions(+), 73 deletions(-) delete mode 100644 memory_mapping-stub.c rename dump-stub.c => stubs/dump.c (65%)
Signature · 1 line
1.8.1.4
PATCH v2 1/7 target-i386: Fix mask of pte index in memory mapping
From: Qiao Nuohan <[email protected]>
Function walk_pte() needs pte index to calculate virtual address. However, pte index of PAE paging or IA-32e paging is 9 bit, so the mask should be 0x1ff.
--- target-i386/arch_memory_mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/arch_memory_mapping.c +1 -1
@@ -38,7 +38,7 @@ static void walk_pte(MemoryMappingList *list, hwaddr pte_start_addr,continue ; } - start_vaddr = start_line_addr | ((i &0x1fff ) <<12 ); + start_vaddr = start_line_addr | ((i &0x1ff ) <<12 );memory_mapping_list_add_merge_sorted (list, start_paddr, start_vaddr,1 <<12 ); }
Signature · 1 line
1.8.1.4
PATCH v2 2/7 dump: Move stubs into libqemustub.a
In reply to Andreas FärberThis allows us to drop CONFIG_NO_CORE_DUMP with its indirect dependency on CONFIG_HAVE_CORE_DUMP.
--- Makefile.target | 2 -- stubs/Makefile.objs | 1 + dump-stub.c => stubs/dump.c | 0 3 files changed, 1 insertion(+), 2 deletions(-) rename dump-stub.c => stubs/dump.c (100%)
Makefile.target +0 -2
@@ -64,7 +64,6 @@ CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y) CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y) CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y) CONFIG_NO_GET_MEMORY_MAPPING = $(if $(subst n,,$(CONFIG_HAVE_GET_MEMORY_MAPPING)),n,y) -CONFIG_NO_CORE_DUMP = $(if $(subst n,,$(CONFIG_HAVE_CORE_DUMP)),n,y) ######################################################### # cpu emulator library
@@ -114,7 +113,6 @@ obj-y += memory.o savevm.o cputlb.o obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o -obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o LIBS+=$(libs_softmmu) # xen support
stubs/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ stub-obj-y += arch-query-cpu-def.o stub-obj-y += clock-warp.o stub-obj-y += cpu-get-clock.o stub-obj-y += cpu-get-icount.o +stub-obj-y += dump.o stub-obj-y += fdset-add-fd.o stub-obj-y += fdset-find-fd.o stub-obj-y += fdset-get-fd.o
stubs/dump.c renamed from dump-stub.c +0 -0
Signature · 1 line
1.8.1.4
PATCH v2 3/7 cpu: Turn cpu_paging_enabled() into a CPUState hook
In reply to Andreas Färber--- include/qom/cpu.h | 10 ++++++++++ include/sysemu/memory_mapping.h | 1 - memory_mapping-stub.c | 6 ------ memory_mapping.c | 2 +- qom/cpu.c | 13 +++++++++++++ target-i386/arch_memory_mapping.c | 6 +----- target-i386/cpu.c | 11 +++++++++-- 7 files changed, 34 insertions(+), 15 deletions(-)
include/qom/cpu.h +10 -0
@@ -48,6 +48,7 @@ typedef struct CPUState CPUState;* @reset: Callback to reset the #CPUState to its initial state. * @do_interrupt: Callback for interrupt handling. * @get_arch_id: Callback for getting architecture-dependent CPU ID. +* @get_paging_enabled: Callback for inquiring whether paging is enabled. * @vmsd: State description for migration. * * Represents a CPU family or model.
@@ -62,6 +63,7 @@ typedef struct CPUClass {void (*reset)(CPUState *cpu);void (*do_interrupt)(CPUState *cpu);int64_t (*get_arch_id)(CPUState *cpu); +bool (*get_paging_enabled)(CPUState *cpu);const struct VMStateDescription *vmsd; int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
@@ -138,6 +140,14 @@ struct CPUState { };/** +* cpu_paging_enabled: +* @cpu: The CPU whose state is to be inspected. +* +* Returns: %true if paging is enabled, %false otherwise. +*/ +bool cpu_paging_enabled (CPUState *cpu); + +/** * cpu_write_elf64_note: * @f: pointer to a function that writes memory to a file * @cpu: The CPU whose memory is to be dumped
include/sysemu/memory_mapping.h +0 -1
@@ -31,7 +31,6 @@ typedef struct MemoryMappingList { } MemoryMappingList;int cpu_get_memory_mapping (MemoryMappingList *list,CPUArchState *env); -bool cpu_paging_enabled (CPUArchState *env);/* * add or merge the memory region [phys_addr, phys_addr + length) into the
memory_mapping-stub.c +0 -6
@@ -25,9 +25,3 @@ int cpu_get_memory_mapping(MemoryMappingList *list, {return -1 ; } - -bool cpu_paging_enabled (CPUArchState *env) -{ -return true; -} -
memory_mapping.c +1 -1
@@ -170,7 +170,7 @@ static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)CPUArchState *env;for (env = start_cpu; env !=NULL ; env = env->next_cpu) { -if (cpu_paging_enabled (env)) { +if (cpu_paging_enabled (ENV_GET_CPU (env))) {return env; } }
qom/cpu.c +13 -0
@@ -50,6 +50,18 @@ bool cpu_exists(int64_t id)return data.found; } +bool cpu_paging_enabled (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +return cc->get_paging_enabled (cpu); +} + +static bool cpu_common_get_paging_enabled (CPUState *cpu) +{ +return true; +} +/* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers =NOTIFIER_LIST_INITIALIZER (cpu_add_notifiers);
@@ -176,6 +188,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->class_by_name = cpu_common_class_by_name; k->reset = cpu_common_reset; k->get_arch_id = cpu_common_get_arch_id; + k->get_paging_enabled = cpu_common_get_paging_enabled; k->write_elf32_qemunote = cpu_common_write_elf32_qemunote; k->write_elf32_note = cpu_common_write_elf32_note; k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
target-i386/arch_memory_mapping.c +1 -5
@@ -239,7 +239,7 @@ static void walk_pml4e(MemoryMappingList *list,int cpu_get_memory_mapping (MemoryMappingList *list,CPUArchState *env) { -if (!cpu_paging_enabled (env)) { +if (!cpu_paging_enabled (ENV_GET_CPU (env))) {/* paging is disabled */ return 0 ; }
@@ -271,7 +271,3 @@ int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)return 0 ; } -bool cpu_paging_enabled (CPUArchState *env) -{ -return env->cr[0 ] &CR0_PG_MASK ; -}
target-i386/cpu.c +9 -2
@@ -2505,6 +2505,13 @@ static int64_t x86_cpu_get_arch_id(CPUState *cs)return env->cpuid_apic_id; } +static bool x86_cpu_get_paging_enabled (CPUState *cs) +{ +X86CPU *cpu =X86_CPU (cs); + +return cpu->env.cr[0 ] &CR0_PG_MASK ; +} +static void x86_cpu_common_class_init (ObjectClass *oc,void *data) {X86CPUClass *xcc =X86_CPU_CLASS (oc);
@@ -2519,6 +2526,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->reset = x86_cpu_reset; cc->do_interrupt = x86_cpu_do_interrupt; + cc->get_arch_id = x86_cpu_get_arch_id; + cc->get_paging_enabled = x86_cpu_get_paging_enabled;#ifndef CONFIG_USER_ONLY cc->write_elf64_note = x86_cpu_write_elf64_note; cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
@@ -2526,8 +2535,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;#endif cpu_class_set_vmsd (cc, &vmstate_x86_cpu); - - cc->get_arch_id = x86_cpu_get_arch_id; }static const TypeInfo x86_cpu_type_info = {
Signature · 1 line
1.8.1.4
PATCH v2 4/7 memory_mapping: Move MemoryMappingList typedef to qemu/typedefs.h
In reply to Andreas FärberThis will avoid issues with hwaddr and ram_addr_t when including sysemu/memory_mapping.h for CONFIG_USER_ONLY.
--- include/qemu/typedefs.h | 2 ++ include/sysemu/memory_mapping.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
include/qemu/typedefs.h +2 -0
@@ -22,6 +22,8 @@ typedef struct AddressSpace AddressSpace;typedef struct MemoryRegion MemoryRegion ;typedef struct MemoryRegionSection MemoryRegionSection ; +typedef struct MemoryMappingList MemoryMappingList ; +typedef struct NICInfo NICInfo ;typedef struct HCIInfo HCIInfo ;typedef struct AudioState AudioState ;
include/sysemu/memory_mapping.h +3 -2
@@ -15,6 +15,7 @@#define MEMORY_MAPPING_H #include "qemu/queue.h" +#include "qemu/typedefs.h" /* The physical and virtual address in the memory mapping are contiguous. */ typedef struct MemoryMapping {
@@ -24,11 +25,11 @@ typedef struct MemoryMapping {QTAILQ_ENTRY (MemoryMapping) next; } MemoryMapping; -typedef struct MemoryMappingList { +struct MemoryMappingList {unsigned int num;MemoryMapping *last_mapping; QTAILQ_HEAD(, MemoryMapping) head; -}MemoryMappingList ; +};int cpu_get_memory_mapping (MemoryMappingList *list,CPUArchState *env);
Signature · 1 line
1.8.1.4
PATCH v2 5/7 cpu: Turn cpu_get_memory_mapping() into a CPUState hook
In reply to Andreas Färber--- include/qom/cpu.h | 11 +++++++++++ include/sysemu/memory_mapping.h | 2 -- memory_mapping-stub.c | 6 ------ memory_mapping.c | 2 +- qom/cpu.c | 14 ++++++++++++++ target-i386/arch_memory_mapping.c | 7 +++++-- target-i386/cpu-qom.h | 2 ++ target-i386/cpu.c | 1 + 8 files changed, 34 insertions(+), 11 deletions(-)
include/qom/cpu.h +11 -0
@@ -23,6 +23,7 @@#include <signal.h> #include "hw/qdev-core.h" #include "qemu/thread.h" +#include "qemu/typedefs.h" typedef int (*WriteCoreDumpFunction )(void *buf,size_t size,void *opaque);
@@ -49,6 +50,7 @@ typedef struct CPUState CPUState;* @do_interrupt: Callback for interrupt handling. * @get_arch_id: Callback for getting architecture-dependent CPU ID. * @get_paging_enabled: Callback for inquiring whether paging is enabled. +* @get_memory_mapping: Callback for obtaining the memory mappings. * @vmsd: State description for migration. * * Represents a CPU family or model.
@@ -64,6 +66,7 @@ typedef struct CPUClass {void (*do_interrupt)(CPUState *cpu);int64_t (*get_arch_id)(CPUState *cpu);bool (*get_paging_enabled)(CPUState *cpu); +int (*get_memory_mapping)(CPUState *cpu,MemoryMappingList *list);const struct VMStateDescription *vmsd; int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
@@ -148,6 +151,14 @@ struct CPUState {bool cpu_paging_enabled (CPUState *cpu);/** +* @cpu: The CPU whose memory mappings are to be obtained. +* @list: Where to write the memory mappings to. +* +* Returns: 0 if successful. +*/ +int cpu_get_memory_mapping (CPUState *cpu,MemoryMappingList *list); + +/** * cpu_write_elf64_note: * @f: pointer to a function that writes memory to a file * @cpu: The CPU whose memory is to be dumped
include/sysemu/memory_mapping.h +0 -2
@@ -31,8 +31,6 @@ struct MemoryMappingList { QTAILQ_HEAD(, MemoryMapping) head; }; -int cpu_get_memory_mapping (MemoryMappingList *list,CPUArchState *env); -/* * add or merge the memory region [phys_addr, phys_addr + length) into the * memory mapping's list. The region's virtual address starts with virt_addr,
memory_mapping-stub.c +0 -6
@@ -19,9 +19,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) {return -2 ; } - -int cpu_get_memory_mapping (MemoryMappingList *list, -CPUArchState *env) -{ -return -1 ; -}
memory_mapping.c +1 -1
@@ -188,7 +188,7 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) first_paging_enabled_cpu =find_paging_enabled_cpu (first_cpu);if (first_paging_enabled_cpu) {for (env = first_paging_enabled_cpu; env !=NULL ; env = env->next_cpu) { - ret =cpu_get_memory_mapping (list, env); + ret =cpu_get_memory_mapping (ENV_GET_CPU (env), list);if (ret <0 ) {return -1 ; }
qom/cpu.c +14 -0
@@ -62,6 +62,19 @@ static bool cpu_common_get_paging_enabled(CPUState *cpu)return true; } +int cpu_get_memory_mapping (CPUState *cpu,MemoryMappingList *list) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +return cc->get_memory_mapping (cpu, list); +} + +static int cpu_common_get_memory_mapping (CPUState *cpu, +MemoryMappingList *list) +{ +return -1 ; +} +/* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers =NOTIFIER_LIST_INITIALIZER (cpu_add_notifiers);
@@ -189,6 +202,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->reset = cpu_common_reset; k->get_arch_id = cpu_common_get_arch_id; k->get_paging_enabled = cpu_common_get_paging_enabled; + k->get_memory_mapping = cpu_common_get_memory_mapping; k->write_elf32_qemunote = cpu_common_write_elf32_qemunote; k->write_elf32_note = cpu_common_write_elf32_note; k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
target-i386/arch_memory_mapping.c +5 -2
@@ -237,9 +237,12 @@ static void walk_pml4e(MemoryMappingList *list, }#endif -int cpu_get_memory_mapping (MemoryMappingList *list,CPUArchState *env) +int x86_cpu_get_memory_mapping (CPUState *cs,MemoryMappingList *list) { -if (!cpu_paging_enabled (ENV_GET_CPU (env))) { +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; + +if (!cpu_paging_enabled (cs)) {/* paging is disabled */ return 0 ; }
target-i386/cpu-qom.h +2 -0
@@ -98,4 +98,6 @@ int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,int x86_cpu_write_elf32_qemunote (WriteCoreDumpFunction f,CPUState *cpu,void *opaque); +int x86_cpu_get_memory_mapping (CPUState *cpu,MemoryMappingList *list); +#endif
target-i386/cpu.c +1 -0
@@ -2529,6 +2529,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->get_arch_id = x86_cpu_get_arch_id; cc->get_paging_enabled = x86_cpu_get_paging_enabled;#ifndef CONFIG_USER_ONLY + cc->get_memory_mapping = x86_cpu_get_memory_mapping; cc->write_elf64_note = x86_cpu_write_elf64_note; cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote; cc->write_elf32_note = x86_cpu_write_elf32_note;
Signature · 1 line
1.8.1.4
PATCH v2 6/7 memory_mapping: Drop qemu_get_memory_mapping() stub
In reply to Andreas Färberdump.c:dump_init() never checked for the return code anyway. If paging is not enabled, it will fall back to an identity map. If paging is enabled and getting memory mapping list is not implemented, qemu_get_guest_memory_mapping() will return an error.
Since the targets not implementing memory mapping also don't implement dump support, we will not reach this code today and can worry about changing cpu_paging_enabled() default when the need arises.
This allows us to drop CONFIG_HAVE_GET_MEMORY_SUPPORT and thereby keep configure out of the picture.
--- Makefile.target | 4 +--- configure | 4 ---- memory_mapping-stub.c | 21 --------------------- 3 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 memory_mapping-stub.c
Makefile.target +1 -3
@@ -63,7 +63,6 @@ all: $(PROGS) stap CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y) CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y) CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y) -CONFIG_NO_GET_MEMORY_MAPPING = $(if $(subst n,,$(CONFIG_HAVE_GET_MEMORY_MAPPING)),n,y) ######################################################### # cpu emulator library
@@ -110,9 +109,8 @@ obj-y += hw/ obj-$(CONFIG_FDT) += device_tree.o obj-$(CONFIG_KVM) += kvm-all.o obj-y += memory.o savevm.o cputlb.o -obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o +obj-y += memory_mapping.o obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o -obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o LIBS+=$(libs_softmmu) # xen support
configure +0 -4
@@ -4340,10 +4340,6 @@ case "$target_arch2" in fi fi esac -case "$target_arch2" in - i386|x86_64) - echo "CONFIG_HAVE_GET_MEMORY_MAPPING=y" >> $config_target_mak -esac if test "$target_bigendian" = "yes" ; then echo "TARGET_WORDS_BIGENDIAN=y" >> $config_target_mak fi
memory_mapping-stub.c deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* QEMU memory mapping -* -* Copyright Fujitsu, Corp. 2011, 2012 -* -* Authors: -* Wen Congyang <[email protected]> -* -* This work is licensed under the terms of the GNU GPL, version 2 or later. -* See the COPYING file in the top-level directory. -* -*/ - -#include "cpu.h" -#include "exec/cpu-all.h" -#include "sysemu/memory_mapping.h" - -int qemu_get_guest_memory_mapping (MemoryMappingList *list) -{ -return -2 ; -}
Signature · 1 line
1.8.1.4
PATCH v2 7/7 dump: Unconditionally compile
In reply to Andreas Färberqmp_dump_guest_memory() calls dump_init() and returns an Error when cpu_get_dump_info() returns an error, as done by the stub. So there is no need to have a stub for qmp_dump_guest_memory().
Enable the documentation of the always-present dump-guest-memory command.
That way we can drop CONFIG_HAVE_CORE_DUMP.
--- Makefile.target | 2 +- configure | 4 ---- hmp-commands.hx | 2 -- stubs/dump.c | 8 -------- 4 files changed, 1 insertion(+), 15 deletions(-)
Makefile.target +1 -1
@@ -110,7 +110,7 @@ obj-$(CONFIG_FDT) += device_tree.o obj-$(CONFIG_KVM) += kvm-all.o obj-y += memory.o savevm.o cputlb.o obj-y += memory_mapping.o -obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o +obj-y += dump.o LIBS+=$(libs_softmmu) # xen support
configure +0 -4
@@ -4345,10 +4345,6 @@ if test "$target_bigendian" = "yes" ; then fi if test "$target_softmmu" = "yes" ; then echo "CONFIG_SOFTMMU=y" >> $config_target_mak - case "$target_arch2" in - i386|x86_64) - echo "CONFIG_HAVE_CORE_DUMP=y" >> $config_target_mak - esac fi if test "$target_user_only" = "yes" ; then echo "CONFIG_USER_ONLY=y" >> $config_target_mak
hmp-commands.hx +0 -2
@@ -989,7 +989,6 @@ server will ask the spice/vnc client to automatically reconnect using the new parameters (if specified) once the vm migration finished successfully. ETEXI -#if defined(CONFIG_HAVE_CORE_DUMP) { .name = "dump-guest-memory", .args_type = "paging:-p,filename:F,begin:i?,length:i?",
@@ -1013,7 +1012,6 @@ gdb. length: the memory size, in bytes. It's optional, and should be specified with begin together. ETEXI -#endif { .name = "snapshot_blkdev",
stubs/dump.c +0 -8
@@ -16,14 +16,6 @@#include "qapi/qmp/qerror.h" #include "qmp-commands.h" -/* we need this function in hmp.c */ -void qmp_dump_guest_memory (bool paging,const char *file,bool has_begin, -int64_t begin,bool has_length,int64_t length, -Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -} -int cpu_get_dump_info (ArchDumpInfo *info) {return -1 ;
Signature · 1 line
1.8.1.4