From: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Philipp Reisner" <philipp.reisner@linbit.com>,
"Lars Ellenberg" <lars.ellenberg@linbit.com>,
drbd-dev@lists.linux.dev, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
Subject: [PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs
Date: Thu, 26 Nov 2026 15:52:55 +0100 [thread overview]
Message-ID: <20261126145257.592085-3-christoph.boehmwalder@linbit.com> (raw)
In-Reply-To: <20261126145257.592085-1-christoph.boehmwalder@linbit.com>
From: Lars Ellenberg <lars.ellenberg@linbit.com>
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@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
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
next prev parent reply other threads:[~2026-11-26 14:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake Christoph Böhmwalder
2026-11-26 14:52 ` Christoph Böhmwalder [this message]
2026-11-26 14:52 ` [PATCH 3/4] drbd: resize: do not silently "truncate" the effective size Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 4/4] drbd: refuse to shrink on resize unless an explicit size is requested Christoph Böhmwalder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126145257.592085-3-christoph.boehmwalder@linbit.com \
--to=christoph.boehmwalder@linbit.com \
--cc=axboe@kernel.dk \
--cc=drbd-dev@lists.linux.dev \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®