From patchwork Tue Apr 9 12:09:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 235061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8EAAF2C00C3 for ; Tue, 9 Apr 2013 22:09:53 +1000 (EST) Received: from localhost ([::1]:58394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPXN1-0002E9-EQ for incoming@patchwork.ozlabs.org; Tue, 09 Apr 2013 08:09:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPXMk-0002DW-8z for qemu-devel@nongnu.org; Tue, 09 Apr 2013 08:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPXMh-000735-Vj for qemu-devel@nongnu.org; Tue, 09 Apr 2013 08:09:34 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:58169) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPXMh-00072d-Hb for qemu-devel@nongnu.org; Tue, 09 Apr 2013 08:09:31 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 Apr 2013 13:06:09 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 Apr 2013 13:06:06 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 5CBC31B08067 for ; Tue, 9 Apr 2013 13:09:24 +0100 (BST) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r39C9EHW46661810 for ; Tue, 9 Apr 2013 12:09:14 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r39AuEMX015114 for ; Tue, 9 Apr 2013 06:56:15 -0400 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r39AuEIA015110; Tue, 9 Apr 2013 06:56:14 -0400 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 1122) id EE4B512243AD; Tue, 9 Apr 2013 14:09:22 +0200 (CEST) From: Jens Freimann To: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 9 Apr 2013 14:09:17 +0200 Message-Id: <1365509357-2568-1-git-send-email-jfrei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <515D3F55.7080205@suse.de> References: <515D3F55.7080205@suse.de> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13040912-5024-0000-0000-000005B1E0CE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.107 Cc: Peter Maydell , Alexander Graf , qemu-devel , Rabin Vincent , Jens Freimann Subject: [Qemu-devel] [RFC] make write_elf_xx functions part of CPUClass, use CPUState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi Andreas, not sure if this is what you had in mind. Does it at least go into the right direction? It is pretty much untested and won't compile as is. I just wanted to get your opinion before putting more work into this. This patch adds 4 write_elf_XX functions to the CPUClass which can be implemented by XXXCPUState, e.g. S390CPUstate. Would it make sense to have paging_enabled/HAVE_MEMORY_MAPPING also as a property of the CPU object? Signed-off-by: Jens Freimann --- dump.c | 28 +++++++++++++++++++++++---- include/qom/cpu.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/dump.h | 9 +-------- qom/cpu.c | 44 +++++++++++++++++++++++++++++++++++++++++++ target-s390x/arch_dump.c | 25 ++++-------------------- target-s390x/arch_dump.h | 14 ++++++++++++++ target-s390x/cpu.c | 6 ++++++ 7 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 target-s390x/arch_dump.h diff --git a/dump.c b/dump.c index 574c292..df49845 100644 --- a/dump.c +++ b/dump.c @@ -272,13 +272,19 @@ static int write_elf64_notes(DumpState *s) { CPUArchState *env; CPUState *cpu; + CPUClass *cc; int ret; int id; for (env = first_cpu; env != NULL; env = env->next_cpu) { cpu = ENV_GET_CPU(env); + cc = CPU_GET_CLASS(cpu); id = cpu_index(cpu); - ret = cpu_write_elf64_note(fd_write_vmcore, env, id, s); + if (cc->write_elf64_note) + ret = cc->write_elf64_note(fd_write_vmcore, cpu, id, s); + else { + ret = 0; + } if (ret < 0) { dump_error(s, "dump: failed to write elf notes.\n"); return -1; @@ -286,7 +292,11 @@ static int write_elf64_notes(DumpState *s) } for (env = first_cpu; env != NULL; env = env->next_cpu) { - ret = cpu_write_elf64_qemunote(fd_write_vmcore, env, s); + if (cc->write_elf64_qemunote) + ret = cc->write_elf64_qemunote(fd_write_vmcore, cpu, s); + else { + ret = 0; + } if (ret < 0) { dump_error(s, "dump: failed to write CPU status.\n"); return -1; @@ -324,13 +334,19 @@ static int write_elf32_notes(DumpState *s) { CPUArchState *env; CPUState *cpu; + CPUClass *cc; int ret; int id; for (env = first_cpu; env != NULL; env = env->next_cpu) { cpu = ENV_GET_CPU(env); + cc = CPU_GET_CLASS(cpu); id = cpu_index(cpu); - ret = cpu_write_elf32_note(fd_write_vmcore, env, id, s); + if (cc->write_elf32_note) { + ret = cc->write_elf32_note(fd_write_vmcore, cpu, id, s); + } else { + ret = 0; + } if (ret < 0) { dump_error(s, "dump: failed to write elf notes.\n"); return -1; @@ -338,7 +354,11 @@ static int write_elf32_notes(DumpState *s) } for (env = first_cpu; env != NULL; env = env->next_cpu) { - ret = cpu_write_elf32_qemunote(fd_write_vmcore, env, s); + if (cc->write_elf32_qemunote) { + ret = cc->write_elf32_qemunote(fd_write_vmcore, cpu, s); + } else { + ret = 0; + } if (ret < 0) { dump_error(s, "dump: failed to write CPU status.\n"); return -1; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index ab2657c..53199f1 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -24,6 +24,8 @@ #include "hw/qdev-core.h" #include "qemu/thread.h" +typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque); + /** * SECTION:cpu * @section_id: QEMU-cpu @@ -55,6 +57,14 @@ typedef struct CPUClass { ObjectClass *(*class_by_name)(const char *cpu_model); void (*reset)(CPUState *cpu); + int (*write_elf64_note)(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque); + int (*write_elf64_qemunote)(write_core_dump_function f, CPUState *cpu, + void *opaque); + int (*write_elf32_note)(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque); + int (*write_elf32_qemunote)(write_core_dump_function f, CPUState *cpu, + void *opaque); } CPUClass; struct KVMState; @@ -116,6 +126,45 @@ struct CPUState { int cpu_index; /* used by alpha TCG */ }; +/** + * cpu_write_elf64_note: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque); + +/** + * cpu_write_elf64_qemunote: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf64_qemunote(write_core_dump_function f, CPUState *cpu, + void *opaque); + +/** + * cpu_write_elf32_note: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf32_note(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque); + +/** + * cpu_write_elf32_qemunote: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf32_qemunote(write_core_dump_function f, CPUState *cpu, + void *opaque); /** * cpu_reset: diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index b03efd4..e5f9f7d 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -16,6 +16,7 @@ #include "qapi/error.h" #include "include/qapi/qmp/qerror.h" +#include "qom/cpu.h" typedef struct ArchDumpInfo { int d_machine; /* Architecture */ @@ -24,14 +25,6 @@ typedef struct ArchDumpInfo { } ArchDumpInfo; typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque); -int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaque); -int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaque); -int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env, - void *opaque); -int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env, - void *opaque); int cpu_get_dump_info(ArchDumpInfo *info); ssize_t cpu_get_note_size(int class, int machine, int nr_cpus); diff --git a/qom/cpu.c b/qom/cpu.c index 0a2194d..e2822d0 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -21,6 +21,50 @@ #include "qom/cpu.h" #include "qemu-common.h" +int cpu_write_elf32_qemunote(write_core_dump_function f, CPUState *cpu, + void *opaque) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + + if (klass->write_elf32_qemunote != NULL) { + return (*klass->write_elf32_qemunote)(f, cpu, opaque); + } + return -1; +} + +int cpu_write_elf32_note(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + + if (klass->write_elf32_note != NULL) { + return (*klass->write_elf32_note)(f, cpu, cpuid, opaque); + } + return -1; +} + +int cpu_write_elf64_qemunote(write_core_dump_function f, CPUState *cpu, + void *opaque) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + + if (klass->write_elf64_note != NULL) { + return (*klass->write_elf64_qemunote)(f, cpu, opaque); + } + return -1; +} + +int cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + + if (klass->write_elf64_note != NULL) { + return (*klass->write_elf64_note)(f, cpu, cpuid, opaque); + } + return -1; +} + void cpu_reset(CPUState *cpu) { CPUClass *klass = CPU_GET_CLASS(cpu); diff --git a/target-s390x/arch_dump.c b/target-s390x/arch_dump.c index 18f2652..c594874 100644 --- a/target-s390x/arch_dump.c +++ b/target-s390x/arch_dump.c @@ -13,6 +13,7 @@ #include "cpu.h" #include "elf.h" +#include "arch_dump.h" #include "exec/cpu-all.h" #include "sysemu/dump.h" #include "sysemu/kvm.h" @@ -186,10 +187,11 @@ static int s390x_write_all_elf64_notes(const char *note_name, write_core_dump_fu } -int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, +int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu, int cpuid, void *opaque) { - return s390x_write_all_elf64_notes("CORE", f, env, cpuid, opaque); + S390CPU *_cpu = S390_CPU(cpu); + return s390x_write_all_elf64_notes("CORE", f, &_cpu->env, cpuid, opaque); } int cpu_get_dump_info(ArchDumpInfo *info) @@ -222,25 +224,6 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) } -int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaque) -{ - return 0; -} - - -int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env, - void *opaque) -{ - return 0; -} - -int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env, - void *opaque) -{ - return 0; -} - int arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length, Error **errp) { diff --git a/target-s390x/arch_dump.h b/target-s390x/arch_dump.h new file mode 100644 index 0000000..8ebc24e --- /dev/null +++ b/target-s390x/arch_dump.h @@ -0,0 +1,14 @@ +/* + * dump guest memory implementation + * + * Copyright 2012 IBM Corp. + * Author(s): Jens Freimann + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu, + int cpuid, void *opaque); + diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 14a9e9d..14b25d8 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -27,6 +27,7 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "hw/hw.h" +#include "arch_dump.h" #ifndef CONFIG_USER_ONLY #include "hw/s390x/sclp.h" #include "sysemu/arch_init.h" @@ -231,6 +232,11 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) scc->parent_reset = cc->reset; cc->reset = s390_cpu_reset; + cc->write_elf64_note = s390_cpu_write_elf64_note; + cc->write_elf64_qemunote = NULL; + cc->write_elf32_note = NULL; + cc->write_elf32_qemunote = NULL; + dc->vmsd = &vmstate_s390_cpu; }