Skip to content

Commit e3bfa38

Browse files
author
Ingo Molnar
committed
x86/fpu: Convert task_struct::thread.fpu accesses to use x86_task_fpu()
This will make the removal of the task_struct::thread.fpu array easier. No change in functionality - code generated before and after this commit is identical on x86-defconfig: kepler:~/tip> diff -up vmlinux.before.asm vmlinux.after.asm kepler:~/tip> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Chang S. Bae <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 77fbcce commit e3bfa38

File tree

15 files changed

+68
-68
lines changed

15 files changed

+68
-68
lines changed

arch/x86/include/asm/fpu/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline void switch_fpu_prepare(struct task_struct *old, int cpu)
4141
{
4242
if (cpu_feature_enabled(X86_FEATURE_FPU) &&
4343
!(old->flags & (PF_KTHREAD | PF_USER_WORKER))) {
44-
struct fpu *old_fpu = &old->thread.fpu;
44+
struct fpu *old_fpu = x86_task_fpu(old);
4545

4646
save_fpregs_to_fpstate(old_fpu);
4747
/*

arch/x86/kernel/fpu/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static inline void fpregs_activate(struct fpu *fpu)
5353
/* Internal helper for switch_fpu_return() and signal frame setup */
5454
static inline void fpregs_restore_userregs(void)
5555
{
56-
struct fpu *fpu = &current->thread.fpu;
56+
struct fpu *fpu = x86_task_fpu(current);
5757
int cpu = smp_processor_id();
5858

5959
if (WARN_ON_ONCE(current->flags & (PF_KTHREAD | PF_USER_WORKER)))
@@ -67,7 +67,7 @@ static inline void fpregs_restore_userregs(void)
6767
* If PKRU is enabled, then the PKRU value is already
6868
* correct because it was either set in switch_to() or in
6969
* flush_thread(). So it is excluded because it might be
70-
* not up to date in current->thread.fpu.xsave state.
70+
* not up to date in current->thread.fpu->xsave state.
7171
*
7272
* XFD state is handled in restore_fpregs_from_fpstate().
7373
*/

arch/x86/kernel/fpu/core.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void fpu_init_guest_permissions(struct fpu_guest *gfpu)
211211
return;
212212

213213
spin_lock_irq(&current->sighand->siglock);
214-
fpuperm = &current->group_leader->thread.fpu.guest_perm;
214+
fpuperm = &x86_task_fpu(current->group_leader)->guest_perm;
215215
perm = fpuperm->__state_perm;
216216

217217
/* First fpstate allocation locks down permissions. */
@@ -323,7 +323,7 @@ EXPORT_SYMBOL_GPL(fpu_update_guest_xfd);
323323
*/
324324
void fpu_sync_guest_vmexit_xfd_state(void)
325325
{
326-
struct fpstate *fps = current->thread.fpu.fpstate;
326+
struct fpstate *fps = x86_task_fpu(current)->fpstate;
327327

328328
lockdep_assert_irqs_disabled();
329329
if (fpu_state_size_dynamic()) {
@@ -337,7 +337,7 @@ EXPORT_SYMBOL_GPL(fpu_sync_guest_vmexit_xfd_state);
337337
int fpu_swap_kvm_fpstate(struct fpu_guest *guest_fpu, bool enter_guest)
338338
{
339339
struct fpstate *guest_fps = guest_fpu->fpstate;
340-
struct fpu *fpu = &current->thread.fpu;
340+
struct fpu *fpu = x86_task_fpu(current);
341341
struct fpstate *cur_fps = fpu->fpstate;
342342

343343
fpregs_lock();
@@ -438,7 +438,7 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
438438
if (!(current->flags & (PF_KTHREAD | PF_USER_WORKER)) &&
439439
!test_thread_flag(TIF_NEED_FPU_LOAD)) {
440440
set_thread_flag(TIF_NEED_FPU_LOAD);
441-
save_fpregs_to_fpstate(&current->thread.fpu);
441+
save_fpregs_to_fpstate(x86_task_fpu(current));
442442
}
443443
__cpu_invalidate_fpregs_state();
444444

@@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(kernel_fpu_end);
467467
*/
468468
void fpu_sync_fpstate(struct fpu *fpu)
469469
{
470-
WARN_ON_FPU(fpu != &current->thread.fpu);
470+
WARN_ON_FPU(fpu != x86_task_fpu(current));
471471

472472
fpregs_lock();
473473
trace_x86_fpu_before_save(fpu);
@@ -552,7 +552,7 @@ void fpstate_reset(struct fpu *fpu)
552552
static inline void fpu_inherit_perms(struct fpu *dst_fpu)
553553
{
554554
if (fpu_state_size_dynamic()) {
555-
struct fpu *src_fpu = &current->group_leader->thread.fpu;
555+
struct fpu *src_fpu = x86_task_fpu(current->group_leader);
556556

557557
spin_lock_irq(&current->sighand->siglock);
558558
/* Fork also inherits the permissions of the parent */
@@ -572,7 +572,7 @@ static int update_fpu_shstk(struct task_struct *dst, unsigned long ssp)
572572
if (!ssp)
573573
return 0;
574574

575-
xstate = get_xsave_addr(&dst->thread.fpu.fpstate->regs.xsave,
575+
xstate = get_xsave_addr(&x86_task_fpu(dst)->fpstate->regs.xsave,
576576
XFEATURE_CET_USER);
577577

578578
/*
@@ -593,8 +593,8 @@ static int update_fpu_shstk(struct task_struct *dst, unsigned long ssp)
593593
int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
594594
unsigned long ssp)
595595
{
596-
struct fpu *src_fpu = &current->thread.fpu;
597-
struct fpu *dst_fpu = &dst->thread.fpu;
596+
struct fpu *src_fpu = x86_task_fpu(current);
597+
struct fpu *dst_fpu = x86_task_fpu(dst);
598598

599599
/* The new task's FPU state cannot be valid in the hardware. */
600600
dst_fpu->last_cpu = -1;
@@ -686,7 +686,7 @@ void fpu__drop(struct fpu *fpu)
686686
{
687687
preempt_disable();
688688

689-
if (fpu == &current->thread.fpu) {
689+
if (fpu == x86_task_fpu(current)) {
690690
/* Ignore delayed exceptions from user space */
691691
asm volatile("1: fwait\n"
692692
"2:\n"
@@ -720,7 +720,7 @@ static inline void restore_fpregs_from_init_fpstate(u64 features_mask)
720720
*/
721721
static void fpu_reset_fpregs(void)
722722
{
723-
struct fpu *fpu = &current->thread.fpu;
723+
struct fpu *fpu = x86_task_fpu(current);
724724

725725
fpregs_lock();
726726
__fpu_invalidate_fpregs_state(fpu);
@@ -749,7 +749,7 @@ static void fpu_reset_fpregs(void)
749749
*/
750750
void fpu__clear_user_states(struct fpu *fpu)
751751
{
752-
WARN_ON_FPU(fpu != &current->thread.fpu);
752+
WARN_ON_FPU(fpu != x86_task_fpu(current));
753753

754754
fpregs_lock();
755755
if (!cpu_feature_enabled(X86_FEATURE_FPU)) {
@@ -782,7 +782,7 @@ void fpu__clear_user_states(struct fpu *fpu)
782782

783783
void fpu_flush_thread(void)
784784
{
785-
fpstate_reset(&current->thread.fpu);
785+
fpstate_reset(x86_task_fpu(current));
786786
fpu_reset_fpregs();
787787
}
788788
/*
@@ -823,7 +823,7 @@ void fpregs_lock_and_load(void)
823823
*/
824824
void fpregs_assert_state_consistent(void)
825825
{
826-
struct fpu *fpu = &current->thread.fpu;
826+
struct fpu *fpu = x86_task_fpu(current);
827827

828828
if (test_thread_flag(TIF_NEED_FPU_LOAD))
829829
return;
@@ -835,7 +835,7 @@ EXPORT_SYMBOL_GPL(fpregs_assert_state_consistent);
835835

836836
void fpregs_mark_activate(void)
837837
{
838-
struct fpu *fpu = &current->thread.fpu;
838+
struct fpu *fpu = x86_task_fpu(current);
839839

840840
fpregs_activate(fpu);
841841
fpu->last_cpu = smp_processor_id();

arch/x86/kernel/fpu/init.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void fpu__init_cpu_generic(void)
3838
/* Flush out any pending x87 state: */
3939
#ifdef CONFIG_MATH_EMULATION
4040
if (!boot_cpu_has(X86_FEATURE_FPU))
41-
fpstate_init_soft(&current->thread.fpu.fpstate->regs.soft);
41+
fpstate_init_soft(&x86_task_fpu(current)->fpstate->regs.soft);
4242
else
4343
#endif
4444
asm volatile ("fninit");
@@ -154,7 +154,7 @@ static void __init fpu__init_task_struct_size(void)
154154
* Subtract off the static size of the register state.
155155
* It potentially has a bunch of padding.
156156
*/
157-
task_size -= sizeof(current->thread.fpu.__fpstate.regs);
157+
task_size -= sizeof(union fpregs_state);
158158

159159
/*
160160
* Add back the dynamically-calculated register state
@@ -204,7 +204,7 @@ static void __init fpu__init_system_xstate_size_legacy(void)
204204
fpu_kernel_cfg.default_size = size;
205205
fpu_user_cfg.max_size = size;
206206
fpu_user_cfg.default_size = size;
207-
fpstate_reset(&current->thread.fpu);
207+
fpstate_reset(x86_task_fpu(current));
208208
}
209209

210210
/*
@@ -213,7 +213,7 @@ static void __init fpu__init_system_xstate_size_legacy(void)
213213
*/
214214
void __init fpu__init_system(void)
215215
{
216-
fpstate_reset(&current->thread.fpu);
216+
fpstate_reset(x86_task_fpu(current));
217217
fpu__init_system_early_generic();
218218

219219
/*

arch/x86/kernel/fpu/regset.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int regset_xregset_fpregs_active(struct task_struct *target, const struct user_r
4545
*/
4646
static void sync_fpstate(struct fpu *fpu)
4747
{
48-
if (fpu == &current->thread.fpu)
48+
if (fpu == x86_task_fpu(current))
4949
fpu_sync_fpstate(fpu);
5050
}
5151

@@ -63,15 +63,15 @@ static void fpu_force_restore(struct fpu *fpu)
6363
* Only stopped child tasks can be used to modify the FPU
6464
* state in the fpstate buffer:
6565
*/
66-
WARN_ON_FPU(fpu == &current->thread.fpu);
66+
WARN_ON_FPU(fpu == x86_task_fpu(current));
6767

6868
__fpu_invalidate_fpregs_state(fpu);
6969
}
7070

7171
int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
7272
struct membuf to)
7373
{
74-
struct fpu *fpu = &target->thread.fpu;
74+
struct fpu *fpu = x86_task_fpu(target);
7575

7676
if (!cpu_feature_enabled(X86_FEATURE_FXSR))
7777
return -ENODEV;
@@ -91,7 +91,7 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
9191
unsigned int pos, unsigned int count,
9292
const void *kbuf, const void __user *ubuf)
9393
{
94-
struct fpu *fpu = &target->thread.fpu;
94+
struct fpu *fpu = x86_task_fpu(target);
9595
struct fxregs_state newstate;
9696
int ret;
9797

@@ -133,7 +133,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
133133
if (!cpu_feature_enabled(X86_FEATURE_XSAVE))
134134
return -ENODEV;
135135

136-
sync_fpstate(&target->thread.fpu);
136+
sync_fpstate(x86_task_fpu(target));
137137

138138
copy_xstate_to_uabi_buf(to, target, XSTATE_COPY_XSAVE);
139139
return 0;
@@ -143,7 +143,7 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
143143
unsigned int pos, unsigned int count,
144144
const void *kbuf, const void __user *ubuf)
145145
{
146-
struct fpu *fpu = &target->thread.fpu;
146+
struct fpu *fpu = x86_task_fpu(target);
147147
struct xregs_state *tmpbuf = NULL;
148148
int ret;
149149

@@ -187,7 +187,7 @@ int ssp_active(struct task_struct *target, const struct user_regset *regset)
187187
int ssp_get(struct task_struct *target, const struct user_regset *regset,
188188
struct membuf to)
189189
{
190-
struct fpu *fpu = &target->thread.fpu;
190+
struct fpu *fpu = x86_task_fpu(target);
191191
struct cet_user_state *cetregs;
192192

193193
if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) ||
@@ -214,7 +214,7 @@ int ssp_set(struct task_struct *target, const struct user_regset *regset,
214214
unsigned int pos, unsigned int count,
215215
const void *kbuf, const void __user *ubuf)
216216
{
217-
struct fpu *fpu = &target->thread.fpu;
217+
struct fpu *fpu = x86_task_fpu(target);
218218
struct xregs_state *xsave = &fpu->fpstate->regs.xsave;
219219
struct cet_user_state *cetregs;
220220
unsigned long user_ssp;
@@ -368,7 +368,7 @@ static void __convert_from_fxsr(struct user_i387_ia32_struct *env,
368368
void
369369
convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk)
370370
{
371-
__convert_from_fxsr(env, tsk, &tsk->thread.fpu.fpstate->regs.fxsave);
371+
__convert_from_fxsr(env, tsk, &x86_task_fpu(tsk)->fpstate->regs.fxsave);
372372
}
373373

374374
void convert_to_fxsr(struct fxregs_state *fxsave,
@@ -401,7 +401,7 @@ void convert_to_fxsr(struct fxregs_state *fxsave,
401401
int fpregs_get(struct task_struct *target, const struct user_regset *regset,
402402
struct membuf to)
403403
{
404-
struct fpu *fpu = &target->thread.fpu;
404+
struct fpu *fpu = x86_task_fpu(target);
405405
struct user_i387_ia32_struct env;
406406
struct fxregs_state fxsave, *fx;
407407

@@ -433,7 +433,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
433433
unsigned int pos, unsigned int count,
434434
const void *kbuf, const void __user *ubuf)
435435
{
436-
struct fpu *fpu = &target->thread.fpu;
436+
struct fpu *fpu = x86_task_fpu(target);
437437
struct user_i387_ia32_struct env;
438438
int ret;
439439

arch/x86/kernel/fpu/signal.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf,
4343
* fpstate layout with out copying the extended state information
4444
* in the memory layout.
4545
*/
46-
if (__get_user(magic2, (__u32 __user *)(fpstate + current->thread.fpu.fpstate->user_size)))
46+
if (__get_user(magic2, (__u32 __user *)(fpstate + x86_task_fpu(current)->fpstate->user_size)))
4747
return false;
4848

4949
if (likely(magic2 == FP_XSTATE_MAGIC2))
5050
return true;
5151
setfx:
52-
trace_x86_fpu_xstate_check_failed(&current->thread.fpu);
52+
trace_x86_fpu_xstate_check_failed(x86_task_fpu(current));
5353

5454
/* Set the parameters for fx only state */
5555
fx_sw->magic1 = 0;
@@ -64,13 +64,13 @@ static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf,
6464
static inline bool save_fsave_header(struct task_struct *tsk, void __user *buf)
6565
{
6666
if (use_fxsr()) {
67-
struct xregs_state *xsave = &tsk->thread.fpu.fpstate->regs.xsave;
67+
struct xregs_state *xsave = &x86_task_fpu(tsk)->fpstate->regs.xsave;
6868
struct user_i387_ia32_struct env;
6969
struct _fpstate_32 __user *fp = buf;
7070

7171
fpregs_lock();
7272
if (!test_thread_flag(TIF_NEED_FPU_LOAD))
73-
fxsave(&tsk->thread.fpu.fpstate->regs.fxsave);
73+
fxsave(&x86_task_fpu(tsk)->fpstate->regs.fxsave);
7474
fpregs_unlock();
7575

7676
convert_from_fxsr(&env, tsk);
@@ -184,7 +184,7 @@ static inline int copy_fpregs_to_sigframe(struct xregs_state __user *buf, u32 pk
184184
bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size, u32 pkru)
185185
{
186186
struct task_struct *tsk = current;
187-
struct fpstate *fpstate = tsk->thread.fpu.fpstate;
187+
struct fpstate *fpstate = x86_task_fpu(tsk)->fpstate;
188188
bool ia32_fxstate = (buf != buf_fx);
189189
int ret;
190190

@@ -272,7 +272,7 @@ static int __restore_fpregs_from_user(void __user *buf, u64 ufeatures,
272272
*/
273273
static bool restore_fpregs_from_user(void __user *buf, u64 xrestore, bool fx_only)
274274
{
275-
struct fpu *fpu = &current->thread.fpu;
275+
struct fpu *fpu = x86_task_fpu(current);
276276
int ret;
277277

278278
/* Restore enabled features only. */
@@ -332,7 +332,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx,
332332
bool ia32_fxstate)
333333
{
334334
struct task_struct *tsk = current;
335-
struct fpu *fpu = &tsk->thread.fpu;
335+
struct fpu *fpu = x86_task_fpu(tsk);
336336
struct user_i387_ia32_struct env;
337337
bool success, fx_only = false;
338338
union fpregs_state *fpregs;
@@ -452,7 +452,7 @@ static inline unsigned int xstate_sigframe_size(struct fpstate *fpstate)
452452
*/
453453
bool fpu__restore_sig(void __user *buf, int ia32_frame)
454454
{
455-
struct fpu *fpu = &current->thread.fpu;
455+
struct fpu *fpu = x86_task_fpu(current);
456456
void __user *buf_fx = buf;
457457
bool ia32_fxstate = false;
458458
bool success = false;
@@ -499,7 +499,7 @@ unsigned long
499499
fpu__alloc_mathframe(unsigned long sp, int ia32_frame,
500500
unsigned long *buf_fx, unsigned long *size)
501501
{
502-
unsigned long frame_size = xstate_sigframe_size(current->thread.fpu.fpstate);
502+
unsigned long frame_size = xstate_sigframe_size(x86_task_fpu(current)->fpstate);
503503

504504
*buf_fx = sp = round_down(sp - frame_size, 64);
505505
if (ia32_frame && use_fxsr()) {

0 commit comments

Comments
 (0)