Add <asm/neon.h> containing kernel_neon_begin/kernel_neon_end function declarations and corresponding definitions in fpsimd.c
These are needed to wrap uses of NEON in kernel mode. The names are identical to the ones used in arm/ so code using intrinsics or vectorized by GCC can be shared between arm and arm64.
Signed-off-by: Ard Biesheuvel ard.biesheuvel@linaro.org --- arch/arm64/Kconfig | 3 +++ arch/arm64/include/asm/neon.h | 14 ++++++++++++++ arch/arm64/kernel/fpsimd.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/neon.h
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 56b3f6d..46ba680 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -95,6 +95,9 @@ config SWIOTLB config IOMMU_HELPER def_bool SWIOTLB
+config KERNEL_MODE_NEON + def_bool y + source "init/Kconfig"
source "kernel/Kconfig.freezer" diff --git a/arch/arm64/include/asm/neon.h b/arch/arm64/include/asm/neon.h new file mode 100644 index 0000000..b0cc58a9 --- /dev/null +++ b/arch/arm64/include/asm/neon.h @@ -0,0 +1,14 @@ +/* + * linux/arch/arm64/include/asm/neon.h + * + * Copyright (C) 2013 Linaro Ltd ard.biesheuvel@linaro.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define cpu_has_neon() (1) + +void kernel_neon_begin(void); +void kernel_neon_end(void); diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index e8b8357..68d6caa 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -83,6 +83,33 @@ void fpsimd_flush_thread(void) fpsimd_load_state(¤t->thread.fpsimd_state); }
+#ifdef CONFIG_KERNEL_MODE_NEON + +/* + * Kernel-side NEON support functions + */ +void kernel_neon_begin(void) +{ + /* Avoid using the NEON in interrupt context */ + might_sleep(); + preempt_disable(); + + if (current->mm) + fpsimd_save_state(¤t->thread.fpsimd_state); +} +EXPORT_SYMBOL(kernel_neon_begin); + +void kernel_neon_end(void) +{ + if (current->mm) + fpsimd_load_state(¤t->thread.fpsimd_state); + + preempt_enable(); +} +EXPORT_SYMBOL(kernel_neon_end); + +#endif /* CONFIG_KERNEL_MODE_NEON */ + /* * FP/SIMD support code initialisation. */ @@ -103,4 +130,4 @@ static int __init fpsimd_init(void)
return 0; } -late_initcall(fpsimd_init); +core_initcall(fpsimd_init);
On Fri, Jun 07, 2013 at 03:50:55PM +0100, Ard Biesheuvel wrote:
+void kernel_neon_begin(void) +{
- /* Avoid using the NEON in interrupt context */
- might_sleep();
The patch looks fine but this might_sleep() does not feel right since we don't expect the subsequent code to sleep. Would something like BUG_ON(in_interrupt()) work?
On 7 June 2013 18:48, Catalin Marinas catalin.marinas@arm.com wrote:
On Fri, Jun 07, 2013 at 03:50:55PM +0100, Ard Biesheuvel wrote:
+void kernel_neon_begin(void) +{
/* Avoid using the NEON in interrupt context */
might_sleep();
The patch looks fine but this might_sleep() does not feel right since we don't expect the subsequent code to sleep. Would something like BUG_ON(in_interrupt()) work?
The underlying purpose (make noise when calling the function in interrupt context) is the same. However, might_sleep() is also a voluntary preemption point in case that option is enabled, and it drops the check for which context it is called from entirely if CONFIG_DEBUG_ATOMIC_SLEEP is not set.
I am fine either way.
I also realized changing late_initcall() to core_initcall() is not necessary here, so I will change that as well. I will follow up with an actual (updated) patch once things have moved some more on the arm/ side.
linaro-kernel@lists.linaro.org