public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] riscv: Expose orig_a0 to userspace for ptrace to set the actual a0
@ 2024-06-19  2:00 zhouquan
  2024-06-19  2:01 ` [RFC PATCH 1/2] riscv: Expose orig_a0 in the user_regs_struct structure zhouquan
  2024-06-19  2:01 ` [RFC PATCH 2/2] riscv: selftests: Add a ptrace test to check a0 of restarted syscall zhouquan
  0 siblings, 2 replies; 9+ messages in thread
From: zhouquan @ 2024-06-19  2:00 UTC (permalink / raw)
  To: linux-riscv, linux-kernel, linux-kselftest
  Cc: oleg, paul.walmsley, palmer, aou, andy.chiu, shuah, charlie,
	zhouquan

From: Quan Zhou <zhouquan@iscas.ac.cn>

Due to the path that modifies a0 in syscall_enter_from_user_mode before the
actual execution of syscall_handler [1], the kernel currently saves a0 to
orig_a0 at the entry point of do_trap_ecall_u as an original copy of a0.
Once the syscall is interrupted and later resumed, the restarted syscall
will use orig_a0 to continue execution.

The above rules generally apply except for ptrace(PTRACE_SETREGSET,),
where the kernel will ignore the tracer's setting of tracee/a0 and
will restart with the tracee's original a0 value. For the current
kernel implementation of ptrace, projects like CRIU/Proot will
encounter issues where the a0 setting becomes ineffective when
performing ptrace(PTRACE_{SET/GET}REGSET,).

Here is a suggested solution, expose orig_a0 to userspace so that ptrace
can choose whether to set orig_a0 based on the actual scenario. In fact,
x86/orig_eax and loongArch/orig_a0 have adopted similar solutions.

[1] link: https://lore.kernel.org/lkml/20230403-crisping-animosity-04ed8a45c625@spud/T/

Quan Zhou (2):
  riscv: Expose orig_a0 in the user_regs_struct structure
  riscv: selftests: Add a ptrace test to check a0 of restarted syscall

 arch/riscv/include/asm/ptrace.h               |   4 +-
 arch/riscv/include/uapi/asm/ptrace.h          |   2 +
 tools/testing/selftests/riscv/Makefile        |   2 +-
 tools/testing/selftests/riscv/abi/.gitignore  |   1 +
 tools/testing/selftests/riscv/abi/Makefile    |  12 ++
 .../riscv/abi/ptrace_restart_syscall.c        | 148 ++++++++++++++++++
 6 files changed, 166 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/riscv/abi/.gitignore
 create mode 100644 tools/testing/selftests/riscv/abi/Makefile
 create mode 100644 tools/testing/selftests/riscv/abi/ptrace_restart_syscall.c


base-commit: 6ba59ff4227927d3a8530fc2973b80e94b54d58f
-- 
2.34.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-06-24  3:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-19  2:00 [RFC PATCH 0/2] riscv: Expose orig_a0 to userspace for ptrace to set the actual a0 zhouquan
2024-06-19  2:01 ` [RFC PATCH 1/2] riscv: Expose orig_a0 in the user_regs_struct structure zhouquan
2024-06-20  1:05   ` Charlie Jenkins
2024-06-20  2:34     ` Quan Zhou
2024-06-19  2:01 ` [RFC PATCH 2/2] riscv: selftests: Add a ptrace test to check a0 of restarted syscall zhouquan
2024-06-20  2:55   ` Charlie Jenkins
2024-06-21  6:29     ` Quan Zhou
2024-06-21 20:20       ` Charlie Jenkins
2024-06-24  3:24         ` Quan Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox