aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/ia32
diff options
context:
space:
mode:
authorSuresh Siddha <suresh.b.siddha@intel.com>2012-07-24 19:05:29 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2012-09-18 18:51:48 -0400
commit72a671ced66db6d1c2bfff1c930a101ac8d08204 (patch)
treefb3f58fa735d2d3cffc636e3e0f8114a04b04623 /arch/x86/ia32
parent0ca5bd0d886578ad0afeceaa83458c0f35cb3c6b (diff)
x86, fpu: Unify signal handling code paths for x86 and x86_64 kernels
Currently for x86 and x86_32 binaries, fpstate in the user sigframe is copied to/from the fpstate in the task struct. And in the case of signal delivery for x86_64 binaries, if the fpstate is live in the CPU registers, then the live state is copied directly to the user sigframe. Otherwise fpstate in the task struct is copied to the user sigframe. During restore, fpstate in the user sigframe is restored directly to the live CPU registers. Historically, different code paths led to different bugs. For example, x86_64 code path was not preemption safe till recently. Also there is lot of code duplication for support of new features like xsave etc. Unify signal handling code paths for x86 and x86_64 kernels. New strategy is as follows: Signal delivery: Both for 32/64-bit frames, align the core math frame area to 64bytes as needed by xsave (this where the main fpu/extended state gets copied to and excludes the legacy compatibility fsave header for the 32-bit [f]xsave frames). If the state is live, copy the register state directly to the user frame. If not live, copy the state in the thread struct to the user frame. And for 32-bit [f]xsave frames, construct the fsave header separately before the actual [f]xsave area. Signal return: As the 32-bit frames with [f]xstate has an additional 'fsave' header, copy everything back from the user sigframe to the fpstate in the task structure and reconstruct the fxstate from the 'fsave' header (Also user passed pointers may not be correctly aligned for any attempt to directly restore any partial state). At the next fpstate usage, everything will be restored to the live CPU registers. For all the 64-bit frames and the 32-bit fsave frame, restore the state from the user sigframe directly to the live CPU registers. 64-bit signals always restored the math frame directly, so we can expect the math frame pointer to be correctly aligned. For 32-bit fsave frames, there are no alignment requirements, so we can restore the state directly. "lat_sig catch" microbenchmark numbers (for x86, x86_64, x86_32 binaries) are with in the noise range with this change. Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Link: http://lkml.kernel.org/r/1343171129-2747-4-git-send-email-suresh.b.siddha@intel.com [ Merged in compilation fix ] Link: http://lkml.kernel.org/r/1344544736.8326.17.camel@sbsiddha-desk.sc.intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/ia32')
-rw-r--r--arch/x86/ia32/ia32_signal.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 452d4dd0a95a..8c77c64fbd27 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -251,7 +251,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
251 251
252 get_user_ex(tmp, &sc->fpstate); 252 get_user_ex(tmp, &sc->fpstate);
253 buf = compat_ptr(tmp); 253 buf = compat_ptr(tmp);
254 err |= restore_i387_xstate_ia32(buf); 254 err |= restore_xstate_sig(buf, 1);
255 255
256 get_user_ex(*pax, &sc->ax); 256 get_user_ex(*pax, &sc->ax);
257 } get_user_catch(err); 257 } get_user_catch(err);
@@ -382,9 +382,12 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
382 sp = (unsigned long) ka->sa.sa_restorer; 382 sp = (unsigned long) ka->sa.sa_restorer;
383 383
384 if (used_math()) { 384 if (used_math()) {
385 sp = sp - sig_xstate_ia32_size; 385 unsigned long fx_aligned, math_size;
386
387 sp = alloc_mathframe(sp, 1, &fx_aligned, &math_size);
386 *fpstate = (struct _fpstate_ia32 __user *) sp; 388 *fpstate = (struct _fpstate_ia32 __user *) sp;
387 if (save_i387_xstate_ia32(*fpstate) < 0) 389 if (save_xstate_sig(*fpstate, (void __user *)fx_aligned,
390 math_size) < 0)
388 return (void __user *) -1L; 391 return (void __user *) -1L;
389 } 392 }
390 393