From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068126; b=Xgt/WprrZrErD/tyyd64ixTXTrQWbsi79Ssl0dOC38QfFlftpUlaILr+tkPHfEdvV3m0 tcq+J8ZkzFeGW6kbhTAaZR2MwOhbKx8kdgAeg4P9quwKUHoosbzyytLHjCG39E2R2mm6p 3L9d0m6HDBH+ZR/ryfMJUHBQ3qwKW8pzbZHJ0t13UiAMloK/llrUwIQUvd8u1ziY9nuQR XG8UZj72Gcwb25M4vRN3KuYjSD6CIBE6VzFlsRmDel+/Gtdrfgdob1+hojUJlrTmlGetk 513mXcfKV97GcWJLhkYM3esoXN5Fx3WMmcye9YYjZeKX/AXBOxUNjpCdCukX0qMzO5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068126; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vs1GzEPaCU+p0k7nl01FHt/dq93xWhSEP+Q65geXf/k=; b=oUjqE93dqQSMIBoStoiox3+44wFEGcRGlyFxeXQWfc7G90ao1PFKE9O4KqDfpfmqVbsT qEYNdaL1SOkAt1bQLe1e7leNM9X0xgr2PK21sMHRLOm4UJYyv2GNraFhRttXtnB9nLQvw nIBby8PHJWVmVTcdPAFr9lJjVRYzlO1/cDnihHzYAlSrjMVGG6p1ZzMsiHuZvGnesYFle Gv3vN0ePSKfF4dZZlFdeX1hY/rVDVAMgy+UtXR1qAwXFTCQtSpeD/t9rfartlLX9afLxs xmVU8d9bM6bV+WQ8YLEEIDrt6PAnMH4RHyDIkzqihbdC28iatnLJpU2Rycz/ho3tM2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aoXVb5Oj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 733EB606A320 for ; Mon, 30 Nov 2026 19:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aoXVb5Oj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 183721F000C1; Mon, 30 Nov 2026 19:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796068126; bh=vs1GzEPaCU+p0k7nl01FHt/dq93xWhSEP+Q65geXf/k=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aoXVb5OjGZ02+GNZcscPuORuJfAnuQNxQen7EtdYKrZrIqHlysCvpPBDN4HK6gT4W 3TOvXjg6aMDmsTEBys/KgdJ8gHDXdlv2UXJ8LMxUhXlZd9KeGszldgg6D74bZn48D/ rhW9GajPQWia8Bk6dMzd6WWl+37rCOpgcDrjjgFBggATr6ORKdCTvhk2X0ft2ZobzL J77/YQYZMqgrYDpgPVemmWDJ/1LPIbwtVFuQWAgdTymiiK010PzVVHrhc2l/EWa9oO 2J9sTszPu55oNUxpJsUxbhD8prpKaXtk9QCigS6gKzb0TTFYDlNc9IjgpHtY2B/Imd 9jdVTuLTyf2oA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y) Reply-To: sashiko-reviews@lists.linux.dev To: "Eric Hagberg" , linux-raid@vger.kernel.org Cc: yukuai@fygo.io In-Reply-To: <20261130193139.1401044-1-ehagberg@janestreet.com> References: <20261130193139.1401044-1-ehagberg@janestreet.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 19:48:45 +0000 X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] md/raid10: missing Signed-off-by trailer and informal inquiry commit message - [High] md/raid10: premature end-of-sync teardown and false abort in raid10_sync_request() - [High] md/raid10: infinite loop or 0-length bio in raid10_sync_request() at resync_max - [Medium] md/raid10: broken sectors_skipped accounting and tight skip loop in raid10_sync_request() - [Low] md/raid10: missing Fixes trailer for commit bc49694a9e8f in commit message -- commit d99e7ee24942d79bda6cdab910442b35145994a1 Author: Eric Hagberg > md/raid10: far-layout member left with stale data after bitmap re-add (6.= 11+, 6.12.y, 6.18.y) > > Hi, > > On 6.12.y and 6.18.y, re-adding a member to a RAID10 array with the far > layout and an internal bitmap can complete "successfully" ([UU]) while > the re-added member still holds stale data for regions written while it > was absent. 6.1.y is not affected. This was seen on 2-disk > far=3D2 arrays (NVMe, internal bitmap, 64 MiB bitmap chunk) after a member > dropped out and came back; filesystems on the arrays were corrupted and > "check" reported non-zero mismatch_cnt. > > #regzbot introduced: bc49694a9e8f > > Reproducer (loop devices, 2 x 16 GiB zero-filled sparse files): > > mdadm --create /dev/md/r10 --run --assume-clean --metadata=3D1.2 \ > --level=3D10 --raid-devices=3D2 --layout=3Df2 --chunk=3D512 \ > --bitmap=3Dinternal --bitmap-chunk=3D65536 /dev/loopA /dev/loopB > mdadm /dev/md/r10 --fail /dev/loopB --remove /dev/loopB > # write a 64 MiB random payload with O_DIRECT to every third > # 64 MiB bitmap chunk (85 regions) > mdadm /dev/md/r10 --re-add /dev/loopB # bitmap-based recovery > mdadm --wait /dev/md/r10 # until [UU] > echo check > /sys/block/mdX/md/sync_action; mdadm --wait /dev/md/r10 > cat /sys/block/mdX/md/mismatch_cnt > mdadm /dev/md/r10 --fail /dev/loopA --remove /dev/loopA > # read the 85 regions back (now served only by loopB) and compare > > Results ("OK" =3D mismatch_cnt 0 and every region read back correctly from > the re-added member): > > kernel far=3D2 near=3D2 > 6.1 OK OK > 6.12 CORRUPTION OK > 6.18 CORRUPTION OK > > We have not yet tested 7.x. A full script is available on request. > > Our analysis, which we would appreciate having checked: > > Commit bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()"), > merged in v6.11, removed the recomputation of max_sector at the > 'skipped:' label in raid10_sync_request(). The giveup path still shrinks > max_sector to sector_nr + max_sync, advances sector_nr to it and jumps > back to the label, where "sector_nr >=3D max_sector" is now true. The > function then takes the end-of-sync branch and calls the bitmap's > close_sync(), which clears RESYNC on every bitmap chunk whose sync has > started, as if it had completed. > > During a bitmap-based recovery, every region that is clean in the bitmap > takes the giveup path. With the far layout, the data covered by one > bitmap chunk is split between the first and second halves of the > recovering member. Once a clean region is skipped, chunks whose first > half has been recovered are treated as done, their second half is > skipped, and the member is marked In_sync with stale data. Near layouts > recover each bitmap chunk contiguously, which matches what we see. > > In mainline, 7435b73f05fb ("md/raid10: cleanup skip handling in > raid10_sync_request"), in v7.0, removed the skip loop and carries > "Fixes: bc49694a9e8f", but has no Cc: stable and is not in 6.12.y or > 6.18.y. It is patch 11 of a 12-patch series and appears to depend on > earlier patches in it (it stops checking rdev_set_badblocks() return > values, which relies on "md: mark rdev Faulty when badblocks setting > fails"). > > Questions: > > 1. Does this analysis look right to you? > 2. What is the preferred fix for 6.12.y and 6.18.y: backporting > 7435b73f05fb together with the patches it depends on, or a smaller > targeted fix? > > As a starting point for discussion only (not a formal submission), the > minimal change we tried restores the pre-6.11 recomputation by resetting > max_sector to the caller's value at the label. With it, the reproducer > passes for both layouts on 6.12 and 6.18. We have since had > concerns raised about it internally and would value your view on > whether it is safe: [Severity: High] This commit is missing a Signed-off-by: trailer and has an informal mailing-list inquiry as its changelog rather than a commit description. [Severity: Low] For a formal submission fixing the regression, the commit message should also carry: Fixes: bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()") > diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c > index 2a9c4ee982e02..bddab5f9909e2 100644 > --- a/drivers/md/raid10.c > +++ b/drivers/md/raid10.c > @@ -3150,6 +3150,7 @@ static sector_t raid10_sync_request(struct mddev *m= ddev, sector_t sector_nr, > sector_t chunk_mask =3D conf->geo.chunk_mask; > int page_idx =3D 0; > int error_disk =3D -1; > + sector_t orig_max_sector =3D max_sector; > =20 > /* > * Allow skipping a full rebuild for incremental assembly > @@ -3171,6 +3172,7 @@ static sector_t raid10_sync_request(struct mddev *m= ddev, sector_t sector_nr, > return 0; > =20 > skipped: > + max_sector =3D orig_max_sector; > if (sector_nr >=3D max_sector) { > conf->cluster_sync_low =3D 0; > conf->cluster_sync_high =3D 0; [Severity: High] Can resetting max_sector at skipped: trigger premature end-of-sync teardown and a false abort when a skipped region reaches the end of the array? md_do_sync() only updates mddev->curr_resync after ->sync_request() returns, and only calls ->sync_request(mddev, max_sectors, max_sectors, &skipped) to run the sector_nr >=3D max_sector teardown block after waiting for mddev->recovery_active to drain. When a mid-sync call skips clean bitmap blocks up to orig_max_sector via giveup:, sector_nr reaches max_sector inside the active iteration while mddev->curr_resync is still the starting offset j (< max_sector): drivers/md/raid10.c:raid10_sync_request() { ... if (sector_nr >=3D max_sector) { ... if (mddev->curr_resync < max_sector) { /* aborted */ if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync, &sync_blocks, 1); else for (i =3D 0; i < conf->geo.raid_disks; i++) { sector_t sect =3D raid10_find_virt(conf, mddev->curr_resync, i); md_bitmap_end_sync(mddev->bitmap, sect, &sync_blocks, 1); } } else { ... } md_bitmap_close_sync(mddev->bitmap); close_sync(conf); *skipped =3D 1; return sectors_skipped; } } Because mddev->curr_resync < max_sector is always true here, this takes the aborted branch (calling md_bitmap_end_sync(..., 1), which can re-mark already-synced bitmap chunks with NEEDED_MASK, and skipping replacement recovery_offset =3D MaxSector and conf->fullsync =3D 0). It also runs md_bitmap_close_sync() while earlier recovery I/Os are still in flight, and destroys conf->r10buf_pool in close_sync(conf) before md_do_sync() makes its final end-of-sync call (which then re-initializes and re-destroys r10buf_pool). [Severity: High] What happens when mddev->resync_max is set below orig_max_sector (for example via /sys/block/mdX/md/sync_max) and the giveup -> skipped loop advances sector_nr up to mddev->resync_max? At skipped:, resetting max_sector =3D orig_max_sector makes sector_nr >=3D max_sector false because sector_nr =3D=3D mddev->resync_max < orig_max_sect= or. Later in raid10_sync_request(), max_sector is clamped back down to mddev->resync_max: drivers/md/raid10.c:raid10_sync_request() { ... if (max_sector > mddev->resync_max) max_sector =3D mddev->resync_max; /* Don't do IO beyond here */ ... } Execution then continues with sector_nr =3D=3D max_sector. If the block at resync_max is clean in the bitmap, chunks_skipped is set to -1 and giveup: adds 0 to sector_nr, increments chunks_skipped back to 0, and jumps to skipped: in an unbreakable infinite loop. If the block at resync_max needs syncing, the page-adding loop sees len =3D=3D 0 on page_idx =3D=3D 0 = and submits a 0-sector bio with no pages. [Severity: Medium] Does re-enabling the internal giveup -> skipped loop across clean bitmap regions also break sectors_skipped accounting when a dirty chunk follows a skipped clean region? When raid10_sync_request() skips clean bitmap blocks and then submits I/O for a dirty block in the same call, it finishes with: drivers/md/raid10.c:raid10_sync_request() { ... if (sectors_skipped) /* pretend they weren't skipped, it makes * no important difference in this case */ md_done_sync(mddev, sectors_skipped, 1); return sectors_skipped + nr_sectors; } This has several bad interactions with md_do_sync(): 1. md_done_sync() takes a signed int blocks argument (truncating 64-bit sector_t sectors_skipped above 1 TiB) and subtracts it from mddev->recovery_active before raid10_sync_request() returns and before md_do_sync() adds the returned sectors to mddev->recovery_active, transiently underflowing recovery_active. 2. Because *skipped is 0, md_do_sync() adds sectors_skipped + nr_sectors to io_sectors, counting skipped clean bitmap space as completed disk I/O and inflating currspeed above speed_max(mddev), which stalls recovery in msleep(500) for up to 30 seconds. 3. Because clean bitmap blocks set chunks_skipped =3D -1 and cap max_sync at 128 KiB, the internal loop scans clean regions in 128 KiB steps without cond_resched() or MD_RECOVERY_INTR checks when conf->nr_waiting =3D=3D 0, and sleeps 1 jiffy per 128 KiB in schedule_timeout_uninterruptible(1) whenever conf->nr_waiting > 0. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130193139.1401= 044-1-ehagberg@janestreet.com?part=3D1