[RFC PATCH] s390/syscall: Sign extend system call number retrieved via syscall_get_nr()

From: Heiko Carstens

Date: Wed Oct 21 2026 - 09:02:30 EST


s390 is the only architecture which supports only 16 bits for the
system call number. Furthermore the system call number returned via
syscall_get_nr() is not sign extended.

This makes s390 also special: if -1 is passed to syscall_set_nr(), and then
syscall_get_nr() is used to retrieve the system call number, the returned
number is 65535 instead of -1, like on all other architectures.

Address this by handling the 16 bit system call number as signed value,
like on all other architectures. This reduces the maximum system call
number to 32767 for s390, but that shouldn't be a problem.

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/include/asm/syscall.h | 2 +-
tools/testing/selftests/ptrace/set_syscall_info.c | 4 ----
2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
index 5f310caad1fc..c67eeca3f33a 100644
--- a/arch/s390/include/asm/syscall.h
+++ b/arch/s390/include/asm/syscall.h
@@ -20,7 +20,7 @@ static inline long syscall_get_nr(struct task_struct *task,
struct pt_regs *regs)
{
return test_pt_regs_flag(regs, PIF_SYSCALL) ?
- (regs->int_code & 0xffff) : -1;
+ (s16)(regs->int_code & 0xffff) : -1;
}

static inline void syscall_set_nr(struct task_struct *task,
diff --git a/tools/testing/selftests/ptrace/set_syscall_info.c b/tools/testing/selftests/ptrace/set_syscall_info.c
index 1cc411a41cd6..2c5fab4a4c41 100644
--- a/tools/testing/selftests/ptrace/set_syscall_info.c
+++ b/tools/testing/selftests/ptrace/set_syscall_info.c
@@ -72,10 +72,6 @@ check_psi_entry(struct __test_metadata *_metadata,
{
unsigned int i;
int exp_nr = exp_entry->nr;
-#if defined __s390__ || defined __s390x__
- /* s390 is the only architecture that has 16-bit syscall numbers */
- exp_nr &= 0xffff;
-#endif

ASSERT_EQ(PTRACE_SYSCALL_INFO_ENTRY, info->op) {
LOG_KILL_TRACEE("%s: entry stop mismatch", text);
--
2.53.0