Skip to content

Commit ab3da15

Browse files
author
Ard Biesheuvel
committed
ARM: be strict about FP exceptions in kernel mode
The support code in vfp_support_entry does not care whether the exception that caused it to be invoked occurred in kernel mode or in user mode. However, neither condition that could trigger this exception (lazy restore and VFP bounce to support code) is currently allowable in kernel mode. In either case, print a message describing the condition before letting the undefined instruction handler run its course and trigger an oops. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Nicolas Pitre <nico@linaro.org>
1 parent 0773d73 commit ab3da15

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎arch/arm/vfp/vfphw.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
ENTRY(vfp_support_entry)
7979
DBGSTR3 "instr %08x pc %08x state %p", r0, r2, r10
8080

81+
ldr r3, [sp, #S_PSR] @ Neither lazy restore nor FP exceptions
82+
and r3, r3, #MODE_MASK @ are supported in kernel mode
83+
teq r3, #USR_MODE
84+
bne vfp_kmode_exception @ Returns through lr
85+
8186
VFPFMRX r1, FPEXC @ Is the VFP enabled?
8287
DBGSTR1 "fpexc %08x", r1
8388
tst r1, #FPEXC_EN

‎arch/arm/vfp/vfpmodule.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,26 @@ static int vfp_hotplug(struct notifier_block *b, unsigned long action,
648648
return NOTIFY_OK;
649649
}
650650

651+
void vfp_kmode_exception(void)
652+
{
653+
/*
654+
* If we reach this point, a floating point exception has been raised
655+
* while running in kernel mode. If the NEON/VFP unit was enabled at the
656+
* time, it means a VFP instruction has been issued that requires
657+
* software assistance to complete, something which is not currently
658+
* supported in kernel mode.
659+
* If the NEON/VFP unit was disabled, and the location pointed to below
660+
* is properly preceded by a call to kernel_neon_begin(), something has
661+
* caused the task to be scheduled out and back in again. In this case,
662+
* rebuilding and running with CONFIG_DEBUG_ATOMIC_SLEEP enabled should
663+
* be helpful in localizing the problem.
664+
*/
665+
if (fmrx(FPEXC) & FPEXC_EN)
666+
pr_crit("BUG: unsupported FP instruction in kernel mode\n");
667+
else
668+
pr_crit("BUG: FP instruction issued in kernel mode with FP unit disabled\n");
669+
}
670+
651671
/*
652672
* VFP support code initialisation.
653673
*/

0 commit comments

Comments
 (0)