forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoongArch: Use generic BUG() handler
Inspired by commit 9fb7410("arm64/BUG: Use BRK instruction for generic BUG traps"), do similar to LoongArch to use generic BUG() handler. This patch uses the BREAK software breakpoint instruction to generate a trap instead, similarly to most other arches, with the generic BUG code generating the dmesg boilerplate. This allows bug metadata to be moved to a separate table and reduces the amount of inline code at BUG and WARN sites. This also avoids clobbering any registers before they can be dumped. To mitigate the size of the bug table further, this patch makes use of the existing infrastructure for encoding addresses within the bug table as 32-bit relative pointers instead of absolute pointers. (Note that this limits the kernel size to 2GB.) Before patch: [ 3018.338013] lkdtm: Performing direct entry BUG [ 3018.342445] Kernel bug detected[#5]: [ 3018.345992] CPU: 2 PID: 865 Comm: cat Tainted: G D 6.0.0-rc6+ torvalds#35 After patch: [ 125.585985] lkdtm: Performing direct entry BUG [ 125.590433] ------------[ cut here ]------------ [ 125.595020] kernel BUG at drivers/misc/lkdtm/bugs.c:78! [ 125.600211] Oops - BUG[#1]: [ 125.602980] CPU: 3 PID: 410 Comm: cat Not tainted 6.0.0-rc6+ torvalds#36 Out-of-line file/line data information obtained compared to before. Signed-off-by: Youling Tang <tangyouling@loongson.cn>
- Loading branch information
1 parent
dc164f4
commit 233fbb6
Showing
4 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,61 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#ifndef __ASM_BUG_H | ||
#define __ASM_BUG_H | ||
|
||
#include <linux/compiler.h> | ||
#include <asm/break.h> | ||
#include <linux/stringify.h> | ||
|
||
#ifdef CONFIG_DEBUG_BUGVERBOSE | ||
#define _BUGVERBOSE_LOCATION(file, line) __BUGVERBOSE_LOCATION(file, line) | ||
#define __BUGVERBOSE_LOCATION(file, line) \ | ||
.pushsection .rodata.str, "aMS", @progbits, 1; \ | ||
10002: .string file; \ | ||
.popsection; \ | ||
\ | ||
.long 10002b - .; \ | ||
.short line; | ||
#else | ||
#define _BUGVERBOSE_LOCATION(file, line) | ||
#endif | ||
|
||
#ifdef CONFIG_BUG | ||
#ifdef CONFIG_GENERIC_BUG | ||
|
||
#define __BUG_ENTRY(flags) \ | ||
.pushsection __bug_table, "aw"; \ | ||
.align 2; \ | ||
10000: .long 10001f - .; \ | ||
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ | ||
.short flags; \ | ||
.popsection; \ | ||
10001: | ||
#else | ||
#define __BUG_ENTRY(flags) | ||
#endif | ||
|
||
#include <asm/break.h> | ||
#define ASM_BUG_FLAGS(flags) \ | ||
__BUG_ENTRY(flags) \ | ||
break BRK_BUG | ||
|
||
static inline void __noreturn BUG(void) | ||
{ | ||
__asm__ __volatile__("break %0" : : "i" (BRK_BUG)); | ||
unreachable(); | ||
} | ||
#define ASM_BUG() ASM_BUG_FLAGS(0) | ||
|
||
#define HAVE_ARCH_BUG | ||
#define __BUG_FLAGS(flags) \ | ||
asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags))); | ||
|
||
#endif | ||
#define BUG() do { \ | ||
instrumentation_begin(); \ | ||
__BUG_FLAGS(0); \ | ||
unreachable(); \ | ||
} while (0) | ||
|
||
#define __WARN_FLAGS(flags) do { \ | ||
instrumentation_begin(); \ | ||
__BUG_FLAGS(BUGFLAG_WARNING|(flags)); \ | ||
instrumentation_end(); \ | ||
} while (0) | ||
|
||
#define HAVE_ARCH_BUG | ||
|
||
#include <asm-generic/bug.h> | ||
|
||
#endif /* __ASM_BUG_H */ | ||
#endif /* ! __ASM_BUG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters