Skip to content

Commit 9ccc27a

Browse files
author
Ingo Molnar
committed
x86/fpu: Remove error return values from copy_kernel_to_*regs() functions
None of the copy_kernel_to_*regs() FPU register copying functions are supposed to fail, and all of them have debugging checks that enforce this. Remove their return values and simplify their call sites, which have redundant error checks and error handling code paths. Cc: Andy Lutomirski <[email protected]> Cc: Bobby Powers <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 3e1bf47 commit 9ccc27a

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static inline int copy_fxregs_to_user(struct fxregs_state __user *fx)
141141
return user_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx));
142142
}
143143

144-
static inline int copy_kernel_to_fxregs(struct fxregs_state *fx)
144+
static inline void copy_kernel_to_fxregs(struct fxregs_state *fx)
145145
{
146146
int err;
147147

@@ -157,8 +157,6 @@ static inline int copy_kernel_to_fxregs(struct fxregs_state *fx)
157157
}
158158
/* Copying from a kernel buffer to FPU registers should never fail: */
159159
WARN_ON_FPU(err);
160-
161-
return err;
162160
}
163161

164162
static inline int copy_user_to_fxregs(struct fxregs_state __user *fx)
@@ -173,13 +171,11 @@ static inline int copy_user_to_fxregs(struct fxregs_state __user *fx)
173171
"m" (*fx));
174172
}
175173

176-
static inline int copy_kernel_to_fregs(struct fregs_state *fx)
174+
static inline void copy_kernel_to_fregs(struct fregs_state *fx)
177175
{
178176
int err = check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
179177

180178
WARN_ON_FPU(err);
181-
182-
return err;
183179
}
184180

185181
static inline int copy_user_to_fregs(struct fregs_state __user *fx)
@@ -450,20 +446,19 @@ static inline int copy_fpregs_to_fpstate(struct fpu *fpu)
450446
return 0;
451447
}
452448

453-
static inline int __copy_kernel_to_fpregs(struct fpu *fpu)
449+
static inline void __copy_kernel_to_fpregs(struct fpu *fpu)
454450
{
455451
if (use_xsave()) {
456452
copy_kernel_to_xregs(&fpu->state.xsave, -1);
457-
return 0;
458453
} else {
459454
if (use_fxsr())
460-
return copy_kernel_to_fxregs(&fpu->state.fxsave);
455+
copy_kernel_to_fxregs(&fpu->state.fxsave);
461456
else
462-
return copy_kernel_to_fregs(&fpu->state.fsave);
457+
copy_kernel_to_fregs(&fpu->state.fsave);
463458
}
464459
}
465460

466-
static inline int copy_kernel_to_fpregs(struct fpu *fpu)
461+
static inline void copy_kernel_to_fpregs(struct fpu *fpu)
467462
{
468463
/*
469464
* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception is
@@ -478,7 +473,7 @@ static inline int copy_kernel_to_fpregs(struct fpu *fpu)
478473
: : [addr] "m" (fpu->fpregs_active));
479474
}
480475

481-
return __copy_kernel_to_fpregs(fpu);
476+
__copy_kernel_to_fpregs(fpu);
482477
}
483478

484479
extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size);
@@ -646,12 +641,8 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
646641
*/
647642
static inline void switch_fpu_finish(struct fpu *new_fpu, fpu_switch_t fpu_switch)
648643
{
649-
if (fpu_switch.preload) {
650-
if (unlikely(copy_kernel_to_fpregs(new_fpu))) {
651-
WARN_ON_FPU(1);
652-
fpu__clear(new_fpu);
653-
}
654-
}
644+
if (fpu_switch.preload)
645+
copy_kernel_to_fpregs(new_fpu);
655646
}
656647

657648
/*

arch/x86/kernel/fpu/core.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ void __kernel_fpu_end(void)
126126
{
127127
struct fpu *fpu = &current->thread.fpu;
128128

129-
if (fpu->fpregs_active) {
130-
if (WARN_ON_FPU(copy_kernel_to_fpregs(fpu)))
131-
fpu__clear(fpu);
132-
} else {
129+
if (fpu->fpregs_active)
130+
copy_kernel_to_fpregs(fpu);
131+
else
133132
__fpregs_deactivate_hw();
134-
}
135133

136134
kernel_fpu_enable();
137135
}
@@ -370,14 +368,8 @@ void fpu__restore(struct fpu *fpu)
370368
/* Avoid __kernel_fpu_begin() right after fpregs_activate() */
371369
kernel_fpu_disable();
372370
fpregs_activate(fpu);
373-
if (unlikely(copy_kernel_to_fpregs(fpu))) {
374-
/* Copying the kernel state to FPU registers should never fail: */
375-
WARN_ON_FPU(1);
376-
fpu__clear(fpu);
377-
force_sig_info(SIGSEGV, SEND_SIG_PRIV, current);
378-
} else {
379-
fpu->counter++;
380-
}
371+
copy_kernel_to_fpregs(fpu);
372+
fpu->counter++;
381373
kernel_fpu_enable();
382374
}
383375
EXPORT_SYMBOL_GPL(fpu__restore);

0 commit comments

Comments
 (0)