From nobody Sun Nov 16 04:14:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=ispras.ru ARC-Seal: i=1; a=rsa-sha256; t=1743589314; cv=none; d=zohomail.com; s=zohoarc; b=SCikrG8H5AU8MT5yt0OQaUdUdeLyMlTH94JdC1oQvNOMp1wa5J7W3Wz+tnOJnKpPZh/Z8xxuSr4+xM3EMRu1KxHyK/4Q14wc/rY5tHjq3CLHdK5btMb450IvkAZpNeD1PBwENKj7SLVMu+zbmdDW2yEV3wJYWjJHrt/ehRwA4e4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743589314; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QdT77uApGerlM6ikEWy+iXoDjZvq2QdTQSZe6pb03rc=; b=TYJFbXeItVsEAmSYlv5l/t/+mAZ6U19rLeduRXmryVYKdFfGml+EnlwsFQaD3Ge8Y5uyZhSCk+oxb/qrzys++MFSzyTTR02iwQQm9yp7iB6Wg6nL0jcL42GGt/jOgAFq9qcbS0v7rOcYHQAp1gqeJsAhJNDFM8obxJr1DkXE1Fw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1743589314686612.2629040994811; Wed, 2 Apr 2025 03:21:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tzvE5-0004sl-TH; Wed, 02 Apr 2025 06:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tzvDz-0004s8-8a; Wed, 02 Apr 2025 06:21:35 -0400 Received: from mail.ispras.ru ([83.149.199.84]) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tzvDx-0002ml-6j; Wed, 02 Apr 2025 06:21:34 -0400 Received: from Neilbrown.intra.ispras.ru (unknown [10.10.2.179]) by mail.ispras.ru (Postfix) with ESMTPSA id 58D22448787C; Wed, 2 Apr 2025 10:21:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 58D22448787C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1743589291; bh=QdT77uApGerlM6ikEWy+iXoDjZvq2QdTQSZe6pb03rc=; h=From:To:Cc:Subject:Date:From; b=PaEen7bQm39Tft78mJtdQzPV1LXbWERJyEFb8AGCFaUAKfdw/kLBLxjFs2ynsiZkQ bYPMkXzVeSKs4GjlFKBhb8ieVS1Gmid7PJeDB68zykgQ5I1r9XE/qihq2tdSpa46eE vMqKGohGFtMrDrfgLqQ+OA0lkBs1Jii09Yn6Z7Q0= From: Vitalii Mordan To: John Snow , Paolo Bonzini Cc: Vitalii Mordan , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, qemu-devel@nongnu.org, sdl.qemu@linuxtesting.org, Vadim Mutilin , Alexey Khoroshilov Subject: [PATCH] Fix data races in test-bdrv-drain test Date: Wed, 2 Apr 2025 13:21:19 +0300 Message-Id: <20250402102119.3345626-1-mordan@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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=83.149.199.84; envelope-from=mordan@ispras.ru; helo=mail.ispras.ru 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ispras.ru) X-ZM-MESSAGEID: 1743589317027019000 Content-Type: text/plain; charset="utf-8" This patch addresses potential data races involving access to Job fields in the test-bdrv-drain test. Fixes: 7253220de4 ("test-bdrv-drain: Test drain vs. block jobs") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2900 Signed-off-by: Vitalii Mordan --- include/qemu/job.h | 2 ++ job.c | 6 ++++++ tests/unit/test-bdrv-drain.c | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/qemu/job.h b/include/qemu/job.h index 2b873f2576..f27551a9ad 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -520,6 +520,8 @@ bool job_is_internal(Job *job); */ bool job_is_cancelled(Job *job); =20 +bool job_is_paused(Job *job); + /* Same as job_is_cancelled(), but called with job lock held. */ bool job_is_cancelled_locked(Job *job); =20 diff --git a/job.c b/job.c index 660ce22c56..d9b2dd8532 100644 --- a/job.c +++ b/job.c @@ -251,6 +251,12 @@ bool job_is_cancelled_locked(Job *job) return job->force_cancel; } =20 +bool job_is_paused(Job *job) +{ + JOB_LOCK_GUARD(); + return job->paused; +} + bool job_is_cancelled(Job *job) { JOB_LOCK_GUARD(); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 7410e6f352..65041c9230 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -667,10 +667,10 @@ static int coroutine_fn test_job_run(Job *job, Error = **errp) =20 /* We are running the actual job code past the pause point in * job_co_entry(). */ - s->running =3D true; + qatomic_set(&s->running, true); =20 job_transition_to_ready(&s->common.job); - while (!s->should_complete) { + while (!qatomic_read(&s->should_complete)) { /* Avoid job_sleep_ns() because it marks the job as !busy. We want= to * emulate some actual activity (probably some I/O) here so that d= rain * has to wait for this activity to stop. */ @@ -685,7 +685,7 @@ static int coroutine_fn test_job_run(Job *job, Error **= errp) static void test_job_complete(Job *job, Error **errp) { TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); - s->should_complete =3D true; + qatomic_set(&s->should_complete, true); } =20 BlockJobDriver test_job_driver =3D { @@ -791,7 +791,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, /* job_co_entry() is run in the I/O thread, wait for the actual job * code to start (we don't want to catch the job in the pause poin= t in * job_co_entry(). */ - while (!tjob->running) { + while (!qatomic_read(&tjob->running)) { aio_poll(qemu_get_aio_context(), false); } } @@ -825,7 +825,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, * * paused is reset in the I/O thread, wait for it */ - while (job->job.paused) { + while (job_is_paused(&job->job)) { aio_poll(qemu_get_aio_context(), false); } } @@ -858,7 +858,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, * * paused is reset in the I/O thread, wait for it */ - while (job->job.paused) { + while (job_is_paused(&job->job)) { aio_poll(qemu_get_aio_context(), false); } } @@ -1422,7 +1422,7 @@ static int coroutine_fn test_drop_backing_job_run(Job= *job, Error **errp) TestDropBackingBlockJob *s =3D container_of(job, TestDropBackingBlockJob, common.job); =20 - while (!s->should_complete) { + while (!qatomic_read(&s->should_complete)) { job_sleep_ns(job, 0); } =20 @@ -1541,7 +1541,7 @@ static void test_blockjob_commit_by_drained_end(void) =20 job_start(&job->common.job); =20 - job->should_complete =3D true; + qatomic_set(&job->should_complete, true); bdrv_drained_begin(bs_child); g_assert(!job_has_completed); bdrv_drained_end(bs_child); @@ -1565,7 +1565,7 @@ static int coroutine_fn test_simple_job_run(Job *job,= Error **errp) { TestSimpleBlockJob *s =3D container_of(job, TestSimpleBlockJob, common= .job); =20 - while (!s->should_complete) { + while (!qatomic_read(&s->should_complete)) { job_sleep_ns(job, 0); } =20 @@ -1700,7 +1700,7 @@ static void test_drop_intermediate_poll(void) job->did_complete =3D &job_has_completed; =20 job_start(&job->common.job); - job->should_complete =3D true; + qatomic_set(&job->should_complete, true); =20 g_assert(!job_has_completed); ret =3D bdrv_drop_intermediate(chain[1], chain[0], NULL, false); --=20 2.34.1