Skip to content

Fix data race with transaction->state

Josef Bacik linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 5 repliesIn review
  2. v12 patches 1 replySuperseded

Changes in v2 from the cover letter

- I'm rusty and forgot READ_ONCE/WRITE_ONCE doesn't mean smp consistency, fixed the race with a proper locked check.
- Updated the smp_mb usage in start_transaction to use the proper helper.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2btrfs: fix data race on transaction->statefs/btrfs/transaction.c+15 -33 replies
2/2btrfs: remove useless smp_mb in start_transactionfs/btrfs/transaction.c+1 -21 reply

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchQu Wenruo
SeriesR-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] Fix data race with transaction->state

v1: https://lore.kernel.org/linux-btrfs/[email protected]/

v1->v2:
- I'm rusty and forgot READ_ONCE/WRITE_ONCE doesn't mean smp consistency, fixed the race with a proper locked check.
- Updated the smp_mb usage in start_transaction to use the proper helper.

I want to note that this isn't actually an observed hang, there was a problem with MMIO based block IO in my version of QEMU that was making IO just stop. I happened to notice this because the hung tasks looked very much like a deadlock. This fixes a real data race, and we would for sure miss wakeups without these fixes, but I don't actually have a reproducer for any sort of deadlock in this area.

=== Original email ===

I've been setting up Claude to setup fstests and run vms automatically and I kept hitting hangs. This turned out to be a bug with qemu's microvm, but at some point I was convinced there was a deadlock with running out of block tags and ordered extent completion and transaction commit. This actually wasn't the case, however this data race is in fact real. We can easily miss wakeups if we have to wait on transaction state to change because we do it outside of a lock and we do not have proper barriers around transaction->state. I suspect this explains the random hangs that I would see in production while at Meta that would clear up eventually (we do call wakeup on the transaction wait thing a lot). In any case this is a data race, even if it wasn't my particular bug, we should fix it. I've run it through fstests a few times, but obviously spot check it since I'm a little rusty with this stuff at the moment. Thanks,

Josef

Josef Bacik (2):
btrfs: fix data race on transaction->state
btrfs: remove useless smp_mb in start_transaction

 fs/btrfs/transaction.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.1