From nobody Tue Apr 30 13:35:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522417027732611.5117604400914; Fri, 30 Mar 2018 06:37:07 -0700 (PDT) Received: from localhost ([::1]:37700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1uDB-0007Rn-SY for importer@patchew.org; Fri, 30 Mar 2018 09:36:57 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D=3D 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 f= lags, abi_ulong newsp, =20 ts =3D 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 =3D cpu_copy(env); /* Init regs that differ from the parent. */ @@ -6364,9 +6368,6 @@ static int do_fork(CPUArchState *env, unsigned int fl= ags, abi_ulong newsp, cpu_set_tls (new_env, newtls); } =20 - /* 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); --=20 2.11.0