From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiPhU-0004jo-Ar for qemu-devel@nongnu.org; Fri, 31 May 2013 09:49:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiPhS-0002MQ-Ay for qemu-devel@nongnu.org; Fri, 31 May 2013 09:49:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiPhS-0002MI-20 for qemu-devel@nongnu.org; Fri, 31 May 2013 09:48:58 -0400 Date: Fri, 31 May 2013 09:48:51 -0400 From: Luiz Capitulino Message-ID: <20130531094851.21b8c7ce@redhat.com> In-Reply-To: <1369926481-20720-7-git-send-email-afaerber@suse.de> References: <1369926481-20720-1-git-send-email-afaerber@suse.de> <1369926481-20720-7-git-send-email-afaerber@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH qom-cpu v3 6/9] cpu: Turn cpu_get_memory_mapping() into a CPUState hook List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?UTF-8?B?RsOkcmJlcg==?= Cc: pbonzini@redhat.com, qiaonuohan@cn.fujitsu.com, qemu-devel@nongnu.org On Thu, 30 May 2013 17:07:58 +0200 Andreas F=C3=A4rber wrote: > Signed-off-by: Andreas F=C3=A4rber > --- > 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(-) >=20 > 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" > =20 > typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaqu= e); > =20 > @@ -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. > =20 > const struct VMStateDescription *vmsd; > int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, > @@ -148,6 +151,14 @@ struct CPUState { > bool cpu_paging_enabled(CPUState *cpu); > =20 > /** > + * @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 > diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapp= ing.h > index 1f71c32..c47e6ee 100644 > --- a/include/sysemu/memory_mapping.h > +++ b/include/sysemu/memory_mapping.h > @@ -31,8 +31,6 @@ struct MemoryMappingList { > QTAILQ_HEAD(, MemoryMapping) head; > }; > =20 > -int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env); > - > /* > * add or merge the memory region [phys_addr, phys_addr + length) into t= he > * 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 6c0dfeb..989dc00 100644 > --- a/memory_mapping-stub.c > +++ b/memory_mapping-stub.c > @@ -19,9 +19,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *li= st) > { > return -2; > } > - > -int cpu_get_memory_mapping(MemoryMappingList *list, > - CPUArchState *env) > -{ > - return -1; > -} > diff --git a/memory_mapping.c b/memory_mapping.c > index 0790aac..481530a 100644 > --- a/memory_mapping.c > +++ b/memory_mapping.c > @@ -188,7 +188,7 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *= list) > first_paging_enabled_cpu =3D find_paging_enabled_cpu(first_cpu); > if (first_paging_enabled_cpu) { > for (env =3D first_paging_enabled_cpu; env !=3D NULL; env =3D en= v->next_cpu) { > - ret =3D cpu_get_memory_mapping(list, env); > + ret =3D cpu_get_memory_mapping(ENV_GET_CPU(env), list); > if (ret < 0) { > return -1; > } > diff --git a/qom/cpu.c b/qom/cpu.c > index ea7e676..e7e1c25 100644 > --- a/qom/cpu.c > +++ b/qom/cpu.c > @@ -62,6 +62,19 @@ static bool cpu_common_get_paging_enabled(CPUState *cp= u) > return true; > } > =20 > +int cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list) > +{ > + CPUClass *cc =3D 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 =3D > NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); > @@ -189,6 +202,7 @@ static void cpu_class_init(ObjectClass *klass, void *= data) > k->reset =3D cpu_common_reset; > k->get_arch_id =3D cpu_common_get_arch_id; > k->get_paging_enabled =3D cpu_common_get_paging_enabled; > + k->get_memory_mapping =3D cpu_common_get_memory_mapping; > k->write_elf32_qemunote =3D cpu_common_write_elf32_qemunote; > k->write_elf32_note =3D cpu_common_write_elf32_note; > k->write_elf64_qemunote =3D cpu_common_write_elf64_qemunote; > diff --git a/target-i386/arch_memory_mapping.c b/target-i386/arch_memory_= mapping.c > index c5a10ec..b117068 100644 > --- a/target-i386/arch_memory_mapping.c > +++ b/target-i386/arch_memory_mapping.c > @@ -239,9 +239,12 @@ static void walk_pml4e(MemoryMappingList *list, > } > #endif > =20 > -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 =3D X86_CPU(cs); > + CPUX86State *env =3D &cpu->env; > + > + if (!cpu_paging_enabled(cs)) { > /* paging is disabled */ > return 0; > } > diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h > index 849cedf..11a4b10 100644 > --- a/target-i386/cpu-qom.h > +++ b/target-i386/cpu-qom.h > @@ -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); > =20 > +int x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list); > + > #endif > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 7364e3b..1303892 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 =3D x86_cpu_get_arch_id; > cc->get_paging_enabled =3D x86_cpu_get_paging_enabled; > #ifndef CONFIG_USER_ONLY > + cc->get_memory_mapping =3D x86_cpu_get_memory_mapping; > cc->write_elf64_note =3D x86_cpu_write_elf64_note; > cc->write_elf64_qemunote =3D x86_cpu_write_elf64_qemunote; > cc->write_elf32_note =3D x86_cpu_write_elf32_note;