Skip to content

Commit 7d2c27a

Browse files
author
Peter Zijlstra
committed
bug: Add report_bug_entry()
Add a report_bug() variant where the bug_entry is already known. This is useful when the exception instruction is not instantiated per-site. But instead has a single instance. In such a case the bug_entry address might be passed along in a known register or something. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251110115757.575795595@infradead.org
1 parent 5c47b7f commit 7d2c27a

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

include/linux/bug.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void bug_get_file_line(struct bug_entry *bug, const char **file,
4242
struct bug_entry *find_bug(unsigned long bugaddr);
4343

4444
enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
45+
enum bug_trap_type report_bug_entry(struct bug_entry *bug, struct pt_regs *regs);
4546

4647
/* These are defined by the architecture */
4748
int is_valid_bugaddr(unsigned long addr);
@@ -62,6 +63,13 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr,
6263
}
6364

6465
struct bug_entry;
66+
67+
static inline enum bug_trap_type
68+
report_bug_entry(struct bug_entry *bug, struct pt_regs *regs)
69+
{
70+
return BUG_TRAP_TYPE_BUG;
71+
}
72+
6573
static inline void bug_get_file_line(struct bug_entry *bug, const char **file,
6674
unsigned int *line)
6775
{

lib/bug.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,20 @@ static void __warn_printf(const char *fmt, struct pt_regs *regs)
183183
printk("%s", fmt);
184184
}
185185

186-
static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *regs)
186+
static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long bugaddr, struct pt_regs *regs)
187187
{
188188
bool warning, once, done, no_cut, has_args;
189189
const char *file, *fmt;
190190
unsigned line;
191191

192-
if (!is_valid_bugaddr(bugaddr))
193-
return BUG_TRAP_TYPE_NONE;
192+
if (!bug) {
193+
if (!is_valid_bugaddr(bugaddr))
194+
return BUG_TRAP_TYPE_NONE;
194195

195-
bug = find_bug(bugaddr);
196-
if (!bug)
197-
return BUG_TRAP_TYPE_NONE;
196+
bug = find_bug(bugaddr);
197+
if (!bug)
198+
return BUG_TRAP_TYPE_NONE;
199+
}
198200

199201
disable_trace_on_warning();
200202

@@ -244,13 +246,25 @@ static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *re
244246
return BUG_TRAP_TYPE_BUG;
245247
}
246248

249+
enum bug_trap_type report_bug_entry(struct bug_entry *bug, struct pt_regs *regs)
250+
{
251+
enum bug_trap_type ret;
252+
bool rcu = false;
253+
254+
rcu = warn_rcu_enter();
255+
ret = __report_bug(bug, 0, regs);
256+
warn_rcu_exit(rcu);
257+
258+
return ret;
259+
}
260+
247261
enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
248262
{
249263
enum bug_trap_type ret;
250264
bool rcu = false;
251265

252266
rcu = warn_rcu_enter();
253-
ret = __report_bug(bugaddr, regs);
267+
ret = __report_bug(NULL, bugaddr, regs);
254268
warn_rcu_exit(rcu);
255269

256270
return ret;

0 commit comments

Comments
 (0)