提交 84ab45b3 编写于 作者: P Paul Burton 提交者: Ralf Baechle

MIPS: disable FPU if the mode is unsupported

The expected semantics of __enable_fpu are for the FPU to be enabled
in the given mode if possible, otherwise for the FPU to be left
disabled and SIGFPE returned. The FPU was incorrectly being left
enabled in cases where the desired value for FR was unavailable.
Without ensuring the FPU is disabled in this case, it would be
possible for userland to go on to execute further FP instructions
natively in the incorrect mode, rather than those instructions being
trapped & emulated as they need to be.
Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/9167/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
上级 ac9ad83b
...@@ -48,6 +48,12 @@ enum fpu_mode { ...@@ -48,6 +48,12 @@ enum fpu_mode {
#define FPU_FR_MASK 0x1 #define FPU_FR_MASK 0x1
}; };
#define __disable_fpu() \
do { \
clear_c0_status(ST0_CU1); \
disable_fpu_hazard(); \
} while (0)
static inline int __enable_fpu(enum fpu_mode mode) static inline int __enable_fpu(enum fpu_mode mode)
{ {
int fr; int fr;
...@@ -86,7 +92,12 @@ static inline int __enable_fpu(enum fpu_mode mode) ...@@ -86,7 +92,12 @@ static inline int __enable_fpu(enum fpu_mode mode)
enable_fpu_hazard(); enable_fpu_hazard();
/* check FR has the desired value */ /* check FR has the desired value */
return (!!(read_c0_status() & ST0_FR) == !!fr) ? 0 : SIGFPE; if (!!(read_c0_status() & ST0_FR) == !!fr)
return 0;
/* unsupported FR value */
__disable_fpu();
return SIGFPE;
default: default:
BUG(); BUG();
...@@ -95,12 +106,6 @@ static inline int __enable_fpu(enum fpu_mode mode) ...@@ -95,12 +106,6 @@ static inline int __enable_fpu(enum fpu_mode mode)
return SIGFPE; return SIGFPE;
} }
#define __disable_fpu() \
do { \
clear_c0_status(ST0_CU1); \
disable_fpu_hazard(); \
} while (0)
#define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU) #define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
static inline int __is_fpu_owner(void) static inline int __is_fpu_owner(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册