diff options
author | Yu-cheng Yu <yu-cheng.yu@intel.com> | 2016-05-20 13:47:08 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-06-18 04:10:19 -0400 |
commit | 99aa22d0d8f70d9317727ab40c85b2ead740a6ca (patch) | |
tree | 34a01084331465f07c9fb42715bdad32e0ec59ac | |
parent | 7d9370607d28afd454775c623d5447603473a3c3 (diff) |
x86/fpu/xstate: Copy xstate registers directly to the signal frame when compacted format is in use
XSAVES is a kernel instruction and uses a compacted format. When working
with user space, the kernel should provide standard-format, non-supervisor
state data. We cannot do __copy_to_user() from a compacted-format kernel
xstate area to a signal frame.
Dave Hansen proposes this method to simplify copy xstate directly to user.
This patch is based on an earlier patch from Fenghua Yu <fenghua.yu@intel.com>
Originally-from: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.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: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/c36f419d525517d04209a28dd8e1e5af9000036e.1463760376.git.yu-cheng.yu@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/include/asm/fpu/xstate.h | 1 | ||||
-rw-r--r-- | arch/x86/kernel/fpu/signal.c | 3 | ||||
-rw-r--r-- | arch/x86/kernel/fpu/xstate.c | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h index 16df2c44ac66..d812cf361282 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h | |||
@@ -47,5 +47,6 @@ extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask); | |||
47 | void fpu__xstate_clear_all_cpu_caps(void); | 47 | void fpu__xstate_clear_all_cpu_caps(void); |
48 | void *get_xsave_addr(struct xregs_state *xsave, int xstate); | 48 | void *get_xsave_addr(struct xregs_state *xsave, int xstate); |
49 | const void *get_xsave_field_ptr(int xstate_field); | 49 | const void *get_xsave_field_ptr(int xstate_field); |
50 | int using_compacted_format(void); | ||
50 | 51 | ||
51 | #endif | 52 | #endif |
diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 06d80f62c03f..8aa96cbb5dfb 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <asm/fpu/internal.h> | 8 | #include <asm/fpu/internal.h> |
9 | #include <asm/fpu/signal.h> | 9 | #include <asm/fpu/signal.h> |
10 | #include <asm/fpu/regset.h> | 10 | #include <asm/fpu/regset.h> |
11 | #include <asm/fpu/xstate.h> | ||
11 | 12 | ||
12 | #include <asm/sigframe.h> | 13 | #include <asm/sigframe.h> |
13 | #include <asm/trace/fpu.h> | 14 | #include <asm/trace/fpu.h> |
@@ -169,7 +170,7 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size) | |||
169 | sizeof(struct user_i387_ia32_struct), NULL, | 170 | sizeof(struct user_i387_ia32_struct), NULL, |
170 | (struct _fpstate_32 __user *) buf) ? -1 : 1; | 171 | (struct _fpstate_32 __user *) buf) ? -1 : 1; |
171 | 172 | ||
172 | if (fpregs_active()) { | 173 | if (fpregs_active() || using_compacted_format()) { |
173 | /* Save the live register state to the user directly. */ | 174 | /* Save the live register state to the user directly. */ |
174 | if (copy_fpregs_to_sigframe(buf_fx)) | 175 | if (copy_fpregs_to_sigframe(buf_fx)) |
175 | return -1; | 176 | return -1; |
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index dbfef1b7be7c..0b01f003df8b 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c | |||
@@ -420,7 +420,7 @@ static int xfeature_size(int xfeature_nr) | |||
420 | * that it is obvious which aspect of 'XSAVES' is being handled | 420 | * that it is obvious which aspect of 'XSAVES' is being handled |
421 | * by the calling code. | 421 | * by the calling code. |
422 | */ | 422 | */ |
423 | static int using_compacted_format(void) | 423 | int using_compacted_format(void) |
424 | { | 424 | { |
425 | return boot_cpu_has(X86_FEATURE_XSAVES); | 425 | return boot_cpu_has(X86_FEATURE_XSAVES); |
426 | } | 426 | } |