From: Ingo Molnar <mingo@kernel.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: x86@kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Ben Greear <greearb@candelatech.com>,
Xiao Liang <shaw.leon@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC PATCH v2] x86/fpu: make kernel-mode FPU reliably usable in softirqs
Date: Wed, 5 Mar 2025 19:09:15 +0100 [thread overview]
Message-ID: <Z8iTSzfzrFLv-JBL@gmail.com> (raw)
In-Reply-To: <20250305173925.GA4014401@google.com>
* Eric Biggers <ebiggers@kernel.org> wrote:
> [...] To avoid irqs_disabled() entirely, we'd need to avoid disabling
> softirqs, which would mean supporting nested kernel-mode FPU in
> softirqs. I can sent out a patch that does that using a per-CPU
> buffer, if you'd like to see that. I wasn't super happy with the
> extra edge cases and memory usage, but we could go in that direction.
Meh: so I just checked, and local_bh_disable()/enable() are pretty
heavy these days - it's not just a simple preempt-count twiddle and a
check anymore. :-/ I don't think my initial argument of irqs_disabled()
overhead is really valid - and if we really cared we could halve it by
saving the irqs_disabled() status at kernel_fpu_begin() time and
reading it at kernel_fpu_end() time.
And the alternative of having nested FPU usage and extra per-CPU FPU
save areas for the kernel feels a bit fragile, even without having seen
the patch.
So I think I'll commit your patch to tip:x86/fpu as-is, unless someone
objects.
BTW., a side note, I was also reviewing the kernel_fpu_begin()/end()
codepaths, and we have gems like:
/* Put sane initial values into the control registers. */
if (likely(kfpu_mask & KFPU_MXCSR) && boot_cpu_has(X86_FEATURE_XMM))
ldmxcsr(MXCSR_DEFAULT);
if (unlikely(kfpu_mask & KFPU_387) && boot_cpu_has(X86_FEATURE_FPU))
asm volatile ("fninit");
has the LDMXCSR instruction, or its effects, ever shown up in profiles?
Because AFAICS these will execute all the time on x86-64, because:
static inline void kernel_fpu_begin(void)
{
#ifdef CONFIG_X86_64
/*
* Any 64-bit code that uses 387 instructions must explicitly request
* KFPU_387.
*/
kernel_fpu_begin_mask(KFPU_MXCSR);
And X86_FEATURE_XMM is set in pretty much every x86 CPU.
Thanks,
Ingo
next prev parent reply other threads:[~2025-03-05 18:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 20:49 [RFC PATCH v2] x86/fpu: make kernel-mode FPU reliably usable in softirqs Eric Biggers
2025-03-05 9:07 ` Ingo Molnar
2025-03-05 16:55 ` Dave Hansen
2025-03-05 17:37 ` Ingo Molnar
2025-03-05 18:04 ` Dave Hansen
2025-03-05 18:13 ` Ingo Molnar
2025-03-05 21:22 ` David Laight
2025-03-05 17:39 ` Eric Biggers
2025-03-05 18:09 ` Ingo Molnar [this message]
2025-03-05 20:30 ` Eric Biggers
2025-03-06 11:42 ` Ingo Molnar
2025-03-06 12:09 ` Peter Zijlstra
2025-03-06 12:00 ` [tip: x86/fpu] x86/fpu: Improve crypto performance by making " tip-bot2 for Eric Biggers
2025-03-06 17:54 ` 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=Z8iTSzfzrFLv-JBL@gmail.com \
--to=mingo@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=ebiggers@kernel.org \
--cc=greearb@candelatech.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=shaw.leon@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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