[haiku-bugs] Re: [Haiku] #17531: KDL (GPE) in syscall entry (thread_hit_debug_event_internal)

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Fri, 18 Mar 2022 19:38:23 -0000

#17531: KDL (GPE) in syscall entry (thread_hit_debug_event_internal)
----------------------------+----------------------------
  Reporter:  waddlesplash   |      Owner:  nobody
      Type:  bug            |     Status:  new
  Priority:  normal         |  Milestone:  Unscheduled
 Component:  System/Kernel  |    Version:  R1/Development
Resolution:                 |   Keywords:
Blocked By:                 |   Blocking:
  Platform:  All            |
----------------------------+----------------------------
Comment (by waddlesplash):

 So! I added some alignment checks:
 {{{
 diff --git a/src/system/kernel/debug/user_debugger.cpp
 b/src/system/kernel/debug/user_debugger.cpp
 index aa1f760759..8d840d382a 100644
 --- a/src/system/kernel/debug/user_debugger.cpp
 +++ b/src/system/kernel/debug/user_debugger.cpp
 @@ -65,6 +65,7 @@ static void schedule_profiling_timer(Thread* thread,
 bigtime_t interval);
  static int32 profiling_event(timer* unused);
  static status_t ensure_debugger_installed();
  static void get_team_debug_info(team_debug_info &teamDebugInfo);
 +extern void alignment_check(void* ptr);


  static inline status_t
 @@ -734,6 +735,7 @@ thread_hit_debug_event_internal(debug_debugger_message
 event,
         // update the thread debug info
         bool destroyThreadInfo = false;
         thread_debug_info threadDebugInfo;
 +       alignment_check(&threadDebugInfo);

         state = disable_interrupts();
         threadDebugInfoLocker.Lock();
 @@ -832,6 +834,7 @@ user_debug_pre_syscall(uint32 syscall, void *args)
  {
         // check whether a debugger is installed
         Thread *thread = thread_get_current_thread();
 +       alignment_check(&thread);
         int32 teamDebugFlags =
 atomic_get(&thread->team->debug_info.flags);
         if (!(teamDebugFlags & B_TEAM_DEBUG_DEBUGGER_INSTALLED))
                 return;
 }}}

 and in another file (as putting this inline just gets optimized out):
 {{{
 void alignment_check(void* ptr)
 {
         if ((intptr_t(ptr) % 16) != 0)
                 panic("BAD ALIGNMENT!");
 }
 }}}

 And indeed:
 {{{
 PANIC: BAD ALIGNMENT!
 Welcome to Kernel Debugging Land...
 Thread 453 "true" running on CPU 0
 stack trace for thread 453 "true"
     kernel stack: 0xffffffff81aba000 to 0xffffffff81abf000
       user stack: 0x00007fee9bacb000 to 0x00007fee9cacb000
 frame                       caller             <image>:function + offset
  0 ffffffff81abe2e0 (+  24) ffffffff80144c3c   <kernel_x86_64>
 arch_debug_call_with_fault_handler + 0x16
  1 ffffffff81abe2f8 (+  80) ffffffff800ae258   <kernel_x86_64>
 debug_call_with_fault_handler + 0x78
  2 ffffffff81abe348 (+  96) ffffffff800af873   <kernel_x86_64>
 kernel_debugger_loop(char const*, char const*, __va_list_
 tag*, int) + 0xf3
  3 ffffffff81abe3a8 (+  80) ffffffff800afc0e   <kernel_x86_64>
 kernel_debugger_internal(char const*, char const*, __va_l
 ist_tag*, int) + 0x6e
  4 ffffffff81abe3f8 (+ 240) ffffffff800aff67   <kernel_x86_64> panic +
 0xb7
  5 ffffffff81abe4e8 (+2224) ffffffff800bdbf8   <kernel_x86_64>
 thread_hit_debug_event_internal[clone .constprop.0] (debu
 g_debugger_message, void const*, int, bool, bool&) + 0x2d8
  6 ffffffff81abed98 (+ 144) ffffffff800bdfde   <kernel_x86_64>
 thread_hit_debug_event(debug_debugger_message, void const
 *, int, bool) + 0x3e
  7 ffffffff81abee28 (+ 192) ffffffff800be4bc   <kernel_x86_64>
 user_debug_pre_syscall + 0xac
  8 ffffffff81abeee8 (+  72) ffffffff8014684a   <kernel_x86_64>
 x86_64_syscall_entry + 0x216
 user iframe at 0xffffffff81abef30 (end = 0xffffffff81abeff8)
  rax 0xc9                  rbx 0x0                   rcx 0x1abfa603224
  rdx 0x7e9ef2b010          rsi 0x5                   rdi 0x224e
  rbp 0x7fee9cacad80         r8 0x0                    r9 0x1
  r10 0x7fee9cacacec        r11 0x246                 r12 0x0
  r13 0x7e9ef2b010          r14 0x7e9ef2b010          r15 0x1abfa80bac0
  rip 0x1abfa603224         rsp 0x7fee9cacad58     rflags 0x246
  vector: 0x63, error code: 0x0
  9 ffffffff81abef30 (+140664926944848) 000001abfa603224
 </boot/system/runtime_loader@0x000001abfa5ee000> <unknown> + 0
 x15224
 10 00007fee9cacad80 (+ 144) 000001abfa5f7be0
 </boot/system/runtime_loader@0x000001abfa5ee000> <unknown> + 0x9be0
 11 00007fee9cacae10 (+  48) 000001abfa5fefe3
 </boot/system/runtime_loader@0x000001abfa5ee000> <unknown> + 0x10fe3
 12 00007fee9cacae40 (+   0) 00007fd3e58d2260   <commpage>
 commpage_thread_exit + 0x00
 kdebug>
 }}}
-- 
Ticket URL: <https://dev.haiku-os.org/ticket/17531#comment:7>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: