2024-04-30 21:41:26

by Chang S. Bae

[permalink] [raw]
Subject: [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

The recent update [1] in the SDM highlights the requirement of
initializing the AMX state for executing the scan test:
"... maintaining AMX state in a non-initialized state ... will
prevent the execution of In-Field Scan tests."
which is one of CPU state conditions required for the test's execution.

In situations where AMX workloads are running, the switched-away active
user AMX state remains due to the optimization to reduce the state
switching cost. A user state reload is fully completed right before
returning to userspace. Consequently, if the switched-in kernel task is
executing the scan test, this non-initialized AMX state causes the test
to be unable to start.

Given the benefit of the scan test in detecting hardware faults, ensuring
its seamless execution is not negligible. This necessitates a proper API
for the driver code to initialize AMX states. Although fpu_idle_fpregs()
may initialize the AMX state, its primary usage should be limited to
sleep state handling, making it unsuitable for the scan test.

The across-architecture FPU API, kernel_fpu_begin()/kernel_fpu_end(), is
universally established for floating-point SIMD code in the kernel. On
x86, kernel_fpu_begin_mask() is available, with kernel_fpu_begin()
serving as a wrapper to it for initializing legacy states by default.

The proposed solution extends kernel_fpu_begin_mask() to accept a new
option for initializing the AMX state. Additionally, it introduces custom
FPU handling wrappers for the In-Field Scan driver, which are variants of
kernel_fpu_begin()/kernel_fpu_end(). This approach is considerably
compliant with established semantics, following the EFI case with
efi_fpu_begin/efi_fpu_end().

Thanks,
Chang

[1] Intel Software Development Manual as of March 2024, Section 18.2
RECOMMENDATIONS FOR SYSTEM SOFTWARE of Vol. 1.
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html

Chang S. Bae (2):
x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state
platform/x86/intel/ifs: Initialize AMX state for the scan test

arch/x86/include/asm/fpu/api.h | 1 +
arch/x86/kernel/fpu/core.c | 3 +++
drivers/platform/x86/intel/ifs/ifs.h | 14 ++++++++++++++
drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
4 files changed, 24 insertions(+)


base-commit: e67572cd2204894179d89bd7b984072f19313b03
--
2.34.1



2024-04-30 21:43:14

by Chang S. Bae

[permalink] [raw]
Subject: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

The scan test does not start when the AMX state remains active and is not
re-initialized. With the extension of kernel_fpu_begin_mask(), the driver
code can now initialize the state properly.

Introduce custom FPU handling wrappers to ensure compliant with the
established FPU API semantics, as kernel_fpu_begin() exclusively sets
legacy states. This follows the EFI case from commit b0dc553cfc9d
("x86/fpu: Make the EFI FPU calling convention explicit").

Then, use these wrappers to surround the MSR_ACTIVATE_SCAN write to
minimize the critical section. To prevent unnecessary delays, invoke
ifs_fpu_begin() before entering the rendezvous loop.

Signed-off-by: Chang S. Bae <[email protected]>
Reviewed-by: Jithu Joseph <[email protected]>
Tested-by: Jithu Joseph <[email protected]>
---
drivers/platform/x86/intel/ifs/ifs.h | 14 ++++++++++++++
drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
2 files changed, 20 insertions(+)

diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h
index 56b9f3e3cf76..71d8b50854b2 100644
--- a/drivers/platform/x86/intel/ifs/ifs.h
+++ b/drivers/platform/x86/intel/ifs/ifs.h
@@ -325,4 +325,18 @@ int do_core_test(int cpu, struct device *dev);
extern struct attribute *plat_ifs_attrs[];
extern struct attribute *plat_ifs_array_attrs[];

+static inline void ifs_fpu_begin(void)
+{
+ /*
+ * The AMX state must be initialized prior to executing In-Field
+ * Scan tests, according to Intel SDM.
+ */
+ kernel_fpu_begin_mask(KFPU_AMX);
+}
+
+static inline void ifs_fpu_end(void)
+{
+ kernel_fpu_end();
+}
+
#endif
diff --git a/drivers/platform/x86/intel/ifs/runtest.c b/drivers/platform/x86/intel/ifs/runtest.c
index 95b4b71fab53..a35eac7c0b44 100644
--- a/drivers/platform/x86/intel/ifs/runtest.c
+++ b/drivers/platform/x86/intel/ifs/runtest.c
@@ -188,6 +188,9 @@ static int doscan(void *data)
/* Only the first logical CPU on a core reports result */
first = cpumask_first(cpu_smt_mask(cpu));

+ /* Prepare FPU state before entering the rendezvous loop*/
+ ifs_fpu_begin();
+
wait_for_sibling_cpu(&scan_cpus_in, NSEC_PER_SEC);

/*
@@ -199,6 +202,9 @@ static int doscan(void *data)
* are processed in a single pass) before it retires.
*/
wrmsrl(MSR_ACTIVATE_SCAN, params->activate->data);
+
+ ifs_fpu_end();
+
rdmsrl(MSR_SCAN_STATUS, status.data);

trace_ifs_status(ifsd->cur_batch, start, stop, status.data);
--
2.34.1


2024-04-30 21:43:24

by Chang S. Bae

[permalink] [raw]
Subject: [PATCH 1/2] x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state

The In-Field Scan [1] test does not start its operation when the CPU is
unprepared. If the AMX state is uninitialized, the scan test will
immediately terminate. Therefore, a proper initialization of the AMX
state is necessary to run the test.

Although fpu_idle_fpregs() initializes the state, its usage should be
limited to specialized cases, primarily before entering the sleep state.
The restore_fpregs_from_fpstate() function offers a suitable mechanism
for initializing fpstate in general, which remains within the core code.

Extend kernel_fpu_begin_mask() to include AMX state initialization,
providing the in-field scan driver code access to the appropriate
initialization method while maintaining compliance with established FPU
API semantics.

[1] https://docs.kernel.org/arch/x86/ifs.html
Signed-off-by: Chang S. Bae <[email protected]>
---
The necessity for AMX initialization is clarified in the Intel Software
Development Manual as of March 2024, particularly in Section 18.2
RECOMMENDATIONS FOR SYSTEM SOFTWARE of Vol. 1.

Side note: restore_fpregs_from_fpstate() also sets the x87 state to a
fixed value. However, this only applies to AMD CPUs with the FXSAVE_LEAK
quirk.
---
arch/x86/include/asm/fpu/api.h | 1 +
arch/x86/kernel/fpu/core.c | 3 +++
2 files changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index a2be3aefff9f..67887fc45c24 100644
--- a/arch/x86/include/asm/fpu/api.h
+++ b/arch/x86/include/asm/fpu/api.h
@@ -25,6 +25,7 @@
/* Kernel FPU states to initialize in kernel_fpu_begin_mask() */
#define KFPU_387 _BITUL(0) /* 387 state will be initialized */
#define KFPU_MXCSR _BITUL(1) /* MXCSR will be initialized */
+#define KFPU_AMX _BITUL(2) /* AMX will be initialized */

extern void kernel_fpu_begin_mask(unsigned int kfpu_mask);
extern void kernel_fpu_end(void);
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 520deb411a70..0c0235b4a901 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -440,6 +440,9 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)

if (unlikely(kfpu_mask & KFPU_387) && boot_cpu_has(X86_FEATURE_FPU))
asm volatile ("fninit");
+
+ if (unlikely(kfpu_mask & KFPU_AMX) && boot_cpu_has(X86_FEATURE_AMX_TILE))
+ restore_fpregs_from_fpstate(&init_fpstate, XFEATURE_MASK_XTILE);
}
EXPORT_SYMBOL_GPL(kernel_fpu_begin_mask);

--
2.34.1


2024-04-30 23:42:59

by Ashok Raj

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state

On Tue, Apr 30, 2024 at 02:25:07PM -0700, Bae, Chang Seok wrote:
> The In-Field Scan [1] test does not start its operation when the CPU is
> unprepared. If the AMX state is uninitialized, the scan test will
> immediately terminate. Therefore, a proper initialization of the AMX
> state is necessary to run the test.

Instead of using new terminology like "unprepared", maybe use the
term "non-initialized state" as in the SDM for clarity?

Maintaining AMX state in a non-initialized state will prevent In-field
Scan test [1] to abort without making progress.

>
> Although fpu_idle_fpregs() initializes the state, its usage should be
> limited to specialized cases, primarily before entering the sleep state.
> The restore_fpregs_from_fpstate() function offers a suitable mechanism
> for initializing fpstate in general, which remains within the core code.
>
> Extend kernel_fpu_begin_mask() to include AMX state initialization,
> providing the in-field scan driver code access to the appropriate
> initialization method while maintaining compliance with established FPU
> API semantics.

Maybe simplify the above paragraph with

Extend kernel_fpu_begin_mask() to allow In-field scan driver to initialize
AMX state before running tests.

>
> [1] https://docs.kernel.org/arch/x86/ifs.html
> Signed-off-by: Chang S. Bae <[email protected]>
> ---
> The necessity for AMX initialization is clarified in the Intel Software
> Development Manual as of March 2024, particularly in Section 18.2
> RECOMMENDATIONS FOR SYSTEM SOFTWARE of Vol. 1.
>
> Side note: restore_fpregs_from_fpstate() also sets the x87 state to a
> fixed value. However, this only applies to AMD CPUs with the FXSAVE_LEAK
> quirk.
> ---
> arch/x86/include/asm/fpu/api.h | 1 +
> arch/x86/kernel/fpu/core.c | 3 +++
> 2 files changed, 4 insertions(+)
>
> diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
> index a2be3aefff9f..67887fc45c24 100644
> --- a/arch/x86/include/asm/fpu/api.h
> +++ b/arch/x86/include/asm/fpu/api.h
> @@ -25,6 +25,7 @@
> /* Kernel FPU states to initialize in kernel_fpu_begin_mask() */
> #define KFPU_387 _BITUL(0) /* 387 state will be initialized */
> #define KFPU_MXCSR _BITUL(1) /* MXCSR will be initialized */
> +#define KFPU_AMX _BITUL(2) /* AMX will be initialized */
>
> extern void kernel_fpu_begin_mask(unsigned int kfpu_mask);
> extern void kernel_fpu_end(void);
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index 520deb411a70..0c0235b4a901 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -440,6 +440,9 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
>
> if (unlikely(kfpu_mask & KFPU_387) && boot_cpu_has(X86_FEATURE_FPU))
> asm volatile ("fninit");
> +
> + if (unlikely(kfpu_mask & KFPU_AMX) && boot_cpu_has(X86_FEATURE_AMX_TILE))
> + restore_fpregs_from_fpstate(&init_fpstate, XFEATURE_MASK_XTILE);
> }
> EXPORT_SYMBOL_GPL(kernel_fpu_begin_mask);
>
> --
> 2.34.1
>

--
Cheers,
Ashok

2024-05-01 00:06:36

by Ashok Raj

[permalink] [raw]
Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

On Tue, Apr 30, 2024 at 02:25:08PM -0700, Bae, Chang Seok wrote:
> The scan test does not start when the AMX state remains active and is not
> re-initialized. With the extension of kernel_fpu_begin_mask(), the driver
> code can now initialize the state properly.

Avoid "re-initialized" and maybe use the same SDM language here as well?

Infield Scan aborts if AMX state is not in initialized state. Use
the kernel_fpu_begin_mask(KFPU_AMX) to ensure AMX state is initialized.

>
> Introduce custom FPU handling wrappers to ensure compliant with the
> established FPU API semantics, as kernel_fpu_begin() exclusively sets
> legacy states. This follows the EFI case from commit b0dc553cfc9d
> ("x86/fpu: Make the EFI FPU calling convention explicit").

The EFI and commit mention is worthy of prior use, but the first line
isn't reading well... Maybe

Introduce custom FPU handling wrappers to ensure compliance with the
established FPU API semantics. This change follows the EFI case from
commit b0dc553cfc9d ("x86/fpu: Make the EFI FPU calling convention explicit").

I dropped the note about legacy states, I didn't quite know how to word
that.

>
> Then, use these wrappers to surround the MSR_ACTIVATE_SCAN write to
> minimize the critical section. To prevent unnecessary delays, invoke
> ifs_fpu_begin() before entering the rendezvous loop.
>
> Signed-off-by: Chang S. Bae <[email protected]>
> Reviewed-by: Jithu Joseph <[email protected]>
> Tested-by: Jithu Joseph <[email protected]>

2024-05-01 08:59:07

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

Hi,

On 4/30/24 11:25 PM, Chang S. Bae wrote:
> The scan test does not start when the AMX state remains active and is not
> re-initialized. With the extension of kernel_fpu_begin_mask(), the driver
> code can now initialize the state properly.
>
> Introduce custom FPU handling wrappers to ensure compliant with the
> established FPU API semantics, as kernel_fpu_begin() exclusively sets
> legacy states. This follows the EFI case from commit b0dc553cfc9d
> ("x86/fpu: Make the EFI FPU calling convention explicit").
>
> Then, use these wrappers to surround the MSR_ACTIVATE_SCAN write to
> minimize the critical section. To prevent unnecessary delays, invoke
> ifs_fpu_begin() before entering the rendezvous loop.
>
> Signed-off-by: Chang S. Bae <[email protected]>
> Reviewed-by: Jithu Joseph <[email protected]>
> Tested-by: Jithu Joseph <[email protected]>

Thanks, the patch looks good to me.

I believe this is best merged through the tip/x86 tree together
with patch 1/2 :

Acked-by: Hans de Goede <[email protected]>

I have checked and this should not cause any conflicts with
the ifs changes current in platform-drivers-x86/for-next.

Regards,

Hans




> ---
> drivers/platform/x86/intel/ifs/ifs.h | 14 ++++++++++++++
> drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h
> index 56b9f3e3cf76..71d8b50854b2 100644
> --- a/drivers/platform/x86/intel/ifs/ifs.h
> +++ b/drivers/platform/x86/intel/ifs/ifs.h
> @@ -325,4 +325,18 @@ int do_core_test(int cpu, struct device *dev);
> extern struct attribute *plat_ifs_attrs[];
> extern struct attribute *plat_ifs_array_attrs[];
>
> +static inline void ifs_fpu_begin(void)
> +{
> + /*
> + * The AMX state must be initialized prior to executing In-Field
> + * Scan tests, according to Intel SDM.
> + */
> + kernel_fpu_begin_mask(KFPU_AMX);
> +}
> +
> +static inline void ifs_fpu_end(void)
> +{
> + kernel_fpu_end();
> +}
> +
> #endif
> diff --git a/drivers/platform/x86/intel/ifs/runtest.c b/drivers/platform/x86/intel/ifs/runtest.c
> index 95b4b71fab53..a35eac7c0b44 100644
> --- a/drivers/platform/x86/intel/ifs/runtest.c
> +++ b/drivers/platform/x86/intel/ifs/runtest.c
> @@ -188,6 +188,9 @@ static int doscan(void *data)
> /* Only the first logical CPU on a core reports result */
> first = cpumask_first(cpu_smt_mask(cpu));
>
> + /* Prepare FPU state before entering the rendezvous loop*/
> + ifs_fpu_begin();
> +
> wait_for_sibling_cpu(&scan_cpus_in, NSEC_PER_SEC);
>
> /*
> @@ -199,6 +202,9 @@ static int doscan(void *data)
> * are processed in a single pass) before it retires.
> */
> wrmsrl(MSR_ACTIVATE_SCAN, params->activate->data);
> +
> + ifs_fpu_end();
> +
> rdmsrl(MSR_SCAN_STATUS, status.data);
>
> trace_ifs_status(ifsd->cur_batch, start, stop, status.data);


2024-05-02 11:02:16

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

On Tue, 30 Apr 2024, Chang S. Bae wrote:

> The scan test does not start when the AMX state remains active and is not
> re-initialized. With the extension of kernel_fpu_begin_mask(), the driver
> code can now initialize the state properly.
>
> Introduce custom FPU handling wrappers to ensure compliant with the
> established FPU API semantics, as kernel_fpu_begin() exclusively sets
> legacy states. This follows the EFI case from commit b0dc553cfc9d
> ("x86/fpu: Make the EFI FPU calling convention explicit").
>
> Then, use these wrappers to surround the MSR_ACTIVATE_SCAN write to
> minimize the critical section. To prevent unnecessary delays, invoke
> ifs_fpu_begin() before entering the rendezvous loop.
>
> Signed-off-by: Chang S. Bae <[email protected]>
> Reviewed-by: Jithu Joseph <[email protected]>
> Tested-by: Jithu Joseph <[email protected]>
> ---
> drivers/platform/x86/intel/ifs/ifs.h | 14 ++++++++++++++
> drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h
> index 56b9f3e3cf76..71d8b50854b2 100644
> --- a/drivers/platform/x86/intel/ifs/ifs.h
> +++ b/drivers/platform/x86/intel/ifs/ifs.h
> @@ -325,4 +325,18 @@ int do_core_test(int cpu, struct device *dev);
> extern struct attribute *plat_ifs_attrs[];
> extern struct attribute *plat_ifs_array_attrs[];
>
> +static inline void ifs_fpu_begin(void)
> +{
> + /*
> + * The AMX state must be initialized prior to executing In-Field
> + * Scan tests, according to Intel SDM.
> + */
> + kernel_fpu_begin_mask(KFPU_AMX);
> +}
> +
> +static inline void ifs_fpu_end(void)
> +{
> + kernel_fpu_end();
> +}
> +
> #endif
> diff --git a/drivers/platform/x86/intel/ifs/runtest.c b/drivers/platform/x86/intel/ifs/runtest.c
> index 95b4b71fab53..a35eac7c0b44 100644
> --- a/drivers/platform/x86/intel/ifs/runtest.c
> +++ b/drivers/platform/x86/intel/ifs/runtest.c
> @@ -188,6 +188,9 @@ static int doscan(void *data)
> /* Only the first logical CPU on a core reports result */
> first = cpumask_first(cpu_smt_mask(cpu));
>
> + /* Prepare FPU state before entering the rendezvous loop*/

Missing space

--
i.


2024-05-02 20:53:06

by Chang S. Bae

[permalink] [raw]
Subject: Re: [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

On 4/30/2024 2:25 PM, Chang S. Bae wrote:
> The recent update [1] in the SDM highlights the requirement of
> initializing the AMX state for executing the scan test:
> "... maintaining AMX state in a non-initialized state ... will
> prevent the execution of In-Field Scan tests."
> which is one of CPU state conditions required for the test's execution.

This brief mention may prompt questions about why the hardware must
refuse to run the test under these conditions. Because this is part of
its internal, we'd go back to folks who wrote this test and will grab
their write-up to provide the logic behind this requirement.

Thanks,
Chang


2024-05-02 20:59:42

by Dave Hansen

[permalink] [raw]
Subject: Re: [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

On 4/30/24 14:25, Chang S. Bae wrote:
> The recent update [1] in the SDM highlights the requirement of
> initializing the AMX state for executing the scan test:
> "... maintaining AMX state in a non-initialized state ... will
> prevent the execution of In-Field Scan tests."
> which is one of CPU state conditions required for the test's execution.

This ended up just being phrased weirdly. It's a lot more compact to
just say:

AMX must be in its init state for In-Field Scan tests to run.

> In situations where AMX workloads are running, the switched-away active
> user AMX state remains due to the optimization to reduce the state
> switching cost. A user state reload is fully completed right before
> returning to userspace. Consequently, if the switched-in kernel task is
> executing the scan test, this non-initialized AMX state causes the test
> to be unable to start.

FPU state in general (and AMX state in particular) is large and
expensive to context switch so the kernel tries to leave FPU state alone
even while running kernel tasks. But, this behavior obviously
conflicts with the (new) IFS need for AMX must be in its init state.

Right?

..
> [1] Intel Software Development Manual as of March 2024, Section 18.2
> RECOMMENDATIONS FOR SYSTEM SOFTWARE of Vol. 1.
> https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html

Rather than, "we're just following the spec", I think there can be a
better explanation here.

These in-field scan tests (IFS) poke the hardware in unique ways. It
ends up that IFS and AMX could attempt to use the same hardware
resources at the same time and step on each other. While it would be
possible to add additional resources to the CPU to allow simultaneous
AMX and IFS, the hardware to do this would be relatively expensive. It
seems pretty reasonable for software to help out here.

The other argument that could be made is that an admin could isolate the
CPUs on which they wanted to run an IFS test. They could use cpusets,
or even the task binding API to try and evict AMX workloads from these
CPUs. But, the promise of IFS is that it can be run without disturbing
workloads _too_ much. Basically anything an admin would do is probably
too onerous and high-impact.

So this mechanism provides two things: One, it makes the hardware
simpler and two, it takes the admin out of the picture. Thing just work.



2024-05-02 21:46:25

by Chang S. Bae

[permalink] [raw]
Subject: Re: [PATCH 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

On 5/2/2024 1:52 PM, Chang S. Bae wrote:
>
> This brief mention may prompt questions about why the hardware must
> refuse to run the test under these conditions. Because this is part of
> its internal, we'd go back to folks who wrote this test and will grab
> their write-up to provide the logic behind this requirement.

Okay, I got the write-up sooner than expected:

In-Field Scan (IFS) is a destructive test meaning that it will overwrite
the existing state to achieve the goal of testing the logic. IFS must
ensure that it is able to return the CPU back to the OS in the same
architectural state as it was prior to IFS start. To do this
architectural state (register state visible to the OS) is saved in a
cache [*]. The cache has a limited size. When AMX is in use, the state
of the AMX logic that needs to be saved is too large to be accommodated
in the cache. Therefore OS must clear the AMX logic from being in use
prior to IFS start.

[*] This cache is software-inaccessible space.

Thanks,
Chang

2024-05-02 22:20:06

by Chang S. Bae

[permalink] [raw]
Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

On 5/2/2024 4:00 AM, Ilpo Järvinen wrote:
> On Tue, 30 Apr 2024, Chang S. Bae wrote:
>
>> + /* Prepare FPU state before entering the rendezvous loop*/
>
> Missing space

Yeah, right. Thanks for spotting this.


2024-05-08 00:22:28

by Chang S. Bae

[permalink] [raw]
Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test

On 5/1/2024 1:58 AM, Hans de Goede wrote:
>
> Thanks, the patch looks good to me.
>
> I believe this is best merged through the tip/x86 tree together
> with patch 1/2 :
>
> Acked-by: Hans de Goede <[email protected]>
>
> I have checked and this should not cause any conflicts with
> the ifs changes current in platform-drivers-x86/for-next.

Thanks!


2024-05-08 00:40:12

by Chang S. Bae

[permalink] [raw]
Subject: [PATCH v2 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

Following feedback from the previous posting [1], this revision comes
with the changelog updates for more clarity:

* The recent change in the SDM alone does not fully explain the
underlying reasons. Provide a clearer explanation rather than simply
echoing the SDM text.

* While it is feasible for administrators to isolate CPUs running the
In-Field Scan tests from those running AMX workloads, this approach is
considerably disruptive and conflicts with the goal of its live
testing. Add this point to the changelog as well.

Thanks to Dave for highlighting these aspects [2]. Additionally, it is
worth noting that the IFS Technical Paper [3] was recently published,
which may offer further context on the IFS testing.

Thanks,
Chang

[1] V1: https://lore.kernel.org/lkml/[email protected]/
[2] Feedback: https://lore.kernel.org/lkml/[email protected]/
[3] IFS Paper: https://www.intel.com/content/www/us/en/content-details/822279/finding-faulty-components-in-a-live-fleet-environment.html

Chang S. Bae (2):
x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state
platform/x86/intel/ifs: Initialize AMX state for the scan test

arch/x86/include/asm/fpu/api.h | 1 +
arch/x86/kernel/fpu/core.c | 3 +++
drivers/platform/x86/intel/ifs/ifs.h | 15 +++++++++++++++
drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
4 files changed, 25 insertions(+)


base-commit: 7598293ab37c92025086de4b0ecd9474013a725f
--
2.34.1


2024-05-08 09:44:37

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] x86/fpu: Extend kernel_fpu_begin_mask() for the In-Field Scan driver

On Tue, 7 May 2024, Chang S. Bae wrote:

> Following feedback from the previous posting [1], this revision comes
> with the changelog updates for more clarity:
>
> * The recent change in the SDM alone does not fully explain the
> underlying reasons. Provide a clearer explanation rather than simply
> echoing the SDM text.
>
> * While it is feasible for administrators to isolate CPUs running the
> In-Field Scan tests from those running AMX workloads, this approach is
> considerably disruptive and conflicts with the goal of its live
> testing. Add this point to the changelog as well.
>
> Thanks to Dave for highlighting these aspects [2]. Additionally, it is
> worth noting that the IFS Technical Paper [3] was recently published,
> which may offer further context on the IFS testing.
>
> Thanks,
> Chang
>
> [1] V1: https://lore.kernel.org/lkml/[email protected]/
> [2] Feedback: https://lore.kernel.org/lkml/[email protected]/
> [3] IFS Paper: https://www.intel.com/content/www/us/en/content-details/822279/finding-faulty-components-in-a-live-fleet-environment.html
>
> Chang S. Bae (2):
> x86/fpu: Extend kernel_fpu_begin_mask() to initialize AMX state
> platform/x86/intel/ifs: Initialize AMX state for the scan test

For both patches:

Reviewed-by: Ilpo J?rvinen <[email protected]>


--
i.

Subject: Re: [PATCH 2/2] platform/x86/intel/ifs: Initialize AMX state for the scan test


On 4/30/24 2:25 PM, Chang S. Bae wrote:
> The scan test does not start when the AMX state remains active and is not
> re-initialized. With the extension of kernel_fpu_begin_mask(), the driver
> code can now initialize the state properly.
>
> Introduce custom FPU handling wrappers to ensure compliant with the
> established FPU API semantics, as kernel_fpu_begin() exclusively sets
> legacy states. This follows the EFI case from commit b0dc553cfc9d
> ("x86/fpu: Make the EFI FPU calling convention explicit").
>
> Then, use these wrappers to surround the MSR_ACTIVATE_SCAN write to
> minimize the critical section. To prevent unnecessary delays, invoke
> ifs_fpu_begin() before entering the rendezvous loop.
>
> Signed-off-by: Chang S. Bae <[email protected]>
> Reviewed-by: Jithu Joseph <[email protected]>
> Tested-by: Jithu Joseph <[email protected]>
> ---

Looks good to me.

Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]>
> drivers/platform/x86/intel/ifs/ifs.h | 14 ++++++++++++++
> drivers/platform/x86/intel/ifs/runtest.c | 6 ++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h
> index 56b9f3e3cf76..71d8b50854b2 100644
> --- a/drivers/platform/x86/intel/ifs/ifs.h
> +++ b/drivers/platform/x86/intel/ifs/ifs.h
> @@ -325,4 +325,18 @@ int do_core_test(int cpu, struct device *dev);
> extern struct attribute *plat_ifs_attrs[];
> extern struct attribute *plat_ifs_array_attrs[];
>
> +static inline void ifs_fpu_begin(void)
> +{
> + /*
> + * The AMX state must be initialized prior to executing In-Field
> + * Scan tests, according to Intel SDM.

Nit: May be helpful to include the section title in SDM.

> + */
> + kernel_fpu_begin_mask(KFPU_AMX);
> +}
> +
> +static inline void ifs_fpu_end(void)
> +{
> + kernel_fpu_end();
> +}
> +
> #endif
> diff --git a/drivers/platform/x86/intel/ifs/runtest.c b/drivers/platform/x86/intel/ifs/runtest.c
> index 95b4b71fab53..a35eac7c0b44 100644
> --- a/drivers/platform/x86/intel/ifs/runtest.c
> +++ b/drivers/platform/x86/intel/ifs/runtest.c
> @@ -188,6 +188,9 @@ static int doscan(void *data)
> /* Only the first logical CPU on a core reports result */
> first = cpumask_first(cpu_smt_mask(cpu));
>
> + /* Prepare FPU state before entering the rendezvous loop*/
> + ifs_fpu_begin();
> +
> wait_for_sibling_cpu(&scan_cpus_in, NSEC_PER_SEC);
>
> /*
> @@ -199,6 +202,9 @@ static int doscan(void *data)
> * are processed in a single pass) before it retires.
> */
> wrmsrl(MSR_ACTIVATE_SCAN, params->activate->data);
> +
> + ifs_fpu_end();
> +
> rdmsrl(MSR_SCAN_STATUS, status.data);
>
> trace_ifs_status(ifsd->cur_batch, start, stop, status.data);

--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer