Skip to contentSkip to conversation

fpsimd fixes and cleanups

PATCH In review Jan Kiszka 3 participants 23 messages Sep 19, 2025 – Nov 18, 2025 arm64

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover fpsimd fixes and cleanups

See patches.

Jan

Jan Kiszka (3):
arm64: fpsimd: dovetail: Hard-disable interrupts inside
fpsimd_save_and_flush_cpu_state
arm64: fpsimd: dovetail: drop redundant hard irqs disabling
arm64: fpsimd: dovetail: Drop extra condition from WARN_ON

 arch/arm64/kernel/fpsimd.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 1/3 arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +2 -2
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON
Signature · 1 line
2.51.0
author
#2 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 16 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +0 -0
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;

arch/arm64/kernel/fpsimd.c void fpsimd_save_and_flush_cpu_state(void) · line 1960

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +2 -2
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON

This one is actually vanishing when rebasing over v6.1.151-cip46 which has
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8f4dc4e54eed4bebb18390305eb1f721c00457e1.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#3 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 26 lines · Jan Kiszka
Quoted 25 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +2 -2
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
Quoted 6 lines

arch/arm64/kernel/fpsimd.c void fpsimd_save_and_flush_cpu_state(void) · line 1960

Quoted 1 line
arch/arm64/kernel/fpsimd.c +0 -0
 #ifdef CONFIG_KERNEL_MODE_NEON

This one is actually vanishing when rebasing over v6.1.151-cip46 which has
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8f4dc4e54eed4bebb18390305eb1f721c00457e1.

...provided some "flags" argument is provided to get/put_cpu_fpsimd_context which I didn't do above, and which should be done while resolving the merge conflict with v6.1.151-cip46.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#4 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

In reply to Jan Kiszka
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Quoted 22 lines
---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +2 -2
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON
Signature · 1 line
Philippe.
author
#5 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 11 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

Jan

Quoted 24 lines
Quoted 23 lines
---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +2 -2
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON
Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#6 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

Quoted 32 lines

Jan

Quoted 24 lines
Quoted 23 lines
---
 arch/arm64/kernel/fpsimd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +2 -2
index 83b8492984982..ba804fcdfdb3f 100644
@@ -1951,10 +1951,10 @@ void fpsimd_save_and_flush_cpu_state(void)
 	if (!system_supports_fpsimd())
 		return;
 	WARN_ON(!hard_irqs_disabled() && preemptible());
-	__get_cpu_fpsimd_context();
+	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
-	__put_cpu_fpsimd_context();
+	put_cpu_fpsimd_context();
 }
 
 #ifdef CONFIG_KERNEL_MODE_NEON
Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#7 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 18 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

Quoted 7 lines

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

All of them.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#8 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

Quoted 7 lines
Quoted 4 lines

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

All of them.

In case backporting is considered:

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

into account. Just a "couple of weeks" old and brings some optimizations.

Quoted 4 lines
Signature · 3 lines
-- 
Siemens AG, Foundational Technologies
Linux Expert Center
author
#9 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 28 lines · Florian Bezdeka
Quoted 27 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

Quoted 9 lines
Quoted 2 lines

All of them.

In case backporting is considered:

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

No signed-off - still testing?

Quoted 3 lines

into account. Just a "couple of weeks" old and brings some optimizations.

That goes to Philippe then.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#10 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 32 lines · Jan Kiszka
Quoted 31 lines · Florian Bezdeka
Quoted 29 lines · Jan Kiszka
Quoted 18 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

Quoted 7 lines

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

All of them.

Quoted 8 lines
Quoted 6 lines

In case backporting is considered:

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

No signed-off - still testing?

No, just realized that as well. Must be a glitch somewhere in my workflow. No idea how that happened. All other patches in the same series were fine...

Quoted 6 lines
Quoted 4 lines

into account. Just a "couple of weeks" old and brings some optimizations.

That goes to Philippe then.

Would be nice to know upfront if that would fix the actual problem...

Quoted 6 lines

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#11 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 47 lines · Florian Bezdeka
Quoted 32 lines · Jan Kiszka
Quoted 31 lines · Florian Bezdeka
Quoted 29 lines · Jan Kiszka
Quoted 18 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

Quoted 7 lines

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

All of them.

Quoted 8 lines
Quoted 6 lines

In case backporting is considered:

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

No signed-off - still testing?

No, just realized that as well. Must be a glitch somewhere in my workflow. No idea how that happened. All other patches in the same series were fine...

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

into account. Just a "couple of weeks" old and brings some optimizations.

That goes to Philippe then.

Would be nice to know upfront if that would fix the actual problem...

Which problem exactly now? I'm currently juggling so many...

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#12 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

In reply to Florian Bezdeka
Quoted 28 lines · Florian Bezdeka
Quoted 27 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

Quoted 5 lines
Quoted 2 lines

All of them.

In case backporting is considered:

We already have 028ad3b2 in [rebase/]6.1.y-cip, I'll pick 97cb63af01de as well.

Quoted 8 lines

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

into account. Just a "couple of weeks" old and brings some optimizations.

We also need to enable the oob preemption test in switchtest, which was disabled so far due to lack of support. Now that 028ad3b2 enables safe preemption of kernel_neon_begin/end sections by oob thread, we should allow testing this feature in v3 as well with something along these lines:

kernel/cobalt/arch/arm64/include/asm/xenomai/fptest.h +5 -1
index 0958d5e2a..b8c0c39c5 100644
@@ -10,16 +10,20 @@
 #include <linux/errno.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <asm/hwcap.h>
+#include <asm/neon.h>
 
 #define have_fp (ELF_HWCAP & HWCAP_FP)
 
 static inline int fp_linux_begin(void)
 {
-	return -ENOSYS;
+	kernel_neon_begin();
+
+	return 0;
 }
 
 static inline void fp_linux_end(void)
 {
+	kernel_neon_end();
 }
 
 static inline int fp_detect(void)

This was just done in v4 by [1], no issue detected afterwards by the 'hectic' test (switchtest equivalent).

[1] https://gitlab.com/Xenomai/xenomai4/linux-evl/-/commit/0396a52a9b3dc352ef10e6a9d2ed096718ef5d80

Signature · 1 line
Philippe.
#13 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 81 lines · Philippe Gerum
Quoted 28 lines · Florian Bezdeka
Quoted 27 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

Quoted 5 lines
Quoted 2 lines

All of them.

In case backporting is considered:

We already have 028ad3b2 in [rebase/]6.1.y-cip, I'll pick 97cb63af01de as well.

Quoted 8 lines

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

into account. Just a "couple of weeks" old and brings some optimizations.

We also need to enable the oob preemption test in switchtest, which was disabled so far due to lack of support. Now that 028ad3b2 enables safe preemption of kernel_neon_begin/end sections by oob thread, we should allow testing this feature in v3 as well with something along these lines:

kernel/cobalt/arch/arm64/include/asm/xenomai/fptest.h +5 -1
index 0958d5e2a..b8c0c39c5 100644
@@ -10,16 +10,20 @@
 #include <linux/errno.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <asm/hwcap.h>
+#include <asm/neon.h>
 
 #define have_fp (ELF_HWCAP & HWCAP_FP)
 
 static inline int fp_linux_begin(void)
 {
-	return -ENOSYS;
+	kernel_neon_begin();
+
+	return 0;
 }
 
 static inline void fp_linux_end(void)
 {
+	kernel_neon_end();
 }
 
 static inline int fp_detect(void)
Quoted 4 lines

This was just done in v4 by [1], no issue detected afterwards by the 'hectic' test (switchtest equivalent).

[1] https://gitlab.com/Xenomai/xenomai4/linux-evl/-/commit/0396a52a9b3dc352ef10e6a9d2ed096718ef5d80

Thanks for the reminder...

I'm quite sure I had sent that to the list. Might have got forgotten or it's hiding successfully in my xenomai queue. I will check and take care of the test enablement.

#14 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 85 lines · Florian Bezdeka
Quoted 84 lines · Philippe Gerum
Quoted 28 lines · Florian Bezdeka
Quoted 27 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Not all callers of this function do that themselves.

Quoted 8 lines
Quoted 4 lines

Are we 100% sure that kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp() would not benefit from doing that themselves precisely, to create an atomic section around their internal state change _and_ the fpsimd flush op?

Is kvm on arm64 officially enabled for oob (-preemption), or are we patching blindly here? If no one was looking at kvm yet, then you might be right. If it was reviewed already, then this here is just cleaning up.

We have
https://gitlab.com/Xenomai/linux-dovetail/-/commit/028ad3b2c19ca8a3655577fb34cac7996f166d2a

since 6.14 (AFAICT). At the time of writing this was the first kernel release that used in-kernel FPU. Maybe that changed (thanks to backports)? Btw: Which version are we talking about right now? 6.1? 6.12?

Quoted 5 lines
Quoted 2 lines

All of them.

In case backporting is considered:

We already have 028ad3b2 in [rebase/]6.1.y-cip, I'll pick 97cb63af01de as well.

Quoted 8 lines

Please also take

97cb63af01de ("arm64: fpsimd: dovetail: Align with x86 implementation")

into account. Just a "couple of weeks" old and brings some optimizations.

We also need to enable the oob preemption test in switchtest, which was disabled so far due to lack of support. Now that 028ad3b2 enables safe preemption of kernel_neon_begin/end sections by oob thread, we should allow testing this feature in v3 as well with something along these lines:

kernel/cobalt/arch/arm64/include/asm/xenomai/fptest.h +5 -1
index 0958d5e2a..b8c0c39c5 100644
@@ -10,16 +10,20 @@
 #include <linux/errno.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <asm/hwcap.h>
+#include <asm/neon.h>
 
 #define have_fp (ELF_HWCAP & HWCAP_FP)
 
 static inline int fp_linux_begin(void)
 {
-	return -ENOSYS;
+	kernel_neon_begin();
+
+	return 0;
 }
 
 static inline void fp_linux_end(void)
 {
+	kernel_neon_end();
 }
 
 static inline int fp_detect(void)

This was just done in v4 by [1], no issue detected afterwards by the 'hectic' test (switchtest equivalent).

Quoted 7 lines
Quoted 1 line

[1] https://gitlab.com/Xenomai/xenomai4/linux-evl/-/commit/0396a52a9b3dc352ef10e6a9d2ed096718ef5d80

Thanks for the reminder...

I'm quite sure I had sent that to the list. Might have got forgotten or it's hiding successfully in my xenomai queue. I will check and take care of the test enablement.

I did some tests with that in-kernel FPU usage enabled. My tests were based on xenomai/next with Kernels down to 5.10.

Results:
- 5.10: Missing backport
- 5.15: Missing backport
- 6.1 : Has the backport but that looks slightly different compared to 6.12. At least the following is needed to get the kernel into a "stable" state, but still no test success:

arch/arm64/kernel/fpsimd.c +1 -0
index 7ee823a6a5e45..be3d37554de0f 100644
@@ -2216,6 +2216,7 @@ void fpsimd_suspend_inband(void)
 	 */
 	if (__this_cpu_read(fpsimd_context_busy)) {
 		fpsimd_save_state(kfpu);
+		__put_cpu_fpsimd_context();
 		set_thread_flag(TIF_KERNEL_FP_PREEMPTED);
 	}
 }
@@ -2224,8 +2225,11 @@ void fpsimd_resume_inband(void)
 {
 	struct user_fpsimd_state *kfpu =

this_cpu_ptr(&in_kernel_fpstate);

- if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED))
+ if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED)) {
fpsimd_load_state(kfpu);
+ __get_cpu_fpsimd_context();
+ }
+
}

#endif

- 6.12 and newer: OK

Btw: I'm on vacation for ~2 weeks now. So please don't expect any progress on that topic ;-)

Florian

#15 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 77 lines · Florian
Quoted 32 lines
Quoted 32 lines

lines:

kernel/cobalt/arch/arm64/include/asm/xenomai/fptest.h +5 -1
index 0958d5e2a..b8c0c39c5 100644
@@ -10,16 +10,20 @@
 #include <linux/errno.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <asm/hwcap.h>
+#include <asm/neon.h>
 
 #define have_fp (ELF_HWCAP & HWCAP_FP)
 
 static inline int fp_linux_begin(void)
 {
-	return -ENOSYS;
+	kernel_neon_begin();
+
+	return 0;
 }
 
 static inline void fp_linux_end(void)
 {
+	kernel_neon_end();
 }
 
 static inline int fp_detect(void)

This was just done in v4 by [1], no issue detected afterwards by the 'hectic' test (switchtest equivalent).

Quoted 7 lines
Quoted 1 line

[1] https://gitlab.com/Xenomai/xenomai4/linux-evl/-/commit/0396a52a9b3dc352ef10e6a9d2ed096718ef5d80

Thanks for the reminder...

I'm quite sure I had sent that to the list. Might have got forgotten or it's hiding successfully in my xenomai queue. I will check and take care of the test enablement.

I did some tests with that in-kernel FPU usage enabled. My tests were based on xenomai/next with Kernels down to 5.10.

Results:
- 5.10: Missing backport
- 5.15: Missing backport
- 6.1 : Has the backport but that looks slightly different compared to 6.12. At least the following is needed to get the kernel into a "stable" state, but still no test success:

arch/arm64/kernel/fpsimd.c +5 -1
index 7ee823a6a5e45..be3d37554de0f 100644
@@ -2216,6 +2216,7 @@ void fpsimd_suspend_inband(void)
 	 */
 	if (__this_cpu_read(fpsimd_context_busy)) {
 		fpsimd_save_state(kfpu);
+		__put_cpu_fpsimd_context();
 		set_thread_flag(TIF_KERNEL_FP_PREEMPTED);
 	}
 }
@@ -2224,8 +2225,11 @@ void fpsimd_resume_inband(void)
 {
 	struct user_fpsimd_state *kfpu =
 this_cpu_ptr(&in_kernel_fpstate);
 
-	if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED))
+	if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED)) {
 		fpsimd_load_state(kfpu);
+		__get_cpu_fpsimd_context();
+	}
+
 }
 

#endif

Quoted 6 lines

- 6.12 and newer: OK

Btw: I'm on vacation for ~2 weeks now. So please don't expect any progress on that topic ;-)

I finally found some time to debug that issue again. To recap: As soon as I enable the in-kernel oob FPU usage (see patch at the beginning of this mail) the xenomai3 switchtest utility will fail when running ontop of Dovetail < 6.12.

The winner is

aefbab8e77eb ("arm64: fpsimd: Preserve/restore kernel mode NEON at context switch")

which is part of 6.8 and newer. That explains why Dovetail versions below 6.12 show this problem. It allows to preempt in-kernel FPU usage sections by implementing the necessary context save/restore.

My summary for now is that the hard_preempt_disable() in kernel_neon_begin() - as part of get_cpu_fpsimd_context() - does not work as it should. Seems we need a fix for Dovetail < 6.12.

Could someone please have a look and share some thoughts? Confirming my assumption / theory would be a nice starting point for me.

Possible workaround: I could implement a version specific test enablement, but I'm not sure if that is papering over a real problem. The FPU usage in such a context looks valid to me.

Best regards,
Florian

author
#16 lore raw

Re: [dovetail 6.1.y-cip][PATCH 1/3] arm64: fpsimd: dovetail: Hard-disable interrupts inside fpsimd_save_and_flush_cpu_state

Quoted 94 lines · Florian Bezdeka
Quoted 77 lines · Florian
Quoted 32 lines
Quoted 32 lines

lines:

kernel/cobalt/arch/arm64/include/asm/xenomai/fptest.h +5 -1
index 0958d5e2a..b8c0c39c5 100644
@@ -10,16 +10,20 @@
 #include <linux/errno.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <asm/hwcap.h>
+#include <asm/neon.h>
 
 #define have_fp (ELF_HWCAP & HWCAP_FP)
 
 static inline int fp_linux_begin(void)
 {
-	return -ENOSYS;
+	kernel_neon_begin();
+
+	return 0;
 }
 
 static inline void fp_linux_end(void)
 {
+	kernel_neon_end();
 }
 
 static inline int fp_detect(void)

This was just done in v4 by [1], no issue detected afterwards by the 'hectic' test (switchtest equivalent).

Quoted 7 lines
Quoted 1 line

[1] https://gitlab.com/Xenomai/xenomai4/linux-evl/-/commit/0396a52a9b3dc352ef10e6a9d2ed096718ef5d80

Thanks for the reminder...

I'm quite sure I had sent that to the list. Might have got forgotten or it's hiding successfully in my xenomai queue. I will check and take care of the test enablement.

I did some tests with that in-kernel FPU usage enabled. My tests were based on xenomai/next with Kernels down to 5.10.

Results:
- 5.10: Missing backport
- 5.15: Missing backport
- 6.1 : Has the backport but that looks slightly different compared to 6.12. At least the following is needed to get the kernel into a "stable" state, but still no test success:

arch/arm64/kernel/fpsimd.c +5 -1
index 7ee823a6a5e45..be3d37554de0f 100644
@@ -2216,6 +2216,7 @@ void fpsimd_suspend_inband(void)
 	 */
 	if (__this_cpu_read(fpsimd_context_busy)) {
 		fpsimd_save_state(kfpu);
+		__put_cpu_fpsimd_context();
 		set_thread_flag(TIF_KERNEL_FP_PREEMPTED);
 	}
 }
@@ -2224,8 +2225,11 @@ void fpsimd_resume_inband(void)
 {
 	struct user_fpsimd_state *kfpu =
 this_cpu_ptr(&in_kernel_fpstate);
 
-	if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED))
+	if (test_and_clear_thread_flag(TIF_KERNEL_FP_PREEMPTED)) {
 		fpsimd_load_state(kfpu);
+		__get_cpu_fpsimd_context();
+	}
+
 }
 

#endif

Quoted 6 lines

- 6.12 and newer: OK

Btw: I'm on vacation for ~2 weeks now. So please don't expect any progress on that topic ;-)

I finally found some time to debug that issue again. To recap: As soon as I enable the in-kernel oob FPU usage (see patch at the beginning of this mail) the xenomai3 switchtest utility will fail when running ontop of Dovetail < 6.12.

The winner is

aefbab8e77eb ("arm64: fpsimd: Preserve/restore kernel mode NEON at context switch")

Quoted 7 lines

which is part of 6.8 and newer. That explains why Dovetail versions below 6.12 show this problem. It allows to preempt in-kernel FPU usage sections by implementing the necessary context save/restore.

My summary for now is that the hard_preempt_disable() in kernel_neon_begin() - as part of get_cpu_fpsimd_context() - does not work as it should. Seems we need a fix for Dovetail < 6.12.

It is not hard_preempt as there is a hard_cond_local_irq_restore at its end, and that lifts all the preempt disabling we have in oob from dovetail perspective: irqs off.

Quoted 8 lines

Could someone please have a look and share some thoughts? Confirming my assumption / theory would be a nice starting point for me.

Possible workaround: I could implement a version specific test enablement, but I'm not sure if that is papering over a real problem. The FPU usage in such a context looks valid to me.

We should rather look into backporting that upstream commit, I would say. Or does it have tons of dependencies?

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#17 lore raw

PATCH 2/3 arm64: fpsimd: dovetail: drop redundant hard irqs disabling

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

fpsimd_save_and_flush_cpu_state() itself does take care of this.

---
 arch/arm64/kernel/fpsimd.c | 4 ----
 1 file changed, 4 deletions(-)
arch/arm64/kernel/fpsimd.c +0 -4
index ba804fcdfdb3f..f915706332191 100644
@@ -2148,13 +2148,9 @@ void __efi_fpsimd_end(void)
 static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
 				  unsigned long cmd, void *v)
 {
-	unsigned long flags;
-
 	switch (cmd) {
 	case CPU_PM_ENTER:
-		flags = hard_cond_local_irq_save();
 		fpsimd_save_and_flush_cpu_state();
-		hard_cond_local_irq_restore(flags);
 		break;
 	case CPU_PM_EXIT:
 		break;
Signature · 1 line
2.51.0
author
#18 lore raw

Re: [dovetail 6.1.y-cip][PATCH 2/3] arm64: fpsimd: dovetail: drop redundant hard irqs disabling

Quoted 17 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

fpsimd_save_and_flush_cpu_state() itself does take care of this.

---
 arch/arm64/kernel/fpsimd.c | 4 ----
 1 file changed, 4 deletions(-)
arch/arm64/kernel/fpsimd.c +0 -0
index ba804fcdfdb3f..f915706332191 100644
@@ -2148,13 +2148,9 @@ void __efi_fpsimd_end(void)
 static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
 				  unsigned long cmd, void *v)
 {

arch/arm64/kernel/fpsimd.c void __efi_fpsimd_end(void) · line 2156

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +0 -4
-	unsigned long flags;
-
 	switch (cmd) {
 	case CPU_PM_ENTER:
-		flags = hard_cond_local_irq_save();
 		fpsimd_save_and_flush_cpu_state();
-		hard_cond_local_irq_restore(flags);
 		break;
 	case CPU_PM_EXIT:
 		break;

And this one for 6.1 should also be merged. The changes in patch 1 and 3 found their way into v6.1.y-cip-dovetail-rebase in the meantime, as it looks like.

BTW, a new release for 6.1 would be good as well then, to get all of this tagged.

Thanks
Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#19 lore raw

Re: [dovetail 6.1.y-cip][PATCH 2/3] arm64: fpsimd: dovetail: drop redundant hard irqs disabling

Quoted 33 lines · Jan Kiszka
Quoted 17 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

fpsimd_save_and_flush_cpu_state() itself does take care of this.

---
 arch/arm64/kernel/fpsimd.c | 4 ----
 1 file changed, 4 deletions(-)
arch/arm64/kernel/fpsimd.c +0 -0
index ba804fcdfdb3f..f915706332191 100644
@@ -2148,13 +2148,9 @@ void __efi_fpsimd_end(void)
 static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
 				  unsigned long cmd, void *v)
 {

arch/arm64/kernel/fpsimd.c void __efi_fpsimd_end(void) · line 2156

Quoted 10 lines
arch/arm64/kernel/fpsimd.c +0 -4
-	unsigned long flags;
-
 	switch (cmd) {
 	case CPU_PM_ENTER:
-		flags = hard_cond_local_irq_save();
 		fpsimd_save_and_flush_cpu_state();
-		hard_cond_local_irq_restore(flags);
 		break;
 	case CPU_PM_EXIT:
 		break;

And this one for 6.1 should also be merged. The changes in patch 1 and 3 found their way into v6.1.y-cip-dovetail-rebase in the meantime, as it looks like.

Quoted 3 lines

BTW, a new release for 6.1 would be good as well then, to get all of this tagged.

There is a set of fixes for the oob network stack coming shortly, rebase over stable is planned right after (Wednesday).

Signature · 1 line
Philippe.
author
#20 lore raw

PATCH 3/3 arm64: fpsimd: dovetail: Drop extra condition from WARN_ON

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

There is no indication that this function is called over oob context as well, and newer dovetail versions do not carry this extra condition anymore.

---
 arch/arm64/kernel/fpsimd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/fpsimd.c +1 -1
index f915706332191..ed269edea7907 100644
@@ -1950,7 +1950,7 @@ void fpsimd_save_and_flush_cpu_state(void)
 {
 	if (!system_supports_fpsimd())
 		return;
-	WARN_ON(!hard_irqs_disabled() && preemptible());
+	WARN_ON(preemptible());
 	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
Signature · 1 line
2.51.0
#21 lore raw

Re: [dovetail 6.1.y-cip][PATCH 3/3] arm64: fpsimd: dovetail: Drop extra condition from WARN_ON

Quoted 6 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

There is no indication that this function is called over oob context as well, and newer dovetail versions do not carry this extra condition anymore.

Depends on whether patch 2/3 is actually correct.

Quoted 18 lines
---
 arch/arm64/kernel/fpsimd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/fpsimd.c +1 -1
index f915706332191..ed269edea7907 100644
@@ -1950,7 +1950,7 @@ void fpsimd_save_and_flush_cpu_state(void)
 {
 	if (!system_supports_fpsimd())
 		return;
-	WARN_ON(!hard_irqs_disabled() && preemptible());
+	WARN_ON(preemptible());
 	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
Signature · 1 line
Philippe.
#22 lore raw

Re: [dovetail 6.1.y-cip][PATCH 3/3] arm64: fpsimd: dovetail: Drop extra condition from WARN_ON

Quoted 10 lines · Philippe Gerum
Quoted 6 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

There is no indication that this function is called over oob context as well, and newer dovetail versions do not carry this extra condition anymore.

Depends on whether patch 2/3 is actually correct.

1/3, not 2/3.

Quoted 19 lines
Quoted 19 lines
---
 arch/arm64/kernel/fpsimd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/fpsimd.c +1 -1
index f915706332191..ed269edea7907 100644
@@ -1950,7 +1950,7 @@ void fpsimd_save_and_flush_cpu_state(void)
 {
 	if (!system_supports_fpsimd())
 		return;
-	WARN_ON(!hard_irqs_disabled() && preemptible());
+	WARN_ON(preemptible());
 	get_cpu_fpsimd_context();
 	__fpsimd_save();
 	fpsimd_flush_cpu_state();
Signature · 1 line
Philippe.