From: Ard Biesheuvel <ardb@kernel.org>
In preparation for making kernel_neon_begin() allocate a stack based
buffer for stashing the kernel mode FP/SIMD state on a context switch,
redefine kernel_neon_begin() and kernel_neon_end() as macros, in a way
that requires them to be called from the same scope, and therefore,
running from the same stack frame.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/include/asm/neon.h | 7 +++++--
arch/arm64/kernel/fpsimd.c | 12 ++++++------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/include/asm/neon.h b/arch/arm64/include/asm/neon.h
index d4b1d172a79b..4e24f1058b55 100644
--- a/arch/arm64/include/asm/neon.h
+++ b/arch/arm64/include/asm/neon.h
@@ -13,7 +13,10 @@
#define cpu_has_neon() system_supports_fpsimd()
-void kernel_neon_begin(void);
-void kernel_neon_end(void);
+void __kernel_neon_begin(void);
+void __kernel_neon_end(void);
+
+#define kernel_neon_begin() do { __kernel_neon_begin()
+#define kernel_neon_end() __kernel_neon_end(); } while (0)
#endif /* ! __ASM_NEON_H */
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index c37f02d7194e..d7eb073d1366 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -1833,7 +1833,7 @@ void fpsimd_save_and_flush_cpu_state(void)
* The caller may freely use the FPSIMD registers until kernel_neon_end() is
* called.
*/
-void kernel_neon_begin(void)
+void __kernel_neon_begin(void)
{
if (WARN_ON(!system_supports_fpsimd()))
return;
@@ -1875,7 +1875,7 @@ void kernel_neon_begin(void)
put_cpu_fpsimd_context();
}
-EXPORT_SYMBOL_GPL(kernel_neon_begin);
+EXPORT_SYMBOL_GPL(__kernel_neon_begin);
/*
* kernel_neon_end(): give the CPU FPSIMD registers back to the current task
@@ -1886,7 +1886,7 @@ EXPORT_SYMBOL_GPL(kernel_neon_begin);
* The caller must not use the FPSIMD registers after this function is called,
* unless kernel_neon_begin() is called again in the meantime.
*/
-void kernel_neon_end(void)
+void __kernel_neon_end(void)
{
if (!system_supports_fpsimd())
return;
@@ -1902,7 +1902,7 @@ void kernel_neon_end(void)
else
clear_thread_flag(TIF_KERNEL_FPSTATE);
}
-EXPORT_SYMBOL_GPL(kernel_neon_end);
+EXPORT_SYMBOL_GPL(__kernel_neon_end);
#ifdef CONFIG_EFI
@@ -1936,7 +1936,7 @@ void __efi_fpsimd_begin(void)
WARN_ON(preemptible());
if (may_use_simd()) {
- kernel_neon_begin();
+ __kernel_neon_begin();
} else {
/*
* If !efi_sve_state, SVE can't be in use yet and doesn't need
@@ -1985,7 +1985,7 @@ void __efi_fpsimd_end(void)
return;
if (!efi_fpsimd_state_used) {
- kernel_neon_end();
+ __kernel_neon_end();
} else {
if (system_supports_sve() && efi_sve_state_used) {
bool ffr = true;
--
2.51.0.384.g4c02a37b29-goog
Hi Ard, kernel test robot noticed the following build errors: [auto build test ERROR on f83ec76bf285bea5727f478a68b894f5543ca76e] url: https://github.com/intel-lab-lkp/linux/commits/Ard-Biesheuvel/crypto-arm64-aes-ce-ccm-Avoid-pointless-yield-of-the-NEON-unit/20250918-143859 base: f83ec76bf285bea5727f478a68b894f5543ca76e patch link: https://lore.kernel.org/r/20250918063539.2640512-11-ardb%2Bgit%40google.com patch subject: [PATCH 4/5] arm64/fpsimd: Require kernel NEON begin/end calls from the same scope config: arm64-randconfig-r132-20250920 (https://download.01.org/0day-ci/archive/20250922/202509220514.RnYqxP9V-lkp@intel.com/config) compiler: aarch64-linux-gcc (GCC) 13.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250922/202509220514.RnYqxP9V-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202509220514.RnYqxP9V-lkp@intel.com/ All error/warnings (new ones prefixed by >>): In file included from drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c:27: drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c: In function 'dc_fpu_begin': >> drivers/gpu/drm/amd/amdgpu/../display/dc/dc_trace.h:42:9: error: expected 'while' before 'trace_dcn_fpu' 42 | trace_dcn_fpu(begin, function, line, ref_count) | ^~~~~~~~~~~~~ drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c:86:9: note: in expansion of macro 'TRACE_DCN_FPU' 86 | TRACE_DCN_FPU(true, function_name, line, depth); | ^~~~~~~~~~~~~ >> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c:106:11: error: 'else' without a previous 'if' 106 | } else { | ^~~~ drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c: At top level: >> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/dc_fpu.c:99:6: warning: 'dc_fpu_end' defined but not used [-Wunused-function] 99 | void dc_fpu_end(const char *function_name, const int line) | ^~~~~~~~~~ vim +42 drivers/gpu/drm/amd/amdgpu/../display/dc/dc_trace.h 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 25 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 26 #define TRACE_DC_PIPE_STATE(pipe_ctx, index, max_pipes) \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 27 for (index = 0; index < max_pipes; ++index) { \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 28 struct pipe_ctx *pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[index]; \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 29 if (pipe_ctx->plane_state) \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 30 trace_amdgpu_dm_dc_pipe_state(pipe_ctx->pipe_idx, pipe_ctx->plane_state, \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 31 pipe_ctx->stream, &pipe_ctx->plane_res, \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 32 pipe_ctx->update_flags.raw); \ 8b198f6e94d669 Rodrigo Siqueira 2020-09-09 33 } 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 34 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 35 #define TRACE_DCE_CLOCK_STATE(dce_clocks) \ 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 36 trace_amdgpu_dm_dce_clocks_state(dce_clocks) 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 37 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 38 #define TRACE_DCN_CLOCK_STATE(dcn_clocks) \ 13b5ca42ca9c96 Rodrigo Siqueira 2020-09-10 39 trace_amdgpu_dm_dc_clocks_state(dcn_clocks) 96ee63730fa306 Rodrigo Siqueira 2021-07-26 40 2d8471dc371f36 Rodrigo Siqueira 2021-07-26 41 #define TRACE_DCN_FPU(begin, function, line, ref_count) \ 2d8471dc371f36 Rodrigo Siqueira 2021-07-26 @42 trace_dcn_fpu(begin, function, line, ref_count) -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.