From nobody Fri Dec 19 11:31:22 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BDAE2F39AD for ; Mon, 8 Dec 2025 12:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765195855; cv=none; b=RV5WaLlMr0cD951RPTGKaRhDhkMkLPypO95cOoE6CSVVzVzGbX/+Bz9JpgqAuJxVzcxWv02C/SueP4GNSNlvLD/a9Tdo9KyVqKxAM3x42lsOEaIjKlgh92Ju6xdd2JBR4vu3M+dD+fHXqPT4PxjfDbeSvRMRKXPkjJab8Jzx9Ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765195855; c=relaxed/simple; bh=u8WVF7+TSibqALZYK0Rishqre6CUPToFoFVRzvaGMlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t5PmnAMLnICClMoJKvjrrxuszjGc4wZOyAGYBG2tiDn9zUahdIDjWkymaPH7tfc3QO2pXK5EGlY4KD7j7OC7tGL79/w7SPordSVuNxHkouu/P1hcA6WkNySNyF3TFNVZZQBkYQZGpT/BfqqbsWYD6uJlhuttG2tiuMSX94T1/Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WL44Ks9P; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WL44Ks9P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765195853; 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=2aK6rSpeP7OmuKpy2WC08z3GtDIuL7UgtM7KA4SREDM=; b=WL44Ks9Pxxm1/PbJa1bFNk40rJvkkWBh6TQsctBPxxFpi0P37mRLg15wL7GXE2qC3ew/BX ZX+52ktisDm42IizxnzWj0M2jSep2ThY7ZWXxPs1mpssvi0MjvJzjPUrLI1zoeY4VGL1qX tFMp86lsFJcBJ7w1xhDj96wiYfOmvt4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-agrsE-LaMz-Nq-br0QCQKQ-1; Mon, 08 Dec 2025 07:10:47 -0500 X-MC-Unique: agrsE-LaMz-Nq-br0QCQKQ-1 X-Mimecast-MFC-AGG-ID: agrsE-LaMz-Nq-br0QCQKQ_1765195846 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6228318002DE; Mon, 8 Dec 2025 12:10:46 +0000 (UTC) Received: from pasta.fast.eng.rdu2.dc.redhat.com (unknown [10.44.34.3]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 30AF71956095; Mon, 8 Dec 2025 12:10:42 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , Jens Axboe , Chris Mason , David Sterba Cc: Andreas Gruenbacher , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC 05/12] bio: add bio_set_status Date: Mon, 8 Dec 2025 12:10:12 +0000 Message-ID: <20251208121020.1780402-6-agruenba@redhat.com> In-Reply-To: <20251208121020.1780402-1-agruenba@redhat.com> References: <20251208121020.1780402-1-agruenba@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Add a bio_set_status(bio, status) helper that sets bio->bi_status to status if status !=3D BLK_STS_OK. Replace instances of this pattern in the code with a call to the new helper. The WRITE_ONCE() in bio_set_status() ensures that the compiler won't reorder things in a weird way, but it isn't needed to prevent tearing because a single-byte field like bi_status cannot tear. Created with Coccinelle using the following semantic patch: @@ struct bio *bio; expression status; @@ - if (status) - bio->bi_status =3D status; + bio_set_status(bio, status); @@ struct bio *bio; expression status; @@ - if (unlikely(status)) - bio->bi_status =3D status; + bio_set_status(bio, status); Signed-off-by: Andreas Gruenbacher --- block/blk-mq.c | 3 +-- drivers/md/dm.c | 3 +-- include/linux/bio.h | 6 ++++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index d626d32f6e57..bc837aa51daa 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -969,8 +969,7 @@ bool blk_update_request(struct request *req, blk_status= _t error, struct bio *bio =3D req->bio; unsigned bio_bytes =3D min(bio->bi_iter.bi_size, nr_bytes); =20 - if (unlikely(error)) - bio->bi_status =3D error; + bio_set_status(bio, error); =20 if (bio_bytes =3D=3D bio->bi_iter.bi_size) { req->bio =3D bio->bi_next; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 6c83ab940af7..cbc64377fa96 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -983,8 +983,7 @@ static void __dm_io_complete(struct dm_io *io, bool fir= st_stage) queue_io(md, bio); } else { /* done with normal IO or empty flush */ - if (io_error) - bio->bi_status =3D io_error; + bio_set_status(bio, io_error); bio_endio(bio); } } diff --git a/include/linux/bio.h b/include/linux/bio.h index 38ebf03036cb..bf4df0b15ee1 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -376,6 +376,12 @@ void submit_bio(struct bio *bio); =20 extern void bio_endio(struct bio *); =20 +static inline void bio_set_status(struct bio *bio, blk_status_t status) +{ + if (status) + WRITE_ONCE(bio->bi_status, status); +} + static inline void bio_io_error(struct bio *bio) { bio->bi_status =3D BLK_STS_IOERR; --=20 2.51.0