Skip to content

Commit f1c8cd0

Browse files
author
Ingo Molnar
committed
x86/fpu: Change fpu->fpregs_active users to fpu->fpstate_active
We want to simplify the FPU state machine by eliminating fpu->fpregs_active, and we can do that because the two state flags (::fpregs_active and ::fpstate_active) are set essentially together. The old lazy FPU switching code used to make a distinction - but there's no lazy switching code anymore, we always switch in an 'eager' fashion. Do this by first changing all substantial uses of fpu->fpregs_active to fpu->fpstate_active and adding a few debug checks to double check our assumption is correct. Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Eric Biggers <ebiggers3@gmail.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Yu-cheng Yu <yu-cheng.yu@intel.com> Link: http://lkml.kernel.org/r/20170923130016.21448-19-mingo@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b6aa855 commit f1c8cd0

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ static inline void fpregs_activate(struct fpu *fpu)
556556
static inline void
557557
switch_fpu_prepare(struct fpu *old_fpu, int cpu)
558558
{
559-
if (old_fpu->fpregs_active) {
559+
WARN_ON_FPU(old_fpu->fpregs_active != old_fpu->fpstate_active);
560+
561+
if (old_fpu->fpstate_active) {
560562
if (!copy_fpregs_to_fpstate(old_fpu))
561563
old_fpu->last_cpu = -1;
562564
else

arch/x86/kernel/fpu/core.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void __kernel_fpu_begin(void)
100100

101101
kernel_fpu_disable();
102102

103-
if (fpu->fpregs_active) {
103+
if (fpu->fpstate_active) {
104104
/*
105105
* Ignore return value -- we don't care if reg state
106106
* is clobbered.
@@ -116,7 +116,7 @@ void __kernel_fpu_end(void)
116116
{
117117
struct fpu *fpu = &current->thread.fpu;
118118

119-
if (fpu->fpregs_active)
119+
if (fpu->fpstate_active)
120120
copy_kernel_to_fpregs(&fpu->state);
121121

122122
kernel_fpu_enable();
@@ -147,8 +147,10 @@ void fpu__save(struct fpu *fpu)
147147
WARN_ON_FPU(fpu != &current->thread.fpu);
148148

149149
preempt_disable();
150+
WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
151+
150152
trace_x86_fpu_before_save(fpu);
151-
if (fpu->fpregs_active) {
153+
if (fpu->fpstate_active) {
152154
if (!copy_fpregs_to_fpstate(fpu)) {
153155
copy_kernel_to_fpregs(&fpu->state);
154156
}
@@ -262,11 +264,12 @@ EXPORT_SYMBOL_GPL(fpu__activate_curr);
262264
*/
263265
void fpu__activate_fpstate_read(struct fpu *fpu)
264266
{
267+
WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
265268
/*
266269
* If fpregs are active (in the current CPU), then
267270
* copy them to the fpstate:
268271
*/
269-
if (fpu->fpregs_active) {
272+
if (fpu->fpstate_active) {
270273
fpu__save(fpu);
271274
} else {
272275
if (!fpu->fpstate_active) {
@@ -362,12 +365,13 @@ void fpu__current_fpstate_write_end(void)
362365
{
363366
struct fpu *fpu = &current->thread.fpu;
364367

368+
WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
365369
/*
366370
* 'fpu' now has an updated copy of the state, but the
367371
* registers may still be out of date. Update them with
368372
* an XRSTOR if they are active.
369373
*/
370-
if (fpu->fpregs_active)
374+
if (fpu->fpstate_active)
371375
copy_kernel_to_fpregs(&fpu->state);
372376

373377
/*
@@ -417,7 +421,7 @@ void fpu__drop(struct fpu *fpu)
417421
if (fpu == &current->thread.fpu) {
418422
WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
419423

420-
if (fpu->fpregs_active) {
424+
if (fpu->fpstate_active) {
421425
/* Ignore delayed exceptions from user space */
422426
asm volatile("1: fwait\n"
423427
"2:\n"

arch/x86/kernel/fpu/signal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
171171
sizeof(struct user_i387_ia32_struct), NULL,
172172
(struct _fpstate_32 __user *) buf) ? -1 : 1;
173173

174-
if (fpu->fpregs_active || using_compacted_format()) {
174+
WARN_ON_FPU(fpu->fpstate_active != fpu->fpregs_active);
175+
176+
if (fpu->fpstate_active || using_compacted_format()) {
175177
/* Save the live register state to the user directly. */
176178
if (copy_fpregs_to_sigframe(buf_fx))
177179
return -1;

arch/x86/mm/pkeys.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <asm/cpufeature.h> /* boot_cpu_has, ... */
2020
#include <asm/mmu_context.h> /* vma_pkey() */
21-
#include <asm/fpu/internal.h> /* fpregs_active() */
2221

2322
int __execute_only_pkey(struct mm_struct *mm)
2423
{
@@ -45,7 +44,7 @@ int __execute_only_pkey(struct mm_struct *mm)
4544
*/
4645
preempt_disable();
4746
if (!need_to_set_mm_pkey &&
48-
current->thread.fpu.fpregs_active &&
47+
current->thread.fpu.fpstate_active &&
4948
!__pkru_allows_read(read_pkru(), execute_only_pkey)) {
5049
preempt_enable();
5150
return execute_only_pkey;

0 commit comments

Comments
 (0)