From patchwork Thu Jul 21 15:54:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 9241877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B29B602F0 for ; Thu, 21 Jul 2016 15:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09BB127C39 for ; Thu, 21 Jul 2016 15:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED84627F46; Thu, 21 Jul 2016 15:55:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 36D8227C39 for ; Thu, 21 Jul 2016 15:55:33 +0000 (UTC) Received: from localhost ([::1]:41651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGJw-0002XU-Mu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 11:55:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGJI-0002VY-3D for qemu-devel@nongnu.org; Thu, 21 Jul 2016 11:54:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQGJG-0007ys-46 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 11:54:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGJF-0007yn-UI; Thu, 21 Jul 2016 11:54:50 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 6AC38A795; Thu, 21 Jul 2016 15:54:49 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6LFsf1l011051; Thu, 21 Jul 2016 11:54:47 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 21 Jul 2016 17:54:33 +0200 Message-Id: <1469116479-233280-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1469116479-233280-1-git-send-email-imammedo@redhat.com> References: <1469116479-233280-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 21 Jul 2016 15:54:49 +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 2/8] exec: don't use cpu_index to detect if cpu_exec_init()'s been called for cpu 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: Riku Voipio , Eduardo Habkost , "Michael S. Tsirkin" , Peter Crosthwaite , Alexander Graf , qemu-ppc@nongnu.org, Bharata B Rao , Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- include/qemu/queue.h | 2 ++ exec.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index c2b6c81..2c2c74b 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -407,6 +407,7 @@ struct { \ else \ (head)->tqh_last = (elm)->field.tqe_prev; \ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + (elm)->field.tqe_prev = NULL; \ } while (/*CONSTCOND*/0) #define QTAILQ_FOREACH(var, head, field) \ @@ -430,6 +431,7 @@ struct { \ #define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL) #define QTAILQ_FIRST(head) ((head)->tqh_first) #define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_prev) #define QTAILQ_LAST(head, headname) \ (*(((struct headname *)((head)->tqh_last))->tqh_last)) diff --git a/exec.c b/exec.c index 2f57c62..8c5da32 100644 --- a/exec.c +++ b/exec.c @@ -643,8 +643,8 @@ 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 (!QTAILQ_IN_USE(cpu, node)) { + /* there is nothing to undo since cpu_exec_init() hasn't been called */ cpu_list_unlock(); return; }