浏览代码

x86/fpu: Improve the initialization logic of 'err' around xstate_fault() constraints

There's a confusing aspect of how xstate_fault() constraints are
handled by the FPU register/memory copying functions in
fpu/internal.h: they use "0" (0) to signal that the asm code
will not always set 'err' to a valid value.

But 'err' is already initialized to 0 in C code, which is duplicated
by the asm() constraint. Should the initialization value ever be
changed, it might become subtly inconsistent with the not too clear
asm() constraint.

Use 'err' as the value of the input variable instead, to clarify
this all.

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: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Ingo Molnar 10 年之前
父节点
当前提交
685c961624
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6 6
      arch/x86/include/asm/fpu/internal.h

+ 6 - 6
arch/x86/include/asm/fpu/internal.h

@@ -316,7 +316,7 @@ static inline int copy_xregs_to_kernel(struct xregs_state *xstate)
 		"memory");
 		"memory");
 	asm volatile("2:\n\t"
 	asm volatile("2:\n\t"
 		     xstate_fault(err)
 		     xstate_fault(err)
-		     : "0" (0)
+		     : "0" (err)
 		     : "memory");
 		     : "memory");
 
 
 	return err;
 	return err;
@@ -327,9 +327,9 @@ static inline int copy_xregs_to_kernel(struct xregs_state *xstate)
  */
  */
 static inline int copy_kernel_to_xregs(struct xregs_state *xstate, u64 mask)
 static inline int copy_kernel_to_xregs(struct xregs_state *xstate, u64 mask)
 {
 {
-	int err = 0;
 	u32 lmask = mask;
 	u32 lmask = mask;
 	u32 hmask = mask >> 32;
 	u32 hmask = mask >> 32;
+	int err = 0;
 
 
 	/*
 	/*
 	 * Use xrstors to restore context if it is enabled. xrstors supports
 	 * Use xrstors to restore context if it is enabled. xrstors supports
@@ -344,7 +344,7 @@ static inline int copy_kernel_to_xregs(struct xregs_state *xstate, u64 mask)
 
 
 	asm volatile("2:\n"
 	asm volatile("2:\n"
 		     xstate_fault(err)
 		     xstate_fault(err)
-		     : "0" (0)
+		     : "0" (err)
 		     : "memory");
 		     : "memory");
 
 
 	return err;
 	return err;
@@ -376,7 +376,7 @@ static inline int copy_xregs_to_user(struct xregs_state __user *buf)
 			     "1:"XSAVE"\n"
 			     "1:"XSAVE"\n"
 			     "2: " ASM_CLAC "\n"
 			     "2: " ASM_CLAC "\n"
 			     xstate_fault(err)
 			     xstate_fault(err)
-			     : "D" (buf), "a" (-1), "d" (-1), "0" (0)
+			     : "D" (buf), "a" (-1), "d" (-1), "0" (err)
 			     : "memory");
 			     : "memory");
 	return err;
 	return err;
 }
 }
@@ -386,16 +386,16 @@ static inline int copy_xregs_to_user(struct xregs_state __user *buf)
  */
  */
 static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)
 static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)
 {
 {
-	int err = 0;
 	struct xregs_state *xstate = ((__force struct xregs_state *)buf);
 	struct xregs_state *xstate = ((__force struct xregs_state *)buf);
 	u32 lmask = mask;
 	u32 lmask = mask;
 	u32 hmask = mask >> 32;
 	u32 hmask = mask >> 32;
+	int err = 0;
 
 
 	__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(err)
 			     xstate_fault(err)
-			     : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
+			     : "D" (xstate), "a" (lmask), "d" (hmask), "0" (err)
 			     : "memory");	/* memory required? */
 			     : "memory");	/* memory required? */
 	return err;
 	return err;
 }
 }