[PATCH RFC 2/2] x86/fpu: change xsave_user() and xrestore_user() to use __user_insn()

From: Oleg Nesterov
Date: Sun Mar 15 2015 - 12:52:51 EST


Change xsave_user() and xrestore_user() to avoid the (imho) horrible
and should-die xstate_fault helper, they both can use __user_insn().

This also removes the "memory" clobber but I think it was never needed.
xrestore_user() doesn't change the memory, it only changes the FPU regs.
xsave_user() does write to "*buf" but this memory is "__user", we must
never access it directly.

This patch adds '"=m" (*buf)' in both cases, but this is only because
currently __user_insn() needs the non-empty "output" arg.

Note: I think we can change all other xstate_fault users too, including
alternative_input's.

Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
---
arch/x86/include/asm/xsave.h | 19 +++++--------------
1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
index 5fa9770..441f171 100644
--- a/arch/x86/include/asm/xsave.h
+++ b/arch/x86/include/asm/xsave.h
@@ -229,12 +229,8 @@ static inline int xsave_user(struct xsave_struct __user *buf)
if (unlikely(err))
return -EFAULT;

- __asm__ __volatile__(ASM_STAC "\n"
- "1:"XSAVE"\n"
- "2: " ASM_CLAC "\n"
- xstate_fault
- : "D" (buf), "a" (-1), "d" (-1), "0" (0)
- : "memory");
+ err = __user_insn(XSAVE, "=m" (*buf), /* unneeded */
+ "D" (buf), "a" (-1), "d" (-1));
return err;
}

@@ -243,17 +239,12 @@ static inline int xsave_user(struct xsave_struct __user *buf)
*/
static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
{
- int err = 0;
- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
u32 lmask = mask;
u32 hmask = mask >> 32;
+ int err;

- __asm__ __volatile__(ASM_STAC "\n"
- "1:"XRSTOR"\n"
- "2: " ASM_CLAC "\n"
- xstate_fault
- : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
- : "memory"); /* memory required? */
+ err = __user_insn(XRSTOR, "=m" (*buf), /* unneeded */
+ "D" (buf), "a" (lmask), "d" (hmask));
return err;
}

--
1.5.5.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/