[haiku-commits] haiku: hrev52724 - src/system/kernel headers/private/kernel/arch/x86

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 7 Jan 2019 23:17:45 -0500 (EST)

hrev52724 adds 3 changesets to branch 'master'
old head: a84bb93b448bc7529066dbd040cbe788cfa4bbb7
new head: 7ea987c1b81c03ea16e5eedeb24f7ea0796ef44f
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=7ea987c1b81c+%5Ea84bb93b448b

----------------------------------------------------------------------------

1c1efa6f2f17: kernel/x86: Use volatile in restore_interrupts.
  
  We already use it in enable_interrupts, so we might as well
  use it here too.

2e33d79d38f6: kernel: Panic on attempting to release a semaphore with 
interrupts disabled...
  
  ... and B_DO_NOT_RESCHEDULE unset. We already have equivalent panics
  for mutexes and condition variables, so it seems to make sense to
  check for this too.
  
  There have been some bug reports recently about hard deadlocks with
  symptoms (i.e. kernel debugger can't even be summoned) that match
  "interrupt handler thread was context-switched while holding interrupt
  lock," and this is the only major remaining path to that without
  such a check.
  
  This would have also helped me with recent FreeBSD driver porting;
  I forgot to pass the flag once and deadlocked my system in precisely
  this manner.

7ea987c1b81c: kernel: Improvements to "resume" KDL command.
  
   * Print a message when not resuming a thread because it is running.
     When I was using this command while working on ipro1000, I assumed
     that "no news was good news." But it seems that wasn't the case.
     Hopefully future developers will be less confused after this.
   * Allow resuming threads that are in "asleep" or "waiting" states,
     not just in "suspended" state. Presumably a developer poking around
     in KDL knows what they are doing, so allowing them to do this
     seems to make sense.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 11 insertions(+), 3 deletions(-)
headers/private/kernel/arch/x86/arch_int.h | 2 +-
src/system/kernel/sem.cpp                  | 6 ++++++
src/system/kernel/thread.cpp               | 6 ++++--

############################################################################

Commit:      1c1efa6f2f17abb1ae18e6d0d8ddf24a3606a522
URL:         https://git.haiku-os.org/haiku/commit/?id=1c1efa6f2f17
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Jan  8 03:12:36 2019 UTC

kernel/x86: Use volatile in restore_interrupts.

We already use it in enable_interrupts, so we might as well
use it here too.

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/arch/x86/arch_int.h 
b/headers/private/kernel/arch/x86/arch_int.h
index bfbe401061..5748a1da0a 100644
--- a/headers/private/kernel/arch/x86/arch_int.h
+++ b/headers/private/kernel/arch/x86/arch_int.h
@@ -41,7 +41,7 @@ static inline void
 arch_int_restore_interrupts_inline(int oldState)
 {
        if (oldState)
-               asm("sti");
+               asm volatile("sti");
 }
 
 

############################################################################

Commit:      2e33d79d38f690be1a2da73a8a300f17f9563d3e
URL:         https://git.haiku-os.org/haiku/commit/?id=2e33d79d38f6
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Jan  8 03:13:35 2019 UTC

kernel: Panic on attempting to release a semaphore with interrupts disabled...

... and B_DO_NOT_RESCHEDULE unset. We already have equivalent panics
for mutexes and condition variables, so it seems to make sense to
check for this too.

There have been some bug reports recently about hard deadlocks with
symptoms (i.e. kernel debugger can't even be summoned) that match
"interrupt handler thread was context-switched while holding interrupt
lock," and this is the only major remaining path to that without
such a check.

This would have also helped me with recent FreeBSD driver porting;
I forgot to pass the flag once and deadlocked my system in precisely
this manner.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/sem.cpp b/src/system/kernel/sem.cpp
index b947f2080e..3bc5a84878 100644
--- a/src/system/kernel/sem.cpp
+++ b/src/system/kernel/sem.cpp
@@ -925,6 +925,12 @@ release_sem_etc(sem_id id, int32 count, uint32 flags)
                return B_BAD_SEM_ID;
        if (count <= 0 && (flags & B_RELEASE_ALL) == 0)
                return B_BAD_VALUE;
+#if KDEBUG
+       if ((flags & B_DO_NOT_RESCHEDULE) == 0 && !are_interrupts_enabled()) {
+               panic("release_sem_etc(): called with interrupts disabled and "
+                       "rescheduling allowed for sem_id %ld", id);
+       }
+#endif
 
        InterruptsLocker _;
        SpinLocker semLocker(sSems[slot].lock);

############################################################################

Revision:    hrev52724
Commit:      7ea987c1b81c03ea16e5eedeb24f7ea0796ef44f
URL:         https://git.haiku-os.org/haiku/commit/?id=7ea987c1b81c
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Jan  8 04:14:41 2019 UTC

kernel: Improvements to "resume" KDL command.

 * Print a message when not resuming a thread because it is running.
   When I was using this command while working on ipro1000, I assumed
   that "no news was good news." But it seems that wasn't the case.
   Hopefully future developers will be less confused after this.
 * Allow resuming threads that are in "asleep" or "waiting" states,
   not just in "suspended" state. Presumably a developer poking around
   in KDL knows what they are doing, so allowing them to do this
   seems to make sense.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp
index 641c6519f9..470f4d71e4 100644
--- a/src/system/kernel/thread.cpp
+++ b/src/system/kernel/thread.cpp
@@ -1551,10 +1551,12 @@ make_thread_resumed(int argc, char **argv)
                if (thread->id != id)
                        continue;
 
-               if (thread->state == B_THREAD_SUSPENDED) {
+               if (thread->state == B_THREAD_SUSPENDED || thread->state == 
B_THREAD_ASLEEP
+                               || thread->state == B_THREAD_WAITING) {
                        scheduler_enqueue_in_run_queue(thread);
                        kprintf("thread %" B_PRId32 " resumed\n", thread->id);
-               }
+               } else
+                       kprintf("thread %" B_PRId32 " is already running\n", 
thread->id);
                found = true;
                break;
        }


Other related posts:

  • » [haiku-commits] haiku: hrev52724 - src/system/kernel headers/private/kernel/arch/x86 - waddlesplash