Skip to contentSkip to conversation

alpha: fix entry bugs and consolidate generic helpers

PATCH In review Magnus Lindholm 2 participants 16 messages Nov 3 – Nov 4

Subsystems (4)
lore
Share & tools
lore

Magnus Lindholm

author maintainer
#0 lore raw

cover alpha: fix entry bugs and consolidate generic helpers

With GENERIC_ENTRY upstream for Alpha, this series moves syscall dispatch and ordinary interrupt/exception entry and exit into C using generic helpers, and removes redundant fork, core-dump, audit and ptrace code. It also reuses generic memory-option parsing, OSF resource accounting and CPU registration.

The consolidation work and its regression testing uncovered bugs in saved-register oops reporting, audit return values, SIGSYS register rollback, syscall restart eligibility and arguments, and handling of skipped syscalls versus invalid syscall numbers. Patches 1-5 fix those bugs before patches 6-14 consolidate the code. The fixes remain distinct commits with their Fixes tags and existing stable Cc tags.

The fixes and consolidation changes exercise the same entry paths and need coordinated review and regression testing. They are presented together so reviewers can follow the fixes through the subsequent code changes. The fixes can still be considered for earlier application or backporting without taking the consolidation patches.

Patch 5 distinguishes the -1 abort sentinel from other invalid numbers:
explicit cancellation preserves a supplied result, whereas an invalid number permitted through entry work returns ENOSYS. It tracks supplied results explicitly, avoiding guesses from r0/a3 contents. This also preserves small successful values and seccomp results matching the entry registers. The C conversion in patch 6 retains the corrected behavior.

The OSF accounting change intentionally follows getrusage(2): RUSAGE_SELF covers the whole thread group, previously zero resource counters are reported, and CPU times use the generic microsecond conversion rather than jiffy rounding. The OSF layout and supported selectors are retained.

On stock-PAL QEMU the rebuilt ES40 image passes all 107 skip/result, 91 portable ptrace, 30 skipped-restart and 50 forced-success checks, as well as SIGSYS rollback, on one and four CPUs. The four-CPU run passes all 18 regression suites, including seccomp (99 passes, 12 expected skips). Patch 5 before the C conversion also passed its focused four-CPU run on the release base.

The complete series passed all 18 regression suites on a three-CPU EV67 ES40. The resource-accounting test now compares OSF peak RSS with native waitid() for the same child and accounts for its final voluntary context switch. Native controls reproduced both the low RSS reading and the extra context switch. The corrected run had 8,364 concurrent CHILDREN snapshots with no mismatches, and lockdep stayed enabled.

All eight focused strace injection and syscall-info tests passed. A full native strace run at 80e661285 had 1,225 passes, 303 skips and seven failures. Three passed on serial recheck. The remaining four involved CLOSE_RANGE_EXCEPT, the separately submitted PR_GET_UNALIGN fix, the Yama hint when running with CAP_SYS_PTRACE, and the getxpid syscall name on Alpha. The companion ptrace selftest remains separate from the series.

Codex assisted with code, tests and descriptions.

Magnus Lindholm (14):
alpha: fix saved registers in page-fault oops dumps
alpha: report syscall errors correctly to audit
alpha: preserve rolled-back registers for SIGSYS
alpha: fix syscall restart eligibility
alpha: distinguish skipped syscalls from invalid numbers
alpha: dispatch system calls from C
alpha: use generic entry helpers for interrupts and exceptions
alpha: use generic syscall exit for new tasks
alpha: remove obsolete core dump register hooks
alpha: use generic syscall audit classification
alpha: use generic ptrace memory writes
alpha: use memparse for memory size options
alpha: use generic getrusage for OSF resource accounting
alpha: use generic CPU device registration

 arch/alpha/Kconfig                     |   5 +-
 arch/alpha/include/asm/elf.h           |   7 -
 arch/alpha/include/asm/entry-common.h  |  11 +-
 arch/alpha/include/asm/ptrace.h        |  13 +-
 arch/alpha/include/asm/syscall.h       |  24 +--
 arch/alpha/include/asm/thread_info.h   |   3 +
 arch/alpha/kernel/Makefile             |   3 +-
 arch/alpha/kernel/asm-offsets.c        |   1 -
 arch/alpha/kernel/audit.c              |  62 -------
 arch/alpha/kernel/entry.S              | 293 ++++-----------------------------
 arch/alpha/kernel/irq.c                |   8 +-
 arch/alpha/kernel/irq_alpha.c          |  41 ++---
 arch/alpha/kernel/osf_sys.c            |  56 ++-----
 arch/alpha/kernel/process.c            |  32 ++--
 arch/alpha/kernel/proto.h              |  16 +-
 arch/alpha/kernel/ptrace.c             |  48 ++----
 arch/alpha/kernel/setup.c              |  41 +----
 arch/alpha/kernel/signal.c             | 151 ++---------------
 arch/alpha/kernel/syscall.c            |  85 ++++++++++
 arch/alpha/kernel/syscalls/syscall.tbl |  10 +-
 arch/alpha/kernel/traps.c              | 118 ++++++++++---
 arch/alpha/mm/fault.c                  |  27 ++-
 22 files changed, 356 insertions(+), 699 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/14 alpha: fix saved registers in page-fault oops dumps

The aligned exception frame moved r9-r15 back by one word. Adjust the pointer passed to die_if_kernel() so s0-s6 show the correct registers.

Fixes 3b35a171060f ("alpha: align stack for page fault and user unaligned trap handlers")
---
 arch/alpha/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/alpha/mm/fault.c +1 -1
index 3dfeb854f196387d8c8f709d0ce355e5145035fb..f09f69894cfd65d814ab1cf498c946043fb9e8a3 100644
@@ -244,7 +244,7 @@ retry:
 	   terminate things with extreme prejudice.  */
 	printk(KERN_ALERT "Unable to handle kernel paging request at "
 	       "virtual address %016lx\n", address);
-	die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16);
+	die_if_kernel("Oops", regs, cause, (unsigned long *)regs - 17);
 	make_task_dead(SIGKILL);
 
 	/* We ran out of memory, or some other thing happened to us that
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/14 alpha: report syscall errors correctly to audit

In reply to Magnus Lindholm

Use a3 to distinguish errors from successful return values and negate error codes for audit. Failed syscalls otherwise appear successful with a positive errno. Keep raw r0 for kernel-mode frames.

Fixes a9302e843944 ("alpha: Enable system-call auditing support.")
---
 arch/alpha/include/asm/ptrace.h | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
arch/alpha/include/asm/ptrace.h +11 -2
index 45d1229344b6f848eb930917bf50ba759da99beb..c933c8805eedd91e3845bb4b46588974258398c2 100644
@@ -21,9 +21,18 @@
 	(current_thread_info()->syscall_meta \
 	|= ALPHA_SYSCALL_META_FORCE_SUCCESS)
 
-static inline unsigned long regs_return_value(struct pt_regs *regs)
+#define is_syscall_success is_syscall_success
+static inline int is_syscall_success(struct pt_regs *regs)
 {
-	return regs->r0;
+	return !regs->r19;
+}
+
+static inline long regs_return_value(struct pt_regs *regs)
+{
+	/* For user-mode registers, a3 is an error flag only at syscall exit. */
+	if (is_syscall_success(regs) || !user_mode(regs))
+		return regs->r0;
+	return -regs->r0;
 }
 
 unsigned long user_stack_pointer(struct pt_regs *regs);
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/14 alpha: preserve rolled-back registers for SIGSYS

In reply to Magnus Lindholm

Record syscall_rollback() in syscall_meta so skipped-syscall handling preserves r0 and a3. Otherwise seccomp RET_TRAP handlers and kill-action core dumps lose the original syscall number and fourth argument.

Fixes 83bd31c2840b ("alpha: enable GENERIC_ENTRY")
---
 arch/alpha/include/asm/syscall.h     |  4 +++-
 arch/alpha/include/asm/thread_info.h |  1 +
 arch/alpha/kernel/signal.c           | 12 ++++++++++--
 3 files changed, 14 insertions(+), 3 deletions(-)
arch/alpha/include/asm/syscall.h +3 -1
index c1394910f584f9ca42367ffc33b1c0ac46cfe112..22315b932f854a71fd3babf6565dda443c6c7a77 100644
@@ -105,14 +105,16 @@ static inline void syscall_set_return_value(struct task_struct *task,
 	}
 }
 
-/* Restore the original syscall nr after seccomp/ptrace modified regs->r1. */
+/* Preserve the original syscall registers for a skipped syscall. */
 
 static inline void syscall_rollback(struct task_struct *task,
 					struct pt_regs *regs)
 {
 	unsigned long nr = task_thread_info(task)->syscall_saved_nr;
 
+	regs->r0 = nr;
 	regs->r1 = nr;
+	task_thread_info(task)->syscall_meta |= ALPHA_SYSCALL_META_ROLLBACK;
 }
 
 static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
arch/alpha/include/asm/thread_info.h +1 -0
index d781ac79106dd1178b9cb0e094333139db531bed..49bc08f3b5a98fbcb1d4ac919001bf70c3db614b 100644
@@ -57,6 +57,7 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
 
 #define ALPHA_SYSCALL_META_SKIP			0x2
 #define ALPHA_SYSCALL_META_FORCE_SUCCESS	0x4
+#define ALPHA_SYSCALL_META_ROLLBACK		0x10
 
 /*
  * Thread information flags:
arch/alpha/kernel/signal.c +10 -2
index 441d8dd61055d5ddc321c2221984eab8aca5d206..3fae37b4593f22f07a375ab7bc0b0712d0130a07 100644
@@ -587,10 +587,11 @@ alpha_syscall_enter_select(struct pt_regs *regs, long syscall)
 	 * entry work did not already change the return state.
 	 */
 	if (unlikely(!permit || (unsigned long)nr >= NR_syscalls)) {
-		if (regs->r0 == saved_r0 && regs->r19 == saved_r19)
+		if (!(ti->syscall_meta & ALPHA_SYSCALL_META_ROLLBACK) &&
+		    regs->r0 == saved_r0 && regs->r19 == saved_r19)
 			syscall_set_return_value(current, regs, -ENOSYS, 0);
 
-		ti->syscall_meta = ALPHA_SYSCALL_META_SKIP;
+		ti->syscall_meta |= ALPHA_SYSCALL_META_SKIP;
 		return fn;	/* ignored by asm when SKIP is set */
 	}
 
@@ -617,6 +618,13 @@ alpha_finish_syscall_to_user_mode(struct pt_regs *regs, long ret)
 
 	instrumentation_begin();
 
+	if (meta & ALPHA_SYSCALL_META_ROLLBACK) {
+		ti->syscall_saved_nr = 0;
+		instrumentation_end();
+		syscall_exit_to_user_mode(regs);
+		return;
+	}
+
 	if (meta & ALPHA_SYSCALL_META_SKIP) {
 	/*
 	 * Skip-dispatch path: ptrace/seccomp may already have installed
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 4/14 alpha: fix syscall restart eligibility

In reply to Magnus Lindholm

After GENERIC_ENTRY, stale restart state or a successful syscall result such as 512 can be mistaken for a restart code, corrupting r0 or the PC.

Clear restart eligibility after use and before returning to userspace, including signal-context restore. Require a3 to indicate an error before handling restart codes, preserving the saved arguments for replay.

Save the fourth argument before entry work can replace r19 with the a3 error flag. Preserve that saved value when seccomp or ptrace skips dispatch and supplies a restart error; dispatched syscalls still save the argument after any ptrace changes.

Fixes 83bd31c2840b ("alpha: enable GENERIC_ENTRY")
---
 arch/alpha/include/asm/entry-common.h | 10 ++++++++++
 arch/alpha/kernel/signal.c            | 13 ++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)
arch/alpha/include/asm/entry-common.h +10 -0
index a811c73454d28dbc166b83b6f5cd550da339b5fb..85dabd1021da012269eb28acb3ce2da21e0ad706 100644
@@ -4,6 +4,7 @@
 
 #include <asm/stacktrace.h> /* For on_thread_stack() */
 #include <asm/syscall.h>
+#include <asm/thread_info.h>
 
 #define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
 
@@ -11,4 +12,13 @@ static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
 				unsigned long ti_work)
 {
 }
+
+#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
+static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
+						 unsigned long ti_work)
+{
+	/* An interrupt after returning to user mode must not restart a syscall. */
+	current_thread_info()->syscall_saved_nr = 0;
+}
+
 #endif
arch/alpha/kernel/signal.c +10 -3
index 3fae37b4593f22f07a375ab7bc0b0712d0130a07..ab32affa09c41152eabd1f3be92a126a85fb7a2d 100644
@@ -154,6 +154,7 @@ restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs)
 	struct switch_stack *sw = (struct switch_stack *)regs - 1;
 
 	current->restart_block.fn = do_no_restart_syscall;
+	current_thread_info()->syscall_saved_nr = 0;
 	current_thread_info()->status |= TS_SAVED_FP | TS_RESTORE_FP;
 
 	sw->r26 = (unsigned long) ret_from_sys_call;
@@ -497,17 +498,20 @@ do_signal(struct pt_regs *regs, unsigned long r0, unsigned long r19)
 	unsigned long single_stepping = ptrace_cancel_bpt(current);
 	struct ksignal ksig;
 
+	/* Consume restart state once, even if the exit loop repeats. */
+	current_thread_info()->syscall_saved_nr = 0;
+
 	/* This lets the debugger run, ... */
 	if (get_signal(&ksig)) {
 		/* ... so re-check the single stepping. */
 		single_stepping |= ptrace_cancel_bpt(current);
 		/* Whee!  Actually deliver the signal.  */
-		if (r0)
+		if (r0 && regs->r19)
 			syscall_restart(r0, r19, regs, &ksig.ka);
 		handle_signal(&ksig, regs);
 	} else {
 		single_stepping |= ptrace_cancel_bpt(current);
-		if (r0) {
+		if (r0 && regs->r19) {
 			switch (regs->r0) {
 			case ERESTARTNOHAND:
 			case ERESTARTSYS:
@@ -571,6 +575,7 @@ alpha_syscall_enter_select(struct pt_regs *regs, long syscall)
 
 	ti->syscall_meta = 0;
 	ti->syscall_saved_nr = syscall;
+	ti->syscall_saved_r19 = saved_r19;
 
 	if (!(ti->status & TS_SAVED_FP)) {
 		ti->status |= TS_SAVED_FP;
@@ -614,7 +619,9 @@ alpha_finish_syscall_to_user_mode(struct pt_regs *regs, long ret)
 	unsigned long meta = ti->syscall_meta;
 
 	ti->syscall_meta = 0;
-	ti->syscall_saved_r19 = regs->r19;
+	/* Entry work may have replaced argument 4 with the a3 error flag. */
+	if (!(meta & ALPHA_SYSCALL_META_SKIP))
+		ti->syscall_saved_r19 = regs->r19;
 
 	instrumentation_begin();
 
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH 5/14 alpha: distinguish skipped syscalls from invalid numbers

In reply to Magnus Lindholm

An out-of-range syscall number other than -1 must return ENOSYS even when a tracer has changed the return registers. Keep explicit results only when entry work rejects dispatch or the number is the -1 abort sentinel. The generic-entry conversion incorrectly treats both cases as skipped calls and preserves tracer results for invalid numbers.

Track explicitly supplied r0 values instead of inferring them from register contents. Alpha cannot preset its complete ENOSYS return state before entry work because r19 is still argument 4. Value comparisons can overwrite legitimate results, including -1, the original syscall number and a seccomp errno matching the entry registers.

Mark results supplied by syscall_set_return_value(), scalar ptrace result writes and regset writes covering r0. Keep number-only aborts returning ENOSYS. After a legacy r0=-1 abort, subsequent r0 writes are results, not another syscall-number substitution. Honor the supplied r19 error flag for regsets instead of turning small successes into errors. Writes outside r0 and empty regset writes must not mark it.

Preserve seccomp return values, SIGSYS rollback and saved restart arguments. The existing per-syscall metadata reset prevents a supplied result from carrying over to another syscall.

Fixes 83bd31c2840b ("alpha: enable GENERIC_ENTRY")
---
 arch/alpha/include/asm/syscall.h     |  2 +-
 arch/alpha/include/asm/thread_info.h |  1 +
 arch/alpha/kernel/ptrace.c           | 25 +++++++++---------------
 arch/alpha/kernel/signal.c           | 37 ++++++++----------------------------
 4 files changed, 19 insertions(+), 46 deletions(-)
arch/alpha/include/asm/syscall.h +1 -1
index 22315b932f854a71fd3babf6565dda443c6c7a77..52fa96ea57caba5f04c2c0c3d9ea31b909eb9f60 100644
@@ -94,7 +94,7 @@ static inline void syscall_set_return_value(struct task_struct *task,
 					struct pt_regs *regs,
 					int error, long val)
 {
-
+	task_thread_info(task)->syscall_meta |= ALPHA_SYSCALL_META_RESULT;
 	if (error) {
 		/* error is negative errno in this tree */
 		regs->r0  = (unsigned long)(-error);  /* positive errno */
arch/alpha/include/asm/thread_info.h +1 -0
index 49bc08f3b5a98fbcb1d4ac919001bf70c3db614b..78f9f60d4ad197c27cd05bfd6a5c20af22bee7a3 100644
@@ -58,6 +58,7 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
 #define ALPHA_SYSCALL_META_SKIP			0x2
 #define ALPHA_SYSCALL_META_FORCE_SUCCESS	0x4
 #define ALPHA_SYSCALL_META_ROLLBACK		0x10
+#define ALPHA_SYSCALL_META_RESULT			0x20
 
 /*
  * Thread information flags:
arch/alpha/kernel/ptrace.c +9 -16
index dba7e9905cfa842dbfe851b3e6ab996c94f7ee46..08e2401cb7e005795a04e169f0c53cf9ed35adb5 100644
@@ -280,21 +280,6 @@ static void alpha_elf_gregs_set(struct task_struct *child,
 
 	if (nwords > 32)
 		ti->pcb.unique = src[32];
-
-/*
- * PTRACE_SETREGSET can be used at a syscall-entry stop to skip the
- * syscall by setting the syscall number to -1.  The seccomp/ptrace
- * selftests use this to synthesize errno returns.
- *
- * Alpha uses r19/a3 as the error flag, so a skipped syscall with a
- * small positive r0 and a clear r19 must be normalized to an error
- * return.
- */
-	if (pt->r1 == (unsigned long)-1 &&
-	    pt->r19 == 0 &&
-	    pt->r0 > 0 &&
-	    pt->r0 < MAX_ERRNO)
-		pt->r19 = 1;
 }
 
 static int
@@ -328,7 +313,8 @@ put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
 	 * mutable syscall number in regs->r1.
 	 */
 
-	if (regno == 0 && regs->r1 == old_r0 &&
+	if (regno == 0 && regs->r1 != (unsigned long)-1 &&
+	    regs->r1 == old_r0 &&
 		(data == (unsigned long)-1 ||
 		(regs->r19 == 0 && data < NR_syscalls))) {
 		regs->r1 = data;
@@ -339,6 +325,9 @@ put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
 	 */
 		if (data == (unsigned long)-1)
 			regs->r19 = 0;
+	} else if (regno == 0) {
+		/* Once dispatch is cancelled, even -1 is a valid result. */
+		task_thread_info(task)->syscall_meta |= ALPHA_SYSCALL_META_RESULT;
 	}
 	return 0;
 }
@@ -535,6 +524,7 @@ static int alpha_regset_set(struct task_struct *target,
 {
 	elf_gregset_t gregs;
 	unsigned int nwords;
+	bool writes_r0 = count && pos < sizeof(elf_greg_t);
 
 	if (pos + count > sizeof(gregs))
 		return -EIO;
@@ -551,6 +541,9 @@ static int alpha_regset_set(struct task_struct *target,
 
 	nwords = sizeof(gregs) / sizeof(elf_greg_t);
 	alpha_elf_gregs_set(target, gregs, nwords);
+	/* Only count r0 bytes actually supplied, not the preserved registers. */
+	if (writes_r0)
+		task_thread_info(target)->syscall_meta |= ALPHA_SYSCALL_META_RESULT;
 
 	return 0;
 }
arch/alpha/kernel/signal.c +8 -29
index ab32affa09c41152eabd1f3be92a126a85fb7a2d..f972f690eb678b9201e340624a60fe26ad7f23c8 100644
@@ -567,7 +567,6 @@ asmlinkage unsigned long
 alpha_syscall_enter_select(struct pt_regs *regs, long syscall)
 {
 	struct thread_info *ti = current_thread_info();
-	unsigned long saved_r0 = regs->r0;
 	unsigned long saved_r19 = regs->r19;
 	unsigned long fn = (unsigned long)sys_ni_syscall;
 	long nr = syscall;
@@ -584,22 +583,20 @@ alpha_syscall_enter_select(struct pt_regs *regs, long syscall)
 
 	permit = syscall_enter_from_user_mode_randomize_stack(regs, &nr);
 
-	/*
-	 * Alpha cannot preset the full -ENOSYS return state before generic
-	 * entry handling, because r19 is still syscall argument 4 on the
-	 * normal dispatch path. So provide the default -ENOSYS result only
-	 * here, after we know no real syscall will be invoked, and only if
-	 * entry work did not already change the return state.
-	 */
-	if (unlikely(!permit || (unsigned long)nr >= NR_syscalls)) {
-		if (!(ti->syscall_meta & ALPHA_SYSCALL_META_ROLLBACK) &&
-		    regs->r0 == saved_r0 && regs->r19 == saved_r19)
+	if (unlikely(!permit || nr == -1)) {
+		/* r19 is still argument 4 unless a hook supplied a result. */
+		if (!(ti->syscall_meta & (ALPHA_SYSCALL_META_RESULT |
+					 ALPHA_SYSCALL_META_ROLLBACK)))
 			syscall_set_return_value(current, regs, -ENOSYS, 0);
 
 		ti->syscall_meta |= ALPHA_SYSCALL_META_SKIP;
 		return fn;	/* ignored by asm when SKIP is set */
 	}
 
+	/* Invalid numbers other than -1 must invoke sys_ni_syscall(). */
+	if (unlikely((unsigned long)nr >= NR_syscalls))
+		return fn;
+
 	instrumentation_begin();
 	{
 		unsigned long index;
@@ -633,24 +630,6 @@ alpha_finish_syscall_to_user_mode(struct pt_regs *regs, long ret)
 	}
 
 	if (meta & ALPHA_SYSCALL_META_SKIP) {
-	/*
-	 * Skip-dispatch path: ptrace/seccomp may already have installed
-	 * the return state in r0/r19. Preserve it unless the syscall was
-	 * skipped with no explicit return value.
-	 *
-	 * Generic PTRACE_SET_SYSCALL_INFO changes only the syscall-number
-	 * shadow, so r1 == -1 while r0 still contains the original Alpha
-	 * syscall number. Legacy PTRACE_POKEUSR based skipping can leave
-	 * r0 == -1 with a3/r19 still indicating success. Both represent
-	 * an unhandled skipped syscall and should become ENOSYS/a3=1.
-	 */
-		if (regs->r1 == (unsigned long)-1 &&
-		   (regs->r0 == ti->syscall_saved_nr ||
-		    regs->r0 == (unsigned long)-1)) {
-			regs->r0 = ENOSYS;
-			regs->r19 = 1;
-		}
-
 		instrumentation_end();
 
 		syscall_exit_to_user_mode(regs);
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 6/14 alpha: dispatch system calls from C

In reply to Magnus Lindholm

Move syscall dispatch and result encoding into alpha_syscall(), keeping the complete user switch_stack available throughout the C call. Use the generic fork/clone handlers and remove the assembly dispatch and sigreturn wrappers. Preserve Alpha's r0/a3 ABI, ptrace/seccomp overrides and restored signal contexts.

The syscall table names also enable tracepoints for fork, vfork, clone, clone3, sigreturn and rt_sigreturn.

---
 arch/alpha/include/asm/syscall.h       |  18 +----
 arch/alpha/include/asm/thread_info.h   |   1 +
 arch/alpha/kernel/Makefile             |   2 +-
 arch/alpha/kernel/asm-offsets.c        |   1 -
 arch/alpha/kernel/entry.S              | 132 +--------------------------------
 arch/alpha/kernel/proto.h              |  10 +--
 arch/alpha/kernel/signal.c             | 126 +++----------------------------
 arch/alpha/kernel/syscall.c            |  85 +++++++++++++++++++++
 arch/alpha/kernel/syscalls/syscall.tbl |  10 +--
 9 files changed, 113 insertions(+), 272 deletions(-)
arch/alpha/include/asm/syscall.h +4 -14
index 52fa96ea57caba5f04c2c0c3d9ea31b909eb9f60..740ac96cef55d28bcf45251fc722b35421a9f2d5 100644
@@ -29,12 +29,8 @@ static inline long syscall_get_error(struct task_struct *task,
 
 
 /*
- * Alpha syscall ABI / kernel conventions:
- *  - PAL provides syscall number in r0 on entry.
- *  - The kernel tracks the active syscall number in regs->r1 (mutable) and
- *    preserves the original syscall number in regs->r2 for rollback/restart.
- *  - Return value is in regs->r0, with regs->r19 ("a3") as the error flag
- *    (0=success, 1=error; on error regs->r0 holds positive errno).
+ * The syscall number arrives in r0. Entry saves the original in thread_info
+ * for rollback and restart, while tracers can change the number in r1.
  */
 
 static inline long syscall_get_nr(struct task_struct *task,
@@ -80,14 +76,8 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	regs->r21 = args[5];
 }
 /*
- * Set return value for a syscall.
- * Alpha uses r0 for return value and r19 ("a3") as the error indicator:
- *   a3 = 0 => success
- *   a3 = 1 => error, and userspace interprets r0 as errno (positive).
- *
- * The kernel reports errors to userspace by setting a3=1 and placing a
- * positive errno value in r0. Some syscall paths do this in entry.S,
- * while others (e.g. seccomp/ptrace helpers) use syscall_set_return_value().
+ * On error, r0 holds a positive errno and a3 is set.
+ * On success, r0 holds the result and a3 is clear.
  */
 
 static inline void syscall_set_return_value(struct task_struct *task,
arch/alpha/include/asm/thread_info.h +1 -0
index 78f9f60d4ad197c27cd05bfd6a5c20af22bee7a3..94bdf9016705cc6b0aea64c3f601de3ef555eb7b 100644
@@ -57,6 +57,7 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
 
 #define ALPHA_SYSCALL_META_SKIP			0x2
 #define ALPHA_SYSCALL_META_FORCE_SUCCESS	0x4
+#define ALPHA_SYSCALL_META_RESTORED		0x8
 #define ALPHA_SYSCALL_META_ROLLBACK		0x10
 #define ALPHA_SYSCALL_META_RESULT			0x20
 
arch/alpha/kernel/Makefile +1 -1
index 9d35715bd440518b327ad576b78ad35f61433bab..668556d8496c0c3ee03996cf5a4a0ee56b980891 100644
@@ -8,7 +8,7 @@ asflags-y	:= $(KBUILD_CFLAGS)
 ccflags-y	:= -Wno-sign-compare
 
 obj-y    := head.o entry.o traps.o process.o osf_sys.o irq.o \
-	    irq_alpha.o signal.o setup.o ptrace.o time.o \
+	    irq_alpha.o signal.o syscall.o setup.o ptrace.o time.o \
 	    systbls.o err_common.o io.o bugs.o termios.o \
 	    stacktrace.o
 
arch/alpha/kernel/asm-offsets.c +0 -1
index 22ed3c975b1ceb014806fec5d2afc2140ac3e03a..b575dcf367bfde210fa19bd955f1163877b752d6 100644
@@ -22,7 +22,6 @@ static void __used foo(void)
 
 	DEFINE(SP_OFF, offsetof(struct pt_regs, ps));
 	DEFINE(SIZEOF_PT_REGS, sizeof(struct pt_regs));
-	DEFINE(TI_SYSCALL_META, offsetof(struct thread_info, syscall_meta));
 	BLANK();
 
 	DEFINE(SWITCH_STACK_SIZE, sizeof(struct switch_stack));
arch/alpha/kernel/entry.S +2 -130

164 lines not on this page · raw message

arch/alpha/kernel/proto.h +3 -7
index 7ece3b635e27ca04fb8fa93d9118e8be9a225b66..90af335cd6798ad4039ecc2a3c67505eadbd32a2 100644
@@ -169,16 +169,12 @@ extern int ptrace_set_bpt (struct task_struct *child);
 extern int ptrace_cancel_bpt (struct task_struct *child);
 
 /* signal.c */
-struct sigcontext;
-extern void do_sigreturn(struct sigcontext __user *);
-struct rt_sigframe;
-extern void do_rt_sigreturn(struct rt_sigframe __user *);
 extern void alpha_schedule_user_work(void);
 extern void do_signal(struct pt_regs *regs, unsigned long r0, unsigned long r19);
-extern void alpha_syscall_exit_to_user_mode(struct pt_regs *regs);
 extern void alpha_exit_to_user_mode(struct pt_regs *regs);
-extern void alpha_finish_syscall_to_user_mode(struct pt_regs *regs, long ret);
-extern unsigned long alpha_syscall_enter_select(struct pt_regs *regs, long syscall);
+
+/* syscall.c */
+extern void alpha_syscall(struct pt_regs *regs);
 
 /* traps.c */
 extern void dik_show_regs(struct pt_regs *regs, unsigned long *r9_15);
arch/alpha/kernel/signal.c +12 -114

181 lines not on this page · raw message

arch/alpha/kernel/syscall.c new file +85 -0

85 lines not on this page · raw message

arch/alpha/kernel/syscalls/syscall.tbl +5 -5
index 52e3538cc7df415f0b1613eb3db7de56d5bf20a2..f804988f90d6672e3bf409258a0fccc4ba214927 100644
@@ -7,9 +7,9 @@
 #
 # The <abi> is always "common" for this file
 #
-0	common	osf_syscall			alpha_syscall_zero
+0	common	osf_syscall			sys_ni_syscall
 1	common	exit				sys_exit
-2	common	fork				alpha_fork
+2	common	fork				sys_fork
 3	common	read				sys_read
 4	common	write				sys_write
 5	common	osf_old_open			sys_ni_syscall
@@ -72,7 +72,7 @@
 63	common	getpgrp				sys_getpgrp
 64	common	getpagesize			sys_getpagesize
 65	common	osf_mremap			sys_ni_syscall
-66	common	vfork				alpha_vfork
+66	common	vfork				sys_vfork
 67	common	stat				sys_newstat
 68	common	lstat				sys_newlstat
 69	common	osf_sbrk			sys_ni_syscall
@@ -242,7 +242,7 @@
 309	common	get_kernel_syms			sys_ni_syscall
 310	common	syslog				sys_syslog
 311	common	reboot				sys_reboot
-312	common	clone				alpha_clone
+312	common	clone				sys_clone
 313	common	uselib				sys_uselib
 314	common	mlock				sys_mlock
 315	common	munlock				sys_munlock
@@ -474,7 +474,7 @@
 542	common	fsmount				sys_fsmount
 543	common	fspick				sys_fspick
 544	common	pidfd_open			sys_pidfd_open
-545	common	clone3				alpha_clone3
+545	common	clone3				sys_clone3
 546	common	close_range			sys_close_range
 547	common	openat2				sys_openat2
 548	common	pidfd_getfd			sys_pidfd_getfd
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 7/14 alpha: use generic entry helpers for interrupts and exceptions

In reply to Magnus Lindholm

Use irqentry_enter()/irqentry_exit() for ordinary interrupts and exceptions and centralize hardirq accounting in do_entInt(). Keep the saved switch_stack available for signals and fault fixups; register restoration and PAL_rti remain in assembly.

Interrupts now save a switch_stack too; generic exit handles kernel IRQ state restoration. Keep kernel FEN recovery outside entry bookkeeping, since it can interrupt FP saves and restores during entry or exit. The special kernel unaligned-access path is unchanged.

---
 arch/alpha/include/asm/entry-common.h |   7 --
 arch/alpha/kernel/entry.S             | 138 ++++++----------------------------
 arch/alpha/kernel/irq.c               |   8 +-
 arch/alpha/kernel/irq_alpha.c         |  41 +++-------
 arch/alpha/kernel/process.c           |   2 +-
 arch/alpha/kernel/signal.c            |   7 +-
 arch/alpha/kernel/traps.c             | 118 +++++++++++++++++++++++------
 arch/alpha/mm/fault.c                 |  25 +++++-
 8 files changed, 154 insertions(+), 192 deletions(-)
arch/alpha/include/asm/entry-common.h +0 -7
index 85dabd1021da012269eb28acb3ce2da21e0ad706..1d3b3d67235858419a069b7d9e4ce44f2e4e5525 100644
@@ -6,13 +6,6 @@
 #include <asm/syscall.h>
 #include <asm/thread_info.h>
 
-#define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
-
-static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
-				unsigned long ti_work)
-{
-}
-
 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 						 unsigned long ti_work)
arch/alpha/kernel/entry.S +22 -116

175 lines not on this page · raw message

arch/alpha/kernel/irq.c +1 -7
index 5867a165504511a6e693bc6a200e7e9a69415103..c7dfa895c64832a4669a44d0bf92e99d0c5247ee 100644
@@ -86,9 +86,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)
 }
 
 /*
- * handle_irq handles all normal device IRQ's (the special
- * SMP cross-CPU interrupts have their own specific
- * handlers).
+ * Device IRQs use this path. do_entInt() handles hardirq accounting.
  */
 
 #define MAX_ILLEGAL_IRQS 16
@@ -109,8 +107,6 @@ handle_irq(int irq)
 	static unsigned int illegal_count=0;
 	struct irq_desc *desc;
 
-	irq_enter();
-
 	desc = irq_to_desc(irq);
 	if (!desc || ((unsigned) irq > ACTUAL_NR_IRQS &&
 	    illegal_count < MAX_ILLEGAL_IRQS)) {
@@ -118,10 +114,8 @@ handle_irq(int irq)
 		illegal_count++;
 		printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
 		       irq);
-		irq_exit();
 		return;
 	}
 
 	generic_handle_irq_desc(desc);
-	irq_exit();
 }
arch/alpha/kernel/irq_alpha.c +11 -30

89 lines not on this page · raw message

arch/alpha/kernel/process.c +1 -1
index 7861c9e767b720a5939553e9ff3218519ee8e4b5..2182496c535661f399a73400e308c0a7fc6d76f1 100644
@@ -136,7 +136,7 @@ common_shutdown_1(void *generic_ptr)
 		/* If we've gotten here after SysRq-b, leave interrupt
 		   context before taking over the console. */
 		if (in_hardirq())
-			irq_exit();
+			irq_exit_rcu();
 		/* This has the effect of resetting the VGA video origin.  */
 		console_lock();
 		do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES-1, 1);
arch/alpha/kernel/signal.c +4 -3
index c6dd0f2864ade320d59cf1531764640bc6713aa6..244fec20294b81e0c749a07321f917befb62b1a7 100644
@@ -538,11 +538,12 @@ do_signal(struct pt_regs *regs, unsigned long r0, unsigned long r19)
 		ptrace_set_bpt(current);	/* re-set breakpoint */
 }
 
-asmlinkage void alpha_exit_to_user_mode(struct pt_regs *regs)
+asmlinkage noinstr void alpha_exit_to_user_mode(struct pt_regs *regs)
 {
+	instrumentation_begin();
 	local_irq_disable();
-	irqentry_exit_to_user_mode_prepare(regs);
-	exit_to_user_mode();
+	instrumentation_end();
+	irqentry_exit_to_user_mode(regs);
 }
 
 void arch_do_signal_or_restart(struct pt_regs *regs)
arch/alpha/kernel/traps.c +93 -25

175 lines not on this page · raw message

arch/alpha/mm/fault.c +22 -3
index f09f69894cfd65d814ab1cf498c946043fb9e8a3..a46553b5e7d91f6209e2323e92d086989676262c 100644
@@ -5,6 +5,7 @@
  *  Copyright (C) 1995  Linus Torvalds
  */
 
+#include <linux/irq-entry-common.h>
 #include <linux/sched/signal.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -130,9 +131,9 @@ static bool is_prefetch(struct pt_regs *regs)
 	       (1ul << (insn >> 26) & 0x30f00001400ul);
 }
 
-asmlinkage void
-do_page_fault(unsigned long address, unsigned long mmcsr,
-	      long cause, struct pt_regs *regs)
+static void
+handle_page_fault(unsigned long address, unsigned long mmcsr,
+		  long cause, struct pt_regs *regs)
 {
 	struct vm_area_struct * vma;
 	struct mm_struct *mm = current->mm;
@@ -309,3 +310,21 @@ retry:
 	}
 #endif
 }
+
+asmlinkage noinstr void
+do_page_fault(unsigned long address, unsigned long mmcsr,
+	      long cause, struct pt_regs *regs)
+{
+	irqentry_state_t state;
+
+	raw_local_irq_disable();
+	state = irqentry_enter(regs);
+
+	instrumentation_begin();
+	local_irq_restore(regs->ps);
+	handle_page_fault(address, mmcsr, cause, regs);
+	local_irq_disable();
+	instrumentation_end();
+
+	irqentry_exit(regs, state);
+}
Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH 8/14 alpha: use generic syscall exit for new tasks

In reply to Magnus Lindholm

Move fork and kernel-thread startup into C and use syscall_exit_to_user_mode() for the return to userspace, retaining the saved user context for exit work.

This also supplies the child syscall-exit tracepoint for fork, vfork, clone and clone3.

---
 arch/alpha/kernel/entry.S   | 23 ++++++++++-------------
 arch/alpha/kernel/process.c | 16 ++++++++++++++++
 arch/alpha/kernel/proto.h   |  6 ++++--
 arch/alpha/kernel/signal.c  |  8 --------
 4 files changed, 30 insertions(+), 23 deletions(-)
arch/alpha/kernel/entry.S +10 -13
index 2233eb6da7065e7d85cbc668a09e565bcfd75a52..5da8c0d17a1d893f59bee1a12f5782276432674d 100644
@@ -417,11 +417,11 @@ ret_from_exception:
 	beq	$0, restore_other
 	br	restore_all
 
-ret_to_user_from_exception:
-
-	mov	$sp, $16
+ret_from_fork_common:
+	mov	$17, $16
+	mov	$sp, $17
 	DO_SWITCH_STACK
-	jsr	$26, alpha_exit_to_user_mode
+	jsr	$26, alpha_ret_from_fork
 	ldgp	$gp, 0($26)
 	UNDO_SWITCH_STACK
 	br	restore_all
@@ -548,9 +548,9 @@ alpha_switch_to:
 	.align	4
 	.ent	ret_from_fork
 ret_from_fork:
-	lda	$26, ret_to_user_from_exception
-	mov	$17, $16
-	jmp	$31, schedule_tail
+	mov	$31, $18
+	mov	$31, $19
+	br	$31, ret_from_fork_common
 .end ret_from_fork
 
 /*
@@ -560,10 +560,7 @@ ret_from_fork:
 	.globl	ret_from_kernel_thread
 	.ent	ret_from_kernel_thread
 ret_from_kernel_thread:
-	mov	$17, $16
-	jsr	$26, schedule_tail
-	mov	$9, $27
-	mov	$10, $16
-	jsr	$26, ($9)
-	br	$31, ret_to_user_from_exception
+	mov	$9, $18
+	mov	$10, $19
+	br	$31, ret_from_fork_common
 .end ret_from_kernel_thread
arch/alpha/kernel/process.c +16 -0
index 2182496c535661f399a73400e308c0a7fc6d76f1..c7e6e7b593af10305414ea30f5b944b9d21dd2e2 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/cpu.h>
+#include <linux/entry-common.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/sched.h>
@@ -226,6 +227,21 @@ flush_thread(void)
 	current_thread_info()->pcb.unique = 0;
 }
 
+/* The assembly stub keeps the complete user switch_stack below regs. */
+asmlinkage noinstr void alpha_ret_from_fork(struct task_struct *prev,
+					 struct pt_regs *regs,
+					 int (*fn)(void *), void *fn_arg)
+{
+	instrumentation_begin();
+	schedule_tail(prev);
+	if (fn)
+		fn(fn_arg);
+	instrumentation_end();
+
+	/* A kernel thread may return after a successful kernel_execve(). */
+	syscall_exit_to_user_mode(regs);
+}
+
 /*
  * Copy architecture-specific thread state
  */
arch/alpha/kernel/proto.h +4 -2
index 90af335cd6798ad4039ecc2a3c67505eadbd32a2..c418333d0b89d910ec59d1d57d6bcc0550efc4aa 100644
@@ -164,14 +164,16 @@ extern void entDbg(void);
 /* pci.c */
 extern void pcibios_claim_one_bus(struct pci_bus *);
 
+/* process.c */
+extern void alpha_ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
+				int (*fn)(void *), void *fn_arg);
+
 /* ptrace.c */
 extern int ptrace_set_bpt (struct task_struct *child);
 extern int ptrace_cancel_bpt (struct task_struct *child);
 
 /* signal.c */
-extern void alpha_schedule_user_work(void);
 extern void do_signal(struct pt_regs *regs, unsigned long r0, unsigned long r19);
-extern void alpha_exit_to_user_mode(struct pt_regs *regs);
 
 /* syscall.c */
 extern void alpha_syscall(struct pt_regs *regs);
arch/alpha/kernel/signal.c +0 -8
index 244fec20294b81e0c749a07321f917befb62b1a7..e3cb1b50c83d9680032731799b644118b46803bc 100644
@@ -538,14 +538,6 @@ do_signal(struct pt_regs *regs, unsigned long r0, unsigned long r19)
 		ptrace_set_bpt(current);	/* re-set breakpoint */
 }
 
-asmlinkage noinstr void alpha_exit_to_user_mode(struct pt_regs *regs)
-{
-	instrumentation_begin();
-	local_irq_disable();
-	instrumentation_end();
-	irqentry_exit_to_user_mode(regs);
-}
-
 void arch_do_signal_or_restart(struct pt_regs *regs)
 {
 	struct thread_info *ti = current_thread_info();
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 9/14 alpha: remove obsolete core dump register hooks

In reply to Magnus Lindholm

Alpha uses CORE_DUMP_USE_REGSET, so remove the unused per-task ELF register-copy hooks. Write saved FP registers directly with membuf_write() instead of copying them through a temporary array. Register layouts and regset writes are unchanged.

---
 arch/alpha/include/asm/elf.h |  7 -------
 arch/alpha/kernel/process.c  | 14 --------------
 arch/alpha/kernel/ptrace.c   | 17 +++--------------
 3 files changed, 3 insertions(+), 35 deletions(-)
arch/alpha/include/asm/elf.h +0 -7
index b15946621d573f630e253b4046fb3ac6e8bbb66b..7a64d4c3e3574aafcec2d23a843f3cdfc6fca780 100644
@@ -109,18 +109,11 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 
 struct pt_regs;
 struct thread_info;
-struct task_struct;
 extern void dump_elf_thread(elf_greg_t *dest, struct pt_regs *pt,
 			    struct thread_info *ti);
 #define ELF_CORE_COPY_REGS(DEST, REGS) \
 	dump_elf_thread(DEST, REGS, current_thread_info());
 
-/* Similar, but for a thread other than current.  */
-
-extern int dump_elf_task(elf_greg_t *dest, struct task_struct *task);
-#define ELF_CORE_COPY_TASK_REGS(TASK, DEST) \
-	dump_elf_task(*(DEST), TASK)
-
 /* This yields a mask that user programs can use to figure out what
    instruction set this CPU supports.  This is trivial on Alpha, 
    but not so on other machines. */
arch/alpha/kernel/process.c +0 -14
index c7e6e7b593af10305414ea30f5b944b9d21dd2e2..6246929cf4d7583e5b98e24a6aa7b1f2021431f7 100644
@@ -344,20 +344,6 @@ dump_elf_thread(elf_greg_t *dest, struct pt_regs *pt, struct thread_info *ti)
 }
 EXPORT_SYMBOL(dump_elf_thread);
 
-int
-dump_elf_task(elf_greg_t *dest, struct task_struct *task)
-{
-	dump_elf_thread(dest, task_pt_regs(task), task_thread_info(task));
-	return 1;
-}
-EXPORT_SYMBOL(dump_elf_task);
-
-int elf_core_copy_task_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
-{
-	memcpy(fpu, task_thread_info(t)->fp, 32 * 8);
-	return 1;
-}
-
 /*
  * Return saved PC of a blocked thread.  This assumes the frame
  * pointer is the 6th saved long on the kernel stack and that the
arch/alpha/kernel/ptrace.c +3 -14
index 08e2401cb7e005795a04e169f0c53cf9ed35adb5..4f857d5cbb1410961a78e4ef36cce4561a7ea7af 100644
@@ -506,16 +506,7 @@ long arch_ptrace(struct task_struct *child, long request,
 	return ret;
 }
 
-/*
- * Minimal regset support for Alpha.
- *
- * Alpha-specific notes:
- *  - Do NOT use ELF_CORE_COPY_REGS(): it uses current_thread_info(),
- *    which is wrong for non-current tasks.
- *  - dump_elf_task() returns 1 unconditionally in this tree, while
- *    regset_get should return 0 on success. So call dump_elf_thread()
- *    directly and return membuf_write()'s result.
- */
+/* Ptrace and ELF core dumps share the same Alpha register layouts. */
 static int alpha_regset_set(struct task_struct *target,
 			    const struct user_regset *regset,
 			    unsigned int pos, unsigned int count,
@@ -588,10 +579,8 @@ static int alpha_fpregset_get(struct task_struct *target,
 			      const struct user_regset *regset,
 			      struct membuf to)
 {
-	elf_fpregset_t fpregs;
-
-	alpha_elf_fpregs_get(target, fpregs);
-	return membuf_write(&to, fpregs, sizeof(fpregs));
+	return membuf_write(&to, task_thread_info(target)->fp,
+			    sizeof(elf_fpregset_t));
 }
 
 enum alpha_regset {
Signature · 1 line
2.43.0
author maintainer
#10 lore raw

PATCH 10/14 alpha: use generic syscall audit classification

In reply to Magnus Lindholm

Replace Alpha's duplicate audit classes and classifier with AUDIT_GENERIC. Alpha has no compat syscall ABI requiring a private implementation.

The generic classifier also makes execveat match execute-permission rules, as execve already does.

---
 arch/alpha/Kconfig         |  4 ---
 arch/alpha/kernel/Makefile |  1 -
 arch/alpha/kernel/audit.c  | 62 ----------------------------------------------
 3 files changed, 67 deletions(-)
arch/alpha/Kconfig +0 -4
index 19ed083d4f0617218e37a3bac516ec82c5423d7e..014a52e63dec88d72c51c93b3d1c254839ecf33c 100644
@@ -53,7 +53,6 @@ config ALPHA
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
-	select AUDIT_ARCH
 	select EDAC_SUPPORT
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_SMP_IDLE_THREAD
@@ -110,9 +109,6 @@ config PGTABLE_LEVELS
 	int
 	default 3
 
-config AUDIT_ARCH
-	bool
-
 config STACKTRACE_SUPPORT
 	def_bool y
 
arch/alpha/kernel/Makefile +0 -1
index 668556d8496c0c3ee03996cf5a4a0ee56b980891..850f1265cc55db5e0472c37b693dc952bdc75421 100644
@@ -20,7 +20,6 @@ obj-$(CONFIG_MODULES)	+= module.o
 obj-$(CONFIG_PERF_EVENTS) += perf_event.o
 obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o
 obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o
-obj-$(CONFIG_AUDIT)	+= audit.o
 
 ifdef CONFIG_ALPHA_GENERIC
 
arch/alpha/kernel/audit.c deleted +0 -62

62 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#11 lore raw

PATCH 11/14 alpha: use generic ptrace memory writes

In reply to Magnus Lindholm

Let ptrace_request() handle PTRACE_POKETEXT and PTRACE_POKEDATA, removing the duplicate calls to generic_ptrace_pokedata(). Keep Alpha's PEEK handlers for its direct-return syscall convention.

---
 arch/alpha/kernel/ptrace.c | 6 ------
 1 file changed, 6 deletions(-)
arch/alpha/kernel/ptrace.c +0 -6
index 4f857d5cbb1410961a78e4ef36cce4561a7ea7af..18860066156ae7fe5a062095fd2641c4ed0c77de 100644
@@ -489,12 +489,6 @@ long arch_ptrace(struct task_struct *child, long request,
 
 		force_successful_syscall_return();
 		break;
-	/* When I and D space are separate, this will have to be fixed.  */
-	case PTRACE_POKETEXT: /* write the word at location addr. */
-	case PTRACE_POKEDATA:
-		ret = generic_ptrace_pokedata(child, addr, data);
-		break;
-
 	case PTRACE_POKEUSR: /* write the specified register */
 		DBG(DBG_MEM, ("poke $%lu<-%#lx\n", addr, data));
 		ret = put_reg(child, addr, data);
Signature · 1 line
2.43.0
author maintainer
#12 lore raw

PATCH 12/14 alpha: use memparse for memory size options

In reply to Magnus Lindholm

Replace the private parser for mem= and gartsize= with memparse(), preserving page rounding. This also accepts T/P/E suffixes and uses memparse()'s saturating overflow handling.

---
 arch/alpha/kernel/setup.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)
arch/alpha/kernel/setup.c +2 -22
index 4cbcfb1852d51e7aaf37b01a176f4a4280af6dae..28387786cb9f9ad4b587a22a3b0267b825b424c7 100644
@@ -241,26 +241,6 @@ reserve_std_resources(void)
 	for ((_cluster) = (memdesc)->cluster, (i) = 0;		\
 	     (i) < (memdesc)->numclusters; (i)++, (_cluster)++)
 
-static unsigned long __init
-get_mem_size_limit(char *s)
-{
-        unsigned long end = 0;
-        char *from = s;
-
-        end = simple_strtoul(from, &from, 0);
-        if ( *from == 'K' || *from == 'k' ) {
-                end = end << 10;
-                from++;
-        } else if ( *from == 'M' || *from == 'm' ) {
-                end = end << 20;
-                from++;
-        } else if ( *from == 'G' || *from == 'g' ) {
-                end = end << 30;
-                from++;
-        }
-        return end >> PAGE_SHIFT; /* Return the PFN of the limit. */
-}
-
 #ifdef CONFIG_BLK_DEV_INITRD
 void * __init
 move_initrd(unsigned long mem_limit)
@@ -486,7 +466,7 @@ setup_arch(char **cmdline_p)
 			continue;
 		}
 		if (strncmp(p, "mem=", 4) == 0) {
-			mem_size_limit = get_mem_size_limit(p+4);
+			mem_size_limit = memparse(p + 4, NULL) >> PAGE_SHIFT;
 			continue;
 		}
 		if (strncmp(p, "srmcons", 7) == 0) {
@@ -499,7 +479,7 @@ setup_arch(char **cmdline_p)
 		}
 		if (strncmp(p, "gartsize=", 9) == 0) {
 			alpha_agpgart_size =
-				get_mem_size_limit(p+9) << PAGE_SHIFT;
+				memparse(p + 9, NULL) & PAGE_MASK;
 			continue;
 		}
 #ifdef CONFIG_VERBOSE_MCHECK
Signature · 1 line
2.43.0
author maintainer
#13 lore raw

PATCH 13/14 alpha: use generic getrusage for OSF resource accounting

In reply to Magnus Lindholm

Use getrusage() for OSF resource accounting. This intentionally aligns osf_getrusage() accounting with getrusage(2): RUSAGE_SELF covers the whole thread group rather than only the calling thread, and ru_maxrss, block I/O and context-switch counts are populated instead of remaining zero. CPU times use the generic microsecond conversion instead of the previous jiffy rounding.

Keep the OSF structure layout and the existing RUSAGE_SELF/RUSAGE_CHILDREN selector restriction. Share result conversion with osf_wait4() and remove the jiffy-based time conversion.

---
 arch/alpha/kernel/osf_sys.c | 56 ++++++++++++++-------------------------------
 1 file changed, 17 insertions(+), 39 deletions(-)
arch/alpha/kernel/osf_sys.c +17 -39
index 61d8061762133f5e128d8538cf104dfede57ea6d..c08796f627332e4562a30557dee700052d03c0e7 100644
@@ -15,7 +15,7 @@
 #include <linux/sched/signal.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/task_stack.h>
-#include <linux/sched/cputime.h>
+#include <linux/resource.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
@@ -960,13 +960,6 @@ put_tv_to_tv32(struct timeval32 __user *o, struct __kernel_old_timeval *i)
 			    sizeof(struct timeval32));
 }
 
-static inline void
-jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
-{
-	value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
-	value->tv_sec = jiffies / HZ;
-}
-
 SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
 		struct timezone __user *, tz)
 {
@@ -1062,37 +1055,27 @@ struct rusage32 {
 	long	ru_nivcsw;		/* involuntary " */
 };
 
+static int put_rusage32(struct rusage32 __user *ru, struct rusage *r)
+{
+	if (put_tv_to_tv32(&ru->ru_utime, &r->ru_utime))
+		return -EFAULT;
+	if (put_tv_to_tv32(&ru->ru_stime, &r->ru_stime))
+		return -EFAULT;
+	if (copy_to_user(&ru->ru_maxrss, &r->ru_maxrss,
+			 sizeof(*ru) - offsetof(struct rusage32, ru_maxrss)))
+		return -EFAULT;
+	return 0;
+}
+
 SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
 {
-	struct rusage32 r;
-	u64 utime, stime;
-	unsigned long utime_jiffies, stime_jiffies;
+	struct rusage r;
 
 	if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 		return -EINVAL;
 
-	memset(&r, 0, sizeof(r));
-	switch (who) {
-	case RUSAGE_SELF:
-		task_cputime(current, &utime, &stime);
-		utime_jiffies = nsecs_to_jiffies(utime);
-		stime_jiffies = nsecs_to_jiffies(stime);
-		jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
-		jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
-		r.ru_minflt = current->min_flt;
-		r.ru_majflt = current->maj_flt;
-		break;
-	case RUSAGE_CHILDREN:
-		utime_jiffies = nsecs_to_jiffies(current->signal->cutime);
-		stime_jiffies = nsecs_to_jiffies(current->signal->cstime);
-		jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
-		jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
-		r.ru_minflt = current->signal->cmin_flt;
-		r.ru_majflt = current->signal->cmaj_flt;
-		break;
-	}
-
-	return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
+	getrusage(current, who, &r);
+	return put_rusage32(ru, &r);
 }
 
 SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
@@ -1104,12 +1087,7 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
 		return err;
 	if (!ur)
 		return err;
-	if (put_tv_to_tv32(&ur->ru_utime, &r.ru_utime))
-		return -EFAULT;
-	if (put_tv_to_tv32(&ur->ru_stime, &r.ru_stime))
-		return -EFAULT;
-	if (copy_to_user(&ur->ru_maxrss, &r.ru_maxrss,
-	      sizeof(struct rusage32) - offsetof(struct rusage32, ru_maxrss)))
+	if (put_rusage32(ur, &r))
 		return -EFAULT;
 	return err;
 }
Signature · 1 line
2.43.0
author maintainer
#14 lore raw

PATCH 14/14 alpha: use generic CPU device registration

In reply to Magnus Lindholm

Select GENERIC_CPU_DEVICES and remove the private registration initcall. Alpha keeps its possible and present CPU masks in sync, and the generic path registers CPU devices after SMP setup using the same register_cpu() helper.

---
 arch/alpha/Kconfig        |  1 +
 arch/alpha/kernel/setup.c | 17 -----------------
 2 files changed, 1 insertion(+), 17 deletions(-)
arch/alpha/Kconfig +1 -0
index 014a52e63dec88d72c51c93b3d1c254839ecf33c..6ccb2d2303269661eb36ba4892e3026bf595f8a7 100644
@@ -54,6 +54,7 @@ config ALPHA
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select EDAC_SUPPORT
+	select GENERIC_CPU_DEVICES
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_SMP_IDLE_THREAD
 	select HAS_IOPORT
arch/alpha/kernel/setup.c +0 -17
index 28387786cb9f9ad4b587a22a3b0267b825b424c7..9fda01b73b18414c8d9c12903660024bfc0af94c 100644
@@ -17,7 +17,6 @@
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
-#include <linux/slab.h>
 #include <linux/user.h>
 #include <linux/screen_info.h>
 #include <linux/delay.h>
@@ -366,22 +365,6 @@ int page_is_ram(unsigned long pfn)
 	return 0;
 }
 
-static int __init
-register_cpus(void)
-{
-	int i;
-
-	for_each_possible_cpu(i) {
-		struct cpu *p = kzalloc_obj(*p);
-		if (!p)
-			return -ENOMEM;
-		register_cpu(p, i);
-	}
-	return 0;
-}
-
-arch_initcall(register_cpus);
-
 #ifdef CONFIG_MAGIC_SYSRQ
 static void sysrq_reboot_handler(u8 unused)
 {
Signature · 1 line
2.43.0
maintainer Tested-by Reviewed-by on the v1 series
#15 lore raw
In reply to Magnus Lindholm
Quoted 3 lines · Magnus Lindholm

With GENERIC_ENTRY upstream for Alpha, this series moves syscall dispatch and ordinary interrupt/exception entry and exit into C using generic helpers, and removes redundant fork, core-dump, audit and ptrace code.

Each patch builds, and the whole series boots and runs fine on my ES47 (EV7) with both CPUs enabled and lockdep on. seccomp_bpf passes 142/142 as both a normal user and root, and the ptrace syscall_info and peeksiginfo selftests pass. No lockdep reports or warnings in dmesg.

I also wrote a small test that reads 512 bytes from /dev/zero in a loop while a 1ms itimer fires SIGALRM. Without the series, 188 of 200000 reads came back wrong; with it, none did. So patch 4 fixes a real problem.

Two small things, neither worth a respin on its own:

Patch 2: the comment in regs_return_value() says a3 is an error flag only at syscall exit, but the code negates r0 for any user-mode regs with r19 set. That's the same as MIPS, and nothing on alpha calls it outside syscall exit today (we have no uprobes), so the code is fine. The comment just reads as though there's a check that isn't there.

Patches 3/5/6: the ALPHA_SYSCALL_META_* bits come in as 0x10, 0x20, then 0x8, and the RESULT define has an extra tab. Cosmetic.

For the series: