Skip to contentSkip to conversation

prctl: Modernise wiring for optional prctl() calls

RFC PATCH In review Dave Martin 4 participants 18 messages May 14, 2018 – May 21, 2018

Subsystems (8)
x86 PowerPC MIPS arm64 +4 more subsystems
lore
Share & tools
lore
#0 lore raw

cover prctl: Modernise wiring for optional prctl() calls

[Reviewer note: this is a cross-arch series. To reduce spam, I have tried not to Cc people on patches they aren't likely to care about. The complete series can be found in the LKML or linux-arch archives.]

The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now.

This series attempts to modernise the code by defining a couple of new Kconfig variables HAVE_PRCTL_ARCH and HAVE_ARCH_PR_SET_GET_UNALIGN to allow architectures to provide hooks for arch-dependent prctls.

For now this series has had minimal testing: some basic testing of arch-specific prctls using PR_SVE_SET_VL on arm64; build-tested on x86; otherwise untested.

This is not polished yet... but I'm interested to know what people think about the approach.

Cheers
---Dave

Dave Martin (11):
prctl: Support movement of arch prctls out of common code
arm64: Move arch-specific prctls out of core code
MIPS: Remove unused task argument from prctl functions
MIPS: Move arch-specific prctls out of core code
x86: Move arch-specific prctls out of core code
powerpc: Remove unused task argument from prctl functions
powerpc: Move arch-specific prctls out of core code
ia64: Remove unused task argument from prctl functions
ia64: Move arch-specific prctls out of core code
prctl: Remove redundant task argument from PR_{SET,GET}_UNALIGN
backends
prctl: Refactor PR_{SET,GET}_UNALIGN to reduce boilerplate

 arch/Kconfig                         |   6 ++
 arch/alpha/Kconfig                   |   1 +
 arch/alpha/include/asm/thread_info.h |  23 --------
 arch/alpha/kernel/Makefile           |   2 +-
 arch/alpha/kernel/sys.c              |  36 ++++++++++++
 arch/arm64/Kconfig                   |   1 +
 arch/arm64/include/asm/processor.h   |   4 --
 arch/arm64/kernel/sys.c              |  15 +++++
 arch/ia64/Kconfig                    |   2 +
 arch/ia64/include/asm/processor.h    |  24 --------
 arch/ia64/kernel/sys_ia64.c          |  37 ++++++++++++
 arch/mips/Kconfig                    |   1 +
 arch/mips/include/asm/processor.h    |   3 -
 arch/mips/kernel/process.c           |  23 ++++----
 arch/mips/kernel/syscall.c           |  15 +++++
 arch/parisc/Kconfig                  |   1 +
 arch/parisc/include/asm/processor.h  |  14 -----
 arch/parisc/kernel/sys_parisc.c      |  15 +++++
 arch/powerpc/Kconfig                 |   2 +
 arch/powerpc/include/asm/processor.h |  20 ++-----
 arch/powerpc/kernel/process.c        |  38 ++++++------
 arch/powerpc/kernel/syscalls.c       |  17 ++++++
 arch/sh/Kconfig                      |   1 +
 arch/sh/include/asm/processor.h      |   7 ---
 arch/sh/mm/alignment.c               |  12 ++--
 arch/x86/Kconfig                     |   1 +
 arch/x86/include/asm/processor.h     |   6 --
 arch/x86/kernel/Makefile             |   1 +
 arch/x86/kernel/sys.c                |  26 +++++++++
 include/linux/prctl.h                |  27 +++++++++
 include/uapi/linux/prctl.h           |   6 +-
 kernel/sys.c                         | 110 ++++-------------------------------
 tools/include/uapi/linux/prctl.h     |   6 +-
 33 files changed, 263 insertions(+), 240 deletions(-)
 create mode 100644 arch/alpha/kernel/sys.c
 create mode 100644 arch/x86/kernel/sys.c
 create mode 100644 include/linux/prctl.h
Signature · 1 line
2.1.4
#1 lore raw

RFC PATCH 1/11 prctl: Support movement of arch prctls out of common code

The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now, using Kconfig.

This patch defines a new arch hook arch_syscall(). Architectures that implemement arch-specific syscalls can now select HAVE_ARCH_SYSCALL in their Kconfig and define this function appropriately.

The core prctl() implementation now matches option against the list of common or legacy prctls, deferring to prctl_arch() if an unrecognised option is encountered.

(arch_prctl() would have been a nicer name, but it conflicts with the pre-existing syscall of the same name on x86, particularly in the um code.)

No functional change.

Cc Andrew Morton <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc James Hogan <[email protected]>
Cc Kees Cook <[email protected]>
Cc Matt Turner <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Rich Felker <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tony Luck <[email protected]>
Cc Will Deacon <[email protected]>
Cc Yoshinori Sato <[email protected]>
---
 arch/Kconfig                     |  3 +++
 include/linux/prctl.h            | 19 +++++++++++++++++++
 include/uapi/linux/prctl.h       |  6 +++---
 kernel/sys.c                     |  2 +-
 tools/include/uapi/linux/prctl.h |  6 +++---
 5 files changed, 29 insertions(+), 7 deletions(-)
 create mode 100644 include/linux/prctl.h
arch/Kconfig +3 -0
index 8e0d665..b34b3e8 100644
@@ -969,4 +969,7 @@ config REFCOUNT_FULL
 	  against various use-after-free conditions that can be used in
 	  security flaw exploits.
 
+config HAVE_PRCTL_ARCH
+	bool
+
 source "kernel/gcov/Kconfig"
include/linux/prctl.h new file +19 -0
new file mode 100644
index 0000000..5ce3713
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PRCTL_H
+#define _LINUX_PRCTL_H
+
+#include <linux/errno.h>
+#include <uapi/linux/prctl.h>
+
+#ifdef CONFIG_HAVE_PRCTL_ARCH
+extern int prctl_arch(int option, unsigned long arg2,
+	unsigned long arg3, unsigned long arg4, unsigned long arg5);
+#else
+static inline int prctl_arch(int option, unsigned long arg2,
+	unsigned long arg3, unsigned long arg4, unsigned long arg5)
+{
+	return -EINVAL;
+}
+#endif
+
+#endif /* ! _LINUX_PRCTL_H */
include/uapi/linux/prctl.h +3 -3
index af5f8c2..c911ff0 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_PRCTL_H
-#define _LINUX_PRCTL_H
+#ifndef _UAPI_LINUX_PRCTL_H
+#define _UAPI_LINUX_PRCTL_H
 
 #include <linux/types.h>
 
@@ -207,4 +207,4 @@ struct prctl_mm_map {
 # define PR_SVE_VL_LEN_MASK		0xffff
 # define PR_SVE_VL_INHERIT		(1 << 17) /* inherit across exec */
 
-#endif /* _LINUX_PRCTL_H */
+#endif /* _UAPI_LINUX_PRCTL_H */
kernel/sys.c +1 -1
index ad69218..5077f1e 100644
@@ -2451,7 +2451,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		error = SVE_GET_VL();
 		break;
 	default:
-		error = -EINVAL;
+		error = prctl_arch(option, arg2, arg3, arg4, arg5);
 		break;
 	}
 	return error;
tools/include/uapi/linux/prctl.h +3 -3
index af5f8c2..c911ff0 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_PRCTL_H
-#define _LINUX_PRCTL_H
+#ifndef _UAPI_LINUX_PRCTL_H
+#define _UAPI_LINUX_PRCTL_H
 
 #include <linux/types.h>
 
@@ -207,4 +207,4 @@ struct prctl_mm_map {
 # define PR_SVE_VL_LEN_MASK		0xffff
 # define PR_SVE_VL_INHERIT		(1 << 17) /* inherit across exec */
 
-#endif /* _LINUX_PRCTL_H */
+#endif /* _UAPI_LINUX_PRCTL_H */
Signature · 1 line
2.1.4
Acked-by on v1 1/11
#2 lore raw

Re: [RFC PATCH 01/11] prctl: Support movement of arch prctls out of common code

Hi Dave,

Quoted 20 lines · Dave Martin

The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now, using Kconfig.

This patch defines a new arch hook arch_syscall(). Architectures that implemement arch-specific syscalls can now select HAVE_ARCH_SYSCALL in their Kconfig and define this function appropriately.

The core prctl() implementation now matches option against the list of common or legacy prctls, deferring to prctl_arch() if an unrecognised option is encountered.

(arch_prctl() would have been a nicer name, but it conflicts with the pre-existing syscall of the same name on x86, particularly in the um code.)

No functional change.

[...]

include/uapi/linux/prctl.h line 3

Quoted 10 lines
include/uapi/linux/prctl.h +2 -2
index af5f8c2..c911ff0 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_PRCTL_H
-#define _LINUX_PRCTL_H
+#ifndef _UAPI_LINUX_PRCTL_H
+#define _UAPI_LINUX_PRCTL_H

Is it safe to rename this #define, or is there a possibility that userspace could be using it for something and relying on it not changing?

Other than that:

Will

#3 lore raw

RFC PATCH 2/11 arm64: Move arch-specific prctls out of core code

In reply to Dave Martin

This patch moves the arm64-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/Kconfig                 |  1 +
 arch/arm64/include/asm/processor.h |  4 ----
 arch/arm64/kernel/sys.c            | 15 +++++++++++++++
 kernel/sys.c                       | 12 ------------
 4 files changed, 16 insertions(+), 16 deletions(-)
arch/arm64/Kconfig +1 -0
index eb2cf49..6b706af 100644
@@ -123,6 +123,7 @@ config ARM64
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
+	select HAVE_PRCTL_ARCH
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RCU_TABLE_FREE
 	select HAVE_SYSCALL_TRACEPOINTS
arch/arm64/include/asm/processor.h +0 -4
index 7675989..b1d262f 100644
@@ -244,9 +244,5 @@ void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused);
 void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused);
 void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused);
 
-/* Userspace interface for PR_SVE_{SET,GET}_VL prctl()s: */
-#define SVE_SET_VL(arg)	sve_set_current_vl(arg)
-#define SVE_GET_VL()	sve_get_current_vl()
-
 #endif /* __ASSEMBLY__ */
 #endif /* __ASM_PROCESSOR_H */
arch/arm64/kernel/sys.c +15 -0
index 72981ba..597ff35 100644
@@ -22,10 +22,12 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/export.h>
+#include <linux/prctl.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 #include <asm/cpufeature.h>
+#include <asm/fpsimd.h>
 
 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
 			 unsigned long prot, unsigned long flags,
@@ -45,6 +47,19 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality)
 	return sys_personality(personality);
 }
 
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)
+{
+	switch (option) {
+	case PR_SVE_SET_VL:
+		return sve_set_current_vl(arg2);
+	case PR_SVE_GET_VL:
+		return sve_get_current_vl();
+	default:
+		return -EINVAL;
+	}
+}
+
 /*
  * Wrappers to pass the pt_regs argument.
  */
kernel/sys.c +0 -12
index 5077f1e..f917d78 100644
@@ -113,12 +113,6 @@
 #ifndef SET_FP_MODE
 # define SET_FP_MODE(a,b)	(-EINVAL)
 #endif
-#ifndef SVE_SET_VL
-# define SVE_SET_VL(a)		(-EINVAL)
-#endif
-#ifndef SVE_GET_VL
-# define SVE_GET_VL()		(-EINVAL)
-#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2444,12 +2438,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_GET_FP_MODE:
 		error = GET_FP_MODE(me);
 		break;
-	case PR_SVE_SET_VL:
-		error = SVE_SET_VL(arg2);
-		break;
-	case PR_SVE_GET_VL:
-		error = SVE_GET_VL();
-		break;
 	default:
 		error = prctl_arch(option, arg2, arg3, arg4, arg5);
 		break;
Signature · 1 line
2.1.4
Acked-by on v1 2/11
#4 lore raw

Re: [RFC PATCH 02/11] arm64: Move arch-specific prctls out of core code

Quoted 65 lines · Dave Martin

This patch moves the arm64-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/Kconfig                 |  1 +
 arch/arm64/include/asm/processor.h |  4 ----
 arch/arm64/kernel/sys.c            | 15 +++++++++++++++
 kernel/sys.c                       | 12 ------------
 4 files changed, 16 insertions(+), 16 deletions(-)
arch/arm64/Kconfig +1 -0
index eb2cf49..6b706af 100644
@@ -123,6 +123,7 @@ config ARM64
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
+	select HAVE_PRCTL_ARCH
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RCU_TABLE_FREE
 	select HAVE_SYSCALL_TRACEPOINTS
arch/arm64/include/asm/processor.h +0 -4
index 7675989..b1d262f 100644
@@ -244,9 +244,5 @@ void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused);
 void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused);
 void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused);
 
-/* Userspace interface for PR_SVE_{SET,GET}_VL prctl()s: */
-#define SVE_SET_VL(arg)	sve_set_current_vl(arg)
-#define SVE_GET_VL()	sve_get_current_vl()
-
 #endif /* __ASSEMBLY__ */
 #endif /* __ASM_PROCESSOR_H */
arch/arm64/kernel/sys.c +4 -0
index 72981ba..597ff35 100644
@@ -22,10 +22,12 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/export.h>
+#include <linux/prctl.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 #include <asm/cpufeature.h>
+#include <asm/fpsimd.h>
 
 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
 			 unsigned long prot, unsigned long flags,
@@ -45,6 +47,19 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality)
 	return sys_personality(personality);
 }
 
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)

arch/arm64/kernel/sys.c SYSCALL_DEFINE1(arm64_personality, unsigned int, personality) · line 61

Quoted 10 lines
arch/arm64/kernel/sys.c +10 -0
+{
+	switch (option) {
+	case PR_SVE_SET_VL:
+		return sve_set_current_vl(arg2);
+	case PR_SVE_GET_VL:
+		return sve_get_current_vl();
+	default:
+		return -EINVAL;
+	}
+}

If we think this might grow, then it might be worth adding a prctl.c to collect these together. Anyhow:

Will

#5 lore raw

RFC PATCH 3/11 MIPS: Remove unused task argument from prctl functions

In reply to Dave Martin

Some MIPS-specific prctl backends take a task argument that is redundant, since the only thing ever passed is "current".

This patch gets rid of the redundant arguments.

No functional change.

Cc Ralf Baechle <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/include/asm/processor.h |  4 ++--
 arch/mips/kernel/process.c        | 23 +++++++++++------------
 arch/mips/kernel/syscall.c        |  1 +
 kernel/sys.c                      |  8 ++++----
 4 files changed, 18 insertions(+), 18 deletions(-)
arch/mips/include/asm/processor.h +2 -2
index af34afb..8f06608 100644
@@ -420,7 +420,7 @@ extern int mips_get_process_fp_mode(struct task_struct *task);
 extern int mips_set_process_fp_mode(struct task_struct *task,
 				    unsigned int value);
 
-#define GET_FP_MODE(task)		mips_get_process_fp_mode(task)
-#define SET_FP_MODE(task,value)		mips_set_process_fp_mode(task, value)
+#define GET_FP_MODE()			mips_get_process_fp_mode()
+#define SET_FP_MODE(value)		mips_set_process_fp_mode(value)
 
 #endif /* _ASM_PROCESSOR_H */
arch/mips/kernel/process.c +11 -12
index b9e9bf6..7db1989 100644
@@ -679,13 +679,13 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
 	put_cpu();
 }
 
-int mips_get_process_fp_mode(struct task_struct *task)
+int mips_get_process_fp_mode(void)
 {
 	int value = 0;
 
-	if (!test_tsk_thread_flag(task, TIF_32BIT_FPREGS))
+	if (!test_thread_flag(TIF_32BIT_FPREGS))
 		value |= PR_FP_MODE_FR;
-	if (test_tsk_thread_flag(task, TIF_HYBRID_FPREGS))
+	if (test_thread_flag(TIF_HYBRID_FPREGS))
 		value |= PR_FP_MODE_FRE;
 
 	return value;
@@ -699,14 +699,14 @@ static void prepare_for_fp_mode_switch(void *info)
 		lose_fpu(1);
 }
 
-int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
+int mips_set_process_fp_mode(unsigned int value)
 {
 	const unsigned int known_bits = PR_FP_MODE_FR | PR_FP_MODE_FRE;
 	struct task_struct *t;
 	int max_users;
 
 	/* If nothing to change, return right away, successfully.  */
-	if (value == mips_get_process_fp_mode(task))
+	if (value == mips_get_process_fp_mode())
 		return 0;
 
 	/* Only accept a mode change if 64-bit FP enabled for o32.  */
@@ -736,11 +736,10 @@ int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
 	preempt_disable();
 
 	/* Save FP & vector context, then disable FPU & MSA */
-	if (task->signal == current->signal)
-		lose_fpu(1);
+	lose_fpu(1);
 
 	/* Prevent any threads from obtaining live FP context */
-	atomic_set(&task->mm->context.fp_mode_switching, 1);
+	atomic_set(&current->mm->context.fp_mode_switching, 1);
 	smp_mb__after_atomic();
 
 	/*
@@ -750,7 +749,7 @@ int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
 	 */
 	if (num_online_cpus() > 1) {
 		/* No need to send an IPI for the local CPU */
-		max_users = (task->mm == current->mm) ? 1 : 0;
+		max_users = (current->mm == current->mm) ? 1 : 0;
 
 		if (atomic_read(&current->mm->mm_users) > max_users)
 			smp_call_function(prepare_for_fp_mode_switch,
@@ -761,7 +760,7 @@ int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
 	 * There are now no threads of the process with live FP context, so it
 	 * is safe to proceed with the FP mode switch.
 	 */
-	for_each_thread(task, t) {
+	for_each_thread(current, t) {
 		/* Update desired FP register width */
 		if (value & PR_FP_MODE_FR) {
 			clear_tsk_thread_flag(t, TIF_32BIT_FPREGS);
@@ -778,10 +777,10 @@ int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
 	}
 
 	/* Allow threads to use FP again */
-	atomic_set(&task->mm->context.fp_mode_switching, 0);
+	atomic_set(&current->mm->context.fp_mode_switching, 0);
 	preempt_enable();
 
-	wake_up_var(&task->mm->context.fp_mode_switching);
+	wake_up_var(&current->mm->context.fp_mode_switching);
 
 	return 0;
 }
arch/mips/kernel/syscall.c +1 -0
index 69c17b5..15f33f0 100644
@@ -12,6 +12,7 @@
 #include <linux/linkage.h>
 #include <linux/fs.h>
 #include <linux/smp.h>
+#include <linux/prctl.h>
 #include <linux/ptrace.h>
 #include <linux/string.h>
 #include <linux/syscalls.h>
kernel/sys.c +4 -4
index f917d78..520d2e8 100644
@@ -108,10 +108,10 @@
 # define MPX_DISABLE_MANAGEMENT()	(-EINVAL)
 #endif
 #ifndef GET_FP_MODE
-# define GET_FP_MODE(a)		(-EINVAL)
+# define GET_FP_MODE()		(-EINVAL)
 #endif
 #ifndef SET_FP_MODE
-# define SET_FP_MODE(a,b)	(-EINVAL)
+# define SET_FP_MODE(a)		(-EINVAL)
 #endif
 
 /*
@@ -2433,10 +2433,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		error = MPX_DISABLE_MANAGEMENT();
 		break;
 	case PR_SET_FP_MODE:
-		error = SET_FP_MODE(me, arg2);
+		error = SET_FP_MODE(arg2);
 		break;
 	case PR_GET_FP_MODE:
-		error = GET_FP_MODE(me);
+		error = GET_FP_MODE();
 		break;
 	default:
 		error = prctl_arch(option, arg2, arg3, arg4, arg5);
Signature · 1 line
2.1.4
#6 lore raw

RFC PATCH 4/11 MIPS: Move arch-specific prctls out of core code

In reply to Dave Martin

This patch moves the MIPS-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Ralf Baechle <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/Kconfig                 |  1 +
 arch/mips/include/asm/processor.h |  3 ---
 arch/mips/kernel/syscall.c        | 14 ++++++++++++++
 kernel/sys.c                      | 12 ------------
 4 files changed, 15 insertions(+), 15 deletions(-)
arch/mips/Kconfig +1 -0
index 225c95d..99eb2ef 100644
@@ -61,6 +61,7 @@ config MIPS
 	select HAVE_NMI
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select HAVE_PRCTL_ARCH
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_VIRT_CPU_ACCOUNTING_GEN if 64BIT || !SMP
arch/mips/include/asm/processor.h +0 -3
index 8f06608..4a8079a 100644
@@ -420,7 +420,4 @@ extern int mips_get_process_fp_mode(struct task_struct *task);
 extern int mips_set_process_fp_mode(struct task_struct *task,
 				    unsigned int value);
 
-#define GET_FP_MODE()			mips_get_process_fp_mode()
-#define SET_FP_MODE(value)		mips_set_process_fp_mode(value)
-
 #endif /* _ASM_PROCESSOR_H */
arch/mips/kernel/syscall.c +14 -0
index 15f33f0..aa8157c 100644
@@ -35,6 +35,7 @@
 #include <asm/cachectl.h>
 #include <asm/cacheflush.h>
 #include <asm/asm-offsets.h>
+#include <asm/processor.h>
 #include <asm/signal.h>
 #include <asm/sim.h>
 #include <asm/shmparam.h>
@@ -237,6 +238,19 @@ SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
 	return -ENOSYS;
 }
 
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)
+{
+	switch (option) {
+	case PR_SET_FP_MODE:
+		return mips_set_process_fp_mode(arg2);
+	case PR_GET_FP_MODE:
+		return mips_get_process_fp_mode();
+	default:
+		return -EINVAL;
+	}
+}
+
 /*
  * If we ever come here the user sp is bad.  Zap the process right away.
  * Due to the bad stack signaling wouldn't work.
kernel/sys.c +0 -12
index 520d2e8..63228e7 100644
@@ -107,12 +107,6 @@
 #ifndef MPX_DISABLE_MANAGEMENT
 # define MPX_DISABLE_MANAGEMENT()	(-EINVAL)
 #endif
-#ifndef GET_FP_MODE
-# define GET_FP_MODE()		(-EINVAL)
-#endif
-#ifndef SET_FP_MODE
-# define SET_FP_MODE(a)		(-EINVAL)
-#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2432,12 +2426,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EINVAL;
 		error = MPX_DISABLE_MANAGEMENT();
 		break;
-	case PR_SET_FP_MODE:
-		error = SET_FP_MODE(arg2);
-		break;
-	case PR_GET_FP_MODE:
-		error = GET_FP_MODE();
-		break;
 	default:
 		error = prctl_arch(option, arg2, arg3, arg4, arg5);
 		break;
Signature · 1 line
2.1.4
#7 lore raw

RFC PATCH 5/11 x86: Move arch-specific prctls out of core code

In reply to Dave Martin

This patch moves the x86-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/Kconfig                 |  1 +
 arch/x86/include/asm/processor.h |  6 ------
 arch/x86/kernel/Makefile         |  1 +
 arch/x86/kernel/sys.c            | 26 ++++++++++++++++++++++++++
 kernel/sys.c                     | 28 ----------------------------
 5 files changed, 28 insertions(+), 34 deletions(-)
 create mode 100644 arch/x86/kernel/sys.c
arch/x86/Kconfig +1 -0
index c07f492..7bae36a 100644
@@ -176,6 +176,7 @@ config X86
 	select HAVE_HARDLOCKUP_DETECTOR_PERF	if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
+	select HAVE_PRCTL_ARCH
 	select HAVE_RCU_TABLE_FREE
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RELIABLE_STACKTRACE		if X86_64 && UNWINDER_FRAME_POINTER && STACK_VALIDATION
arch/x86/include/asm/processor.h +0 -6
index 21a1149..0ecdda4 100644
@@ -924,18 +924,12 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define KSTK_EIP(task)		(task_pt_regs(task)->ip)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
-#define GET_TSC_CTL(adr)	get_tsc_mode((adr))
-#define SET_TSC_CTL(val)	set_tsc_mode((val))
-
 extern int get_tsc_mode(unsigned long adr);
 extern int set_tsc_mode(unsigned int val);
 
 DECLARE_PER_CPU(u64, msr_misc_features_shadow);
 
 /* Register/unregister a process' MPX related resource */
-#define MPX_ENABLE_MANAGEMENT()	mpx_enable_management()
-#define MPX_DISABLE_MANAGEMENT()	mpx_disable_management()
-
 #ifdef CONFIG_X86_INTEL_MPX
 extern int mpx_enable_management(void);
 extern int mpx_disable_management(void);
arch/x86/kernel/Makefile +1 -0
index 02d6f5c..636e40d 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_MODIFY_LDT_SYSCALL)	+= ldt.o
 obj-y			+= setup.o x86_init.o i8259.o irqinit.o jump_label.o
 obj-$(CONFIG_IRQ_WORK)  += irq_work.o
 obj-y			+= probe_roms.o
+obj-y			+= sys.o
 obj-$(CONFIG_X86_64)	+= sys_x86_64.o
 obj-$(CONFIG_X86_ESPFIX64)	+= espfix_64.o
 obj-$(CONFIG_SYSFS)	+= ksysfs.o
arch/x86/kernel/sys.c new file +26 -0
new file mode 100644
index 0000000..3be4d16
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/errno.h>
+#include <linux/prctl.h>
+#include <asm/processor.h>
+
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)
+{
+	switch (option) {
+	case PR_GET_TSC:
+		return get_tsc_mode(arg2);
+	case PR_SET_TSC:
+		return set_tsc_mode(arg2);
+	case PR_MPX_ENABLE_MANAGEMENT:
+		if (arg2 || arg3 || arg4 || arg5)
+			return -EINVAL;
+		return mpx_enable_management();
+	case PR_MPX_DISABLE_MANAGEMENT:
+		if (arg2 || arg3 || arg4 || arg5)
+			return -EINVAL;
+		return mpx_disable_management();
+	default:
+		return -EINVAL;
+	}
+}
kernel/sys.c +0 -28
index 63228e7..994b5711 100644
@@ -95,18 +95,6 @@
 #ifndef SET_ENDIAN
 # define SET_ENDIAN(a, b)	(-EINVAL)
 #endif
-#ifndef GET_TSC_CTL
-# define GET_TSC_CTL(a)		(-EINVAL)
-#endif
-#ifndef SET_TSC_CTL
-# define SET_TSC_CTL(a)		(-EINVAL)
-#endif
-#ifndef MPX_ENABLE_MANAGEMENT
-# define MPX_ENABLE_MANAGEMENT()	(-EINVAL)
-#endif
-#ifndef MPX_DISABLE_MANAGEMENT
-# define MPX_DISABLE_MANAGEMENT()	(-EINVAL)
-#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2314,12 +2302,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_SET_SECCOMP:
 		error = prctl_set_seccomp(arg2, (char __user *)arg3);
 		break;
-	case PR_GET_TSC:
-		error = GET_TSC_CTL(arg2);
-		break;
-	case PR_SET_TSC:
-		error = SET_TSC_CTL(arg2);
-		break;
 	case PR_TASK_PERF_EVENTS_DISABLE:
 		error = perf_event_task_disable();
 		break;
@@ -2416,16 +2398,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			clear_bit(MMF_DISABLE_THP, &me->mm->flags);
 		up_write(&me->mm->mmap_sem);
 		break;
-	case PR_MPX_ENABLE_MANAGEMENT:
-		if (arg2 || arg3 || arg4 || arg5)
-			return -EINVAL;
-		error = MPX_ENABLE_MANAGEMENT();
-		break;
-	case PR_MPX_DISABLE_MANAGEMENT:
-		if (arg2 || arg3 || arg4 || arg5)
-			return -EINVAL;
-		error = MPX_DISABLE_MANAGEMENT();
-		break;
 	default:
 		error = prctl_arch(option, arg2, arg3, arg4, arg5);
 		break;
Signature · 1 line
2.1.4
#8 lore raw

RFC PATCH 6/11 powerpc: Remove unused task argument from prctl functions

In reply to Dave Martin

Some powerpc-specific prctl backends take a task argument that is redundant, since the only thing ever passed is "current".

This patch gets rid of the redundant arguments.

No functional change.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/include/asm/processor.h | 16 ++++++++--------
 arch/powerpc/kernel/process.c        | 30 +++++++++++++++---------------
 kernel/sys.c                         | 12 ++++++------
 3 files changed, 29 insertions(+), 29 deletions(-)
arch/powerpc/include/asm/processor.h +8 -8
index c4b36a4..313dec1 100644
@@ -407,17 +407,17 @@ unsigned long get_wchan(struct task_struct *p);
 #define KSTK_ESP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
 
 /* Get/set floating-point exception mode */
-#define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
-#define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
+#define GET_FPEXC_CTL(adr) get_fpexc_mode((adr))
+#define SET_FPEXC_CTL(val) set_fpexc_mode((val))
 
-extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
-extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
+extern int get_fpexc_mode(unsigned long adr);
+extern int set_fpexc_mode(unsigned int val);
 
-#define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
-#define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
+#define GET_ENDIAN(adr) get_endian((adr))
+#define SET_ENDIAN(val) set_endian((val))
 
-extern int get_endian(struct task_struct *tsk, unsigned long adr);
-extern int set_endian(struct task_struct *tsk, unsigned int val);
+extern int get_endian(unsigned long adr);
+extern int set_endian(unsigned int val);
 
 #define GET_UNALIGN_CTL(tsk, adr)	get_unalign_ctl((tsk), (adr))
 #define SET_UNALIGN_CTL(tsk, val)	set_unalign_ctl((tsk), (val))
arch/powerpc/kernel/process.c +15 -15
index 1237f13..0fcb2f5 100644
@@ -1896,9 +1896,9 @@ EXPORT_SYMBOL(start_thread);
 #define PR_FP_ALL_EXCEPT (PR_FP_EXC_DIV | PR_FP_EXC_OVF | PR_FP_EXC_UND \
 		| PR_FP_EXC_RES | PR_FP_EXC_INV)
 
-int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
+int set_fpexc_mode(unsigned int val)
 {
-	struct pt_regs *regs = tsk->thread.regs;
+	struct pt_regs *regs = current->thread.regs;
 
 	/* This is a bit hairy.  If we are an SPE enabled  processor
 	 * (have embedded fp) we store the IEEE exception enable flags in
@@ -1919,8 +1919,8 @@ int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
 			 * anyway to restore the prctl settings from
 			 * the saved environment.
 			 */
-			tsk->thread.spefscr_last = mfspr(SPRN_SPEFSCR);
-			tsk->thread.fpexc_mode = val &
+			current->thread.spefscr_last = mfspr(SPRN_SPEFSCR);
+			current->thread.fpexc_mode = val &
 				(PR_FP_EXC_SW_ENABLE | PR_FP_ALL_EXCEPT);
 			return 0;
 		} else {
@@ -1938,18 +1938,18 @@ int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
 	 * them does not change anything */
 	if (val > PR_FP_EXC_PRECISE)
 		return -EINVAL;
-	tsk->thread.fpexc_mode = __pack_fe01(val);
+	current->thread.fpexc_mode = __pack_fe01(val);
 	if (regs != NULL && (regs->msr & MSR_FP) != 0)
 		regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1))
-			| tsk->thread.fpexc_mode;
+			| current->thread.fpexc_mode;
 	return 0;
 }
 
-int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
+int get_fpexc_mode(unsigned long adr)
 {
 	unsigned int val;
 
-	if (tsk->thread.fpexc_mode & PR_FP_EXC_SW_ENABLE)
+	if (current->thread.fpexc_mode & PR_FP_EXC_SW_ENABLE)
 #ifdef CONFIG_SPE
 		if (cpu_has_feature(CPU_FTR_SPE)) {
 			/*
@@ -1964,21 +1964,21 @@ int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
 			 * anyway to restore the prctl settings from
 			 * the saved environment.
 			 */
-			tsk->thread.spefscr_last = mfspr(SPRN_SPEFSCR);
-			val = tsk->thread.fpexc_mode;
+			current->thread.spefscr_last = mfspr(SPRN_SPEFSCR);
+			val = current->thread.fpexc_mode;
 		} else
 			return -EINVAL;
 #else
 		return -EINVAL;
 #endif
 	else
-		val = __unpack_fe01(tsk->thread.fpexc_mode);
+		val = __unpack_fe01(current->thread.fpexc_mode);
 	return put_user(val, (unsigned int __user *) adr);
 }
 
-int set_endian(struct task_struct *tsk, unsigned int val)
+int set_endian(unsigned int val)
 {
-	struct pt_regs *regs = tsk->thread.regs;
+	struct pt_regs *regs = current->thread.regs;
 
 	if ((val == PR_ENDIAN_LITTLE && !cpu_has_feature(CPU_FTR_REAL_LE)) ||
 	    (val == PR_ENDIAN_PPC_LITTLE && !cpu_has_feature(CPU_FTR_PPC_LE)))
@@ -1997,9 +1997,9 @@ int set_endian(struct task_struct *tsk, unsigned int val)
 	return 0;
 }
 
-int get_endian(struct task_struct *tsk, unsigned long adr)
+int get_endian(unsigned long adr)
 {
-	struct pt_regs *regs = tsk->thread.regs;
+	struct pt_regs *regs = current->thread.regs;
 	unsigned int val;
 
 	if (!cpu_has_feature(CPU_FTR_PPC_LE) &&
kernel/sys.c +6 -6
index 994b5711..44e1c47 100644
@@ -90,10 +90,10 @@
 # define GET_FPEXC_CTL(a, b)	(-EINVAL)
 #endif
 #ifndef GET_ENDIAN
-# define GET_ENDIAN(a, b)	(-EINVAL)
+# define GET_ENDIAN(b)		(-EINVAL)
 #endif
 #ifndef SET_ENDIAN
-# define SET_ENDIAN(a, b)	(-EINVAL)
+# define SET_ENDIAN(b)		(-EINVAL)
 #endif
 
 /*
@@ -2265,10 +2265,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		error = GET_FPEMU_CTL(me, arg2);
 		break;
 	case PR_SET_FPEXC:
-		error = SET_FPEXC_CTL(me, arg2);
+		error = SET_FPEXC_CTL(arg2);
 		break;
 	case PR_GET_FPEXC:
-		error = GET_FPEXC_CTL(me, arg2);
+		error = GET_FPEXC_CTL(arg2);
 		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
@@ -2291,10 +2291,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EFAULT;
 		break;
 	case PR_GET_ENDIAN:
-		error = GET_ENDIAN(me, arg2);
+		error = GET_ENDIAN(arg2);
 		break;
 	case PR_SET_ENDIAN:
-		error = SET_ENDIAN(me, arg2);
+		error = SET_ENDIAN(arg2);
 		break;
 	case PR_GET_SECCOMP:
 		error = prctl_get_seccomp();
Signature · 1 line
2.1.4
reviewer Acked-by on v1 6/11
#9 lore raw

Re: [RFC PATCH 06/11] powerpc: Remove unused task argument from prctl functions

Quoted 11 lines · Dave Martin

Some powerpc-specific prctl backends take a task argument that is redundant, since the only thing ever passed is "current".

This patch gets rid of the redundant arguments.

No functional change.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Quoted 5 lines
---
 arch/powerpc/include/asm/processor.h | 16 ++++++++--------
 arch/powerpc/kernel/process.c        | 30 +++++++++++++++---------------
 kernel/sys.c                         | 12 ++++++------
 3 files changed, 29 insertions(+), 29 deletions(-)

This looks fine. I'm happy for it to get tested in linux-next to shake out anything subtle.

cheers

#10 lore raw

RFC PATCH 7/11 powerpc: Move arch-specific prctls out of core code

In reply to Dave Martin

This patch moves the powerpc-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/Kconfig                 |  1 +
 arch/powerpc/include/asm/processor.h |  6 ------
 arch/powerpc/kernel/syscalls.c       | 17 +++++++++++++++++
 kernel/sys.c                         | 24 ------------------------
 4 files changed, 18 insertions(+), 30 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181..b94323e 100644
@@ -218,6 +218,7 @@ config PPC
 	select HAVE_HARDLOCKUP_DETECTOR_PERF	if PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
+	select HAVE_PRCTL_ARCH
 	select HAVE_RCU_TABLE_FREE		if SMP
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_SYSCALL_TRACEPOINTS
arch/powerpc/include/asm/processor.h +0 -6
index 313dec1..e1cd7ec 100644
@@ -407,15 +407,9 @@ unsigned long get_wchan(struct task_struct *p);
 #define KSTK_ESP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
 
 /* Get/set floating-point exception mode */
-#define GET_FPEXC_CTL(adr) get_fpexc_mode((adr))
-#define SET_FPEXC_CTL(val) set_fpexc_mode((val))
-
 extern int get_fpexc_mode(unsigned long adr);
 extern int set_fpexc_mode(unsigned int val);
 
-#define GET_ENDIAN(adr) get_endian((adr))
-#define SET_ENDIAN(val) set_endian((val))
-
 extern int get_endian(unsigned long adr);
 extern int set_endian(unsigned int val);
 
arch/powerpc/kernel/syscalls.c +17 -0
index 4662165..0d6a914 100644
@@ -139,3 +139,20 @@ long sys_switch_endian(void)
 
 	return 0;
 }
+
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)
+{
+	switch (option) {
+	case PR_SET_FPEXC:
+		return set_fpexc_mode(arg2);
+	case PR_GET_FPEXC:
+		return get_fpexc_mode(arg2);
+	case PR_GET_ENDIAN:
+		return get_endian(arg2);
+	case PR_SET_ENDIAN:
+		return set_endian(arg2);
+	default:
+		return -EINVAL;
+	}
+}
kernel/sys.c +0 -24
index 44e1c47..b154561 100644
@@ -83,18 +83,6 @@
 #ifndef GET_FPEMU_CTL
 # define GET_FPEMU_CTL(a, b)	(-EINVAL)
 #endif
-#ifndef SET_FPEXC_CTL
-# define SET_FPEXC_CTL(a, b)	(-EINVAL)
-#endif
-#ifndef GET_FPEXC_CTL
-# define GET_FPEXC_CTL(a, b)	(-EINVAL)
-#endif
-#ifndef GET_ENDIAN
-# define GET_ENDIAN(b)		(-EINVAL)
-#endif
-#ifndef SET_ENDIAN
-# define SET_ENDIAN(b)		(-EINVAL)
-#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2264,12 +2252,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_GET_FPEMU:
 		error = GET_FPEMU_CTL(me, arg2);
 		break;
-	case PR_SET_FPEXC:
-		error = SET_FPEXC_CTL(arg2);
-		break;
-	case PR_GET_FPEXC:
-		error = GET_FPEXC_CTL(arg2);
-		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
 		break;
@@ -2290,12 +2272,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		if (copy_to_user((char __user *)arg2, comm, sizeof(comm)))
 			return -EFAULT;
 		break;
-	case PR_GET_ENDIAN:
-		error = GET_ENDIAN(arg2);
-		break;
-	case PR_SET_ENDIAN:
-		error = SET_ENDIAN(arg2);
-		break;
 	case PR_GET_SECCOMP:
 		error = prctl_get_seccomp();
 		break;
Signature · 1 line
2.1.4
reviewer Acked-by on v1 7/11
#11 lore raw

Re: [RFC PATCH 07/11] powerpc: Move arch-specific prctls out of core code

Quoted 10 lines · Dave Martin

This patch moves the powerpc-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Quoted 6 lines
---
 arch/powerpc/Kconfig                 |  1 +
 arch/powerpc/include/asm/processor.h |  6 ------
 arch/powerpc/kernel/syscalls.c       | 17 +++++++++++++++++
 kernel/sys.c                         | 24 ------------------------
 4 files changed, 18 insertions(+), 30 deletions(-)

This also looks OK to me.

cheers

#12 lore raw

RFC PATCH 8/11 ia64: Remove unused task argument from prctl functions

In reply to Dave Martin

Some ia64-specific prctl backends take a task argument that is redundant, since the only thing ever passed is "current".

This patch gets rid of the redundant arguments.

No functional change.

---
 arch/ia64/include/asm/processor.h | 8 ++++----
 kernel/sys.c                      | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
arch/ia64/include/asm/processor.h +4 -4
index 10061ccf..0489b80 100644
@@ -259,15 +259,15 @@ typedef struct {
 		 (int __user *) (addr));							\
 })
 
-#define SET_FPEMU_CTL(task,value)								\
+#define SET_FPEMU_CTL(value)									\
 ({												\
-	(task)->thread.flags = (((task)->thread.flags & ~IA64_THREAD_FPEMU_MASK)		\
+	current->thread.flags = ((current->thread.flags & ~IA64_THREAD_FPEMU_MASK)		\
 			  | (((value) << IA64_THREAD_FPEMU_SHIFT) & IA64_THREAD_FPEMU_MASK));	\
 	0;											\
 })
-#define GET_FPEMU_CTL(task,addr)								\
+#define GET_FPEMU_CTL(addr)									\
 ({												\
-	put_user(((task)->thread.flags & IA64_THREAD_FPEMU_MASK) >> IA64_THREAD_FPEMU_SHIFT,	\
+	put_user((current->thread.flags & IA64_THREAD_FPEMU_MASK) >> IA64_THREAD_FPEMU_SHIFT,	\
 		 (int __user *) (addr));							\
 })
 
kernel/sys.c +4 -4
index b154561..5549505 100644
@@ -78,10 +78,10 @@
 # define GET_UNALIGN_CTL(a, b)	(-EINVAL)
 #endif
 #ifndef SET_FPEMU_CTL
-# define SET_FPEMU_CTL(a, b)	(-EINVAL)
+# define SET_FPEMU_CTL(a)	(-EINVAL)
 #endif
 #ifndef GET_FPEMU_CTL
-# define GET_FPEMU_CTL(a, b)	(-EINVAL)
+# define GET_FPEMU_CTL(a)	(-EINVAL)
 #endif
 
 /*
@@ -2247,10 +2247,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		error = GET_UNALIGN_CTL(me, arg2);
 		break;
 	case PR_SET_FPEMU:
-		error = SET_FPEMU_CTL(me, arg2);
+		error = SET_FPEMU_CTL(arg2);
 		break;
 	case PR_GET_FPEMU:
-		error = GET_FPEMU_CTL(me, arg2);
+		error = GET_FPEMU_CTL(arg2);
 		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
Signature · 1 line
2.1.4
#13 lore raw

RFC PATCH 9/11 ia64: Move arch-specific prctls out of core code

In reply to Dave Martin

This patch moves the ia64-specific prctl call implementations out of core code and removes redundant boilerplate associated with them.

No functional change.

---
 arch/ia64/Kconfig                 |  1 +
 arch/ia64/include/asm/processor.h | 12 ------------
 arch/ia64/kernel/sys_ia64.c       | 22 ++++++++++++++++++++++
 kernel/sys.c                      | 12 ------------
 4 files changed, 23 insertions(+), 24 deletions(-)
arch/ia64/Kconfig +1 -0
index bbe12a0..a673dd7 100644
@@ -54,6 +54,7 @@ config IA64
 	select MODULES_USE_ELF_RELA
 	select ARCH_USE_CMPXCHG_LOCKREF
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_PRCTL_ARCH
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/processor.h +0 -12
index 0489b80..e40242e 100644
@@ -259,18 +259,6 @@ typedef struct {
 		 (int __user *) (addr));							\
 })
 
-#define SET_FPEMU_CTL(value)									\
-({												\
-	current->thread.flags = ((current->thread.flags & ~IA64_THREAD_FPEMU_MASK)		\
-			  | (((value) << IA64_THREAD_FPEMU_SHIFT) & IA64_THREAD_FPEMU_MASK));	\
-	0;											\
-})
-#define GET_FPEMU_CTL(addr)									\
-({												\
-	put_user((current->thread.flags & IA64_THREAD_FPEMU_MASK) >> IA64_THREAD_FPEMU_SHIFT,	\
-		 (int __user *) (addr));							\
-})
-
 struct thread_struct {
 	__u32 flags;			/* various thread flags (see IA64_THREAD_*) */
 	/* writing on_ustack is performance-critical, so it's worth spending 8 bits on it... */
arch/ia64/kernel/sys_ia64.c +22 -0
index 9ebe1d6..d996585 100644
@@ -15,11 +15,13 @@
 #include <linux/sched/task_stack.h>
 #include <linux/shm.h>
 #include <linux/file.h>		/* doh, must come after sched.h... */
+#include <liunx/prctl.h>
 #include <linux/smp.h>
 #include <linux/syscalls.h>
 #include <linux/highuid.h>
 #include <linux/hugetlb.h>
 
+#include <asm/processor.h>
 #include <asm/shmparam.h>
 #include <linux/uaccess.h>
 
@@ -184,3 +186,23 @@ sys_pciconfig_write (unsigned long bus, unsigned long dfn, unsigned long off, un
 }
 
 #endif /* CONFIG_PCI */
+
+int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
+	       unsigned long arg4, unsigned long arg5)
+{
+	int res;
+
+	switch (option) {
+	case PR_SET_FPEMU:
+		current->thread.flags &= ~IA64_THREAD_FPEMU_MASK;
+		current->thread.flags |= (arg2 << IA64_THREAD_FPEMU_SHIFT) &
+			IA64_THREAD_FPEMU_MASK;
+		return 0;
+	case PR_GET_FPEMU:
+		res = (current->thread.flags & IA64_THREAD_FPEMU_MASK) >>
+			IA64_THREAD_FPEMU_SHIFT;
+		return put_user(res, (int __user *)arg2);
+	default:
+		return -EINVAL;
+	}
+}
kernel/sys.c +0 -12
index 5549505..8111c0d 100644
@@ -77,12 +77,6 @@
 #ifndef GET_UNALIGN_CTL
 # define GET_UNALIGN_CTL(a, b)	(-EINVAL)
 #endif
-#ifndef SET_FPEMU_CTL
-# define SET_FPEMU_CTL(a)	(-EINVAL)
-#endif
-#ifndef GET_FPEMU_CTL
-# define GET_FPEMU_CTL(a)	(-EINVAL)
-#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2246,12 +2240,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_GET_UNALIGN:
 		error = GET_UNALIGN_CTL(me, arg2);
 		break;
-	case PR_SET_FPEMU:
-		error = SET_FPEMU_CTL(arg2);
-		break;
-	case PR_GET_FPEMU:
-		error = GET_FPEMU_CTL(arg2);
-		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
 		break;
Signature · 1 line
2.1.4
#14 lore raw

RFC PATCH 10/11 prctl: Remove redundant task argument from PR_{SET,GET}_UNALIGN backends

In reply to Dave Martin

Architecture backends for the PT_SET_UNALIGN and PR_GET_UNALIGN prctl() calls take a task argument that is redundant, since the only thing ever passed is "current".

This patch gets rid of the redundant arguments.

No functional change.

Cc Kees Cook <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Yoshinori Sato <[email protected]>
Cc Rich Felker <[email protected]>
---
 arch/alpha/include/asm/thread_info.h | 10 +++++-----
 arch/ia64/include/asm/processor.h    |  8 ++++----
 arch/parisc/include/asm/processor.h  |  8 ++++----
 arch/powerpc/include/asm/processor.h |  8 ++++----
 arch/powerpc/kernel/process.c        |  8 ++++----
 arch/sh/include/asm/processor.h      |  8 ++++----
 arch/sh/mm/alignment.c               | 10 +++++-----
 kernel/sys.c                         |  8 ++++----
 8 files changed, 34 insertions(+), 34 deletions(-)
arch/alpha/include/asm/thread_info.h +5 -5
index 807d7b9..403b3c8 100644
@@ -85,19 +85,19 @@ register struct thread_info *__current_thread_info __asm__("$8");
 #define TS_UAC_NOFIX		0x0002	/* ! flags as they match          */
 #define TS_UAC_SIGBUS		0x0004	/* ! userspace part of 'osf_sysinfo' */
 
-#define SET_UNALIGN_CTL(task,value)	({				\
-	__u32 status = task_thread_info(task)->status & ~UAC_BITMASK;	\
+#define SET_UNALIGN_CTL(value)	({					\
+	__u32 status = current_thread_info()->status & ~UAC_BITMASK;	\
 	if (value & PR_UNALIGN_NOPRINT)					\
 		status |= TS_UAC_NOPRINT;				\
 	if (value & PR_UNALIGN_SIGBUS)					\
 		status |= TS_UAC_SIGBUS;				\
 	if (value & 4)	/* alpha-specific */				\
 		status |= TS_UAC_NOFIX;					\
-	task_thread_info(task)->status = status;			\
+	current_thread_info()->status = status;				\
 	0; })
 
-#define GET_UNALIGN_CTL(task,value)	({				\
-	__u32 status = task_thread_info(task)->status & ~UAC_BITMASK;	\
+#define GET_UNALIGN_CTL(value)	({					\
+	__u32 status = current_thread_info()->status & ~UAC_BITMASK;	\
 	__u32 res = 0;							\
 	if (status & TS_UAC_NOPRINT)					\
 		res |= PR_UNALIGN_NOPRINT;				\
arch/ia64/include/asm/processor.h +4 -4
index e40242e..8d5184f 100644
@@ -247,15 +247,15 @@ typedef struct {
 	unsigned long seg;
 } mm_segment_t;
 
-#define SET_UNALIGN_CTL(task,value)								\
+#define SET_UNALIGN_CTL(value)								\
 ({												\
-	(task)->thread.flags = (((task)->thread.flags & ~IA64_THREAD_UAC_MASK)			\
+	current->thread.flags = ((current->thread.flags & ~IA64_THREAD_UAC_MASK)			\
 				| (((value) << IA64_THREAD_UAC_SHIFT) & IA64_THREAD_UAC_MASK));	\
 	0;											\
 })
-#define GET_UNALIGN_CTL(task,addr)								\
+#define GET_UNALIGN_CTL(addr)								\
 ({												\
-	put_user(((task)->thread.flags & IA64_THREAD_UAC_MASK) >> IA64_THREAD_UAC_SHIFT,	\
+	put_user((current->thread.flags & IA64_THREAD_UAC_MASK) >> IA64_THREAD_UAC_SHIFT,	\
 		 (int __user *) (addr));							\
 })
 
arch/parisc/include/asm/processor.h +4 -4
index 2dbe558..b59720f 100644
@@ -139,17 +139,17 @@ struct thread_struct {
 #define PARISC_UAC_SHIFT	0
 #define PARISC_UAC_MASK		(PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
 
-#define SET_UNALIGN_CTL(task,value)                                       \
+#define SET_UNALIGN_CTL(value)                                            \
         ({                                                                \
-        (task)->thread.flags = (((task)->thread.flags & ~PARISC_UAC_MASK) \
+        current->thread.flags = ((current->thread.flags & ~PARISC_UAC_MASK) \
                                 | (((value) << PARISC_UAC_SHIFT) &        \
                                    PARISC_UAC_MASK));                     \
         0;                                                                \
         })
 
-#define GET_UNALIGN_CTL(task,addr)                                        \
+#define GET_UNALIGN_CTL(addr)                                             \
         ({                                                                \
-        put_user(((task)->thread.flags & PARISC_UAC_MASK)                 \
+        put_user((current->thread.flags & PARISC_UAC_MASK)                \
                  >> PARISC_UAC_SHIFT, (int __user *) (addr));             \
         })
 
arch/powerpc/include/asm/processor.h +4 -4
index e1cd7ec..b8d9306 100644
@@ -413,11 +413,11 @@ extern int set_fpexc_mode(unsigned int val);
 extern int get_endian(unsigned long adr);
 extern int set_endian(unsigned int val);
 
-#define GET_UNALIGN_CTL(tsk, adr)	get_unalign_ctl((tsk), (adr))
-#define SET_UNALIGN_CTL(tsk, val)	set_unalign_ctl((tsk), (val))
+#define GET_UNALIGN_CTL(adr)	get_unalign_ctl((adr))
+#define SET_UNALIGN_CTL(val)	set_unalign_ctl((val))
 
-extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
-extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
+extern int get_unalign_ctl(unsigned long adr);
+extern int set_unalign_ctl(unsigned int val);
 
 extern void load_fp_state(struct thread_fp_state *fp);
 extern void store_fp_state(struct thread_fp_state *fp);
arch/powerpc/kernel/process.c +4 -4
index 0fcb2f5..17708b7 100644
@@ -2020,15 +2020,15 @@ int get_endian(unsigned long adr)
 	return put_user(val, (unsigned int __user *)adr);
 }
 
-int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
+int set_unalign_ctl(unsigned int val)
 {
-	tsk->thread.align_ctl = val;
+	current->thread.align_ctl = val;
 	return 0;
 }
 
-int get_unalign_ctl(struct task_struct *tsk, unsigned long adr)
+int get_unalign_ctl(unsigned long adr)
 {
-	return put_user(tsk->thread.align_ctl, (unsigned int __user *)adr);
+	return put_user(current->thread.align_ctl, (unsigned int __user *)adr);
 }
 
 static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
arch/sh/include/asm/processor.h +4 -4
index 6fbf8c8..ce3d9f6 100644
@@ -117,11 +117,11 @@ extern void free_thread_xstate(struct task_struct *);
 extern struct kmem_cache *task_xstate_cachep;
 
 /* arch/sh/mm/alignment.c */
-extern int get_unalign_ctl(struct task_struct *, unsigned long addr);
-extern int set_unalign_ctl(struct task_struct *, unsigned int val);
+extern int get_unalign_ctl(unsigned long addr);
+extern int set_unalign_ctl(unsigned int val);
 
-#define GET_UNALIGN_CTL(tsk, addr)	get_unalign_ctl((tsk), (addr))
-#define SET_UNALIGN_CTL(tsk, val)	set_unalign_ctl((tsk), (val))
+#define GET_UNALIGN_CTL(addr)	get_unalign_ctl((addr))
+#define SET_UNALIGN_CTL(val)	set_unalign_ctl((val))
 
 /* arch/sh/mm/init.c */
 extern unsigned int mem_init_done;
arch/sh/mm/alignment.c +5 -5
index ec2b253..bad2a31 100644
@@ -80,16 +80,16 @@ unsigned int unaligned_user_action(void)
 	return action;
 }
 
-int get_unalign_ctl(struct task_struct *tsk, unsigned long addr)
+int get_unalign_ctl(unsigned long addr)
 {
-	return put_user(tsk->thread.flags & SH_THREAD_UAC_MASK,
+	return put_user(current->thread.flags & SH_THREAD_UAC_MASK,
 			(unsigned int __user *)addr);
 }
 
-int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
+int set_unalign_ctl(unsigned int val)
 {
-	tsk->thread.flags = (tsk->thread.flags & ~SH_THREAD_UAC_MASK) |
-			    (val & SH_THREAD_UAC_MASK);
+	current->thread.flags = (current->thread.flags & ~SH_THREAD_UAC_MASK) |
+				(val & SH_THREAD_UAC_MASK);
 	return 0;
 }
 
kernel/sys.c +4 -4
index 8111c0d..47cf999 100644
@@ -72,10 +72,10 @@
 #include "uid16.h"
 
 #ifndef SET_UNALIGN_CTL
-# define SET_UNALIGN_CTL(a, b)	(-EINVAL)
+# define SET_UNALIGN_CTL(a)	(-EINVAL)
 #endif
 #ifndef GET_UNALIGN_CTL
-# define GET_UNALIGN_CTL(a, b)	(-EINVAL)
+# define GET_UNALIGN_CTL(a)	(-EINVAL)
 #endif
 
 /*
@@ -2235,10 +2235,10 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		break;
 
 	case PR_SET_UNALIGN:
-		error = SET_UNALIGN_CTL(me, arg2);
+		error = SET_UNALIGN_CTL(arg2);
 		break;
 	case PR_GET_UNALIGN:
-		error = GET_UNALIGN_CTL(me, arg2);
+		error = GET_UNALIGN_CTL(arg2);
 		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
Signature · 1 line
2.1.4
#15 lore raw

RFC PATCH 11/11 prctl: Refactor PR_{SET,GET}_UNALIGN to reduce boilerplate

In reply to Dave Martin

The PR_SET_UNALIGN and PR_GET_UNALIGN prctl() calls are implemented by five architectures today, but there is some irregularity and duplication in the way they are implemented.

This patch moves the common put_user() operation to common code, since the user pointer type is the same in all cases.

Because this is hardly hot-path code, there is no strong reason to inline the arch backends for these operations, so this patch also pushes them down into the arch trees as proper C functions, and regularises the style of the backends somewhat.

Cc Kees Cook <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Yoshinori Sato <[email protected]>
Cc Rich Felker <[email protected]>
---
 arch/Kconfig                         |  3 +++
 arch/alpha/Kconfig                   |  1 +
 arch/alpha/include/asm/thread_info.h | 23 -----------------------
 arch/alpha/kernel/Makefile           |  2 +-
 arch/alpha/kernel/sys.c              | 36 ++++++++++++++++++++++++++++++++++++
 arch/ia64/Kconfig                    |  1 +
 arch/ia64/include/asm/processor.h    | 12 ------------
 arch/ia64/kernel/sys_ia64.c          | 15 +++++++++++++++
 arch/parisc/Kconfig                  |  1 +
 arch/parisc/include/asm/processor.h  | 14 --------------
 arch/parisc/kernel/sys_parisc.c      | 15 +++++++++++++++
 arch/powerpc/Kconfig                 |  1 +
 arch/powerpc/include/asm/processor.h |  6 ------
 arch/powerpc/kernel/process.c        |  6 +++---
 arch/sh/Kconfig                      |  1 +
 arch/sh/include/asm/processor.h      |  7 -------
 arch/sh/mm/alignment.c               |  8 ++++----
 include/linux/prctl.h                |  8 ++++++++
 kernel/sys.c                         | 20 ++++++++++----------
 19 files changed, 100 insertions(+), 80 deletions(-)
 create mode 100644 arch/alpha/kernel/sys.c
arch/Kconfig +3 -0
index b34b3e8..a9195ffc 100644
@@ -972,4 +972,7 @@ config REFCOUNT_FULL
 config HAVE_PRCTL_ARCH
 	bool
 
+config HAVE_ARCH_PR_SET_GET_UNALIGN
+	bool
+
 source "kernel/gcov/Kconfig"
arch/alpha/Kconfig +1 -0
index b202288..afb9aaa 100644
@@ -23,6 +23,7 @@ config ALPHA
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_PR_SET_GET_UNALIGN
 	select HAVE_MOD_ARCH_SPECIFIC
 	select MODULES_USE_ELF_RELA
 	select ODD_RT_SIGACTION
arch/alpha/include/asm/thread_info.h +0 -23
index 403b3c8..7ba2099 100644
@@ -85,28 +85,5 @@ register struct thread_info *__current_thread_info __asm__("$8");
 #define TS_UAC_NOFIX		0x0002	/* ! flags as they match          */
 #define TS_UAC_SIGBUS		0x0004	/* ! userspace part of 'osf_sysinfo' */
 
-#define SET_UNALIGN_CTL(value)	({					\
-	__u32 status = current_thread_info()->status & ~UAC_BITMASK;	\
-	if (value & PR_UNALIGN_NOPRINT)					\
-		status |= TS_UAC_NOPRINT;				\
-	if (value & PR_UNALIGN_SIGBUS)					\
-		status |= TS_UAC_SIGBUS;				\
-	if (value & 4)	/* alpha-specific */				\
-		status |= TS_UAC_NOFIX;					\
-	current_thread_info()->status = status;				\
-	0; })
-
-#define GET_UNALIGN_CTL(value)	({					\
-	__u32 status = current_thread_info()->status & ~UAC_BITMASK;	\
-	__u32 res = 0;							\
-	if (status & TS_UAC_NOPRINT)					\
-		res |= PR_UNALIGN_NOPRINT;				\
-	if (status & TS_UAC_SIGBUS)					\
-		res |= PR_UNALIGN_SIGBUS;				\
-	if (status & TS_UAC_NOFIX)					\
-		res |= 4;						\
-	put_user(res, (int __user *)(value));				\
-	})
-
 #endif /* __KERNEL__ */
 #endif /* _ALPHA_THREAD_INFO_H */
arch/alpha/kernel/Makefile +1 -1
index 5a74581..e4b5294 100644
@@ -9,7 +9,7 @@ ccflags-y	:= -Wno-sign-compare
 
 obj-y    := entry.o traps.o process.o osf_sys.o irq.o \
 	    irq_alpha.o signal.o setup.o ptrace.o time.o \
-	    systbls.o err_common.o io.o bugs.o
+	    systbls.o err_common.o io.o bugs.o sys.o
 
 obj-$(CONFIG_VGA_HOSE)	+= console.o
 obj-$(CONFIG_SMP)	+= smp.o
arch/alpha/kernel/sys.c new file +36 -0
new file mode 100644
index 0000000..3dc454f
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/prctl.h>
+#include <linux/thread_info.h>
+#include <linux/uaccess.h>
+
+int arch_set_unalign_ctl(unsigned int val)
+{
+	__u32 status = current_thread_info()->status & ~UAC_BITMASK;
+
+	if (val & PR_UNALIGN_NOPRINT)
+		status |= TS_UAC_NOPRINT;
+	if (val & PR_UNALIGN_SIGBUS)
+		status |= TS_UAC_SIGBUS;
+	if (val & 4)	/* alpha-specific */
+		status |= TS_UAC_NOFIX;
+
+	current_thread_info()->status = status;
+
+	return 0;
+}
+
+int arch_get_unalign_ctl(void)
+{
+	__u32 status = current_thread_info()->status & ~UAC_BITMASK;
+	int res = 0;
+
+	if (status & TS_UAC_NOPRINT)
+		res |= PR_UNALIGN_NOPRINT;
+	if (status & TS_UAC_SIGBUS)
+		res |= PR_UNALIGN_SIGBUS;
+	if (status & TS_UAC_NOFIX)
+		res |= 4;
+
+	return res;
+}
arch/ia64/Kconfig +1 -0
index a673dd7..ab62a57 100644
@@ -55,6 +55,7 @@ config IA64
 	select ARCH_USE_CMPXCHG_LOCKREF
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_PRCTL_ARCH
+	select HAVE_ARCH_PR_SET_GET_UNALIGN
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/processor.h +0 -12
index 8d5184f..49f4ef9 100644
@@ -247,18 +247,6 @@ typedef struct {
 	unsigned long seg;
 } mm_segment_t;
 
-#define SET_UNALIGN_CTL(value)								\
-({												\
-	current->thread.flags = ((current->thread.flags & ~IA64_THREAD_UAC_MASK)			\
-				| (((value) << IA64_THREAD_UAC_SHIFT) & IA64_THREAD_UAC_MASK));	\
-	0;											\
-})
-#define GET_UNALIGN_CTL(addr)								\
-({												\
-	put_user((current->thread.flags & IA64_THREAD_UAC_MASK) >> IA64_THREAD_UAC_SHIFT,	\
-		 (int __user *) (addr));							\
-})
-
 struct thread_struct {
 	__u32 flags;			/* various thread flags (see IA64_THREAD_*) */
 	/* writing on_ustack is performance-critical, so it's worth spending 8 bits on it... */
arch/ia64/kernel/sys_ia64.c +15 -0
index d996585..2c2fd65 100644
@@ -206,3 +206,18 @@ int prctl_arch(int option, unsigned long arg2, unsigned long arg3,
 		return -EINVAL;
 	}
 }
+
+int arch_set_unalign_ctl(unsigned int val)
+{
+	current->thread.flags &= ~IA64_THREAD_UAC_MASK;
+	current->thread.flags |= (val << IA64_THREAD_UAC_SHIFT) &
+		IA64_THREAD_UAC_MASK;
+
+	return 0;
+}
+
+int arch_get_unalign_ctl(void)
+{
+	return (current->thread.flags & IA64_THREAD_UAC_MASK) >>
+		IA64_THREAD_UAC_SHIFT;
+}
arch/parisc/Kconfig +1 -0
index fc5a574..a2f0f0a 100644
@@ -44,6 +44,7 @@ config PARISC
 	select HAVE_DEBUG_STACKOVERFLOW
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_HASH
+	select HAVE_ARCH_PR_SET_GET_UNALIGN
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select GENERIC_SCHED_CLOCK
arch/parisc/include/asm/processor.h +0 -14
index b59720f..dbea6e9 100644
@@ -139,20 +139,6 @@ struct thread_struct {
 #define PARISC_UAC_SHIFT	0
 #define PARISC_UAC_MASK		(PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
 
-#define SET_UNALIGN_CTL(value)                                            \
-        ({                                                                \
-        current->thread.flags = ((current->thread.flags & ~PARISC_UAC_MASK) \
-                                | (((value) << PARISC_UAC_SHIFT) &        \
-                                   PARISC_UAC_MASK));                     \
-        0;                                                                \
-        })
-
-#define GET_UNALIGN_CTL(addr)                                             \
-        ({                                                                \
-        put_user((current->thread.flags & PARISC_UAC_MASK)                \
-                 >> PARISC_UAC_SHIFT, (int __user *) (addr));             \
-        })
-
 #define INIT_THREAD { \
 	.regs = {	.gr	= { 0, }, \
 			.fr	= { 0, }, \
arch/parisc/kernel/sys_parisc.c +15 -0
index 43b308c..e3a7f29 100644
@@ -30,6 +30,7 @@
 #include <linux/linkage.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
+#include <linux/prctl.h>
 #include <linux/sched/signal.h>
 #include <linux/sched/mm.h>
 #include <linux/shm.h>
@@ -37,6 +38,7 @@
 #include <linux/utsname.h>
 #include <linux/personality.h>
 #include <linux/random.h>
+#include <asm/processor.h>
 
 /* we construct an artificial offset for the mapping based on the physical
  * address of the kernel mapping variable */
@@ -391,3 +393,16 @@ long parisc_personality(unsigned long personality)
 
 	return err;
 }
+
+int arch_set_unalign_ctl(unsigned int val)
+{
+	current->thread.flags &= ~PARISC_UAC_MASK;
+	current->thread.flags |= (val << PARISC_UAC_SHIFT) & PARISC_UAC_MASK;
+
+	return 0;
+}
+
+int arch_get_unalign_ctl(void)
+{
+	return (current->thread.flags & PARISC_UAC_MASK) >> PARISC_UAC_SHIFT;
+}
arch/powerpc/Kconfig +1 -0
index b94323e..68c31fb 100644
@@ -181,6 +181,7 @@ config PPC
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS	if COMPAT
+	select HAVE_ARCH_PR_SET_GET_UNALIGN
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_CBPF_JIT			if !PPC64
arch/powerpc/include/asm/processor.h +0 -6
index b8d9306..8bac2f6 100644
@@ -413,12 +413,6 @@ extern int set_fpexc_mode(unsigned int val);
 extern int get_endian(unsigned long adr);
 extern int set_endian(unsigned int val);
 
-#define GET_UNALIGN_CTL(adr)	get_unalign_ctl((adr))
-#define SET_UNALIGN_CTL(val)	set_unalign_ctl((val))
-
-extern int get_unalign_ctl(unsigned long adr);
-extern int set_unalign_ctl(unsigned int val);
-
 extern void load_fp_state(struct thread_fp_state *fp);
 extern void store_fp_state(struct thread_fp_state *fp);
 extern void load_vr_state(struct thread_vr_state *vr);
arch/powerpc/kernel/process.c +3 -3
index 17708b7..a623373 100644
@@ -2020,15 +2020,15 @@ int get_endian(unsigned long adr)
 	return put_user(val, (unsigned int __user *)adr);
 }
 
-int set_unalign_ctl(unsigned int val)
+int arch_set_unalign_ctl(unsigned int val)
 {
 	current->thread.align_ctl = val;
 	return 0;
 }
 
-int get_unalign_ctl(unsigned long adr)
+int arch_get_unalign_ctl(void)
 {
-	return put_user(current->thread.align_ctl, (unsigned int __user *)adr);
+	return current->thread.align_ctl;
 }
 
 static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
arch/sh/Kconfig +1 -0
index 97fe293..f9631bf 100644
@@ -48,6 +48,7 @@ config SUPERH
 	select OLD_SIGSUSPEND
 	select OLD_SIGACTION
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_PR_SET_GET_UNALIGN
 	select HAVE_FUTEX_CMPXCHG if FUTEX
 	select HAVE_NMI
 	help
arch/sh/include/asm/processor.h +0 -7
index ce3d9f6..ff4d332 100644
@@ -116,13 +116,6 @@ extern unsigned int xstate_size;
 extern void free_thread_xstate(struct task_struct *);
 extern struct kmem_cache *task_xstate_cachep;
 
-/* arch/sh/mm/alignment.c */
-extern int get_unalign_ctl(unsigned long addr);
-extern int set_unalign_ctl(unsigned int val);
-
-#define GET_UNALIGN_CTL(addr)	get_unalign_ctl((addr))
-#define SET_UNALIGN_CTL(val)	set_unalign_ctl((val))
-
 /* arch/sh/mm/init.c */
 extern unsigned int mem_init_done;
 
arch/sh/mm/alignment.c +4 -4
index bad2a31..63fc963 100644
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/seq_file.h>
+#include <linux/prctl.h>
 #include <linux/proc_fs.h>
 #include <linux/uaccess.h>
 #include <linux/ratelimit.h>
@@ -80,13 +81,12 @@ unsigned int unaligned_user_action(void)
 	return action;
 }
 
-int get_unalign_ctl(unsigned long addr)
+int arch_get_unalign_ctl(void)
 {
-	return put_user(current->thread.flags & SH_THREAD_UAC_MASK,
-			(unsigned int __user *)addr);
+	return current->thread.flags & SH_THREAD_UAC_MASK;
 }
 
-int set_unalign_ctl(unsigned int val)
+int arch_set_unalign_ctl(unsigned int val)
 {
 	current->thread.flags = (current->thread.flags & ~SH_THREAD_UAC_MASK) |
 				(val & SH_THREAD_UAC_MASK);
include/linux/prctl.h +8 -0
index 5ce3713..abc803e 100644
@@ -16,4 +16,12 @@ static inline int prctl_arch(int option, unsigned long arg2,
 }
 #endif
 
+#ifdef CONFIG_HAVE_ARCH_PR_SET_GET_UNALIGN
+extern int arch_set_unalign_ctl(unsigned int val);
+extern int arch_get_unalign_ctl(void);
+#else
+static inline int arch_set_unalign_ctl(unsigned int val) { return -EINVAL; }
+static inline int arch_get_unalign_ctl(void) { return -EINVAL; }
+#endif
+
 #endif /* ! _LINUX_PRCTL_H */
kernel/sys.c +10 -10
index 47cf999..562ffbe 100644
@@ -71,13 +71,6 @@
 
 #include "uid16.h"
 
-#ifndef SET_UNALIGN_CTL
-# define SET_UNALIGN_CTL(a)	(-EINVAL)
-#endif
-#ifndef GET_UNALIGN_CTL
-# define GET_UNALIGN_CTL(a)	(-EINVAL)
-#endif
-
 /*
  * this is where the system-wide overflow UID and GID are defined, for
  * architectures that now have 32-bit UID/GID but didn't in the past
@@ -2235,10 +2228,17 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		break;
 
 	case PR_SET_UNALIGN:
-		error = SET_UNALIGN_CTL(arg2);
+		error = arch_set_unalign_ctl(arg2);
 		break;
-	case PR_GET_UNALIGN:
-		error = GET_UNALIGN_CTL(arg2);
+	case PR_GET_UNALIGN: {
+		int res;
+
+		res = arch_get_unalign_ctl();
+		if (res >= 0)
+			error = put_user(res, (int __user *)arg2);
+		else
+			error = res;
+		}
 		break;
 	case PR_GET_TIMING:
 		error = PR_TIMING_STATISTICAL;
Signature · 1 line
2.1.4
#16 lore raw
In reply to Dave Martin
Quoted 9 lines · Dave Martin

[Reviewer note: this is a cross-arch series. To reduce spam, I have tried not to Cc people on patches they aren't likely to care about. The complete series can be found in the LKML or linux-arch archives.]

The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now.

This is a nice clean-up series, thanks! Some thoughts/comments below...

Quoted 11 lines

This series attempts to modernise the code by defining a couple of new Kconfig variables HAVE_PRCTL_ARCH and HAVE_ARCH_PR_SET_GET_UNALIGN to allow architectures to provide hooks for arch-dependent prctls.

For now this series has had minimal testing: some basic testing of arch-specific prctls using PR_SVE_SET_VL on arm64; build-tested on x86; otherwise untested.

This is not polished yet... but I'm interested to know what people think about the approach.

I'm not entirely convinced the removal of the "task not current" interface is very useful as I've found myself needing to adjust other interfaces like this to _add_ the "task not current" logic, but ... I can't really argue very hard for keeping the task args since nothing is using them... meh.

I dislike this being named "prctl_arch" when everything else like this is "arch_foo...", but I do see the collision with the x86-specific "arch_prctl" syscall. Perhaps it might be better to wire things up differently, since x86's arch_prctl is actually "sys_arch_prctl" so I don't think there would be a symbol collision, and maybe the 9 options could be added to the global prctl list, with the x86 syscall getting called at the end of the new "arch_prctl"? Then the syscall could get deprecated in favor of just using prctl directly?

Your new x86 arch_prctl (neé prctl_arch) could be something like:

int arch_prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
... existing stuff in your series ...

    case ARCH_SET_GS:
    case ARCH_SET_FS:
    case ARCH_GET_GS:
    case ARCH_GET_FS:
    case ARCH_MAP_VDSO_X32:
    case ARCH_MAP_VDSO_32:
    case ARCH_MAP_VDSO_64:
        if (arg3 || arg4 || arg5)
            return -EINVAL;
        return do_arch_prctl_64(current, option, arg2);
    case ARCH_GET_CPUID:
    case ARCH_SET_CPUID:
        if (arg3 || arg4 || arg5)
            return -EINVAL;
        return do_arch_prctl_common(current, option, arg2);
    default:
        return -EINVAL;
    }
}

Or maybe all the logic could get ripped out of arch/x86/kernel/process*.c and put in arch/x86/kernel/sys.c directly?

Perhaps this is all overkill, but I find it rather annoying that one arch's weird syscall would block "expected" naming of a cross-arch interface...

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#17 lore raw
Quoted 22 lines · Kees Cook
Quoted 9 lines · Dave Martin

[Reviewer note: this is a cross-arch series. To reduce spam, I have tried not to Cc people on patches they aren't likely to care about. The complete series can be found in the LKML or linux-arch archives.]

The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now.

This is a nice clean-up series, thanks! Some thoughts/comments below...

Quoted 9 lines

This series attempts to modernise the code by defining a couple of new Kconfig variables HAVE_PRCTL_ARCH and HAVE_ARCH_PR_SET_GET_UNALIGN to allow architectures to provide hooks for arch-dependent prctls.

For now this series has had minimal testing: some basic testing of arch-specific prctls using PR_SVE_SET_VL on arm64; build-tested on x86; otherwise untested.

Quoted 8 lines
Quoted 2 lines

This is not polished yet... but I'm interested to know what people think about the approach.

I'm not entirely convinced the removal of the "task not current" interface is very useful as I've found myself needing to adjust other interfaces like this to _add_ the "task not current" logic, but ... I can't really argue very hard for keeping the task args since nothing is using them... meh.

For operations that are shared with ptrace it does make sense to have a task argument, but in the end I found it equally natural to put that only in the backend rather than having it invoked directly with an explicit argument by the prctl demux.

In the case of PR_SVE_SET_VL the interface has to be massaged in different ways depending on whether it's being invokved via prctl or ptrace anyway, so I guess there was no temptation to keep the task argument on the prctl side in this case.

Ptrace differs from prctl in that in the former case we can assume the task is stopped and in the latter we can't. This results in some conditional local_bh_disable()..local_bh_enable() in sve_set_vector_length(), which is a bit gross. Maybe it's best not to encourage ptrace and prctl to be given the same backend functions without thinking about it.

(See the different callers of sve_set_vector_length() under arch/arm64/.)

Others' views may differ though, so I'm happy to be overruled on this if people object.

Quoted 3 lines

I dislike this being named "prctl_arch" when everything else like this is "arch_foo...", but I do see the collision with the x86-specific "arch_prctl" syscall. Perhaps it might be better to wire things up

Agreed. Actually, it was originally called arch_prctl(), until I discovered that it broke um. x86 seems happy enough, since its existing arch_prctl() functions all have do_/sys_/etc. prefixes.

Quoted 23 lines

differently, since x86's arch_prctl is actually "sys_arch_prctl" so I don't think there would be a symbol collision, and maybe the 9 options could be added to the global prctl list, with the x86 syscall getting called at the end of the new "arch_prctl"? Then the syscall could get deprecated in favor of just using prctl directly?

Your new x86 arch_prctl (neé prctl_arch) could be something like:

int arch_prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
... existing stuff in your series ...

    case ARCH_SET_GS:
    case ARCH_SET_FS:
    case ARCH_GET_GS:
    case ARCH_GET_FS:
    case ARCH_MAP_VDSO_X32:
    case ARCH_MAP_VDSO_32:
    case ARCH_MAP_VDSO_64:
        if (arg3 || arg4 || arg5)
            return -EINVAL;
        return do_arch_prctl_64(current, option, arg2);
    case ARCH_GET_CPUID:
Quoted 8 lines
    case ARCH_SET_CPUID:
        if (arg3 || arg4 || arg5)
            return -EINVAL;
        return do_arch_prctl_common(current, option, arg2);
    default:
        return -EINVAL;
    }
}

So, you mean we merge x86's arch_prctl() syscall with the generic one, and have both syscalls from userland invoke the common backend?

That does look kind of feasible, given the compatible ABI and the fact that there does not appear to be a namespace clash in the option values.

Quoted 6 lines

Or maybe all the logic could get ripped out of arch/x86/kernel/process*.c and put in arch/x86/kernel/sys.c directly?

Perhaps this is all overkill, but I find it rather annoying that one arch's weird syscall would block "expected" naming of a cross-arch interface...

I didn't really like overloading the name "arch_prctl" at all, since this is established as the name of the existing x86 syscall. Even if we arrange things in the kernel so that there is no linkage namespace clash, there seemed to be high risk of confusion.

If we can merge the two (as suggested above) then that might be acceptable, but I wasn't confident that there were no subtle gotchas with such an approach...

Thoughts?

Cheers
---Dave