From patchwork Thu Nov 25 15:41:42 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: 519669 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp1021714imj; Thu, 25 Nov 2021 07:50:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNroXzgLAJxAe99CiuMVUTLHXTNAgED/JJkrrF54RDfFjtIFHUKo5AdbxryuPJIy0WezxT X-Received: by 2002:a9f:3142:: with SMTP id n2mr27090183uab.102.1637855415120; Thu, 25 Nov 2021 07:50:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637855415; cv=none; d=google.com; s=arc-20160816; b=yXFG1zu47FgMEUymGsHRydYxqWst0KVawqAI+m1OyOXBskGcPmgT/Poaoec8N5ZWWb eXHd3lYtOh2NWgrwTdG3TayUQc2HIoXh+Za4t6lHxp2qlqNnjub5nt/Hc1ywGwy/OBQ0 l1AXoEaoUX2SlhtYR21zLBCo71qSgnDWP39jEfVEKsklBHWhBltGCrPo9ZSK4HeSAoum 61DVpJqbVUqpq53tsb4xXaCBthaJdsJFXEUI3OB6rq2Bxf5YGtXvJQ9RMIzIlYwSkN/+ eBpazflPGruU7tI6Be7E/3pPlOCe+nBjZqeMdUvDpegqrD8dJePVysrIcdyEy3Ppm6Bs FwYQ== 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=bUO0SB+BMTWj4cM859jVLA0edAg0vIZYqctggby2tKg=; b=Mc5Jhx6l2xgMpd+KMrIiWyWdet1jJUppwme5WYDVMJui+OZd+nNRr7RAOfWT1oQ4cF 5KZpQWNrTGhnpMDrvQaKr37L3QgW662xvj2ZxuTTdo0k9Pb85RnxXw2NegRWffZ38MCb 1dmmH5GB0CUAykZ3x1OGkgkSOHhQ2pUzRCznIPDfgLxW3Z+VXjXPb6O4sGhXUmoACbQN ImWurB5BbgVnFQ0s369VEVfzipJBD1hO1+f8czqtl5Cnzdj8HIHucv6tru5RF/i9wwWf rjFuAgSmb+OgqhIRI/TkdpkIKPuAdF5ZsYZbBkRNVHfPMEp7e5acdYRG+gf5M4f3dSHW zfhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cOks5faj; 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 y16si8256368vsi.162.2021.11.25.07.50.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Nov 2021 07:50:15 -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=cOks5faj; 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]:58552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mqH0o-0003vT-Jb for patch@linaro.org; Thu, 25 Nov 2021 10:50:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mqGsq-0006kn-55 for qemu-devel@nongnu.org; Thu, 25 Nov 2021 10:42:01 -0500 Received: from [2a00:1450:4864:20::431] (port=41773 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mqGso-0002L2-5G for qemu-devel@nongnu.org; Thu, 25 Nov 2021 10:41:59 -0500 Received: by mail-wr1-x431.google.com with SMTP id a9so12517539wrr.8 for ; Thu, 25 Nov 2021 07:41:57 -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=bUO0SB+BMTWj4cM859jVLA0edAg0vIZYqctggby2tKg=; b=cOks5faj1ZAeIOESC8RJFn6w4X5WgrioTNGAJyEejDJhhhQ24BnJ1v3uQbcEAvYjUy OxM+su2lMvoLf3brzyI3BCTi45MN4vpk8gAssu23UzWB2jYGKqILq9T72p0qwiZX21Qy mNih0JSAHQNDwE1mPtKNYABdJPLnAEwa6kEz/ywpr4mwhPOMrRK9v+twtMR/CyTGFRfv 91n94onlI/6k9Omrsph+7AUZOsgBYQ78iSvOL4Tlyt+gqBldP4FFoaPtIPvJxeStKqzE owIMC+WZc05+sM2DJ5PvwlTqb3KOpmI0FpidQDC0jjWXCW/NE8wm14880nc6fUBs6e4m uEYA== 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=bUO0SB+BMTWj4cM859jVLA0edAg0vIZYqctggby2tKg=; b=WhM0+Di9FRb0/u5fHsIgkX8fNkare34D+LiZRomBOQgNo5pmSgL5Pq0GIU+7mh87iO CEqz2CtEI7R5+FzrRMsGYAo3usVrIykpx7/F8Rig2iG5XEqYb9pyDrMpIMBREcRvTzGE vFgoDJerDKr38vt7KYGVf3BeB9FrnIv9HvqB1EfYyRXinAtbGbnF17qMrYAGmjuQikWL LYZEgBwTzqIfQfFHNIyrlKcnA9TJM0UJtQ2HBeUMpzTE3dd4zT+Rb9VmLMEIhlxfaTbN VXAXP6XolMefC4Me6kMtqlxMpiKtjzB4GXgb5rRNaeSGGJW8jYtO8Wv25tmNjxo52/Y2 pvKg== X-Gm-Message-State: AOAM530BnCvfObyFKiW8lmjWJ7iNbIxEVzfsde9aNlFKDpOSPkxH4r80 4MTawMAQqlQDNP9WfLNwWMg4XQ== X-Received: by 2002:a5d:54d0:: with SMTP id x16mr7522187wrv.606.1637854916892; Thu, 25 Nov 2021 07:41:56 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id ay21sm7865615wmb.7.2021.11.25.07.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 07:41:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 624C81FF9C; Thu, 25 Nov 2021 15:41:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 5/7] gdbstub: handle a potentially racing TaskState Date: Thu, 25 Nov 2021 15:41:42 +0000 Message-Id: <20211125154144.2904741-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211125154144.2904741-1-alex.bennee@linaro.org> References: <20211125154144.2904741-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.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 Message-Id: <20211123205729.2205806-6-alex.bennee@linaro.org> --- 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