x86/fpu: minor cleanups
A message that is not in the archive (sent off-list or not yet received): CAJ_zFkJkHpU4Y8wrrZjO0VnhzUVqJfyrLmNfRsBRT29bgbDSHg@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
cover x86/fpu: minor cleanups
add lkml/cc's.
Quoted 8 lines · Oleg Nesterov
Btw, why xstateregs_get/set() looks so confusing? The comment says "Copy the 48bytes defined by the software first into the xstate" but the code uses ->fxsave. Yes, this is the same memory, but still. I'll send the cosmetic cleanup.
Or
fx_finit()... Again,memset(fx, 0, xstate_size)is correct but only because of the current layout. I think this needs a cleanup too.
Of course this is purely cosmetic, but still...
Oleg.
PATCH 1/2 x86/regsets: change xstateregs_get/set to use ->xsave.i387 rather than ->fxsave
Cosmetic. xstateregs_get() and xstateregs_set() abuse ->fxsave to access xsave->i387.sw_reserved. This 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 "struct xsave_struct *" local.
--- arch/x86/kernel/i387.c | 25 +++++++++---------------- 1 files changed, 9 insertions(+), 16 deletions(-)
arch/x86/kernel/i387.c +9 -16
@@ -339,6 +339,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret;if (!cpu_has_xsave)
@@ -353,14 +354,12 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,* memory layout in the thread struct, so that we can copy the entire * xstateregs to the user using one user_regset_copyout(). */ -memcpy (&target->thread.fpu.state->fxsave.sw_reserved, - xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes)); - +memcpy (&xsave->i387.sw_reserved, + xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes));/* * Copy the xstate memory layout. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );return ret; }
@@ -368,8 +367,8 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret; -struct xsave_hdr_struct *xsave_hdr;if (!cpu_has_xsave)return -ENODEV ;
@@ -378,22 +377,16 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,if (ret)return ret; - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); - + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );/* * mxcsr reserved bits must be masked to zero for security reasons. */ - target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; - - xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr; - - xsave_hdr->xstate_bv &= pcntxt_mask; + xsave->i387.mxcsr &= mxcsr_feature_mask; + xsave->xsave_hdr.xstate_bv &= pcntxt_mask;/* * These bits must be zero. */ -memset (xsave_hdr->reserved,0 ,48 ); - +memset (&xsave->xsave_hdr.reserved,0 ,48 );return ret; }
Signature · 1 line
1.5.5.1
Re: [PATCH 1/2] x86/regsets: change xstateregs_get/set to use ->xsave.i387 rather than ->fxsave
Quoted 8 lines · Oleg Nesterov
Cosmetic.
xstateregs_get()andxstateregs_set()abuse ->fxsave to accessxsave->i387.sw_reserved. This is correct, ->fxsave andxsave->i387share the same memory, but imho this looks confusing.And we can make this code more readable if we add "struct
xsave_struct*" local.Signed-off-by Oleg Nesterov <[email protected]>
Signature · 1 line
All rights reversed
Re: [PATCH 1/2] x86/regsets: change xstateregs_get/set to use ->xsave.i387 rather than ->fxsave
In reply to Oleg NesterovQuoted 8 lines · Oleg Nesterov
Cosmetic.
xstateregs_get()andxstateregs_set()abuse ->fxsave to accessxsave->i387.sw_reserved. This is correct, ->fxsave andxsave->i387share the same memory, but imho this looks confusing.And we can make this code more readable if we add "struct
xsave_struct*" local.Signed-off-by Oleg Nesterov <[email protected]>
Applied, thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--tip-bot for Oleg Nesterov
merge bot[tip:x86/fpu] x86/fpu: Change xstateregs_get()/set() to use -> xsave.i387 rather than ->fxsave
In reply to Oleg Nesterovx86/fpu: Change xstateregs_get()/set() to use ->xsave.i387 rather than ->fxsave
Commit-ID: e7f180dcd8ab48f18b20d7e8a7e9b39192bdf8e0 Gitweb: http://git.kernel.org/tip/e7f180dcd8ab48f18b20d7e8a7e9b39192bdf8e0 Author: Oleg Nesterov <[email protected]> AuthorDate: Tue, 10 Mar 2015 07:06:24 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 10 Mar 2015 07:14:31 +0100
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.
--- arch/x86/kernel/i387.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
arch/x86/kernel/i387.c +9 -16
@@ -339,6 +339,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret;if (!cpu_has_xsave)
@@ -353,14 +354,12 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,* memory layout in the thread struct, so that we can copy the entire * xstateregs to the user using one user_regset_copyout(). */ -memcpy (&target->thread.fpu.state->fxsave.sw_reserved, - xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes)); - +memcpy (&xsave->i387.sw_reserved, + xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes));/* * Copy the xstate memory layout. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );return ret; }
@@ -368,8 +367,8 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret; -struct xsave_hdr_struct *xsave_hdr;if (!cpu_has_xsave)return -ENODEV ;
@@ -378,22 +377,16 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,if (ret)return ret; - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); - + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );/* * mxcsr reserved bits must be masked to zero for security reasons. */ - target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; - - xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr; - - xsave_hdr->xstate_bv &= pcntxt_mask; + xsave->i387.mxcsr &= mxcsr_feature_mask; + xsave->xsave_hdr.xstate_bv &= pcntxt_mask;/* * These bits must be zero. */ -memset (xsave_hdr->reserved,0 ,48 ); - +memset (&xsave->xsave_hdr.reserved,0 ,48 );return ret; }
PATCH 2/2 x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths
In reply to Oleg Nesterovfx_finit() has 2 users but only fpu_finit() needs to nullify xstate, alloc_bootmem_align() in setup_init_fpu_buf() returns zero-filled memory.
And note that both memset()'s look confusing. Yes, offsetof() is 0 for ->fxsave or ->fsave, but it would be more clean to turn them into a single memset() which nullifies fpu->state.
--- arch/x86/include/asm/fpu-internal.h | 1 - arch/x86/kernel/i387.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/fpu-internal.h +0 -1
@@ -107,7 +107,6 @@ static __always_inline __pure bool use_fxsr(void)static inline void fx_finit (struct i387_fxsave_struct *fx) { -memset (fx,0 , xstate_size); fx->cwd =0x37f ; fx->mxcsr =MXCSR_DEFAULT ; }
arch/x86/kernel/i387.c +2 -1
@@ -224,11 +224,12 @@ void fpu_finit(struct fpu *fpu)return ; } +memset (fpu->state,0 , xstate_size); +if (cpu_has_fxsr) {fx_finit (&fpu->state->fxsave); }else {struct i387_fsave_struct *fp = &fpu->state->fsave; -memset (fp,0 , xstate_size); fp->cwd =0xffff037fu ; fp->swd =0xffff0000u ; fp->twd =0xffffffffu ;
Signature · 1 line
1.5.5.1
Re: [PATCH 2/2] x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths
Quoted 9 lines · Oleg Nesterov
fx_finit()has 2 users but onlyfpu_finit()needs to nullify xstate,alloc_bootmem_align()insetup_init_fpu_buf()returns zero-filled memory.And note that both memset()'s look confusing. Yes,
offsetof()is 0 for ->fxsave or ->fsave, but it would be more clean to turn them into a singlememset()which nullifiesfpu->state.Signed-off-by Oleg Nesterov <[email protected]>
Signature · 1 line
All rights reversed
Re: [PATCH 2/2] x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths
In reply to Oleg NesterovQuoted 9 lines · Oleg Nesterov
fx_finit()has 2 users but onlyfpu_finit()needs to nullify xstate,alloc_bootmem_align()insetup_init_fpu_buf()returns zero-filled memory.And note that both memset()'s look confusing. Yes,
offsetof()is 0 for ->fxsave or ->fsave, but it would be more clean to turn them into a singlememset()which nullifiesfpu->state.Signed-off-by Oleg Nesterov <[email protected]>
Applied, thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--tip-bot for Oleg Nesterov
merge bot[tip:x86/fpu] x86/fpu: Factor out memset(xstate, 0) in fpu_finit( ) paths
In reply to Oleg Nesterovx86/fpu: Factor out memset(xstate, 0) in fpu_finit() paths
Commit-ID: 1d23c4518b1f3a03c278f23333149245c178d2a6 Gitweb: http://git.kernel.org/tip/1d23c4518b1f3a03c278f23333149245c178d2a6 Author: Oleg Nesterov <[email protected]> AuthorDate: Tue, 10 Mar 2015 07:06:25 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 10 Mar 2015 07:14:31 +0100
x86/fpu: Factor out memset(xstate, 0) in fpu_finit() paths
fx_finit() has two users but only fpu_finit() needs to clear xstate, alloc_bootmem_align() in setup_init_fpu_buf() returns zero-filled memory.
And note that both memset()'s look confusing. Yes, offsetof() is 0 for ->fxsave or ->fsave, but it would be cleaner to turn them into a single memset() which zeroes fpu->state.
--- arch/x86/include/asm/fpu-internal.h | 1 - arch/x86/kernel/i387.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/fpu-internal.h +0 -1
@@ -135,7 +135,6 @@ static __always_inline __pure bool use_fxsr(void)static inline void fx_finit (struct i387_fxsave_struct *fx) { -memset (fx,0 , xstate_size); fx->cwd =0x37f ; fx->mxcsr =MXCSR_DEFAULT ; }
arch/x86/kernel/i387.c +2 -1
@@ -224,11 +224,12 @@ void fpu_finit(struct fpu *fpu)return ; } +memset (fpu->state,0 , xstate_size); +if (cpu_has_fxsr) {fx_finit (&fpu->state->fxsave); }else {struct i387_fsave_struct *fp = &fpu->state->fsave; -memset (fp,0 , xstate_size); fp->cwd =0xffff037fu ; fp->swd =0xffff0000u ; fp->twd =0xffffffffu ;
Borislav Petkov
maintainer[GIT PULL] x86/fpu cleanups
Hi Ingo,
please pull two more cleanups to the FPU insanity from Oleg.
So this is *not* the urgent stuff - the urgent stuff will come later. This is the unload-some-more-onto-tip stuff which can be safely queued for 4.1 and I can forget about it here. :)
Thanks.
---
The following changes since commit ae486033b980346eb6a77240101210cb66924a91:
Merge tag 'tip_x86_fpu' of git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp into x86/fpu (2015-03-03 12:12:15 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git tags/tip_x86_fpu_2
for you to fetch changes up to 9ed010d31f173be786f0398a64f08bb4a0300c3b:
x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths (2015-03-04 11:57:46 +0100)
----------------------------------------------------------------
Two more cleanups from Oleg.
----------------------------------------------------------------
Oleg Nesterov (2):
x86/fpu: Change xstateregs_get()/set() to use ->xsave.i387 rather than ->fxsave x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths
arch/x86/include/asm/fpu-internal.h | 1 - arch/x86/kernel/i387.c | 28 +++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-)
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Borislav Petkov
maintainerPATCH 1/2 x86/fpu: Change xstateregs_get()/set() to use ->xsave.i387 rather than ->fxsave
From: Oleg Nesterov <[email protected]>
This is a cosmetic change: xstateregs_get() and xstateregs_set() abuse ->fxsave to access xsave->i387.sw_reserved. This 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 "struct xsave_struct *" local.
--- arch/x86/kernel/i387.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
arch/x86/kernel/i387.c +9 -16
@@ -339,6 +339,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret;if (!cpu_has_xsave)
@@ -353,14 +354,12 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,* memory layout in the thread struct, so that we can copy the entire * xstateregs to the user using one user_regset_copyout(). */ -memcpy (&target->thread.fpu.state->fxsave.sw_reserved, - xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes)); - +memcpy (&xsave->i387.sw_reserved, + xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes));/* * Copy the xstate memory layout. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );return ret; }
@@ -368,8 +367,8 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { + struct xsave_struct *xsave = &target->thread.fpu.state->xsave;int ret; -struct xsave_hdr_struct *xsave_hdr;if (!cpu_has_xsave)return -ENODEV ;
@@ -378,22 +377,16 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,if (ret)return ret; - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.state->xsave,0 ,-1 ); - + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 );/* * mxcsr reserved bits must be masked to zero for security reasons. */ - target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; - - xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr; - - xsave_hdr->xstate_bv &= pcntxt_mask; + xsave->i387.mxcsr &= mxcsr_feature_mask; + xsave->xsave_hdr.xstate_bv &= pcntxt_mask;/* * These bits must be zero. */ -memset (xsave_hdr->reserved,0 ,48 ); - +memset (&xsave->xsave_hdr.reserved,0 ,48 );return ret; }
Signature · 1 line
2.2.0.33.gc18b867
Borislav Petkov
maintainerPATCH 2/2 x86/fpu: factor out memset(xstate, 0) in fpu_finit() paths
From: Oleg Nesterov <[email protected]>
fx_finit() has 2 users but only fpu_finit() needs to nullify xstate, alloc_bootmem_align() in setup_init_fpu_buf() returns zero-filled memory.
And note that both memset()'s look confusing. Yes, offsetof() is 0 for ->fxsave or ->fsave, but it would be more clean to turn them into a single memset() which nullifies fpu->state.
--- arch/x86/include/asm/fpu-internal.h | 1 - arch/x86/kernel/i387.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/fpu-internal.h +0 -1
@@ -135,7 +135,6 @@ static __always_inline __pure bool use_fxsr(void)static inline void fx_finit (struct i387_fxsave_struct *fx) { -memset (fx,0 , xstate_size); fx->cwd =0x37f ; fx->mxcsr =MXCSR_DEFAULT ; }
arch/x86/kernel/i387.c +2 -1
@@ -224,11 +224,12 @@ void fpu_finit(struct fpu *fpu)return ; } +memset (fpu->state,0 , xstate_size); +if (cpu_has_fxsr) {fx_finit (&fpu->state->fxsave); }else {struct i387_fsave_struct *fp = &fpu->state->fsave; -memset (fp,0 , xstate_size); fp->cwd =0xffff037fu ; fp->swd =0xffff0000u ; fp->twd =0xffffffffu ;
Signature · 1 line
2.2.0.33.gc18b867