linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/3] arm64: restore FPSIMD to default state for kernel and signal contexts
@ 2013-10-16  3:26 Jiang Liu
  2013-10-16  3:26 ` [PATCH v3 2/3] arm64: reduce duplicated code when saving/restoring FPSIMD for signal handling Jiang Liu
  2013-10-16  3:26 ` [PATCH v3 3/3] arm64: reuse FPSIMD hardware context if possible Jiang Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Jiang Liu @ 2013-10-16  3:26 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jiang Liu <jiang.liu@huawei.com>

Restore FPSIMD control and status registers to default values
when creating new FPSIMD contexts for kernel context and reset
FPSIMD status register when creating FPSIMD context for signal
handling, otherwise the stale value in FPSIMD control and status
registers may affect the new kernal or signal handling contexts.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Jiang Liu <liuj97@gmail.com>
---
 arch/arm64/include/asm/fpsimd.h |  4 ++++
 arch/arm64/kernel/fpsimd.c      | 30 ++++++++++++++++++++++++++++--
 arch/arm64/kernel/signal.c      |  1 +
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h
index c43b4ac..b3c12fd 100644
--- a/arch/arm64/include/asm/fpsimd.h
+++ b/arch/arm64/include/asm/fpsimd.h
@@ -50,6 +50,8 @@ struct fpsimd_state {
 #define VFP_STATE_SIZE		((32 * 8) + 4)
 #endif
 
+#define	AARCH64_FPCR_DEFAULT_VAL	0
+
 struct task_struct;
 
 extern void fpsimd_save_state(struct fpsimd_state *state);
@@ -58,6 +60,8 @@ extern void fpsimd_load_state(struct fpsimd_state *state);
 extern void fpsimd_thread_switch(struct task_struct *next);
 extern void fpsimd_flush_thread(void);
 
+extern void fpsimd_init_sigctx(struct fpsimd_state *state);
+
 #endif
 
 #endif
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index bb785d2..9daee2c 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -33,6 +33,21 @@
 #define FPEXC_IXF	(1 << 4)
 #define FPEXC_IDF	(1 << 7)
 
+static inline void fpsimd_init_hw_state(void)
+{
+	int val = AARCH64_FPCR_DEFAULT_VAL;
+
+	asm volatile ("msr fpcr, %x0\n"
+		      "msr fpsr, xzr\n"
+		      : : "r"(val) : "memory");
+}
+
+static inline void fpsimd_clear_fpsr(void)
+{
+	asm volatile ("msr fpsr, xzr\n"
+		      : : : "memory");
+}
+
 /*
  * Trapped FP/ASIMD access.
  */
@@ -80,12 +95,21 @@ void fpsimd_thread_switch(struct task_struct *next)
 
 void fpsimd_flush_thread(void)
 {
+	struct fpsimd_state *state = &current->thread.fpsimd_state;
+
 	preempt_disable();
-	memset(&current->thread.fpsimd_state, 0, sizeof(struct fpsimd_state));
-	fpsimd_load_state(&current->thread.fpsimd_state);
+	memset(state, 0, sizeof(struct fpsimd_state));
+	if (AARCH64_FPCR_DEFAULT_VAL)
+		state->fpcr = AARCH64_FPCR_DEFAULT_VAL;
+	fpsimd_load_state(state);
 	preempt_enable();
 }
 
+void fpsimd_init_sigctx(struct fpsimd_state *state)
+{
+	fpsimd_clear_fpsr();
+}
+
 #ifdef CONFIG_KERNEL_MODE_NEON
 
 /*
@@ -99,6 +123,8 @@ void kernel_neon_begin(void)
 
 	if (current->mm)
 		fpsimd_save_state(&current->thread.fpsimd_state);
+
+	fpsimd_init_hw_state();
 }
 EXPORT_SYMBOL(kernel_neon_begin);
 
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 890a591..f2c83e8 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -320,6 +320,7 @@ static void handle_signal(unsigned long sig, struct k_sigaction *ka,
 	 * handler.
 	 */
 	user_fastforward_single_step(tsk);
+	fpsimd_init_sigctx(&tsk->thread.fpsimd_state);
 
 	signal_delivered(sig, info, ka, regs, 0);
 }
-- 
1.8.1.2

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

end of thread, other threads:[~2013-10-16  3:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-16  3:26 [PATCH v3 1/3] arm64: restore FPSIMD to default state for kernel and signal contexts Jiang Liu
2013-10-16  3:26 ` [PATCH v3 2/3] arm64: reduce duplicated code when saving/restoring FPSIMD for signal handling Jiang Liu
2013-10-16  3:26 ` [PATCH v3 3/3] arm64: reuse FPSIMD hardware context if possible Jiang Liu

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).