Skip to contentSkip to conversation

calling __get_cpu_fpsimd_context twice in a row when kernel_neon_begin running

PATCH linz 5 participants 14 messages Jan 9, 2024 – Feb 14, 2025 arm64

lore
Share & tools
lore

linz

author
#0 lore raw

Hi, I find a call tracing when I use xenomai v3.2.2 branch and test latency testsuit, the Call trace is as follows

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0 [  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits
[  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000
[  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2 [  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--)
[  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260)
[  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

The reason is when kernel_neon_begin is called, it calls __get_cpu_fpsimd_context. Then xenomai oob interrupt triggers function named __switch_to, which calls  __get_cpu_fpsimd_context again. Calling this function twice in a row will trigger a call trace.
The function call relationship is as follows:

efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin =>get_cpu_fpsimd_context =>hard_preempt_disable  // disable interrupt =>__get_cpu_fpsimd_context    // *first call* =>hard_cond_local_irq_restore  // enable interrupt

      handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
          =>irq_exit_pipeline
            =>xnsched_run
              =>__xnsched_run
                =>pipeline_schedule
                  =>run_oob_call
                    =>___xnsched_run
                      =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context //*second call*

The fixed up patch is as follows:

From f0cb2b2f3174789eb8348feff6abdc7dbdafc8c4 Mon Sep 17 00:00:00 2001
From: zhanglin <[email protected]>
Date: Tue, 9 Jan 2024 17:08:20 +0800
Subject: [PATCH] arm64/fpsimd: fix bug for calling __get_cpu_fpsimd_context twice in a row when kernel_neon_begin running

---
 arch/arm64/kernel/fpsimd.c | 6 ++++++

 1 file changed, 6 insertions(+)
arch/arm64/kernel/fpsimd.c +0 -0
index 01a4774a2..bc180d0cf 100644
@@ -44,6 +44,10 @@

 #include <asm/traps.h>
 #include <asm/virt.h>

+#ifdef CONFIG_KERNEL_MODE_NEON
+#include <cobalt/kernel/sched.h>
+#endif
+
 #define FPEXC_IOF    (1 << 0)
 #define FPEXC_DZF    (1 << 1)
 #define FPEXC_OFF    (1 << 2)
@@ -1367,6 +1371,7 @@ void kernel_neon_begin(void)

     BUG_ON(!may_use_simd());

+    xnsched_lock();
     get_cpu_fpsimd_context(flags);

     /* Save unsaved fpsimd state, if any: */
@@ -1397,6 +1402,7 @@ void kernel_neon_end(void)
         return;

     put_cpu_fpsimd_context(flags);
+    xnsched_unlock();
 }
 EXPORT_SYMBOL(kernel_neon_end);

Signature · 4 lines
2.25.1


Please help to review it, thank you.
#1 lore raw
Quoted 19 lines · linz

Hi, I find a call tracing when I use xenomai v3.2.2 branch and test latency testsuit, the Call trace is as follows

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0
[  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits [  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000 [  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP [  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2

Could you check if the issue persists with latest v6.6-dovetail1-rebase? Just to avoid that we are missing some fix backports in 5.10.

Quoted 113 lines

[  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--) [  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260) [  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

The reason is when kernel_neon_begin is called, it calls __get_cpu_fpsimd_context. Then xenomai oob interrupt triggers function named __switch_to, which calls  __get_cpu_fpsimd_context again. Calling this function twice in a row will trigger a call trace. The function call relationship is as follows:

efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin =>get_cpu_fpsimd_context =>hard_preempt_disable  // disable interrupt =>__get_cpu_fpsimd_context    // *first call* =>hard_cond_local_irq_restore  // enable interrupt

      handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
          =>irq_exit_pipeline
            =>xnsched_run
              =>__xnsched_run
                =>pipeline_schedule
                  =>run_oob_call
                    =>___xnsched_run
                      =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context //*second call*

The fixed up patch is as follows:

From f0cb2b2f3174789eb8348feff6abdc7dbdafc8c4 Mon Sep 17 00:00:00 2001
From: zhanglin <[email protected]>
Date: Tue, 9 Jan 2024 17:08:20 +0800
Subject: [PATCH] arm64/fpsimd: fix bug for calling __get_cpu_fpsimd_context twice in a row when kernel_neon_begin running

---
 arch/arm64/kernel/fpsimd.c | 6 ++++++

 1 file changed, 6 insertions(+)
arch/arm64/kernel/fpsimd.c +4 -0
index 01a4774a2..bc180d0cf 100644
@@ -44,6 +44,10 @@
  #include <asm/traps.h>
  #include <asm/virt.h>
 
+#ifdef CONFIG_KERNEL_MODE_NEON
+#include <cobalt/kernel/sched.h>
+#endif
+
  #define FPEXC_IOF    (1 << 0)
  #define FPEXC_DZF    (1 << 1)
  #define FPEXC_OFF    (1 << 2)

arch/arm64/kernel/fpsimd.c void kernel_neon_begin(void) · line 1374

Quoted 4 lines
arch/arm64/kernel/fpsimd.c +1 -0
@@ -1367,6 +1371,7 @@ void kernel_neon_begin(void)
 
      BUG_ON(!may_use_simd());
 
+    xnsched_lock();

This would be a laying violation: dovetail has no knowledge of Xenomai, and it also serves EVL with a different API. But we will find a fitting locking construct here quickly once we understood the issue completely (or I - need to spend some calm cycles later).

arch/arm64/kernel/fpsimd.c void kernel_neon_end(void) · line 1408

Quoted 11 lines
arch/arm64/kernel/fpsimd.c +1 -0
      get_cpu_fpsimd_context(flags);
 
      /* Save unsaved fpsimd state, if any: */
@@ -1397,6 +1402,7 @@ void kernel_neon_end(void)
          return;
 
      put_cpu_fpsimd_context(flags);
+    xnsched_unlock();
  }
  EXPORT_SYMBOL(kernel_neon_end);
 

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
author
#2 lore raw

Thank you very much for your suggestion. Currently, our hardware products do not support linux kernel 6.6. If upgrading, we will test it out.

Quoted 158 lines · Jan Kiszka
Quoted 19 lines · linz

Hi, I find a call tracing when I use xenomai v3.2.2 branch and test latency testsuit, the Call trace is as follows

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0
[  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits [  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000 [  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP [  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2

Could you check if the issue persists with latest v6.6-dovetail1-rebase? Just to avoid that we are missing some fix backports in 5.10.

Quoted 113 lines

[  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--) [  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260) [  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

The reason is when kernel_neon_begin is called, it calls __get_cpu_fpsimd_context. Then xenomai oob interrupt triggers function named __switch_to, which calls  __get_cpu_fpsimd_context again. Calling this function twice in a row will trigger a call trace. The function call relationship is as follows:

efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin =>get_cpu_fpsimd_context =>hard_preempt_disable  // disable interrupt =>__get_cpu_fpsimd_context    // *first call* =>hard_cond_local_irq_restore  // enable interrupt

      handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
          =>irq_exit_pipeline
            =>xnsched_run
              =>__xnsched_run
                =>pipeline_schedule
                  =>run_oob_call
                    =>___xnsched_run
                      =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context //*second call*

The fixed up patch is as follows:

From f0cb2b2f3174789eb8348feff6abdc7dbdafc8c4 Mon Sep 17 00:00:00 2001
From: zhanglin <[email protected]>
Date: Tue, 9 Jan 2024 17:08:20 +0800
Subject: [PATCH] arm64/fpsimd: fix bug for calling __get_cpu_fpsimd_context
 twice in a row when kernel_neon_begin running

---
  arch/arm64/kernel/fpsimd.c | 6 ++++++
  1 file changed, 6 insertions(+)
arch/arm64/kernel/fpsimd.c +4 -0
index 01a4774a2..bc180d0cf 100644
@@ -44,6 +44,10 @@
  #include <asm/traps.h>
  #include <asm/virt.h>
 
+#ifdef CONFIG_KERNEL_MODE_NEON
+#include <cobalt/kernel/sched.h>
+#endif
+
  #define FPEXC_IOF    (1 << 0)
  #define FPEXC_DZF    (1 << 1)
  #define FPEXC_OFF    (1 << 2)

arch/arm64/kernel/fpsimd.c void kernel_neon_begin(void) · line 1374

Quoted 4 lines
arch/arm64/kernel/fpsimd.c +1 -0
@@ -1367,6 +1371,7 @@ void kernel_neon_begin(void)
 
      BUG_ON(!may_use_simd());
 
+    xnsched_lock();

This would be a laying violation: dovetail has no knowledge of Xenomai, and it also serves EVL with a different API. But we will find a fitting locking construct here quickly once we understood the issue completely (or I - need to spend some calm cycles later).

arch/arm64/kernel/fpsimd.c void kernel_neon_end(void) · line 1408

Quoted 11 lines
arch/arm64/kernel/fpsimd.c +1 -0
      get_cpu_fpsimd_context(flags);
 
      /* Save unsaved fpsimd state, if any: */
@@ -1397,6 +1402,7 @@ void kernel_neon_end(void)
          return;
 
      put_cpu_fpsimd_context(flags);
+    xnsched_unlock();
  }
  EXPORT_SYMBOL(kernel_neon_end);
 

Jan

#3 lore raw
In reply to Jan Kiszka
Quoted 21 lines · Jan Kiszka
Quoted 19 lines · linz

Hi, I find a call tracing when I use xenomai v3.2.2 branch and test latency testsuit, the Call trace is as follows

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0
[  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits [  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000 [  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP [  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2

Quoted 67 lines

Could you check if the issue persists with latest v6.6-dovetail1-rebase? Just to avoid that we are missing some fix backports in 5.10.

Quoted 64 lines

[  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--) [  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260) [  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

The reason is when kernel_neon_begin is called, it calls __get_cpu_fpsimd_context. Then xenomai oob interrupt triggers function named __switch_to, which calls  __get_cpu_fpsimd_context again. Calling this function twice in a row will trigger a call trace. The function call relationship is as follows:

efi_call_rts
  =>__efi_fpsimd_begin

BTW, calling into the firmware on core that is also supposed to do hard RT is a no-go. PREEMPT-RT turns off EFI runtime services for that reason. That's another topic, not the core of this issue here, though.

Quoted 50 lines
Quoted 50 lines

    =>kernel_neon_begin =>get_cpu_fpsimd_context =>hard_preempt_disable  // disable interrupt =>__get_cpu_fpsimd_context    // *first call* =>hard_cond_local_irq_restore  // enable interrupt

      handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
          =>irq_exit_pipeline
            =>xnsched_run
              =>__xnsched_run
                =>pipeline_schedule
                  =>run_oob_call
                    =>___xnsched_run
                      =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context //*second call*

The fixed up patch is as follows:

From f0cb2b2f3174789eb8348feff6abdc7dbdafc8c4 Mon Sep 17 00:00:00 2001
From: zhanglin <[email protected]>
Date: Tue, 9 Jan 2024 17:08:20 +0800
Subject: [PATCH] arm64/fpsimd: fix bug for calling __get_cpu_fpsimd_context twice in a row when kernel_neon_begin running

---
 arch/arm64/kernel/fpsimd.c | 6 ++++++

 1 file changed, 6 insertions(+)
arch/arm64/kernel/fpsimd.c +4 -0
index 01a4774a2..bc180d0cf 100644
@@ -44,6 +44,10 @@
  #include <asm/traps.h>
  #include <asm/virt.h>
 
+#ifdef CONFIG_KERNEL_MODE_NEON
+#include <cobalt/kernel/sched.h>
+#endif
+
  #define FPEXC_IOF    (1 << 0)
  #define FPEXC_DZF    (1 << 1)
  #define FPEXC_OFF    (1 << 2)
@@ -1367,6 +1371,7 @@ void kernel_neon_begin(void)
 
Quoted 9 lines

arch/arm64/kernel/fpsimd.c void kernel_neon_begin(void) · line 1374

Quoted 3 lines
arch/arm64/kernel/fpsimd.c +1 -0
      BUG_ON(!may_use_simd());
 
+    xnsched_lock();

This would be a laying violation: dovetail has no knowledge of Xenomai, and it also serves EVL with a different API. But we will find a fitting locking construct here quickly once we understood the issue completely (or I - need to spend some calm cycles later).

In addition, your changes make the sections kernel_neon_begin..end non-interruptible. I'm not sure that this is something desirable. It's also not what we do on x86 eg. for kernel_fpu_begin..end.

Philippe, is the kernel neon section already interruptible by OOB scheduling and just the warning about the busy flag misleading here, or do we still have more todos?

Jan

Quoted 14 lines

arch/arm64/kernel/fpsimd.c void kernel_neon_end(void) · line 1408

Quoted 11 lines
arch/arm64/kernel/fpsimd.c +1 -0
      get_cpu_fpsimd_context(flags);
 
      /* Save unsaved fpsimd state, if any: */
@@ -1397,6 +1402,7 @@ void kernel_neon_end(void)
          return;
 
      put_cpu_fpsimd_context(flags);
+    xnsched_unlock();
  }
  EXPORT_SYMBOL(kernel_neon_end);
 

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
author
#4 lore raw

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly. efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy =>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

So, I think there are more todos on arm64. Do you have any other good suggestions?

When the call trace is trigger on arm64, the ftrace is as follows:

   kworker/u16:1-503     [003] ...1  3037.586789: kernel_neon_begin <-__efi_fpsimd_begin
   kworker/u16:1-503     [003] ...1  3037.586789: hard_preempt_disable <-kernel_neon_begin // enter the critical zone
   kworker/u16:1-503     [003] D..1  3037.586790: preempt_count_add <-hard_preempt_disable
   kworker/u16:1-503     [003] D..2  3037.586790: __get_cpu_fpsimd_context <-kernel_neon_begin                                     // first call __get_cpu_fpsimd_context kworker/u16:1-503     [003] D..2  3037.586790: __fpsimd_save <-kernel_neon_begin
   kworker/u16:1-503     [003] D..2  3037.586791: fpsimd_flush_cpu_state <-kernel_neon_begin
// when hard_cond_local_irq_restore finishes, leave the critcal zone
// ftrace can't get hard_cond_local_irq_restore because it's macro
// in function kernel_neon_begin, hard_cond_local_irq_restore enable the interrupt
   kworker/u16:1-503     [003] D..2  3037.587260: handle_irq_pipelined <-handle_arch_irq_pipelined                                 // the latency timer interrupt is trigger, so the interrupt is disabled again kworker/u16:1-503     [003] D..2  3037.587261: handle_irq_pipelined_prepare <-handle_irq_pipelined
   kworker/u16:1-503     [003] D..2  3037.587261: preempt_count_add <-handle_irq_pipelined_prepare
   kworker/u16:1-503     [003] D.~2  3037.587261: preempt_count_add <-handle_irq_pipelined_prepare
   kworker/u16:1-503     [003] D.~2  3037.587262: gic_handle_irq <-handle_irq_pipelined
   kworker/u16:1-503     [003] D.~2  3037.587262: irq_find_mapping <-gic_handle_irq
   kworker/u16:1-503     [003] D.~2  3037.587262: rcu_oob_prepare_lock <-irq_find_mapping
   kworker/u16:1-503     [003] D.~2  3037.587263: __rcu_read_lock <-irq_find_mapping
   kworker/u16:1-503     [003] D.~2  3037.587263: __rcu_read_unlock <-irq_find_mapping
   kworker/u16:1-503     [003] D.~2  3037.587263: rcu_oob_finish_lock <-irq_find_mapping
   kworker/u16:1-503     [003] D.~2  3037.587264: generic_pipeline_irq <-gic_handle_irq
   kworker/u16:1-503     [003] D.~2  3037.587264: generic_pipeline_irq_desc <-generic_pipeline_irq
   kworker/u16:1-503     [003] D.~2  3037.587265: handle_percpu_devid_irq <-generic_pipeline_irq_desc
   kworker/u16:1-503     [003] D.~2  3037.587265: handle_oob_irq <-handle_percpu_devid_irq
   kworker/u16:1-503     [003] D.~2  3037.587265: handle_oob_irq.part.0 <-handle_oob_irq
   kworker/u16:1-503     [003] D.~2  3037.587265: do_oob_irq <-handle_oob_irq.part.0
   kworker/u16:1-503     [003] D.~2  3037.587266: arch_timer_handler_phys <-do_oob_irq
   kworker/u16:1-503     [003] D.~2  3037.587266: xnintr_core_clock_handler <-arch_timer_handler_phys
   kworker/u16:1-503     [003] D.~2  3037.587267: ___xnlock_get <-xnintr_core_clock_handler
   kworker/u16:1-503     [003] D.~2  3037.587267: xnclock_tick <-xnintr_core_clock_handler
   kworker/u16:1-503     [003] D.~2  3037.587267: ktime_get_mono_fast_ns <-xnclock_tick
   kworker/u16:1-503     [003] D.~2  3037.587268: arch_counter_read <-ktime_get_mono_fast_ns
   kworker/u16:1-503     [003] D.~2  3037.587268: timerfd_handler <-xnclock_tick
   kworker/u16:1-503     [003] D.~2  3037.587268: xnsynch_wakeup_one_sleeper <-timerfd_handler
   kworker/u16:1-503     [003] D.~2  3037.587269: ___xnlock_get <-xnsynch_wakeup_one_sleeper
   kworker/u16:1-503     [003] D.~2  3037.587269: xnthread_resume <-xnsynch_wakeup_one_sleeper
   kworker/u16:1-503     [003] D.~2  3037.587269: ___xnlock_get <-xnthread_resume
   kworker/u16:1-503     [003] D.~2  3037.587270: ktime_get_mono_fast_ns <-xnclock_tick
   kworker/u16:1-503     [003] D.~2  3037.587270: arch_counter_read <-ktime_get_mono_fast_ns
   kworker/u16:1-503     [003] D.~2  3037.587271: xnclock_core_local_shot <-xnclock_tick
   kworker/u16:1-503     [003] D.~2  3037.587271: ktime_get_mono_fast_ns <-xnclock_core_local_shot
   kworker/u16:1-503     [003] D.~2  3037.587271: arch_counter_read <-ktime_get_mono_fast_ns
   kworker/u16:1-503     [003] D.~2  3037.587272: pipeline_set_timer_shot <-xnclock_core_local_shot
   kworker/u16:1-503     [003] D.~2  3037.587272: arch_timer_set_next_event_phys <-pipeline_set_timer_shot
   kworker/u16:1-503     [003] D.~2  3037.587272: ___xnlock_put <-xnintr_core_clock_handler
   kworker/u16:1-503     [003] D.~2  3037.587273: gic_eoimode1_eoi_irq <-handle_percpu_devid_irq
   kworker/u16:1-503     [003] D.~2  3037.587273: handle_irq_pipelined_finish <-handle_irq_pipelined
   kworker/u16:1-503     [003] D.~2  3037.587273: preempt_count_sub <-handle_irq_pipelined_finish
   kworker/u16:1-503     [003] D.~2  3037.587274: ___xnsched_run <-run_oob_call
   kworker/u16:1-503     [003] D.~2  3037.587275: ___xnlock_get <-___xnsched_run
   kworker/u16:1-503     [003] D.~2  3037.587275: xnsched_pick_next <-___xnsched_run
   kworker/u16:1-503     [003] D.~2  3037.587276: ktime_get_mono_fast_ns <-___xnsched_run
   kworker/u16:1-503     [003] D.~2  3037.587276: arch_counter_read <-ktime_get_mono_fast_ns
   kworker/u16:1-503     [003] D.~2  3037.587276: pipeline_switch_to <-___xnsched_run
   kworker/u16:1-503     [003] D.~2  3037.587277: dovetail_context_switch <-pipeline_switch_to
   kworker/u16:1-503     [003] D.~2  3037.587277: check_and_switch_context <-dovetail_context_switch
   kworker/u16:1-503     [003] D.~2  3037.587277: cpu_do_switch_mm <-check_and_switch_context
   kworker/u16:1-503     [003] D.~2  3037.587278: post_ttbr_update_workaround <-cpu_do_switch_mm
   kworker/u16:1-503     [003] D.~2  3037.587278: fpsimd_thread_switch <-__switch_to
   kworker/u16:1-503     [003] D.~2  3037.587279: __get_cpu_fpsimd_context <-fpsimd_thread_switch                               // second call __get_cpu_fpsimd_context, similar with AA deadlock

Quoted 173 lines · Jan Kiszka
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · linz

Hi, I find a call tracing when I use xenomai v3.2.2 branch and test latency testsuit, the Call trace is as follows

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0
[  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits [  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000 [  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP [  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2

Quoted 67 lines

Could you check if the issue persists with latest v6.6-dovetail1-rebase? Just to avoid that we are missing some fix backports in 5.10.

Quoted 64 lines

[  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--) [  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260) [  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

The reason is when kernel_neon_begin is called, it calls __get_cpu_fpsimd_context. Then xenomai oob interrupt triggers function named __switch_to, which calls  __get_cpu_fpsimd_context again. Calling this function twice in a row will trigger a call trace. The function call relationship is as follows:

efi_call_rts
  =>__efi_fpsimd_begin

BTW, calling into the firmware on core that is also supposed to do hard RT is a no-go. PREEMPT-RT turns off EFI runtime services for that reason. That's another topic, not the core of this issue here, though.

Quoted 50 lines
Quoted 50 lines

    =>kernel_neon_begin =>get_cpu_fpsimd_context =>hard_preempt_disable  // disable interrupt =>__get_cpu_fpsimd_context    // *first call* =>hard_cond_local_irq_restore  // enable interrupt

      handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
          =>irq_exit_pipeline
            =>xnsched_run
              =>__xnsched_run
                =>pipeline_schedule
                  =>run_oob_call
                    =>___xnsched_run
                      =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context //*second call*

The fixed up patch is as follows:

From f0cb2b2f3174789eb8348feff6abdc7dbdafc8c4 Mon Sep 17 00:00:00 2001
From: zhanglin <[email protected]>
Date: Tue, 9 Jan 2024 17:08:20 +0800
Subject: [PATCH] arm64/fpsimd: fix bug for calling __get_cpu_fpsimd_context
 twice in a row when kernel_neon_begin running

---
  arch/arm64/kernel/fpsimd.c | 6 ++++++
  1 file changed, 6 insertions(+)
arch/arm64/kernel/fpsimd.c +4 -0
index 01a4774a2..bc180d0cf 100644
@@ -44,6 +44,10 @@
  #include <asm/traps.h>
  #include <asm/virt.h>
 
+#ifdef CONFIG_KERNEL_MODE_NEON
+#include <cobalt/kernel/sched.h>
+#endif
+
  #define FPEXC_IOF    (1 << 0)
  #define FPEXC_DZF    (1 << 1)
  #define FPEXC_OFF    (1 << 2)
@@ -1367,6 +1371,7 @@ void kernel_neon_begin(void)
 
Quoted 8 lines

arch/arm64/kernel/fpsimd.c void kernel_neon_begin(void) · line 1374

Quoted 3 lines
arch/arm64/kernel/fpsimd.c +1 -0
      BUG_ON(!may_use_simd());
 
+    xnsched_lock();

This would be a laying violation: dovetail has no knowledge of Xenomai, and it also serves EVL with a different API. But we will find a fitting locking construct here quickly once we understood the issue completely (or I - need to spend some calm cycles later).

In addition, your changes make the sections kernel_neon_begin..end non-interruptible. I'm not sure that this is something desirable. It's also not what we do on x86 eg. for kernel_fpu_begin..end.

Philippe, is the kernel neon section already interruptible by OOB scheduling and just the warning about the busy flag misleading here, or do we still have more todos?

Jan

Quoted 13 lines

arch/arm64/kernel/fpsimd.c void kernel_neon_end(void) · line 1408

Quoted 11 lines
arch/arm64/kernel/fpsimd.c +1 -0
      get_cpu_fpsimd_context(flags);
 
      /* Save unsaved fpsimd state, if any: */
@@ -1397,6 +1402,7 @@ void kernel_neon_end(void)
          return;
 
      put_cpu_fpsimd_context(flags);
+    xnsched_unlock();
  }
  EXPORT_SYMBOL(kernel_neon_end);
 

Jan

#5 lore raw
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

Thanks,
Jan

author
#6 lore raw

This issue could result in a data access exception. And finally, the running core would get stuck.

[  777.563100] Unable to handle kernel NULL pointer dereference at virtual address 00000000000002c0 [  777.563101] Mem abort info:
[  777.563102]   ESR = 0x96000004
[  777.563103]   EC = 0x25: DABT (current EL), IL = 32 bits
[  777.563104]   SET = 0, FnV = 0
[  777.563104]   EA = 0, S1PTW = 0
[  777.563105] Data abort info:
[  777.563105]   ISV = 0, ISS = 0x00000004
[  777.563106]   CM = 0, WnR = 0
[  777.563107] user pgtable: 4k pages, 48-bit VAs, pgdp=000000200c513000
[  777.563108] [00000000000002c0] pgd=0000000000000000, p4d=0000000000000000
[  777.563110] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[  777.563118] CPU: 3 PID: 149 Comm: kworker/u16:2 Not tainted 5.10.153-dovetail3 #2 [  777.563119] IRQ stage: Xenomai
[  777.563120] Workqueue: efi_rts_wq efi_call_rts
[  777.563121] pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO BTYPE=--)
[  777.563121] pc : xnthread_relax+0x78/0x1d4
[  777.563122] lr : xnthread_relax+0x78/0x1d4
[  777.563122] sp : ffff80001001bbf0
[  777.563123] x29: ffff80001001bbf0 x28: ffff001f809daa00
[  777.563124] x27: ffff001f803426c8 x26: ffff80001001c000
[  777.563126] x25: ffff800010018000 x24: ffff0020f6f93008
[  777.563127] x23: 0000000080000085 x22: 0000000000000003
[  777.563129] x21: ffff001f809daa00 x20: 0000000000000001
[  777.563130] x19: 0000000000000000 x18: 0000000000000000
[  777.563132] x17: 0000015a8ca44dbc x16: 0000000000000013
[  777.563133] x15: ffff800010f892a8 x14: 0000000000000002
[  777.563135] x13: 0000000000000043 x12: 0000000000000040
[  777.563136] x11: ffff001f804dab58 x10: ffff001f804dab5a
[  777.563137] x9 : 00000000000003c0 x8 : 0000000000000000
[  777.563139] x7 : 0000000000000000 x6 : 0000000000000001
[  777.563140] x5 : ffff0020f6f8ece0 x4 : 0000000000000000
[  777.563142] x3 : ffff0020f6f8eae0 x2 : ffff8020e5a57000
[  777.563143] x1 : 0000000000000003 x0 : 0000000000000002
[  777.563144] Call trace:
[  777.563145]  xnthread_relax+0x78/0x1d4
[  777.563146]  handle_oob_trap_entry+0x78/0x1b0
[  777.563146]  __oob_trap_notify+0x40/0x70
[  777.563147]  do_debug_exception+0x170/0x1c4
[  777.563147]  el1_dbg+0x34/0x50
[  777.563148]  el1_sync_handler+0x9c/0xd0
[  777.563148]  el1_sync+0x88/0x140
[  777.563149]  __get_cpu_fpsimd_context+0x2c/0x40
[  777.563150]  __switch_to+0x20/0x120
[  777.563150]  dovetail_context_switch+0x6c/0x130
[  777.563151]  pipeline_switch_to+0x10/0x20
[  777.563151]  ___xnsched_run+0x174/0x25c
[  777.563152]  run_oob_call+0x88/0x174
[  777.563153]  handle_irq_pipelined_finish+0x1d8/0x1ec
[  777.563153]  handle_irq_pipelined+0x38/0x50
[  777.563154]  handle_arch_irq_pipelined+0x10/0x20
[  777.563155]  el1_irq+0xdc/0x1c0
[  777.563155]  0x203626c4
[  777.563156]  0x20361190
[  777.563156]  0x203615b4
[  777.563156]  0x20361660
[  777.563157]  0x20361da0
[  777.563157]  0x203609ec
[  777.563158]  __efi_rt_asm_wrapper+0x28/0x4c
[  777.563159]  efi_call_rts+0x204/0x3d0
[  777.563159]  process_one_work+0x1cc/0x350
[  777.563160]  worker_thread+0x138/0x46c
[  777.563160]  kthread+0x154/0x160
[  777.563161]  ret_from_fork+0x10/0x3c
[  777.563162] Code: 97ff4dae f000a180 91236000 97ffdde7 (f9416260)
[  777.563162] ---[ end trace 5ef18d81e2ade362 ]---
[  777.563163] note: kworker/u16:2[149] exited with preempt_count 33554434

Quoted 50 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone
        =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu)); =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

Thanks,
Jan

#7 lore raw
In reply to Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 8 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections. Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.
author
#8 lore raw

I understand, thank you. Do you have a plan to solve this problem?

Quoted 58 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone
        =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu)); =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 7 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections. Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

author
#9 lore raw
In reply to Philippe Gerum

Hi, all
I think the following patch can resolve the bug, it allows oob threads to safely preempt kernel_neon_begin() / kernel_neon_end sections.
https://source.denx.de/Xenomai/linux-dovetail/-/commit/9b19700e623f96222c69ecb2adecb1a3e3664cc0

But this patch has been merged into the Linux kernel version 6.8. At present, I have no plan to upgrade to version 6.8. I'm not sure if I understand correctly, but if so, is there a plan to backport this patch to a lower version, such as 5.10?

Quoted 63 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 8 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections. Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.
#10 lore raw
Quoted 7 lines · linz

Hi, all
I think the following patch can resolve the bug, it allows oob threads to safely preempt kernel_neon_begin() / kernel_neon_end sections.
https://source.denx.de/Xenomai/linux-dovetail/-/commit/9b19700e623f96222c69ecb2adecb1a3e3664cc0

But this patch has been merged into the Linux kernel version 6.8. At present, I have no plan to upgrade to version 6.8. I'm not sure if I understand correctly, but if so, is there a plan to backport this patch to a lower version, such as 5.10?

Have you tried to backport it to your kernel already to confirm that it helps?

Unfortunately, it looks like a cleanup to upstream, so we may not get it in via normal LTS. But if it help, picking it into dovetail LTS trees is imaginable.

Jan

Quoted 65 lines
Quoted 63 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 8 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections. Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.
Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#11 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 7 lines · linz

Hi,  all
I think the following patch can resolve the bug,  it allows oob threads to safely preempt kernel_neon_begin() / kernel_neon_end sections.
https://source.denx.de/Xenomai/linux-dovetail/-/commit/9b19700e623f96222c69ecb2adecb1a3e3664cc0

But this patch has been merged into the Linux kernel version 6.8. At present, I have no plan to upgrade to version 6.8. I'm not sure if I understand correctly, but if so, is there a plan to backport this patch to a lower version, such as 5.10?

Quoted 6 lines

Have you tried to backport it to your kernel already to confirm that it helps?

Unfortunately, it looks like a cleanup to upstream, so we may not get it in via normal LTS. But if it help, picking it into dovetail LTS trees is imaginable.

That patch at least depends on

13150149 ("arm64: fpsimd: run kernel mode NEON with softirqs disabled")

There is more work to be done to have that properly backported, or update to one of the recent LTS versions.

Florian

Quoted 73 lines

Jan

Quoted 60 lines
Quoted 58 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
        =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 8 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections.  Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

Quoted 5 lines
Quoted 5 lines

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.

--
Siemens AG, Foundational Technologies
Linux Expert Center

author
#12 lore raw

I don't have any plans recently to backport this patch to the lower versions of the Dovetail kernel.
When I'm free in a few months, I might backport this patch to the lower versions and conduct some tests. I will keep everyone informed of the results. Thank you for your advice, Florian Bezdeka and Jan Kiszka

Quoted 91 lines · Florian Bezdeka
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · linz

Hi,  all
I think the following patch can resolve the bug,  it allows oob threads to safely preempt kernel_neon_begin() / kernel_neon_end sections.
https://source.denx.de/Xenomai/linux-dovetail/-/commit/9b19700e623f96222c69ecb2adecb1a3e3664cc0

But this patch has been merged into the Linux kernel version 6.8. At present, I have no plan to upgrade to version 6.8. I'm not sure if I understand correctly, but if so, is there a plan to backport this patch to a lower version, such as 5.10?

Quoted 6 lines

Have you tried to backport it to your kernel already to confirm that it helps?

Unfortunately, it looks like a cleanup to upstream, so we may not get it in via normal LTS. But if it help, picking it into dovetail LTS trees is imaginable.

That patch at least depends on

13150149 ("arm64: fpsimd: run kernel mode NEON with softirqs disabled")

There is more work to be done to have that properly backported, or update to one of the recent LTS versions.

Florian

Quoted 67 lines

Jan

Quoted 56 lines
Quoted 55 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone
        =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu)); =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 7 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections.  Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

Quoted 5 lines
Quoted 5 lines

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.

--
Siemens AG, Foundational Technologies
Linux Expert Center

#13 lore raw
Quoted 6 lines · powertree

I don't have any plans recently to backport this patch to the lower versions of the Dovetail kernel.
When I'm free in a few months, I might backport this patch to the lower versions and conduct some tests. I will keep everyone informed of the results.
Thank you for your advice, Florian Bezdeka and Jan Kiszka

Let me revive this stalled topic:

This issue still persists, the mentioned patch (alone) does not help here. Dovetail on arm(64) is missing a proper store/restore logic for in-kernel-FPU usage when an out-of-band is preempting a inband task.

This topic came back while forward porting dovetail to 6.14. The xenomai test suite is sufficient to trigger a FPU corruption.

We discussed the topic in our Dovetail maintainer sync today. I might have some time next week to look into this topic. At least for arm64. arm might need separate care. I will start by revisiting the x86 implementation.

Best regards,
Florian

Quoted 95 lines · Florian Bezdeka
Quoted 91 lines · Jan Kiszka
Quoted 8 lines · linz
Quoted 7 lines

Hi,  all
I think the following patch can resolve the bug,  it allows oob threads to safely preempt kernel_neon_begin() / kernel_neon_end sections.
https://source.denx.de/Xenomai/linux-dovetail/-/commit/9b19700e623f96222c69ecb2adecb1a3e3664cc0

But this patch has been merged into the Linux kernel version 6.8. At present, I have no plan to upgrade to version 6.8. I'm not sure if I understand correctly, but if so, is there a plan to backport this patch to a lower version, such as 5.10?

Quoted 6 lines

Have you tried to backport it to your kernel already to confirm that it helps?

Unfortunately, it looks like a cleanup to upstream, so we may not get it in via normal LTS. But if it help, picking it into dovetail LTS trees is imaginable.

That patch at least depends on

13150149 ("arm64: fpsimd: run kernel mode NEON with softirqs disabled")

There is more work to be done to have that properly backported, or update to one of the recent LTS versions.

Florian

Quoted 67 lines

Jan

Quoted 56 lines
Quoted 55 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · linz

I think my patch is not suitable after listening to your suggestions. And I don't have any other good solutions.

I think x86 is ok because there is no operation of writing global variables in the critical zone.

kernel_fpu_begin
    =>kernel_fpu_begin_mask
=>preempt_disable // enter the critical zone
        =>WARN_ON_FPU(!irq_fpu_usable()); =>WARN_ON_FPU(this_cpu_read(in_kernel_fpu)); =>flags = hard_cond_local_irq_save(); // leave the critcal zone

But in arm64, there is operation of writing global variables in the critical zone, unfortunernaly.
efi_call_rts
  =>__efi_fpsimd_begin
    =>kernel_neon_begin
      =>get_cpu_fpsimd_context
=>hard_preempt_disable // disable interrupt, enter the critical zone =>__get_cpu_fpsimd_context //  first call, modify global variable fpsimd_context_busy
=>hard_cond_local_irq_restore // enable interrupt, leave the critcal zone

handle_arch_irq_pipelined // Latency timer interrupt triggered =>handle_irq_pipelined_finish
  =>irq_exit_pipeline
    =>xnsched_run
      =>__xnsched_run
        =>pipeline_schedule
          =>run_oob_call
            =>___xnsched_run
              =>pipeline_switch_to =>dovetail_context_switch =>__switch_to =>fpsimd_thread_switch =>__get_cpu_fpsimd_context // second call

Quoted 7 lines
Quoted 3 lines

So, I think there are more todos on arm64. Do you have any other good suggestions?

Philippe, some input on this issue would be helpful to know what the next step needs to be. It's still unclear to me how fundemental this issue is (false positive warning or real state corruption?).

This is a current limitation on arm64 which amounts to a bug actually. x86 has the proper implementation, which allows oob threads to safely preempt kernel_fpu_begin() / kernel_fpu_end sections.  Since kernel_neon_begin() re-enables hard irqs before leaving, it is creating the opportunity for a mess.

Quoted 5 lines
Quoted 5 lines

The way to fix this is to implement the x86 logic to arm64 when it comes to in-kernel fpu usage.

Signature · 1 line
Philippe.

--
Siemens AG, Foundational Technologies
Linux Expert Center