mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf
@ 2026-10-09  9:27 Magnus Lindholm
  2026-10-10  1:28 ` Matt Turner
  0 siblings, 1 reply; 3+ messages in thread
From: Magnus Lindholm @ 2026-10-09  9:27 UTC (permalink / raw)
  To: kees, shuah, wad, richard.henderson, mattst88, linux-kernel,
	linux-alpha, linux-kselftest
  Cc: linmag7

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf
  2026-10-09  9:27 [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf Magnus Lindholm
@ 2026-10-10  1:28 ` Matt Turner
  2026-10-10 11:31   ` Magnus Lindholm
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Turner @ 2026-10-10  1:28 UTC (permalink / raw)
  To: Magnus Lindholm
  Cc: kees, shuah, wad, richard.henderson, linux-kernel, linux-alpha,
	linux-kselftest

On Fri, Oct 9, 2026 at 11:27 AM Magnus Lindholm <linmag7@gmail.com> wrote:
> Skip the pre-notification signal test when /proc/self/syscall is absent,
> rather than unconditionally skipping it on Alpha.

Nothing in the tree skips it on Alpha; that was only in v1.

> +/* Alpha returns positive errno in r0 with the r19/a3 error flag set. */
> +# define SYSCALL_RET_SET(_regs, _val)                                \

r19 is still the fourth syscall argument at an entry stop, so this
relies on the callers also setting the syscall number to -1. Worth
saying so in the comment.

> +     if (access("/proc/self/syscall", R_OK) != 0 && errno == ENOENT)
> +             SKIP(return, "/proc/<pid>/syscall not available on this kernel");

Alpha selects HAVE_ARCH_TRACEHOOK, so the file is there and this never
triggers. I guess that is why you have 12 skips now instead of 13.
Please drop the hunk, or send it separately for UML and friends.

With that:

Reviewed-by: Matt Turner <mattst88@gmail.com>

Build-tested only, with a cross compiler.

Unrelated to this patch: with the selftest setting a3 itself, do we
still need the fixup at the end of alpha_elf_gregs_set()? As it stands a
tracer cannot skip a syscall and have it return a small positive value;
it comes back as an errno. The r0 == syscall_saved_nr check in
alpha_finish_syscall_to_user_mode() has the same kind of problem.

Matt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf
  2026-10-10  1:28 ` Matt Turner
@ 2026-10-10 11:31   ` Magnus Lindholm
  0 siblings, 0 replies; 3+ messages in thread
From: Magnus Lindholm @ 2026-10-10 11:31 UTC (permalink / raw)
  To: Matt Turner
  Cc: kees, shuah, wad, richard.henderson, linux-kernel, linux-alpha,
	linux-kselftest

Hi Matt,

On Sat, Oct 10, 2026 at 3:28 AM Matt Turner <mattst88@gmail.com> wrote:
>
> On Fri, Oct 9, 2026 at 11:27 AM Magnus Lindholm <linmag7@gmail.com> wrote:
> > Skip the pre-notification signal test when /proc/self/syscall is absent,
> > rather than unconditionally skipping it on Alpha.
>
> Nothing in the tree skips it on Alpha; that was only in v1.
>
> > +/* Alpha returns positive errno in r0 with the r19/a3 error flag set. */
> > +# define SYSCALL_RET_SET(_regs, _val)                                \
>
> r19 is still the fourth syscall argument at an entry stop, so this
> relies on the callers also setting the syscall number to -1. Worth
> saying so in the comment.
>
> > +     if (access("/proc/self/syscall", R_OK) != 0 && errno == ENOENT)
> > +             SKIP(return, "/proc/<pid>/syscall not available on this kernel");
>
> Alpha selects HAVE_ARCH_TRACEHOOK, so the file is there and this never
> triggers. I guess that is why you have 12 skips now instead of 13.
> Please drop the hunk, or send it separately for UML and friends.
>
> With that:
>
> Reviewed-by: Matt Turner <mattst88@gmail.com>
>
> Build-tested only, with a cross compiler.
>

Thanks for taking the time to review this, will put out a v3 asap

> Unrelated to this patch: with the selftest setting a3 itself, do we
> still need the fixup at the end of alpha_elf_gregs_set()? As it stands a
> tracer cannot skip a syscall and have it return a small positive value;
> it comes back as an errno. The r0 == syscall_saved_nr check in
> alpha_finish_syscall_to_user_mode() has the same kind of problem.
>

Interesting, I'll make a note on this and look into it later, you may be
on to something here.

Magnus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-10 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09  9:27 [PATCH v2] selftests/seccomp: add Alpha support to seccomp_bpf Magnus Lindholm
2026-10-10  1:28 ` Matt Turner
2026-10-10 11:31   ` Magnus Lindholm

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®