Commit 5a5d7e9b authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG

In order to avoid WARN/BUG from generating nested or even recursive
warnings, force rcu_is_watching() true during
WARN/lockdep_rcu_suspicious().

Notably things like unwinding the stack can trigger rcu_dereference()
warnings, which then triggers more unwinding which then triggers more
warnings etc..
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230126151323.408156109@infradead.org
parent 393e2ea3
...@@ -130,9 +130,36 @@ static __always_inline unsigned long ct_state_inc(int incby) ...@@ -130,9 +130,36 @@ static __always_inline unsigned long ct_state_inc(int incby)
return arch_atomic_add_return(incby, this_cpu_ptr(&context_tracking.state)); return arch_atomic_add_return(incby, this_cpu_ptr(&context_tracking.state));
} }
static __always_inline bool warn_rcu_enter(void)
{
bool ret = false;
/*
* Horrible hack to shut up recursive RCU isn't watching fail since
* lots of the actual reporting also relies on RCU.
*/
preempt_disable_notrace();
if (rcu_dynticks_curr_cpu_in_eqs()) {
ret = true;
ct_state_inc(RCU_DYNTICKS_IDX);
}
return ret;
}
static __always_inline void warn_rcu_exit(bool rcu)
{
if (rcu)
ct_state_inc(RCU_DYNTICKS_IDX);
preempt_enable_notrace();
}
#else #else
static inline void ct_idle_enter(void) { } static inline void ct_idle_enter(void) { }
static inline void ct_idle_exit(void) { } static inline void ct_idle_exit(void) { }
static __always_inline bool warn_rcu_enter(void) { return false; }
static __always_inline void warn_rcu_exit(bool rcu) { }
#endif /* !CONFIG_CONTEXT_TRACKING_IDLE */ #endif /* !CONFIG_CONTEXT_TRACKING_IDLE */
#endif #endif
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <linux/context_tracking.h>
#include <asm/sections.h> #include <asm/sections.h>
...@@ -6555,6 +6556,7 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s) ...@@ -6555,6 +6556,7 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s)
{ {
struct task_struct *curr = current; struct task_struct *curr = current;
int dl = READ_ONCE(debug_locks); int dl = READ_ONCE(debug_locks);
bool rcu = warn_rcu_enter();
/* Note: the following can be executed concurrently, so be careful. */ /* Note: the following can be executed concurrently, so be careful. */
pr_warn("\n"); pr_warn("\n");
...@@ -6595,5 +6597,6 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s) ...@@ -6595,5 +6597,6 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s)
lockdep_print_held_locks(curr); lockdep_print_held_locks(curr);
pr_warn("\nstack backtrace:\n"); pr_warn("\nstack backtrace:\n");
dump_stack(); dump_stack();
warn_rcu_exit(rcu);
} }
EXPORT_SYMBOL_GPL(lockdep_rcu_suspicious); EXPORT_SYMBOL_GPL(lockdep_rcu_suspicious);
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/context_tracking.h>
#include <trace/events/error_report.h> #include <trace/events/error_report.h>
#include <asm/sections.h> #include <asm/sections.h>
...@@ -679,6 +680,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, ...@@ -679,6 +680,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
void warn_slowpath_fmt(const char *file, int line, unsigned taint, void warn_slowpath_fmt(const char *file, int line, unsigned taint,
const char *fmt, ...) const char *fmt, ...)
{ {
bool rcu = warn_rcu_enter();
struct warn_args args; struct warn_args args;
pr_warn(CUT_HERE); pr_warn(CUT_HERE);
...@@ -693,11 +695,13 @@ void warn_slowpath_fmt(const char *file, int line, unsigned taint, ...@@ -693,11 +695,13 @@ void warn_slowpath_fmt(const char *file, int line, unsigned taint,
va_start(args.args, fmt); va_start(args.args, fmt);
__warn(file, line, __builtin_return_address(0), taint, NULL, &args); __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
va_end(args.args); va_end(args.args);
warn_rcu_exit(rcu);
} }
EXPORT_SYMBOL(warn_slowpath_fmt); EXPORT_SYMBOL(warn_slowpath_fmt);
#else #else
void __warn_printk(const char *fmt, ...) void __warn_printk(const char *fmt, ...)
{ {
bool rcu = warn_rcu_enter();
va_list args; va_list args;
pr_warn(CUT_HERE); pr_warn(CUT_HERE);
...@@ -705,6 +709,7 @@ void __warn_printk(const char *fmt, ...) ...@@ -705,6 +709,7 @@ void __warn_printk(const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
vprintk(fmt, args); vprintk(fmt, args);
va_end(args); va_end(args);
warn_rcu_exit(rcu);
} }
EXPORT_SYMBOL(__warn_printk); EXPORT_SYMBOL(__warn_printk);
#endif #endif
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include <linux/ftrace.h> #include <linux/ftrace.h>
#include <linux/context_tracking.h>
extern struct bug_entry __start___bug_table[], __stop___bug_table[]; extern struct bug_entry __start___bug_table[], __stop___bug_table[];
...@@ -153,7 +154,7 @@ struct bug_entry *find_bug(unsigned long bugaddr) ...@@ -153,7 +154,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
return module_find_bug(bugaddr); return module_find_bug(bugaddr);
} }
enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *regs)
{ {
struct bug_entry *bug; struct bug_entry *bug;
const char *file; const char *file;
...@@ -209,6 +210,18 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) ...@@ -209,6 +210,18 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
return BUG_TRAP_TYPE_BUG; return BUG_TRAP_TYPE_BUG;
} }
enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
{
enum bug_trap_type ret;
bool rcu = false;
rcu = warn_rcu_enter();
ret = __report_bug(bugaddr, regs);
warn_rcu_exit(rcu);
return ret;
}
static void clear_once_table(struct bug_entry *start, struct bug_entry *end) static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
{ {
struct bug_entry *bug; struct bug_entry *bug;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment