Skip to content

Commit 379eb01

Browse files
VincentZWCpalmer-dabbelt
authored andcommitted
riscv: Ensure the value of FP registers in the core dump file is up to date
The value of FP registers in the core dump file comes from the thread.fstate. However, kernel saves the FP registers to the thread.fstate only before scheduling out the process. If no process switch happens during the exception handling process, kernel will not have a chance to save the latest value of FP registers to thread.fstate. It will cause the value of FP registers in the core dump file may be incorrect. To solve this problem, this patch force lets kernel save the FP register into the thread.fstate if the target task_struct equals the current. Signed-off-by: Vincent Chen <[email protected]> Reviewed-by: Jisheng Zhang <[email protected]> Fixes: b8c8a95 ("RISC-V: Add FP register ptrace support for gdb.") Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent aa3e1ba commit 379eb01

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/riscv/kernel/ptrace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <asm/ptrace.h>
1111
#include <asm/syscall.h>
1212
#include <asm/thread_info.h>
13+
#include <asm/switch_to.h>
1314
#include <linux/audit.h>
1415
#include <linux/ptrace.h>
1516
#include <linux/elf.h>
@@ -56,6 +57,9 @@ static int riscv_fpr_get(struct task_struct *target,
5657
{
5758
struct __riscv_d_ext_state *fstate = &target->thread.fstate;
5859

60+
if (target == current)
61+
fstate_save(current, task_pt_regs(current));
62+
5963
membuf_write(&to, fstate, offsetof(struct __riscv_d_ext_state, fcsr));
6064
membuf_store(&to, fstate->fcsr);
6165
return membuf_zero(&to, 4); // explicitly pad

0 commit comments

Comments
 (0)