From: Eric Biggers <ebiggers@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-pm@vger.kernel.org, Borislav Petkov <bp@alien8.de>,
Thomas Gleixner <tglx@linutronix.de>,
Ayush Jain <Ayush.Jain3@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH v3 1/2] x86/fpu: Replace in_kernel_fpu with kernel_fpu_allowed
Date: Tue, 20 May 2025 08:29:37 -0700 [thread overview]
Message-ID: <20250520152938.21881-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20250520152938.21881-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Replace the per-CPU bool in_kernel_fpu with kernel_fpu_allowed which
carries the opposite meaning. Initialize to true instead of false. No
functional change.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
arch/x86/kernel/fpu/core.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 948b4f5fad99c..6495259a23962 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -43,11 +43,11 @@ struct fpu_state_config fpu_user_cfg __ro_after_init;
* depending on the FPU hardware format:
*/
struct fpstate init_fpstate __ro_after_init;
/* Track in-kernel FPU usage */
-static DEFINE_PER_CPU(bool, in_kernel_fpu);
+static DEFINE_PER_CPU(bool, kernel_fpu_allowed) = true;
/*
* Track which context is using the FPU on the CPU:
*/
DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
@@ -75,11 +75,11 @@ bool irq_fpu_usable(void)
* In kernel FPU usage already active? This detects any explicitly
* nested usage in task or softirq context, which is unsupported. It
* also detects attempted usage in a hardirq that has interrupted a
* kernel-mode FPU section.
*/
- if (this_cpu_read(in_kernel_fpu)) {
+ if (!this_cpu_read(kernel_fpu_allowed)) {
WARN_ON_FPU(!in_hardirq());
return false;
}
/*
@@ -437,13 +437,14 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
{
if (!irqs_disabled())
fpregs_lock();
WARN_ON_FPU(!irq_fpu_usable());
- WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
- this_cpu_write(in_kernel_fpu, true);
+ /* Toggle kernel_fpu_allowed to false: */
+ WARN_ON_FPU(!this_cpu_read(kernel_fpu_allowed));
+ this_cpu_write(kernel_fpu_allowed, false);
if (!(current->flags & (PF_KTHREAD | PF_USER_WORKER)) &&
!test_thread_flag(TIF_NEED_FPU_LOAD)) {
set_thread_flag(TIF_NEED_FPU_LOAD);
save_fpregs_to_fpstate(x86_task_fpu(current));
@@ -459,13 +460,14 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
}
EXPORT_SYMBOL_GPL(kernel_fpu_begin_mask);
void kernel_fpu_end(void)
{
- WARN_ON_FPU(!this_cpu_read(in_kernel_fpu));
+ /* Toggle kernel_fpu_allowed back to true: */
+ WARN_ON_FPU(this_cpu_read(kernel_fpu_allowed));
+ this_cpu_write(kernel_fpu_allowed, true);
- this_cpu_write(in_kernel_fpu, false);
if (!irqs_disabled())
fpregs_unlock();
}
EXPORT_SYMBOL_GPL(kernel_fpu_end);
--
2.49.0
next prev parent reply other threads:[~2025-05-20 15:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 15:29 [PATCH v3 0/2] x86/fpu: Fix irq_fpu_usable() to return false during CPU onlining Eric Biggers
2025-05-20 15:29 ` Eric Biggers [this message]
2025-05-20 15:29 ` [PATCH v3 2/2] " Eric Biggers
2025-05-28 2:04 ` kernel test robot
2025-05-28 4:25 ` Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250520152938.21881-2-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Ayush.Jain3@amd.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox