kmsan splat fixes
cover kmsan splat fixes
we should be just about kmsan clean now; not 100%, the kmsan tests are extremely heavy so I'm not flipping them on in the CI yet.
none of these were actual bugs, but this will make a massive dent in the syzbot dashboard.
Kent Overstreet (5):
bcachefs: Disable asm memcpys when kmsan enabled
bcachefs: Fix kmsan warnings in bch2_extent_crc_pack()
bcachefs: kmsan asserts
bcachefs: Fix a KMSAN splat in btree_update_nodes_written()
bcachefs: move_bucket_key -> __packed
fs/bcachefs/btree_trans_commit.c | 1 + fs/bcachefs/btree_update.c | 2 ++ fs/bcachefs/btree_update.h | 2 ++ fs/bcachefs/btree_update_interior.c | 18 +++++++------- fs/bcachefs/extents.c | 38 +++++++++++++++++------------ fs/bcachefs/move_types.h | 2 +- fs/bcachefs/util.h | 4 +-- 7 files changed, 39 insertions(+), 28 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/5 bcachefs: Disable asm memcpys when kmsan enabled
kmsan doesn't know about inline assembly, obviously; this will close a ton of syzbot bugs.
--- fs/bcachefs/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/util.h +2 -2
@@ -431,7 +431,7 @@ static inline void memcpy_u64s_small(void *dst, const void *src,static inline void __memcpy_u64s (void *dst,const void *src,unsigned u64s) { -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64 ) && !defined(CONFIG_KMSAN )long d0, d1, d2; asm volatile("rep ; movsq"
@@ -508,7 +508,7 @@ static inline void __memmove_u64s_up(void *_dst, const void *_src,u64 *dst = (u64 *) _dst + u64s -1 ;u64 *src = (u64 *) _src + u64s -1 ; -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64 ) && !defined(CONFIG_KMSAN )long d0, d1, d2; asm volatile("std ;\n"
Signature · 1 line
2.49.0
PATCH 2/5 bcachefs: Fix kmsan warnings in bch2_extent_crc_pack()
In reply to Kent OverstreetWe store to all fields, so the kmsan warnings were spurious - but initializing via stores to bitfields appear to have been giving the compiler/kmsan trouble, and they're not necessary.
--- fs/bcachefs/extents.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
fs/bcachefs/extents.c +22 -16
@@ -592,29 +592,35 @@ static void bch2_extent_crc_pack(union bch_extent_crc *dst, struct bch_extent_crc_unpacked src, enum bch_extent_entry_type type) { -#define set_common_fields (_dst, _src) \ - _dst.type = 1 << type; \ - _dst.csum_type = _src.csum_type, \ - _dst.compression_type = _src.compression_type, \ - _dst._compressed_size = _src.compressed_size - 1, \ - _dst._uncompressed_size = _src.uncompressed_size - 1, \ - _dst.offset = _src.offset +#define common_fields (_src) \ + .type = BIT(type), \ + .csum_type = _src.csum_type, \ + .compression_type = _src.compression_type, \ + ._compressed_size = _src.compressed_size - 1, \ + ._uncompressed_size = _src.uncompressed_size - 1, \ + .offset = _src.offsetswitch (type) {case BCH_EXTENT_ENTRY_crc32: -set_common_fields (dst->crc32, src); - dst->crc32.csum = (u32__force ) *((__le32 *) &src.csum.lo); + dst->crc32 = (struct bch_extent_crc32 ) { +common_fields (src), + .csum = (u32__force ) *((__le32 *) &src.csum.lo), + };break ;case BCH_EXTENT_ENTRY_crc64: -set_common_fields (dst->crc64, src); - dst->crc64.nonce = src.nonce; - dst->crc64.csum_lo = (u64 __force ) src.csum.lo; - dst->crc64.csum_hi = (u64__force ) *((__le16 *) &src.csum.hi); + dst->crc64 = (struct bch_extent_crc64 ) { +common_fields (src), + .nonce = src.nonce, + .csum_lo = (u64 __force ) src.csum.lo, + .csum_hi = (u64__force ) *((__le16 *) &src.csum.hi), + };break ;case BCH_EXTENT_ENTRY_crc128: -set_common_fields (dst->crc128, src); - dst->crc128.nonce = src.nonce; - dst->crc128.csum = src.csum; + dst->crc128 = (struct bch_extent_crc128 ) { +common_fields (src), + .nonce = src.nonce, + .csum = src.csum, + };break ;default :BUG ();
Signature · 1 line
2.49.0
PATCH 3/5 bcachefs: kmsan asserts
In reply to Kent OverstreetCatching these early makes them a lot easier to track down.
--- fs/bcachefs/btree_trans_commit.c | 1 + fs/bcachefs/btree_update.c | 2 ++ fs/bcachefs/btree_update.h | 2 ++ 3 files changed, 5 insertions(+)
fs/bcachefs/btree_trans_commit.c +1 -0
@@ -164,6 +164,7 @@ bool bch2_btree_bset_insert_key(struct btree_trans *trans,EBUG_ON (bpos_gt (insert->k.p, b->data->max_key));EBUG_ON (insert->k.u64s >bch2_btree_keys_u64s_remaining (b));EBUG_ON (!b->c.level && !bpos_eq (insert->k.p, path->pos)); +kmsan_check_memory (insert,bkey_bytes (&insert->k)); k =bch2_btree_node_iter_peek_all (node_iter, b);if (k &&bkey_cmp_left_packed (b, k, &insert->k.p))
fs/bcachefs/btree_update.c +2 -0
@@ -512,6 +512,8 @@ static noinline int bch2_trans_update_get_key_cache(struct btree_trans *trans,int __must_check bch2_trans_update (struct btree_trans *trans,struct btree_iter *iter,struct bkey_i *k,enum btree_iter_update_trigger_flags flags) { +kmsan_check_memory (k,bkey_bytes (&k->k)); +btree_path_idx_t path_idx = iter->update_path ?: iter->path;int ret;
fs/bcachefs/btree_update.h +2 -0
@@ -133,6 +133,8 @@ static inline int __must_check bch2_trans_update_buffered(struct btree_trans *trenum btree_id btree, struct bkey_i *k) { + kmsan_check_memory(k, bkey_bytes(&k->k)); +if (unlikely (!btree_type_uses_write_buffer (btree))) {int ret =bch2_btree_write_buffer_insert_err (trans, btree, k);dump_stack ();
Signature · 1 line
2.49.0
PATCH 4/5 bcachefs: Fix a KMSAN splat in btree_update_nodes_written()
In reply to Kent OverstreetWe 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.
--- fs/bcachefs/btree_update_interior.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
fs/bcachefs/btree_update_interior.c +9 -9
@@ -649,6 +649,14 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans,return 0 ; } +/* If the node has been reused, we might be reading uninitialized memory - that's fine: */ +static noinline __no_kmsan_checks bool btree_node_seq_matches(struct btree *b, __le64 seq) +{ +struct btree_node *b_data =READ_ONCE (b->data); + +return (b_data ? b_data->keys.seq :0 ) == seq; +} +static void btree_update_nodes_written (struct btree_update *as) {struct bch_fs *c = as->c;
@@ -677,17 +685,9 @@ static void btree_update_nodes_written(struct btree_update *as)* on disk: */ for (i =0 ; i < as->nr_old_nodes; i++) { -__le64 seq; - b = as->old_nodes[i]; -bch2_trans_begin (trans); -btree_node_lock_nopath_nofail (trans, &b->c, SIX_LOCK_read); - seq = b->data ? b->data->keys.seq :0 ; -six_unlock_read (&b->c.lock); -bch2_trans_unlock_long (trans); - -if (seq == as->old_nodes_seq[i]) +if (btree_node_seq_matches (b, as->old_nodes_seq[i]))wait_on_bit_io (&b->flags, BTREE_NODE_write_in_flight_inner,TASK_UNINTERRUPTIBLE ); }
Signature · 1 line
2.49.0
PATCH 5/5 bcachefs: move_bucket_key -> __packed
In reply to Kent Overstreetwe appear to be tripping over a compiler/kmsan bug with padding fields - this is an easy workaround.
--- fs/bcachefs/move_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/move_types.h +1 -1
@@ -33,7 +33,7 @@ struct bch_move_stats {struct move_bucket_key {struct bpos bucket;u8 gen; -}; +} __packed;struct move_bucket {struct move_bucket_key k;
Signature · 1 line
2.49.0