bcachefs: Fix possible console lock involved deadlock
authorAlan Huang <mmpgouride@gmail.com>
Tue, 20 May 2025 07:34:28 +0000 (15:34 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Jun 2025 03:21:30 +0000 (23:21 -0400)
Link: https://lore.kernel.org/all/6822ab02.050a0220.f2294.00cb.GAE@google.com/T/
Reported-by: syzbot+2c3ef91c9523c3d1a25c@syzkaller.appspotmail.com
Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs.h
fs/bcachefs/btree_locking.c
fs/bcachefs/error.c
fs/bcachefs/super.c
fs/bcachefs/util.c
fs/bcachefs/util.h

index 3651a296d506c937664d8b644e38fa70eb0494ea..5a1cede2febf5e3d070cfa5eee097203219317b9 100644 (file)
@@ -296,7 +296,6 @@ do {                                                                        \
 #define bch2_fmt(_c, fmt)              bch2_log_msg(_c, fmt "\n")
 
 void bch2_print_str(struct bch_fs *, const char *, const char *);
-void bch2_print_str_nonblocking(struct bch_fs *, const char *, const char *);
 
 __printf(2, 3)
 void bch2_print_opts(struct bch_opts *, const char *, ...);
index 47035aae232ea8fa58a2825ce01eb12620515f2b..91a51aef82f1c4e50ce5459a346624e80f5d9722 100644 (file)
@@ -213,7 +213,7 @@ static noinline __noreturn void break_cycle_fail(struct lock_graph *g)
                prt_newline(&buf);
        }
 
-       bch2_print_str_nonblocking(g->g->trans->c, KERN_ERR, buf.buf);
+       bch2_print_str(g->g->trans->c, KERN_ERR, buf.buf);
        printbuf_exit(&buf);
        BUG();
 }
index ff49cebfd0e8d1ad25c5c14041c436a02642bfe9..a8ec6aae57383fd875d95b131b8124e588c3b762 100644 (file)
@@ -69,7 +69,7 @@ static bool bch2_fs_trans_inconsistent(struct bch_fs *c, struct btree_trans *tra
        if (trans)
                bch2_trans_updates_to_text(&buf, trans);
        bool ret = __bch2_inconsistent_error(c, &buf);
-       bch2_print_str_nonblocking(c, KERN_ERR, buf.buf);
+       bch2_print_str(c, KERN_ERR, buf.buf);
 
        printbuf_exit(&buf);
        return ret;
index 8648f22411be8c8364cc9cdfba9e9370d2609bce..ae8fa58a208df53eac19bc3cfcd158ed1babbcfa 100644 (file)
@@ -104,7 +104,7 @@ const char * const bch2_dev_write_refs[] = {
 #undef x
 
 static void __bch2_print_str(struct bch_fs *c, const char *prefix,
-                            const char *str, bool nonblocking)
+                            const char *str)
 {
 #ifdef __KERNEL__
        struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c);
@@ -114,17 +114,12 @@ static void __bch2_print_str(struct bch_fs *c, const char *prefix,
                return;
        }
 #endif
-       bch2_print_string_as_lines(KERN_ERR, str, nonblocking);
+       bch2_print_string_as_lines(KERN_ERR, str);
 }
 
 void bch2_print_str(struct bch_fs *c, const char *prefix, const char *str)
 {
-       __bch2_print_str(c, prefix, str, false);
-}
-
-void bch2_print_str_nonblocking(struct bch_fs *c, const char *prefix, const char *str)
-{
-       __bch2_print_str(c, prefix, str, true);
+       __bch2_print_str(c, prefix, str);
 }
 
 __printf(2, 0)
index dc3817f545fa7eb657f108012e66ba03391c5630..df9a6071fe186b2fdf56cb3c7278acd6a3b050b0 100644 (file)
@@ -262,8 +262,7 @@ static bool string_is_spaces(const char *str)
        return true;
 }
 
-void bch2_print_string_as_lines(const char *prefix, const char *lines,
-                               bool nonblocking)
+void bch2_print_string_as_lines(const char *prefix, const char *lines)
 {
        bool locked = false;
        const char *p;
@@ -273,12 +272,7 @@ void bch2_print_string_as_lines(const char *prefix, const char *lines,
                return;
        }
 
-       if (!nonblocking) {
-               console_lock();
-               locked = true;
-       } else {
-               locked = console_trylock();
-       }
+       locked = console_trylock();
 
        while (*lines) {
                p = strchrnul(lines, '\n');
index 0a4b1d4336217e6be5cf9aa1d3c64dcb13216230..6488f098d1407e2fa8acc8ef33bca43b1055a4d4 100644 (file)
@@ -214,7 +214,7 @@ u64 bch2_read_flag_list(const char *, const char * const[]);
 void bch2_prt_u64_base2_nbits(struct printbuf *, u64, unsigned);
 void bch2_prt_u64_base2(struct printbuf *, u64);
 
-void bch2_print_string_as_lines(const char *, const char *, bool);
+void bch2_print_string_as_lines(const char *, const char *);
 
 typedef DARRAY(unsigned long) bch_stacktrace;
 int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned, gfp_t);