From patchwork Tue Nov 23 20:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 519341 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp9240556imj; Tue, 23 Nov 2021 13:02:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlbwbK1L1cW8T+XBLPM0CFo7iI5eRKwOt1s3koy+mfpZiNt3WlHTaE3SiRFGW/Sd8cMJd8 X-Received: by 2002:a05:6000:12d2:: with SMTP id l18mr11402562wrx.289.1637701336753; Tue, 23 Nov 2021 13:02:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637701336; cv=none; d=google.com; s=arc-20160816; b=HM8T8AbHeJ1mq6yQF/jXQq05p1IDkesVEUgW62WKXd/r0zhZw67GTVP/jxAM5qLmeU zTWiGifUElDBpBA5Icnn7YVlh/zRr59EFtpvbe1tjcYl8EL3usax/st5TsW109TwSdAx ilUJm+g6Sp/z+YXAhLjCD3PAk8ezqcYSDs4vXYV2wN/S3mWQHwTk0JqzgbLrrHt+Fhwa nK9veTEAiQTRFclir5lOrxkiPM56k02jVTAnaE6gDyest/LyzHIeSN7gCHe1S7uuDlea DXBWqDjgIFJCn1WJjxcA+1ZPh6RsL5M7Kqrqiy4V5tKs8kdF90NR2ycc69JKk6u6RHW8 d3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=SycTkjrDr+1oRjBfcTSdUKJyzjeYOYHJsQB5AU6b3cM=; b=vEQFqU4lirHAi+OlLjiWSLf3EmeLBUY6UORKF0hSzM5R3S1SXmM6whe5LLXbhFGcFq 070isZOpPlgdobqj+8cpFkK3nM/XCse2Y8V0kIQwxZBJ6N640483eFQbhszxh4YLRLUm rUdFPx3XZ+p0R6p7aYUyX2FNmqtFd9H7yhNTpuvMs9ysUM65DNloqiO47HFqoUOOo6/Y ogvNaa11G0kUGjN12odZmq5unHnmLOOI1cIdRCV+Lhcv/zkYJa7v7fiYff+pNzjQaFZn HRj/XwpipbkTMNaGI4jWbvtl5k33nj4asZj8Q6W1t7LJNpRPaBI5GxYZLh737hyL1auT LueA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h6VheffY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l13si25556742wrq.255.2021.11.23.13.02.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Nov 2021 13:02:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h6VheffY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpcvf-0007R8-P9 for patch@linaro.org; Tue, 23 Nov 2021 16:02:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpcrF-00026f-ER for qemu-devel@nongnu.org; Tue, 23 Nov 2021 15:57:41 -0500 Received: from [2a00:1450:4864:20::32a] (port=42993 helo=mail-wm1-x32a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpcrD-0006Nf-Qp for qemu-devel@nongnu.org; Tue, 23 Nov 2021 15:57:41 -0500 Received: by mail-wm1-x32a.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so265820wmd.1 for ; Tue, 23 Nov 2021 12:57:39 -0800 (PST) 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=SycTkjrDr+1oRjBfcTSdUKJyzjeYOYHJsQB5AU6b3cM=; b=h6VheffYOdocYdpTShecWBrRrd7pMGlluzqm+ZXYEBpryShPP58HEc2sLEB+kzx3gm f2Ch1tPIa2G54ZU+j8iB0ntA7OQCv1of8x25YGjKVhnMnk1xhjt6XJcuNPzlXBN4/TbZ eKzy6g1BFkyFicJR64/iz/kqZK7m/uxMhJ+qv1sHUz1u5aGo/is0AgiqWU2ChikvyulU yU/3VwAYcpxrOIW7bCKRRzUPkKogCJNva0rhqO9S1x7IiOuqt3UCJuqDLMF6z+xPAeeE lWPHepy263DUyToI4fo2m9CcxVc8y/CL5hJCpoT8ni+U5IRkvFt4NyUa4FoBIrVm2pv4 QM9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SycTkjrDr+1oRjBfcTSdUKJyzjeYOYHJsQB5AU6b3cM=; b=QozlJEeYBwAUHRLWY8A6QYKRMhKBgbT7BINhblfrS/tgFFu6u2/PB5XdoGfCDqfv87 C8DRCiedV5YX8Z2+B4VYRI1/Un+pzr5j7DWJ2OrZfcFnDbNNfvo0GYvTe8Mfnx8DGTp6 h7AkuGuBTg212R0WPBb2nKktCDmBza8Lm+9syCy7nmmqUeIqd3YN24tT4PG+JOXpTNL0 SdDtwXR61lNUxg8J7eymhe4ARUszOzk1TWb6BumHtusF6l5p84mAoBnXa8IGf4Z9egj4 Pd8eK1kjyJ/SSvkLI4SorPRHJnHgoMXv4ZzTfSqsccXAIdBbNP8/D9J2FWNUUYBtAi7C fLRw== X-Gm-Message-State: AOAM5334hgfjSgxE7sFYEKL87ejlh+rQs0gZPIiR43Qb/bykKrBdjAkW m4QYMBgSbdnX1noT6r7fXKPWrA== X-Received: by 2002:a05:600c:4f55:: with SMTP id m21mr7354997wmq.68.1637701058555; Tue, 23 Nov 2021 12:57:38 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k8sm12651400wrn.91.2021.11.23.12.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 12:57:37 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 851C41FF9C; Tue, 23 Nov 2021 20:57:29 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 5/7] gdbstub: handle a potentially racing TaskState Date: Tue, 23 Nov 2021 20:57:27 +0000 Message-Id: <20211123205729.2205806-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211123205729.2205806-1-alex.bennee@linaro.org> References: <20211123205729.2205806-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Richard Henderson , f4bug@amsat.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When dealing with multi-threaded userspace programs there is a race condition with the addition of cpu->opaque (aka TaskState). This is due to cpu_copy calling cpu_create which updates the global vCPU list. However the task state isn't set until later. This shouldn't be a problem because the new thread can't have executed anything yet but the gdbstub code does liberally iterate through the CPU list in various places. This sticking plaster ensure the not yet fully realized vCPU is given an pid of -1 which should be enough to ensure it doesn't show up anywhere else. In the longer term I think the code that manages the association between vCPUs and attached GDB processes could do with a clean-up and re-factor. Signed-off-by: Alex Bennée Tested-by: Richard Henderson Reviewed-by: Richard Henderson Cc: Richard Henderson Resolves: https://gitlab.com/qemu-project/qemu/-/issues/730 --- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdbstub.c b/gdbstub.c index 23baaef40e..141d7bc4ec 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -94,7 +94,7 @@ static inline int cpu_gdb_index(CPUState *cpu) { #if defined(CONFIG_USER_ONLY) TaskState *ts = (TaskState *) cpu->opaque; - return ts->ts_tid; + return ts ? ts->ts_tid : -1; #else return cpu->cpu_index + 1; #endif