linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/raid5: recheck if reshape has finished with device_lock held
@ 2024-06-27  5:37 Benjamin Marzinski
  2024-06-27 12:17 ` Yu Kuai
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Marzinski @ 2024-06-27  5:37 UTC (permalink / raw)
  To: Song Liu, Yu Kuai; +Cc: Heinz Mauelshagen, Xiao Ni, linux-raid

When handling an IO request, MD checks if a reshape is currently
happening, and if so, where the IO sector is in relation to the reshape
progress. MD uses conf->reshape_progress for both of these tasks.  When
the reshape finishes, conf->reshape_progress is set to MaxSector.  If
this occurs after MD checks if the reshape is currently happening but
before it calls ahead_of_reshape(), then ahead_of_reshape() will end up
comparing the IO sector against MaxSector. During a backwards reshape,
this will make MD think the IO sector is in the area not yet reshaped,
causing it to use the previous configuration, and map the IO to the
sector where that data was before the reshape.

This bug can be triggered by running the lvm2
lvconvert-raid-reshape-linear_to_raid6-single-type.sh test in a loop,
although it's very hard to reproduce.

Fix this by rechecking if the reshape has finished after grabbing the
device_lock.

Fixes: fef9c61fdfabf ("md/raid5: change reshape-progress measurement to cope with reshaping backwards.")
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 drivers/md/raid5.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 547fd15115cd..65d9b1ca815c 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5923,15 +5923,17 @@ static enum stripe_result make_stripe_request(struct mddev *mddev,
 		 * to check again.
 		 */
 		spin_lock_irq(&conf->device_lock);
-		if (ahead_of_reshape(mddev, logical_sector,
-				     conf->reshape_progress)) {
-			previous = 1;
-		} else {
+		if (conf->reshape_progress != MaxSector) {
 			if (ahead_of_reshape(mddev, logical_sector,
-					     conf->reshape_safe)) {
-				spin_unlock_irq(&conf->device_lock);
-				ret = STRIPE_SCHEDULE_AND_RETRY;
-				goto out;
+					     conf->reshape_progress)) {
+				previous = 1;
+			} else {
+				if (ahead_of_reshape(mddev, logical_sector,
+						     conf->reshape_safe)) {
+					spin_unlock_irq(&conf->device_lock);
+					ret = STRIPE_SCHEDULE_AND_RETRY;
+					goto out;
+				}
 			}
 		}
 		spin_unlock_irq(&conf->device_lock);
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-27 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-27  5:37 [PATCH] md/raid5: recheck if reshape has finished with device_lock held Benjamin Marzinski
2024-06-27 12:17 ` Yu Kuai
2024-06-27 14:54   ` Benjamin Marzinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).