2005-04-17 06:20:36 +08:00
|
|
|
/* U1copy_from_user.S: UltraSparc-I/II/IIi/IIe optimized copy from userspace.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EX_LD(x) \
|
|
|
|
98: x; \
|
2006-03-05 15:23:56 +08:00
|
|
|
.section __ex_table,"a";\
|
2005-04-17 06:20:36 +08:00
|
|
|
.align 4; \
|
2009-02-09 14:00:55 +08:00
|
|
|
.word 98b, __retl_one; \
|
2005-04-17 06:20:36 +08:00
|
|
|
.text; \
|
|
|
|
.align 4;
|
|
|
|
|
sparc64: fix FP corruption in user copy functions
Short story: Exception handlers used by some copy_to_user() and
copy_from_user() functions do not diligently clean up floating point
register usage, and this can result in a user process seeing invalid
values in floating point registers. This sometimes makes the process
fail.
Long story: Several cpu-specific (NG4, NG2, U1, U3) memcpy functions
use floating point registers and VIS alignaddr/faligndata to
accelerate data copying when source and dest addresses don't align
well. Linux uses a lazy scheme for saving floating point registers; It
is not done upon entering the kernel since it's a very expensive
operation. Rather, it is done only when needed. If the kernel ends up
not using FP regs during the course of some trap or system call, then
it can return to user space without saving or restoring them.
The various memcpy functions begin their FP code with VISEntry (or a
variation thereof), which saves the FP regs. They conclude their FP
code with VISExit (or a variation) which essentially marks the FP regs
"clean", ie, they contain no unsaved values. fprs.FPRS_FEF is turned
off so that a lazy restore will be triggered when/if the user process
accesses floating point regs again.
The bug is that the user copy variants of memcpy, copy_from_user() and
copy_to_user(), employ an exception handling mechanism to detect faults
when accessing user space addresses, and when this handler is invoked,
an immediate return from the function is forced, and VISExit is not
executed, thus leaving the fprs register in an indeterminate state,
but often with fprs.FPRS_FEF set and one or more dirty bits. This
results in a return to user space with invalid values in the FP regs,
and since fprs.FPRS_FEF is on, no lazy restore occurs.
This bug affects copy_to_user() and copy_from_user() for NG4, NG2,
U3, and U1. All are fixed by using a new exception handler for those
loads and stores that are done during the time between VISEnter and
VISExit.
n.b. In NG4memcpy, the problematic code can be triggered by a copy
size greater than 128 bytes and an unaligned source address. This bug
is known to be the cause of random user process memory corruptions
while perf is running with the callgraph option (ie, perf record -g).
This occurs because perf uses copy_from_user() to read user stacks,
and may fault when it follows a stack frame pointer off to an
invalid page. Validation checks on the stack address just obscure
the underlying problem.
Signed-off-by: Rob Gardner <rob.gardner@oracle.com>
Signed-off-by: Dave Aldridge <david.j.aldridge@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-12-23 14:24:49 +08:00
|
|
|
#define EX_LD_FP(x) \
|
|
|
|
98: x; \
|
|
|
|
.section __ex_table,"a";\
|
|
|
|
.align 4; \
|
|
|
|
.word 98b, __retl_one_fp;\
|
|
|
|
.text; \
|
|
|
|
.align 4;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define FUNC_NAME ___copy_from_user
|
|
|
|
#define LOAD(type,addr,dest) type##a [addr] %asi, dest
|
|
|
|
#define LOAD_BLK(addr,dest) ldda [addr] ASI_BLK_AIUS, dest
|
|
|
|
#define EX_RETVAL(x) 0
|
|
|
|
|
|
|
|
/* Writing to %asi is _expensive_ so we hardcode it.
|
|
|
|
* Reading %asi to check for KERNEL_DS is comparatively
|
|
|
|
* cheap.
|
|
|
|
*/
|
|
|
|
#define PREAMBLE \
|
|
|
|
rd %asi, %g1; \
|
|
|
|
cmp %g1, ASI_AIUS; \
|
2009-02-09 14:32:31 +08:00
|
|
|
bne,pn %icc, ___copy_in_user; \
|
2005-04-17 06:20:36 +08:00
|
|
|
nop; \
|
|
|
|
|
|
|
|
#include "U1memcpy.S"
|