From 88f62c2b1deb466749e340a8a241975c509bd9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 17 May 2013 10:41:20 +0200 Subject: [PATCH 01/17] dump: Move stubs into libqemustub.a MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to drop CONFIG_NO_CORE_DUMP with its indirect dependency on CONFIG_HAVE_CORE_DUMP. Acked-by: Paolo Bonzini Signed-off-by: Andreas Färber --- 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%) diff --git a/Makefile.target b/Makefile.target index ce4391fca7..1cafb176e3 100644 --- a/Makefile.target +++ b/Makefile.target @@ -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 diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 03dff202e4..9b701b4714 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -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 diff --git a/dump-stub.c b/stubs/dump.c similarity index 100% rename from dump-stub.c rename to stubs/dump.c From 8de433cb0820dc1f387a2d580d255744aacd60cc Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 30 May 2013 17:09:34 +0200 Subject: [PATCH 02/17] pc: Fix crash when attempting to hotplug CPU with negative ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QMP command "{ 'execute': 'cpu-add', 'arguments': { 'id': -1 }}" may cause QEMU SIGSEGV at: piix4_cpu_hotplug_req () ... g->sts[cpu_id / 8] |= (1 << (cpu_id % 8)); ... Since for PC in current implementation id should be in range [0...maxcpus) and maxcpus is already checked, add check for lower bound and error out on incorrect value. Signed-off-by: Igor Mammedov Signed-off-by: Andreas Färber --- hw/i386/pc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4844a6b370..553becbd42 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -927,6 +927,11 @@ void pc_hot_add_cpu(const int64_t id, Error **errp) DeviceState *icc_bridge; int64_t apic_id = x86_cpu_apic_id_from_index(id); + if (id < 0) { + error_setg(errp, "Invalid CPU id: %" PRIi64, id); + return; + } + if (cpu_exists(apic_id)) { error_setg(errp, "Unable to add CPU: %" PRIi64 ", it already exists", id); From 45053fdef54fa9aac1cc9b09f2a1d08af90b7b43 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Mon, 27 May 2013 17:23:53 -0300 Subject: [PATCH 03/17] pc: Create pc-*-1.6 machine-types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some CPU model fixes are going to be included and they will require compatibility properties in the pc-*-1.5 machine-types. Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- hw/i386/pc_piix.c | 14 ++++++++++++-- hw/i386/pc_q35.c | 12 +++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index d6185705a6..7fb2bce628 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -327,8 +327,8 @@ static void pc_xen_hvm_init(QEMUMachineInitArgs *args) } #endif -static QEMUMachine pc_i440fx_machine_v1_5 = { - .name = "pc-i440fx-1.5", +static QEMUMachine pc_i440fx_machine_v1_6 = { + .name = "pc-i440fx-1.6", .alias = "pc", .desc = "Standard PC (i440FX + PIIX, 1996)", .init = pc_init_pci, @@ -338,6 +338,15 @@ static QEMUMachine pc_i440fx_machine_v1_5 = { DEFAULT_MACHINE_OPTIONS, }; +static QEMUMachine pc_i440fx_machine_v1_5 = { + .name = "pc-i440fx-1.5", + .desc = "Standard PC (i440FX + PIIX, 1996)", + .init = pc_init_pci, + .hot_add_cpu = pc_hot_add_cpu, + .max_cpus = 255, + DEFAULT_MACHINE_OPTIONS, +}; + static QEMUMachine pc_i440fx_machine_v1_4 = { .name = "pc-i440fx-1.4", .desc = "Standard PC (i440FX + PIIX, 1996)", @@ -735,6 +744,7 @@ static QEMUMachine xenfv_machine = { static void pc_machine_init(void) { + qemu_register_machine(&pc_i440fx_machine_v1_6); qemu_register_machine(&pc_i440fx_machine_v1_5); qemu_register_machine(&pc_i440fx_machine_v1_4); qemu_register_machine(&pc_machine_v1_3); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 7888dfe03f..db5c46e131 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -215,9 +215,18 @@ static void pc_q35_init_1_4(QEMUMachineInitArgs *args) pc_q35_init(args); } +static QEMUMachine pc_q35_machine_v1_6 = { + .name = "pc-q35-1.6", + .alias = "q35", + .desc = "Standard PC (Q35 + ICH9, 2009)", + .init = pc_q35_init, + .hot_add_cpu = pc_hot_add_cpu, + .max_cpus = 255, + DEFAULT_MACHINE_OPTIONS, +}; + static QEMUMachine pc_q35_machine_v1_5 = { .name = "pc-q35-1.5", - .alias = "q35", .desc = "Standard PC (Q35 + ICH9, 2009)", .init = pc_q35_init, .hot_add_cpu = pc_hot_add_cpu, @@ -239,6 +248,7 @@ static QEMUMachine pc_q35_machine_v1_4 = { static void pc_q35_machine_init(void) { + qemu_register_machine(&pc_q35_machine_v1_6); qemu_register_machine(&pc_q35_machine_v1_5); qemu_register_machine(&pc_q35_machine_v1_4); } From ffce9ebbb69363dfe7605585cdad58ea3847edf4 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Mon, 27 May 2013 17:23:54 -0300 Subject: [PATCH 04/17] target-i386: Update model values on Conroe/Penryn/Nehalem CPU models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CPUID model values on Conroe, Penryn, and Nehalem are too conservative and don't reflect the values found on real Conroe, Penryn, and Nehalem CPUs. This causes at least one known problems: Windows XP disables sysenter when (family == 6 && model <= 2), but Skype tries to use the sysenter instruction anyway because it is reported as available on CPUID, making it crash. This patch sets appropriate model values that correspond to real Conroe, Penryn, and Nehalem CPUs. Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- hw/i386/pc_piix.c | 4 ++++ hw/i386/pc_q35.c | 4 ++++ include/hw/i386/pc.h | 16 ++++++++++++++++ target-i386/cpu.c | 6 +++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 7fb2bce628..69eb2a17be 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -344,6 +344,10 @@ static QEMUMachine pc_i440fx_machine_v1_5 = { .init = pc_init_pci, .hot_add_cpu = pc_hot_add_cpu, .max_cpus = 255, + .compat_props = (GlobalProperty[]) { + PC_COMPAT_1_5, + { /* end of list */ } + }, DEFAULT_MACHINE_OPTIONS, }; diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index db5c46e131..bb0ce6ae6b 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -231,6 +231,10 @@ static QEMUMachine pc_q35_machine_v1_5 = { .init = pc_q35_init, .hot_add_cpu = pc_hot_add_cpu, .max_cpus = 255, + .compat_props = (GlobalProperty[]) { + PC_COMPAT_1_5, + { /* end of list */ } + }, DEFAULT_MACHINE_OPTIONS, }; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 61540587a4..f232d75605 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -185,7 +185,23 @@ int pvpanic_init(ISABus *bus); int e820_add_entry(uint64_t, uint64_t, uint32_t); +#define PC_COMPAT_1_5 \ + {\ + .driver = "Conroe-" TYPE_X86_CPU,\ + .property = "model",\ + .value = stringify(2),\ + },{\ + .driver = "Penryn-" TYPE_X86_CPU,\ + .property = "model",\ + .value = stringify(2),\ + },{\ + .driver = "Nehalem-" TYPE_X86_CPU,\ + .property = "model",\ + .value = stringify(2),\ + } + #define PC_COMPAT_1_4 \ + PC_COMPAT_1_5, \ {\ .driver = "scsi-hd",\ .property = "discard_granularity",\ diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 1a501d9d33..6b48562a1a 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -672,7 +672,7 @@ static x86_def_t builtin_x86_defs[] = { .level = 2, .vendor = CPUID_VENDOR_INTEL, .family = 6, - .model = 2, + .model = 15, .stepping = 3, .features[FEAT_1_EDX] = CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | @@ -694,7 +694,7 @@ static x86_def_t builtin_x86_defs[] = { .level = 2, .vendor = CPUID_VENDOR_INTEL, .family = 6, - .model = 2, + .model = 23, .stepping = 3, .features[FEAT_1_EDX] = CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | @@ -717,7 +717,7 @@ static x86_def_t builtin_x86_defs[] = { .level = 2, .vendor = CPUID_VENDOR_INTEL, .family = 6, - .model = 2, + .model = 26, .stepping = 3, .features[FEAT_1_EDX] = CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | From 6b11322e0f724eb0649fdc324a44288b783023ad Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Mon, 27 May 2013 17:23:55 -0300 Subject: [PATCH 05/17] target-i386: Set level=4 on Conroe/Penryn/Nehalem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CPUID level value on Conroe, Penryn, and Nehalem are too low. This causes at least one known problem: the -smp "threads" option doesn't work as expect if level is < 4, because thread count information is provided to the guest on CPUID[EAX=4,ECX=2].EAX Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- include/hw/i386/pc.h | 12 ++++++++++++ target-i386/cpu.c | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index f232d75605..fab9be51cc 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -190,14 +190,26 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); .driver = "Conroe-" TYPE_X86_CPU,\ .property = "model",\ .value = stringify(2),\ + },{\ + .driver = "Conroe-" TYPE_X86_CPU,\ + .property = "level",\ + .value = stringify(2),\ },{\ .driver = "Penryn-" TYPE_X86_CPU,\ .property = "model",\ .value = stringify(2),\ + },{\ + .driver = "Penryn-" TYPE_X86_CPU,\ + .property = "level",\ + .value = stringify(2),\ },{\ .driver = "Nehalem-" TYPE_X86_CPU,\ .property = "model",\ .value = stringify(2),\ + },{\ + .driver = "Nehalem-" TYPE_X86_CPU,\ + .property = "level",\ + .value = stringify(2),\ } #define PC_COMPAT_1_4 \ diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 6b48562a1a..762baadd4b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -669,7 +669,7 @@ static x86_def_t builtin_x86_defs[] = { }, { .name = "Conroe", - .level = 2, + .level = 4, .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 15, @@ -691,7 +691,7 @@ static x86_def_t builtin_x86_defs[] = { }, { .name = "Penryn", - .level = 2, + .level = 4, .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 23, @@ -714,7 +714,7 @@ static x86_def_t builtin_x86_defs[] = { }, { .name = "Nehalem", - .level = 2, + .level = 4, .vendor = CPUID_VENDOR_INTEL, .family = 6, .model = 26, From 31ccdde298d98b08526dc23059071c9086dec6c2 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 3 Jun 2013 18:23:27 +0200 Subject: [PATCH 06/17] target-i386: cpu: Fix potential buffer overrun in get_register_name_32() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spotted by Coverity, x86_reg_info_32[] is CPU_NB_REGS32 elements long, so accessing x86_reg_info_32[CPU_NB_REGS32] will be one element off array. Signed-off-by: Igor Mammedov Reviewed-by: liguang Reviewed by: Jesse Larrew Signed-off-by: Andreas Färber --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 762baadd4b..4b2da0d750 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -221,7 +221,7 @@ X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = { const char *get_register_name_32(unsigned int reg) { - if (reg > CPU_NB_REGS32) { + if (reg >= CPU_NB_REGS32) { return NULL; } return x86_reg_info_32[reg].name; From c51a944b7505ba827adc897d5452d2b54dbf86bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 17 May 2013 16:57:52 +0200 Subject: [PATCH 07/17] monitor: Simplify do_inject_mce() with qemu_get_cpu() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids an open-coded CPU loop. Reviewed-by: liguang Reviewed-by: Luiz Capitulino Signed-off-by: Andreas Färber --- monitor.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 017411fcb0..70ae8f5b18 100644 --- a/monitor.c +++ b/monitor.c @@ -2013,7 +2013,6 @@ static void do_acl_remove(Monitor *mon, const QDict *qdict) static void do_inject_mce(Monitor *mon, const QDict *qdict) { X86CPU *cpu; - CPUX86State *cenv; CPUState *cs; int cpu_index = qdict_get_int(qdict, "cpu_index"); int bank = qdict_get_int(qdict, "bank"); @@ -2026,14 +2025,11 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict) if (qdict_get_try_bool(qdict, "broadcast", 0)) { flags |= MCE_INJECT_BROADCAST; } - for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) { - cpu = x86_env_get_cpu(cenv); - cs = CPU(cpu); - if (cs->cpu_index == cpu_index) { - cpu_x86_inject_mce(mon, cpu, bank, status, mcg_status, addr, misc, - flags); - break; - } + cs = qemu_get_cpu(cpu_index); + if (cs != NULL) { + cpu = X86_CPU(cs); + cpu_x86_inject_mce(mon, cpu, bank, status, mcg_status, addr, misc, + flags); } } #endif From 444d55907871f88276a654fc7fdc8c7db95f4b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 28 May 2013 13:28:38 +0200 Subject: [PATCH 08/17] cpu: Turn cpu_paging_enabled() into a CPUState hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relocate assignment of x86 get_arch_id to have all hooks in one place. Reviewed-by: Jens Freimann Reviewed-by: Luiz Capitulino Signed-off-by: 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(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 7cd9442503..1f70240991 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -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)(const CPUState *cpu); const struct VMStateDescription *vmsd; int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, @@ -137,6 +139,14 @@ struct CPUState { uint32_t halted; /* used by alpha, cris, ppc TCG */ }; +/** + * cpu_paging_enabled: + * @cpu: The CPU whose state is to be inspected. + * + * Returns: %true if paging is enabled, %false otherwise. + */ +bool cpu_paging_enabled(const CPUState *cpu); + /** * cpu_write_elf64_note: * @f: pointer to a function that writes memory to a file diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h index 1256125963..6f01524451 100644 --- a/include/sysemu/memory_mapping.h +++ b/include/sysemu/memory_mapping.h @@ -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 diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c index 24d5d67371..6c0dfeb01c 100644 --- a/memory_mapping-stub.c +++ b/memory_mapping-stub.c @@ -25,9 +25,3 @@ int cpu_get_memory_mapping(MemoryMappingList *list, { return -1; } - -bool cpu_paging_enabled(CPUArchState *env) -{ - return true; -} - diff --git a/memory_mapping.c b/memory_mapping.c index ff45b3a239..0790aacc21 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -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; } } diff --git a/qom/cpu.c b/qom/cpu.c index 04aefbb956..9f6da0fdd8 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -50,6 +50,18 @@ bool cpu_exists(int64_t id) return data.found; } +bool cpu_paging_enabled(const CPUState *cpu) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + + return cc->get_paging_enabled(cpu); +} + +static bool cpu_common_get_paging_enabled(const 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; diff --git a/target-i386/arch_memory_mapping.c b/target-i386/arch_memory_mapping.c index 5096fbdf44..c5a10ec9bd 100644 --- a/target-i386/arch_memory_mapping.c +++ b/target-i386/arch_memory_mapping.c @@ -241,7 +241,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; } @@ -273,7 +273,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; -} diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 4b2da0d750..f6fa7fa8b6 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -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(const 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 = { From 6d4d3ae77dbb756d454c2deb2ef844b0cc7bde7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 28 May 2013 14:20:15 +0200 Subject: [PATCH 09/17] memory_mapping: Move MemoryMappingList typedef to qemu/typedefs.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will avoid issues with hwaddr and ram_addr_t when including sysemu/memory_mapping.h for CONFIG_USER_ONLY, e.g., from qom/cpu.h. Signed-off-by: Andreas Färber --- include/qemu/typedefs.h | 2 ++ include/sysemu/memory_mapping.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index afe4ec76e1..698fc03d78 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -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; diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h index 6f01524451..1f71c327b1 100644 --- a/include/sysemu/memory_mapping.h +++ b/include/sysemu/memory_mapping.h @@ -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); From a23bbfda75118eb738acce84afd64965934828f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 28 May 2013 13:52:01 +0200 Subject: [PATCH 10/17] cpu: Turn cpu_get_memory_mapping() into a CPUState hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error reporting from return value to Error argument. Reviewed-by: Jens Freimann Reviewed-by: Luiz Capitulino [AF: Fixed cpu_get_memory_mapping() documentation] Signed-off-by: Andreas Färber --- include/qom/cpu.h | 13 +++++++++++++ include/sysemu/memory_mapping.h | 2 -- memory_mapping-stub.c | 6 ------ memory_mapping.c | 7 ++++--- qom/cpu.c | 16 ++++++++++++++++ target-i386/arch_memory_mapping.c | 12 +++++++----- target-i386/cpu-qom.h | 3 +++ target-i386/cpu.c | 1 + 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1f70240991..a5bb515978 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -23,6 +23,7 @@ #include #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,8 @@ typedef struct CPUClass { void (*do_interrupt)(CPUState *cpu); int64_t (*get_arch_id)(CPUState *cpu); bool (*get_paging_enabled)(const CPUState *cpu); + void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list, + Error **errp); const struct VMStateDescription *vmsd; int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, @@ -147,6 +151,15 @@ struct CPUState { */ bool cpu_paging_enabled(const CPUState *cpu); +/** + * cpu_get_memory_mapping: + * @cpu: The CPU whose memory mappings are to be obtained. + * @list: Where to write the memory mappings to. + * @errp: Pointer for reporting an #Error. + */ +void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, + Error **errp); + /** * cpu_write_elf64_note: * @f: pointer to a function that writes memory to a file diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h index 1f71c327b1..c47e6ee1fd 100644 --- a/include/sysemu/memory_mapping.h +++ b/include/sysemu/memory_mapping.h @@ -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, diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c index 6c0dfeb01c..989dc00f8b 100644 --- a/memory_mapping-stub.c +++ b/memory_mapping-stub.c @@ -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; -} diff --git a/memory_mapping.c b/memory_mapping.c index 0790aacc21..9bd24cecd2 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -183,13 +183,14 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) CPUArchState *env, *first_paging_enabled_cpu; RAMBlock *block; ram_addr_t offset, length; - int ret; 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); - if (ret < 0) { + Error *err = NULL; + cpu_get_memory_mapping(ENV_GET_CPU(env), list, &err); + if (err) { + error_free(err); return -1; } } diff --git a/qom/cpu.c b/qom/cpu.c index 9f6da0fdd8..b25fbc9f5a 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -62,6 +62,21 @@ static bool cpu_common_get_paging_enabled(const CPUState *cpu) return true; } +void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, + Error **errp) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + + return cc->get_memory_mapping(cpu, list, errp); +} + +static void cpu_common_get_memory_mapping(CPUState *cpu, + MemoryMappingList *list, + Error **errp) +{ + error_setg(errp, "Obtaining memory mappings is unsupported on this CPU."); +} + /* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers = NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); @@ -189,6 +204,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; diff --git a/target-i386/arch_memory_mapping.c b/target-i386/arch_memory_mapping.c index c5a10ec9bd..2566a040a6 100644 --- a/target-i386/arch_memory_mapping.c +++ b/target-i386/arch_memory_mapping.c @@ -239,11 +239,15 @@ static void walk_pml4e(MemoryMappingList *list, } #endif -int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env) +void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list, + Error **errp) { - 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; + return; } if (env->cr[4] & CR4_PAE_MASK) { @@ -269,7 +273,5 @@ int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env) pse = !!(env->cr[4] & CR4_PSE_MASK); walk_pde2(list, pde_addr, env->a20_mask, pse); } - - return 0; } diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 849cedf94c..e0ac072c5f 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -98,4 +98,7 @@ int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); +void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, + Error **errp); + #endif diff --git a/target-i386/cpu.c b/target-i386/cpu.c index f6fa7fa8b6..a7154af11d 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -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; From c22d8e0448aecb48a91f3936419ad1b63fbb4a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 28 May 2013 14:53:32 +0200 Subject: [PATCH 11/17] memory_mapping: Drop qemu_get_memory_mapping() stub MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dump.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. Signed-off-by: Andreas Färber --- Makefile.target | 4 +--- configure | 4 ---- memory_mapping-stub.c | 21 --------------------- 3 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 memory_mapping-stub.c diff --git a/Makefile.target b/Makefile.target index 1cafb176e3..f9e1d89365 100644 --- a/Makefile.target +++ b/Makefile.target @@ -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 diff --git a/configure b/configure index 1654413762..64017628c4 100755 --- a/configure +++ b/configure @@ -4298,10 +4298,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 diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c deleted file mode 100644 index 989dc00f8b..0000000000 --- a/memory_mapping-stub.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * QEMU memory mapping - * - * Copyright Fujitsu, Corp. 2011, 2012 - * - * Authors: - * Wen Congyang - * - * 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; -} From 2a78636bd204e389068d203473ec76558083b44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 17 May 2013 11:54:40 +0200 Subject: [PATCH 12/17] dump: Drop qmp_dump_guest_memory() stub and build for all targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qmp_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 and leave configure completely out of the picture for target CPU features. Signed-off-by: Andreas Färber --- Makefile.target | 2 +- configure | 4 ---- hmp-commands.hx | 2 -- stubs/dump.c | 8 -------- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Makefile.target b/Makefile.target index f9e1d89365..b0be124d29 100644 --- a/Makefile.target +++ b/Makefile.target @@ -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 diff --git a/configure b/configure index 64017628c4..c61d8620da 100755 --- a/configure +++ b/configure @@ -4303,10 +4303,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 diff --git a/hmp-commands.hx b/hmp-commands.hx index 396691a5d6..915b0d16fa 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -991,7 +991,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?", @@ -1015,7 +1014,6 @@ gdb. length: the memory size, in bytes. It's optional, and should be specified with begin together. ETEXI -#endif { .name = "snapshot_blkdev", diff --git a/stubs/dump.c b/stubs/dump.c index b3f42cb2f1..43c9a3fa02 100644 --- a/stubs/dump.c +++ b/stubs/dump.c @@ -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; From 6db297ea361f4e03c096a0f28f26b060f0060de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 9 Jun 2013 16:03:46 +0200 Subject: [PATCH 13/17] cpu: Change default for CPUClass::get_paging_enabled() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu_get_guest_memory_mapping() uses cpu_paging_enabled() to determine whether to use cpu_get_memory_mapping() to return mappings or whether to fall back to a simple identity map. Since by default CPUClass::get_memory_mapping() is not implemented, change the default to false to use the identity map by default. Reviewed-by: Jens Freimann Reviewed-by: Luiz Capitulino Signed-off-by: Andreas Färber --- qom/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qom/cpu.c b/qom/cpu.c index b25fbc9f5a..dba4a11edc 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -59,7 +59,7 @@ bool cpu_paging_enabled(const CPUState *cpu) static bool cpu_common_get_paging_enabled(const CPUState *cpu) { - return true; + return false; } void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, From 1b3509ca5bbd8e7d2be92ac42196a3ee2e31cb03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 9 Jun 2013 16:48:29 +0200 Subject: [PATCH 14/17] dump: Abstract dump_init() with cpu_synchronize_all_states() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of calling cpu_synchronize_state() for each CPU, call the existing cpu_synchronize_all_states() helper. Reviewed-by: Luiz Capitulino Signed-off-by: Andreas Färber --- dump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dump.c b/dump.c index c0d3da515b..87ca12cee0 100644 --- a/dump.c +++ b/dump.c @@ -21,6 +21,7 @@ #include "sysemu/dump.h" #include "sysemu/sysemu.h" #include "sysemu/memory_mapping.h" +#include "sysemu/cpus.h" #include "qapi/error.h" #include "qmp-commands.h" @@ -731,12 +732,12 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, * If the target architecture is not supported, cpu_get_dump_info() will * return -1. * - * if we use kvm, we should synchronize the register before we get dump + * If we use KVM, we should synchronize the registers before we get dump * info. */ + cpu_synchronize_all_states(); nr_cpus = 0; for (env = first_cpu; env != NULL; env = env->next_cpu) { - cpu_synchronize_state(env); nr_cpus++; } From 11ed09cf0753c1288a97f00138fc4534135442bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 29 May 2013 21:54:03 +0200 Subject: [PATCH 15/17] memory_mapping: Improve qemu_get_guest_memory_mapping() error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass any Error out into dump_init() and have it actually stop on errors. Whether it is unsupported on a certain CPU can be checked by looking for a NULL CPUClass::get_memory_mapping field. Reviewed-by: Luiz Capitulino [AF: Reverted changes to CPU loops] Signed-off-by: Andreas Färber --- dump.c | 7 ++++++- include/sysemu/memory_mapping.h | 8 +------- memory_mapping.c | 10 ++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/dump.c b/dump.c index 87ca12cee0..44a1339c8a 100644 --- a/dump.c +++ b/dump.c @@ -707,6 +707,7 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, { CPUArchState *env; int nr_cpus; + Error *err = NULL; int ret; if (runstate_is_running()) { @@ -757,7 +758,11 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, /* get memory mapping */ memory_mapping_list_init(&s->list); if (paging) { - qemu_get_guest_memory_mapping(&s->list); + qemu_get_guest_memory_mapping(&s->list, &err); + if (err != NULL) { + error_propagate(errp, err); + goto cleanup; + } } else { qemu_get_guest_simple_memory_mapping(&s->list); } diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h index c47e6ee1fd..6dfb68ddcd 100644 --- a/include/sysemu/memory_mapping.h +++ b/include/sysemu/memory_mapping.h @@ -45,13 +45,7 @@ void memory_mapping_list_free(MemoryMappingList *list); void memory_mapping_list_init(MemoryMappingList *list); -/* - * Return value: - * 0: success - * -1: failed - * -2: unsupported - */ -int qemu_get_guest_memory_mapping(MemoryMappingList *list); +void qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp); /* get guest's memory mapping without do paging(virtual address is 0). */ void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list); diff --git a/memory_mapping.c b/memory_mapping.c index 9bd24cecd2..5634f813cd 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -178,7 +178,7 @@ static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu) return NULL; } -int qemu_get_guest_memory_mapping(MemoryMappingList *list) +void qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp) { CPUArchState *env, *first_paging_enabled_cpu; RAMBlock *block; @@ -190,11 +190,11 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) Error *err = NULL; cpu_get_memory_mapping(ENV_GET_CPU(env), list, &err); if (err) { - error_free(err); - return -1; + error_propagate(errp, err); + return; } } - return 0; + return; } /* @@ -206,8 +206,6 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) length = block->length; create_new_memory_mapping(list, offset, offset, length); } - - return 0; } void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list) From 05318a858c1212d845d03f924e6ab5f22ab51ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 29 May 2013 21:03:31 +0200 Subject: [PATCH 16/17] spapr_rtas: Abstract rtas_query_cpu_stopped_state() with qemu_get_cpu() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of looping over all CPUArchState, use a helper to obtain the desired CPUState directly. Saves a CPUPPCState variable and QOM cast. Signed-off-by: Andreas Färber --- hw/ppc/spapr_rtas.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 8ecaa5f8ec..a1c3d204b6 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -130,7 +130,6 @@ static void rtas_query_cpu_stopped_state(sPAPREnvironment *spapr, uint32_t nret, target_ulong rets) { target_ulong id; - CPUPPCState *env; CPUState *cpu; if (nargs != 1 || nret != 2) { @@ -139,12 +138,8 @@ static void rtas_query_cpu_stopped_state(sPAPREnvironment *spapr, } id = rtas_ld(args, 0); - for (env = first_cpu; env; env = env->next_cpu) { - cpu = CPU(ppc_env_get_cpu(env)); - if (cpu->cpu_index != id) { - continue; - } - + cpu = qemu_get_cpu(id); + if (cpu != NULL) { if (cpu->halted) { rtas_st(rets, 1, 0); } else { From c67e216bdf42abfb8505790b2da9562356103976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 29 May 2013 21:06:39 +0200 Subject: [PATCH 17/17] spapr_rtas: Abstract rtas_start_cpu() with qemu_get_cpu() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of looping over all CPUArchState, use a helper to obtain the desired CPUState. Free the "cpu" variable for PowerPCCPU, to access its CPUPPCState. Signed-off-by: Andreas Färber --- hw/ppc/spapr_rtas.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index a1c3d204b6..f4bd3c9d86 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -160,8 +160,7 @@ static void rtas_start_cpu(sPAPREnvironment *spapr, uint32_t nret, target_ulong rets) { target_ulong id, start, r3; - CPUState *cpu; - CPUPPCState *env; + CPUState *cs; if (nargs != 3 || nret != 1) { rtas_st(rets, 0, -3); @@ -172,14 +171,12 @@ static void rtas_start_cpu(sPAPREnvironment *spapr, start = rtas_ld(args, 1); r3 = rtas_ld(args, 2); - for (env = first_cpu; env; env = env->next_cpu) { - cpu = CPU(ppc_env_get_cpu(env)); + cs = qemu_get_cpu(id); + if (cs != NULL) { + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; - if (cpu->cpu_index != id) { - continue; - } - - if (!cpu->halted) { + if (!cs->halted) { rtas_st(rets, 0, -1); return; } @@ -192,9 +189,9 @@ static void rtas_start_cpu(sPAPREnvironment *spapr, env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME); env->nip = start; env->gpr[3] = r3; - cpu->halted = 0; + cs->halted = 0; - qemu_cpu_kick(cpu); + qemu_cpu_kick(cs); rtas_st(rets, 0, 0); return;