Skip to content

Commit 1f88c35

Browse files
author
Kent Overstreet
committed
bcachefs: Fix a KMSAN splat in btree_update_nodes_written()
We may sometimes read from uninitialized memory; we know, and that's ok. We check if a btree node has been reused before waiting on any outstanding IO. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 28aa859 commit 1f88c35

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/bcachefs/btree_update_interior.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,14 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans,
649649
return 0;
650650
}
651651

652+
/* If the node has been reused, we might be reading uninitialized memory - that's fine: */
653+
static noinline __no_kmsan_checks bool btree_node_seq_matches(struct btree *b, __le64 seq)
654+
{
655+
struct btree_node *b_data = READ_ONCE(b->data);
656+
657+
return (b_data ? b_data->keys.seq : 0) == seq;
658+
}
659+
652660
static void btree_update_nodes_written(struct btree_update *as)
653661
{
654662
struct bch_fs *c = as->c;
@@ -677,17 +685,9 @@ static void btree_update_nodes_written(struct btree_update *as)
677685
* on disk:
678686
*/
679687
for (i = 0; i < as->nr_old_nodes; i++) {
680-
__le64 seq;
681-
682688
b = as->old_nodes[i];
683689

684-
bch2_trans_begin(trans);
685-
btree_node_lock_nopath_nofail(trans, &b->c, SIX_LOCK_read);
686-
seq = b->data ? b->data->keys.seq : 0;
687-
six_unlock_read(&b->c.lock);
688-
bch2_trans_unlock_long(trans);
689-
690-
if (seq == as->old_nodes_seq[i])
690+
if (btree_node_seq_matches(b, as->old_nodes_seq[i]))
691691
wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight_inner,
692692
TASK_UNINTERRUPTIBLE);
693693
}

0 commit comments

Comments
 (0)