[PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs

From: Christoph Böhmwalder

Date: Thu Nov 26 2026 - 09:53:20 EST


From: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>

drbd_queue_bitmap_io(): set_bit(BITMAP_IO); read ap_bio_cnt (req_lock)
dec_ap_bio(): dec ap_bio_cnt; test_bit(BITMAP_IO)

Both sites decide whether to queue the whole-bitmap work by inspecting
the same two locations in opposite order. dec_ap_bio() does not take
req_lock, so the lock gives no mutual exclusion between them. On a
weakly ordered CPU the queue-side set_bit/atomic_read store-load pair
may reorder, so both sites read the other's pre-update value and neither
queues the work. BITMAP_IO then stays set and application IO is frozen
until the connection times out.

Observed on aarch64: a source-side reconnect parks in WFBitMapS,
drbd_send_bitmap never runs (no "send bitmap stats", no WFBitMapS ->
SyncSource), database threads hang in fdatasync/writeback. Not
reproducible on x86, where set_bit() is a full barrier.

Order the BITMAP_IO store before the ap_bio_cnt load.
atomic_dec_return() already orders the dec_ap_bio() side.

Commit 22afd7ee94c1 ("drbd: Fixed race condition in
drbd_queue_bitmap_io") added the req_lock on the queue side only; it
does not close this reorder.

Signed-off-by: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@xxxxxxxxxx>
---
drivers/block/drbd/drbd_int.h | 3 +++
drivers/block/drbd/drbd_main.c | 8 ++++++++
2 files changed, 11 insertions(+)

diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 40be382b24d2..20899a0d7e45 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -2213,6 +2213,9 @@ static inline void dec_ap_bio(struct drbd_device *device)

D_ASSERT(device, ap_bio >= 0);

+ /* atomic_dec_return() above orders this against the
+ * set_bit(BITMAP_IO) / ap_bio_cnt read in drbd_queue_bitmap_io().
+ */
if (ap_bio == 0 && test_bit(BITMAP_IO, &device->flags)) {
if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags))
drbd_queue_work(&first_peer_device(device)->
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index aed1d1ab6d0f..fd83fc492a79 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -3497,6 +3497,14 @@ void drbd_queue_bitmap_io(struct drbd_device *device,

spin_lock_irq(&device->resource->req_lock);
set_bit(BITMAP_IO, &device->flags);
+ /* Pair with atomic_dec_return() in dec_ap_bio(): order this BITMAP_IO
+ * store before the ap_bio_cnt load below. dec_ap_bio() decrements
+ * ap_bio_cnt and then tests BITMAP_IO in the reverse order. Without
+ * this barrier, on weakly ordered CPUs both sites may observe the
+ * other's stale value, so neither queues the bitmap work: BITMAP_IO
+ * stays set and application IO freezes.
+ */
+ smp_mb__after_atomic();
/* don't wait for pending application IO if the caller indicates that
* application IO does not conflict anyways. */
if (flags == BM_LOCKED_CHANGE_ALLOWED || atomic_read(&device->ap_bio_cnt) == 0) {
--
2.56.0