sparc64: Fix userspace FPU register corruptions.
David Miller
maintainerPATCH 1/1 sparc64: Fix userspace FPU register corruptions.
If we have a series of events from userpsace, with %fprs=FPRS_FEF, like follows:
ETRAP
ETRAP VIS_ENTRY(fprs=0x4) VIS_EXIT RTRAP (kernel FPU restore with fpu_saved=0x4) RTRAP
We will not restore the user registers that were clobbered by the FPU using kernel code in the inner-most trap.
Traps allocate FPU save slots in the thread struct, and FPU using sequences save the "dirty" FPU registers only.
This works at the initial trap level because all of the registers get recorded into the top-level FPU save area, and we'll return to userspace with the FPU disabled so that any FPU use by the user will take an FPU disabled trap wherein we'll load the registers back up properly.
But this is not how trap returns from kernel to kernel operate.
The simplest fix for this bug is to always save all FPU register state for anything other than the top-most FPU save area.
Getting rid of the optimized inner-slot FPU saving code ends up making VISEntryHalf degenerate into plain VISEntry.
Longer term we need to do something smarter to reinstate the partial save optimizations. Perhaps the fundament error is having trap entry and exit allocate FPU save slots and restore register state. Instead, the VISEntry et al. calls should be doing that work.
This bug is about two decades old.
---
I'll get this to Linus and -stable ASAP...
arch/sparc/include/asm/visasm.h | 16 +++------- arch/sparc/lib/NG4memcpy.S | 5 ++- arch/sparc/lib/VISsave.S | 67 ++--------------------------------------- arch/sparc/lib/ksyms.c | 4 --- 4 files changed, 11 insertions(+), 81 deletions(-)
arch/sparc/include/asm/visasm.h +5 -11
@@ -28,16 +28,10 @@* Must preserve %o5 between VISEntryHalf and VISExitHalf */ #define VISEntryHalf \ - rd %fprs, %o5; \ - andcc %o5, FPRS_FEF, %g0; \ - be,pt %icc, 297f; \ - sethi %hi(298f), %g7; \ - sethi %hi(VISenterhalf), %g1; \ - jmpl %g1 + %lo(VISenterhalf), %g0; \ - or %g7, %lo(298f), %g7; \ - clr %o5; \ -297: wr %o5, FPRS_FEF, %fprs; \ -298: + VISEntry + +#define VISExitHalf \ + VISExit#define VISEntryHalfFast (fail_label) \ rd %fprs, %o5; \
@@ -47,7 +41,7 @@ ba,a,pt %xcc, fail_label; \ 297: wr %o5, FPRS_FEF, %fprs; -#define VISExitHalf \ +#define VISExitHalfFast \ wr %o5, 0, %fprs;#ifndef __ASSEMBLY__
arch/sparc/lib/NG4memcpy.S +4 -1
@@ -240,8 +240,11 @@ FUNC_NAME: /* %o0=dst, %o1=src, %o2=len */ add %o0, 0x40, %o0 bne,pt %icc, 1b LOAD(prefetch, %g1 + 0x200, #n_reads_strong) +#ifdef NON_USER_COPY + VISExitHalfFast +#else VISExitHalf - +#endif brz,pn %o2, .Lexit cmp %o2, 19 ble,pn %icc, .Lsmall_unaligned
arch/sparc/lib/VISsave.S +2 -65
76 lines not on this page · raw message
arch/sparc/lib/ksyms.c +0 -4
@@ -135,10 +135,6 @@ EXPORT_SYMBOL(copy_user_page);void VISenter (void );EXPORT_SYMBOL (VISenter); -/* CRYPTO code needs this */ -void VISenterhalf (void ); -EXPORT_SYMBOL (VISenterhalf); -extern void xor_vis_2 (unsigned long ,unsigned long *,unsigned long *);extern void xor_vis_3 (unsigned long ,unsigned long *,unsigned long *,unsigned long *);
Signature · 1 line
2.1.0