mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Michal Suchánek" <msuchanek@suse.de>,
	"Dmitry V . Levin" <ldv@strace.io>,
	"Renzo Davoli" <renzo@cs.unibo.it>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [RFC PATCH] s390/syscall: Sign extend system call number retrieved via syscall_get_nr()
Date: Wed, 21 Oct 2026 14:59:11 +0200	[thread overview]
Message-ID: <20261021125911.1550331-1-hca@linux.ibm.com> (raw)

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@linux.ibm.com>
---
 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


                 reply	other threads:[~2026-10-21 13:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021125911.1550331-1-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=ldv@strace.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=msuchanek@suse.de \
    --cc=oleg@redhat.com \
    --cc=renzo@cs.unibo.it \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®