Skip to contentSkip to conversation

arm64: neon: Forbid when irqs are disabled

PATCH New Dave Martin 3 participants 3 messages Aug 9, 2017 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: neon: Forbid when irqs are disabled

Currently, may_use_simd() can return true if IRQs are disabled. If the caller goes ahead and calls kernel_neon_begin(), this can result in use of local_bh_enable() in an unsafe context.

In particular, __efi_fpsimd_begin() may do this when calling EFI as part of system shutdown.

This patch ensures that callers don't think they can use kernel_neon_begin() in such a context.

---
 arch/arm64/include/asm/simd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/simd.h +3 -1
index 5a1a927..fa8b3fe 100644
@@ -10,6 +10,7 @@
 #define __ASM_SIMD_H
 
 #include <linux/compiler.h>
+#include <linux/irqflags.h>
 #include <linux/percpu.h>
 #include <linux/preempt.h>
 #include <linux/types.h>
@@ -40,7 +41,8 @@ static __must_check inline bool may_use_simd(void)
 	 * can't migrate to another CPU and spuriously see it become
 	 * false.
 	 */
-	return !in_irq() && !in_nmi() && !raw_cpu_read(kernel_neon_busy);
+	return !in_irq() && !irqs_disabled() && !in_nmi() &&
+		!raw_cpu_read(kernel_neon_busy);
 }
 
 #else /* ! CONFIG_KERNEL_MODE_NEON */
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 arm64: neon: Forbid when irqs are disabled

Quoted 11 lines · Dave Martin

Currently, may_use_simd() can return true if IRQs are disabled. If the caller goes ahead and calls kernel_neon_begin(), this can result in use of local_bh_enable() in an unsafe context.

In particular, __efi_fpsimd_begin() may do this when calling EFI as part of system shutdown.

This patch ensures that callers don't think they can use kernel_neon_begin() in such a context.

Quoted 29 lines
---
 arch/arm64/include/asm/simd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/simd.h +3 -2
index 5a1a927..fa8b3fe 100644
@@ -10,6 +10,7 @@
 #define __ASM_SIMD_H
 
 #include <linux/compiler.h>
+#include <linux/irqflags.h>
 #include <linux/percpu.h>
 #include <linux/preempt.h>
 #include <linux/types.h>
@@ -40,7 +41,8 @@ static __must_check inline bool may_use_simd(void)
         * can't migrate to another CPU and spuriously see it become
         * false.
         */
-       return !in_irq() && !in_nmi() && !raw_cpu_read(kernel_neon_busy);
+       return !in_irq() && !irqs_disabled() && !in_nmi() &&
+               !raw_cpu_read(kernel_neon_busy);
 }
 
 #else /* ! CONFIG_KERNEL_MODE_NEON */
--

2.1.4

maintainer
#2 lore raw

PATCH 1/1 arm64: neon: Forbid when irqs are disabled

In reply to Dave Martin
Quoted 11 lines · Dave P Martin

Currently, may_use_simd() can return true if IRQs are disabled. If the caller goes ahead and calls kernel_neon_begin(), this can result in use of local_bh_enable() in an unsafe context.

In particular, __efi_fpsimd_begin() may do this when calling EFI as part of system shutdown.

This patch ensures that callers don't think they can use kernel_neon_begin() in such a context.

Thanks. I pushed it out to the for-next/kernel-mode-neon branch.

Signature · 1 line
Catalin