From patchwork Fri Mar 30 13:35:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10317715 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 4042860212 for ; Fri, 30 Mar 2018 13:36:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 206532A55E for ; Fri, 30 Mar 2018 13:36:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 146842A565; Fri, 30 Mar 2018 13:36:38 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 B25492A55E for ; Fri, 30 Mar 2018 13:36:37 +0000 (UTC) Received: from localhost ([::1]:37700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1uCr-0007Rn-0R for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Mar 2018 09:36:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1uC5-00071T-8Z for qemu-devel@nongnu.org; Fri, 30 Mar 2018 09:35:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1uC4-0003op-GF for qemu-devel@nongnu.org; Fri, 30 Mar 2018 09:35:49 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:37243) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1uC4-0003nN-7u for qemu-devel@nongnu.org; Fri, 30 Mar 2018 09:35:48 -0400 Received: by mail-lf0-x241.google.com with SMTP id m200-v6so6855626lfm.4 for ; Fri, 30 Mar 2018 06:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=WAO7hcro+JkumZ8o0w/z46RnccYOEg7LcIV6j7v02ks=; b=YGGrHnFO5NCVun1hv7Qq1OqmbYnUFUKyfu2cfzEGlExP24Hl60V8CEaGHV/cfAxqtM Y/QjpvJwoanVeGpO2VlvJ+YLA/YOU0HxXGF5gszaGlesx912cKqLZSCq0dymMryFPKSA 52Ba57kzX8Brho0bbIVDuNqtLeqRDpKDoyd3R9C5RcIc6sXdYO9sUwMMVBbkQLAHxiIP YaeafY4EeOnF2Mdemj5jJA9UMmuBa2l4dOR4WdjE7GPi/EyIWYNQwEX3SJlzOmV28Jh5 p5+ViQujkN10/2IwNW6b5HLZz8toMyjmGrMzDaa7m6CwmaTZ7SGHWxigCMWsBGZWnq9U SszQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WAO7hcro+JkumZ8o0w/z46RnccYOEg7LcIV6j7v02ks=; b=T6JaCybEYp6spFVemdAtg8x7cCCtdTjmcP/rTUb2rz0Igqo/It8Yi4Eac5RO1G90RF e22wleus2DHZW+OYPYabtHwXhih5mWRvTvpLIng+jwRY8Y2vfJtGLiU4DUu3+4zkVhgW OV0yvRQZNt2qyKkMDDZ/xLCQWWneGYLW84RUsosuFkylD3K9Y1fFcaYhXXFjMIdTsnKk hjJbOt0cxqAYpdfjV5t9ZpAE3nY9gLXxcn0BG/8/surU/XOZ6NlCx6NUvDXpYTgwzof8 tBxUUPvrrMkJWHG89Y4wqor32cpNbun3DD6NqnIux5ACnFzqnCk2j15sbCUEf+yrcsxN 69Jg== X-Gm-Message-State: AElRT7EfFxxe3BqWid04Iy4id5OJO1bnXM7DsFPrUs0+XQ9ZWwWSHYxv TMztdgUVzxbc5utb1PBFmARoiw== X-Google-Smtp-Source: AIpwx4/cxq+S+70dhClDivdQfy7dr5++Ufo8eXQUmtxhM3bQ79trti9u2aXzScO0qQteQnSBDxi7fg== X-Received: by 2002:a19:4847:: with SMTP id v68-v6mr7825520lfa.63.1522416946694; Fri, 30 Mar 2018 06:35:46 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net. (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id b8sm1458423ljj.44.2018.03.30.06.35.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Mar 2018 06:35:46 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 30 Mar 2018 06:35:25 -0700 Message-Id: <20180330133525.10994-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH] linux-user: call cpu_copy under clone_lock 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: Max Filippov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP cpu_copy adds newly created CPU object to container/machine/unattached, but does it w/o proper locking. As a result when multiple threads are created rapidly QEMU may abort with the following message: GLib-CRITICAL **: g_hash_table_iter_next: assertion 'ri->version == ri->hash_table->version' failed ERROR:qemu/qom/object.c:1663:object_get_canonical_path_component: code should not be reached Move cpu_copy invocation under clone_lock to fix that. Signed-off-by: Max Filippov Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 889abbda1e65..18ea79140f16 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6346,6 +6346,10 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, ts = g_new0(TaskState, 1); init_task_state(ts); + + /* Grab a mutex so that thread setup appears atomic. */ + pthread_mutex_lock(&clone_lock); + /* we create a new CPU instance. */ new_env = cpu_copy(env); /* Init regs that differ from the parent. */ @@ -6364,9 +6368,6 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, cpu_set_tls (new_env, newtls); } - /* Grab a mutex so that thread setup appears atomic. */ - pthread_mutex_lock(&clone_lock); - memset(&info, 0, sizeof(info)); pthread_mutex_init(&info.mutex, NULL); pthread_mutex_lock(&info.mutex);