From nobody Tue Feb 10 06:26:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589391402; cv=none; d=zohomail.com; s=zohoarc; b=OyESRgubCjIeoJFx98+wtB7GOku+qnufCUJXUTN4IluHUMnGpXn2HI8MokQrPwZ4MScNAf4Xw2lfEkWHGKnAZ5ff3yLHzZPschUMeLlON7XysvA76b/AsUhuZvkrNOe29AITCyHV8SQ7E37k5YV1GxLi3KbQvD1wJ7Zpu6SLgi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589391402; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AurL0SAZRHpkVWbSIjSJmyFw3W3Or7KduKRq6WmTvNA=; b=L8gFFuKVKZSaMd9D1RxZLXs/+be8P0PZC60v1MUWGv+4J82tEcZzLGMr3dJy7RzDBOLKLjNAs0o3+WTjBGvlZfREKdUiNWjVx5zoF/b0sEE0Ww2SuXE89vRw+ZqGDZy2yAu7lF9uL538OJR6QaICLM+a/pHrR51Ipiszmq0VK/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589391402761879.8706913566593; Wed, 13 May 2020 10:36:42 -0700 (PDT) Received: from localhost ([::1]:47072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYvJB-00038F-3e for importer@patchew.org; Wed, 13 May 2020 13:36:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvEt-0004pu-6C for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:15 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:33180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYvEs-0007nB-7s for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:14 -0400 Received: by mail-wr1-x443.google.com with SMTP id l11so496533wru.0 for ; Wed, 13 May 2020 10:32:13 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y3sm210170wrm.64.2020.05.13.10.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 10:32:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6DA8E1FF92; Wed, 13 May 2020 18:32:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AurL0SAZRHpkVWbSIjSJmyFw3W3Or7KduKRq6WmTvNA=; b=NOSgJ89BSMgdetJsU+IaXENbLCZyAC8NzNSwJDcpivO8AkDsH2Spgd5q6zhAIrTF0f VQloZO6Pq+h7VPfuzZjMRf/55WoM9Cmm6DV6NHEN84c6PC5qBx5K/1itP4bqYycqg1Le wvAjioxDwCbrhraHXdt1yx+Lq60wCRYi2xxP2e0dqb/UUx9A7LDhRt465dTktF4V+KYq 1P1iHSPCJZah1zVh48pbseJuEb5/FMD9HI56mwBMTs+AzmDcR9vI+c63YJ+Bc5Ho5lsc 4vXVvI4KLBbYkEqK7j/eJz3iZGKfmt0QvzTFh9+rPkwcVsCKHGjN8qbyj7xRi0fXyczr kzJw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=AurL0SAZRHpkVWbSIjSJmyFw3W3Or7KduKRq6WmTvNA=; b=o5Yh/OPPR8zeim4p/1T+10clCGU3C6wjDV8hZj9nOgd2M5SkkvRlEXSMPtrW7D2LEC GmvyAiClWVrUTyywVSzmVAm2ZF41HX/SzZ5tw2TpzpJeXD9v6fXRzVtjBjUzb/wtNV7o qlShszes7ztgR7kydUsqhr88LHYXM+vd9ySflwzrn5SbqCrFuhriwzDX4xUwTFGmCGpu HA9JgGtgQpIMP9Bssuq9GMPtTAa9fXQ6wf8DZt2Sxukxkm4cQHBVQE0HRuuJY5B1GgaN gjs179DCWyZjxb/kQekfpHyfgAcAk9FPFeEWNuMbeouJ7FcQIqbDpFuzCd0ggCv3rOt2 Z/jw== X-Gm-Message-State: AOAM533Lob9kNe/Nr8AhrscDe4iWZApYKvnX9uZk42WT21utPxJ6WTtU zP/5CW6HCbv8aQrAXpNoWQrqUQ== X-Google-Smtp-Source: ABdhPJyUHp4evpHBWv8Wc8iM9jFH7MZkmLJDCDtUbVy7y+mQKvoCrFRhgR5+0VKWKpAM9PLlGzD2pg== X-Received: by 2002:a5d:460d:: with SMTP id t13mr469692wrq.280.1589391132861; Wed, 13 May 2020 10:32:12 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 6/8] linux-user: properly "unrealize" vCPU object Date: Wed, 13 May 2020 18:31:58 +0100 Message-Id: <20200513173200.11830-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200513173200.11830-1-alex.bennee@linaro.org> References: <20200513173200.11830-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Nikolay Igotti Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We shouldn't be messing around with the CPU list in linux-user save for the very special case of do_fork(). When threads end we need to properly follow QOM object lifetime handling and allow the eventual cpu_common_unrealizefn to both remove the CPU and ensure any clean-up actions are taken place, for example calling plugin exit hooks. There is still a race condition to avoid so use the linux-user specific clone_lock instead of the cpu_list_lock to avoid it. Signed-off-by: Alex Benn=C3=A9e Cc: Nikolay Igotti Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/syscall.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff0..7f6700c54e3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7635,30 +7635,33 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, return -TARGET_ERESTARTSYS; } =20 - cpu_list_lock(); + pthread_mutex_lock(&clone_lock); =20 if (CPU_NEXT(first_cpu)) { - TaskState *ts; + TaskState *ts =3D cpu->opaque; =20 - /* Remove the CPU from the list. */ - QTAILQ_REMOVE_RCU(&cpus, cpu, node); + object_property_set_bool(OBJECT(cpu), false, "realized", NULL); + object_unref(OBJECT(cpu)); + /* + * At this point the CPU should be unrealized and removed + * from cpu lists. We can clean-up the rest of the thread + * data without the lock held. + */ =20 - cpu_list_unlock(); + pthread_mutex_unlock(&clone_lock); =20 - ts =3D cpu->opaque; if (ts->child_tidptr) { put_user_u32(0, ts->child_tidptr); do_sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, NULL, NULL, 0); } thread_cpu =3D NULL; - object_unref(OBJECT(cpu)); g_free(ts); rcu_unregister_thread(); pthread_exit(NULL); } =20 - cpu_list_unlock(); + pthread_mutex_unlock(&clone_lock); preexit_cleanup(cpu_env, arg1); _exit(arg1); return 0; /* avoid warning */ --=20 2.20.1