From 73f88592dd1bef38542024ef8223599afc2c41bb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 21 Jun 2024 16:38:44 -0400 Subject: bcachefs: mean_and_variance: Avoid too-large shift amounts Shifting a value by the width of its type or more is undefined. Signed-off-by: Tavian Barnes Signed-off-by: Kent Overstreet --- fs/bcachefs/mean_and_variance.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/bcachefs/mean_and_variance.h b/fs/bcachefs/mean_and_variance.h index 4fcf062dd22c..47e4a3c3d26e 100644 --- a/fs/bcachefs/mean_and_variance.h +++ b/fs/bcachefs/mean_and_variance.h @@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift) { u128_u r; - r.lo = i.lo << shift; + r.lo = i.lo << (shift & 63); if (shift < 64) - r.hi = (i.hi << shift) | (i.lo >> (64 - shift)); + r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63)); else { - r.hi = i.lo << (shift - 64); + r.hi = i.lo << (-shift & 63); r.lo = 0; } return r; -- cgit From 2fa88b191929d3115ccda098071b34922957bb08 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 17 Jul 2024 11:56:05 -0400 Subject: bcachefs: kill btree_trans_too_many_iters() in bch2_bucket_alloc_freelist() When we're called via trans commit -> btree split -> allocator We may have already arbitrarily many btree_paths, for the transaction commit we're trying to do; when this happens, the btree_trans_too_many_iters() call causes us to livelock. Since the allocator calls btree_iter_dontneed to release paths as it iterates, this shouldn't cause any problems. Signed-off-by: Kent Overstreet --- fs/bcachefs/alloc_foreground.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/bcachefs/alloc_foreground.c b/fs/bcachefs/alloc_foreground.c index cabf866c7956..618d2ff0292e 100644 --- a/fs/bcachefs/alloc_foreground.c +++ b/fs/bcachefs/alloc_foreground.c @@ -496,12 +496,6 @@ again: for (alloc_cursor = max(alloc_cursor, bkey_start_offset(k.k)); alloc_cursor < k.k->p.offset; alloc_cursor++) { - ret = btree_trans_too_many_iters(trans); - if (ret) { - ob = ERR_PTR(ret); - break; - } - s->buckets_seen++; u64 bucket = alloc_cursor & ~(~0ULL << 56); -- cgit From 7a086baad0d640a45dbc65d6853a58ca6368892b Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 20 Jul 2024 14:37:24 -0400 Subject: bcachefs: More informative error message in reattach_inode() Signed-off-by: Kent Overstreet --- fs/bcachefs/fsck.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index cc4f0963c0c5..9138944c5ae6 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -283,6 +283,7 @@ static int reattach_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 inode_snapshot) { + struct bch_fs *c = trans->c; struct bch_hash_info dir_hash; struct bch_inode_unpacked lostfound; char name_buf[20]; @@ -317,7 +318,7 @@ static int reattach_inode(struct btree_trans *trans, return ret; } - dir_hash = bch2_hash_info_init(trans->c, &lostfound); + dir_hash = bch2_hash_info_init(c, &lostfound); name = (struct qstr) QSTR(name_buf); @@ -330,8 +331,10 @@ static int reattach_inode(struct btree_trans *trans, inode->bi_subvol ?: inode->bi_inum, &dir_offset, STR_HASH_must_create); - if (ret) + if (ret) { + bch_err_msg(c, ret, "error creating dirent"); return ret; + } inode->bi_dir = lostfound.bi_inum; inode->bi_dir_offset = dir_offset; -- cgit From 737759fc098f7bb7fb4cef64fec731803e955e01 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 22 Jul 2024 11:25:03 -0400 Subject: bcachefs: Fix printbuf usage while atomic Reported-by: syzbot+f765e51170cf13493f0b@syzkaller.appspotmail.com Fixes: f12410bb7ddd ("bcachefs: Add an error message for insufficient rw journal devs") Signed-off-by: Kent Overstreet --- fs/bcachefs/journal_reclaim.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/bcachefs/journal_reclaim.c b/fs/bcachefs/journal_reclaim.c index d8a630742887..70b998d9f19c 100644 --- a/fs/bcachefs/journal_reclaim.c +++ b/fs/bcachefs/journal_reclaim.c @@ -206,6 +206,7 @@ void bch2_journal_space_available(struct journal *j) if (nr_online < metadata_replicas_required(c)) { struct printbuf buf = PRINTBUF; + buf.atomic++; prt_printf(&buf, "insufficient writeable journal devices available: have %u, need %u\n" "rw journal devs:", nr_online, metadata_replicas_required(c)); -- cgit