Re: [PATCH] arm64/fpsimd: Exit streaming mode when flushing tasks

From: Mark Rutland
Date: Thu Jun 08 2023 - 11:51:59 EST


On Wed, Jun 07, 2023 at 09:30:51PM +0100, Mark Brown wrote:
> Ensure there is no path where we might attempt to save SME state after we
> flush a task by updating the SVCR register state as well as updating our
> in memory state. I haven't seen a specific case where this is happening or
> seen a path where it might happen but for the cost of a single low overhead
> instruction it seems sensible to close the potential gap.
>
> Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
> ---
> arch/arm64/kernel/fpsimd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
> index 2fbafa5cc7ac..1627e0efe39a 100644
> --- a/arch/arm64/kernel/fpsimd.c
> +++ b/arch/arm64/kernel/fpsimd.c
> @@ -1649,6 +1649,7 @@ void fpsimd_flush_thread(void)
>
> fpsimd_flush_thread_vl(ARM64_VEC_SME);
> current->thread.svcr = 0;
> + sme_smstop_sm();

I don't think we should blindly do this if we never expect to get here in that
state; this is just going to mask bugs and make them harder to debug going
forwards.

If we need this, it'd be better to have something like:

if (WARN_ON_ONCE(sme_is_in_streaming_mode()))
sme_smstop_sm();

... so that we can identify this case and fix it.

Thanks,
Mark.