* [PATCH] md/raid1: fix data lost for writemostly rdev
@ 2025-09-03 1:41 Yu Kuai
2025-09-03 3:23 ` Li Nan
0 siblings, 1 reply; 2+ messages in thread
From: Yu Kuai @ 2025-09-03 1:41 UTC (permalink / raw)
To: song, ian
Cc: linux-raid, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun,
johnny.chenyi
From: Yu Kuai <yukuai3@huawei.com>
If writemostly is enabled, alloc_behind_master_bio() will allocate a new
bio for rdev, with bi_opf set to 0. Later, raid1_write_request() will
clone from this bio, hence bi_opf is still 0 for the cloned bio. Submit
this cloned bio will end up to be read, causing write data lost.
Fix this problem by inheriting bi_opf from original bio for
behind_mast_bio.
Fixes: e879a0d9cb08 ("md/raid1,raid10: don't ignore IO flags")
Reported-and-tested-by: Ian Dall <ian@beware.dropbear.id.au>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220507
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/raid1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index f8434049f9b1..f391fd56d67f 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1225,7 +1225,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,
int i = 0;
struct bio *behind_bio = NULL;
- behind_bio = bio_alloc_bioset(NULL, vcnt, 0, GFP_NOIO,
+ behind_bio = bio_alloc_bioset(NULL, vcnt, bio->bi_opf, GFP_NOIO,
&r1_bio->mddev->bio_set);
/* discard op, we don't support writezero/writesame yet */
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] md/raid1: fix data lost for writemostly rdev
2025-09-03 1:41 [PATCH] md/raid1: fix data lost for writemostly rdev Yu Kuai
@ 2025-09-03 3:23 ` Li Nan
0 siblings, 0 replies; 2+ messages in thread
From: Li Nan @ 2025-09-03 3:23 UTC (permalink / raw)
To: Yu Kuai, song, ian
Cc: linux-raid, linux-kernel, yukuai3, yi.zhang, yangerkun,
johnny.chenyi
在 2025/9/3 9:41, Yu Kuai 写道:
> From: Yu Kuai <yukuai3@huawei.com>
>
> If writemostly is enabled, alloc_behind_master_bio() will allocate a new
> bio for rdev, with bi_opf set to 0. Later, raid1_write_request() will
> clone from this bio, hence bi_opf is still 0 for the cloned bio. Submit
> this cloned bio will end up to be read, causing write data lost.
>
> Fix this problem by inheriting bi_opf from original bio for
> behind_mast_bio.
>
> Fixes: e879a0d9cb08 ("md/raid1,raid10: don't ignore IO flags")
> Reported-and-tested-by: Ian Dall <ian@beware.dropbear.id.au>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220507
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/raid1.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index f8434049f9b1..f391fd56d67f 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1225,7 +1225,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,
> int i = 0;
> struct bio *behind_bio = NULL;
>
> - behind_bio = bio_alloc_bioset(NULL, vcnt, 0, GFP_NOIO,
> + behind_bio = bio_alloc_bioset(NULL, vcnt, bio->bi_opf, GFP_NOIO,
> &r1_bio->mddev->bio_set);
>
> /* discard op, we don't support writezero/writesame yet */
LGTM
Reviewed-by: Li Nan <linan122@huawei.com>
--
Thanks,
Nan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-03 3:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 1:41 [PATCH] md/raid1: fix data lost for writemostly rdev Yu Kuai
2025-09-03 3:23 ` Li Nan
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).