Skip to content

Commit c79f816

Browse files
ardbiesheuvelRussell King (Oracle)
authored andcommitted
ARM: 9283/1: permit non-nested kernel mode NEON in softirq context
We currently only permit kernel mode NEON in process context, to avoid the need to preserve/restore the NEON register file when taking an exception while running in the kernel. Like we did on arm64, we can relax this restriction substantially, by permitting kernel mode NEON from softirq context, while ensuring that softirq processing is disabled when the NEON is being used in task context. This guarantees that only NEON context belonging to user space needs to be preserved and restored, which is already taken care of. This is especially relevant for network encryption, where incoming frames are typically handled in softirq context, and deferring software decryption to a kernel thread or falling back to C code are both undesirable from a performance PoV. Tested-by: Martin Willi <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 62b95a7 commit c79f816

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

arch/arm/include/asm/simd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#include <linux/hardirq.h>
4+
5+
static __must_check inline bool may_use_simd(void)
6+
{
7+
return IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && !in_hardirq();
8+
}

arch/arm/vfp/vfpmodule.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,12 @@ void kernel_neon_begin(void)
723723
local_bh_disable();
724724

725725
/*
726-
* Kernel mode NEON is only allowed outside of interrupt context
727-
* with preemption disabled. This will make sure that the kernel
728-
* mode NEON register contents never need to be preserved.
726+
* Kernel mode NEON is only allowed outside of hardirq context with
727+
* preemption and softirq processing disabled. This will make sure that
728+
* the kernel mode NEON register contents never need to be preserved.
729729
*/
730-
BUG_ON(in_interrupt());
731-
cpu = get_cpu();
730+
BUG_ON(in_hardirq());
731+
cpu = __smp_processor_id();
732732

733733
fpexc = fmrx(FPEXC) | FPEXC_EN;
734734
fmxr(FPEXC, fpexc);
@@ -744,15 +744,14 @@ void kernel_neon_begin(void)
744744
vfp_save_state(vfp_current_hw_state[cpu], fpexc);
745745
#endif
746746
vfp_current_hw_state[cpu] = NULL;
747-
local_bh_enable();
748747
}
749748
EXPORT_SYMBOL(kernel_neon_begin);
750749

751750
void kernel_neon_end(void)
752751
{
753752
/* Disable the NEON/VFP unit. */
754753
fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
755-
put_cpu();
754+
local_bh_enable();
756755
}
757756
EXPORT_SYMBOL(kernel_neon_end);
758757

0 commit comments

Comments
 (0)