Re: [PATCH v2 2/2] LoongArch: Extend the maximum number of watchpoints

From: Xi Ruoyao
Date: Thu Jan 23 2025 - 09:04:45 EST


On Wed, 2025-01-22 at 11:23 +0800, Tiezhu Yang wrote:
> 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 when developing and testing
> the patches, when the applications in the userspace get watchpoint state,
> the length will be specified which will not 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 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.

OK, I think it has cleared my doubts.

Reviewed-by: Xi Ruoyao <xry111@xxxxxxxxxxx>

--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University