[PATCH] bcachefs: fix hung in bch2_fs_read_only_work

Lizhi Xu posted 1 patch 1 year, 5 months ago
fs/bcachefs/journal_io.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] bcachefs: fix hung in bch2_fs_read_only_work
Posted by Lizhi Xu 1 year, 5 months ago
Error logs:
[ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down
[ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down
[ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down

When hit -BCH_ERR_fsck_errors_not_fixed in journal_entry_err, it will make
journal_entry_btree_keys_validate output too many same error log, and it will block
bch2_fs_start to release state_lock.

Reported-and-tested-by: syzbot+8996d8f176cf946ef641@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8996d8f176cf946ef641
Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
---
 fs/bcachefs/journal_io.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index 492426c8d869..67c3f09162e4 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -415,6 +415,8 @@ static int journal_entry_btree_keys_validate(struct bch_fs *c,
 					       flags|BCH_VALIDATE_journal);
 		if (ret == FSCK_DELETED_KEY)
 			continue;
+		else if (ret == -BCH_ERR_fsck_errors_not_fixed)
+			break;
 
 		k = bkey_next(k);
 	}
-- 
2.43.0
Re: [PATCH] bcachefs: fix hung in bch2_fs_read_only_work
Posted by Kent Overstreet 1 year, 5 months ago
On Mon, Jul 01, 2024 at 10:36:06PM GMT, Lizhi Xu wrote:
> Error logs:
> [ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down
> [ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down
> [ T5078] invalid journal entry, version=1.7: mi_btree_bitmap type=btree_keys in superblock: k->u64s 0, shutting down
> 
> When hit -BCH_ERR_fsck_errors_not_fixed in journal_entry_err, it will make
> journal_entry_btree_keys_validate output too many same error log, and it will block
> bch2_fs_start to release state_lock.
> 
> Reported-and-tested-by: syzbot+8996d8f176cf946ef641@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=8996d8f176cf946ef641
> Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
> ---
>  fs/bcachefs/journal_io.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
> index 492426c8d869..67c3f09162e4 100644
> --- a/fs/bcachefs/journal_io.c
> +++ b/fs/bcachefs/journal_io.c
> @@ -415,6 +415,8 @@ static int journal_entry_btree_keys_validate(struct bch_fs *c,
>  					       flags|BCH_VALIDATE_journal);
>  		if (ret == FSCK_DELETED_KEY)
>  			continue;
> +		else if (ret == -BCH_ERR_fsck_errors_not_fixed)
> +			break;

Actually, this is wrong: we need to return the error


commit b2879202fa55861d05088bbffdb529cf5d5ba7f8
Author: Kent Overstreet <kent.overstreet@linux.dev>
Date:   Thu Jul 4 21:18:06 2024 -0400

    bcachefs: Fix missing error check in journal_entry_btree_keys_validate()
    
    Closes: https://syzkaller.appspot.com/bug?extid=8996d8f176cf946ef641
    Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index 40ed7a619594..7a833a3f1c63 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -415,6 +415,8 @@ static int journal_entry_btree_keys_validate(struct bch_fs *c,
 					       flags|BCH_VALIDATE_journal);
 		if (ret == FSCK_DELETED_KEY)
 			continue;
+		else if (ret)
+			return ret;
 
 		k = bkey_next(k);
 	}