Skip to content

Commit 124dece

Browse files
ChangSeokBaegregkh
authored andcommitted
x86/fpu: Refactor xfeature bitmask update code for sigframe XSAVE
commit 64e5446 upstream. Currently, saving register states in the signal frame, the legacy feature bits are always set in xregs_state->header->xfeatures. This code sequence can be generalized for reuse in similar cases. Refactor the logic to ensure a consistent approach across similar usages. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Link: https://lore.kernel.org/r/20250416021720.12305-8-chang.seok.bae@intel.com Cc: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5640e62 commit 124dece

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

arch/x86/kernel/fpu/signal.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ static inline bool save_xstate_epilog(void __user *buf, int ia32_frame,
114114
{
115115
struct xregs_state __user *x = buf;
116116
struct _fpx_sw_bytes sw_bytes = {};
117-
u32 xfeatures;
118117
int err;
119118

120119
/* Setup the bytes not touched by the [f]xsave and reserved for SW. */
@@ -127,12 +126,6 @@ static inline bool save_xstate_epilog(void __user *buf, int ia32_frame,
127126
err |= __put_user(FP_XSTATE_MAGIC2,
128127
(__u32 __user *)(buf + fpstate->user_size));
129128

130-
/*
131-
* Read the xfeatures which we copied (directly from the cpu or
132-
* from the state in task struct) to the user buffers.
133-
*/
134-
err |= __get_user(xfeatures, (__u32 __user *)&x->header.xfeatures);
135-
136129
/*
137130
* For legacy compatible, we always set FP/SSE bits in the bit
138131
* vector while saving the state to the user context. This will
@@ -144,9 +137,7 @@ static inline bool save_xstate_epilog(void __user *buf, int ia32_frame,
144137
* header as well as change any contents in the memory layout.
145138
* xrestore as part of sigreturn will capture all the changes.
146139
*/
147-
xfeatures |= XFEATURE_MASK_FPSSE;
148-
149-
err |= __put_user(xfeatures, (__u32 __user *)&x->header.xfeatures);
140+
err |= set_xfeature_in_sigframe(x, XFEATURE_MASK_FPSSE);
150141

151142
return !err;
152143
}

arch/x86/kernel/fpu/xstate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ static inline u64 xfeatures_mask_independent(void)
6969
return fpu_kernel_cfg.independent_features;
7070
}
7171

72+
static inline int set_xfeature_in_sigframe(struct xregs_state __user *xbuf, u64 mask)
73+
{
74+
u64 xfeatures;
75+
int err;
76+
77+
/* Read the xfeatures value already saved in the user buffer */
78+
err = __get_user(xfeatures, &xbuf->header.xfeatures);
79+
xfeatures |= mask;
80+
err |= __put_user(xfeatures, &xbuf->header.xfeatures);
81+
82+
return err;
83+
}
84+
7285
/*
7386
* Update the value of PKRU register that was already pushed onto the signal frame.
7487
*/

0 commit comments

Comments
 (0)