From patchwork Wed Jun 5 13:10:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 249042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 39E452C0082 for ; Wed, 5 Jun 2013 23:11:00 +1000 (EST) Received: from localhost ([::1]:59574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkDUP-0004Ha-F1 for incoming@patchwork.ozlabs.org; Wed, 05 Jun 2013 09:10:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkDTt-0004Cc-TK for qemu-devel@nongnu.org; Wed, 05 Jun 2013 09:10:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkDTs-000690-9A for qemu-devel@nongnu.org; Wed, 05 Jun 2013 09:10:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33624 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkDTr-00068n-TB for qemu-devel@nongnu.org; Wed, 05 Jun 2013 09:10:24 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 419DBA50DE; Wed, 5 Jun 2013 15:10:23 +0200 (CEST) Message-ID: <51AF38BD.5090907@suse.de> Date: Wed, 05 Jun 2013 15:10:21 +0200 From: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= Organization: SUSE LINUX Products GmbH User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: Luiz Capitulino References: <1369926481-20720-1-git-send-email-afaerber@suse.de> <1369926481-20720-7-git-send-email-afaerber@suse.de> <20130531094851.21b8c7ce@redhat.com> In-Reply-To: <20130531094851.21b8c7ce@redhat.com> X-Enigmail-Version: 1.6a1pre X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: pbonzini@redhat.com, qiaonuohan@cn.fujitsu.com, qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH qom-cpu v3 6/9] cpu: Turn cpu_get_memory_mapping() into a CPUState hook 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 Am 31.05.2013 15:48, schrieb Luiz Capitulino: > On Thu, 30 May 2013 17:07:58 +0200 > Andreas Färber wrote: > >> Signed-off-by: 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(-) >> >> diff --git a/include/qom/cpu.h b/include/qom/cpu.h >> index cf5fec2..93a4612 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,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); > > Would be nice to take an Error argument and fill it properly when > get_memory_mapping() is not implemented. Done. Andreas diff --cc include/qom/cpu.h index 1f70240,93a4612..0000000 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@@ -63,7 -65,8 +65,9 @@@ 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); - int (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list); + 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, @@@ -145,9 -148,17 +149,19 @@@ struct CPUState * * Returns: %true if paging is enabled, %false otherwise. */ -bool cpu_paging_enabled(CPUState *cpu); +bool cpu_paging_enabled(const CPUState *cpu); /** + * @cpu: The CPU whose memory mappings are to be obtained. + * @list: Where to write the memory mappings to. ++ * @errp: Pointer for reporting an #Error. + * + * Returns: 0 if successful. + */ -int cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list); ++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 * @cpu: The CPU whose memory is to be dumped #endif diff --git a/memory_mapping.c b/memory_mapping.c index 481530a..9bd24ce 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(ENV_GET_CPU(env), list); - 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 97063e1..b25fbc9 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -62,17 +62,19 @@ static bool cpu_common_get_paging_enabled(const CPUState *cpu) return true; } -int cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list) +void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, + Error **errp) { CPUClass *cc = CPU_GET_CLASS(cpu); - return cc->get_memory_mapping(cpu, list); + return cc->get_memory_mapping(cpu, list, errp); } -static int cpu_common_get_memory_mapping(CPUState *cpu, - MemoryMappingList *list) +static void cpu_common_get_memory_mapping(CPUState *cpu, + MemoryMappingList *list, + Error **errp) { - return -1; + error_setg(errp, "Obtaining memory mappings is unsupported on this CPU."); } /* CPU hot-plug notifiers */ diff --git a/target-i386/arch_memory_mapping.c b/target-i386/arch_memory_mapping.c index b117068..2566a04 100644 --- a/target-i386/arch_memory_mapping.c +++ b/target-i386/arch_memory_mapping.c @@ -239,14 +239,15 @@ static void walk_pml4e(MemoryMappingList *list, } #endif -int x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list) +void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list, + Error **errp) { 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) { @@ -272,7 +273,5 @@ int x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list) 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 11a4b10..e0ac072 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -98,6 +98,7 @@ 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); +void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, + Error **errp);