Skip to content
  • Ulrich Obergfell's avatar
    watchdog: introduce proc_watchdog_common() · ef246a21
    Ulrich Obergfell authored
    
    
    Three of four handlers for the watchdog parameters in /proc/sys/kernel
    essentially have to do the same thing.
    
      if the parameter is being read {
        return the state of the corresponding bit(s) in 'watchdog_enabled'
      } else {
        set/clear the state of the corresponding bit(s) in 'watchdog_enabled'
        update the run state of the lockup detector(s)
      }
    
    Hence, introduce a common function that can be called by those handlers.
    The callers pass a 'bit mask' to this function to indicate which bit(s)
    should be set/cleared in 'watchdog_enabled'.
    
    This function handles an uncommon race with watchdog_nmi_enable() where a
    concurrent update of 'watchdog_enabled' is possible.  We use 'cmpxchg' to
    detect the concurrency.  [This avoids introducing a new spinlock or a
    mutex to synchronize updates of 'watchdog_enabled'.  Using the same lock
    or mutex in watchdog thread context and in system call context needs to be
    considered carefully because it can make the code prone to deadlock
    situations in connection with parking/unparking the watchdog threads.]
    
    Signed-off-by: default avatarUlrich Obergfell <uobergfe@redhat.com>
    Signed-off-by: default avatarDon Zickus <dzickus@redhat.com>
    Cc: Ingo Molnar <mingo@elte.hu>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    ef246a21