[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-4ee91519e1dccc175665fe24bb20a47c6053575c@git.kernel.org>
Date: Sat, 13 Apr 2019 13:52:10 -0700
From: tip-bot for Rik van Riel <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: Jason@...c4.com, aubrey.li@...el.com, luto@...nel.org,
dave.hansen@...el.com, rkrcmar@...hat.com, jannh@...gle.com,
x86@...nel.org, pbonzini@...hat.com, mingo@...hat.com,
riel@...riel.com, bp@...e.de, tglx@...utronix.de,
kvm@...r.kernel.org, bigeasy@...utronix.de, hpa@...or.com,
linux-kernel@...r.kernel.org, mingo@...nel.org
Subject: [tip:x86/fpu] x86/fpu: Add an __fpregs_load_activate() internal
helper
Commit-ID: 4ee91519e1dccc175665fe24bb20a47c6053575c
Gitweb: https://git.kernel.org/tip/4ee91519e1dccc175665fe24bb20a47c6053575c
Author: Rik van Riel <riel@...riel.com>
AuthorDate: Wed, 3 Apr 2019 18:41:38 +0200
Committer: Borislav Petkov <bp@...e.de>
CommitDate: Wed, 10 Apr 2019 16:23:14 +0200
x86/fpu: Add an __fpregs_load_activate() internal helper
Add a helper function that ensures the floating point registers for the
current task are active. Use with preemption disabled.
While at it, add fpregs_lock/unlock() helpers too, to be used in later
patches.
[ bp: Add a comment about its intended usage. ]
Signed-off-by: Rik van Riel <riel@...riel.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Signed-off-by: Borislav Petkov <bp@...e.de>
Reviewed-by: Dave Hansen <dave.hansen@...el.com>
Reviewed-by: Thomas Gleixner <tglx@...utronix.de>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Aubrey Li <aubrey.li@...el.com>
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Jann Horn <jannh@...gle.com>
Cc: "Jason A. Donenfeld" <Jason@...c4.com>
Cc: kvm ML <kvm@...r.kernel.org>
Cc: Paolo Bonzini <pbonzini@...hat.com>
Cc: Radim Krčmář <rkrcmar@...hat.com>
Cc: Rik van Riel <riel@...riel.com>
Cc: x86-ml <x86@...nel.org>
Link: https://lkml.kernel.org/r/20190403164156.19645-10-bigeasy@linutronix.de
---
arch/x86/include/asm/fpu/api.h | 11 +++++++++++
arch/x86/include/asm/fpu/internal.h | 22 ++++++++++++++--------
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index b56d504af654..73e684160f35 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>
/*
* Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It
@@ -22,6 +23,16 @@ extern void kernel_fpu_begin(void);
extern void kernel_fpu_end(void);
extern bool irq_fpu_usable(void);
+static inline void fpregs_lock(void)
+{
+ preempt_disable();
+}
+
+static inline void fpregs_unlock(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 54f70cae2f15..3e0c2c496f2d 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -484,6 +484,18 @@ static inline void fpregs_activate(struct fpu *fpu)
trace_x86_fpu_regs_activated(fpu);
}
+/*
+ * Internal helper, do not use directly. Use switch_fpu_return() instead.
+ */
+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);
+ fpregs_activate(fpu);
+ }
+}
+
/*
* FPU state switching for scheduling.
*
@@ -522,14 +534,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);
- }
-
- fpregs_activate(new_fpu);
- }
+ if (static_cpu_has(X86_FEATURE_FPU))
+ __fpregs_load_activate(new_fpu, cpu);
}
/*
Powered by blists - more mailing lists