Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <martin@strongswan.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

authored by

Ard Biesheuvel and committed by
Russell King (Oracle)
c79f8163 62b95a7b

+14 -7
+8
arch/arm/include/asm/simd.h
··· 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 + }
+6 -7
arch/arm/vfp/vfpmodule.c
··· 723 723 local_bh_disable(); 724 724 725 725 /* 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. 729 729 */ 730 - BUG_ON(in_interrupt()); 731 - cpu = get_cpu(); 730 + BUG_ON(in_hardirq()); 731 + cpu = __smp_processor_id(); 732 732 733 733 fpexc = fmrx(FPEXC) | FPEXC_EN; 734 734 fmxr(FPEXC, fpexc); ··· 744 744 vfp_save_state(vfp_current_hw_state[cpu], fpexc); 745 745 #endif 746 746 vfp_current_hw_state[cpu] = NULL; 747 - local_bh_enable(); 748 747 } 749 748 EXPORT_SYMBOL(kernel_neon_begin); 750 749 ··· 751 752 { 752 753 /* Disable the NEON/VFP unit. */ 753 754 fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); 754 - put_cpu(); 755 + local_bh_enable(); 755 756 } 756 757 EXPORT_SYMBOL(kernel_neon_end); 757 758