Skip to content

arm64: Run kernel mode NEON with preemption enabled

Ard Biesheuvel linux-arm-kernel linux-crypto linux-renesas-soc 4 versions – Applied

Status from this message: I applied the first three patches to for-next/fpsimd:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 9 repliesApplied
  2. v35 patches 4 repliesSuperseded
  3. v24 patches 6 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches6 repliesSuperseded

Changes in v4 from the cover letter

- for the time being, make the existing yield logic depend on CONFIG_PREEMPT_VOLUNTARY, so it can be retired once the prerequisite core preempt changes (which remove CONFIG_PREEMPT_VOLUNTARY) have been merged [0]
- incorporate feedback from Mark Rutland and include his acks

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/4arm64: fpsimd: Drop unneeded 'busy' flagarch/arm64/include/asm/simd.h arch/arm64/kernel/fpsimd.c+13 -515 replies
2/4arm64: fpsimd: Preserve/restore kernel mode NEON at context switcharch/arm64/include/asm/processor.h arch/arm64/include/asm/thread_info.h arch/arm64/kernel/fpsimd.c+77 -180 replies
3/4arm64: fpsimd: Implement lazy restore for kernel mode FPSIMDarch/arm64/include/asm/processor.h arch/arm64/kernel/fpsimd.c+19 -00 replies
4/4arm64: crypto: Disable yielding logic unless CONFIG_PREEMPT_VOLUNTARY=yarch/arm64/crypto/aes-ce-ccm-glue.c arch/arm64/crypto/chacha-neon-glue.c arch/arm64/crypto/crct10dif-ce-glue.c +4 more+31 -110 replies

Reviews trailers per patch

3 of 4 patches have a Reviewed-by or Acked-by.

PatchMark BrownMark RutlandGeert Uytterhoeven
1/4R-b T-b
2/4R-b R-b
3/4R-b A-b
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/4] arm64: Run kernel mode NEON with preemption enabled

From: Ard Biesheuvel <[email protected]>

Currently, kernel mode NEON (SIMD) support is implemented in a way that requires preemption to be disabled while the SIMD registers are live. The reason for this is that those registers are not in the set that is preserved/restored on exception entry/exit and context switch, as this would impact performance generally, even for workloads where kernel mode SIMD is not the bottleneck.

However, doing substantial work with preemption disabled is not great, as it affects scheduling latency, which is especially problematic for real-time use cases. So ideally, we should keep preemption enabled when we can, and find another way to ensure that this does not corrupt the NEON register state of in-kernel SIMD users.

This series implements a suggestion by Mark Rutland, and introduces a thread_info flag TIF_KERNEL_FPSTATE, which indicates to the thread switch machinery that the task in question has live kernel mode SIMD state which needs to be preserved and restored. The space needed for this is allocated in thread_struct. (*)

Given that currently, we run kernel mode NEON with softirqs disabled (to avoid the need for preserving kernel mode NEON context belonging to task context while the SIMD unit is being used by code running in softirq context), just removing the preempt_disable/enable calls is not sufficient, and we also need to leave softirqs enabled. This means that we may need to preserve kernel mode NEON state not only on a context switch, but also when code running in softirq context takes ownership of the SIMD unit, but this is straight-forward once we add the scratch space to thread_struct. (On PREEMPT_RT, softirqs execute with preemption enabled, making kernel mode FPSIMD in softirq context preemptible as well. We rely on the fact that the task that hosts the softirq dispatch logic does not itself use kernel mode FPSIMD in task context to ensure that there is only a single kernel mode FPSIMD state that may need to be preserved and restored.)

(*) We might decide to allocate this space (~512 bytes) dynamically, if the thread_struct memory footprint causes issues. However, we should also explore doing the same for the user space FPSIMD state, as kernel threads never return to user space and have no need for this allocation.

v4:
- for the time being, make the existing yield logic depend on CONFIG_PREEMPT_VOLUNTARY, so it can be retired once the prerequisite core preempt changes (which remove CONFIG_PREEMPT_VOLUNTARY) have been merged [0]
- incorporate feedback from Mark Rutland and include his acks

v3:
- add patch to drop yield logic from crypto C glue code
- add R-b from Mark

v2:
- tweak some commit logs for clarity
- integrate with the existing lazy restore logic
- add Mark's R-b to patch #1

[0] https://lore.kernel.org/lkml/[email protected]/

Cc Marc Zyngier <[email protected]>
Cc Will Deacon <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Kees Cook <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Mark Brown <[email protected]>
Cc Eric Biggers <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>

Ard Biesheuvel (4):
arm64: fpsimd: Drop unneeded 'busy' flag
arm64: fpsimd: Preserve/restore kernel mode NEON at context switch
arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD
arm64: crypto: Disable yielding logic unless
CONFIG_PREEMPT_VOLUNTARY=y

 arch/arm64/crypto/aes-ce-ccm-glue.c      |   8 +-
 arch/arm64/crypto/chacha-neon-glue.c     |   5 +-
 arch/arm64/crypto/crct10dif-ce-glue.c    |   6 +-
 arch/arm64/crypto/nhpoly1305-neon-glue.c |   5 +-
 arch/arm64/crypto/poly1305-glue.c        |   5 +-
 arch/arm64/crypto/polyval-ce-glue.c      |   9 +-
 arch/arm64/include/asm/assembler.h       |   4 +-
 arch/arm64/include/asm/processor.h       |   3 +
 arch/arm64/include/asm/simd.h            |  11 +-
 arch/arm64/include/asm/thread_info.h     |   1 +
 arch/arm64/kernel/fpsimd.c               | 163 +++++++++++++-------
 11 files changed, 140 insertions(+), 80 deletions(-)
Signature · 1 line
2.43.0.472.g3155946c3a-goog