From nobody Sun Jun 14 07:35:29 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 D73AE39D6C5 for ; Fri, 1 May 2026 11:47:08 +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=1777636030; cv=none; b=iAVTbLHosKiQHFjVvuRQxTi3rGFTigR2Dja8U/g3wUkvYZ0AO+hUpPGhlG0w0/VE3EfFbQchZC4K9ZfRVBiv7pgXNp2zXMFtQ+j2PmtsSZXjjwhBaM/UsJKX12UTEkv68geQx9MOtMgxax0d8azeZ1Vgn9PJ48v2XQAGr54RkI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777636030; c=relaxed/simple; bh=2tkshv6RNUHaw17n3hyMG/8cvdL2bnJSqh32+9Y18ps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=by6yewtE1UPL0mHModtL2kYKB6bptugEoBwRCZNbR3qGjcT34+3UT5/XnDCDselrsuawYLbsY0KSHsyfvenK85FYmC+kmz4rNY3NBjhNHjcX0jrVB1Md5cPRMyHWHcaDkAA+ryefTw+kHhNxZXVmgCOT/elyziyyFLwkc0xe8Yg= 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=AEwvxzYa; 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="AEwvxzYa" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso15307405e9.1 for ; Fri, 01 May 2026 04:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777636027; x=1778240827; 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; bh=/AQMFflzu8Awj9MuV1XBDZv36TqZfHy0cYYLO/nHMK8=; b=AEwvxzYaJ3PvUKKxKXH45HrIib2Y5iuF0tmEoQc+/Na8fzU0q0vJ6oTJDzs/zReMRv nvoKGeE/ZfBYUtY2YvA40HSjxR+Ee/J223RbyMopsz4MSAm1/fQ5LWVcGXKuh7iqFRkO YTP27y7+Qt+tkOgEcwO0QekfVa5nQnOcF/XNP2wI/DLhn97ZQsuPWIWt32navimOIpMg PzjSEpe9PcNxBwdwv3sLi1MUxnfHQUG0BKfp9eqzpGAFupWrbfpF6+9AclN/cWHuB8hM rvYqaaObp2Y9cXn2UXpwBurDpp7XKbEsMkx6ZBpUSezZh2tR0gwF7Xxa0XGpMYUTVyRR 02ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777636027; x=1778240827; 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; bh=/AQMFflzu8Awj9MuV1XBDZv36TqZfHy0cYYLO/nHMK8=; b=IU92QBOnXtMhO2ukw4DVZApQ/sx2jDaorLctviKdRwOJr50ONt39h2S4Aa9Ra/SQlF 8+t8bIPrFUk52jpIKOG4TMoOEoJgOft6vVCcfsXtBx/kMaWqFuKhe/iCIAfiKiNxm/hS 9V+vGRiB2fKqDzbNT1vOdz1zCV7409ygtgD1AjTanjNHf/5ER1+88kqx/V7JMWTpt89P U7WV+8SRZWNDc4xxEAAPYDmOPMf+90TdwE6upXncwsW4kcZ6x0V7lXkqc4DgPDzx3N1B 4hqVSsp+XyEyIeleND2joehqpTJiU9diMWl5xXTtnYsHHObsjPXJxnO9KbHDG48eG+GI CI0g== X-Forwarded-Encrypted: i=1; AFNElJ+aPXVSmYPUdWoXhMBVeFtCKdQNJbJ77rD+fAgjaQBwCri02Eh/gatPONCde1erfpyJeY4C2mVHlc2vnQ0=@vger.kernel.org X-Gm-Message-State: AOJu0YwV5z1nauFBmlliMtWWSPG1KHEpPjOwn6OABpf2HDisayWCP7y1 0K2ri075DVixbqNNJtR7UUPuHOzJD86j2F4UPA3R5sexQq4e8uzRQA63 X-Gm-Gg: AeBDievTwj5P3Towm0Z7aF7lco5aVRKXlS35Qv2elN6IrYhf0rDO936IJlpDT9JPmqd g4OlOx6L49+xa9DmqggPrqMPlzTRaMXJdsad54rSLjcystQfVoPU04UmDv4sgPRfV4zl5keh+9w jIYpQ5GXNyNky7s/qRdt0S5rSi0QvORlsTfZtmuMOZJzlFaCFbDN3r5EakmxVfUOOqIhyJo8HsY Zwel1gqnGvPvt8a9euceyTexQdGfS5I3kGi8vjayelDRu/suSMj0SkfOyUvuY1yAD6wDjNZEayJ szvRg1ABNlBF77fkddLodKjOUjpHszi9xn/8v6iCXMH/0hQ9SBFF/0MR5YsTOxOLnctx30WXNqw b2pM0Q8pHeAcJhWSL1Rm3zwxL8DSVm14fA3PsYQtIiXTtTXI8ZuJX2fdU5X1axKxQRMif2XpP+d jPV+A13upbXEBen8x9ES8EL9Bn+8qiRcxH68hg2jVCGZ6Y X-Received: by 2002:a05:600c:a40e:b0:488:fd7e:1063 with SMTP id 5b1f17b1804b1-48a84468524mr93816275e9.29.1777636026974; Fri, 01 May 2026 04:47:06 -0700 (PDT) Received: from yocto.. ([2a02:3037:621:7039:f080:d03a:2ee1:37d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8fee5033sm11797005e9.22.2026.05.01.04.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:47:06 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fnnas.com, xni@redhat.com, neilb@suse.com, shli@fb.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Abd-Alrhman Masalkhi Subject: [PATCH v2 1/3] md/raid1,raid10: fix deadlock in read error recovery path Date: Fri, 1 May 2026 13:46:49 +0200 Message-ID: <20260501114652.590037-2-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260501114652.590037-1-abd.masalkhi@gmail.com> References: <20260501114652.590037-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" raid1d and raid10d may resubmit a split md cloned bio while handling a read error. In this case, resubmitting the bio can lead to a deadlock if the array is suspended before md_handle_request() acquires an active_io reference via percpu_ref_tryget_live(). Since the cloned bio already holds an active_io reference, trying to acquire another reference via percpu_ref_tryget_live() can lead to a deadlock while the array is suspended. Fix this by using percpu_ref_get() for md cloned bios. Fixes: bb2a9acefaf9 ("md/raid1: switch to use md_account_bio() for io accou= nting") Fixes: 820455238366 ("md/raid10: switch to use md_account_bio() for io acco= unting") Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Xiao Ni Reviewed-by: Yu Kuai --- Changes in v2: - Use md_cloned_bio() consistently to detect cloned bios. - Recognize that raid10 has the same issue and fix it in this series=09 - Allow splitting bios. - Handle md cloned bios explicitly in md_handle_request() - Link v1: https://lore.kernel.org/linux-raid/20260427103446.300378-1-abd.= masalkhi@gmail.com/ Please let me know if I should add a Suggested-by tag for Yu Kuai, as the solution approach was suggested during review. Link to Yu Kuai' email: https://lore.kernel.org/linux-raid/m2lde74dtw.fsf@g= mail.com/T/#m714020a38b60fc5f84b9a24f0c46acbe5d7342d6 Thanks Abd-alrhman --- drivers/md/md.c | 25 ++++++++++++++++--------- drivers/md/md.h | 5 +++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index e926aef9ec43..96db1e7850e9 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -396,17 +396,24 @@ static bool is_suspended(struct mddev *mddev, struct = bio *bio) bool md_handle_request(struct mddev *mddev, struct bio *bio) { check_suspended: - if (is_suspended(mddev, bio)) { - /* Bail out if REQ_NOWAIT is set for the bio */ - if (bio->bi_opf & REQ_NOWAIT) { - bio_wouldblock_error(bio); - return true; + if (unlikely(md_cloned_bio(mddev, bio))) { + /* + * This bio is an MD cloned bio and already holds an + * active_io reference, so percpu_ref_get() is safe here. + */ + percpu_ref_get(&mddev->active_io); + } else { + if (is_suspended(mddev, bio)) { + /* Bail out if REQ_NOWAIT is set for the bio */ + if (bio->bi_opf & REQ_NOWAIT) { + bio_wouldblock_error(bio); + return true; + } + wait_event(mddev->sb_wait, !is_suspended(mddev, bio)); } - wait_event(mddev->sb_wait, !is_suspended(mddev, bio)); + if (!percpu_ref_tryget_live(&mddev->active_io)) + goto check_suspended; } - if (!percpu_ref_tryget_live(&mddev->active_io)) - goto check_suspended; - if (!mddev->pers->make_request(mddev, bio)) { percpu_ref_put(&mddev->active_io); if (mddev_is_dm(mddev) && mddev->pers->prepare_suspend) diff --git a/drivers/md/md.h b/drivers/md/md.h index 3bfbee595156..e44074d30cf9 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -1038,6 +1038,11 @@ void mddev_update_io_opt(struct mddev *mddev, unsign= ed int nr_stripes); =20 extern const struct block_device_operations md_fops; =20 +static inline bool md_cloned_bio(struct mddev *mddev, struct bio *bio) +{ + return bio->bi_pool =3D=3D &mddev->io_clone_set; +} + /* * MD devices can be used undeneath by DM, in which case ->gendisk is NULL. */ --=20 2.43.0 From nobody Sun Jun 14 07:35:29 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 A64E1364927 for ; Fri, 1 May 2026 11:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777636035; cv=none; b=aDRBhBaWLILokFMJpSoZeGSmE2/xywbpgV7QJOjRq1Eeajf9uWWzOkVtRpf1plWf0OSz1H7I5UxSug0YYU0uJ4t7LxBuS66eDTAGCEGmUQoz3Qzml5TK2wP6eLkXJMgoFhl8nouUPooH9dDpN4BE49oN4WnMXNNxdPQ9Hb5db9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777636035; c=relaxed/simple; bh=nI2K72PB2NtpPwpeuHNMfMbO44D3urEqQcaji0c1x9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SKLENZeT+uiYItwzgwxr5mwbj3YP7X8z7Em3cZ2XTZkrkyFx68sh0rZGU4A/eOsRoh4J3so4E42vPW7FCDLrff9kIHnI8D8TJLKFeX4pAogqH4yB6lX4y1lTC9uuQMY9quyHKzz1PKd9hrWvOusXAQYImGQG5EmV6+mxav/zLR8= 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=Szv3CjAA; arc=none smtp.client-ip=209.85.128.50 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="Szv3CjAA" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-48909558b3aso19358615e9.0 for ; Fri, 01 May 2026 04:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777636032; x=1778240832; 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; bh=yycJU3roRGwzwJP1s3LivQySTtrdat7N1ahieeEDuNU=; b=Szv3CjAA86gjhYxztaP1m0bD6JaEAoljxXf7HIXVBUc8xykDHxQ7e+Up0+t20HOWBF 4MgwktfS/JasUvywqjhyuaGupGGg0NhKkz2gMu8HHsvRTrFttTHTTRcpDdfg7iLO1fAk g0lMrgRxO/MCfslbRVslCVF2/RVjpzFgqBOx7FS4kIHX+s9LbiCg795mFajwcmgXFORY 6NWmAi8ooKXbEk1JsguKpnOIGa6VJncu8wQGBKXBeVp2uPnSEpqe2e9yoFVZZsjqw7Om KbCdKv5FHo0w/0eRc77wIpuHsnZNV9lXCqXwF0r5Aji4Avvel2s6UaLHGIZjPEZKjaD5 A5Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777636032; x=1778240832; 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; bh=yycJU3roRGwzwJP1s3LivQySTtrdat7N1ahieeEDuNU=; b=CmX734glL5r7SRh6uCgapRT6K7kdZKu1HeQaX4hZr0j0tvTQ42t6WNMOl2gw88FixE C41pY+Zyr9OQws5iX2cOnevfoY8qTuBXusvUyJ0o58WTdwcGzfJM05RjHGXUQ/HzFkaI uB1oVB4vB8bGg2hfV/xXskh1Pn5c1PXXjlvox7mANu7S0NzDkfpgoi25dOxaim9yhNKc tA7sjAEGyd2XMx6UFxIjffzM1GbV6u2AoWB0ZL3jMgibJThYRUd9y7kBQKtrrLoC7kLK ckVGmQUIH1RTMP4tP7f154eukS+J0z6ZkwVBBSBr6SCvW3nj1Y00tTaldzO/QfSCUehn XsAg== X-Forwarded-Encrypted: i=1; AFNElJ8+O9W96tmM+3SLO6O3gSMFPqerbqK6bCZaBftT8katylvb0A/D0DzmQDHSTWHZ9qeO0JiDOPzOOUrH0Hc=@vger.kernel.org X-Gm-Message-State: AOJu0YyaipvYLkrvD0QxSB+DgVXTcdOYSEeSyEufhVR8soaeEcXyeUSl jr4KZgudy+lOHhTPduN0+nGPz6SjC9iafomm3k34ecoGorQ4yu0mAmv3 X-Gm-Gg: AeBDieuo0vPbyzvMmeqzBQhdybNkgQruc0jWkKs+A7QXryYzZ8u4ZcjLTKmJZje8Gzm kfDhiBX9y9Y++SvcdGXhb5lXzuAkeRp9NLiFNa8iWW1SH3dlO1kZwZlWKduvbCFAyF3L7JAU24O uhQcwFUorxe2OBt1MwpVNT/pkZwzdA8AJwCmiXzyBomvLh+AVkG2IgY30Htsovl1za2FmOzkk0/ o83hEZZk9wuS3KJGDfJXEI+KhzD0+oXyLRdiDchVZZ5dd1aFNZIkAQfre7oYAEAjU3YrpzTsB1d ur2kny26yXDjsdG9kOSL3Fjk+aJOH530MPHwGiue1RshaovPTmado5zV0BB4wyDCvQKk3fLeZyf YIE83lEULSO3YOzJzBAS/ZKHkfhy/yjzSw0JZY4CdwAX647t0wf1d47bIDZh9kiyKktWcZNT1mb M66vNf2PUxrYMHFbrvtZYO2/c69Qv93RVF7w== X-Received: by 2002:a05:600c:8010:b0:485:46fd:7887 with SMTP id 5b1f17b1804b1-48a8446d8a4mr111327165e9.13.1777636031973; Fri, 01 May 2026 04:47:11 -0700 (PDT) Received: from yocto.. ([2a02:3037:621:7039:f080:d03a:2ee1:37d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8fee5033sm11797005e9.22.2026.05.01.04.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:47:11 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fnnas.com, xni@redhat.com, neilb@suse.com, shli@fb.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Abd-Alrhman Masalkhi Subject: [PATCH v2 2/3] md/raid1,raid10: fix error-path detection with md_cloned_bio() Date: Fri, 1 May 2026 13:46:50 +0200 Message-ID: <20260501114652.590037-3-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260501114652.590037-1-abd.masalkhi@gmail.com> References: <20260501114652.590037-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" Detect the error path using md_cloned_bio() instead of relying on r1_bio in raid1 or r10_bio->read_slot in raid10, which may be NULL or -1 after splitting and resubmitting a failed bio. As a result, the error path may not be recognized and memory allocations can incorrectly use GFP_NOIO instead of (GFP_NOIO | __GFP_HIGH), which can lead to a deadlock under memory pressure. Fixes: 689389a06ce7 ("md/raid1: simplify handle_read_error().") Fixes: 545250f24809 ("md/raid10: simplify handle_read_error()") Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Xiao Ni --- This patch depends on patch 1. Changes in v2: - New patch. --- drivers/md/raid1.c | 13 ++++++++++--- drivers/md/raid10.c | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index cc9914bd15c1..c52ecd38c163 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1321,11 +1321,18 @@ static void raid1_read_request(struct mddev *mddev,= struct bio *bio, bool r1bio_existed =3D !!r1_bio; =20 /* - * If r1_bio is set, we are blocking the raid1d thread - * so there is a tiny risk of deadlock. So ask for + * An md cloned bio indicates we are in the error path. + * This is more reliable than checking r1_bio, which might + * be NULL even in the error path if a failed bio was split. + */ + bool err_path =3D md_cloned_bio(mddev, bio); + + /* + * If we are in the error path, we are blocking the raid1d + * thread so there is a tiny risk of deadlock. So ask for * emergency memory if needed. */ - gfp_t gfp =3D r1_bio ? (GFP_NOIO | __GFP_HIGH) : GFP_NOIO; + gfp_t gfp =3D err_path ? (GFP_NOIO | __GFP_HIGH) : GFP_NOIO; =20 /* * Still need barrier for READ in case that whole diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 3a591e60a144..8c6fc398260e 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1155,7 +1155,20 @@ static void raid10_read_request(struct mddev *mddev,= struct bio *bio, char b[BDEVNAME_SIZE]; int slot =3D r10_bio->read_slot; struct md_rdev *err_rdev =3D NULL; - gfp_t gfp =3D GFP_NOIO; + + /* + * An md cloned bio indicates we are in the error path. + * This is more reliable than checking slot, which might + * be -1 even in the error path if a failed bio was split. + */ + bool err_path =3D md_cloned_bio(mddev, bio); + + /* + * If we are in the error path, we are blocking the raid10d + * thread so there is a tiny risk of deadlock. So ask for + * emergency memory if needed. + */ + gfp_t gfp =3D err_path ? (GFP_NOIO | __GFP_HIGH) : GFP_NOIO; =20 if (slot >=3D 0 && r10_bio->devs[slot].rdev) { /* @@ -1166,11 +1179,6 @@ static void raid10_read_request(struct mddev *mddev,= struct bio *bio, * we lose the device name in error messages. */ int disk; - /* - * As we are blocking raid10, it is a little safer to - * use __GFP_HIGH. - */ - gfp =3D GFP_NOIO | __GFP_HIGH; =20 disk =3D r10_bio->devs[slot].devnum; err_rdev =3D conf->mirrors[disk].rdev; --=20 2.43.0 From nobody Sun Jun 14 07:35:29 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 5D32D39E192 for ; Fri, 1 May 2026 11:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777636037; cv=none; b=UMbF7HIw1bJO1MH9WVd23J/xPzmxR6UUszTy203o+Jr4nkmHnVsqhzyPC8dZS3MopZr2TLNU0zECdJuTDN6prIJehFEyIL1l4ceC9PYrOBrpEwMqmYOO81kYNjDZNO6uusH76mzIZkmi3+d3a/yULVtoEwR3ggKvk/LkM/rWOq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777636037; c=relaxed/simple; bh=MY25n66b3XI8l9MKMDg8jxLtPtljlha3GqLPvC0cIFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WNb9ZqZd6ZHdWxl7SUU7K5WDpoTU5MHgtu9D+23gWfsfSrnTqqoe/rW5Mq0O8aPWJ9hWdg+N/d6EN3/GdQ0QiQMl0QG3OD9yAjoaCbXB45OaXsYcB3ian0IjQvvaKtieagN44ifc+M/qljye1H1BuQlu1MoVdOutA/aOeO1cZ80= 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=eQdC6Y8g; arc=none smtp.client-ip=209.85.128.54 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="eQdC6Y8g" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4891e86fabeso23641145e9.1 for ; Fri, 01 May 2026 04:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777636035; x=1778240835; 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; bh=v3DoX980qHTT9loeDHHdIPh9j7EwwCIsT/UFKNqvCqA=; b=eQdC6Y8gQQWhVs481xZKRTrBy4Zu/M+7Scr/RsHrgzn9NuJvnFNpDh4bhLljc8II9V 18dZK6VjoLlwSvFeMJ924G8F4n/rwPlT5WbKcla24SXOg05dnjGVp7v1O30HPC/a6W1V uknjSsdUlZSFkP9Fd66OPLJdhzBDK9bjCOakP3yTmpb2PZY1SWWFcDKTeOfIz/Z1w92J sxkbyDTAWZjO+Z+ikns+uRrPtzlW5pj9MDweo8ya3qUlYrqK2NbFpLxdRjm1rd/yU5Hy 09Uibdh4iTZv617ZYlEIz2ydnZwYVQTSaGu9W3tUpJu98AIsbQbvKQA/9d9m12jk0cEj FMyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777636035; x=1778240835; 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; bh=v3DoX980qHTT9loeDHHdIPh9j7EwwCIsT/UFKNqvCqA=; b=Z8KTN18vLuW5xamLLQfyao1/KO/3THfvI3p+7+6kmLpunAcXKidxEZPMpiQvaLHj+H nEX+iaEriBEaTlJXi31RrezYCKsBJOHb0wKofROa75CsVYovdtOIVroU3Bx8FBCsWNr9 hein/0cZtKwjyNCpRydFzWMXM3f+BgMvEQGysyxFsjuUWQLSOXMavt4x2M9t6NpY6hOh iW6n3w8rRWOD2nUJ3Jd4fvRiZMnNBeT7UiUcwpkX/uKg9YeUsX6SLxW+YgKZZSagWw0Y Yb3WE64JDIV4068TQu11Pj2ty5pb/nNhw3JvbL4gWL2wB359Ty1z1Pi5F76NIPWdReLP oJyQ== X-Forwarded-Encrypted: i=1; AFNElJ/TMlE72woNVmZ85Pi1XVD7Dlm3uth113YjuKxSkWdH+FChMygI5BrG9hhK37Tvayfj19oMRRlUdHPhymM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3QTC0dAeawLhBYeXaHe7JWEBFWdggT5y7sCcbd8iAThopUrpe rt+tgXWYV6jqR/ZdCey61e0fkBv3fYl3+VSaCTLhwQwvxcN487r3K4Ei X-Gm-Gg: AeBDiesHYo3CNDvkfziJtZUKE/Knch58WxCDy1jmRzOfzWgks9wVjW6ZXZp6noPrpTy iwq+SCanrYODn/WkbvvmlFsYpeUxu1mEMSSSF/qrkVv0qEKtAllq824MZeIVKUtNT41buL9ZcWp +i6gFCH/MWRgoDqCiBpu+MvEINu60Iyz+8WG9y/yZe8KUbCSZLFUtjkuUuQg3zxbkNkaDwntUEA AtqaNIvFsbhXBg0P2QpuhCHuG3PlNr0w2zPc/c9U+Ab8Q1HDCRnMYBB5aeOovTUANB5uJdUdiZu ih4tJ0TrskDd+g8Eagvg/ekbJp7dSJXdbkuN/xUfxzUmJS1T9Gg5hEDw0Bf/yPoXaZcPxMq3oQv 7oKYG3FEU5xWqkjWo+nikMPbTCbhcOY0ImssmUrGno1bsRmCAfoH7p37nTX9+I+f9zgc4Cg+Gd9 3/YV/JsURLjht8cNZ7e8sRM8vaJ5zYptdO2g== X-Received: by 2002:a05:600c:c117:b0:489:6c22:e081 with SMTP id 5b1f17b1804b1-48a83d05535mr80606955e9.0.1777636034625; Fri, 01 May 2026 04:47:14 -0700 (PDT) Received: from yocto.. ([2a02:3037:621:7039:f080:d03a:2ee1:37d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8fee5033sm11797005e9.22.2026.05.01.04.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:47:14 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fnnas.com, xni@redhat.com, neilb@suse.com, shli@fb.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Abd-Alrhman Masalkhi Subject: [PATCH v2 3/3] md/raid1,raid10: fix bio accounting for split md cloned bios Date: Fri, 1 May 2026 13:46:51 +0200 Message-ID: <20260501114652.590037-4-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260501114652.590037-1-abd.masalkhi@gmail.com> References: <20260501114652.590037-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" Use md_cloned_bio() to control bio accounting instead of relying on r1bio_existed in raid1 or the io_accounting flag in raid10. The previous logic does not reliably reflect whether a bio is an md cloned bio. When a failed bio is split and resubmitted via bio_submit_split_bioset() on the error path, this can lead to either double accounting for md cloned bios, or missing accounting for bios returned from bio_submit_split_bioset() Fix this by using md_cloned_bio() to detect md cloned bios and skip accounting accordingly. Fixes: bb2a9acefaf9 ("md/raid1: switch to use md_account_bio() for io accou= nting") Fixes: 820455238366 ("md/raid10: switch to use md_account_bio() for io acco= unting") Signed-off-by: Abd-Alrhman Masalkhi Reviewed-by: Xiao Ni --- This patch depends on patch 1. Changes in v2: - New patch. --- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index c52ecd38c163..dfaf34141325 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1396,7 +1396,7 @@ static void raid1_read_request(struct mddev *mddev, s= truct bio *bio, } =20 r1_bio->read_disk =3D rdisk; - if (!r1bio_existed) { + if (likely(!md_cloned_bio(mddev, bio))) { md_account_bio(mddev, &bio); r1_bio->master_bio =3D bio; } diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 8c6fc398260e..93af7bbc9005 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1146,7 +1146,7 @@ static bool regular_request_wait(struct mddev *mddev,= struct r10conf *conf, } =20 static void raid10_read_request(struct mddev *mddev, struct bio *bio, - struct r10bio *r10_bio, bool io_accounting) + struct r10bio *r10_bio) { struct r10conf *conf =3D mddev->private; struct bio *read_bio; @@ -1226,7 +1226,7 @@ static void raid10_read_request(struct mddev *mddev, = struct bio *bio, } slot =3D r10_bio->read_slot; =20 - if (io_accounting) { + if (likely(!md_cloned_bio(mddev, bio))) { md_account_bio(mddev, &bio); r10_bio->master_bio =3D bio; } @@ -1552,7 +1552,7 @@ static void __make_request(struct mddev *mddev, struc= t bio *bio, int sectors) conf->geo.raid_disks); =20 if (bio_data_dir(bio) =3D=3D READ) - raid10_read_request(mddev, bio, r10_bio, true); + raid10_read_request(mddev, bio, r10_bio); else raid10_write_request(mddev, bio, r10_bio); } @@ -2872,7 +2872,7 @@ 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, false); + raid10_read_request(mddev, r10_bio->master_bio, r10_bio); /* * allow_barrier after re-submit to ensure no sync io * can be issued while regular io pending. --=20 2.43.0