[PATCH v3 1/3] arm64: restore FPSIMD to default state for kernel and signal contexts
Jiang Liu
liuj97 at gmail.com
Tue Oct 15 23:26:43 EDT 2013
From: Jiang Liu <jiang.liu at 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 at huawei.com>
Cc: Jiang Liu <liuj97 at 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 = ¤t->thread.fpsimd_state;
+
preempt_disable();
- memset(¤t->thread.fpsimd_state, 0, sizeof(struct fpsimd_state));
- fpsimd_load_state(¤t->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(¤t->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
More information about the linux-arm-kernel
mailing list