From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.106 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796497726; b=aTTw22lrMkd7A+NZUKfKPTJpinJP1V3S3io58Gt+8ErqSv92WI42Vgj8g0jE4Rww2TK1 Al0b6fbHFy1lHY/z+1xP5dzZ+2YAXM/n1lXHFExsjm8XRwhNVEijYSq2cxuwstyjvHs1Y eKRUZVoBSUxazOtAKr3vpm3vD4Qpgds5xX0Viaxk5NFVjwLeUliZyeDLDuMW5qUW1B70R CAOHdTwuFmhDn2Gnrj9VEQxNUxfRxmdWhp2JfzNFd2MEDeF8E8JxmRJhdR/1r5S2bq+su EbVaduNbHwiccjWXxpRh83cCW0NekiQ3SDAn2223uezfKTcP+eGY418ZP3H2B8EGz/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796497726; h=DMARC-Filter:DKIM-Signature:X-Pm-Submission-Id:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=NQinyOb3C2/UjHT/e22dlJur1EdtfLwARmZRoBIWy8g=; b=MSb8pnUHgWYojzNXKTdIlN3bnFGMCynKRg6ik+zez/nJnb32mott9C01UQuWs6bWDzY4 mWH2oWH7VqgRY0aOtL4Wt6RrAh0DvTKbHv1xy9IoRHNcPw8ggOvF0d9fxVkmVvYFyY5Gv A5r6iG9gMGfl0cnzhhXIb9Pf5EROgcsRhdMuWv3wK7WYvg21R3j8jGD1IMHasj2VYFq1+ VozK965gK7xe0nH+pQVDlwjouRJ2mMLjiwFeJm46qMDJ9g7UZ3klwYaYyqzbORBaN4Si1 DXZKyumWzF/kVl/FvWsaV7Jmv4YTIjGs/WLUUD0yuj9GoeqjuO463u+t7ibc6QQ/+qQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=raidlab.org; spf=pass smtp.mailfrom=raidlab.org; dkim=pass header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=cM9eI8L0; arc=none smtp.remote-ip=109.224.244.106 Received: from mail-244106.protonmail.ch (mail-244106.protonmail.ch [109.224.244.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FFA7606A322 for ; Sat, 5 Dec 2026 19:08:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4FFA7606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raidlab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raidlab.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=cM9eI8L0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raidlab.org; s=protonmail; t=1796497722; x=1796756922; bh=NQinyOb3C2/UjHT/e22dlJur1EdtfLwARmZRoBIWy8g=; h=From:To:Cc:Subject:Date:Message-ID:From:To:Cc:Date:Subject: Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=cM9eI8L0xUJs/b2yJGZ4bEft6ckt5ZQTN7XhLZJ6h+yI+pmQCRM5SYcQYVvWzLa+C drBF4y7MUcJAjcYj7Vnk8zQoHtwqVXmcDpNmI7fjzuorFInYcryBjFniZD5f+fjocY QixV9SsyUEIuFxM+2DUdPhPNcRlcUSTfW2DQ/EJXIuxK9AFi/1jEpM8nRisRFPAcuy SHjP4ELBHTuMansGr6kyuIE0eRzDi6gyS58fBpT/7QCBhdiQdjCZha+91OG19Me9nA ScD/yK2FwPfcF1jOc/iJb4GKyb/l56tcc5TtLJxNhfsdE87h8aJQFJ8MhlP1O6uvyQ ue+JnTjtNeVHg== X-Pm-Submission-Id: 4jhdF41LzFz2Scd2 From: Miroslav Cimerman To: Song Liu , Yu Kuai Cc: Li Nan , Xiao Ni , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] md/raid10: don't take a recovering member as the resync source Date: Sat, 5 Dec 2026 19:07:40 +0000 Message-ID: <20261205190740.1519480-1-mc@raidlab.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A power failure during a recovery can leave the array dirty. At the next assembly the recovering member keeps its slot, without In_sync and with the recovery offset from its superblock. This holds for a new spare and for a member re-added with a write-intent bitmap. md resyncs a dirty array before it recovers, so raid10 resyncs with the member in its slot. The resync reads every copy of a row whose member is present and not Faulty. sync_request_write() takes the first copy that read without error as the source, and overwrites every copy that differs from it. When the recovering member holds the first copy of a row past its recovery offset, its old content overwrites the other copy. For a spare: assembly after the power failure array dirty, so md starts with a resync spare in its slot, not In_sync, recovery_offset from the superblock resync, every row past the recovery offset raid10_sync_request(): reads the spare and the surviving copy sync_request_write(): fbio = read from the spare, overwrites the surviving copy with its data recovery skipped, the resync cleared conf->fullsync the spare becomes In_sync Every such row then reads back the spare's old content from both copies, and md reports the array in sync. For a re-added member, the resync covers only the regions its bitmap marks dirty. The surviving copy gets the member's old content there. read_balance() never reads a member that is not In_sync above its recovery_offset, and raid1_sync_request() only writes to such a member. Apply the same rule in sync_request_write(): such a copy is never the source, and it is always overwritten with the source. The resync then rewrites the recovering member as well. Found with FuzzyRAID, a fault injection tester for RAID. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org # 6.12+ Signed-off-by: Miroslav Cimerman --- 6.12+ because 4b10a3bc67c1 ("md: ensure resync is prioritized over recovery") made the bug reachable. Before it, md recovered the member first, and the recovery reads only In_sync copies. 4b10a3bc67c1 is in 6.15, 6.12.y and 6.14.y. In the tests below, its parent loses nothing, and 4b10a3bc67c1 loses the same as md-7.5. Reproduced on md-7.5 with null_blk members that have a volatile cache: RAID10 near=2 over 4 members with 126 MiB of data, and a power-off of the members after a 4 KiB write at 31% of a recovery. With a spare added after a failed member, 86 of the 126 MiB read back wrong after the assembly, every MiB from MiB 40 on (mismatch_cnt 87808 sectors). MiB 40 of the array is the spare's recovery offset of 20 MiB. The lost rows were written and flushed before the member failed, and the one write before the power-off read back correctly. The same happened with a write-intent bitmap, with the far=2 layout, and with a member re-added with a bitmap. Without the write, the array stays clean and nothing is lost. With this patch, all data read back intact in every case. If the only valid copy of a row fails to read, the row still reads back the member's old content without an error. I have a follow-up patch ready that marks such a row bad on the member. Prepared with help from an LLM. drivers/md/raid10.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 68f42cad32a5..2139c7030bfe 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -2292,6 +2292,19 @@ static void end_sync_write(struct bio *bio) end_sync_request(r10_bio); } +/* + * A member that is not In_sync holds valid data only below its + * recovery_offset, see read_balance(). + */ +static bool sync_copy_valid(struct r10conf *conf, struct r10bio *r10_bio, + int i) +{ + struct md_rdev *rdev = conf->mirrors[r10_bio->devs[i].devnum].rdev; + sector_t end = r10_bio->devs[i].addr + r10_bio->sectors; + + return test_bit(In_sync, &rdev->flags) || end <= rdev->recovery_offset; +} + /* * Note: sync and recover and handled very differently for raid10 * This code is for resync. @@ -2320,7 +2333,8 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) /* find the first device with a block */ for (i=0; icopies; i++) - if (!r10_bio->devs[i].bio->bi_status) + if (!r10_bio->devs[i].bio->bi_status && + sync_copy_valid(conf, r10_bio, i)) break; if (i == conf->copies) @@ -2349,7 +2363,15 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) tpages = get_resync_pages(tbio)->pages; d = r10_bio->devs[i].devnum; rdev = conf->mirrors[d].rdev; - if (!r10_bio->devs[i].bio->bi_status) { + if (!r10_bio->devs[i].bio->bi_status && + !sync_copy_valid(conf, r10_bio, i)) { + /* + * Not recovered yet: don't compare, write the source + * to it, unless this is a check. + */ + if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) + continue; + } else if (!r10_bio->devs[i].bio->bi_status) { /* We know that the bi_io_vec layout is the same for * both 'first' and 'i', so we just compare them. * All vec entries are PAGE_SIZE; base-commit: c526b7cd32f75fea6021ffdab287b81cf38ddeb7 -- 2.53.0