Skip to content

Commit ff9a184

Browse files
wildea01Russell King
authored andcommitted
ARM: 7400/1: vfp: clear fpscr length and stride bits on entry to sig handler
The ARM PCS mandates that the length and stride bits of the fpscr are cleared on entry to and return from a public interface. Although signal handlers run asynchronously with respect to the interrupted function, the handler itself expects to run as though it has been called like a normal function. This patch updates the state mirroring the VFP hardware before entry to a signal handler so that it adheres to the PCS. Furthermore, we disable VFP to ensure that we trap on any floating point operation performed by the signal handler and synchronise the hardware appropriately. A check is inserted after the signal handler to avoid redundant flushing if VFP was not used. Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 2498814 commit ff9a184

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎arch/arm/vfp/vfpmodule.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,21 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
564564

565565
if (err)
566566
return -EFAULT;
567+
568+
/* Ensure that VFP is disabled. */
569+
vfp_flush_hwstate(thread);
570+
571+
/*
572+
* As per the PCS, clear the length and stride bits for function
573+
* entry.
574+
*/
575+
hwstate->fpscr &= ~(FPSCR_LENGTH_MASK | FPSCR_STRIDE_MASK);
576+
577+
/*
578+
* Disable VFP in the hwstate so that we can detect if it gets
579+
* used.
580+
*/
581+
hwstate->fpexc &= ~FPEXC_EN;
567582
return 0;
568583
}
569584

@@ -576,7 +591,12 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
576591
unsigned long fpexc;
577592
int err = 0;
578593

579-
vfp_flush_hwstate(thread);
594+
/*
595+
* If VFP has been used, then disable it to avoid corrupting
596+
* the new thread state.
597+
*/
598+
if (hwstate->fpexc & FPEXC_EN)
599+
vfp_flush_hwstate(thread);
580600

581601
/*
582602
* Copy the floating point registers. There can be unused

0 commit comments

Comments
 (0)