2022-05-31 18:04:11 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
|
|
|
|
/*
|
|
|
|
* Author: Hanlu Li <lihanlu@loongson.cn>
|
|
|
|
* Huacai Chen <chenhuacai@loongson.cn>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
|
|
*/
|
|
|
|
#ifndef _UAPI_ASM_PTRACE_H
|
|
|
|
#define _UAPI_ASM_PTRACE_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#ifndef __KERNEL__
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For PTRACE_{POKE,PEEK}USR. 0 - 31 are GPRs,
|
|
|
|
* 32 is syscall's original ARG0, 33 is PC, 34 is BADVADDR.
|
|
|
|
*/
|
|
|
|
#define GPR_BASE 0
|
|
|
|
#define GPR_NUM 32
|
|
|
|
#define GPR_END (GPR_BASE + GPR_NUM - 1)
|
|
|
|
#define ARG0 (GPR_END + 1)
|
|
|
|
#define PC (GPR_END + 2)
|
|
|
|
#define BADVADDR (GPR_END + 3)
|
|
|
|
|
|
|
|
#define NUM_FPU_REGS 32
|
|
|
|
|
|
|
|
struct user_pt_regs {
|
|
|
|
/* Main processor registers. */
|
|
|
|
unsigned long regs[32];
|
|
|
|
|
|
|
|
/* Original syscall arg0. */
|
|
|
|
unsigned long orig_a0;
|
|
|
|
|
|
|
|
/* Special CSR registers. */
|
|
|
|
unsigned long csr_era;
|
|
|
|
unsigned long csr_badv;
|
|
|
|
unsigned long reserved[10];
|
|
|
|
} __attribute__((aligned(8)));
|
|
|
|
|
|
|
|
struct user_fp_state {
|
2023-06-29 20:58:43 +08:00
|
|
|
uint64_t fpr[32];
|
|
|
|
uint64_t fcc;
|
|
|
|
uint32_t fcsr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct user_lsx_state {
|
|
|
|
/* 32 registers, 128 bits width per register. */
|
|
|
|
uint64_t vregs[32*2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct user_lasx_state {
|
|
|
|
/* 32 registers, 256 bits width per register. */
|
|
|
|
uint64_t vregs[32*4];
|
2022-05-31 18:04:11 +08:00
|
|
|
};
|
|
|
|
|
2023-09-06 22:53:55 +08:00
|
|
|
struct user_lbt_state {
|
|
|
|
uint64_t scr[4];
|
|
|
|
uint32_t eflags;
|
|
|
|
uint32_t ftop;
|
|
|
|
};
|
|
|
|
|
2023-02-25 15:52:57 +08:00
|
|
|
struct user_watch_state {
|
2023-04-19 12:07:27 +08:00
|
|
|
uint64_t dbg_info;
|
2023-02-25 15:52:57 +08:00
|
|
|
struct {
|
|
|
|
uint64_t addr;
|
|
|
|
uint64_t mask;
|
|
|
|
uint32_t ctrl;
|
2023-04-19 12:07:27 +08:00
|
|
|
uint32_t pad;
|
2023-02-25 15:52:57 +08:00
|
|
|
} dbg_regs[8];
|
|
|
|
};
|
|
|
|
|
LoongArch: Extend the maximum number of watchpoints
The maximum number of load/store watchpoints and fetch instruction
watchpoints is 14 each according to LoongArch Reference Manual, so
extend the maximum number of watchpoints from 8 to 14 for ptrace.
By the way, just simply change 8 to 14 for the definition in struct
user_watch_state at the beginning, but it may corrupt uapi, then add
a new struct user_watch_state_v2 directly.
As far as I can tell, the only users for this struct in the userspace
are GDB and LLDB, there are no any problems of software compatibility
between the application and kernel according to the analysis.
The compatibility problem has been considered while developing and
testing. When the applications in the userspace get watchpoint state,
the length will be specified which is no bigger than the sizeof struct
user_watch_state or user_watch_state_v2, the actual length is assigned
as the minimal value of the application and kernel in the generic code
of ptrace:
kernel/ptrace.c: ptrace_regset():
kiov->iov_len = min(kiov->iov_len,
(__kernel_size_t) (regset->n * regset->size));
if (req == PTRACE_GETREGSET)
return copy_regset_to_user(task, view, regset_no, 0,
kiov->iov_len, kiov->iov_base);
else
return copy_regset_from_user(task, view, regset_no, 0,
kiov->iov_len, kiov->iov_base);
For example, there are four kind of combinations, all of them work well.
(1) "older kernel + older gdb", the actual length is 8+(8+8+4+4)*8=200;
(2) "newer kernel + newer gdb", the actual length is 8+(8+8+4+4)*14=344;
(3) "older kernel + newer gdb", the actual length is 8+(8+8+4+4)*8=200;
(4) "newer kernel + older gdb", the actual length is 8+(8+8+4+4)*8=200.
Link: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints
Cc: stable@vger.kernel.org
Fixes: 1a69f7a161a7 ("LoongArch: ptrace: Expose hardware breakpoints to debuggers")
Reviewed-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2025-01-26 21:49:59 +08:00
|
|
|
struct user_watch_state_v2 {
|
|
|
|
uint64_t dbg_info;
|
|
|
|
struct {
|
|
|
|
uint64_t addr;
|
|
|
|
uint64_t mask;
|
|
|
|
uint32_t ctrl;
|
|
|
|
uint32_t pad;
|
|
|
|
} dbg_regs[14];
|
|
|
|
};
|
|
|
|
|
2022-05-31 18:04:11 +08:00
|
|
|
#define PTRACE_SYSEMU 0x1f
|
|
|
|
#define PTRACE_SYSEMU_SINGLESTEP 0x20
|
|
|
|
|
|
|
|
#endif /* _UAPI_ASM_PTRACE_H */
|