Commit b11ca7fb authored by Ingo Molnar's avatar Ingo Molnar

x86/fpu/xstate: Use explicit parameter in xstate_fault()

While looking at xstate.h it took me some time to realize that
'xstate_fault' uses 'err' as a silent parameter. This is not
obvious at the call site, at all.

Make it an explicit macro argument, so that the syntactic
connection is easier to see. Also explain xstate_fault()
a bit.

Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent b1b64dc3
...@@ -47,12 +47,18 @@ extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask); ...@@ -47,12 +47,18 @@ extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask);
#define XRSTOR ".byte " REX_PREFIX "0x0f,0xae,0x2f" #define XRSTOR ".byte " REX_PREFIX "0x0f,0xae,0x2f"
#define XRSTORS ".byte " REX_PREFIX "0x0f,0xc7,0x1f" #define XRSTORS ".byte " REX_PREFIX "0x0f,0xc7,0x1f"
#define xstate_fault ".section .fixup,\"ax\"\n" \ /* xstate instruction fault handler: */
#define xstate_fault(__err) \
\
".section .fixup,\"ax\"\n" \
\
"3: movl $-1,%[err]\n" \ "3: movl $-1,%[err]\n" \
" jmp 2b\n" \ " jmp 2b\n" \
\
".previous\n" \ ".previous\n" \
\
_ASM_EXTABLE(1b, 3b) \ _ASM_EXTABLE(1b, 3b) \
: [err] "=r" (err) : [err] "=r" (__err)
/* /*
* This function is called only during boot time when x86 caps are not set * This function is called only during boot time when x86 caps are not set
...@@ -70,13 +76,13 @@ static inline int copy_xregs_to_kernel_booting(struct xregs_state *fx) ...@@ -70,13 +76,13 @@ static inline int copy_xregs_to_kernel_booting(struct xregs_state *fx)
if (boot_cpu_has(X86_FEATURE_XSAVES)) if (boot_cpu_has(X86_FEATURE_XSAVES))
asm volatile("1:"XSAVES"\n\t" asm volatile("1:"XSAVES"\n\t"
"2:\n\t" "2:\n\t"
xstate_fault xstate_fault(err)
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
: "memory"); : "memory");
else else
asm volatile("1:"XSAVE"\n\t" asm volatile("1:"XSAVE"\n\t"
"2:\n\t" "2:\n\t"
xstate_fault xstate_fault(err)
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
: "memory"); : "memory");
return err; return err;
...@@ -97,13 +103,13 @@ static inline int copy_kernel_to_xregs_booting(struct xregs_state *fx, u64 mask) ...@@ -97,13 +103,13 @@ static inline int copy_kernel_to_xregs_booting(struct xregs_state *fx, u64 mask)
if (boot_cpu_has(X86_FEATURE_XSAVES)) if (boot_cpu_has(X86_FEATURE_XSAVES))
asm volatile("1:"XRSTORS"\n\t" asm volatile("1:"XRSTORS"\n\t"
"2:\n\t" "2:\n\t"
xstate_fault xstate_fault(err)
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
: "memory"); : "memory");
else else
asm volatile("1:"XRSTOR"\n\t" asm volatile("1:"XRSTOR"\n\t"
"2:\n\t" "2:\n\t"
xstate_fault xstate_fault(err)
: "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
: "memory"); : "memory");
return err; return err;
...@@ -141,7 +147,7 @@ static inline int copy_xregs_to_kernel(struct xregs_state *fx) ...@@ -141,7 +147,7 @@ static inline int copy_xregs_to_kernel(struct xregs_state *fx)
[fx] "D" (fx), "a" (lmask), "d" (hmask) : [fx] "D" (fx), "a" (lmask), "d" (hmask) :
"memory"); "memory");
asm volatile("2:\n\t" asm volatile("2:\n\t"
xstate_fault xstate_fault(err)
: "0" (0) : "0" (0)
: "memory"); : "memory");
...@@ -169,7 +175,7 @@ static inline int copy_kernel_to_xregs(struct xregs_state *fx, u64 mask) ...@@ -169,7 +175,7 @@ static inline int copy_kernel_to_xregs(struct xregs_state *fx, u64 mask)
: "memory"); : "memory");
asm volatile("2:\n" asm volatile("2:\n"
xstate_fault xstate_fault(err)
: "0" (0) : "0" (0)
: "memory"); : "memory");
...@@ -201,7 +207,7 @@ static inline int copy_xregs_to_user(struct xregs_state __user *buf) ...@@ -201,7 +207,7 @@ static inline int copy_xregs_to_user(struct xregs_state __user *buf)
__asm__ __volatile__(ASM_STAC "\n" __asm__ __volatile__(ASM_STAC "\n"
"1:"XSAVE"\n" "1:"XSAVE"\n"
"2: " ASM_CLAC "\n" "2: " ASM_CLAC "\n"
xstate_fault xstate_fault(err)
: "D" (buf), "a" (-1), "d" (-1), "0" (0) : "D" (buf), "a" (-1), "d" (-1), "0" (0)
: "memory"); : "memory");
return err; return err;
...@@ -220,7 +226,7 @@ static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask) ...@@ -220,7 +226,7 @@ static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)
__asm__ __volatile__(ASM_STAC "\n" __asm__ __volatile__(ASM_STAC "\n"
"1:"XRSTOR"\n" "1:"XRSTOR"\n"
"2: " ASM_CLAC "\n" "2: " ASM_CLAC "\n"
xstate_fault xstate_fault(err)
: "D" (xstate), "a" (lmask), "d" (hmask), "0" (0) : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
: "memory"); /* memory required? */ : "memory"); /* memory required? */
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment