Skip to content

Commit e115f2c

Browse files
committed
sh: unwinder: Use a special bug flag for unwinder traps.
This simplifies the unwinder trap handling, dropping the use of the special trapa vector and simply piggybacking on top of the BUG support. A new BUGFLAG_UNWINDER is added for flagging the unwinder fault, before continuing on with regular BUG dispatch. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent c153a58 commit e115f2c

4 files changed

Lines changed: 24 additions & 35 deletions

File tree

‎arch/sh/include/asm/bug.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef __ASM_SH_BUG_H
22
#define __ASM_SH_BUG_H
33

4-
#define TRAPA_UNWINDER_BUG_OPCODE 0xc33b /* trapa #0x3b */
54
#define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */
5+
#define BUGFLAG_UNWINDER (1 << 1)
66

77
#ifdef CONFIG_GENERIC_BUG
88
#define HAVE_ARCH_BUG
@@ -73,15 +73,16 @@ do { \
7373
unlikely(__ret_warn_on); \
7474
})
7575

76-
#define UNWINDER_BUG() \
76+
#define UNWINDER_BUG() \
7777
do { \
7878
__asm__ __volatile__ ( \
7979
"1:\t.short %O0\n" \
80-
_EMIT_BUG_ENTRY \
80+
_EMIT_BUG_ENTRY \
8181
: \
82-
: "n" (TRAPA_UNWINDER_BUG_OPCODE), \
82+
: "n" (TRAPA_BUG_OPCODE), \
8383
"i" (__FILE__), \
84-
"i" (__LINE__), "i" (0), \
84+
"i" (__LINE__), \
85+
"i" (BUGFLAG_UNWINDER), \
8586
"i" (sizeof(struct bug_entry))); \
8687
} while (0)
8788

‎arch/sh/kernel/debugtraps.S‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020
#if !defined(CONFIG_SH_STANDARD_BIOS)
2121
#define sh_bios_handler debug_trap_handler
22-
#endif
23-
24-
#if !defined(CONFIG_DWARF_UNWINDER)
25-
#define unwinder_trap_handler debug_trap_handler
2622
#endif
2723

2824
.data
@@ -39,7 +35,7 @@ ENTRY(debug_trap_table)
3935
.long debug_trap_handler /* 0x38 */
4036
.long debug_trap_handler /* 0x39 */
4137
.long debug_trap_handler /* 0x3a */
42-
.long unwinder_trap_handler /* 0x3b */
38+
.long debug_trap_handler /* 0x3b */
4339
.long breakpoint_trap_handler /* 0x3c */
4440
.long singlestep_trap_handler /* 0x3d */
4541
.long bug_trap_handler /* 0x3e */

‎arch/sh/kernel/traps.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@
55
#include <linux/signal.h>
66
#include <linux/sched.h>
77
#include <linux/uaccess.h>
8+
#include <asm/unwinder.h>
89
#include <asm/system.h>
910

1011
#ifdef CONFIG_BUG
1112
void handle_BUG(struct pt_regs *regs)
1213
{
14+
const struct bug_entry *bug;
15+
unsigned long bugaddr = regs->pc;
1316
enum bug_trap_type tt;
14-
tt = report_bug(regs->pc, regs);
17+
18+
if (!is_valid_bugaddr(bugaddr))
19+
goto invalid;
20+
21+
bug = find_bug(bugaddr);
22+
23+
/* Switch unwinders when unwind_stack() is called */
24+
if (bug->flags & BUGFLAG_UNWINDER)
25+
unwinder_faulted = 1;
26+
27+
tt = report_bug(bugaddr, regs);
1528
if (tt == BUG_TRAP_TYPE_WARN) {
16-
regs->pc += instruction_size(regs->pc);
29+
regs->pc += instruction_size(bugaddr);
1730
return;
1831
}
1932

33+
invalid:
2034
die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);
2135
}
2236

@@ -28,8 +42,7 @@ int is_valid_bugaddr(unsigned long addr)
2842
return 0;
2943
if (probe_kernel_address((insn_size_t *)addr, opcode))
3044
return 0;
31-
32-
if (opcode == TRAPA_BUG_OPCODE || opcode == TRAPA_UNWINDER_BUG_OPCODE)
45+
if (opcode == TRAPA_BUG_OPCODE)
3346
return 1;
3447

3548
return 0;

‎arch/sh/kernel/unwinder.c‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,4 @@ void unwind_stack(struct task_struct *task, struct pt_regs *regs,
161161

162162
curr_unwinder->dump(task, regs, sp, ops, data);
163163
}
164-
165-
/*
166-
* Trap handler for UWINDER_BUG() statements. We must switch to the
167-
* unwinder with the next highest rating.
168-
*/
169-
BUILD_TRAP_HANDLER(unwinder)
170-
{
171-
insn_size_t insn;
172-
TRAP_HANDLER_DECL;
173-
174-
/* Rewind */
175-
regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
176-
insn = *(insn_size_t *)instruction_pointer(regs);
177-
178-
/* Switch unwinders when unwind_stack() is called */
179-
unwinder_faulted = 1;
180-
181-
#ifdef CONFIG_BUG
182-
handle_BUG(regs);
183-
#endif
184-
}
185164
EXPORT_SYMBOL_GPL(unwind_stack);

0 commit comments

Comments
 (0)