From patchwork Tue Oct 18 19:22:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 683838 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sz4mV4cdmz9ryr for ; Wed, 19 Oct 2016 06:25:46 +1100 (AEDT) Received: from localhost ([::1]:43468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwa19-0000kT-C6 for incoming@patchwork.ozlabs.org; Tue, 18 Oct 2016 15:25:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwZzh-00081J-KY for qemu-devel@nongnu.org; Tue, 18 Oct 2016 15:24:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwZzg-0006Pe-EX for qemu-devel@nongnu.org; Tue, 18 Oct 2016 15:24:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwZza-0006M5-Fz; Tue, 18 Oct 2016 15:24:06 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2A1C90251; Tue, 18 Oct 2016 19:24:05 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9IJMt9m024602; Tue, 18 Oct 2016 15:23:54 -0400 From: Laurent Vivier To: Eduardo Habkost , Igor Mammedov , Bharata B Rao , David Gibson , Peter Maydell Date: Tue, 18 Oct 2016 21:22:53 +0200 Message-Id: <1476818573-5228-4-git-send-email-lvivier@redhat.com> In-Reply-To: <1476818573-5228-1-git-send-email-lvivier@redhat.com> References: <1476818573-5228-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Oct 2016 19:24:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 3/3] exec: call cpu_exec_exit() from a CPU unrealize common function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Green , qemu-devel@nongnu.org, Alexander Graf , Max Filippov , Greg Ungerer , "Edgar E . Iglesias" , Guan Xuetao , Jia Liu , Markus Armbruster , Artyom Tarasenko , Laurent Vivier , Andrew Jones , Chen Gang , Greg Kurz , qemu-arm@nongnu.org, Richard Henderson , Matthew Rosato , Bastian Koppelmann , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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() and ppc_cpu_unrealizefn() overwrite the device class unrealize function, add a call to a parent_unrealize pointer. Signed-off-by: Laurent Vivier --- exec.c | 2 +- include/qom/cpu.h | 2 +- qom/cpu.c | 8 +++++++- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 9 +++++++++ target-ppc/cpu-qom.h | 1 + target-ppc/translate_init.c | 9 ++++++++- 7 files changed, 28 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-qom.h b/target-i386/cpu-qom.h index 5dde658..07030d2 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -64,6 +64,7 @@ typedef struct X86CPUClass { bool kvm_required; DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; void (*parent_reset)(CPUState *cpu); } X86CPUClass; diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 3476d46..95ce067 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -3243,6 +3243,8 @@ out: static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp) { X86CPU *cpu = X86_CPU(dev); + X86CPUClass *xcc = X86_CPU_GET_CLASS(dev); + Error *local_err = NULL; #ifndef CONFIG_USER_ONLY cpu_remove_sync(CPU(dev)); @@ -3253,6 +3255,12 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp) object_unparent(OBJECT(cpu->apic_state)); cpu->apic_state = NULL; } + + xcc->parent_unrealize(dev, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } } typedef struct BitProperty { @@ -3502,6 +3510,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); xcc->parent_realize = dc->realize; + xcc->parent_unrealize = dc->unrealize; dc->realize = x86_cpu_realizefn; dc->unrealize = x86_cpu_unrealizefn; dc->props = x86_cpu_properties; diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 713deef..d46c31a 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -174,6 +174,7 @@ typedef struct PowerPCCPUClass { /*< public >*/ DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; void (*parent_reset)(CPUState *cpu); uint32_t pvr; diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 40dae70..208fa1e 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -9906,11 +9906,17 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) { PowerPCCPU *cpu = POWERPC_CPU(dev); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); CPUPPCState *env = &cpu->env; + Error *local_err = NULL; opc_handler_t **table, **table_2; int i, j, k; - cpu_exec_exit(CPU(dev)); + pcc->parent_unrealize(dev, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) { if (env->opcodes[i] == &invalid_handler) { @@ -10521,6 +10527,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;