aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2015-03-10 02:06:24 -0400
committerIngo Molnar <mingo@kernel.org>2015-03-10 02:14:31 -0400
commite7f180dcd8ab48f18b20d7e8a7e9b39192bdf8e0 (patch)
tree96aeb3f9e38c888728417376daa7ab92472f8c5d
parentae486033b980346eb6a77240101210cb66924a91 (diff)
x86/fpu: Change xstateregs_get()/set() to use ->xsave.i387 rather than ->fxsave
This is a cosmetic change: xstateregs_get() and xstateregs_set() abuse ->fxsave to access xsave->i387.sw_reserved. This practice is correct, ->fxsave and xsave->i387 share the same memory, but IMHO this looks confusing. And we can make this code more readable if we add a "struct xsave_struct *" local variable as well. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Tavis Ormandy <taviso@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1425967585-4725-1-git-send-email-bp@alien8.de Link: http://lkml.kernel.org/r/20150302183237.GB23085@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/i387.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 8416b5f85806..03cc0add8694 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -339,6 +339,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
339 unsigned int pos, unsigned int count, 339 unsigned int pos, unsigned int count,
340 void *kbuf, void __user *ubuf) 340 void *kbuf, void __user *ubuf)
341{ 341{
342 struct xsave_struct *xsave = &target->thread.fpu.state->xsave;
342 int ret; 343 int ret;
343 344
344 if (!cpu_has_xsave) 345 if (!cpu_has_xsave)
@@ -353,14 +354,12 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
353 * memory layout in the thread struct, so that we can copy the entire 354 * memory layout in the thread struct, so that we can copy the entire
354 * xstateregs to the user using one user_regset_copyout(). 355 * xstateregs to the user using one user_regset_copyout().
355 */ 356 */
356 memcpy(&target->thread.fpu.state->fxsave.sw_reserved, 357 memcpy(&xsave->i387.sw_reserved,
357 xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes)); 358 xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes));
358
359 /* 359 /*
360 * Copy the xstate memory layout. 360 * Copy the xstate memory layout.
361 */ 361 */
362 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 362 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
363 &target->thread.fpu.state->xsave, 0, -1);
364 return ret; 363 return ret;
365} 364}
366 365
@@ -368,8 +367,8 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
368 unsigned int pos, unsigned int count, 367 unsigned int pos, unsigned int count,
369 const void *kbuf, const void __user *ubuf) 368 const void *kbuf, const void __user *ubuf)
370{ 369{
370 struct xsave_struct *xsave = &target->thread.fpu.state->xsave;
371 int ret; 371 int ret;
372 struct xsave_hdr_struct *xsave_hdr;
373 372
374 if (!cpu_has_xsave) 373 if (!cpu_has_xsave)
375 return -ENODEV; 374 return -ENODEV;
@@ -378,22 +377,16 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
378 if (ret) 377 if (ret)
379 return ret; 378 return ret;
380 379
381 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, 380 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
382 &target->thread.fpu.state->xsave, 0, -1);
383
384 /* 381 /*
385 * mxcsr reserved bits must be masked to zero for security reasons. 382 * mxcsr reserved bits must be masked to zero for security reasons.
386 */ 383 */
387 target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; 384 xsave->i387.mxcsr &= mxcsr_feature_mask;
388 385 xsave->xsave_hdr.xstate_bv &= pcntxt_mask;
389 xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr;
390
391 xsave_hdr->xstate_bv &= pcntxt_mask;
392 /* 386 /*
393 * These bits must be zero. 387 * These bits must be zero.
394 */ 388 */
395 memset(xsave_hdr->reserved, 0, 48); 389 memset(&xsave->xsave_hdr.reserved, 0, 48);
396
397 return ret; 390 return ret;
398} 391}
399 392