Skip to contentSkip to conversation

md: fix bi_status reporting in md_end_clone_io

PATCH In review Song Liu 3 participants 4 messages Nov 18, 2023 – Nov 20, 2023 MD RAID

lore
Share & tools
lore

Song Liu

author maintainer
#0 lore raw

PATCH 1/1 md: fix bi_status reporting in md_end_clone_io

md_end_clone_io() may overwrite error status in orig_bio->bi_status with BLK_STS_OK. This could happen when orig_bio has BIO_CHAIN (split by md_submit_bio => bio_split_to_limits, for example). As a result, upper layer may miss error reported from md (or the device) and consider the failed IO was successful.

Fix this by only update orig_bio->bi_status when current bio reports error and orig_bio is BLK_STS_OK. This is the same behavior as __bio_chain_endio().

Fixes 10764815ff47 ("md: add io accounting for raid0 and raid5")
Cc Guoqing Jiang <[email protected]>
---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
index 4ee4593c874a..c94373d64f2c 100644
@@ -8666,7 +8666,8 @@ static void md_end_clone_io(struct bio *bio)
 	struct bio *orig_bio = md_io_clone->orig_bio;
 	struct mddev *mddev = md_io_clone->mddev;
 
-	orig_bio->bi_status = bio->bi_status;
+	if (bio->bi_status && !orig_bio->bi_status)
+		orig_bio->bi_status = bio->bi_status;
 
 	if (md_io_clone->start_time)
 		bio_end_io_acct(orig_bio, md_io_clone->start_time);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Song Liu

md_end_clone_io() may overwrite error status in orig_bio->bi_status with BLK_STS_OK. This could happen when orig_bio has BIO_CHAIN (split by md_submit_bio => bio_split_to_limits, for example). As a result, upper layer may miss error reported from md (or the device) and consider the failed IO was successful.

Fix this by only update orig_bio->bi_status when current bio reports error and orig_bio is BLK_STS_OK. This is the same behavior as __bio_chain_endio().

LGTM

Quoted 26 lines
Fixes 10764815ff47 ("md: add io accounting for raid0 and raid5")
Cc Guoqing Jiang <[email protected]>
---
  drivers/md/md.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
index 4ee4593c874a..c94373d64f2c 100644
@@ -8666,7 +8666,8 @@ static void md_end_clone_io(struct bio *bio)
  	struct bio *orig_bio = md_io_clone->orig_bio;
  	struct mddev *mddev = md_io_clone->mddev;
 
-	orig_bio->bi_status = bio->bi_status;
+	if (bio->bi_status && !orig_bio->bi_status)
+		orig_bio->bi_status = bio->bi_status;
 
  	if (md_io_clone->start_time)
  		bio_end_io_acct(orig_bio, md_io_clone->start_time);
Acked-by on v1 1/1
#2 lore raw
In reply to Song Liu
Quoted 9 lines · Song Liu

md_end_clone_io() may overwrite error status in orig_bio->bi_status with BLK_STS_OK. This could happen when orig_bio has BIO_CHAIN (split by md_submit_bio => bio_split_to_limits, for example). As a result, upper layer may miss error reported from md (or the device) and consider the failed IO was successful.

Fix this by only update orig_bio->bi_status when current bio reports error and orig_bio is BLK_STS_OK. This is the same behavior as __bio_chain_endio().

DRBD has the similar change.

Quoted 15 lines
Fixes 10764815ff47 ("md: add io accounting for raid0 and raid5")
Cc Guoqing Jiang <[email protected]>
---
  drivers/md/md.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index 4ee4593c874a..c94373d64f2c 100644

drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 8670

Quoted 6 lines
drivers/md/md.c +2 -1
@@ -8666,7 +8666,8 @@ static void md_end_clone_io(struct bio *bio)
  	struct bio *orig_bio = md_io_clone->orig_bio;
  	struct mddev *mddev = md_io_clone->mddev;
 
-	orig_bio->bi_status = bio->bi_status;
+	if (bio->bi_status && !orig_bio->bi_status)
+		orig_bio->bi_status = bio->bi_status;

Thanks for the fix!

Guoqing

Acked-by on v1 1/1
#3 lore raw
In reply to Song Liu
Quoted 9 lines · Song Liu

md_end_clone_io() may overwrite error status in orig_bio->bi_status with BLK_STS_OK. This could happen when orig_bio has BIO_CHAIN (split by md_submit_bio => bio_split_to_limits, for example). As a result, upper layer may miss error reported from md (or the device) and consider the failed IO was successful.

Fix this by only update orig_bio->bi_status when current bio reports error and orig_bio is BLK_STS_OK. This is the same behavior as __bio_chain_endio().

DRBD has the similar change.

Quoted 15 lines
Fixes 10764815ff47 ("md: add io accounting for raid0 and raid5")
Cc Guoqing Jiang <[email protected]>
---
  drivers/md/md.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index 4ee4593c874a..c94373d64f2c 100644

drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 8670

Quoted 6 lines
drivers/md/md.c +2 -1
@@ -8666,7 +8666,8 @@ static void md_end_clone_io(struct bio *bio)
  	struct bio *orig_bio = md_io_clone->orig_bio;
  	struct mddev *mddev = md_io_clone->mddev;
 
-	orig_bio->bi_status = bio->bi_status;
+	if (bio->bi_status && !orig_bio->bi_status)
+		orig_bio->bi_status = bio->bi_status;

Thanks for the fix!

Guoqing