]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
md/md-llbitmap: raise barrier before state machine transition
authorYu Kuai <yukuai@fnnas.com>
Mon, 23 Feb 2026 02:40:35 +0000 (10:40 +0800)
committerYu Kuai <yukuai@fnnas.com>
Sun, 15 Mar 2026 17:24:59 +0000 (01:24 +0800)
Move the barrier raise operation before calling llbitmap_state_machine()
in both llbitmap_start_write() and llbitmap_start_discard(). This
ensures the barrier is in place before any state transitions occur,
preventing potential race conditions where the state machine could
complete before the barrier is properly raised.

Cc: stable@vger.kernel.org
Fixes: 5ab829f1971d ("md/md-llbitmap: introduce new lockless bitmap")
Link: https://lore.kernel.org/linux-raid/20260223024038.3084853-3-yukuai@fnnas.com
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
drivers/md/md-llbitmap.c

index 6b2d27de152856e0c19dadf3757b84a27db7657a..cdfecaca216bfcb0ebd9c5fa7123ac78a33bd8af 100644 (file)
@@ -1070,12 +1070,12 @@ static void llbitmap_start_write(struct mddev *mddev, sector_t offset,
        int page_start = (start + BITMAP_DATA_OFFSET) >> PAGE_SHIFT;
        int page_end = (end + BITMAP_DATA_OFFSET) >> PAGE_SHIFT;
 
-       llbitmap_state_machine(llbitmap, start, end, BitmapActionStartwrite);
-
        while (page_start <= page_end) {
                llbitmap_raise_barrier(llbitmap, page_start);
                page_start++;
        }
+
+       llbitmap_state_machine(llbitmap, start, end, BitmapActionStartwrite);
 }
 
 static void llbitmap_end_write(struct mddev *mddev, sector_t offset,
@@ -1102,12 +1102,12 @@ static void llbitmap_start_discard(struct mddev *mddev, sector_t offset,
        int page_start = (start + BITMAP_DATA_OFFSET) >> PAGE_SHIFT;
        int page_end = (end + BITMAP_DATA_OFFSET) >> PAGE_SHIFT;
 
-       llbitmap_state_machine(llbitmap, start, end, BitmapActionDiscard);
-
        while (page_start <= page_end) {
                llbitmap_raise_barrier(llbitmap, page_start);
                page_start++;
        }
+
+       llbitmap_state_machine(llbitmap, start, end, BitmapActionDiscard);
 }
 
 static void llbitmap_end_discard(struct mddev *mddev, sector_t offset,