From nobody Mon Feb 9 17:06:27 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661520597; cv=none; d=zohomail.com; s=zohoarc; b=YGXIkJyylR5JEy2abgvcl6doqOIT4apL1hE2cjh2pr09Y0kT1gajKqI0NSFF4Txq2ZyRrlIijUgXPpUS37wKGtQh5c7T48MwAmYob4lw/U8DDQUwH2bcKKyFoVK4jQQjfmpdUu6ERKuBpi/ASvH1tlQSH5EBVUDq2vKaaPsLN/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661520597; h=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=zJMEDRs6Y5f7Uh0a9VV4p2JYN9JIvhqSQDPRyxh/dQ0=; b=kdO/9yTZOJ2Sn020QyIbPLy4r2IKouGbGcLQ/c/tNxiUJgE0hJZVbF8tklc5GKs0e7RECN6teApE9a82JGBlqwvR/NO/0/yMfXNAZqQrOyDex3OXduNyQimaFYLV1pZD/9UAISpqRrjsed3aSA7sV6uMneX86wL3+Hd0S+6eeog= 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 1661520597697311.11551406735487; Fri, 26 Aug 2022 06:29:57 -0700 (PDT) Received: from localhost ([::1]:58642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRZPI-0008FO-Cx for importer@patchew.org; Fri, 26 Aug 2022 09:29:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRZH7-00011O-Pk for qemu-devel@nongnu.org; Fri, 26 Aug 2022 09:21:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRZGx-0003zO-1I for qemu-devel@nongnu.org; Fri, 26 Aug 2022 09:21:29 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-21-KucgsLEeMjGWpWGo1-pQ-g-1; Fri, 26 Aug 2022 09:21:14 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8F6B3810D39; Fri, 26 Aug 2022 13:21:13 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98329492C3B; Fri, 26 Aug 2022 13:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661520077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zJMEDRs6Y5f7Uh0a9VV4p2JYN9JIvhqSQDPRyxh/dQ0=; b=dy3bqMgFWP1cfHEgQ+keX3ZiaUxJ7nsfL5ZJPZfOJJYteTORYsmYp/5MLf08cGPwu3qGmy 9qpJ9igMid1abFW7DE+js6OgxLbdGgNdiLk/4JLel9LsLO/2dC64tgTQX1xYBsoRIFK1WD 7pi0SbagKsgc5Ms0zROLYNFtG2dovhA= X-MC-Unique: KucgsLEeMjGWpWGo1-pQ-g-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Wen Congyang , Xie Changlong , Markus Armbruster , Stefan Hajnoczi , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v11 16/21] blockjob: protect iostatus field in BlockJob struct Date: Fri, 26 Aug 2022 09:20:59 -0400 Message-Id: <20220826132104.3678958-17-eesposit@redhat.com> In-Reply-To: <20220826132104.3678958-1-eesposit@redhat.com> References: <20220826132104.3678958-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661520599777100001 Content-Type: text/plain; charset="utf-8" iostatus is the only field (together with .job) that needs protection using the job mutex. It is set in the main loop (GLOBAL_STATE functions) but read in I/O code (block_job_error_action). In order to protect it, change block_job_iostatus_set_err to block_job_iostatus_set_err_locked(), always called under job lock. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/mirror.c | 7 +++++-- blockjob.c | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index c6bf7f40ce..7e32ee1d31 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -893,7 +893,7 @@ static int coroutine_fn mirror_run(Job *job, Error **er= rp) MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; BlockDriverState *target_bs =3D blk_bs(s->target); - bool need_drain =3D true; + bool need_drain =3D true, iostatus; int64_t length; int64_t target_length; BlockDriverInfo bdi; @@ -1016,8 +1016,11 @@ static int coroutine_fn mirror_run(Job *job, Error *= *errp) * We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there= is * an error, or when the source is clean, whichever comes first. */ delta =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_n= s; + WITH_JOB_LOCK_GUARD() { + iostatus =3D s->common.iostatus; + } if (delta < BLOCK_JOB_SLICE_TIME && - s->common.iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { + iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight >=3D MAX_IN_FLIGHT || s->buf_free_count =3D= =3D 0 || (cnt =3D=3D 0 && s->in_flight > 0)) { trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight= ); diff --git a/blockjob.c b/blockjob.c index d8fb5311c7..d04f804001 100644 --- a/blockjob.c +++ b/blockjob.c @@ -363,7 +363,8 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **er= rp) return block_job_query_locked(job, errp); } =20 -static void block_job_iostatus_set_err(BlockJob *job, int error) +/* Called with job lock held */ +static void block_job_iostatus_set_err_locked(BlockJob *job, int error) { if (job->iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { job->iostatus =3D error =3D=3D ENOSPC ? BLOCK_DEVICE_IO_STATUS_NOS= PACE : @@ -577,8 +578,8 @@ BlockErrorAction block_job_error_action(BlockJob *job, = BlockdevOnError on_err, */ job->job.user_paused =3D true; } + block_job_iostatus_set_err_locked(job, error); } - block_job_iostatus_set_err(job, error); } return action; } --=20 2.31.1