From: Dave Hansen <dave.hansen@intel.com>
To: "Chang S. Bae" <chang.seok.bae@intel.com>, linux-kernel@vger.kernel.org
Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, hdegoede@redhat.com,
ilpo.jarvinen@linux.intel.com, tony.luck@intel.com,
ashok.raj@intel.com, jithu.joseph@intel.com
Subject: Re: [PATCH v2 1/2] x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state
Date: Thu, 9 May 2024 10:36:16 -0700 [thread overview]
Message-ID: <fde6149c-7ddf-488f-98c0-04f336b7092e@intel.com> (raw)
In-Reply-To: <7e589b35-4ff8-43fa-99dd-d3b17f56d3ea@intel.com>
On 5/8/24 17:29, Chang S. Bae wrote:
> +void kernel_fpu_reset(void)
> +{
> + kernel_fpu_begin();
> + if (cpu_feature_enabled(X86_FEATURE_AMX_TILE))
> + tile_release();
> + kernel_fpu_end();
> +}
> +EXPORT_SYMBOL(kernel_fpu_reset);
> +
...
> --- a/drivers/platform/x86/intel/ifs/runtest.c
> +++ b/drivers/platform/x86/intel/ifs/runtest.c
> @@ -188,6 +188,8 @@ static int doscan(void *data)
> /* Only the first logical CPU on a core reports result */
> first = cpumask_first(cpu_smt_mask(cpu));
>
> + kernel_fpu_reset();
> +
> wait_for_sibling_cpu(&scan_cpus_in, NSEC_PER_SEC);
Remember, kernel_fpu_begin/end() mark a section of code that needs the
FPU. Once code calls kernel_fpu_end(), it no longer owns the FPU and
all bets are off. A interrupt could theoretically come in and do
whatever it wants.
I _assume_ that this is practically impossible since the stop_machine()
infrastructure keeps interrupts at bay. But it's rather subtle.
I'd probably just do this:
+ kernel_fpu_begin();
+ // AMX *MUST* be in the init state for the wrmsr() to work.
+ // But, the more in the init state, the less state the test
+ // has to save and restore. Just zap everything.
+ restore_fpregs_from_fpstate(&init_fpstate,
+ fpu_user_cfg.max_features);
+
wrmsrl(MSR_ACTIVATE_SCAN, params->activate->data);
rdmsrl(MSR_SCAN_STATUS, status.data);
+ kernel_fpu_end();
That's dirt simple. It doesn't require new infrastructure. It doesn't
call an opaque new helper. It doesn't require a feature check. It
probably makes the IFS test run faster. It will also magically work for
any fancy new feature that comes along which *ALSO* needs to be in its
init state ... with zero changes to this code. For bonus points, this
code is quite universal. It will work, as-is, in a bunch of kernel
contexts if future deranged kernel developer copies and pastes it. The
code you suggested above can race unless it's called under
stop_machine() and isn't safe to copy elsewhere.
Three lines of code:
1. IFS declares its need to own the FPU for a moment, like any
other kernel_fpu_begin() user. It's not a special snowflake.
It is boring.
2. IFS zaps the FPU state
3. IFS gives up the FPU
Am I out of my mind? What am I missing? Why bother with _anything_
more complicated than this?
next prev parent reply other threads:[~2024-05-09 17:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 21:25 [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver Chang S. Bae
2024-04-30 21:25 ` [PATCH 1/2] x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state Chang S. Bae
2024-04-30 23:42 ` Ashok Raj
2024-04-30 21:25 ` [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test Chang S. Bae
2024-05-01 0:06 ` Ashok Raj
2024-05-01 8:58 ` Hans de Goede
2024-05-08 0:22 ` Chang S. Bae
2024-05-02 11:00 ` Ilpo Järvinen
2024-05-02 22:19 ` Chang S. Bae
2024-05-09 0:45 ` Kuppuswamy Sathyanarayanan
2024-05-02 20:52 ` [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver Chang S. Bae
2024-05-02 21:35 ` Chang S. Bae
2024-05-02 20:59 ` Dave Hansen
2024-05-07 23:53 ` [PATCH v2 " Chang S. Bae
2024-05-07 23:53 ` [PATCH v2 1/2] x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state Chang S. Bae
2024-05-08 13:00 ` Thomas Gleixner
2024-05-08 14:40 ` Dave Hansen
2024-05-08 18:03 ` Chang S. Bae
2024-05-08 19:11 ` Dave Hansen
2024-05-09 0:29 ` Chang S. Bae
2024-05-09 17:36 ` Dave Hansen [this message]
2024-05-09 17:41 ` Dave Hansen
2024-05-09 18:41 ` Chang S. Bae
2024-05-09 18:50 ` Dave Hansen
2024-05-10 7:51 ` Thomas Gleixner
2024-05-07 23:53 ` [PATCH v2 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test Chang S. Bae
2024-05-08 0:19 ` Ashok Raj
2024-05-08 0:21 ` Chang S. Bae
2024-05-08 8:28 ` [PATCH v2 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver Ilpo Järvinen
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=fde6149c-7ddf-488f-98c0-04f336b7092e@intel.com \
--to=dave.hansen@intel.com \
--cc=ashok.raj@intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jithu.joseph@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--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