2023-08-14 06:20:48

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 0/2] Modify die() for LoongArch

This is based on 6.5-rc6.

v2:
-- Update the commit message to give more detailed info, split into
two individual patches, suggested by Maciej, thank you.

Tiezhu Yang (2):
LoongArch: Remove noreturn attribute for die()
LoongArch: Modify the declaration for die()

arch/loongarch/include/asm/ptrace.h | 2 +-
arch/loongarch/kernel/traps.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)

--
2.1.0



2023-08-14 07:16:04

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 2/2] LoongArch: Modify the declaration for die()

While at it, modify the die() declaration in ptrace.h to fix
the following checkpatch warnings:

WARNING: function definition argument 'const char *' should also have an identifier name
WARNING: function definition argument 'struct pt_regs *' should also have an identifier name

Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/include/asm/ptrace.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/include/asm/ptrace.h b/arch/loongarch/include/asm/ptrace.h
index 35f0958..2101301 100644
--- a/arch/loongarch/include/asm/ptrace.h
+++ b/arch/loongarch/include/asm/ptrace.h
@@ -162,7 +162,7 @@ static inline void regs_set_return_value(struct pt_regs *regs, unsigned long val
#define instruction_pointer(regs) ((regs)->csr_era)
#define profile_pc(regs) instruction_pointer(regs)

-extern void die(const char *, struct pt_regs *) __noreturn;
+void die(const char *str, struct pt_regs *regs);

static inline void die_if_kernel(const char *str, struct pt_regs *regs)
{
--
2.1.0


2023-08-14 07:21:17

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 1/2] LoongArch: Remove noreturn attribute for die()

If notify_die() returns NOTIFY_STOP, honor the return value from the
handler chain invocation in die() as, through a debugger, the fault
may have been fixed. It makes sense even if ignoring the event will
make the system unstable, by allowing access through a debugger it
has been compromised already anyway. So we can remove the noreturn
attribute for die() to make our port consistent with x86, arm64,
riscv and csky.

Commit 20c0d2d44029 ("[PATCH] i386: pass proper trap numbers to die
chain handlers") may be the earliest of similar changes.

Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/kernel/traps.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c
index 8fb5e7a..bbdfc5b 100644
--- a/arch/loongarch/kernel/traps.c
+++ b/arch/loongarch/kernel/traps.c
@@ -383,16 +383,15 @@ void show_registers(struct pt_regs *regs)

static DEFINE_RAW_SPINLOCK(die_lock);

-void __noreturn die(const char *str, struct pt_regs *regs)
+void die(const char *str, struct pt_regs *regs)
{
static int die_counter;
- int sig = SIGSEGV;
+ int ret;

oops_enter();

- if (notify_die(DIE_OOPS, str, regs, 0, current->thread.trap_nr,
- SIGSEGV) == NOTIFY_STOP)
- sig = 0;
+ ret = notify_die(DIE_OOPS, str, regs, 0,
+ current->thread.trap_nr, SIGSEGV);

console_verbose();
raw_spin_lock_irq(&die_lock);
@@ -414,7 +413,8 @@ void __noreturn die(const char *str, struct pt_regs *regs)
if (panic_on_oops)
panic("Fatal exception");

- make_task_dead(sig);
+ if (ret != NOTIFY_STOP)
+ make_task_dead(SIGSEGV);
}

static inline void setup_vint_size(unsigned int size)
--
2.1.0