From nobody Fri Apr 4 21:41:27 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=1739445088; cv=none; d=zohomail.com; s=zohoarc; b=Bij5HPilVRQLny0/WJjr1chDi7oD3ZTU0Wv+oyA5kfBnjpgsPEjbd3Kz+Nmowqe13NomiUEitRs/e7pbQOJxdgqo59BdNIJWgZQLJvZnN8MFdua4EoYWe08aBeA27wIqfMQhXGUFR0qCxYSJVm36PcaiGwXPY+sRpqQ7zGnVa4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739445088; 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=JYVDohb5Vzfbi7ZY/z+vjZ6PgqxgJ9qLDVNpVzBZSM4=; b=NOsGqzKzigyJLBlhxo4u6go1zRpvxUYSseQusryiQy2ASJDXmjJEZAnRwo+JiLUS3cvIpAeRh+M/wBxCo7xfMAurN27uabHDV7s7Mokp4BNMNPhLyUyEFx0Ep/RCGuMQwH1ogKBXpKxXSWpM3KG/ixcELRw35B8X5hEmaI5ShGA= 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 1739445087850597.9277770146792; Thu, 13 Feb 2025 03:11:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tiX7O-00051q-EE; Thu, 13 Feb 2025 06:10:54 -0500 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 1tiX7L-00051f-Cu for qemu-devel@nongnu.org; Thu, 13 Feb 2025 06:10:51 -0500 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 1tiX7I-0007wR-W3 for qemu-devel@nongnu.org; Thu, 13 Feb 2025 06:10:51 -0500 Received: from Neilbrown.intra.ispras.ru (unknown [10.10.2.179]) by mail.ispras.ru (Postfix) with ESMTPSA id 470A8422488E; Thu, 13 Feb 2025 11:10:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 470A8422488E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1739445044; bh=JYVDohb5Vzfbi7ZY/z+vjZ6PgqxgJ9qLDVNpVzBZSM4=; h=From:To:Cc:Subject:Date:From; b=HT+LbJcPn+fLwGi4BQi8YtMxX0MQE2acsTLdBeB1a7Emdao0ARY8ve0afr8/Hp3n7 /PM+j60QDAnhgLBWe0rXkXAMv2aHztU1bQT85kikNzqjUWdJ3eQgoCtqm4hhJn26N7 OZ/uWZJITm0LWXnILgnFZ4xMWGCL0Qil3sLHdTeg= From: Vitalii Mordan To: Richard Henderson Cc: Vitalii Mordan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Zhao Liu , Halil Pasic , qemu-devel@nongnu.org, sdl.qemu@linuxtesting.org, Vadim Mutilin , Alexey Khoroshilov Subject: [PATCH] Fix Data Races with TestBlockJob Fields in test-block-iothread Date: Thu, 13 Feb 2025 14:10:31 +0300 Message-Id: <20250213111032.2726976-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: 1739445091765019100 Content-Type: text/plain; charset="utf-8" This patch resolves potential data races involving access to TestBlockJob fields in test-block-iothread.c. Fixes: 93c60f3862 ("test-block-iothread: Job coroutine thread after AioCont= ext switch") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2809 Signed-off-by: Vitalii Mordan --- tests/unit/test-block-iothread.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 7324ea4a68..b3d3f2fdb3 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -513,8 +513,8 @@ static int coroutine_fn test_job_run(Job *job, Error **= errp) TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); =20 job_transition_to_ready(&s->common.job); - while (!s->should_complete) { - s->n++; + while (!qatomic_read(&s->should_complete)) { + qatomic_inc(&s->n); g_assert(qemu_get_current_aio_context() =3D=3D job->aio_context); =20 /* Avoid job_sleep_ns() because it marks the job as !busy. We want= to @@ -533,7 +533,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 { @@ -564,28 +564,28 @@ static void test_attach_blockjob(void) 0, 0, NULL, NULL, &error_abort); job_start(&tjob->common.job); =20 - while (tjob->n =3D=3D 0) { + while (qatomic_read(&tjob->n) =3D=3D 0) { aio_poll(qemu_get_aio_context(), false); } =20 blk_set_aio_context(blk, ctx, &error_abort); =20 tjob->n =3D 0; - while (tjob->n =3D=3D 0) { + while (qatomic_read(&tjob->n) =3D=3D 0) { aio_poll(qemu_get_aio_context(), false); } =20 blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); =20 tjob->n =3D 0; - while (tjob->n =3D=3D 0) { + while (qatomic_read(&tjob->n) =3D=3D 0) { aio_poll(qemu_get_aio_context(), false); } =20 blk_set_aio_context(blk, ctx, &error_abort); =20 tjob->n =3D 0; - while (tjob->n =3D=3D 0) { + while (qatomic_read(&tjob->n) =3D=3D 0) { aio_poll(qemu_get_aio_context(), false); } =20 --=20 2.34.1