Patch "md/raid10: fix io loss while replacement replace rdev" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    md/raid10: fix io loss while replacement replace rdev

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     md-raid10-fix-io-loss-while-replacement-replace-rdev.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 258b4311b5591eee493b5629bc3560bcb1f7ac38
Author: Li Nan <linan122@xxxxxxxxxx>
Date:   Fri Jun 2 17:18:39 2023 +0800

    md/raid10: fix io loss while replacement replace rdev
    
    [ Upstream commit 2ae6aaf76912bae53c74b191569d2ab484f24bf3 ]
    
    When removing a disk with replacement, the replacement will be used to
    replace rdev. During this process, there is a brief window in which both
    rdev and replacement are read as NULL in raid10_write_request(). This
    will result in io not being submitted but it should be.
    
      //remove                              //write
      raid10_remove_disk                    raid10_write_request
       mirror->rdev = NULL
                                             read rdev -> NULL
       mirror->rdev = mirror->replacement
       mirror->replacement = NULL
                                             read replacement -> NULL
    
    Fix it by reading replacement first and rdev later, meanwhile, use smp_mb()
    to prevent memory reordering.
    
    Fixes: 475b0321a4df ("md/raid10: writes should get directed to replacement as well as original.")
    Signed-off-by: Li Nan <linan122@xxxxxxxxxx>
    Reviewed-by: Yu Kuai <yukuai3@xxxxxxxxxx>
    Signed-off-by: Song Liu <song@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20230602091839.743798-3-linan666@xxxxxxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index d3f8156da44e5..99607d51d128d 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -752,8 +752,16 @@ static struct md_rdev *read_balance(struct r10conf *conf,
 		disk = r10_bio->devs[slot].devnum;
 		rdev = rcu_dereference(conf->mirrors[disk].replacement);
 		if (rdev == NULL || test_bit(Faulty, &rdev->flags) ||
-		    r10_bio->devs[slot].addr + sectors > rdev->recovery_offset)
+		    r10_bio->devs[slot].addr + sectors >
+		    rdev->recovery_offset) {
+			/*
+			 * Read replacement first to prevent reading both rdev
+			 * and replacement as NULL during replacement replace
+			 * rdev.
+			 */
+			smp_mb();
 			rdev = rcu_dereference(conf->mirrors[disk].rdev);
+		}
 		if (rdev == NULL ||
 		    test_bit(Faulty, &rdev->flags))
 			continue;
@@ -1449,9 +1457,15 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
 
 	for (i = 0;  i < conf->copies; i++) {
 		int d = r10_bio->devs[i].devnum;
-		struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev);
-		struct md_rdev *rrdev = rcu_dereference(
-			conf->mirrors[d].replacement);
+		struct md_rdev *rdev, *rrdev;
+
+		rrdev = rcu_dereference(conf->mirrors[d].replacement);
+		/*
+		 * Read replacement first to prevent reading both rdev and
+		 * replacement as NULL during replacement replace rdev.
+		 */
+		smp_mb();
+		rdev = rcu_dereference(conf->mirrors[d].rdev);
 		if (rdev == rrdev)
 			rrdev = NULL;
 		if (rdev && (test_bit(Faulty, &rdev->flags)))



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux