mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ludwig Rydberg <ludwig.rydberg@gaisler.com>
To: Andreas Larsson <andreas@gaisler.com>,
	"David S. Miller" <davem@davemloft.net>,
	Kees Cook <kees@kernel.org>,
	sparclinux@vger.kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>, Oleg Nesterov <oleg@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Stian Halseth <stian@itx.no>,
	Ludwig Rydberg <ludwig.rydberg@gaisler.com>
Subject: [PATCH 3/3] selftests/seccomp: add sparc32 support
Date: Wed, 14 Oct 2026 10:07:30 +0200	[thread overview]
Message-ID: <20261014080730.8817-4-ludwig.rydberg@gaisler.com> (raw)
In-Reply-To: <20261014080730.8817-1-ludwig.rydberg@gaisler.com>

Add SPARC32 definitions to seccomp_bpf selftest.

Reuse the sparc64 register handling on sparc32 but adapt the carry
bit handling to use %tstate on sparc64 and %psr on sparc32.

Signed-off-by: Ludwig Rydberg <ludwig.rydberg@gaisler.com>
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 38 +++++++++++++------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 3711060c22a7..60ae1de8201d 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -1872,10 +1872,21 @@ TEST_F(TRACE_poke, getpid_runs_normally)
 # define ARCH_REGS		struct user_regs_struct
 # define SYSCALL_NUM(_regs)	(_regs).orig_d0
 # define SYSCALL_RET(_regs)	(_regs).d0
-#elif defined(__sparc__) && defined(__arch64__)
+#elif defined(__sparc__)
 # include <asm/ptrace.h>
+
+# if defined(__arch64__)
+#  include <asm/pstate.h>
+#  define CARRY_MASK			(TSTATE_ICARRY | TSTATE_XCARRY)
+#  define SPARC_CARRY_REG(_regs)	((_regs).tstate)
+# else
+#  include <asm/psr.h>
+#  define CARRY_MASK			PSR_C
+#  define SPARC_CARRY_REG(_regs)	((_regs).psr)
+# endif
+
 /*
- * PTRACE_GETREGS64/PTRACE_SETREGS64 transfer the uapi struct pt_regs,
+ * PTRACE_GETREGS{64}/PTRACE_SETREGS{64} transfer the uapi struct pt_regs,
  * but in the historical layout that omits %g0: the blob starts at %g1,
  * so every u_regs index is one lower than the register number suggests.
  */
@@ -1883,20 +1894,20 @@ TEST_F(TRACE_poke, getpid_runs_normally)
 # define SYSCALL_NUM(_regs)	(_regs).u_regs[0]	/* %g1 */
 # define SYSCALL_RET(_regs)	(_regs).u_regs[7]	/* %o0 */
 /*
- * A syscall error is signaled by the carry bit in tstate, with the
- * errno held in %o0 as a positive value; the carry can only be
- * written reliably once the syscall has been skipped or has run.
+ * A syscall error is signaled by the carry bit in tstate (SPARC64) or
+ * psr (SPARC32), with the errno held in %o0 as a positive value;
+ * the carry can only be written reliably once the syscall has been
+ * skipped or has run.
  */
-# define SPARC64_TSTATE_CARRY	0x0000001100000000UL	/* xcc.c | icc.c */
 # define SYSCALL_RET_SET(_regs, _val)				\
 	do {							\
 		typeof(_val) _result = (_val);			\
 		if (_result < 0) {				\
 			SYSCALL_RET(_regs) = -_result;		\
-			(_regs).tstate |= SPARC64_TSTATE_CARRY;	\
+			SPARC_CARRY_REG(_regs) |= CARRY_MASK;	\
 		} else {					\
 			SYSCALL_RET(_regs) = _result;		\
-			(_regs).tstate &= ~SPARC64_TSTATE_CARRY; \
+			SPARC_CARRY_REG(_regs) &= ~CARRY_MASK;	\
 		}						\
 	} while (0)
 # define SYSCALL_RET_SET_ON_PTRACE_EXIT
@@ -1967,14 +1978,19 @@ const bool ptrace_entry_set_syscall_ret =
 #if defined(__x86_64__) || defined(__i386__) || defined(__mips__) || defined(__mc68000__)
 # define ARCH_GETREGS(_regs)	ptrace(PTRACE_GETREGS, tracee, 0, &(_regs))
 # define ARCH_SETREGS(_regs)	ptrace(PTRACE_SETREGS, tracee, 0, &(_regs))
-#elif defined(__sparc__) && defined(__arch64__)
+#elif defined(__sparc__)
+# if defined(__arch64__)
 /*
  * The NT_PRSTATUS regset appends the register window, which struct
  * pt_regs does not carry; the sparc-specific requests transfer
  * struct pt_regs directly (and take the buffer in addr).
  */
-# define ARCH_GETREGS(_regs)	ptrace(PTRACE_GETREGS64, tracee, &(_regs), 0)
-# define ARCH_SETREGS(_regs)	ptrace(PTRACE_SETREGS64, tracee, &(_regs), 0)
+#  define ARCH_GETREGS(_regs)	ptrace(PTRACE_GETREGS64, tracee, &(_regs), 0)
+#  define ARCH_SETREGS(_regs)	ptrace(PTRACE_SETREGS64, tracee, &(_regs), 0)
+# else
+#  define ARCH_GETREGS(_regs)	ptrace(PTRACE_GETREGS, tracee, &(_regs), 0)
+#  define ARCH_SETREGS(_regs)	ptrace(PTRACE_SETREGS, tracee, &(_regs), 0)
+# endif
 #else
 # define ARCH_GETREGS(_regs)	({					\
 		struct iovec __v;					\
-- 
2.35.3


  parent reply	other threads:[~2026-10-14  8:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  8:07 [PATCH 0/3] sparc32: add seccomp filter support Ludwig Rydberg
2026-10-14  8:07 ` [PATCH 1/3] sparc32: Split common syscall_trace() to syscall_trace_{enter|leave}() Ludwig Rydberg
2026-10-14  8:07 ` [PATCH 2/3] sparc32: add seccomp filter support Ludwig Rydberg
2026-10-14  8:07 ` Ludwig Rydberg [this message]
2026-10-14  9:29   ` [PATCH 3/3] selftests/seccomp: add sparc32 support Stian Halseth
2026-10-14 16:40   ` Kees Cook
2026-10-14 16:36 ` [PATCH 0/3] sparc32: add seccomp filter support Magnus Lindholm
2026-10-16 14:25 ` Andreas Larsson

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=20261014080730.8817-4-ludwig.rydberg@gaisler.com \
    --to=ludwig.rydberg@gaisler.com \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=oleg@redhat.com \
    --cc=shuah@kernel.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=stian@itx.no \
    --cc=wad@chromium.org \
    /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®