[PATCH] arm64/fpsimd: Avoid erroneous elide of user state reload

Janne Grunau j at jannau.net
Wed May 22 03:13:46 PDT 2024


Hej,

On Wed, May 22, 2024, at 11:13, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb at kernel.org>
>
> TIF_FOREIGN_FPSTATE is a 'convenience' flag that should reflect whether
> the current CPU holds the most recent user mode FP/SIMD state of the
> current task. It combines two conditions:
> - whether the current CPU's FP/SIMD state belongs to the task;
> - whether that state is the most recent associated with the task (as a
>   task may have executed on other CPUs as well).
>
> When a task is scheduled in and TIF_KERNEL_FPSTATE is set, it means the
> task was in a kernel mode NEON section when it was scheduled out, and so
> the kernel mode FP/SIMD state is restored. Since this implies that the
> current CPU is *not* holding the most recent user mode FP/SIMD state of
> the current task, the TIF_FOREIGN_FPSTATE flag is set too, so that the
> user mode FP/SIMD state is reloaded from memory when returning to
> userland.
>
> However, the task may be scheduled out after completing the kernel mode
> NEON section, but before returning to userland. When this happens, the
> TIF_FOREIGN_FPSTATE flag will not be preserved, but will be set as usual
> the next time the task is scheduled in, and will be based on the above
> conditions.
>
> This means that, rather than setting TIF_FOREIGN_FPSTATE when scheduling
> in a task with TIF_KERNEL_FPSTATE set, the underlying state should be
> updated so that TIF_FOREIGN_FPSTATE will assume the expected value as a
> result.
>
> So instead, call fpsimd_flush_cpu_state(), which takes care of this.
>
> Closes: 
> https://lore.kernel.org/all/cb8822182231850108fa43e0446a4c7f@kernel.org
> Reported-by: Johannes Nixdorf <mixi at shadowice.org>
> Fixes: aefbab8e77eb ("arm64: fpsimd: Preserve/restore kernel mode NEON 
> at context switch")
> Cc: Mark Brown <broonie at kernel.org>
> Cc: Dave Martin <Dave.Martin at arm.com>
> Cc: Janne Grunau <j at jannau.net>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  arch/arm64/kernel/fpsimd.c | 44 +++++++++++++++++++-------------------
>  1 file changed, 22 insertions(+), 22 deletions(-)

All previous errors no longer reproduce with this patch applied on top of v6.8.
Over 20 repetitions of the fio reproducer without verification error, fp-stress
mismatches and AV1 decoding errors. I'll continue to run the reproducer but
I don't expect any failures. Previously at least one failure would occur for a
single fio run.

Please add Cc: stable at vger.kernel.org and feel free to add

Tested-by: Janne Grunau <j at jannau.net>

thanks

Janne



More information about the linux-arm-kernel mailing list