linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/16] MSA vector context signal handling & HWCAPs
@ 2015-07-10 15:00 Paul Burton
  2015-07-10 15:00 ` [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h Paul Burton
                   ` (15 more replies)
  0 siblings, 16 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin,
	Zubair Lutfullah Kakakhel, James Hogan, Daniel Borkmann,
	Huacai Chen, Maciej W. Rozycki, Alex Smith, Michal Nazarewicz,
	Maciej W. Rozycki, Markos Chandras, Frederic Weisbecker,
	Ralf Baechle, Andrew Morton, Peter Zijlstra, Andy Lutomirski,
	Manuel Lauss, Kees Cook, Michael Ellerman, linux-kernel,
	Richard Weinberger, David Daney

This series provides the final bits of support for MSA as far as
userland that isn't a debugger goes. In order to preserve backwards
compatibility it saves the extended vector context after the end of the
sigframe or ucontext, at a fixed offset. A bit set in sigcontext's
sc_used_math field indicates to userland (and to the kernel on
sigreturn) that the extended context is present.

With these final bits in, the presence of MSA support is indicated via a
HWCAP bit that userland may check for.

Paul Burton (16):
  MIPS: remove outdated comments in sigcontext.h
  MIPS: simplify EVA FP context handling code
  MIPS: add offsets to sigcontext FP fields to struct mips_abi
  MIPS: use struct mips_abi offsets to save FP context
  MIPS: move FP usage checks into protected_{save,restore}_fp_context
  MIPS: skip odd double FP registers when copying FP32 sigcontext
  MIPS: use common FP sigcontext code for O32 compat
  MIPS: remove unused {get,put}_sigset functions
  MIPS: indicate FP mode in sigcontext sc_used_math
  MIPS: add definitions for extended context
  MIPS: save MSA extended context around signals
  MIPS: AT_HWCAP aux vector infrastructure
  MIPS: advertise MIPSr6 via HWCAP when appropriate
  MIPS: advertise MSA support via HWCAP when present
  MIPS: require O32 FP64 support for MIPS64 with O32 compat
  MIPS: drop EXPERIMENTAL tag from O32+FP64 & MSA

 arch/mips/Kconfig                       |   5 +-
 arch/mips/include/asm/Kbuild            |   1 -
 arch/mips/include/asm/abi.h             |   4 +
 arch/mips/include/asm/elf.h             |   4 +-
 arch/mips/include/asm/signal.h          |   3 +
 arch/mips/include/uapi/asm/hwcap.h      |   8 +
 arch/mips/include/uapi/asm/sigcontext.h |  19 +-
 arch/mips/include/uapi/asm/ucontext.h   |  65 +++++
 arch/mips/kernel/asm-offsets.c          |  11 -
 arch/mips/kernel/cpu-probe.c            |   7 +
 arch/mips/kernel/r4k_fpu.S              | 372 +++++++++++++-------------
 arch/mips/kernel/signal-common.h        |   9 +
 arch/mips/kernel/signal.c               | 446 ++++++++++++++++++++++++--------
 arch/mips/kernel/signal32.c             | 207 +--------------
 arch/mips/kernel/signal_n32.c           |   6 +-
 15 files changed, 666 insertions(+), 501 deletions(-)
 create mode 100644 arch/mips/include/uapi/asm/hwcap.h
 create mode 100644 arch/mips/include/uapi/asm/ucontext.h

-- 
2.4.4


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

* [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-14 13:56   ` Ralf Baechle
  2015-07-10 15:00 ` [PATCH 02/16] MIPS: simplify EVA FP context handling code Paul Burton
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips; +Cc: Matthew Fortune, Paul Burton, Ralf Baechle, linux-kernel

The offsets to various fields within struct sigcontext are declared
using asm-offsets.c these days, so drop the outdated comment that talks
about keeping in sync with a no longer present file.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/uapi/asm/sigcontext.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/mips/include/uapi/asm/sigcontext.h b/arch/mips/include/uapi/asm/sigcontext.h
index 6c9906f..ae78902 100644
--- a/arch/mips/include/uapi/asm/sigcontext.h
+++ b/arch/mips/include/uapi/asm/sigcontext.h
@@ -14,10 +14,6 @@
 
 #if _MIPS_SIM == _MIPS_SIM_ABI32
 
-/*
- * Keep this struct definition in sync with the sigcontext fragment
- * in arch/mips/tools/offset.c
- */
 struct sigcontext {
 	unsigned int		sc_regmask;	/* Unused */
 	unsigned int		sc_status;	/* Unused */
@@ -45,9 +41,6 @@ struct sigcontext {
 
 #include <linux/posix_types.h>
 /*
- * Keep this struct definition in sync with the sigcontext fragment
- * in arch/mips/tools/offset.c
- *
  * Warning: this structure illdefined with sc_badvaddr being just an unsigned
  * int so it was changed to unsigned long in 2.6.0-test1.  This may break
  * binary compatibility - no prisoners.
-- 
2.4.4


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

* [PATCH 02/16] MIPS: simplify EVA FP context handling code
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
  2015-07-10 15:00 ` [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 03/16] MIPS: add offsets to sigcontext FP fields to struct mips_abi Paul Burton
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Markos Chandras,
	Richard Weinberger, linux-kernel, Maciej W. Rozycki,
	Andy Lutomirski, Ralf Baechle, Andrew Morton

The protected_{save,restore}_fp_context functions had effectively
different implementations for EVA. Simplify & unify the code somewhat
such that EVA configurations simply guarantee the FPU-not-owned path
through the standard code path.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: Markos Chandras <markos.chandras@imgtec.com>
---

 arch/mips/kernel/signal.c | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 6a28c79..796c7d8 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -101,7 +101,14 @@ static int copy_fp_from_sigcontext(struct sigcontext __user *sc)
 static int protected_save_fp_context(struct sigcontext __user *sc)
 {
 	int err;
-#ifndef CONFIG_EVA
+
+	/*
+	 * EVA does not have userland equivalents of ldc1 or sdc1, so
+	 * save to the kernel FP context & copy that to userland below.
+	 */
+	if (config_enabled(CONFIG_EVA))
+		lose_fpu(1);
+
 	while (1) {
 		lock_fpu_owner();
 		if (is_fpu_owner()) {
@@ -120,21 +127,22 @@ static int protected_save_fp_context(struct sigcontext __user *sc)
 		if (err)
 			break;	/* really bad sigcontext */
 	}
-#else
-	/*
-	 * EVA does not have FPU EVA instructions so saving fpu context directly
-	 * does not work.
-	 */
-	lose_fpu(1);
-	err = save_fp_context(sc); /* this might fail */
-#endif
+
 	return err;
 }
 
 static int protected_restore_fp_context(struct sigcontext __user *sc)
 {
 	int err, tmp __maybe_unused;
-#ifndef CONFIG_EVA
+
+	/*
+	 * EVA does not have userland equivalents of ldc1 or sdc1, so we
+	 * disable the FPU here such that the code below simply copies to
+	 * the kernel FP context.
+	 */
+	if (config_enabled(CONFIG_EVA))
+		lose_fpu(0);
+
 	while (1) {
 		lock_fpu_owner();
 		if (is_fpu_owner()) {
@@ -153,14 +161,7 @@ static int protected_restore_fp_context(struct sigcontext __user *sc)
 		if (err)
 			break;	/* really bad sigcontext */
 	}
-#else
-	/*
-	 * EVA does not have FPU EVA instructions so restoring fpu context
-	 * directly does not work.
-	 */
-	lose_fpu(0);
-	err = restore_fp_context(sc); /* this might fail */
-#endif
+
 	return err;
 }
 
@@ -629,7 +630,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
 }
 
 #ifdef CONFIG_SMP
-#ifndef CONFIG_EVA
 static int smp_save_fp_context(struct sigcontext __user *sc)
 {
 	return raw_cpu_has_fpu
@@ -643,12 +643,10 @@ static int smp_restore_fp_context(struct sigcontext __user *sc)
 	       ? _restore_fp_context(sc)
 	       : copy_fp_from_sigcontext(sc);
 }
-#endif /* CONFIG_EVA */
 #endif
 
 static int signal_setup(void)
 {
-#ifndef CONFIG_EVA
 #ifdef CONFIG_SMP
 	/* For now just do the cpu_has_fpu check when the functions are invoked */
 	save_fp_context = smp_save_fp_context;
@@ -662,10 +660,6 @@ static int signal_setup(void)
 		restore_fp_context = copy_fp_from_sigcontext;
 	}
 #endif /* CONFIG_SMP */
-#else
-	save_fp_context = copy_fp_to_sigcontext;
-	restore_fp_context = copy_fp_from_sigcontext;
-#endif
 
 	return 0;
 }
-- 
2.4.4


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

* [PATCH 03/16] MIPS: add offsets to sigcontext FP fields to struct mips_abi
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
  2015-07-10 15:00 ` [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h Paul Burton
  2015-07-10 15:00 ` [PATCH 02/16] MIPS: simplify EVA FP context handling code Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context Paul Burton
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Michael Ellerman, linux-kernel,
	Richard Weinberger, James Hogan, Andy Lutomirski, Ralf Baechle,
	Maciej W. Rozycki, Andrew Morton

Add fields to struct mips_abi, which holds information regarding the
kernel-userland ABI regarding signals, to specify the offsets to the FP
related fields within the appropriate variant of struct sigcontext.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/asm/abi.h   | 4 ++++
 arch/mips/kernel/signal.c     | 6 +++++-
 arch/mips/kernel/signal32.c   | 6 +++++-
 arch/mips/kernel/signal_n32.c | 6 +++++-
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/mips/include/asm/abi.h b/arch/mips/include/asm/abi.h
index 7186bb5..37f8407 100644
--- a/arch/mips/include/asm/abi.h
+++ b/arch/mips/include/asm/abi.h
@@ -20,6 +20,10 @@ struct mips_abi {
 				     struct pt_regs *regs, sigset_t *set);
 	const unsigned long	rt_signal_return_offset;
 	const unsigned long	restart;
+
+	unsigned	off_sc_fpregs;
+	unsigned	off_sc_fpc_csr;
+	unsigned	off_sc_used_math;
 };
 
 #endif /* _ASM_ABI_H */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 796c7d8..ddf8318 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -521,7 +521,11 @@ struct mips_abi mips_abi = {
 	.setup_rt_frame = setup_rt_frame,
 	.rt_signal_return_offset =
 		offsetof(struct mips_vdso, rt_signal_trampoline),
-	.restart	= __NR_restart_syscall
+	.restart	= __NR_restart_syscall,
+
+	.off_sc_fpregs = offsetof(struct sigcontext, sc_fpregs),
+	.off_sc_fpc_csr = offsetof(struct sigcontext, sc_fpc_csr),
+	.off_sc_used_math = offsetof(struct sigcontext, sc_used_math),
 };
 
 static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 19a7705..6b65658 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -587,7 +587,11 @@ struct mips_abi mips_abi_32 = {
 	.setup_rt_frame = setup_rt_frame_32,
 	.rt_signal_return_offset =
 		offsetof(struct mips_vdso, o32_rt_signal_trampoline),
-	.restart	= __NR_O32_restart_syscall
+	.restart	= __NR_O32_restart_syscall,
+
+	.off_sc_fpregs = offsetof(struct sigcontext32, sc_fpregs),
+	.off_sc_fpc_csr = offsetof(struct sigcontext32, sc_fpc_csr),
+	.off_sc_used_math = offsetof(struct sigcontext32, sc_used_math),
 };
 
 static int signal32_init(void)
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index f1d4751..0d017fd 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -153,5 +153,9 @@ struct mips_abi mips_abi_n32 = {
 	.setup_rt_frame = setup_rt_frame_n32,
 	.rt_signal_return_offset =
 		offsetof(struct mips_vdso, n32_rt_signal_trampoline),
-	.restart	= __NR_N32_restart_syscall
+	.restart	= __NR_N32_restart_syscall,
+
+	.off_sc_fpregs = offsetof(struct sigcontext, sc_fpregs),
+	.off_sc_fpc_csr = offsetof(struct sigcontext, sc_fpc_csr),
+	.off_sc_used_math = offsetof(struct sigcontext, sc_used_math),
 };
-- 
2.4.4


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

* [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (2 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 03/16] MIPS: add offsets to sigcontext FP fields to struct mips_abi Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-19  0:21   ` Paul Gortmaker
  2015-07-10 15:00 ` [PATCH 05/16] MIPS: move FP usage checks into protected_{save,restore}_fp_context Paul Burton
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin, Michael Ellerman,
	linux-kernel, Richard Weinberger, James Hogan, Andy Lutomirski,
	Markos Chandras, Ralf Baechle, Manuel Lauss, Maciej W. Rozycki

When saving FP state to struct sigcontext, make use of the offsets
provided by struct mips_abi to obtain appropriate addresses for the
sc_fpregs & sc_fpc_csr fields of the sigcontext. This is done only for
the native struct sigcontext in this patch (ie. for O32 in CONFIG_32BIT
kernels or for N64 in CONFIG_64BIT kernels) but is done in preparation
for sharing this code with compat ABIs in further patches.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/r4k_fpu.S       | 151 +++++++++++++++++++++------------------
 arch/mips/kernel/signal-common.h |   6 ++
 arch/mips/kernel/signal.c        |  85 +++++++++++++++-------
 3 files changed, 145 insertions(+), 97 deletions(-)

diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index 1d88af2..9e2d18d 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -35,6 +35,14 @@
 
 	.set	noreorder
 
+/**
+ * _save_fp_context() - save FP context from the FPU
+ * @a0 - pointer to fpregs field of sigcontext
+ * @a1 - pointer to fpc_csr field of sigcontext
+ *
+ * Save FP context, including the 32 FP data registers and the FP
+ * control & status register, from the FPU to signal context.
+ */
 LEAF(_save_fp_context)
 	.set	push
 	SET_HARDFLOAT
@@ -54,45 +62,45 @@ LEAF(_save_fp_context)
 	 nop
 #endif
 	/* Store the 16 odd double precision registers */
-	EX	sdc1 $f1, SC_FPREGS+8(a0)
-	EX	sdc1 $f3, SC_FPREGS+24(a0)
-	EX	sdc1 $f5, SC_FPREGS+40(a0)
-	EX	sdc1 $f7, SC_FPREGS+56(a0)
-	EX	sdc1 $f9, SC_FPREGS+72(a0)
-	EX	sdc1 $f11, SC_FPREGS+88(a0)
-	EX	sdc1 $f13, SC_FPREGS+104(a0)
-	EX	sdc1 $f15, SC_FPREGS+120(a0)
-	EX	sdc1 $f17, SC_FPREGS+136(a0)
-	EX	sdc1 $f19, SC_FPREGS+152(a0)
-	EX	sdc1 $f21, SC_FPREGS+168(a0)
-	EX	sdc1 $f23, SC_FPREGS+184(a0)
-	EX	sdc1 $f25, SC_FPREGS+200(a0)
-	EX	sdc1 $f27, SC_FPREGS+216(a0)
-	EX	sdc1 $f29, SC_FPREGS+232(a0)
-	EX	sdc1 $f31, SC_FPREGS+248(a0)
+	EX	sdc1 $f1, 8(a0)
+	EX	sdc1 $f3, 24(a0)
+	EX	sdc1 $f5, 40(a0)
+	EX	sdc1 $f7, 56(a0)
+	EX	sdc1 $f9, 72(a0)
+	EX	sdc1 $f11, 88(a0)
+	EX	sdc1 $f13, 104(a0)
+	EX	sdc1 $f15, 120(a0)
+	EX	sdc1 $f17, 136(a0)
+	EX	sdc1 $f19, 152(a0)
+	EX	sdc1 $f21, 168(a0)
+	EX	sdc1 $f23, 184(a0)
+	EX	sdc1 $f25, 200(a0)
+	EX	sdc1 $f27, 216(a0)
+	EX	sdc1 $f29, 232(a0)
+	EX	sdc1 $f31, 248(a0)
 1:	.set	pop
 #endif
 
 	.set push
 	SET_HARDFLOAT
 	/* Store the 16 even double precision registers */
-	EX	sdc1 $f0, SC_FPREGS+0(a0)
-	EX	sdc1 $f2, SC_FPREGS+16(a0)
-	EX	sdc1 $f4, SC_FPREGS+32(a0)
-	EX	sdc1 $f6, SC_FPREGS+48(a0)
-	EX	sdc1 $f8, SC_FPREGS+64(a0)
-	EX	sdc1 $f10, SC_FPREGS+80(a0)
-	EX	sdc1 $f12, SC_FPREGS+96(a0)
-	EX	sdc1 $f14, SC_FPREGS+112(a0)
-	EX	sdc1 $f16, SC_FPREGS+128(a0)
-	EX	sdc1 $f18, SC_FPREGS+144(a0)
-	EX	sdc1 $f20, SC_FPREGS+160(a0)
-	EX	sdc1 $f22, SC_FPREGS+176(a0)
-	EX	sdc1 $f24, SC_FPREGS+192(a0)
-	EX	sdc1 $f26, SC_FPREGS+208(a0)
-	EX	sdc1 $f28, SC_FPREGS+224(a0)
-	EX	sdc1 $f30, SC_FPREGS+240(a0)
-	EX	sw t1, SC_FPC_CSR(a0)
+	EX	sdc1 $f0, 0(a0)
+	EX	sdc1 $f2, 16(a0)
+	EX	sdc1 $f4, 32(a0)
+	EX	sdc1 $f6, 48(a0)
+	EX	sdc1 $f8, 64(a0)
+	EX	sdc1 $f10, 80(a0)
+	EX	sdc1 $f12, 96(a0)
+	EX	sdc1 $f14, 112(a0)
+	EX	sdc1 $f16, 128(a0)
+	EX	sdc1 $f18, 144(a0)
+	EX	sdc1 $f20, 160(a0)
+	EX	sdc1 $f22, 176(a0)
+	EX	sdc1 $f24, 192(a0)
+	EX	sdc1 $f26, 208(a0)
+	EX	sdc1 $f28, 224(a0)
+	EX	sdc1 $f30, 240(a0)
+	EX	sw t1, 0(a1)
 	jr	ra
 	 li	v0, 0					# success
 	.set pop
@@ -158,13 +166,16 @@ LEAF(_save_fp_context32)
 	END(_save_fp_context32)
 #endif
 
-/*
- * Restore FPU state:
- *  - fp gp registers
- *  - cp1 status/control register
+/**
+ * _restore_fp_context() - restore FP context to the FPU
+ * @a0 - pointer to fpregs field of sigcontext
+ * @a1 - pointer to fpc_csr field of sigcontext
+ *
+ * Restore FP context, including the 32 FP data registers and the FP
+ * control & status register, from signal context to the FPU.
  */
 LEAF(_restore_fp_context)
-	EX	lw t1, SC_FPC_CSR(a0)
+	EX	lw t1, 0(a1)
 
 #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)  || \
 		defined(CONFIG_CPU_MIPS32_R6)
@@ -178,42 +189,42 @@ LEAF(_restore_fp_context)
 	bgez	t0, 1f			# skip loading odd if FR=0
 	 nop
 #endif
-	EX	ldc1 $f1, SC_FPREGS+8(a0)
-	EX	ldc1 $f3, SC_FPREGS+24(a0)
-	EX	ldc1 $f5, SC_FPREGS+40(a0)
-	EX	ldc1 $f7, SC_FPREGS+56(a0)
-	EX	ldc1 $f9, SC_FPREGS+72(a0)
-	EX	ldc1 $f11, SC_FPREGS+88(a0)
-	EX	ldc1 $f13, SC_FPREGS+104(a0)
-	EX	ldc1 $f15, SC_FPREGS+120(a0)
-	EX	ldc1 $f17, SC_FPREGS+136(a0)
-	EX	ldc1 $f19, SC_FPREGS+152(a0)
-	EX	ldc1 $f21, SC_FPREGS+168(a0)
-	EX	ldc1 $f23, SC_FPREGS+184(a0)
-	EX	ldc1 $f25, SC_FPREGS+200(a0)
-	EX	ldc1 $f27, SC_FPREGS+216(a0)
-	EX	ldc1 $f29, SC_FPREGS+232(a0)
-	EX	ldc1 $f31, SC_FPREGS+248(a0)
+	EX	ldc1 $f1, 8(a0)
+	EX	ldc1 $f3, 24(a0)
+	EX	ldc1 $f5, 40(a0)
+	EX	ldc1 $f7, 56(a0)
+	EX	ldc1 $f9, 72(a0)
+	EX	ldc1 $f11, 88(a0)
+	EX	ldc1 $f13, 104(a0)
+	EX	ldc1 $f15, 120(a0)
+	EX	ldc1 $f17, 136(a0)
+	EX	ldc1 $f19, 152(a0)
+	EX	ldc1 $f21, 168(a0)
+	EX	ldc1 $f23, 184(a0)
+	EX	ldc1 $f25, 200(a0)
+	EX	ldc1 $f27, 216(a0)
+	EX	ldc1 $f29, 232(a0)
+	EX	ldc1 $f31, 248(a0)
 1:	.set pop
 #endif
 	.set push
 	SET_HARDFLOAT
-	EX	ldc1 $f0, SC_FPREGS+0(a0)
-	EX	ldc1 $f2, SC_FPREGS+16(a0)
-	EX	ldc1 $f4, SC_FPREGS+32(a0)
-	EX	ldc1 $f6, SC_FPREGS+48(a0)
-	EX	ldc1 $f8, SC_FPREGS+64(a0)
-	EX	ldc1 $f10, SC_FPREGS+80(a0)
-	EX	ldc1 $f12, SC_FPREGS+96(a0)
-	EX	ldc1 $f14, SC_FPREGS+112(a0)
-	EX	ldc1 $f16, SC_FPREGS+128(a0)
-	EX	ldc1 $f18, SC_FPREGS+144(a0)
-	EX	ldc1 $f20, SC_FPREGS+160(a0)
-	EX	ldc1 $f22, SC_FPREGS+176(a0)
-	EX	ldc1 $f24, SC_FPREGS+192(a0)
-	EX	ldc1 $f26, SC_FPREGS+208(a0)
-	EX	ldc1 $f28, SC_FPREGS+224(a0)
-	EX	ldc1 $f30, SC_FPREGS+240(a0)
+	EX	ldc1 $f0, 0(a0)
+	EX	ldc1 $f2, 16(a0)
+	EX	ldc1 $f4, 32(a0)
+	EX	ldc1 $f6, 48(a0)
+	EX	ldc1 $f8, 64(a0)
+	EX	ldc1 $f10, 80(a0)
+	EX	ldc1 $f12, 96(a0)
+	EX	ldc1 $f14, 112(a0)
+	EX	ldc1 $f16, 128(a0)
+	EX	ldc1 $f18, 144(a0)
+	EX	ldc1 $f20, 160(a0)
+	EX	ldc1 $f22, 176(a0)
+	EX	ldc1 $f24, 192(a0)
+	EX	ldc1 $f26, 208(a0)
+	EX	ldc1 $f28, 224(a0)
+	EX	ldc1 $f30, 240(a0)
 	ctc1	t1, fcr31
 	.set pop
 	jr	ra
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 06805e0..d594695 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -36,4 +36,10 @@ extern int fpcsr_pending(unsigned int __user *fpcsr);
 #define unlock_fpu_owner()	pagefault_enable()
 #endif
 
+/* Assembly functions to move context to/from the FPU */
+extern asmlinkage int
+_save_fp_context(void __user *fpregs, void __user *csr);
+extern asmlinkage int
+_restore_fp_context(void __user *fpregs, void __user *csr);
+
 #endif	/* __SIGNAL_COMMON_H */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index ddf8318..10f7dbc 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -41,11 +41,8 @@
 
 #include "signal-common.h"
 
-static int (*save_fp_context)(struct sigcontext __user *sc);
-static int (*restore_fp_context)(struct sigcontext __user *sc);
-
-extern asmlinkage int _save_fp_context(struct sigcontext __user *sc);
-extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc);
+static int (*save_fp_context)(void __user *sc);
+static int (*restore_fp_context)(void __user *sc);
 
 struct sigframe {
 	u32 sf_ass[4];		/* argument save space for o32 */
@@ -65,41 +62,71 @@ struct rt_sigframe {
  * Thread saved context copy to/from a signal context presumed to be on the
  * user stack, and therefore accessed with appropriate macros from uaccess.h.
  */
-static int copy_fp_to_sigcontext(struct sigcontext __user *sc)
+static int copy_fp_to_sigcontext(void __user *sc)
 {
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int i;
 	int err = 0;
 
 	for (i = 0; i < NUM_FPU_REGS; i++) {
 		err |=
 		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
-			       &sc->sc_fpregs[i]);
+			       &fpregs[i]);
 	}
-	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
+	err |= __put_user(current->thread.fpu.fcr31, csr);
 
 	return err;
 }
 
-static int copy_fp_from_sigcontext(struct sigcontext __user *sc)
+static int copy_fp_from_sigcontext(void __user *sc)
 {
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int i;
 	int err = 0;
 	u64 fpr_val;
 
 	for (i = 0; i < NUM_FPU_REGS; i++) {
-		err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
+		err |= __get_user(fpr_val, &fpregs[i]);
 		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
 	}
-	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
+	err |= __get_user(current->thread.fpu.fcr31, csr);
 
 	return err;
 }
 
 /*
+ * Wrappers for the assembly _{save,restore}_fp_context functions.
+ */
+static int save_hw_fp_context(void __user *sc)
+{
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
+
+	return _save_fp_context(fpregs, csr);
+}
+
+static int restore_hw_fp_context(void __user *sc)
+{
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
+
+	return _restore_fp_context(fpregs, csr);
+}
+
+/*
  * Helper routines
  */
-static int protected_save_fp_context(struct sigcontext __user *sc)
+static int protected_save_fp_context(void __user *sc)
 {
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int err;
 
 	/*
@@ -121,9 +148,9 @@ static int protected_save_fp_context(struct sigcontext __user *sc)
 		if (likely(!err))
 			break;
 		/* touch the sigcontext and try again */
-		err = __put_user(0, &sc->sc_fpregs[0]) |
-			__put_user(0, &sc->sc_fpregs[31]) |
-			__put_user(0, &sc->sc_fpc_csr);
+		err = __put_user(0, &fpregs[0]) |
+			__put_user(0, &fpregs[31]) |
+			__put_user(0, csr);
 		if (err)
 			break;	/* really bad sigcontext */
 	}
@@ -131,8 +158,11 @@ static int protected_save_fp_context(struct sigcontext __user *sc)
 	return err;
 }
 
-static int protected_restore_fp_context(struct sigcontext __user *sc)
+static int protected_restore_fp_context(void __user *sc)
 {
+	struct mips_abi *abi = current->thread.abi;
+	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
+	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int err, tmp __maybe_unused;
 
 	/*
@@ -155,9 +185,9 @@ static int protected_restore_fp_context(struct sigcontext __user *sc)
 		if (likely(!err))
 			break;
 		/* touch the sigcontext and try again */
-		err = __get_user(tmp, &sc->sc_fpregs[0]) |
-			__get_user(tmp, &sc->sc_fpregs[31]) |
-			__get_user(tmp, &sc->sc_fpc_csr);
+		err = __get_user(tmp, &fpregs[0]) |
+			__get_user(tmp, &fpregs[31]) |
+			__get_user(tmp, csr);
 		if (err)
 			break;	/* really bad sigcontext */
 	}
@@ -225,11 +255,12 @@ int fpcsr_pending(unsigned int __user *fpcsr)
 }
 
 static int
-check_and_restore_fp_context(struct sigcontext __user *sc)
+check_and_restore_fp_context(void __user *sc)
 {
+	struct mips_abi *abi = current->thread.abi;
 	int err, sig;
 
-	err = sig = fpcsr_pending(&sc->sc_fpc_csr);
+	err = sig = fpcsr_pending(sc + abi->off_sc_fpc_csr);
 	if (err > 0)
 		err = 0;
 	err |= protected_restore_fp_context(sc);
@@ -634,17 +665,17 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
 }
 
 #ifdef CONFIG_SMP
-static int smp_save_fp_context(struct sigcontext __user *sc)
+static int smp_save_fp_context(void __user *sc)
 {
 	return raw_cpu_has_fpu
-	       ? _save_fp_context(sc)
+	       ? save_hw_fp_context(sc)
 	       : copy_fp_to_sigcontext(sc);
 }
 
-static int smp_restore_fp_context(struct sigcontext __user *sc)
+static int smp_restore_fp_context(void __user *sc)
 {
 	return raw_cpu_has_fpu
-	       ? _restore_fp_context(sc)
+	       ? restore_hw_fp_context(sc)
 	       : copy_fp_from_sigcontext(sc);
 }
 #endif
@@ -657,8 +688,8 @@ static int signal_setup(void)
 	restore_fp_context = smp_restore_fp_context;
 #else
 	if (cpu_has_fpu) {
-		save_fp_context = _save_fp_context;
-		restore_fp_context = _restore_fp_context;
+		save_fp_context = save_hw_fp_context;
+		restore_fp_context = restore_hw_fp_context;
 	} else {
 		save_fp_context = copy_fp_to_sigcontext;
 		restore_fp_context = copy_fp_from_sigcontext;
-- 
2.4.4


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

* [PATCH 05/16] MIPS: move FP usage checks into protected_{save,restore}_fp_context
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (3 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 06/16] MIPS: skip odd double FP registers when copying FP32 sigcontext Paul Burton
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Michael Ellerman, linux-kernel,
	Richard Weinberger, Andy Lutomirski, Ralf Baechle,
	Maciej W. Rozycki

In preparation for sharing protected_{save,restore}_fp_context with
compat ABIs, move the FP usage checks into said functions. This will
both enable that code to be shared, and allow for extensions of it in
further patches to also be shared.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/signal.c | 73 ++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 39 deletions(-)

diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 10f7dbc..76f9136 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -127,8 +127,15 @@ static int protected_save_fp_context(void __user *sc)
 	struct mips_abi *abi = current->thread.abi;
 	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
 	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
+	uint32_t __user *used_math = sc + abi->off_sc_used_math;
+	unsigned int used;
 	int err;
 
+	used = !!used_math();
+	err = __put_user(used, used_math);
+	if (err || !used)
+		return err;
+
 	/*
 	 * EVA does not have userland equivalents of ldc1 or sdc1, so
 	 * save to the kernel FP context & copy that to userland below.
@@ -163,7 +170,25 @@ static int protected_restore_fp_context(void __user *sc)
 	struct mips_abi *abi = current->thread.abi;
 	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
 	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
-	int err, tmp __maybe_unused;
+	uint32_t __user *used_math = sc + abi->off_sc_used_math;
+	unsigned int used;
+	int err, sig, tmp __maybe_unused;
+
+	err = __get_user(used, used_math);
+	conditional_used_math(used);
+
+	/*
+	 * The signal handler may have used FPU; give it up if the program
+	 * doesn't want it following sigreturn.
+	 */
+	if (err || !used)
+		lose_fpu(0);
+	if (err)
+		return err;
+
+	err = sig = fpcsr_pending(csr);
+	if (err < 0)
+		return err;
 
 	/*
 	 * EVA does not have userland equivalents of ldc1 or sdc1, so we
@@ -192,14 +217,13 @@ static int protected_restore_fp_context(void __user *sc)
 			break;	/* really bad sigcontext */
 	}
 
-	return err;
+	return err ?: sig;
 }
 
 int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 {
 	int err = 0;
 	int i;
-	unsigned int used_math;
 
 	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
 
@@ -222,16 +246,13 @@ int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
 	}
 
-	used_math = !!used_math();
-	err |= __put_user(used_math, &sc->sc_used_math);
 
-	if (used_math) {
-		/*
-		 * Save FPU state to signal context. Signal handler
-		 * will "inherit" current FPU state.
-		 */
-		err |= protected_save_fp_context(sc);
-	}
+	/*
+	 * Save FPU state to signal context. Signal handler
+	 * will "inherit" current FPU state.
+	 */
+	err |= protected_save_fp_context(sc);
+
 	return err;
 }
 
@@ -254,22 +275,8 @@ int fpcsr_pending(unsigned int __user *fpcsr)
 	return err ?: sig;
 }
 
-static int
-check_and_restore_fp_context(void __user *sc)
-{
-	struct mips_abi *abi = current->thread.abi;
-	int err, sig;
-
-	err = sig = fpcsr_pending(sc + abi->off_sc_fpc_csr);
-	if (err > 0)
-		err = 0;
-	err |= protected_restore_fp_context(sc);
-	return err ?: sig;
-}
-
 int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 {
-	unsigned int used_math;
 	unsigned long treg;
 	int err = 0;
 	int i;
@@ -297,19 +304,7 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 	for (i = 1; i < 32; i++)
 		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
 
-	err |= __get_user(used_math, &sc->sc_used_math);
-	conditional_used_math(used_math);
-
-	if (used_math) {
-		/* restore fpu context if we have used it before */
-		if (!err)
-			err = check_and_restore_fp_context(sc);
-	} else {
-		/* signal handler may have used FPU.  Give it up. */
-		lose_fpu(0);
-	}
-
-	return err;
+	return err ?: protected_restore_fp_context(sc);
 }
 
 void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
-- 
2.4.4


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

* [PATCH 06/16] MIPS: skip odd double FP registers when copying FP32 sigcontext
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (4 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 05/16] MIPS: move FP usage checks into protected_{save,restore}_fp_context Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 07/16] MIPS: use common FP sigcontext code for O32 compat Paul Burton
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, linux-kernel, Richard Weinberger,
	Andrew Morton, Andy Lutomirski, Ralf Baechle, Maciej W. Rozycki

When a task uses 32 bit floating point, the odd indexed 32b register
values are stored in bits 63:32 of the preceding even indexed 64b
FP register field in saved context. Thus there is no point in
preserving the odd indexed 64b register fields since they hold no
valid context. This patch will cause them to be skipped, as is
already done in arch/mips/kernel/signal32.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/signal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 76f9136..23913ad 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -69,8 +69,9 @@ static int copy_fp_to_sigcontext(void __user *sc)
 	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int i;
 	int err = 0;
+	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
 
-	for (i = 0; i < NUM_FPU_REGS; i++) {
+	for (i = 0; i < NUM_FPU_REGS; i += inc) {
 		err |=
 		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
 			       &fpregs[i]);
@@ -87,9 +88,10 @@ static int copy_fp_from_sigcontext(void __user *sc)
 	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	int i;
 	int err = 0;
+	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
 	u64 fpr_val;
 
-	for (i = 0; i < NUM_FPU_REGS; i++) {
+	for (i = 0; i < NUM_FPU_REGS; i += inc) {
 		err |= __get_user(fpr_val, &fpregs[i]);
 		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
 	}
-- 
2.4.4


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

* [PATCH 07/16] MIPS: use common FP sigcontext code for O32 compat
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (5 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 06/16] MIPS: skip odd double FP registers when copying FP32 sigcontext Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 08/16] MIPS: remove unused {get,put}_sigset functions Paul Burton
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin, Manuel Lauss,
	linux-kernel, Richard Weinberger, James Hogan, Andrew Morton,
	Andy Lutomirski, Michael Ellerman, Markos Chandras, Ralf Baechle,
	Maciej W. Rozycki, David Daney

Make use of the common FP sigcontext code for O32 binaries running on
MIPS64 kernels now that it is taking appropriate offsets into struct
sigcontext(32) from struct mips_abi.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/asm/signal.h |   3 +
 arch/mips/kernel/asm-offsets.c |  11 ---
 arch/mips/kernel/r4k_fpu.S     | 114 -------------------------------
 arch/mips/kernel/signal.c      |   4 +-
 arch/mips/kernel/signal32.c    | 150 ++---------------------------------------
 5 files changed, 11 insertions(+), 271 deletions(-)

diff --git a/arch/mips/include/asm/signal.h b/arch/mips/include/asm/signal.h
index 8efe5a9..003e273 100644
--- a/arch/mips/include/asm/signal.h
+++ b/arch/mips/include/asm/signal.h
@@ -23,4 +23,7 @@
 
 #define __ARCH_HAS_IRIX_SIGACTION
 
+extern int protected_save_fp_context(void __user *sc);
+extern int protected_restore_fp_context(void __user *sc);
+
 #endif /* _ASM_SIGNAL_H */
diff --git a/arch/mips/kernel/asm-offsets.c b/arch/mips/kernel/asm-offsets.c
index beabe19..e5feff4 100644
--- a/arch/mips/kernel/asm-offsets.c
+++ b/arch/mips/kernel/asm-offsets.c
@@ -245,17 +245,6 @@ void output_sc_defines(void)
 }
 #endif
 
-#ifdef CONFIG_MIPS32_COMPAT
-void output_sc32_defines(void)
-{
-	COMMENT("Linux 32-bit sigcontext offsets.");
-	OFFSET(SC32_FPREGS, sigcontext32, sc_fpregs);
-	OFFSET(SC32_FPC_CSR, sigcontext32, sc_fpc_csr);
-	OFFSET(SC32_FPC_EIR, sigcontext32, sc_fpc_eir);
-	BLANK();
-}
-#endif
-
 void output_signal_defined(void)
 {
 	COMMENT("Linux signal numbers.");
diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index 9e2d18d..aa11f43 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -106,66 +106,6 @@ LEAF(_save_fp_context)
 	.set pop
 	END(_save_fp_context)
 
-#ifdef CONFIG_MIPS32_COMPAT
-	/* Save 32-bit process floating point context */
-LEAF(_save_fp_context32)
-	.set push
-	.set MIPS_ISA_ARCH_LEVEL_RAW
-	SET_HARDFLOAT
-	cfc1	t1, fcr31
-
-#ifndef CONFIG_CPU_MIPS64_R6
-	mfc0	t0, CP0_STATUS
-	sll	t0, t0, 5
-	bgez	t0, 1f			# skip storing odd if FR=0
-	 nop
-#endif
-
-	/* Store the 16 odd double precision registers */
-	EX      sdc1 $f1, SC32_FPREGS+8(a0)
-	EX      sdc1 $f3, SC32_FPREGS+24(a0)
-	EX      sdc1 $f5, SC32_FPREGS+40(a0)
-	EX      sdc1 $f7, SC32_FPREGS+56(a0)
-	EX      sdc1 $f9, SC32_FPREGS+72(a0)
-	EX      sdc1 $f11, SC32_FPREGS+88(a0)
-	EX      sdc1 $f13, SC32_FPREGS+104(a0)
-	EX      sdc1 $f15, SC32_FPREGS+120(a0)
-	EX      sdc1 $f17, SC32_FPREGS+136(a0)
-	EX      sdc1 $f19, SC32_FPREGS+152(a0)
-	EX      sdc1 $f21, SC32_FPREGS+168(a0)
-	EX      sdc1 $f23, SC32_FPREGS+184(a0)
-	EX      sdc1 $f25, SC32_FPREGS+200(a0)
-	EX      sdc1 $f27, SC32_FPREGS+216(a0)
-	EX      sdc1 $f29, SC32_FPREGS+232(a0)
-	EX      sdc1 $f31, SC32_FPREGS+248(a0)
-
-	/* Store the 16 even double precision registers */
-1:	EX	sdc1 $f0, SC32_FPREGS+0(a0)
-	EX	sdc1 $f2, SC32_FPREGS+16(a0)
-	EX	sdc1 $f4, SC32_FPREGS+32(a0)
-	EX	sdc1 $f6, SC32_FPREGS+48(a0)
-	EX	sdc1 $f8, SC32_FPREGS+64(a0)
-	EX	sdc1 $f10, SC32_FPREGS+80(a0)
-	EX	sdc1 $f12, SC32_FPREGS+96(a0)
-	EX	sdc1 $f14, SC32_FPREGS+112(a0)
-	EX	sdc1 $f16, SC32_FPREGS+128(a0)
-	EX	sdc1 $f18, SC32_FPREGS+144(a0)
-	EX	sdc1 $f20, SC32_FPREGS+160(a0)
-	EX	sdc1 $f22, SC32_FPREGS+176(a0)
-	EX	sdc1 $f24, SC32_FPREGS+192(a0)
-	EX	sdc1 $f26, SC32_FPREGS+208(a0)
-	EX	sdc1 $f28, SC32_FPREGS+224(a0)
-	EX	sdc1 $f30, SC32_FPREGS+240(a0)
-	EX	sw t1, SC32_FPC_CSR(a0)
-	cfc1	t0, $0				# implementation/version
-	EX	sw t0, SC32_FPC_EIR(a0)
-	.set pop
-
-	jr	ra
-	 li	v0, 0					# success
-	END(_save_fp_context32)
-#endif
-
 /**
  * _restore_fp_context() - restore FP context to the FPU
  * @a0 - pointer to fpregs field of sigcontext
@@ -231,60 +171,6 @@ LEAF(_restore_fp_context)
 	 li	v0, 0					# success
 	END(_restore_fp_context)
 
-#ifdef CONFIG_MIPS32_COMPAT
-LEAF(_restore_fp_context32)
-	/* Restore an o32 sigcontext.  */
-	.set push
-	SET_HARDFLOAT
-	EX	lw t1, SC32_FPC_CSR(a0)
-
-#ifndef CONFIG_CPU_MIPS64_R6
-	mfc0	t0, CP0_STATUS
-	sll	t0, t0, 5
-	bgez	t0, 1f			# skip loading odd if FR=0
-	 nop
-#endif
-
-	EX      ldc1 $f1, SC32_FPREGS+8(a0)
-	EX      ldc1 $f3, SC32_FPREGS+24(a0)
-	EX      ldc1 $f5, SC32_FPREGS+40(a0)
-	EX      ldc1 $f7, SC32_FPREGS+56(a0)
-	EX      ldc1 $f9, SC32_FPREGS+72(a0)
-	EX      ldc1 $f11, SC32_FPREGS+88(a0)
-	EX      ldc1 $f13, SC32_FPREGS+104(a0)
-	EX      ldc1 $f15, SC32_FPREGS+120(a0)
-	EX      ldc1 $f17, SC32_FPREGS+136(a0)
-	EX      ldc1 $f19, SC32_FPREGS+152(a0)
-	EX      ldc1 $f21, SC32_FPREGS+168(a0)
-	EX      ldc1 $f23, SC32_FPREGS+184(a0)
-	EX      ldc1 $f25, SC32_FPREGS+200(a0)
-	EX      ldc1 $f27, SC32_FPREGS+216(a0)
-	EX      ldc1 $f29, SC32_FPREGS+232(a0)
-	EX      ldc1 $f31, SC32_FPREGS+248(a0)
-
-1:	EX	ldc1 $f0, SC32_FPREGS+0(a0)
-	EX	ldc1 $f2, SC32_FPREGS+16(a0)
-	EX	ldc1 $f4, SC32_FPREGS+32(a0)
-	EX	ldc1 $f6, SC32_FPREGS+48(a0)
-	EX	ldc1 $f8, SC32_FPREGS+64(a0)
-	EX	ldc1 $f10, SC32_FPREGS+80(a0)
-	EX	ldc1 $f12, SC32_FPREGS+96(a0)
-	EX	ldc1 $f14, SC32_FPREGS+112(a0)
-	EX	ldc1 $f16, SC32_FPREGS+128(a0)
-	EX	ldc1 $f18, SC32_FPREGS+144(a0)
-	EX	ldc1 $f20, SC32_FPREGS+160(a0)
-	EX	ldc1 $f22, SC32_FPREGS+176(a0)
-	EX	ldc1 $f24, SC32_FPREGS+192(a0)
-	EX	ldc1 $f26, SC32_FPREGS+208(a0)
-	EX	ldc1 $f28, SC32_FPREGS+224(a0)
-	EX	ldc1 $f30, SC32_FPREGS+240(a0)
-	ctc1	t1, fcr31
-	jr	ra
-	 li	v0, 0					# success
-	.set pop
-	END(_restore_fp_context32)
-#endif
-
 	.set	reorder
 
 	.type	fault@function
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 23913ad..5b28f67 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -124,7 +124,7 @@ static int restore_hw_fp_context(void __user *sc)
 /*
  * Helper routines
  */
-static int protected_save_fp_context(void __user *sc)
+int protected_save_fp_context(void __user *sc)
 {
 	struct mips_abi *abi = current->thread.abi;
 	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
@@ -167,7 +167,7 @@ static int protected_save_fp_context(void __user *sc)
 	return err;
 }
 
-static int protected_restore_fp_context(void __user *sc)
+int protected_restore_fp_context(void __user *sc)
 {
 	struct mips_abi *abi = current->thread.abi;
 	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 6b65658..2a7c6dd 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -36,12 +36,6 @@
 
 #include "signal-common.h"
 
-static int (*save_fp_context32)(struct sigcontext32 __user *sc);
-static int (*restore_fp_context32)(struct sigcontext32 __user *sc);
-
-extern asmlinkage int _save_fp_context32(struct sigcontext32 __user *sc);
-extern asmlinkage int _restore_fp_context32(struct sigcontext32 __user *sc);
-
 /*
  * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  */
@@ -74,99 +68,11 @@ struct rt_sigframe32 {
 	struct ucontext32 rs_uc;
 };
 
-/*
- * Thread saved context copy to/from a signal context presumed to be on the
- * user stack, and therefore accessed with appropriate macros from uaccess.h.
- */
-static int copy_fp_to_sigcontext32(struct sigcontext32 __user *sc)
-{
-	int i;
-	int err = 0;
-	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
-
-	for (i = 0; i < NUM_FPU_REGS; i += inc) {
-		err |=
-		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
-			       &sc->sc_fpregs[i]);
-	}
-	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
-
-	return err;
-}
-
-static int copy_fp_from_sigcontext32(struct sigcontext32 __user *sc)
-{
-	int i;
-	int err = 0;
-	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
-	u64 fpr_val;
-
-	for (i = 0; i < NUM_FPU_REGS; i += inc) {
-		err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
-		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
-	}
-	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
-
-	return err;
-}
-
-/*
- * sigcontext handlers
- */
-static int protected_save_fp_context32(struct sigcontext32 __user *sc)
-{
-	int err;
-	while (1) {
-		lock_fpu_owner();
-		if (is_fpu_owner()) {
-			err = save_fp_context32(sc);
-			unlock_fpu_owner();
-		} else {
-			unlock_fpu_owner();
-			err = copy_fp_to_sigcontext32(sc);
-		}
-		if (likely(!err))
-			break;
-		/* touch the sigcontext and try again */
-		err = __put_user(0, &sc->sc_fpregs[0]) |
-			__put_user(0, &sc->sc_fpregs[31]) |
-			__put_user(0, &sc->sc_fpc_csr);
-		if (err)
-			break;	/* really bad sigcontext */
-	}
-	return err;
-}
-
-static int protected_restore_fp_context32(struct sigcontext32 __user *sc)
-{
-	int err, tmp __maybe_unused;
-	while (1) {
-		lock_fpu_owner();
-		if (is_fpu_owner()) {
-			err = restore_fp_context32(sc);
-			unlock_fpu_owner();
-		} else {
-			unlock_fpu_owner();
-			err = copy_fp_from_sigcontext32(sc);
-		}
-		if (likely(!err))
-			break;
-		/* touch the sigcontext and try again */
-		err = __get_user(tmp, &sc->sc_fpregs[0]) |
-			__get_user(tmp, &sc->sc_fpregs[31]) |
-			__get_user(tmp, &sc->sc_fpc_csr);
-		if (err)
-			break;	/* really bad sigcontext */
-	}
-	return err;
-}
-
 static int setup_sigcontext32(struct pt_regs *regs,
 			      struct sigcontext32 __user *sc)
 {
 	int err = 0;
 	int i;
-	u32 used_math;
 
 	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
 
@@ -186,35 +92,18 @@ static int setup_sigcontext32(struct pt_regs *regs,
 		err |= __put_user(mflo3(), &sc->sc_lo3);
 	}
 
-	used_math = !!used_math();
-	err |= __put_user(used_math, &sc->sc_used_math);
+	/*
+	 * Save FPU state to signal context.  Signal handler
+	 * will "inherit" current FPU state.
+	 */
+	err |= protected_save_fp_context(sc);
 
-	if (used_math) {
-		/*
-		 * Save FPU state to signal context.  Signal handler
-		 * will "inherit" current FPU state.
-		 */
-		err |= protected_save_fp_context32(sc);
-	}
 	return err;
 }
 
-static int
-check_and_restore_fp_context32(struct sigcontext32 __user *sc)
-{
-	int err, sig;
-
-	err = sig = fpcsr_pending(&sc->sc_fpc_csr);
-	if (err > 0)
-		err = 0;
-	err |= protected_restore_fp_context32(sc);
-	return err ?: sig;
-}
-
 static int restore_sigcontext32(struct pt_regs *regs,
 				struct sigcontext32 __user *sc)
 {
-	u32 used_math;
 	int err = 0;
 	s32 treg;
 	int i;
@@ -238,19 +127,7 @@ static int restore_sigcontext32(struct pt_regs *regs,
 	for (i = 1; i < 32; i++)
 		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
 
-	err |= __get_user(used_math, &sc->sc_used_math);
-	conditional_used_math(used_math);
-
-	if (used_math) {
-		/* restore fpu context if we have used it before */
-		if (!err)
-			err = check_and_restore_fp_context32(sc);
-	} else {
-		/* signal handler may have used FPU.  Give it up. */
-		lose_fpu(0);
-	}
-
-	return err;
+	return err ?: protected_restore_fp_context(sc);
 }
 
 /*
@@ -593,18 +470,3 @@ struct mips_abi mips_abi_32 = {
 	.off_sc_fpc_csr = offsetof(struct sigcontext32, sc_fpc_csr),
 	.off_sc_used_math = offsetof(struct sigcontext32, sc_used_math),
 };
-
-static int signal32_init(void)
-{
-	if (cpu_has_fpu) {
-		save_fp_context32 = _save_fp_context32;
-		restore_fp_context32 = _restore_fp_context32;
-	} else {
-		save_fp_context32 = copy_fp_to_sigcontext32;
-		restore_fp_context32 = copy_fp_from_sigcontext32;
-	}
-
-	return 0;
-}
-
-arch_initcall(signal32_init);
-- 
2.4.4


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

* [PATCH 08/16] MIPS: remove unused {get,put}_sigset functions
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (6 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 07/16] MIPS: use common FP sigcontext code for O32 compat Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 09/16] MIPS: indicate FP mode in sigcontext sc_used_math Paul Burton
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, linux-kernel, Richard Weinberger,
	James Hogan, Andy Lutomirski, Ralf Baechle, Andrew Morton

These functions are never called & thus dead code. Remove them.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/signal32.c | 51 ---------------------------------------------
 1 file changed, 51 deletions(-)

diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 2a7c6dd..3059f36 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -131,57 +131,6 @@ static int restore_sigcontext32(struct pt_regs *regs,
 }
 
 /*
- *
- */
-extern void __put_sigset_unknown_nsig(void);
-extern void __get_sigset_unknown_nsig(void);
-
-static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf)
-{
-	int err = 0;
-
-	if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)))
-		return -EFAULT;
-
-	switch (_NSIG_WORDS) {
-	default:
-		__put_sigset_unknown_nsig();
-	case 2:
-		err |= __put_user(kbuf->sig[1] >> 32, &ubuf->sig[3]);
-		err |= __put_user(kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]);
-	case 1:
-		err |= __put_user(kbuf->sig[0] >> 32, &ubuf->sig[1]);
-		err |= __put_user(kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]);
-	}
-
-	return err;
-}
-
-static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf)
-{
-	int err = 0;
-	unsigned long sig[4];
-
-	if (!access_ok(VERIFY_READ, ubuf, sizeof(*ubuf)))
-		return -EFAULT;
-
-	switch (_NSIG_WORDS) {
-	default:
-		__get_sigset_unknown_nsig();
-	case 2:
-		err |= __get_user(sig[3], &ubuf->sig[3]);
-		err |= __get_user(sig[2], &ubuf->sig[2]);
-		kbuf->sig[1] = sig[2] | (sig[3] << 32);
-	case 1:
-		err |= __get_user(sig[1], &ubuf->sig[1]);
-		err |= __get_user(sig[0], &ubuf->sig[0]);
-		kbuf->sig[0] = sig[0] | (sig[1] << 32);
-	}
-
-	return err;
-}
-
-/*
  * Atomically swap in the new signal mask, and wait for a signal.
  */
 
-- 
2.4.4


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

* [PATCH 09/16] MIPS: indicate FP mode in sigcontext sc_used_math
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (7 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 08/16] MIPS: remove unused {get,put}_sigset functions Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 10/16] MIPS: add definitions for extended context Paul Burton
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, linux-kernel, Richard Weinberger,
	James Hogan, Andy Lutomirski, Ralf Baechle, Maciej W. Rozycki

The sc_used_math field of struct sigcontext & its variants has
traditionally been used as a boolean value indicating only whether or
not floating point context is saved within the sigcontext. With various
supported FP modes & the ability to switch between them this information
will no longer be enough to decode the meaning of the data stored in the
sc_fpregs fields of struct sigcontext.

To make that possible 3 bits are defined within sc_used_math:

  - Bit 0 (USED_FP) represents whether FP was used, essentially
    providing the boolean flag which sc_used_math as a whole provided
    previously.

  - Bit 1 (USED_FR1) provides the value of the Status.FR bit at the time
    the FP context was saved.

  - Bit 2 (USED_HYBRID_FPRS) indicates whether the FP context was saved
    under the hybrid FPR scheme. Essentially, when set the odd singles
    are located in bits 63:32 of the preceding even indexed sc_fpregs
    element.

Any userland that tests whether the sc_used_math field is zero or
non-zero will continue to function as expected. Having said that, I
could not find any userland which uses the sc_used_math field at all.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/uapi/asm/sigcontext.h |  9 +++++++++
 arch/mips/kernel/signal.c               | 15 +++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/arch/mips/include/uapi/asm/sigcontext.h b/arch/mips/include/uapi/asm/sigcontext.h
index ae78902..f28facd 100644
--- a/arch/mips/include/uapi/asm/sigcontext.h
+++ b/arch/mips/include/uapi/asm/sigcontext.h
@@ -12,6 +12,15 @@
 #include <linux/types.h>
 #include <asm/sgidefs.h>
 
+/* scalar FP context was used */
+#define USED_FP			(1 << 0)
+
+/* the value of Status.FR when context was saved */
+#define USED_FR1		(1 << 1)
+
+/* FR=1, but with odd singles in bits 63:32 of preceding even double */
+#define USED_HYBRID_FPRS	(1 << 2)
+
 #if _MIPS_SIM == _MIPS_SIM_ABI32
 
 struct sigcontext {
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 5b28f67..de0b451 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -133,9 +133,16 @@ int protected_save_fp_context(void __user *sc)
 	unsigned int used;
 	int err;
 
-	used = !!used_math();
+	used = used_math() ? USED_FP : 0;
+	if (used) {
+		if (!test_thread_flag(TIF_32BIT_FPREGS))
+			used |= USED_FR1;
+		if (test_thread_flag(TIF_HYBRID_FPREGS))
+			used |= USED_HYBRID_FPRS;
+	}
+
 	err = __put_user(used, used_math);
-	if (err || !used)
+	if (err || !(used & USED_FP))
 		return err;
 
 	/*
@@ -177,13 +184,13 @@ int protected_restore_fp_context(void __user *sc)
 	int err, sig, tmp __maybe_unused;
 
 	err = __get_user(used, used_math);
-	conditional_used_math(used);
+	conditional_used_math(used & USED_FP);
 
 	/*
 	 * The signal handler may have used FPU; give it up if the program
 	 * doesn't want it following sigreturn.
 	 */
-	if (err || !used)
+	if (err || !(used & USED_FP))
 		lose_fpu(0);
 	if (err)
 		return err;
-- 
2.4.4


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

* [PATCH 10/16] MIPS: add definitions for extended context
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (8 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 09/16] MIPS: indicate FP mode in sigcontext sc_used_math Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-10-25 21:10   ` [PATCH 10/16] compile error: " Hauke Mehrtens
  2015-07-10 15:00 ` [PATCH 11/16] MIPS: save MSA extended context around signals Paul Burton
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Peter Zijlstra,
	Zubair Lutfullah Kakakhel, Alex Smith, linux-kernel,
	Michal Nazarewicz, Richard Weinberger, Andrew Morton,
	Andy Lutomirski, Daniel Borkmann, Markos Chandras,
	Frederic Weisbecker, Ralf Baechle, Michael Ellerman,
	Maciej W. Rozycki

The context introduced by MSA needs to be saved around signals. However,
we can't increase the size of struct sigcontext because that will change
the offset of the signal mask in struct sigframe or struct ucontext.
This patch instead places the new context immediately after the struct
sigframe for traditional signals, or similarly after struct ucontext for
RT signals. The layout of struct sigframe & struct ucontext is identical
from their sigcontext fields onwards, so the offset from the sigcontext
to the extended context will always be the same regardless of the type
of signal.

Userland will be able to search through the extended context by using
the magic values to detect which types of context are present. Any
unrecognised context can be skipped over using the size field of struct
extcontext. Once the magic value END_EXTCONTEXT_MAGIC is seen it is
known that there are no further extended context structures to examine.

This approach is somewhat similar to that taken by ARM to save VFP &
other context at the end of struct ucontext.

Userland can determine whether extended context is present by checking
for the USED_EXTCONTEXT bit in the sc_used_math field of struct
sigcontext. Whilst this could potentially change the historic semantics
of sc_used_math if further extended context which does not imply FP
context were to be introduced in the future, I have been unable to find
any userland code making use of sc_used_math at all. Using one of the
fields described as unused in struct sigcontext was considered, but the
kernel does not already write to those fields so there would be no
guarantee of the field being clear on older kernels. Other alternatives
would be to have userland check the kernel version, or to have a HWCAP
bit indicating presence of extended context. However there is a desire
to have the context & information required to decode it be self
contained such that, for example, debuggers could decode the saved
context easily.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/asm/Kbuild            |  1 -
 arch/mips/include/uapi/asm/sigcontext.h |  3 ++
 arch/mips/include/uapi/asm/ucontext.h   | 65 +++++++++++++++++++++++++++++++++
 arch/mips/kernel/signal.c               | 13 +++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/uapi/asm/ucontext.h

diff --git a/arch/mips/include/asm/Kbuild b/arch/mips/include/asm/Kbuild
index 526539c..18e8b8d 100644
--- a/arch/mips/include/asm/Kbuild
+++ b/arch/mips/include/asm/Kbuild
@@ -16,6 +16,5 @@ generic-y += sections.h
 generic-y += segment.h
 generic-y += serial.h
 generic-y += trace_clock.h
-generic-y += ucontext.h
 generic-y += user.h
 generic-y += xor.h
diff --git a/arch/mips/include/uapi/asm/sigcontext.h b/arch/mips/include/uapi/asm/sigcontext.h
index f28facd..80db06c 100644
--- a/arch/mips/include/uapi/asm/sigcontext.h
+++ b/arch/mips/include/uapi/asm/sigcontext.h
@@ -21,6 +21,9 @@
 /* FR=1, but with odd singles in bits 63:32 of preceding even double */
 #define USED_HYBRID_FPRS	(1 << 2)
 
+/* extended context was used, see struct extcontext for details */
+#define USED_EXTCONTEXT		(1 << 3)
+
 #if _MIPS_SIM == _MIPS_SIM_ABI32
 
 struct sigcontext {
diff --git a/arch/mips/include/uapi/asm/ucontext.h b/arch/mips/include/uapi/asm/ucontext.h
new file mode 100644
index 0000000..2320144
--- /dev/null
+++ b/arch/mips/include/uapi/asm/ucontext.h
@@ -0,0 +1,65 @@
+#ifndef __MIPS_UAPI_ASM_UCONTEXT_H
+#define __MIPS_UAPI_ASM_UCONTEXT_H
+
+/**
+ * struct extcontext - extended context header structure
+ * @magic:	magic value identifying the type of extended context
+ * @size:	the size in bytes of the enclosing structure
+ *
+ * Extended context structures provide context which does not fit within struct
+ * sigcontext. They are placed sequentially in memory at the end of struct
+ * ucontext and struct sigframe, with each extended context structure beginning
+ * with a header defined by this struct. The type of context represented is
+ * indicated by the magic field. Userland may check each extended context
+ * structure against magic values that it recognises. The size field allows any
+ * unrecognised context to be skipped, allowing for future expansion. The end
+ * of the extended context data is indicated by the magic value
+ * END_EXTCONTEXT_MAGIC.
+ */
+struct extcontext {
+	unsigned int		magic;
+	unsigned int		size;
+};
+
+/**
+ * struct msa_extcontext - MSA extended context structure
+ * @ext:	the extended context header, with magic == MSA_EXTCONTEXT_MAGIC
+ * @wr:		the most significant 64 bits of each MSA vector register
+ * @csr:	the value of the MSA control & status register
+ *
+ * If MSA context is live for a task at the time a signal is delivered to it,
+ * this structure will hold the MSA context of the task as it was prior to the
+ * signal delivery.
+ */
+struct msa_extcontext {
+	struct extcontext	ext;
+#define MSA_EXTCONTEXT_MAGIC	0x784d5341	/* xMSA */
+
+	unsigned long long	wr[32];
+	unsigned int		csr;
+};
+
+#define END_EXTCONTEXT_MAGIC	0x78454e44	/* xEND */
+
+/**
+ * struct ucontext - user context structure
+ * @uc_flags:
+ * @uc_link:
+ * @uc_stack:
+ * @uc_mcontext:	holds basic processor state
+ * @uc_sigmask:
+ * @uc_extcontext:	holds extended processor state
+ */
+struct ucontext {
+	/* Historic fields matching asm-generic */
+	unsigned long		uc_flags;
+	struct ucontext		*uc_link;
+	stack_t			uc_stack;
+	struct sigcontext	uc_mcontext;
+	sigset_t		uc_sigmask;
+
+	/* Extended context structures may follow ucontext */
+	unsigned long long	uc_extcontext[0];
+};
+
+#endif /* __MIPS_UAPI_ASM_UCONTEXT_H */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index de0b451..4e626ca 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -47,8 +47,11 @@ static int (*restore_fp_context)(void __user *sc);
 struct sigframe {
 	u32 sf_ass[4];		/* argument save space for o32 */
 	u32 sf_pad[2];		/* Was: signal trampoline */
+
+	/* Matches struct ucontext from its uc_mcontext field onwards */
 	struct sigcontext sf_sc;
 	sigset_t sf_mask;
+	unsigned long long sf_extcontext[0];
 };
 
 struct rt_sigframe {
@@ -686,6 +689,16 @@ static int smp_restore_fp_context(void __user *sc)
 
 static int signal_setup(void)
 {
+	/*
+	 * The offset from sigcontext to extended context should be the same
+	 * regardless of the type of signal, such that userland can always know
+	 * where to look if it wishes to find the extended context structures.
+	 */
+	BUILD_BUG_ON((offsetof(struct sigframe, sf_extcontext) -
+		      offsetof(struct sigframe, sf_sc)) !=
+		     (offsetof(struct rt_sigframe, rs_uc.uc_extcontext) -
+		      offsetof(struct rt_sigframe, rs_uc.uc_mcontext)));
+
 #ifdef CONFIG_SMP
 	/* For now just do the cpu_has_fpu check when the functions are invoked */
 	save_fp_context = smp_save_fp_context;
-- 
2.4.4


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

* [PATCH 11/16] MIPS: save MSA extended context around signals
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (9 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 10/16] MIPS: add definitions for extended context Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 12/16] MIPS: AT_HWCAP aux vector infrastructure Paul Burton
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin, Michael Ellerman,
	linux-kernel, Richard Weinberger, James Hogan, Andrew Morton,
	Andy Lutomirski, Markos Chandras, Ralf Baechle, Manuel Lauss,
	Maciej W. Rozycki

It is desirable for signal handlers to be allowed to make use of MSA,
particularly if auto vectorisation is used when compiling a program.
The MSA context must therefore be saved & restored before & after
invoking the signal handler. Make use of the extended context structs
defined in the preceding patch to save MSA context after the sigframe
when appropriate.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/r4k_fpu.S       | 119 ++++++++++++++++++
 arch/mips/kernel/signal-common.h |   3 +
 arch/mips/kernel/signal.c        | 252 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 344 insertions(+), 30 deletions(-)

diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index aa11f43..c7fe72d 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -13,6 +13,7 @@
  * Copyright (C) 1999, 2001 Silicon Graphics, Inc.
  */
 #include <asm/asm.h>
+#include <asm/asmmacro.h>
 #include <asm/errno.h>
 #include <asm/fpregdef.h>
 #include <asm/mipsregs.h>
@@ -171,6 +172,124 @@ LEAF(_restore_fp_context)
 	 li	v0, 0					# success
 	END(_restore_fp_context)
 
+#ifdef CONFIG_CPU_HAS_MSA
+
+	.macro	save_msa_upper	wr, off, base
+	.set	push
+	.set	noat
+#ifdef CONFIG_64BIT
+	copy_u_d \wr, 1
+	EX sd	$1, \off(\base)
+#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
+	copy_u_w \wr, 2
+	EX sw	$1, \off(\base)
+	copy_u_w \wr, 3
+	EX sw	$1, (\off+4)(\base)
+#else /* CONFIG_CPU_BIG_ENDIAN */
+	copy_u_w \wr, 2
+	EX sw	$1, (\off+4)(\base)
+	copy_u_w \wr, 3
+	EX sw	$1, \off(\base)
+#endif
+	.set	pop
+	.endm
+
+LEAF(_save_msa_all_upper)
+	save_msa_upper	0, 0x00, a0
+	save_msa_upper	1, 0x08, a0
+	save_msa_upper	2, 0x10, a0
+	save_msa_upper	3, 0x18, a0
+	save_msa_upper	4, 0x20, a0
+	save_msa_upper	5, 0x28, a0
+	save_msa_upper	6, 0x30, a0
+	save_msa_upper	7, 0x38, a0
+	save_msa_upper	8, 0x40, a0
+	save_msa_upper	9, 0x48, a0
+	save_msa_upper	10, 0x50, a0
+	save_msa_upper	11, 0x58, a0
+	save_msa_upper	12, 0x60, a0
+	save_msa_upper	13, 0x68, a0
+	save_msa_upper	14, 0x70, a0
+	save_msa_upper	15, 0x78, a0
+	save_msa_upper	16, 0x80, a0
+	save_msa_upper	17, 0x88, a0
+	save_msa_upper	18, 0x90, a0
+	save_msa_upper	19, 0x98, a0
+	save_msa_upper	20, 0xa0, a0
+	save_msa_upper	21, 0xa8, a0
+	save_msa_upper	22, 0xb0, a0
+	save_msa_upper	23, 0xb8, a0
+	save_msa_upper	24, 0xc0, a0
+	save_msa_upper	25, 0xc8, a0
+	save_msa_upper	26, 0xd0, a0
+	save_msa_upper	27, 0xd8, a0
+	save_msa_upper	28, 0xe0, a0
+	save_msa_upper	29, 0xe8, a0
+	save_msa_upper	30, 0xf0, a0
+	save_msa_upper	31, 0xf8, a0
+	jr	ra
+	 li	v0, 0
+	END(_save_msa_all_upper)
+
+	.macro	restore_msa_upper	wr, off, base
+	.set	push
+	.set	noat
+#ifdef CONFIG_64BIT
+	EX ld	$1, \off(\base)
+	insert_d \wr, 1
+#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
+	EX lw	$1, \off(\base)
+	insert_w \wr, 2
+	EX lw	$1, (\off+4)(\base)
+	insert_w \wr, 3
+#else /* CONFIG_CPU_BIG_ENDIAN */
+	EX lw	$1, (\off+4)(\base)
+	insert_w \wr, 2
+	EX lw	$1, \off(\base)
+	insert_w \wr, 3
+#endif
+	.set	pop
+	.endm
+
+LEAF(_restore_msa_all_upper)
+	restore_msa_upper	0, 0x00, a0
+	restore_msa_upper	1, 0x08, a0
+	restore_msa_upper	2, 0x10, a0
+	restore_msa_upper	3, 0x18, a0
+	restore_msa_upper	4, 0x20, a0
+	restore_msa_upper	5, 0x28, a0
+	restore_msa_upper	6, 0x30, a0
+	restore_msa_upper	7, 0x38, a0
+	restore_msa_upper	8, 0x40, a0
+	restore_msa_upper	9, 0x48, a0
+	restore_msa_upper	10, 0x50, a0
+	restore_msa_upper	11, 0x58, a0
+	restore_msa_upper	12, 0x60, a0
+	restore_msa_upper	13, 0x68, a0
+	restore_msa_upper	14, 0x70, a0
+	restore_msa_upper	15, 0x78, a0
+	restore_msa_upper	16, 0x80, a0
+	restore_msa_upper	17, 0x88, a0
+	restore_msa_upper	18, 0x90, a0
+	restore_msa_upper	19, 0x98, a0
+	restore_msa_upper	20, 0xa0, a0
+	restore_msa_upper	21, 0xa8, a0
+	restore_msa_upper	22, 0xb0, a0
+	restore_msa_upper	23, 0xb8, a0
+	restore_msa_upper	24, 0xc0, a0
+	restore_msa_upper	25, 0xc8, a0
+	restore_msa_upper	26, 0xd0, a0
+	restore_msa_upper	27, 0xd8, a0
+	restore_msa_upper	28, 0xe0, a0
+	restore_msa_upper	29, 0xe8, a0
+	restore_msa_upper	30, 0xf0, a0
+	restore_msa_upper	31, 0xf8, a0
+	jr	ra
+	 li	v0, 0
+	END(_restore_msa_all_upper)
+
+#endif /* CONFIG_CPU_HAS_MSA */
+
 	.set	reorder
 
 	.type	fault@function
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index d594695..a99987f 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -42,4 +42,7 @@ _save_fp_context(void __user *fpregs, void __user *csr);
 extern asmlinkage int
 _restore_fp_context(void __user *fpregs, void __user *csr);
 
+extern asmlinkage int _save_msa_all_upper(void __user *buf);
+extern asmlinkage int _restore_msa_all_upper(void __user *buf);
+
 #endif	/* __SIGNAL_COMMON_H */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 4e626ca..98bbca6 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -38,6 +38,7 @@
 #include <asm/vdso.h>
 #include <asm/dsp.h>
 #include <asm/inst.h>
+#include <asm/msa.h>
 
 #include "signal-common.h"
 
@@ -125,6 +126,168 @@ static int restore_hw_fp_context(void __user *sc)
 }
 
 /*
+ * Extended context handling.
+ */
+
+static inline void __user *sc_to_extcontext(void __user *sc)
+{
+	struct ucontext __user *uc;
+
+	/*
+	 * We can just pretend the sigcontext is always embedded in a struct
+	 * ucontext here, because the offset from sigcontext to extended
+	 * context is the same in the struct sigframe case.
+	 */
+	uc = container_of(sc, struct ucontext, uc_mcontext);
+	return &uc->uc_extcontext;
+}
+
+static int save_msa_extcontext(void __user *buf)
+{
+	struct msa_extcontext __user *msa = buf;
+	uint64_t val;
+	int i, err;
+
+	if (!thread_msa_context_live())
+		return 0;
+
+	/*
+	 * Ensure that we can't lose the live MSA context between checking
+	 * for it & writing it to memory.
+	 */
+	preempt_disable();
+
+	if (is_msa_enabled()) {
+		/*
+		 * There are no EVA versions of the vector register load/store
+		 * instructions, so MSA context has to be saved to kernel memory
+		 * and then copied to user memory. The save to kernel memory
+		 * should already have been done when handling scalar FP
+		 * context.
+		 */
+		BUG_ON(config_enabled(CONFIG_EVA));
+
+		err = __put_user(read_msa_csr(), &msa->csr);
+		err |= _save_msa_all_upper(&msa->wr);
+
+		preempt_enable();
+	} else {
+		preempt_enable();
+
+		err = __put_user(current->thread.fpu.msacsr, &msa->csr);
+
+		for (i = 0; i < NUM_FPU_REGS; i++) {
+			val = get_fpr64(&current->thread.fpu.fpr[i], 1);
+			err |= __put_user(val, &msa->wr[i]);
+		}
+	}
+
+	err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
+	err |= __put_user(sizeof(*msa), &msa->ext.size);
+
+	return err ? -EFAULT : sizeof(*msa);
+}
+
+static int restore_msa_extcontext(void __user *buf, unsigned int size)
+{
+	struct msa_extcontext __user *msa = buf;
+	unsigned long long val;
+	unsigned int csr;
+	int i, err;
+
+	if (size != sizeof(*msa))
+		return -EINVAL;
+
+	err = get_user(csr, &msa->csr);
+	if (err)
+		return err;
+
+	preempt_disable();
+
+	if (is_msa_enabled()) {
+		/*
+		 * There are no EVA versions of the vector register load/store
+		 * instructions, so MSA context has to be copied to kernel
+		 * memory and later loaded to registers. The same is true of
+		 * scalar FP context, so FPU & MSA should have already been
+		 * disabled whilst handling scalar FP context.
+		 */
+		BUG_ON(config_enabled(CONFIG_EVA));
+
+		write_msa_csr(csr);
+		err |= _restore_msa_all_upper(&msa->wr);
+		preempt_enable();
+	} else {
+		preempt_enable();
+
+		current->thread.fpu.msacsr = csr;
+
+		for (i = 0; i < NUM_FPU_REGS; i++) {
+			err |= __get_user(val, &msa->wr[i]);
+			set_fpr64(&current->thread.fpu.fpr[i], 1, val);
+		}
+	}
+
+	return err;
+}
+
+static int save_extcontext(void __user *buf)
+{
+	int sz;
+
+	sz = save_msa_extcontext(buf);
+	if (sz < 0)
+		return sz;
+	buf += sz;
+
+	/* If no context was saved then trivially return */
+	if (!sz)
+		return 0;
+
+	/* Write the end marker */
+	if (__put_user(END_EXTCONTEXT_MAGIC, (u32 *)buf))
+		return -EFAULT;
+
+	sz += sizeof(((struct extcontext *)NULL)->magic);
+	return sz;
+}
+
+static int restore_extcontext(void __user *buf)
+{
+	struct extcontext ext;
+	int err;
+
+	while (1) {
+		err = __get_user(ext.magic, (unsigned int *)buf);
+		if (err)
+			return err;
+
+		if (ext.magic == END_EXTCONTEXT_MAGIC)
+			return 0;
+
+		err = __get_user(ext.size, (unsigned int *)(buf
+			+ offsetof(struct extcontext, size)));
+		if (err)
+			return err;
+
+		switch (ext.magic) {
+		case MSA_EXTCONTEXT_MAGIC:
+			err = restore_msa_extcontext(buf, ext.size);
+			break;
+
+		default:
+			err = -EINVAL;
+			break;
+		}
+
+		if (err)
+			return err;
+
+		buf += ext.size;
+	}
+}
+
+/*
  * Helper routines
  */
 int protected_save_fp_context(void __user *sc)
@@ -133,7 +296,7 @@ int protected_save_fp_context(void __user *sc)
 	uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
 	uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
 	uint32_t __user *used_math = sc + abi->off_sc_used_math;
-	unsigned int used;
+	unsigned int used, ext_sz;
 	int err;
 
 	used = used_math() ? USED_FP : 0;
@@ -142,39 +305,40 @@ int protected_save_fp_context(void __user *sc)
 			used |= USED_FR1;
 		if (test_thread_flag(TIF_HYBRID_FPREGS))
 			used |= USED_HYBRID_FPRS;
-	}
 
-	err = __put_user(used, used_math);
-	if (err || !(used & USED_FP))
-		return err;
-
-	/*
-	 * EVA does not have userland equivalents of ldc1 or sdc1, so
-	 * save to the kernel FP context & copy that to userland below.
-	 */
-	if (config_enabled(CONFIG_EVA))
-		lose_fpu(1);
-
-	while (1) {
-		lock_fpu_owner();
-		if (is_fpu_owner()) {
-			err = save_fp_context(sc);
-			unlock_fpu_owner();
-		} else {
-			unlock_fpu_owner();
-			err = copy_fp_to_sigcontext(sc);
+		/*
+		 * EVA does not have userland equivalents of ldc1 or sdc1, so
+		 * save to the kernel FP context & copy that to userland below.
+		 */
+		if (config_enabled(CONFIG_EVA))
+			lose_fpu(1);
+
+		while (1) {
+			lock_fpu_owner();
+			if (is_fpu_owner()) {
+				err = save_fp_context(sc);
+				unlock_fpu_owner();
+			} else {
+				unlock_fpu_owner();
+				err = copy_fp_to_sigcontext(sc);
+			}
+			if (likely(!err))
+				break;
+			/* touch the sigcontext and try again */
+			err = __put_user(0, &fpregs[0]) |
+				__put_user(0, &fpregs[31]) |
+				__put_user(0, csr);
+			if (err)
+				return err;	/* really bad sigcontext */
 		}
-		if (likely(!err))
-			break;
-		/* touch the sigcontext and try again */
-		err = __put_user(0, &fpregs[0]) |
-			__put_user(0, &fpregs[31]) |
-			__put_user(0, csr);
-		if (err)
-			break;	/* really bad sigcontext */
 	}
 
-	return err;
+	ext_sz = err = save_extcontext(sc_to_extcontext(sc));
+	if (err < 0)
+		return err;
+	used |= ext_sz ? USED_EXTCONTEXT : 0;
+
+	return __put_user(used, used_math);
 }
 
 int protected_restore_fp_context(void __user *sc)
@@ -229,6 +393,9 @@ int protected_restore_fp_context(void __user *sc)
 			break;	/* really bad sigcontext */
 	}
 
+	if (used & USED_EXTCONTEXT)
+		err |= restore_extcontext(sc_to_extcontext(sc));
+
 	return err ?: sig;
 }
 
@@ -268,6 +435,28 @@ int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 	return err;
 }
 
+static size_t extcontext_max_size(void)
+{
+	size_t sz = 0;
+
+	/*
+	 * The assumption here is that between this point & the point at which
+	 * the extended context is saved the size of the context should only
+	 * ever be able to shrink (if the task is preempted), but never grow.
+	 * That is, what this function returns is an upper bound on the size of
+	 * the extended context for the current task at the current time.
+	 */
+
+	if (thread_msa_context_live())
+		sz += sizeof(struct msa_extcontext);
+
+	/* If any context is saved then we'll append the end marker */
+	if (sz)
+		sz += sizeof(((struct extcontext *)NULL)->magic);
+
+	return sz;
+}
+
 int fpcsr_pending(unsigned int __user *fpcsr)
 {
 	int err, sig = 0;
@@ -324,6 +513,9 @@ void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
 {
 	unsigned long sp;
 
+	/* Leave space for potential extended context */
+	frame_size += extcontext_max_size();
+
 	/* Default to using normal stack */
 	sp = regs->regs[29];
 
-- 
2.4.4


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

* [PATCH 12/16] MIPS: AT_HWCAP aux vector infrastructure
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (10 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 11/16] MIPS: save MSA extended context around signals Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 13/16] MIPS: advertise MIPSr6 via HWCAP when appropriate Paul Burton
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Kees Cook, Leonid Yegoshin,
	Maciej W. Rozycki, Alex Smith, linux-kernel, Huacai Chen,
	Markos Chandras, Ralf Baechle

In order for userland to determine whether various features are safe to
use, it will need to know both that the hardware supports those features
and that the kernel is recent enough & configured appropriately to
support them. For example under the O32 modeless FP proposal the dynamic
linker & ifunc resolvers will need this information.  The kernel is the
only thing in a position to know availability accurately, so the kernel
needs to provide the information to userland. This patch introduces the
infrastructure to provide the AT_HWCAP aux vector to userland in order
to provide that information. It also defines the 2 currently specified
flags, which indicate MIPSr6 & MSA support.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/include/asm/elf.h        | 4 +++-
 arch/mips/include/uapi/asm/hwcap.h | 8 ++++++++
 arch/mips/kernel/cpu-probe.c       | 3 +++
 3 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/uapi/asm/hwcap.h

diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index f19e890..53b2693 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -382,7 +382,9 @@ do {									\
    instruction set this cpu supports.  This could be done in userspace,
    but it's not easy, and we've already done it here.  */
 
-#define ELF_HWCAP	(0)
+#define ELF_HWCAP	(elf_hwcap)
+extern unsigned int elf_hwcap;
+#include <asm/hwcap.h>
 
 /*
  * This yields a string that ld.so will use to load implementation
diff --git a/arch/mips/include/uapi/asm/hwcap.h b/arch/mips/include/uapi/asm/hwcap.h
new file mode 100644
index 0000000..c7484a7
--- /dev/null
+++ b/arch/mips/include/uapi/asm/hwcap.h
@@ -0,0 +1,8 @@
+#ifndef _UAPI_ASM_HWCAP_H
+#define _UAPI_ASM_HWCAP_H
+
+/* HWCAP flags */
+#define HWCAP_MIPS_R6		(1 << 0)
+#define HWCAP_MIPS_MSA		(1 << 1)
+
+#endif /* _UAPI_ASM_HWCAP_H */
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 209e5b76..e184921 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -32,6 +32,9 @@
 #include <asm/spram.h>
 #include <asm/uaccess.h>
 
+/* Hardware capabilities */
+unsigned int elf_hwcap __read_mostly;
+
 /*
  * Get the FPU Implementation/Revision.
  */
-- 
2.4.4


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

* [PATCH 13/16] MIPS: advertise MIPSr6 via HWCAP when appropriate
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (11 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 12/16] MIPS: AT_HWCAP aux vector infrastructure Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 14/16] MIPS: advertise MSA support via HWCAP when present Paul Burton
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin, Maciej W. Rozycki,
	linux-kernel, Huacai Chen, Markos Chandras, Ralf Baechle

When running on a CPU implementing the release 6 of the MIPS32 or MIPS64
ISA, advertise that to userland via the appropriate HWCAP bit.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/cpu-probe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index e184921..168a5d3 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -1489,6 +1489,9 @@ void cpu_probe(void)
 	else
 		c->srsets = 1;
 
+	if (cpu_has_mips_r6)
+		elf_hwcap |= HWCAP_MIPS_R6;
+
 	if (cpu_has_msa) {
 		c->msa_id = cpu_get_msa_id();
 		WARN(c->msa_id & MSA_IR_WRPF,
-- 
2.4.4


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

* [PATCH 14/16] MIPS: advertise MSA support via HWCAP when present
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (12 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 13/16] MIPS: advertise MIPSr6 via HWCAP when appropriate Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 15/16] MIPS: require O32 FP64 support for MIPS64 with O32 compat Paul Burton
  2015-07-10 15:00 ` [PATCH 16/16] MIPS: drop EXPERIMENTAL tag from O32+FP64 & MSA Paul Burton
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Leonid Yegoshin, Maciej W. Rozycki,
	linux-kernel, Huacai Chen, Markos Chandras, Ralf Baechle

If MSA is supported by both the hardware & the kernel then advertise
that support to userland via the AT_HWCAP aux vector.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/kernel/cpu-probe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 168a5d3..15e9efc 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -1496,6 +1496,7 @@ void cpu_probe(void)
 		c->msa_id = cpu_get_msa_id();
 		WARN(c->msa_id & MSA_IR_WRPF,
 		     "Vector register partitioning unimplemented!");
+		elf_hwcap |= HWCAP_MIPS_MSA;
 	}
 
 	cpu_probe_vmbits(c);
-- 
2.4.4


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

* [PATCH 15/16] MIPS: require O32 FP64 support for MIPS64 with O32 compat
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (13 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 14/16] MIPS: advertise MSA support via HWCAP when present Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  2015-07-10 15:00 ` [PATCH 16/16] MIPS: drop EXPERIMENTAL tag from O32+FP64 & MSA Paul Burton
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips
  Cc: Matthew Fortune, Paul Burton, Markos Chandras, stable,
	Ralf Baechle, linux-kernel

MIPS32r6 code requires FP64 (ie. FR=1) support. Building a kernel with
support for MIPS32r6 binaries but without support for O32 with FP64 is
therefore a problem which can lead to incorrectly executed userland.

CONFIG_MIPS_O32_FP64_SUPPORT is already selected when the kernel is
configured for MIPS32r6, but not when the kernel is configured for
MIPS64r6 with O32 compat support. Select CONFIG_MIPS_O32_FP64_SUPPORT in
such configurations to prevent building kernels which execute MIPS32r6
userland incorrectly.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: Markos Chandras <markos.chandras@imgtec.com>
Cc: <stable@vger.kernel.org> # v4.0-
---

 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index f501665..a3b1ffe 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1417,6 +1417,7 @@ config CPU_MIPS64_R6
 	select CPU_SUPPORTS_HIGHMEM
 	select CPU_SUPPORTS_MSA
 	select GENERIC_CSUM
+	select MIPS_O32_FP64_SUPPORT if MIPS32_O32
 	help
 	  Choose this option to build a kernel for release 6 or later of the
 	  MIPS64 architecture.  New MIPS processors, starting with the Warrior
-- 
2.4.4


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

* [PATCH 16/16] MIPS: drop EXPERIMENTAL tag from O32+FP64 & MSA
  2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
                   ` (14 preceding siblings ...)
  2015-07-10 15:00 ` [PATCH 15/16] MIPS: require O32 FP64 support for MIPS64 with O32 compat Paul Burton
@ 2015-07-10 15:00 ` Paul Burton
  15 siblings, 0 replies; 23+ messages in thread
From: Paul Burton @ 2015-07-10 15:00 UTC (permalink / raw)
  To: linux-mips; +Cc: Matthew Fortune, Paul Burton, Ralf Baechle, linux-kernel

CONFIG_MIPS_O32_FP64_SUPPORT and CONFIG_CPU_HAS_MSA are in pretty good
shape these days, and in much wider use than they once were. Stop
referring to them as EXPERIMENTAL.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

---

 arch/mips/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index a3b1ffe..1c657e0 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2301,7 +2301,7 @@ config CPU_MICROMIPS
 endchoice
 
 config CPU_HAS_MSA
-	bool "Support for the MIPS SIMD Architecture (EXPERIMENTAL)"
+	bool "Support for the MIPS SIMD Architecture"
 	depends on CPU_SUPPORTS_MSA
 	depends on 64BIT || MIPS_O32_FP64_SUPPORT
 	help
@@ -2641,7 +2641,7 @@ config SECCOMP
 	  If unsure, say Y. Only embedded should say N here.
 
 config MIPS_O32_FP64_SUPPORT
-	bool "Support for O32 binaries using 64-bit FP (EXPERIMENTAL)"
+	bool "Support for O32 binaries using 64-bit FP"
 	depends on 32BIT || MIPS32_O32
 	help
 	  When this is enabled, the kernel will support use of 64-bit floating
-- 
2.4.4


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

* Re: [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h
  2015-07-10 15:00 ` [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h Paul Burton
@ 2015-07-14 13:56   ` Ralf Baechle
  0 siblings, 0 replies; 23+ messages in thread
From: Ralf Baechle @ 2015-07-14 13:56 UTC (permalink / raw)
  To: Paul Burton; +Cc: linux-mips, Matthew Fortune, linux-kernel

On Fri, Jul 10, 2015 at 04:00:10PM +0100, Paul Burton wrote:

> The offsets to various fields within struct sigcontext are declared
> using asm-offsets.c these days, so drop the outdated comment that talks
> about keeping in sync with a no longer present file.

What's outdated is the path but the offsets still need to be extracted
by asm-offset.c and that requires the field names to be kept in sync
in both files.

  Ralf

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

* Re: [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context
  2015-07-10 15:00 ` [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context Paul Burton
@ 2015-07-19  0:21   ` Paul Gortmaker
  2015-07-19  0:25     ` Ralf Baechle
  0 siblings, 1 reply; 23+ messages in thread
From: Paul Gortmaker @ 2015-07-19  0:21 UTC (permalink / raw)
  To: Paul Burton
  Cc: linux-mips, Matthew Fortune, Leonid Yegoshin, Michael Ellerman,
	LKML, Richard Weinberger, James Hogan, Andy Lutomirski,
	Markos Chandras, Ralf Baechle, Manuel Lauss, Maciej W. Rozycki,
	linux-next

On Fri, Jul 10, 2015 at 11:00 AM, Paul Burton <paul.burton@imgtec.com> wrote:
> When saving FP state to struct sigcontext, make use of the offsets
> provided by struct mips_abi to obtain appropriate addresses for the
> sc_fpregs & sc_fpc_csr fields of the sigcontext. This is done only for
> the native struct sigcontext in this patch (ie. for O32 in CONFIG_32BIT
> kernels or for N64 in CONFIG_64BIT kernels) but is done in preparation
> for sharing this code with compat ABIs in further patches.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> ---
>
>  arch/mips/kernel/r4k_fpu.S       | 151 +++++++++++++++++++++------------------
>  arch/mips/kernel/signal-common.h |   6 ++
>  arch/mips/kernel/signal.c        |  85 +++++++++++++++-------
>  3 files changed, 145 insertions(+), 97 deletions(-)
>

 The current version of this in linux-next picked up a booger in transit.

$ git show 6775b4ea74d5922e5310b7b7a902a8fbe61a0c9d|diffstat
 arch/mips/kernel/r4k_fpu.S       |  151 ++++++++++++++++++++-------------------
 arch/mips/kernel/signal-common.h |    6 +
 arch/mips/kernel/signal.c        |   85 ++++++++++++++-------
 index.html                       |   16 ++++
 4 files changed, 161 insertions(+), 97 deletions(-)

Guessing it happened at Ralf's end.

Paul.
--

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

* Re: [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context
  2015-07-19  0:21   ` Paul Gortmaker
@ 2015-07-19  0:25     ` Ralf Baechle
  0 siblings, 0 replies; 23+ messages in thread
From: Ralf Baechle @ 2015-07-19  0:25 UTC (permalink / raw)
  To: Paul Gortmaker
  Cc: Paul Burton, linux-mips, Matthew Fortune, Leonid Yegoshin,
	Michael Ellerman, LKML, Richard Weinberger, James Hogan,
	Andy Lutomirski, Markos Chandras, Manuel Lauss,
	Maciej W. Rozycki, linux-next

On Sat, Jul 18, 2015 at 08:21:53PM -0400, Paul Gortmaker wrote:
> Date:   Sat, 18 Jul 2015 20:21:53 -0400
> From: Paul Gortmaker <paul.gortmaker@windriver.com>
> To: Paul Burton <paul.burton@imgtec.com>
> Cc: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>, Matthew
>  Fortune <matthew.fortune@imgtec.com>, Leonid Yegoshin
>  <Leonid.Yegoshin@imgtec.com>, Michael Ellerman <mpe@ellerman.id.au>, LKML
>  <linux-kernel@vger.kernel.org>, Richard Weinberger <richard@nod.at>, James
>  Hogan <james.hogan@imgtec.com>, Andy Lutomirski <luto@amacapital.net>,
>  Markos Chandras <markos.chandras@imgtec.com>, Ralf Baechle
>  <ralf@linux-mips.org>, Manuel Lauss <manuel.lauss@gmail.com>, "Maciej W.
>  Rozycki" <macro@codesourcery.com>, "linux-next@vger.kernel.org"
>  <linux-next@vger.kernel.org>
> Subject: Re: [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP
>  context
> Content-Type: text/plain; charset=UTF-8
> 
> On Fri, Jul 10, 2015 at 11:00 AM, Paul Burton <paul.burton@imgtec.com> wrote:
> > When saving FP state to struct sigcontext, make use of the offsets
> > provided by struct mips_abi to obtain appropriate addresses for the
> > sc_fpregs & sc_fpc_csr fields of the sigcontext. This is done only for
> > the native struct sigcontext in this patch (ie. for O32 in CONFIG_32BIT
> > kernels or for N64 in CONFIG_64BIT kernels) but is done in preparation
> > for sharing this code with compat ABIs in further patches.
> >
> > Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> > ---
> >
> >  arch/mips/kernel/r4k_fpu.S       | 151 +++++++++++++++++++++------------------
> >  arch/mips/kernel/signal-common.h |   6 ++
> >  arch/mips/kernel/signal.c        |  85 +++++++++++++++-------
> >  3 files changed, 145 insertions(+), 97 deletions(-)
> >
> 
>  The current version of this in linux-next picked up a booger in transit.
> 
> $ git show 6775b4ea74d5922e5310b7b7a902a8fbe61a0c9d|diffstat
>  arch/mips/kernel/r4k_fpu.S       |  151 ++++++++++++++++++++-------------------
>  arch/mips/kernel/signal-common.h |    6 +
>  arch/mips/kernel/signal.c        |   85 ++++++++++++++-------
>  index.html                       |   16 ++++
>  4 files changed, 161 insertions(+), 97 deletions(-)
> 
> Guessing it happened at Ralf's end.

Yes and I fixed a few hours ago.  Should be ok in the next -next.

  Ralf

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

* Re: [PATCH 10/16] compile error: MIPS: add definitions for extended context
  2015-07-10 15:00 ` [PATCH 10/16] MIPS: add definitions for extended context Paul Burton
@ 2015-10-25 21:10   ` Hauke Mehrtens
  2015-10-25 21:47     ` Florian Fainelli
  0 siblings, 1 reply; 23+ messages in thread
From: Hauke Mehrtens @ 2015-10-25 21:10 UTC (permalink / raw)
  To: Paul Burton, linux-mips, Ralf Baechle
  Cc: Matthew Fortune, Peter Zijlstra, Zubair Lutfullah Kakakhel,
	Alex Smith, linux-kernel, Michal Nazarewicz, Richard Weinberger,
	Andrew Morton, Andy Lutomirski, Daniel Borkmann, Markos Chandras,
	Frederic Weisbecker, Michael Ellerman, Maciej W. Rozycki

This patch is causing a build error for me on 4.3-rc7.

  CC      arch/mips/kernel/signal.o
arch/mips/kernel/signal.c: In function 'sc_to_extcontext':
arch/mips/kernel/signal.c:143:12: error: 'struct ucontext' has no member
named 'uc_extcontext'
  return &uc->uc_extcontext;
            ^
In file included from include/linux/poll.h:11:0,
                 from include/linux/ring_buffer.h:7,
                 from include/linux/trace_events.h:5,
                 from include/trace/syscall.h:6,
                 from include/linux/syscalls.h:81,
                 from arch/mips/kernel/signal.c:26:
arch/mips/kernel/signal.c: In function 'save_msa_extcontext':
arch/mips/kernel/signal.c:171:40: error: dereferencing pointer to
incomplete type 'struct msa_extcontext'
   err = __put_user(read_msa_csr(), &msa->csr);
                                        ^
./arch/mips/include/asm/uaccess.h:441:15: note: in definition of macro
'__put_user_nocheck'
  __typeof__(*(ptr)) __pu_val;     \
               ^
arch/mips/kernel/signal.c:171:9: note: in expansion of macro '__put_user'
   err = __put_user(read_msa_csr(), &msa->csr);
         ^
arch/mips/kernel/signal.c:186:20: error: 'MSA_EXTCONTEXT_MAGIC'
undeclared (first use in this function)
  err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
                    ^
./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
'__put_user_nocheck'
  __pu_val = (x);       \
              ^
arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
  err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
         ^
arch/mips/kernel/signal.c:186:20: note: each undeclared identifier is
reported only once for each function it appears in
  err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
                    ^
./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
'__put_user_nocheck'
  __pu_val = (x);       \
              ^
arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
  err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
         ^
.......


When I include uapi/asm/ucontext.h instead of asm/ucontext.h in signal.c
it compiles again.

Hauke

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

* Re: [PATCH 10/16] compile error: MIPS: add definitions for extended context
  2015-10-25 21:10   ` [PATCH 10/16] compile error: " Hauke Mehrtens
@ 2015-10-25 21:47     ` Florian Fainelli
  2015-10-25 22:18       ` Hauke Mehrtens
  0 siblings, 1 reply; 23+ messages in thread
From: Florian Fainelli @ 2015-10-25 21:47 UTC (permalink / raw)
  To: Hauke Mehrtens, Paul Burton, linux-mips, Ralf Baechle
  Cc: Matthew Fortune, Peter Zijlstra, Zubair Lutfullah Kakakhel,
	Alex Smith, linux-kernel, Michal Nazarewicz, Richard Weinberger,
	Andrew Morton, Andy Lutomirski, Daniel Borkmann, Markos Chandras,
	Frederic Weisbecker, Michael Ellerman, Maciej W. Rozycki

Le 25/10/2015 14:10, Hauke Mehrtens a écrit :
> This patch is causing a build error for me on 4.3-rc7.
> 
>   CC      arch/mips/kernel/signal.o
> arch/mips/kernel/signal.c: In function 'sc_to_extcontext':
> arch/mips/kernel/signal.c:143:12: error: 'struct ucontext' has no member
> named 'uc_extcontext'
>   return &uc->uc_extcontext;
>             ^
> In file included from include/linux/poll.h:11:0,
>                  from include/linux/ring_buffer.h:7,
>                  from include/linux/trace_events.h:5,
>                  from include/trace/syscall.h:6,
>                  from include/linux/syscalls.h:81,
>                  from arch/mips/kernel/signal.c:26:
> arch/mips/kernel/signal.c: In function 'save_msa_extcontext':
> arch/mips/kernel/signal.c:171:40: error: dereferencing pointer to
> incomplete type 'struct msa_extcontext'
>    err = __put_user(read_msa_csr(), &msa->csr);
>                                         ^
> ./arch/mips/include/asm/uaccess.h:441:15: note: in definition of macro
> '__put_user_nocheck'
>   __typeof__(*(ptr)) __pu_val;     \
>                ^
> arch/mips/kernel/signal.c:171:9: note: in expansion of macro '__put_user'
>    err = __put_user(read_msa_csr(), &msa->csr);
>          ^
> arch/mips/kernel/signal.c:186:20: error: 'MSA_EXTCONTEXT_MAGIC'
> undeclared (first use in this function)
>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>                     ^
> ./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
> '__put_user_nocheck'
>   __pu_val = (x);       \
>               ^
> arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>          ^
> arch/mips/kernel/signal.c:186:20: note: each undeclared identifier is
> reported only once for each function it appears in
>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>                     ^
> ./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
> '__put_user_nocheck'
>   __pu_val = (x);       \
>               ^
> arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>          ^
> .......
> 
> 
> When I include uapi/asm/ucontext.h instead of asm/ucontext.h in signal.c
> it compiles again.

The problem appears if you had previously auto-generated files in
arch/mips/include/generated that do not get automatically cleaned up
when you switch to a new kernel version, and with an incompatible
ucontext layout between the two.

Jacek tripped over that here:

https://www.linux-mips.org/archives/linux-mips/2015-09/msg00150.html

and I asked whether we could follow-up with a proper Kbuild patch to
address that build dependency here:

https://www.linux-mips.org/archives/linux-mips/2015-09/msg00165.html

but this does not appear to have been proposed or addressed yet.

Paul, could you look into this and see how we could teach Kbuild about
this build dependency?
-- 
Florian

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

* Re: [PATCH 10/16] compile error: MIPS: add definitions for extended context
  2015-10-25 21:47     ` Florian Fainelli
@ 2015-10-25 22:18       ` Hauke Mehrtens
  0 siblings, 0 replies; 23+ messages in thread
From: Hauke Mehrtens @ 2015-10-25 22:18 UTC (permalink / raw)
  To: Florian Fainelli, Paul Burton, linux-mips, Ralf Baechle
  Cc: Matthew Fortune, Peter Zijlstra, Zubair Lutfullah Kakakhel,
	Alex Smith, linux-kernel, Michal Nazarewicz, Richard Weinberger,
	Andrew Morton, Andy Lutomirski, Daniel Borkmann, Markos Chandras,
	Frederic Weisbecker, Michael Ellerman, Maciej W. Rozycki

On 10/25/2015 10:47 PM, Florian Fainelli wrote:
> Le 25/10/2015 14:10, Hauke Mehrtens a écrit :
>> This patch is causing a build error for me on 4.3-rc7.
>>
>>   CC      arch/mips/kernel/signal.o
>> arch/mips/kernel/signal.c: In function 'sc_to_extcontext':
>> arch/mips/kernel/signal.c:143:12: error: 'struct ucontext' has no member
>> named 'uc_extcontext'
>>   return &uc->uc_extcontext;
>>             ^
>> In file included from include/linux/poll.h:11:0,
>>                  from include/linux/ring_buffer.h:7,
>>                  from include/linux/trace_events.h:5,
>>                  from include/trace/syscall.h:6,
>>                  from include/linux/syscalls.h:81,
>>                  from arch/mips/kernel/signal.c:26:
>> arch/mips/kernel/signal.c: In function 'save_msa_extcontext':
>> arch/mips/kernel/signal.c:171:40: error: dereferencing pointer to
>> incomplete type 'struct msa_extcontext'
>>    err = __put_user(read_msa_csr(), &msa->csr);
>>                                         ^
>> ./arch/mips/include/asm/uaccess.h:441:15: note: in definition of macro
>> '__put_user_nocheck'
>>   __typeof__(*(ptr)) __pu_val;     \
>>                ^
>> arch/mips/kernel/signal.c:171:9: note: in expansion of macro '__put_user'
>>    err = __put_user(read_msa_csr(), &msa->csr);
>>          ^
>> arch/mips/kernel/signal.c:186:20: error: 'MSA_EXTCONTEXT_MAGIC'
>> undeclared (first use in this function)
>>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>>                     ^
>> ./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
>> '__put_user_nocheck'
>>   __pu_val = (x);       \
>>               ^
>> arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
>>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>>          ^
>> arch/mips/kernel/signal.c:186:20: note: each undeclared identifier is
>> reported only once for each function it appears in
>>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>>                     ^
>> ./arch/mips/include/asm/uaccess.h:444:14: note: in definition of macro
>> '__put_user_nocheck'
>>   __pu_val = (x);       \
>>               ^
>> arch/mips/kernel/signal.c:186:9: note: in expansion of macro '__put_user'
>>   err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
>>          ^
>> .......
>>
>>
>> When I include uapi/asm/ucontext.h instead of asm/ucontext.h in signal.c
>> it compiles again.
> 
> The problem appears if you had previously auto-generated files in
> arch/mips/include/generated that do not get automatically cleaned up
> when you switch to a new kernel version, and with an incompatible
> ucontext layout between the two.
> 
> Jacek tripped over that here:
> 
> https://www.linux-mips.org/archives/linux-mips/2015-09/msg00150.html
> 
> and I asked whether we could follow-up with a proper Kbuild patch to
> address that build dependency here:
> 
> https://www.linux-mips.org/archives/linux-mips/2015-09/msg00165.html
> 
> but this does not appear to have been proposed or addressed yet.
> 
> Paul, could you look into this and see how we could teach Kbuild about
> this build dependency?
> 

Yes that was the problem, after doing this I worked again:
rm arch/mips/include/generated/ -rf

Hauke

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

end of thread, other threads:[~2015-10-25 22:18 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 15:00 [PATCH 00/16] MSA vector context signal handling & HWCAPs Paul Burton
2015-07-10 15:00 ` [PATCH 01/16] MIPS: remove outdated comments in sigcontext.h Paul Burton
2015-07-14 13:56   ` Ralf Baechle
2015-07-10 15:00 ` [PATCH 02/16] MIPS: simplify EVA FP context handling code Paul Burton
2015-07-10 15:00 ` [PATCH 03/16] MIPS: add offsets to sigcontext FP fields to struct mips_abi Paul Burton
2015-07-10 15:00 ` [PATCH 04/16] MIPS: use struct mips_abi offsets to save FP context Paul Burton
2015-07-19  0:21   ` Paul Gortmaker
2015-07-19  0:25     ` Ralf Baechle
2015-07-10 15:00 ` [PATCH 05/16] MIPS: move FP usage checks into protected_{save,restore}_fp_context Paul Burton
2015-07-10 15:00 ` [PATCH 06/16] MIPS: skip odd double FP registers when copying FP32 sigcontext Paul Burton
2015-07-10 15:00 ` [PATCH 07/16] MIPS: use common FP sigcontext code for O32 compat Paul Burton
2015-07-10 15:00 ` [PATCH 08/16] MIPS: remove unused {get,put}_sigset functions Paul Burton
2015-07-10 15:00 ` [PATCH 09/16] MIPS: indicate FP mode in sigcontext sc_used_math Paul Burton
2015-07-10 15:00 ` [PATCH 10/16] MIPS: add definitions for extended context Paul Burton
2015-10-25 21:10   ` [PATCH 10/16] compile error: " Hauke Mehrtens
2015-10-25 21:47     ` Florian Fainelli
2015-10-25 22:18       ` Hauke Mehrtens
2015-07-10 15:00 ` [PATCH 11/16] MIPS: save MSA extended context around signals Paul Burton
2015-07-10 15:00 ` [PATCH 12/16] MIPS: AT_HWCAP aux vector infrastructure Paul Burton
2015-07-10 15:00 ` [PATCH 13/16] MIPS: advertise MIPSr6 via HWCAP when appropriate Paul Burton
2015-07-10 15:00 ` [PATCH 14/16] MIPS: advertise MSA support via HWCAP when present Paul Burton
2015-07-10 15:00 ` [PATCH 15/16] MIPS: require O32 FP64 support for MIPS64 with O32 compat Paul Burton
2015-07-10 15:00 ` [PATCH 16/16] MIPS: drop EXPERIMENTAL tag from O32+FP64 & MSA Paul Burton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).