Skip to content

Commit 775a9ba

Browse files
YuKuai-huaweigregkh
authored andcommitted
md/raid5: avoid BUG_ON() while continue reshape after reassembling
[ Upstream commit 305a517 ] Currently, mdadm support --revert-reshape to abort the reshape while reassembling, as the test 07revert-grow. However, following BUG_ON() can be triggerred by the test: kernel BUG at drivers/md/raid5.c:6278! invalid opcode: 0000 [#1] PREEMPT SMP PTI irq event stamp: 158985 CPU: 6 PID: 891 Comm: md0_reshape Not tainted 6.9.0-03335-g7592a0b0049a #94 RIP: 0010:reshape_request+0x3f1/0xe60 Call Trace: <TASK> raid5_sync_request+0x43d/0x550 md_do_sync+0xb7a/0x2110 md_thread+0x294/0x2b0 kthread+0x147/0x1c0 ret_from_fork+0x59/0x70 ret_from_fork_asm+0x1a/0x30 </TASK> Root cause is that --revert-reshape update the raid_disks from 5 to 4, while reshape position is still set, and after reassembling the array, reshape position will be read from super block, then during reshape the checking of 'writepos' that is caculated by old reshape position will fail. Fix this panic the easy way first, by converting the BUG_ON() to WARN_ON(), and stop the reshape if checkings fail. Noted that mdadm must fix --revert-shape as well, and probably md/raid should enhance metadata validation as well, however this means reassemble will fail and there must be user tools to fix the wrong metadata. Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 3fd5346 commit 775a9ba

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/md/raid5.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,7 +6326,9 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
63266326
safepos = conf->reshape_safe;
63276327
sector_div(safepos, data_disks);
63286328
if (mddev->reshape_backwards) {
6329-
BUG_ON(writepos < reshape_sectors);
6329+
if (WARN_ON(writepos < reshape_sectors))
6330+
return MaxSector;
6331+
63306332
writepos -= reshape_sectors;
63316333
readpos += reshape_sectors;
63326334
safepos += reshape_sectors;
@@ -6344,14 +6346,18 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
63446346
* to set 'stripe_addr' which is where we will write to.
63456347
*/
63466348
if (mddev->reshape_backwards) {
6347-
BUG_ON(conf->reshape_progress == 0);
6349+
if (WARN_ON(conf->reshape_progress == 0))
6350+
return MaxSector;
6351+
63486352
stripe_addr = writepos;
6349-
BUG_ON((mddev->dev_sectors &
6350-
~((sector_t)reshape_sectors - 1))
6351-
- reshape_sectors - stripe_addr
6352-
!= sector_nr);
6353+
if (WARN_ON((mddev->dev_sectors &
6354+
~((sector_t)reshape_sectors - 1)) -
6355+
reshape_sectors - stripe_addr != sector_nr))
6356+
return MaxSector;
63536357
} else {
6354-
BUG_ON(writepos != sector_nr + reshape_sectors);
6358+
if (WARN_ON(writepos != sector_nr + reshape_sectors))
6359+
return MaxSector;
6360+
63556361
stripe_addr = sector_nr;
63566362
}
63576363

0 commit comments

Comments
 (0)