Skip to content

Commit 5665bc3

Browse files
npigginmpe
authored andcommitted
powerpc/64s/syscall: Use pt_regs.trap to distinguish syscall ABI difference between sc and scv syscalls
The sc and scv 0 system calls have different ABI conventions, and ptracers need to know which system call type is being used if they want to look at the syscall registers. Document that pt_regs.trap can be used for this, and fix one in-tree user to work with scv 0 syscalls. Fixes: 7fa95f9 ("powerpc/64s: system call support for scv/rfscv instructions") Cc: [email protected] # v5.9+ Reported-by: "Dmitry V. Levin" <[email protected]> Suggested-by: "Dmitry V. Levin" <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e2f5efd commit 5665bc3

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Documentation/powerpc/syscall64-abi.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ auxiliary vector.
109109

110110
scv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC.
111111

112+
ptrace
113+
------
114+
When ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains
115+
the system call type that can be used to distinguish between sc and scv 0
116+
system calls, and the different register conventions can be accounted for.
117+
118+
If the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was
119+
performed with the sc instruction, if it is 0x3000 then the system call was
120+
performed with the scv 0 instruction.
121+
112122
vsyscall
113123
========
114124

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,16 +1753,25 @@ TEST_F(TRACE_poke, getpid_runs_normally)
17531753
# define SYSCALL_RET_SET(_regs, _val) \
17541754
do { \
17551755
typeof(_val) _result = (_val); \
1756-
/* \
1757-
* A syscall error is signaled by CR0 SO bit \
1758-
* and the code is stored as a positive value. \
1759-
*/ \
1760-
if (_result < 0) { \
1761-
SYSCALL_RET(_regs) = -_result; \
1762-
(_regs).ccr |= 0x10000000; \
1763-
} else { \
1756+
if ((_regs.trap & 0xfff0) == 0x3000) { \
1757+
/* \
1758+
* scv 0 system call uses -ve result \
1759+
* for error, so no need to adjust. \
1760+
*/ \
17641761
SYSCALL_RET(_regs) = _result; \
1765-
(_regs).ccr &= ~0x10000000; \
1762+
} else { \
1763+
/* \
1764+
* A syscall error is signaled by the \
1765+
* CR0 SO bit and the code is stored as \
1766+
* a positive value. \
1767+
*/ \
1768+
if (_result < 0) { \
1769+
SYSCALL_RET(_regs) = -_result; \
1770+
(_regs).ccr |= 0x10000000; \
1771+
} else { \
1772+
SYSCALL_RET(_regs) = _result; \
1773+
(_regs).ccr &= ~0x10000000; \
1774+
} \
17661775
} \
17671776
} while (0)
17681777
# define SYSCALL_RET_SET_ON_PTRACE_EXIT

0 commit comments

Comments
 (0)