arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD
authorArd Biesheuvel <ardb@kernel.org>
Fri, 8 Dec 2023 11:32:22 +0000 (12:32 +0100)
committerWill Deacon <will@kernel.org>
Tue, 12 Dec 2023 14:31:55 +0000 (14:31 +0000)
commit2632e25217696712681dd1f3ecc0d71624ea3b23
tree68c6f91648a915e55493358fbc1229d84566eff5
parentaefbab8e77eb16b56e18f24b85a09ebf4dc60e93
arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD

Now that kernel mode FPSIMD state is context switched along with other
task state, we can enable the existing logic that keeps track of which
task's FPSIMD state the CPU is holding in its registers. If it is the
context of the task that we are switching to, we can elide the reload of
the FPSIMD state from memory.

Note that we also need to check whether the FPSIMD state on this CPU is
the most recent: if a task gets migrated away and back again, the state
in memory may be more recent than the state in the CPU. So add another
CPU id field to task_struct to keep track of this. (We could reuse the
existing CPU id field used for user mode context, but that might result
in user state to be discarded unnecessarily, given that two distinct
CPUs could be holding the most recent user mode state and the most
recent kernel mode state)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Mark Brown <broonie@kernel.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20231208113218.3001940-9-ardb@google.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/processor.h
arch/arm64/kernel/fpsimd.c