[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181107194858.9380-12-bigeasy@linutronix.de>
Date: Wed, 7 Nov 2018 20:48:46 +0100
From: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To: linux-kernel@...r.kernel.org
Cc: x86@...nel.org, Andy Lutomirski <luto@...nel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Radim Krčmář <rkrcmar@...hat.com>,
kvm@...r.kernel.org, "Jason A. Donenfeld" <Jason@...c4.com>,
Rik van Riel <riel@...riel.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Subject: [PATCH 11/23] x86/fpu: Add (__)make_fpregs_active helpers
From: Rik van Riel <riel@...riel.com>
Add helper function that ensures the floating point registers for
the current task are active. Use with preemption disabled.
Signed-off-by: Rik van Riel <riel@...riel.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
---
arch/x86/include/asm/fpu/api.h | 11 +++++++++++
arch/x86/include/asm/fpu/internal.h | 26 ++++++++++++++++----------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index a9caac9d4a729..8c03b42416656 100644
--- a/arch/x86/include/asm/fpu/api.h
+++ b/arch/x86/include/asm/fpu/api.h
@@ -10,6 +10,7 @@
#ifndef _ASM_X86_FPU_API_H
#define _ASM_X86_FPU_API_H
+#include <linux/preempt.h>
/*
* Careful: __kernel_fpu_begin/end() must be called with preempt disabled
@@ -27,6 +28,16 @@ extern void kernel_fpu_begin(void);
extern void kernel_fpu_end(void);
extern bool irq_fpu_usable(void);
+static inline void __fpregs_changes_begin(void)
+{
+ preempt_disable();
+}
+
+static inline void __fpregs_changes_end(void)
+{
+ preempt_enable();
+}
+
/*
* Query the presence of one or more xfeatures. Works on any legacy CPU as well.
*
diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index d7f9e14c73c19..260cd4f4ba2bb 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -512,6 +512,20 @@ static inline void fpregs_activate(struct fpu *fpu)
trace_x86_fpu_regs_activated(fpu);
}
+/*
+ * Load the FPU state for the current task. Call with preemption disabled.
+ */
+static inline void __fpregs_load_activate(struct fpu *fpu, int cpu)
+{
+ if (!fpregs_state_valid(fpu, cpu)) {
+ if (current->mm)
+ copy_kernel_to_fpregs(&fpu->state);
+ else
+ copy_kernel_to_fpregs(&init_fpstate);
+ }
+ fpregs_activate(fpu);
+}
+
/*
* FPU state switching for scheduling.
*
@@ -547,16 +561,8 @@ switch_fpu_prepare(struct fpu *old_fpu, int cpu)
*/
static inline void switch_fpu_finish(struct fpu *new_fpu, int cpu)
{
- if (static_cpu_has(X86_FEATURE_FPU)) {
- if (!fpregs_state_valid(new_fpu, cpu)) {
- if (current->mm)
- copy_kernel_to_fpregs(&new_fpu->state);
- else
- copy_kernel_to_fpregs(&init_fpstate);
- }
-
- fpregs_activate(new_fpu);
- }
+ if (static_cpu_has(X86_FEATURE_FPU))
+ __fpregs_load_activate(new_fpu, cpu);
}
/*
--
2.19.1
Powered by blists - more mailing lists