Received: from eggs.gnu.org ([2001:4830:134:3::10]:52731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPq0-0000e1-BQ for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSPpy-0005Gp-9f for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58308) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPpy-0005Gi-3w for qemu-devel@nongnu.org; Wed, 27 Jul 2016 10:29:30 -0400 From: Eduardo Habkost Date: Wed, 27 Jul 2016 11:29:14 -0300 Message-Id: <1469629761-23274-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1469629761-23274-1-git-send-email-ehabkost@redhat.com> References: <1469629761-23274-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PULL 2/9] exec: Don't use cpu_index to detect if cpu_exec_init()'s been called List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Paolo Bonzini , Richard Henderson , Marcel Apfelbaum , qemu-devel@nongnu.org, Igor Mammedov From: Igor Mammedov Instead use QTAIL's tqe_prev field to detect if cpu's been placed in list by cpu_exec_init() which is always set if QTAIL element is in list. Fixes SIGSEGV on failure path in case cpu_index is assigned by board and cpu.relalize() fails before cpu_exec_init() is called. In follow up patches, cpu_index will be assigned by boards that support cpu hot(un)plug and need stable cpu_index that doesn't depend on order cpus are created/removed. Signed-off-by: Igor Mammedov Reported-by: David Gibson Reviewed-by: David Gibson Signed-off-by: Eduardo Habkost --- exec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 2f57c62..ae45a70 100644 --- a/exec.c +++ b/exec.c @@ -643,13 +643,14 @@ void cpu_exec_exit(CPUState *cpu) CPUClass *cc = CPU_GET_CLASS(cpu); cpu_list_lock(); - if (cpu->cpu_index == -1) { - /* cpu_index was never allocated by this @cpu or was already freed. */ + if (cpu->node.tqe_prev == NULL) { + /* there is nothing to undo since cpu_exec_init() hasn't been called */ cpu_list_unlock(); return; } QTAILQ_REMOVE(&cpus, cpu, node); + cpu->node.tqe_prev = NULL; cpu_release_index(cpu); cpu->cpu_index = -1; cpu_list_unlock(); -- 2.5.5