]> www.infradead.org Git - users/willy/pagecache.git/commit
LoongArch: Extend the maximum number of watchpoints
authorTiezhu Yang <yangtiezhu@loongson.cn>
Sun, 26 Jan 2025 13:49:59 +0000 (21:49 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Sun, 26 Jan 2025 13:49:59 +0000 (21:49 +0800)
commit531936dee53e471a3ec668de3c94ca357f54b7e8
treea5b8082f0656ee9d6482a93931e005b7972b6be3
parentf502ea618bf16d615d7dc6138c8988d3118fe750
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>
arch/loongarch/include/uapi/asm/ptrace.h
arch/loongarch/kernel/ptrace.c