From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB2CE3D1A8E for ; Fri, 10 Jul 2026 10:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678567; cv=none; b=nYGFx02Xywvvpv5UuyA4oAD/YmhhvM+Viac9HttqhfX+R5r3/rKA80+dWrTHHSEa3LrucfgRnHXRJAJ6QsaniP17P73bFpu2n01wEmoj66MnSG9hf6j2rBjSZqNQEgaJNGNGlGI8e1F26EghlsmygJM16sioidoZSowLMxfFPlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678567; c=relaxed/simple; bh=qSkQjXB7pdgaBV3uxRi/wPJF9W177xpnB5jhtdcPuAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSKgyKD4q/uwVxbEicYIbtXRZvmIIhVl4hvIrIKckS+gnLMSpmhYVvnKQoksTLFjI1InaK3aZeSQ2Bsby7kvDES9SzAk93R6leXDAHaZBZdNB0eTBkquEE8ZkpFbWAgG979/gsrspWC35KBMGzD3OImcXN1RRrmUP8tcoE/pKhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bvvzi28c; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bvvzi28c" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-493c7902f47so6429855e9.1 for ; Fri, 10 Jul 2026 03:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678564; x=1784283364; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oT3DtNxFURc+4K/kdjvPhLm+M8EJZnQsiPmbC3co1xc=; b=bvvzi28cadI+8GWehTKPHP34WRORRFZG+pVbTqkZyNPP4823Cd6Xspv+bDt+lF3nE8 /wxYkLRYPZwz4nEyLF+HOR8oVT0JQSeztsHGuLsc5QhJzmme1H6Pj/Db8PpEDtbrOWLb 1szDsxpsLtIcY5uoo/noEgAo1yyTJrEnLsZz3OaLcDtedd0B2mRwIHlwRoouNfHhpveT j/JC1xa8IMlhvc9CfChNrjlS7cA9wW8mwgzpythXfbUt+p9qzvgd3mkOlQFCwoDugej7 vVEqissf800pn5SKPizox7mI6W4Z5rhn+51UBCv7VPVM4yj2xktukf6YwI/NXm/d4BWE BDMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678564; x=1784283364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=oT3DtNxFURc+4K/kdjvPhLm+M8EJZnQsiPmbC3co1xc=; b=WSckejn9qDGFwLsaay7OTxPAr8r1syy3MBLdi/Xy4cp9FKQjlzsNTiClmRXFzEkwFw uRzXghe3s1iJynYX5Cmug4z6eBaV5aC9nSbntXL7h0OUALVUmvNHFrH9F7dO6nFo1J7w khn95pnSaLr9qyijtQeiHDC7ySwG6oliMyYvvlB9V/n4/SIA1ljL8sW6q4fawTVrtOtI ghE6zbkKuITJvAZJbEEaS7bNShinVS8j6nre6f5UbJeGvin+nli4fSCIjqKB9Otdmdwb FH32mmcZHTmDN0WzinnCnrCx/UfL6t6D0zpyzwjTnoQnQ0OmuzujUJExmhXIecc8jX18 d4nQ== X-Forwarded-Encrypted: i=1; AHgh+RoE/iRTd7DXNl3BOFGU3RZc2/070irmBfd8bo9BDn7pW4GXwoKUzrx9O0X0DnhucYESF1CWxDFAHJ8SrX0=@vger.kernel.org X-Gm-Message-State: AOJu0YzVnik7YFQa22FN79itvWOFYuGqfqH2JvcXLF9IiwimTN4GlgNs m88C3KwocLFIeeKzzei7oczz3/+43iTB4RneQDmn9+mcPZ07jjT+hSuC X-Gm-Gg: AfdE7ckUx90Ba1iHkEI+Svv/WlyfXKO/2hGzKR+yZ5xsOcp+cbRnY7F0XPClcK0tncr vKc2u2Nk0R0kKx3CVEsAhSFZK5O4Po/YoahcUUm0HYbxzs7jZ7pLJb4IFx98tJNxLPtGYMwpljL JitUvV4WPrQ2D5cH6vqJlhdsiP2S2QdjF300PCzPqxlan6uRkl1yZ1hkbQHI+YgqxjkL4Y6XEo6 i9/L3eG0ejGWz5tinHa0YL1QRRlDT4rhkCfPCXWZ15oHyuz/SX6e8BfBd7kVDuHs2jExtgvfl9x LvBtv3zQB+McCGvfHxkWgKbwwKsS7+x9wvgH7yxSaxna1FcD6nOpgBn+aq8DbW9xvJ+YzwOgTmz yeynlU/l+H+YABsWJR6UATbFhz084gw5GQox+itlS+Vu40yg7M8Dz8sXfdA97vspyCfsDO/Cxz5 0sfX6nz17B0qPkgl9J6P2XAXOEOhOVqlN1Y3vVbX1Bi+3pvYEeaAZTKgnzndm7btRZ X-Received: by 2002:a05:600d:8496:20b0:493:f251:3e84 with SMTP id 5b1f17b1804b1-493f2513eccmr24899145e9.15.1783678563823; Fri, 10 Jul 2026 03:16:03 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:03 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org, sashiko-bot Subject: [PATCH v4 1/7] md/raid10: fix r10bio leak in raid10_write_request() error paths Date: Fri, 10 Jul 2026 10:15:15 +0000 Message-ID: <20260710101521.1714-2-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" When raid10_write_request() fails because REQ_NOWAIT is set, the allocated r10_bio is not freed before returning, resulting in a memory leak. Free r10_bio before returning from the REQ_NOWAIT error paths. Fixes: c9aa889b035f ("md: raid10 add nowait support") Reported-by: sashiko-bot Closes: https://lore.kernel.org/linux-raid/20260613184042.BCEC01F000E9@smtp= .kernel.org/ Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Yu Kuai --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-2-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-2-= abd.masalkhi@gmail.com/ Changes in v2: - No changes. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-2-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 0a3cfdd3f5df..bd322eccdc3f 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1365,6 +1365,7 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, /* Bail out if REQ_NOWAIT is set for the bio */ if (bio->bi_opf & REQ_NOWAIT) { bio_wouldblock_error(bio); + free_r10bio(r10_bio); return false; } for (;;) { @@ -1398,6 +1399,7 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, if (bio->bi_opf & REQ_NOWAIT) { allow_barrier(conf); bio_wouldblock_error(bio); + free_r10bio(r10_bio); return false; } mddev_add_trace_msg(conf->mddev, --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AF55405C59 for ; Fri, 10 Jul 2026 10:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678572; cv=none; b=p/NbI0At4FGQVfu/AFU/wbJyoENY6CbiN9yWsfcKdJpQ/wqkPERwUEO3+y5v5ZoU83eu9R65541jufAEd9E45yxl1zpYXqjqH6ctk/a2fQU4M7AtQuhcoPXY+AGxvHoCptSyGpUqG4wtohUN95LGqVoATO32LI1RhhAABiFp3xQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678572; c=relaxed/simple; bh=Bfe3xB0thmKW8/yG8nKExHeAvMXcWVoeWwJ8pXNNBD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ps9PfI0ywHLL37bIe6AAoHMApSTbHmkTGVRTvdbOeRYiTFaDtUy2Kbgar0+tiAosF879hacimBdhk/zfSA3fr+rFt1FSPbqpKziwO6Fmk5otl851m1Rx3e1QMgyN4YtrOwqRShzeSoUtTaqI3CZRfKNR1RaDA4vLogKuHofHFC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kt9ORlkN; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kt9ORlkN" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4938d5f86f3so5093155e9.1 for ; Fri, 10 Jul 2026 03:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678568; x=1784283368; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=t1JCSAO04+tj+XFeggFKh3PqCgoc7uDvt/WquxeaeBY=; b=kt9ORlkNc1j3uUzZUJ4BE3XENOH+1ZQJiFbzkvutp/Cs1QS+a5DL60TgRBxDrRiWUw /SUvU9hbHctUo3m6h53BGf6DyB/BUd1q7xgBdwWIijXaiOZc1y/Z0r01iOTvGptuIvL6 Cad3bw3CeTMNpc2qfQN3eTSU1zEPUsqXDbj7gsoYvgfo0wq7k+DhN3QK2yIPLWLJKb6g pxmNB4JUApE0t9NS10nXXvcp3fkwdqJG8XvEgdk45uo66WP/RbugCGtGbGY8R8ruGd+F /RfMy8BNyiVw6XmWAeGLYui4o1AcHvZLUVfiD1rYVkbo6I6eS2U8WbxLNFDG37huDufq 6LWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678568; x=1784283368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=t1JCSAO04+tj+XFeggFKh3PqCgoc7uDvt/WquxeaeBY=; b=pQtOzpgr/NHntm8vsHY6PdteYC3t/mkFlpY04XfPXRSj+m+GCL6USo+Fowc+r2sKNf A08lgm8j/+bnmaSPjdEAGWBARmq8PUrxbnJWYOQApz/hd9Y0jXxgzR0nXlLeD8nqgMH6 xQmSp0zgz/oNwRDxAm+Jj82bEjM3ZHST3FNm+cLqQ6kgQi1dAAguDo34y1KugwtmztUl 2AzrBSMOlpbg+5ZA8ZVemujT7nFGZRSiIxTgHeJV0y6n2hkpqPt+rXx3pBOtrna0/ZIA ASnQWQ9qvWN7k4g2XWmMsh4XirejtA4fPAfC1rZ0RYdfs4LuvQrs6IubyyCG33J5hkyz HfWQ== X-Forwarded-Encrypted: i=1; AHgh+Rqeb3ZzRr2VsBEo4hv1i3rmxNfKBpDHFSMyEKecAjRrpRs4khbPMjmI50j4U7il8OweG8DqlltXO0oh8R4=@vger.kernel.org X-Gm-Message-State: AOJu0YxqjDKMdHcIvayu75PIM6a3wVENoQc6De73IbGisCgNKTrdQONz 0q9GSMwVU4VZMXOHwkCf/JaX21TtggkpgiBRy7Jnv0k0j/j8aGtYHg9A X-Gm-Gg: AfdE7cmS0BjbOYysGtIe/VxTaaRn3UFy0aqxeZTpwxsvbpSw9gJM+7IU+CQPcSzRQtN E4YBYNxVqQok4kJXN9AVSWfiuK8CsEAd/YP2SxQstr/pfKL9WeJeg2bcfxXi1z7DCwo8fmeRVt7 jhT2F6uviZ3kvFopeQkWSJKcCPRIhhNKM4m0tkXm8UlBXpF1S26Jlny/32sXoUc6tgFN6hk5/yb rjQeJiQlZJXMC6UjuLWZNc9io4bsiVk4WheTkOlhbsgGjNwKK3EVK10suC3ryXXXC7BTFmTHgXM yf5kQtAQoYSBE1SC6ybw4tm5/IbqJpI6UJCDEhpg0SzN2jomKrEX30jRx8qkFkgsq8hPcX8v9lK ky+TJhxrqOVERZ2b2mK31rOapM50gUGVMGFECjHbNJ0FI55OqYmliY3eLMQx1tfAldSrvB7tPvP gXScETX6vtuhAPN3Z5oZANCzmnFoIjg9e0qyH8ESpMUZAaD1WveaRp+LLCDOQSq+2r X-Received: by 2002:a05:600c:56d3:b0:493:e2c3:af25 with SMTP id 5b1f17b1804b1-493f2b37187mr15757895e9.12.1783678566847; Fri, 10 Jul 2026 03:16:06 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:06 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 2/7] md/raid1: restrict atomic write limits and handle runtime constraints Date: Fri, 10 Jul 2026 10:15:16 +0000 Message-ID: <20260710101521.1714-3-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" Restrict the RAID1 atomic write limits by setting chunk_sectors to BARRIER_UNIT_SECTOR_SIZE so that atomic writes never straddle a barrier unit. A bio that passes block-layer validation may still become unserviceable within RAID1 due to bad blocks or write-behind constraints. In the former case, complete the bio with EIO. In the latter case, disable write-behind rather than failing the bio with EIO. Fixes: f2a38abf5f1c ("md/raid1: Atomic write support") Fixes: a4c55c902670 ("md/raid1: simplify raid1_write_request() error handli= ng") Reviewed-by: John Garry Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Yu Kuai --- Changes in v4: - Improve the commit message. - Add Reviewed-by tag from John Garry. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-3-a= bd.masalkhi@gmail.com/ Changes in v3: - Set chunk_sectors to BARRIER_UNIT_SECTOR_SIZE instead of setting atomic_write_hw_unit_max. - Avoid enabling write-behind when the atomic write exceeds the write-behind limit. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-3-= abd.masalkhi@gmail.com/ Changes in v2: - Drop the early atomic write split check from raid1_write_request(). - Advertise the atomic write size limit via queue limits. - Disable write-behind instead of failing atomic writes when the BIO_MAX_VECS limit is encountered. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-3-a= bd.masalkhi@gmail.com/ --- drivers/md/raid1.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index afe2ca96ad8c..6c8beca995e6 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1522,6 +1522,7 @@ static bool raid1_write_request(struct mddev *mddev, = struct bio *bio, int first_clone; bool write_behind =3D false; bool nowait =3D bio->bi_opf & REQ_NOWAIT; + bool atomic =3D bio->bi_opf & REQ_ATOMIC; bool is_discard =3D op_is_discard(bio->bi_opf); sector_t sector =3D bio->bi_iter.bi_sector; =20 @@ -1577,7 +1578,8 @@ static bool raid1_write_request(struct mddev *mddev, = struct bio *bio, * write-mostly, which means we could allocate write behind * bio later. */ - if (!is_discard && rdev && test_bit(WriteMostly, &rdev->flags)) + if (!is_discard && rdev && test_bit(WriteMostly, &rdev->flags) && + (!atomic || max_sectors <=3D BIO_MAX_VECS * (PAGE_SIZE >> 9))) write_behind =3D true; =20 r1_bio->bios[i] =3D NULL; @@ -1603,20 +1605,6 @@ static bool raid1_write_request(struct mddev *mddev,= struct bio *bio, } if (is_bad) { int good_sectors; - - /* - * We cannot atomically write this, so just - * error in that case. It could be possible to - * atomically write other mirrors, but the - * complexity of supporting that is not worth - * the benefit. - */ - if (bio->bi_opf & REQ_ATOMIC) { - bio->bi_status =3D BLK_STS_NOTSUPP; - bio_endio(bio); - goto err_dec_pending; - } - good_sectors =3D first_bad - sector; if (good_sectors < max_sectors) max_sectors =3D good_sectors; @@ -1636,7 +1624,13 @@ static bool raid1_write_request(struct mddev *mddev,= struct bio *bio, if (write_behind && mddev->bitmap) max_sectors =3D min_t(int, max_sectors, BIO_MAX_VECS * (PAGE_SIZE >> 9)); + if (max_sectors < bio_sectors(bio)) { + if (atomic) { + bio_io_error(bio); + goto err_dec_pending; + } + bio =3D bio_submit_split_bioset(bio, max_sectors, &conf->bio_split); if (!bio) @@ -3228,6 +3222,7 @@ static int raid1_set_limits(struct mddev *mddev) md_init_stacking_limits(&lim); lim.max_write_zeroes_sectors =3D 0; lim.max_hw_wzeroes_unmap_sectors =3D 0; + lim.chunk_sectors =3D BARRIER_UNIT_SECTOR_SIZE; lim.logical_block_size =3D mddev->logical_block_size; lim.features |=3D BLK_FEAT_ATOMIC_WRITES; lim.features |=3D BLK_FEAT_PCI_P2PDMA; --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 789ED351C27 for ; Fri, 10 Jul 2026 10:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678574; cv=none; b=vA9kGczFj5f57C/S/QI6AmZPHJFXzYCzJkWAnbpxlV1/ogqhzzA9mHvMnp+vqwjY4qhOhq6+vvcVhSMhvgt4bcbkFsvAF58zPFv2mJGYP5FTG3klrgm1aInEU5rLJlnHrxlhwmUX+P54V9GQrb4Ytt8ZPe89hEoejbNwWjqd5/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678574; c=relaxed/simple; bh=1tlFjz/cCmyQHjce8cSURjPwovVmOpmqfVBATU2ybJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z1pzjBb8KvM6htXCsqDHQoc75sJbtasCAqn55ZWdd1wH7JA/reKEhtgJxkQGo5FC6RXrht5xkiG0weAJR3FrnZuQzaLApaZXiHLx1Gg7aQ39rGW0uRpH7zSrEyKVShlWUiC9CHnaLsfEeX8PL2BCSE5bHr61qaMxRCmbNqDSmfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kyIjCGeB; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kyIjCGeB" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493b7612475so5891985e9.3 for ; Fri, 10 Jul 2026 03:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678570; x=1784283370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=l+6lrXW8MRgVUIlREriBzz+n9VJVDvmnQ2y2tzCDScM=; b=kyIjCGeB1zBW5vz1gqUGl2qoA5isRqdNsvYuqt+VzTpEk8q1SfdRCcyzd7o9qP5lDj 40exawOwB9P4WtAQOmKourc9VlJ40jJqkRgkvZfxNUSdKfv0Gz8soKjnPjVDPSbPjW4s 1Gav4QxEQ4R2BvH/9RKa7EY8tX46IYYsTKdx2fdyjouPL1FPvmmyoCvNd3GbArXkFMBg /VXIe+Yncexy3hsdCRSeeSo2lt+roq/VcHo2yGgg30QXnk4JL68568kLKWc249pPuZ6f Ak1zdYiOrTJceYUgIkjUDtfIhxwd3qG8CuQ4CeBkEO86yjkL2iijk3Y4nDybDYEAH3bc uLog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678570; x=1784283370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=l+6lrXW8MRgVUIlREriBzz+n9VJVDvmnQ2y2tzCDScM=; b=QKeUJI7QV2WpEZsOZjn1XGa+EdHG3JVnf3PtOWue7tECH23cdfoY2LV/yU9LsBnSug DEK08Zb1EkfDt5RMBIv30MEbG5lgc+wiEaM8XZcKmk+Lpz7CJqxrZ/z/ySNspPloEK51 U9GehaT9uXojrfg/jvkkkNEBmqFYKEzQHEJRDACRflLOcpt3rOBjLWM4z5slzCpTxKU3 wq/tkm6i5FqkbfikjF5CyTE8Ysmx3j6PafE/CscmBGErkev586go5yYV9WPJXufUSeo4 CiFzEYIm41TENR5ufupm3jexQ9U6AnDb/+b5js2xKefLobwZ1eIGBR70GENn2Sl5Juk2 5opA== X-Forwarded-Encrypted: i=1; AHgh+RpcbJpfQrrSF9Ka/n5mwrAcs/+OBHUckuNJx0CmpCMRGNhuQc5tlshRwEckS/tuBDdbK5rYeLdc8n+C7fI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/ek6qICOvNHWSB3LdzVQ7CgdIS7jne5nHp2TIq0SRUCtMmuax CNBe6TA5kl7eVx3Pf9Yk1+LZHYuLIOgFp1q8tEd+QtiJGHNjsXJ0qKR5 X-Gm-Gg: AfdE7cnlskr7AfS59K1NrZ/vU/jLOtWFNfihtQ2dDywkdgR2ldvwaY0g23nPEckDABi JuZI6qBqIcqcni3nma7v5Wp6yNGy3/4rs4bA3fLdk6VD8P/Fqr2F6HIRTP7UiiwG2IYiyaZMhcM Bfj/PlXdMZgP5rRg8L0QZn6QElTePUx8nl9b4+PV88IWYRjEDCTk0c3aApld+cWdA1bh02x1Sgi lzwJnVm1j7CSeSzootVj6CTV5TMp39vmRho0UheXFpKRKnl3QEqAMPhbMHeAK83mSr5sz4hvJy0 GVPNI+3hnHBeviuONucKCSn3nVa0/t//qDHBfN4Mk4cVzSmqx4XvPE+3W7OSl8i8YhVZJXEpqwp ihKlAF8/zwe9A3UfX0wONyBrwDIYV25uy8D+PyUj3o7tqgkbJLnOB2/FHTE+qz8DNuI5gQmzA39 mI6bSCREu0HdYSIpSI+pngiZmdxMpcI/TkH3wWfr6JZTDUGtTX9iHrsDmM8IvMcJDGIQEvwibO1 UQ= X-Received: by 2002:a05:600c:c3cf:10b0:493:f0f5:f2db with SMTP id 5b1f17b1804b1-493f0f5f3aemr32432155e9.22.1783678569482; Fri, 10 Jul 2026 03:16:09 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:08 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 3/7] md/raid10: consistently fail atomic writes that require splitting Date: Fri, 10 Jul 2026 10:15:17 +0000 Message-ID: <20260710101521.1714-4-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" RAID10 currently handles one badblock path explicitly by failing atomic writes with EIO. However, another badblock path can also reduce the writable range and force the bio through bio_submit_split_bioset(), which implicitly completes the bio with EINVAL. Fix this by handling atomic writes in the common split check. If RAID10 determines that an atomic write would require splitting, complete the bio with EIO. Fixes: a1d9b4fd42d9 ("md/raid10: Atomic write support") Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: John Garry Reviewed-by: Yu Kuai --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-4-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-4-= abd.masalkhi@gmail.com/ Changes in v2: - Drop the early atomic write split check from raid10_write_request() and rely on queue limits instead. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-4-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index bd322eccdc3f..3480fc7907f0 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1356,6 +1356,7 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, int i, k; sector_t sectors; int max_sectors; + bool atomic =3D bio->bi_opf & REQ_ATOMIC; =20 if ((mddev_is_clustered(mddev) && mddev->cluster_ops->area_resyncing(mddev, WRITE, @@ -1464,16 +1465,6 @@ static bool raid10_write_request(struct mddev *mddev= , struct bio *bio, if (is_bad) { int good_sectors; =20 - /* - * We cannot atomically write this, so just - * error in that case. It could be possible to - * atomically write other mirrors, but the - * complexity of supporting that is not worth - * the benefit. - */ - if (bio->bi_opf & REQ_ATOMIC) - goto err_handle; - good_sectors =3D first_bad - dev_sector; if (good_sectors < max_sectors) max_sectors =3D good_sectors; @@ -1493,6 +1484,9 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, r10_bio->sectors =3D max_sectors; =20 if (r10_bio->sectors < bio_sectors(bio)) { + if (atomic) + goto err_handle; + allow_barrier(conf); bio =3D bio_submit_split_bioset(bio, r10_bio->sectors, &conf->bio_split); --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0DFE405C4F for ; Fri, 10 Jul 2026 10:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678578; cv=none; b=ebOufny+EkarzrY1C0M03/6tyjr176kuD1r7BLV2Eucw8qzdmhxy8Cc6QBaPByBiyO5gZqKnTFaHNfA0/HsJkSoBVx6OPLUSPVHbwIE0hNkUHllmTgkk+0PFkkD/LYJWRY5QX42r/eQq+93G5QzNKXkIgzd197AR8vFBhRDJTc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678578; c=relaxed/simple; bh=N2/4bpj+Xkr951tLE4PruUTtiurHt1Y/kuwTFiLb83c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OkTwJ/nPb6UyAYXGqlGgwJe9cQsPcvCKB6+4igBRpTsNSsetM4bT/KDmuaxL75cdthIfpwAca61Ehhe9cjJbywmQ8HDvreUyRwSoJUpjB7wFNlQrN0Uta8Zgzz4HzAMv8Rs1146M7OYopw9WXcBWgmQt/HanOCPSfZNxeOXLq50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JijvvJ7m; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JijvvJ7m" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-493f431e317so3699685e9.0 for ; Fri, 10 Jul 2026 03:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678572; x=1784283372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sDXS6mRL4qrhgTwIfHDccn9N8HWpnmgy7FQ0KITOahY=; b=JijvvJ7muYI6KrG9+3FagUnEQJzoooODlQzWawGYRtuVpvTuiwNyk+tZGg+82VAeOe fs4T2zmW0Mk3NNZ55gry4C4/hfoM3NbBiuMcoQqnRjn+yHoxijuy4oNcOWXcTfNwWBi7 58jLwPc4aHOSjHvdRZ3DjMc9Gbogt9cJsCKsXhFnEa3PiHJepnjoewkBo0F8kwFaLDVQ M7ZMFU3g3SUyTwCmW4uWeqKW2mzvdP79ctoo4D8QMCmQ+hu1ol/1lSZTvn6vySoiecQK hXXSmdaVMqmSnc/obbWQPLcV/k5F7xgEuyIpMoyMsk0ijJwDpyMBgjeyTuzT6yBxMEFL DOyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678572; x=1784283372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sDXS6mRL4qrhgTwIfHDccn9N8HWpnmgy7FQ0KITOahY=; b=Se8YMHm6Rd1jKDfyX4E4wWpusJFQZQdeTuAl6TSiow+ixam3gP+TCbHn9xf1UiXZBf iF1zzgPZM5kzc2rZbgRi5mB+iha13fCj4T71LKj4+nK3HGvxdBj7J0oPVEhjQPxe8sd1 ZsLdCyOMjy7Hc4GCpM6+rHPFpGWmvwuBUs/E/vErfWOs/5q8M8P7+KkfH7x8PN5IZaRb eNugh5hPB48EESt4BYIRNPq+XKvisnGZMVJkP6tYRGf9vqoLE0Lv6p5VYBEEm3Ch//m0 Jt4BTI6vH0+GzP9COhzN/+IrlJzGOVWWwgehQCbP6e8bw2TujG5tIow4fq5CHUbrOwjl kpSw== X-Forwarded-Encrypted: i=1; AHgh+Rql9ffjTUKIGxe8+vicQU6JHetCMYSxxXj+TlczahzZpK/OPqHrRFuEw+pCFGNLhSP6IE8aYiqvPGGQSTQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywio27nl2AFCzYMkH4FHPi1fCWm/sjgY7tzw76ql4Bm2Onvsl1q V7tfncaLEj370pN1px7yzXtN4A+r/i4mxVa5aWh/z+nB9MlSTXBiUCC7 X-Gm-Gg: AfdE7cnLWoZh9/MMiH3Kv/5/xKhTXhMJhqfptl7BC0liMUe3kizu6V2QwK4evTncDQh e3PZKAaHhPHt5zbL1WWgPSIB++4Ii7TJmmIQErVsw90M8y8fV/MxIoQuCY1DvpocZoCcOYpkff0 PuMNI1CR7bhqHlVohLs8h9ZZnMs0sp/QPbMaUdq6e/PWpM61h/Hmc6Z+7olDMNpL1k5OXZ3hNed O/BH+MekoHT+EtuYSluDxZn0xN9vnMJvkDpmuMfZHRiyWV8oYca8HoP6pV+zqlGDef/87XqK0TO lLISEQTRWM2GCGGpJmjj/q8VXJdcva887sKyhsmKTtNj03AaCANs660u7uDLnTIMLcUdvb/yhE8 X1G/sRmc/majbsD9GGESo1QSKqBDZY3nE8KzfUZmrG2CGVXNdVUE7MFx5rPR4FZkcH/+Np2MUrP gMKP6Nt6jouZlOPJxKYRF8UyTPXsnTP3SJnqfxIhayG50oKvNaMhNlOYV7dYG5Db5K X-Received: by 2002:a05:600c:828c:b0:493:bed9:b53d with SMTP id 5b1f17b1804b1-493e68ee07cmr95833595e9.31.1783678572187; Fri, 10 Jul 2026 03:16:12 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:11 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 4/7] md/raid10: remove unnecessary barrier around bio_submit_split_bioset() Date: Fri, 10 Jul 2026 10:15:18 +0000 Message-ID: <20260710101521.1714-5-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" raid10_write_request() drops the barrier before calling bio_submit_split_bioset() and reacquires it afterwards. This is no longer necessary because the split bio cannot re-enter raid10_write_request() while the barrier is held. The allow_barrier()/wait_barrier() pair was introduced by commit e820d55cb99d ("md: fix raid10 hang issue caused by barrier") when submit_flushes() called md_handle_request() directly, allowing re-entry into raid10_write_request(). Since v5.2, submit_flushes() has instead gone through submit_bio(), eliminating that recursion. submit_flushes() was later removed entirely by commit b75197e86e6d ("md: Remove flush handling"). Currently, raid10_write_request() is only entered from the bio submission path, so the split bio submitted by bio_submit_split_bioset() cannot recurse back into wait_barrier(). Remove the redundant allow_barrier()/wait_barrier() pair around bio_submit_split_bioset(). Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Yu Kuai --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-5-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-5-= abd.masalkhi@gmail.com/ Changes in v2: - Expand the commit message to explain why the allow_barrier()/wait_barrier() pair is no longer needed. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-5-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 3480fc7907f0..2574f60dd771 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1487,10 +1487,8 @@ static bool raid10_write_request(struct mddev *mddev= , struct bio *bio, if (atomic) goto err_handle; =20 - allow_barrier(conf); bio =3D bio_submit_split_bioset(bio, r10_bio->sectors, &conf->bio_split); - wait_barrier(conf, false); if (!bio) { set_bit(R10BIO_Returned, &r10_bio->state); goto err_handle; --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0936440683F for ; Fri, 10 Jul 2026 10:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678581; cv=none; b=uOSLtrLcvF4cLa18An0ornEDU7Dn+E4Ry3o9QkjszMSioCPn51oWTJr6TgyqOoyMk7+rzlNvNXOIghbb3cV7X+CL929NTGOs+7WpQqw6l1nJdZbZQryr+HxI8qXwfwa0ZQ6xGEcY3Z60VklVdKCeVXfF7FDju0PJ6df5tcovQiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678581; c=relaxed/simple; bh=DUcXJs4mGLHZ6uymZZALHDG0hWSlwUF/mtempvDSnec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZGhPvN7WuD2Oi4OSQ8Ku2oGPDx32KxEfkHXorXD/Hed/IjWvLEl/K4cz+rTfg0yXu191tZabnDLhRH5iuVayO/6PHhYFKg3kiQncnFeqFH3/2RSIlevoJBBACpTxHNG0rsy4c3mqQZTU83kP6tByZz6JgTs8DZJNBQMJ1MzyJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OY2Xi4+J; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OY2Xi4+J" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-493b966dd74so2673295e9.3 for ; Fri, 10 Jul 2026 03:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678574; x=1784283374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=T9GmK302JjUZNyPIbeSQCN1z48qUp83oZeSDjYiDAN4=; b=OY2Xi4+J35WOUWG4yUipeQVfNR9W1aMkkrfGdJh9eLt0C3nhm6S6Mqbcau3L82vOQz +uWepsfC4bNzsacShKAttPn+69B8ejaWB5WJEh3Bh2oPzHL/kQHYLTrM5AwQox/HKsj9 QcKXwO6CfSp+WgNK4m+bTPcJrCw5UtjnpLIBSR0v78WU8SckFfL7/GOjQ5Qs40pdsOvD LNH1UFR0wm4BQEfzrv8JJMocBHJwtMoxitdwmsnHqv9zXCTl9ay+4/aW8MxC28fi5YDp AUPShAz5/XmjstKduKieph09X0rtnMdalln6Eaw4iGks2LN8aiju+bRAC1ohENAnsh2O Z5zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678574; x=1784283374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=T9GmK302JjUZNyPIbeSQCN1z48qUp83oZeSDjYiDAN4=; b=ZBBsHeLz5OSWkpRSnam30HSoY2Ig40asdilcIjJ3Vd1/CC63Kx7quJgGXlqC/yw3oI sMW7qVmYVPMzqhgEmBMkWPNTLKcS5ax12tH7X+RSCVfqOp39Cks9LPGURt1YLzRilFIx PUAVDGt7e5rw2RqjbodHkUAubAVWcrJBhxKrjU61bbrOvFHPXlTn7/TzZJOM7md5UuTQ mqjHVuLeGd4eCgssn/YltCoLEkLdszacI5RwO09mLBVU50FwU5P/9YWe+bqQ3tcM8q8P EBq7/93kMP1VwFGu7Lslq5b7dDgqJyNq9oRTbe66juMA4aXgZuFiTzL+3FRYlMSQVcOj WmFA== X-Forwarded-Encrypted: i=1; AHgh+Rpeg3fRSf0DhE+nnFqacF2vcRfIuzWlXKxeoDid0JaqXHNiRI8C4dRmw0eh/Mly+y94xIjCnzZ7hpCKHv0=@vger.kernel.org X-Gm-Message-State: AOJu0YyWwbOE0FyEh8pV5gv588c/yLlzpEWp5uS/xylk0EuRHN1/8KZT 7te6A/uFUZnUZrBw76YHyKMD7ZOpnVfPDeWgz4lMDzm4xi3KL3iZ1c9Q X-Gm-Gg: AfdE7ckqKMTGjscpqHoVwjNY/Xk4FYMhwgeefZINiPUqMRV+REoCZFzdTbLcxzosbGL vwwzdUaPz5nLV3SiRtfOOXSvkTp1ByrM0vDNTOH0oOnEKdb5pKJsi4pwTMT6a2K/VZFnQBi+EqP C0cAbboH6AV7HvtUuNytto21/+IPWWI1Y0ZUEf38sei4QvrZjDXFbf/hMpwZBdXMGjZvVMne/MG BOIOAf71UNmmWFqPUhBD18vzVJ2tnl9K/Yw7MHmlfJQvXWh270pG0407LkI8J/icg7lruxklDsM kJauDU4BdNznppDCYakpyD4eXJa5fdJdLqheu3U6f0DNqR3GqsZ3r5cw2VziTutAD+weF1oI9BF /8Ds+LaGrwtar1G5whPGbNv1c0J4rExPLvr/OrYTpItXAh7jFoUXAUKnOB+/iQCRucubXc0je/7 63zgTXUAoxILZiOzrf8i0pVGiEHczNSTuDGHeHA3SROV9ZhYHrGWnZ864dvwCUKfuV X-Received: by 2002:a05:600c:4e01:b0:492:4cce:53e2 with SMTP id 5b1f17b1804b1-493e6831719mr109196505e9.3.1783678574414; Fri, 10 Jul 2026 03:16:14 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:13 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 5/7] md/raid10: replace wait loop with wait_event_idle() Date: Fri, 10 Jul 2026 10:15:19 +0000 Message-ID: <20260710101521.1714-6-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" The wait loop is equivalent to wait_event_idle() and can be simplified by usaing it for improving readability. Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Yu Kuai --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-6-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-6-= abd.masalkhi@gmail.com/ Changes in v2: - No changes. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-6-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 2574f60dd771..57813f249578 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1362,22 +1362,17 @@ static bool raid10_write_request(struct mddev *mdde= v, struct bio *bio, mddev->cluster_ops->area_resyncing(mddev, WRITE, bio->bi_iter.bi_sector, bio_end_sector(bio)))) { - DEFINE_WAIT(w); /* Bail out if REQ_NOWAIT is set for the bio */ if (bio->bi_opf & REQ_NOWAIT) { bio_wouldblock_error(bio); free_r10bio(r10_bio); return false; } - for (;;) { - prepare_to_wait(&conf->wait_barrier, - &w, TASK_IDLE); - if (!mddev->cluster_ops->area_resyncing(mddev, WRITE, - bio->bi_iter.bi_sector, bio_end_sector(bio))) - break; - schedule(); - } - finish_wait(&conf->wait_barrier, &w); + + wait_event_idle(conf->wait_barrier, + !mddev->cluster_ops->area_resyncing(mddev, WRITE, + bio->bi_iter.bi_sector, + bio_end_sector(bio))); } =20 sectors =3D r10_bio->sectors; --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17E133E0749 for ; Fri, 10 Jul 2026 10:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678583; cv=none; b=LFRlJkhP9p06Jr0O4dQxEFWKjCMkvmN+k4Q20nnQpSDJilKEFtCAzowxysHGIxKG6dpGbqPt9Q6EdDPfLJMhG+aSdvmsNov1oG3dJy/BH9I2VMf4O0Q/6w9lQaIFGBtLvfU+fsd8nMESoDCLRqz62ezkJ3OVJ2sZtI9j7+E1dXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678583; c=relaxed/simple; bh=G+0gt2lhZ/mJikbyerKKDgjQ1BeFViDpaZ9RXk+5+PQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z/nrANl25P1kaIdF9xoTe3mbc0I2oUTmmmgmVrvd7LOAkuXIBtR6vQgpymRN2emG1AdWJZyTjztkvKJAbO2sQpfFb8MtAlZtvFJc5CxNPGa3+Dxcc9z4MqpNYEVoViD+m53F5pDXHvwjZx/SIdTXQMX5N25ejy60oxiaiqq0aSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sBWp7BPo; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sBWp7BPo" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493c19bad03so6260335e9.2 for ; Fri, 10 Jul 2026 03:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678577; x=1784283377; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LBwHL7lIBb2cw/DWoNSHlaQyMeoLrvz1sqiTNmxmOWc=; b=sBWp7BPoCIiP2R7S33INgL03FXItwZSNTt93GB+CdDT0FJ8jluSnZYRBgWGPgXN8Zo yiEhYq/BlVDzU7SkG2m2xNsi5H62CTObIhuOZL+pGerHryjovgblXt/vgU68nrGlOCnH GuQfVbSZAq8vsUxwBk+VKYcUIo71Ul3OxvwmtnA9gexHLTgXsieXfzaD5yuZnnEwKhhV sySJY9hVm9DMzWM/TkH7hUvEhsUhUJH7fAqh1mTgGcPUQQ2HyUhGVweQqsA+v/ShFdnQ tLpEehLD3wWmT1InMdSh+GdmHIpEK/NX5NFKQy0wnhAKQ7Kon9xlUU8guvDRilrhvM1D dRXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678577; x=1784283377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=LBwHL7lIBb2cw/DWoNSHlaQyMeoLrvz1sqiTNmxmOWc=; b=NVqv1Ce8hye52k0qL9El8AXxVvZ/WXGrDxcexCz1IBlHuvqCFS1EEzTQOyipBBKbOP di0PZ0VdpBREoypU508swGDpgRJCbkccBZ7eFGvCaXKNcuGZbdmPjwCIOghP/PP/Y6WF nL6/jzIZ1U4VXvz+u/10SNBDT1U3vxQ+Hlxcm1VVjzTUiw9xvfelnf2wbjvdjr4rBAvm AAmaZcur6lxT6qZeJojLtI8znZ0d7Ib9rhwP63Gpb5xEpqHxtvQz5hMtRcjTzQIQhmVb dgvusKUkxV4ZI181XSnHx/IuPU2k/ruDknHLrXnnsXvNHdh66mKIinypX2nGJjwsvAog 51lg== X-Forwarded-Encrypted: i=1; AHgh+Rr6LFtQbkVPwpb53Vhe//g+UvMrkBVI4qb4+PYKujxl3rzcOon2FNBPjnPapvbFlzdCvqjH0jqpaTxLcsM=@vger.kernel.org X-Gm-Message-State: AOJu0YyUfhkqVdbJfDqS3506q2hx6vOuryg9lDrmE4BI+3h5DE5Rk93T Ofxr+8hmU4JowQ+ixENgYmaAZTdKL8clF2Ai+GqsEhMQVYkqugTQrlIK X-Gm-Gg: AfdE7cmfcCYfFaSwcIyX44OJPGYMwTKvki/XavyLR+mawMCIWj3jt/RZnzZLGSDAc1o FEyoxxqCLO6G4H03dy1VKXBnWlNhOSKzx4Qhu89KgKebqA/zYlgLqMKHW1W6+P1yxnyvn8DXCdO VVxeh2Uu8YptkkYOC28mLL3mZ9Z1J5OqSd+Km76vLP6QnNQXPgiOFNrAVKONZ13xNspEPrL/lsw DeWCv9tkgtOybWUK7+VJizwHGTL+wuG+JaarvShPR3XZNRojVaCgRZfZCL4GypdQJ4oyscyArVZ z92jFQnps4MCX3pFlfpYaGQhS60hvIRkxRHgO5wCtYy9cjRbfbJNYYhoOhe6qINanbvZeJpKZiU 7b+i05WtBoQtv2YYRaURKXv1kuMU/OmwYpv853wnY3c+ic8Y4qZQxo9kNxNtufMvO6T7FtDWJlg 3on//2HaKQeazXkFXR08KzhB37JSOB/1dXlLdMOSUllMqtYpLPZ1L4A1AbZfquhmRa X-Received: by 2002:a05:600c:4453:b0:492:3da4:81ef with SMTP id 5b1f17b1804b1-493e685ff4cmr105091945e9.18.1783678576988; Fri, 10 Jul 2026 03:16:16 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:16 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 6/7] md/raid10: simplify write request error handling Date: Fri, 10 Jul 2026 10:15:20 +0000 Message-ID: <20260710101521.1714-7-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" raid10_write_request() currently handles bio completion, barrier handling, and r10_bio lifetime management in several different error paths. This results in duplicated cleanup logic and increases the risk of introducing bugs in future modifications. Move bio_wouldblock_error() handling to the callers of regular_request_wait(), consolidate the write error paths, and free r10_bio from a single location in __make_request() when raid10_write_request() fails. It remove redundant local copies of r10_bio->sectors and use a single max_sectors variable throughout the function. Signed-off-by: Abd-Alrhman Masalkhi --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-7-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-7-= abd.masalkhi@gmail.com/ Changes in v2: - No changes. - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-7-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 58 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 57813f249578..d94c1f28a6f6 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1123,18 +1123,16 @@ static bool regular_request_wait(struct mddev *mdde= v, struct r10conf *conf, struct bio *bio, sector_t sectors) { /* Bail out if REQ_NOWAIT is set for the bio */ - if (!wait_barrier(conf, bio->bi_opf & REQ_NOWAIT)) { - bio_wouldblock_error(bio); + if (!wait_barrier(conf, bio->bi_opf & REQ_NOWAIT)) return false; - } + while (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && bio->bi_iter.bi_sector < conf->reshape_progress && bio->bi_iter.bi_sector + sectors > conf->reshape_progress) { allow_barrier(conf); - if (bio->bi_opf & REQ_NOWAIT) { - bio_wouldblock_error(bio); + if (bio->bi_opf & REQ_NOWAIT) return false; - } + mddev_add_trace_msg(conf->mddev, "raid10 wait reshape"); wait_event(conf->wait_barrier, conf->reshape_progress <=3D bio->bi_iter.bi_sector || @@ -1192,6 +1190,7 @@ static void raid10_read_request(struct mddev *mddev, = struct bio *bio, } =20 if (!regular_request_wait(mddev, conf, bio, r10_bio->sectors)) { + bio_wouldblock_error(bio); free_r10bio(r10_bio); return; } @@ -1354,8 +1353,8 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, { struct r10conf *conf =3D mddev->private; int i, k; - sector_t sectors; - int max_sectors; + int max_sectors =3D r10_bio->sectors; + bool nowait =3D bio->bi_opf & REQ_NOWAIT; bool atomic =3D bio->bi_opf & REQ_ATOMIC; =20 if ((mddev_is_clustered(mddev) && @@ -1363,9 +1362,8 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, bio->bi_iter.bi_sector, bio_end_sector(bio)))) { /* Bail out if REQ_NOWAIT is set for the bio */ - if (bio->bi_opf & REQ_NOWAIT) { + if (nowait) { bio_wouldblock_error(bio); - free_r10bio(r10_bio); return false; } =20 @@ -1375,28 +1373,25 @@ static bool raid10_write_request(struct mddev *mdde= v, struct bio *bio, bio_end_sector(bio))); } =20 - sectors =3D r10_bio->sectors; - if (!regular_request_wait(mddev, conf, bio, sectors)) { - free_r10bio(r10_bio); + if (!regular_request_wait(mddev, conf, bio, max_sectors)) { + bio_wouldblock_error(bio); return false; } =20 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && (mddev->reshape_backwards ? (bio->bi_iter.bi_sector < conf->reshape_safe && - bio->bi_iter.bi_sector + sectors > conf->reshape_progress) - : (bio->bi_iter.bi_sector + sectors > conf->reshape_safe && + bio->bi_iter.bi_sector + max_sectors > conf->reshape_progress) + : (bio->bi_iter.bi_sector + max_sectors > conf->reshape_safe && bio->bi_iter.bi_sector < conf->reshape_progress))) { /* Need to update reshape_position in metadata */ mddev->reshape_position =3D conf->reshape_progress; set_mask_bits(&mddev->sb_flags, 0, BIT(MD_SB_CHANGE_DEVS) | BIT(MD_SB_CHANGE_PENDING)); md_wakeup_thread(mddev->thread); - if (bio->bi_opf & REQ_NOWAIT) { - allow_barrier(conf); + if (nowait) { bio_wouldblock_error(bio); - free_r10bio(r10_bio); - return false; + goto err_allow_barrier; } mddev_add_trace_msg(conf->mddev, "raid10 wait reshape metadata"); @@ -1421,8 +1416,6 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, =20 wait_blocked_dev(mddev, r10_bio); =20 - max_sectors =3D r10_bio->sectors; - for (i =3D 0; i < conf->copies; i++) { int d =3D r10_bio->devs[i].devnum; struct md_rdev *rdev, *rrdev; @@ -1479,15 +1472,15 @@ static bool raid10_write_request(struct mddev *mdde= v, struct bio *bio, r10_bio->sectors =3D max_sectors; =20 if (r10_bio->sectors < bio_sectors(bio)) { - if (atomic) - goto err_handle; + if (atomic) { + bio_io_error(bio); + goto err_dec_pending; + } =20 bio =3D bio_submit_split_bioset(bio, r10_bio->sectors, &conf->bio_split); - if (!bio) { - set_bit(R10BIO_Returned, &r10_bio->state); - goto err_handle; - } + if (!bio) + goto err_dec_pending; =20 r10_bio->master_bio =3D bio; } @@ -1505,7 +1498,7 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, one_write_done(r10_bio); return true; =20 -err_handle: +err_dec_pending: for (k =3D 0; k < i; k++) { int d =3D r10_bio->devs[k].devnum; struct md_rdev *rdev =3D conf->mirrors[d].rdev; @@ -1521,7 +1514,9 @@ static bool raid10_write_request(struct mddev *mddev,= struct bio *bio, } } =20 - raid_end_bio_io(r10_bio); +err_allow_barrier: + allow_barrier(conf); + return false; } =20 @@ -1546,8 +1541,11 @@ static bool __make_request(struct mddev *mddev, stru= ct bio *bio, int sectors) ret =3D true; if (bio_data_dir(bio) =3D=3D READ) raid10_read_request(mddev, bio, r10_bio); - else + else { ret =3D raid10_write_request(mddev, bio, r10_bio); + if (!ret) + free_r10bio(r10_bio); + } =20 return ret; } --=20 2.43.0 From nobody Sun Jul 26 01:10:36 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D746407CE0 for ; Fri, 10 Jul 2026 10:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678587; cv=none; b=OHwgzcYUFB8Se8nzBJZeThqQYSVNXKmSKQ6G8TpVROF7q/Ph2nkwOMKeTpfvxWAZzYmZr//8pWOTj7Dbxpt1fSdjX1jcMQlgcGEIMOX4tqh8EFIRk/9So7ytWubqvXF9VdibI2xxXkEH08ThR4jxmBWlYIgXmeYgNIicTwCv23s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783678587; c=relaxed/simple; bh=vpWol1tRmIS2LWSbAfl0XKPRYz2NlD0X6ph51kt02us=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XvGzkShmLEOyt1JYVU+WpQs4vHi3xtMv3ZOiqd+pgn0gOOVm3+UjgP7InO/CxCaXYb/tbRdYEx7wjQydciRuQzW/En5EeJjzUZwg4VDEPScmZSz/1FO9XdlPe0wH9kNGxD3iNlch6qnlQH5s4CqFc+4erx/CXwR7QI0SLVquEDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yaha3uo8; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yaha3uo8" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493b27c7451so22769985e9.0 for ; Fri, 10 Jul 2026 03:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678580; x=1784283380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bSeLDzEoDs8fRhcqQi+T9x/Op3hPFFXdqP0g91gxk84=; b=Yaha3uo8JqBWYSwHYGluYluWDXji5sbgpoiP37M4wqlTr+p4S3IXrh8Sj/xwvPEWwi z4oFH5Yu99ZOKZhfsMPIbKIsjVRrizIORv4E3rCodK9GGZ/ZdgZhLjj/zO6lku4nnilQ bc+eqISf9VphyPilvi+lES9mNf1Y2hX1a8eotaHj9XatxbS0Ed4EmotIef2zMAaa/Q5L ypV4rDnN1xROPOrSh86w2QR2I3mvKxFDw89vxNZ3JnF/7233EIwV559MOnVcJwdHb45z X+i474hF0qQWnK0XgQo1rKaubIHg1+SmjI01kJEywwjLT7nLuVOugAMJfZyC/jPxq9H1 MVnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678580; x=1784283380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=bSeLDzEoDs8fRhcqQi+T9x/Op3hPFFXdqP0g91gxk84=; b=X63vZRuHFLEYFiHH8o6y5q2WNyE3ccrUq0Ak/zwwZtbEzg9sTt9upbyXwTNTchbx89 ivAkpgorI5XYYJWkfUWue5d+pMU8skCy4BeW2naoKE+SzFI+P1S77EVLQQV/URFg9nZz nNCz63auAWmz74sZKPbqBnofxIk3PQeF/8mG6p7j6Mv2pbQfnxByy6MKmtrhYorkoikm ODp+ag0WWdz257zjULHROTQmnOTB/nk5otOkuznAcMha/226s98dP53WqtqrRFOXvZ76 FwOfAL9N2pfJiJsfGyfYwk3Nr/2hS4aRVDAgqFnaflk121K2phhn40zT31WTEmVxbgqk +ceA== X-Forwarded-Encrypted: i=1; AHgh+RqN3uBCdPaHuAltN3o6rTmCkK9LyTWHn6Y/0E+Z22VcCUuV8ILHCp6wcwDUJ93S5HUgP4VbK+3OOGx6rwA=@vger.kernel.org X-Gm-Message-State: AOJu0YxE0HpStacbtPWOt510LIlL+it2yYBS11HgVHYhAurnqHGIUsDg uUPqH/znNxnhxAkTcPHTj/a7uSn/2h3W2uEG6FuwdMbpE3cw9/CaSear X-Gm-Gg: AfdE7ck/rUu/3KIhYirwliAWBieJlYAyMTTQNVtqEpx8t5nmGw3CS5/cJZwPsEMMWsq 7pkLij8wpKz6JqB5Wk9d70aejMqmy+L/NMQbp1xZG2H9deSk7hnQkvrdEjGSu3uBxg3boqxJsxd 9un4y1fEfcDctYszfOM2zE9P2zJ0l7rtXYIyXn3mqfjrERQeiuhjrSsrk3g3jSYx7UEqHkvlsKr KkLofi31wF6NGiVIDNjRxwJ0ckHJNQq9tsMiCd8Sl0qAZERddHy0fs6aQvEHHTWU42tTFiW3wRc W+qzSH2GGanBwrbWIL7wulQaiGHQzGpmnmMC8bdI37PRRB0mGVTJyzCtPPAbP/68eS3B4ywczTj numGsFfleTJMg8FsQvD2UParXi1Z2AZNjiVZw8tbn7CakJ3XqwBIjXV9in+ohRmPxX78AUHBlpB s50X7ZThZOF+YxU/IlwdsHQa3KH1UCmibNqOvKXmelKKXJQSrlCf6ePh5mUE6W91yte1J7Dl0VU UM= X-Received: by 2002:a05:600c:46cd:b0:492:6f5c:fd8c with SMTP id 5b1f17b1804b1-493f2b3fedcmr26876775e9.15.1783678580171; Fri, 10 Jul 2026 03:16:20 -0700 (PDT) Received: from yocto.. (dynamic-176-007-199-185.176.7.pool.telefonica.de. [176.7.199.185]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb670a41sm123554875e9.0.2026.07.10.03.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:16:18 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, vverma@digitalocean.com, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com, linux-kernel@vger.kernel.org Cc: linux-raid@vger.kernel.org Subject: [PATCH v4 7/7] md/raid10: simplify read request error handling Date: Fri, 10 Jul 2026 10:15:21 +0000 Message-ID: <20260710101521.1714-8-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710101521.1714-1-abd.masalkhi@gmail.com> References: <20260710101521.1714-1-abd.masalkhi@gmail.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 Content-Type: text/plain; charset="utf-8" raid10_read_request() currently handles bio completion, barrier handling, and r10_bio lifetime management in several different error paths. This results in duplicated cleanup logic and increases the risk of introducing bugs in future modifications. Make raid10_read_request() return a status to its callers, consolidate the read error paths, and free r10_bio from a single location in the callers. Since the callers allocate r10_bio, they should also be responsible for freeing it when the request fails. This makes the read path follow the same ownership model as the write path and simplifies the error handling flow. Signed-off-by: Abd-Alrhman Masalkhi --- Changes in v4: - No changes. - Link to v3: https://lore.kernel.org/linux-raid/20260708101341.473750-8-a= bd.masalkhi@gmail.com/ Changes in v3: - No changes. - Link to v2: https://lore.kernel.org/linux-raid/20260628142420.1051027-8-= abd.masalkhi@gmail.com/ Changes in v2: - Fix a compilation error (bi -> bio). - Link to v1: https://lore.kernel.org/linux-raid/20260623072456.333437-8-a= bd.masalkhi@gmail.com/ --- drivers/md/raid10.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index d94c1f28a6f6..01162c483644 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1143,7 +1143,7 @@ static bool regular_request_wait(struct mddev *mddev,= struct r10conf *conf, return true; } =20 -static void raid10_read_request(struct mddev *mddev, struct bio *bio, +static bool raid10_read_request(struct mddev *mddev, struct bio *bio, struct r10bio *r10_bio) { struct r10conf *conf =3D mddev->private; @@ -1191,8 +1191,7 @@ static void raid10_read_request(struct mddev *mddev, = struct bio *bio, =20 if (!regular_request_wait(mddev, conf, bio, r10_bio->sectors)) { bio_wouldblock_error(bio); - free_r10bio(r10_bio); - return; + return false; } =20 rdev =3D read_balance(conf, r10_bio, &max_sectors); @@ -1202,8 +1201,8 @@ static void raid10_read_request(struct mddev *mddev, = struct bio *bio, mdname(mddev), b, (unsigned long long)r10_bio->sector); } - raid_end_bio_io(r10_bio); - return; + bio_io_error(bio); + goto err_allow_barrier; } if (err_rdev) pr_err_ratelimited("md/raid10:%s: %pg: redirecting sector %llu to anothe= r mirror\n", @@ -1215,10 +1214,8 @@ static void raid10_read_request(struct mddev *mddev,= struct bio *bio, bio =3D bio_submit_split_bioset(bio, max_sectors, &conf->bio_split); wait_barrier(conf, false); - if (!bio) { - set_bit(R10BIO_Returned, &r10_bio->state); - goto err_handle; - } + if (!bio) + goto err_dec_pending; =20 r10_bio->master_bio =3D bio; r10_bio->sectors =3D max_sectors; @@ -1244,10 +1241,16 @@ static void raid10_read_request(struct mddev *mddev= , struct bio *bio, read_bio->bi_private =3D r10_bio; mddev_trace_remap(mddev, read_bio, r10_bio->sector); submit_bio_noacct(read_bio); - return; -err_handle: + + return true; + +err_dec_pending: atomic_dec(&rdev->nr_pending); - raid_end_bio_io(r10_bio); + +err_allow_barrier: + allow_barrier(conf); + + return false; } =20 static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_= bio, @@ -1538,14 +1541,13 @@ static bool __make_request(struct mddev *mddev, str= uct bio *bio, int sectors) memset(r10_bio->devs, 0, sizeof(r10_bio->devs[0]) * conf->geo.raid_disks); =20 - ret =3D true; if (bio_data_dir(bio) =3D=3D READ) - raid10_read_request(mddev, bio, r10_bio); - else { + ret =3D raid10_read_request(mddev, bio, r10_bio); + else ret =3D raid10_write_request(mddev, bio, r10_bio); - if (!ret) - free_r10bio(r10_bio); - } + + if (!ret) + free_r10bio(r10_bio); =20 return ret; } @@ -1875,6 +1877,7 @@ static bool raid10_make_request(struct mddev *mddev, = struct bio *bio) sector_t chunk_mask =3D (conf->geo.chunk_mask & conf->prev.chunk_mask); int chunk_sects =3D chunk_mask + 1; int sectors =3D bio_sectors(bio); + bool write =3D bio_data_dir(bio) =3D=3D WRITE; =20 if (unlikely(bio->bi_opf & REQ_PREFLUSH) && md_flush_request(mddev, bio)) @@ -1898,7 +1901,7 @@ static bool raid10_make_request(struct mddev *mddev, = struct bio *bio) sectors =3D chunk_sects - (bio->bi_iter.bi_sector & (chunk_sects - 1)); - if (!__make_request(mddev, bio, sectors)) + if (!__make_request(mddev, bio, sectors) && write) md_write_end(mddev); =20 /* In case raid10d snuck in to freeze_array */ @@ -2866,7 +2869,9 @@ static void handle_read_error(struct mddev *mddev, st= ruct r10bio *r10_bio) =20 rdev_dec_pending(rdev, mddev); r10_bio->state =3D 0; - raid10_read_request(mddev, r10_bio->master_bio, r10_bio); + if (!raid10_read_request(mddev, r10_bio->master_bio, r10_bio)) + free_r10bio(r10_bio); + /* * allow_barrier after re-submit to ensure no sync io * can be issued while regular io pending. --=20 2.43.0