mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Magnus Lindholm <linmag7@gmail.com>
To: kees@kernel.org, shuah@kernel.org, wad@chromium.org,
	richard.henderson@linaro.org, mattst88@gmail.com,
	linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Cc: linmag7@gmail.com
Subject: [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf
Date: Fri,  9 Oct 2026 11:27:27 +0200	[thread overview]
Message-ID: <20261009092759.968521-1-linmag7@gmail.com> (raw)

Enable the seccomp BPF selftests on Alpha with a fallback seccomp syscall
number and architecture-specific syscall register accessors.

Use the NT_PRSTATUS register layout rather than struct pt_regs. The
register set contains r0-r30 followed by pc and unique. Read and update
the syscall number in r1, and set both r0 and the r19/a3 error flag when
synthesizing syscall results.

Skip the pre-notification signal test when /proc/self/syscall is absent,
rather than unconditionally skipping it on Alpha.

Kernel support for seccomp is already upstream for alpha so this is
for the tools selftests only.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
Changes in v2:
- Use the NT_PRSTATUS layout for PTRACE_GETREGSET/PTRACE_SETREGSET.
- Set the Alpha return value and error flag together.
- Check for /proc/self/syscall at runtime before creating child processes.

Link to v1:
https://lore.kernel.org/linux-alpha/20260203063357.14320-1-linmag7@gmail.com/

Tested on an AlphaServer ES40 (EV67 Tsunami), running
7.3.0-rc1-00010-g19a47cb46b82, built with GCC 15.2.1:
  PASSED: 111 / 111 tests passed.
  Totals: pass:99 fail:0 xfail:0 xpass:0 skip:12 error:0

Applied and built on my alpha/for-next at
29289afbc513df29f0f981d45676980ed8eb13d2.

 tools/testing/selftests/seccomp/seccomp_bpf.c | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 0622bc2..92d3713 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -136,6 +136,8 @@ struct seccomp_data {
 #  define __NR_seccomp 354
 # elif defined(__x86_64__)
 #  define __NR_seccomp 317
+# elif defined(__alpha__)
+#  define __NR_seccomp 514
 # elif defined(__arm__)
 #  define __NR_seccomp 383
 # elif defined(__aarch64__)
@@ -1754,6 +1756,25 @@ TEST_F(TRACE_poke, getpid_runs_normally)
 # define ARCH_REGS		struct user_regs_struct
 # define SYSCALL_NUM(_regs)	(_regs).orig_eax
 # define SYSCALL_RET(_regs)	(_regs).eax
+#elif defined(__alpha__)
+/* NT_PRSTATUS contains r0-r30, pc and unique, not struct pt_regs. */
+struct alpha_regs {
+	unsigned long regs[33];
+};
+
+# define ARCH_REGS		struct alpha_regs
+/* The kernel keeps the mutable syscall number in r1. */
+# define SYSCALL_NUM(_regs)	((_regs).regs[1])
+# define SYSCALL_RET(_regs)	((_regs).regs[0])
+/* Alpha returns positive errno in r0 with the r19/a3 error flag set. */
+# define SYSCALL_RET_SET(_regs, _val)				\
+	do {							\
+		struct alpha_regs *__regs = &(_regs);		\
+		long __ret = (_val);				\
+								\
+		__regs->regs[0] = __ret < 0 ? -__ret : __ret;	\
+		__regs->regs[19] = __ret < 0;			\
+	} while (0)
 #elif defined(__arm__)
 # define ARCH_REGS		struct pt_regs
 # define SYSCALL_NUM(_regs)	(_regs).ARM_r7
@@ -4652,6 +4673,9 @@ TEST(user_notification_wait_killable_pre_notification)
 	/* 100 ms */
 	struct timespec delay = { .tv_nsec = 100000000 };
 
+	if (access("/proc/self/syscall", R_OK) != 0 && errno == ENOENT)
+		SKIP(return, "/proc/<pid>/syscall not available on this kernel");
+
 	ASSERT_EQ(sigemptyset(&new_action.sa_mask), 0);
 
 	ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
-- 
2.43.0


             reply	other threads:[~2026-10-09  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  9:27 Magnus Lindholm [this message]
2026-10-10  1:28 ` Matt Turner
2026-10-10 11:31   ` Magnus Lindholm

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=20261009092759.968521-1-linmag7@gmail.com \
    --to=linmag7@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mattst88@gmail.com \
    --cc=richard.henderson@linaro.org \
    --cc=shuah@kernel.org \
    --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®