Received: from eggs.gnu.org ([2001:4830:134:3::10]:44089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bw68R-0000wb-49 for qemu-devel@nongnu.org; Mon, 17 Oct 2016 07:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bw68N-00078O-0T for qemu-devel@nongnu.org; Mon, 17 Oct 2016 07:31:15 -0400 Date: Mon, 17 Oct 2016 13:30:56 +0200 From: Igor Mammedov Message-ID: <20161017133056.739fa6fd@nial.brq.redhat.com> In-Reply-To: <1476485569-6744-4-git-send-email-lvivier@redhat.com> References: <1476485569-6744-1-git-send-email-lvivier@redhat.com> <1476485569-6744-4-git-send-email-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 3/3] exec: call cpu_exec_exit() from a CPU unrealize common function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier Cc: Eduardo Habkost , Bharata B Rao , David Gibson , Peter Maydell , Matthew Rosato , Jia Liu , Max Filippov , Markus Armbruster , Anthony Green , "Edgar E . Iglesias" , Alexander Graf , Bastian Koppelmann , qemu-devel@nongnu.org, Greg Kurz , Michael Walle , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Aurelien Jarno , Greg Ungerer , Paolo Bonzini , Chen Gang , Guan Xuetao , Artyom Tarasenko , Richard Henderson On Sat, 15 Oct 2016 00:52:49 +0200 Laurent Vivier wrote: > As cpu_exec_exit() mirrors the cpu_exec_realizefn(), > rename it as cpu_exec_unrealizefn(). > > Create and register a cpu_common_unrealizefn() function for > the CPU device class and call cpu_exec_unrealizefn() from > this function. > > Remove cpu_exec_exit() from cpu_common_finalize() > (which mirrors init, not realize), and as x86_cpu_unrealizefn() > overwrites the device class unrealize function, add a call to > cpu_exec_unrealizefn() (as in ppc_cpu_unrealizefn()). > > Signed-off-by: Laurent Vivier > --- > exec.c | 2 +- > include/qom/cpu.h | 2 +- > qom/cpu.c | 8 +++++++- > target-i386/cpu.c | 2 ++ > target-ppc/translate_init.c | 2 +- > 5 files changed, 12 insertions(+), 4 deletions(-) > > diff --git a/exec.c b/exec.c > index 203eb52..3cd25db 100644 > --- a/exec.c > +++ b/exec.c > @@ -596,7 +596,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) > } > #endif > > -void cpu_exec_exit(CPUState *cpu) > +void cpu_exec_unrealizefn(CPUState *cpu) > { > CPUClass *cc = CPU_GET_CLASS(cpu); > > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 5520c6c..633c3fc 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -948,7 +948,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) > GCC_FMT_ATTR(2, 3); > void cpu_exec_initfn(CPUState *cpu); > void cpu_exec_realizefn(CPUState *cpu, Error **errp); > -void cpu_exec_exit(CPUState *cpu); > +void cpu_exec_unrealizefn(CPUState *cpu); > > #ifdef CONFIG_SOFTMMU > extern const struct VMStateDescription vmstate_cpu_common; > diff --git a/qom/cpu.c b/qom/cpu.c > index 85f1132..03d9190 100644 > --- a/qom/cpu.c > +++ b/qom/cpu.c > @@ -345,6 +345,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) > trace_init_vcpu(cpu); > } > > +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp) > +{ > + CPUState *cpu = CPU(dev); > + cpu_exec_unrealizefn(cpu); > +} > + > static void cpu_common_initfn(Object *obj) > { > CPUState *cpu = CPU(obj); > @@ -369,7 +375,6 @@ static void cpu_common_initfn(Object *obj) > static void cpu_common_finalize(Object *obj) > { > CPUState *cpu = CPU(obj); > - cpu_exec_exit(cpu); > g_free(cpu->trace_dstate); > } > > @@ -403,6 +408,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) > k->cpu_exec_exit = cpu_common_noop; > k->cpu_exec_interrupt = cpu_common_exec_interrupt; > dc->realize = cpu_common_realizefn; > + dc->unrealize = cpu_common_unrealizefn; > /* > * Reason: CPUs still need special care by board code: wiring up > * IRQs, adding reset handlers, halting non-first CPUs, ... > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 3476d46..399a3e4 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -3253,6 +3253,8 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp) > object_unparent(OBJECT(cpu->apic_state)); > cpu->apic_state = NULL; > } > + > + cpu_exec_unrealizefn(CPU(dev)); perhaps it should mirror the same pattern as realize override i.e. child class is it has it's own unrealize() should have parent_unrealize field where it save original unrealize pointer before override. grep for parent_realize to see used pattern. > } > > typedef struct BitProperty { > diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c > index 40dae70..2de6a06 100644 > --- a/target-ppc/translate_init.c > +++ b/target-ppc/translate_init.c > @@ -9910,7 +9910,7 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) > opc_handler_t **table, **table_2; > int i, j, k; > > - cpu_exec_exit(CPU(dev)); > + cpu_exec_unrealizefn(CPU(dev)); > > for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) { > if (env->opcodes[i] == &invalid_handler) {