[PATCH v2 1/5] md/md-llbitmap: skip reading rdevs that are not in_sync

Yu Kuai posted 5 patches 1 month, 1 week ago
[PATCH v2 1/5] md/md-llbitmap: skip reading rdevs that are not in_sync
Posted by Yu Kuai 1 month, 1 week ago
When reading bitmap pages from member disks, the code iterates through
all rdevs and attempts to read from the first available one. However,
it only checks for raid_disk assignment and Faulty flag, missing the
In_sync flag check.

This can cause bitmap data to be read from spare disks that are still
being rebuilt and don't have valid bitmap information yet. Reading
stale or uninitialized bitmap data from such disks can lead to
incorrect dirty bit tracking, potentially causing data corruption
during recovery or normal operation.

Add the In_sync flag check to ensure bitmap pages are only read from
fully synchronized member disks that have valid bitmap data.

Cc: stable@vger.kernel.org
Fixes: 5ab829f1971d ("md/md-llbitmap: introduce new lockless bitmap")
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
 drivers/md/md-llbitmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
index cd713a7dc270..30d7e36b22c4 100644
--- a/drivers/md/md-llbitmap.c
+++ b/drivers/md/md-llbitmap.c
@@ -459,7 +459,8 @@ static struct page *llbitmap_read_page(struct llbitmap *llbitmap, int idx)
 	rdev_for_each(rdev, mddev) {
 		sector_t sector;
 
-		if (rdev->raid_disk < 0 || test_bit(Faulty, &rdev->flags))
+		if (rdev->raid_disk < 0 || test_bit(Faulty, &rdev->flags) ||
+		    !test_bit(In_sync, &rdev->flags))
 			continue;
 
 		sector = mddev->bitmap_info.offset +
-- 
2.51.0
Re: [PATCH v2 1/5] md/md-llbitmap: skip reading rdevs that are not in_sync
Posted by Xiao Ni 3 weeks, 3 days ago
On Mon, Feb 23, 2026 at 10:41 AM Yu Kuai <yukuai@fnnas.com> wrote:
>
> When reading bitmap pages from member disks, the code iterates through
> all rdevs and attempts to read from the first available one. However,
> it only checks for raid_disk assignment and Faulty flag, missing the
> In_sync flag check.
>
> This can cause bitmap data to be read from spare disks that are still
> being rebuilt and don't have valid bitmap information yet. Reading
> stale or uninitialized bitmap data from such disks can lead to
> incorrect dirty bit tracking, potentially causing data corruption
> during recovery or normal operation.
>
> Add the In_sync flag check to ensure bitmap pages are only read from
> fully synchronized member disks that have valid bitmap data.
>
> Cc: stable@vger.kernel.org
> Fixes: 5ab829f1971d ("md/md-llbitmap: introduce new lockless bitmap")
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
>  drivers/md/md-llbitmap.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
> index cd713a7dc270..30d7e36b22c4 100644
> --- a/drivers/md/md-llbitmap.c
> +++ b/drivers/md/md-llbitmap.c
> @@ -459,7 +459,8 @@ static struct page *llbitmap_read_page(struct llbitmap *llbitmap, int idx)
>         rdev_for_each(rdev, mddev) {
>                 sector_t sector;
>
> -               if (rdev->raid_disk < 0 || test_bit(Faulty, &rdev->flags))
> +               if (rdev->raid_disk < 0 || test_bit(Faulty, &rdev->flags) ||
> +                   !test_bit(In_sync, &rdev->flags))
>                         continue;
>
>                 sector = mddev->bitmap_info.offset +
> --
> 2.51.0
>
>

Reviewed-by: Xiao Ni <xni@redhat.com>