bcachefs: Fix possible console lock involved deadlock

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>
This commit is contained in:
Alan Huang 2025-05-20 15:34:28 +08:00 committed by Kent Overstreet
parent 3315113af1
commit 0acb385ec1
6 changed files with 8 additions and 20 deletions

View 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 *, ...);

View 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();
}

View 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;

View 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)

View 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();
}
while (*lines) {
p = strchrnul(lines, '\n');

View 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);