watchdog: avoid races in watchdog_nmi_{en|disable} functions - follow up patches
Subsystems (2)
cover watchdog: avoid races in watchdog_nmi_{en|disable} functions - follow up patches
This small series follows up to patch discussion related to $subject patch series which is now in linux-next at:
- introduce watchdog_park_threads() and watchdog_unpark_threads()
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/kernel/watchdog.c?id=89f536017155c7f76c8a620e6aed03809e53cd4c
- introduce watchdog_suspend() and watchdog_resume()
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/kernel/watchdog.c?id=e0dd9ee3ecf3394e93343cf9542d8ca1b54eca08
- use park/unpark functions in update_watchdog_all_cpus()
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/kernel/watchdog.c?id=eef1a759acfb98766fef20afca9e06f014299e3f
- use suspend/resume interface in fixup_ht_bug()
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/kernel/watchdog.c?id=77592a82363dd508ce3dbe4eaaa2c6c45b966ebb
Changes based on patch discussion:
- Patch 1/2: rename watchdog_{suspend|resume}, add comment blocks
http://marc.info/?l=linux-kernel&m=143844050610220&w=2
http://marc.info/?l=linux-kernel&m=143876224114821&w=2
- Patch 2/2: use pr_debug() instead of pr_info()
http://marc.info/?l=linux-kernel&m=143869949229461&w=2
Ulrich Obergfell (2):
watchdog: rename watchdog_suspend() and watchdog_resume()
watchdog: use pr_debug() in fixup_ht_bug() failure path
arch/x86/kernel/cpu/perf_event_intel.c | 6 +++--- include/linux/nmi.h | 8 ++++---- kernel/watchdog.c | 26 ++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/2 watchdog: rename watchdog_suspend() and watchdog_resume()
Rename watchdog_suspend() to lockup_detector_suspend() and watchdog_resume() to lockup_detector_resume() to avoid confusion with the watchdog subsystem and to be consistent with the existing name lockup_detector_init().
Also provide comment blocks to explain the watchdog_running and watchdog_suspended variables and their relationship.
--- arch/x86/kernel/cpu/perf_event_intel.c | 4 ++-- include/linux/nmi.h | 8 ++++---- kernel/watchdog.c | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +2 -2
@@ -3368,7 +3368,7 @@ static __init int fixup_ht_bug(void)return 0 ; } -if (watchdog_suspend () !=0 ) { +if (lockup_detector_suspend () !=0 ) {pr_info ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" );return 0 ; }
@@ -3379,7 +3379,7 @@ static __init int fixup_ht_bug(void) x86_pmu.commit_scheduling =NULL ; x86_pmu.stop_scheduling =NULL ; -watchdog_resume (); +lockup_detector_resume ();get_online_cpus ();
include/linux/nmi.h +4 -4
@@ -84,15 +84,15 @@ extern int proc_watchdog_thresh(struct ctl_table *, int , void __user *, size_t *, loff_t *);extern int proc_watchdog_cpumask (struct ctl_table *,int ,void __user *,size_t *,loff_t *); -extern int watchdog_suspend (void ); -extern void watchdog_resume (void ); +extern int lockup_detector_suspend (void ); +extern void lockup_detector_resume (void );#else -static inline int watchdog_suspend (void ) +static inline int lockup_detector_suspend (void ) {return 0 ; } -static inline void watchdog_resume (void ) +static inline void lockup_detector_resume (void ) { }#endif
kernel/watchdog.c +22 -4
@@ -67,8 +67,26 @@ unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);#define for_each_watchdog_cpu (cpu) \ for_each_cpu_and((cpu), cpu_online_mask, &watchdog_cpumask) -static int __read_mostly watchdog_suspended; +/* +* The 'watchdog_running' variable is set to 1 when the watchdog threads +* are registered/started and is set to 0 when the watchdog threads are +* unregistered/stopped, so it is an indicator whether the threads exist. +*/ static int __read_mostly watchdog_running; +/* +* If a subsystem has a need to deactivate the watchdog temporarily, it +* can use the suspend/resume interface to achieve this. The content of +* the 'watchdog_suspended' variable reflects this state. Existing threads +* are parked/unparked by the lockup_detector_{suspend|resume} functions +* (see comment blocks pertaining to those functions for further details). +* +* 'watchdog_suspended' also prevents threads from being registered/started +* or unregistered/stopped via parameters in /proc/sys/kernel, so the state +* of 'watchdog_running' cannot change while the watchdog is deactivated +* temporarily (see related code in 'proc' handlers). +*/ +static int __read_mostly watchdog_suspended; +static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);
@@ -669,7 +687,7 @@ static void watchdog_unpark_threads(void)/* * Suspend the hard and soft lockup detector by parking the watchdog threads. */ -int watchdog_suspend (void ) +int lockup_detector_suspend (void ) {int ret =0 ;
@@ -679,7 +697,7 @@ int watchdog_suspend(void)* the 'watchdog_suspended' variable). If the watchdog threads are * running, the first caller takes care that they will be parked. * The state of 'watchdog_running' cannot change while a suspend -* request is active (see related changes in 'proc' handlers). +* request is active (see related code in 'proc' handlers). */ if (watchdog_running && !watchdog_suspended) ret =watchdog_park_threads ();
@@ -695,7 +713,7 @@ int watchdog_suspend(void)/* * Resume the hard and soft lockup detector by unparking the watchdog threads. */ -void watchdog_resume (void ) +void lockup_detector_resume (void ) {mutex_lock (&watchdog_proc_mutex);
Signature · 1 line
1.7.11.7
Re: [PATCH 1/2] watchdog: rename watchdog_suspend() and watchdog_resume()
Quoted 112 lines · Ulrich Obergfell
Rename
watchdog_suspend()tolockup_detector_suspend()andwatchdog_resume()tolockup_detector_resume()to avoid confusion with the watchdog subsystem and to be consistent with the existing namelockup_detector_init().Also provide comment blocks to explain the
watchdog_runningandwatchdog_suspendedvariables and their relationship.Signed-off-by Ulrich Obergfell <[email protected]>--- arch/x86/kernel/cpu/perf_event_intel.c | 4 ++-- include/linux/nmi.h | 8 ++++---- kernel/watchdog.c | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 10 deletions(-)arch/x86/kernel/cpu/perf_event_intel.c +2
-2@@ -3368,7 +3368,7 @@ static __init int fixup_ht_bug(void)return 0 ; } -if (watchdog_suspend () !=0 ) { +if (lockup_detector_suspend () !=0 ) {pr_info ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" );return 0 ; }@@ -3379,7 +3379,7 @@ static __init int fixup_ht_bug(void) x86_pmu.commit_scheduling =NULL ; x86_pmu.stop_scheduling =NULL ; -watchdog_resume (); +lockup_detector_resume ();get_online_cpus ();include/linux/nmi.h +4
-4@@ -84,15 +84,15 @@ extern int proc_watchdog_thresh(struct ctl_table *, int , void __user *, size_t *, loff_t *);extern int proc_watchdog_cpumask (struct ctl_table *,int ,void __user *,size_t *,loff_t *); -extern int watchdog_suspend (void ); -extern void watchdog_resume (void ); +extern int lockup_detector_suspend (void ); +extern void lockup_detector_resume (void );#else -static inline int watchdog_suspend (void ) +static inline int lockup_detector_suspend (void ) {return 0 ; } -static inline void watchdog_resume (void ) +static inline void lockup_detector_resume (void ) { }#endif kernel/watchdog.c +21
-3@@ -67,8 +67,26 @@ unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);#define for_each_watchdog_cpu (cpu) \ for_each_cpu_and((cpu), cpu_online_mask, &watchdog_cpumask) -static int __read_mostly watchdog_suspended; +/* +* The 'watchdog_running' variable is set to 1 when the watchdog threads +* are registered/started and is set to 0 when the watchdog threads are +* unregistered/stopped, so it is an indicator whether the threads exist. +*/ static int __read_mostly watchdog_running; +/* +* If a subsystem has a need to deactivate the watchdog temporarily, it +* can use the suspend/resume interface to achieve this. The content of +* the 'watchdog_suspended' variable reflects this state. Existing threads +* are parked/unparked by the lockup_detector_{suspend|resume} functions +* (see comment blocks pertaining to those functions for further details). +* +* 'watchdog_suspended' also prevents threads from being registered/started +* or unregistered/stopped via parameters in /proc/sys/kernel, so the state +* of 'watchdog_running' cannot change while the watchdog is deactivated +* temporarily (see related code in 'proc' handlers). +*/ +static int __read_mostly watchdog_suspended; +static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);@@ -669,7 +687,7 @@ static void watchdog_unpark_threads(void)/* * Suspend the hard and soft lockup detector by parking the watchdog threads. */ -int watchdog_suspend (void ) +int lockup_detector_suspend (void ) {int ret =0 ;@@ -679,7 +697,7 @@ int watchdog_suspend(void)* the 'watchdog_suspended' variable). If the watchdog threads are * running, the first caller takes care that they will be parked. * The state of 'watchdog_running' cannot change while a suspend -* request is active (see related changes in 'proc' handlers). +* request is active (see related code in 'proc' handlers). */ if (watchdog_running && !watchdog_suspended) ret =watchdog_park_threads ();
kernel/watchdog.c int watchdog_suspend(void) · line 719
Quoted 8 lines
kernel/watchdog.c +1
-1@@ -695,7 +713,7 @@ int watchdog_suspend(void)/* * Resume the hard and soft lockup detector by unparking the watchdog threads. */ -void watchdog_resume (void ) +void lockup_detector_resume (void ) {mutex_lock (&watchdog_proc_mutex);
Signature · 1 line
Aaron Tomlin
PATCH 2/2 watchdog: use pr_debug() in fixup_ht_bug() failure path
In reply to Ulrich Obergfell--- arch/x86/kernel/cpu/perf_event_intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_intel.c +1 -1
@@ -3369,7 +3369,7 @@ static __init int fixup_ht_bug(void) }if (lockup_detector_suspend () !=0 ) { -pr_info ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" ); +pr_debug ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" );return 0 ; }
Signature · 1 line
1.7.11.7
Re: [PATCH 2/2] watchdog: use pr_debug() in fixup_ht_bug() failure path
Quoted 11 lines · Ulrich Obergfell
Signed-off-by Ulrich Obergfell <[email protected]>--- arch/x86/kernel/cpu/perf_event_intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/perf_event_intel.c +0
-0
arch/x86/kernel/cpu/perf_event_intel.c static __init int fixup_ht_bug(void) · line 3375
Quoted 8 lines
arch/x86/kernel/cpu/perf_event_intel.c +1
-1@@ -3369,7 +3369,7 @@ static __init int fixup_ht_bug(void) }if (lockup_detector_suspend () !=0 ) { -pr_info ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" ); +pr_debug ("failed to disable PMU erratum BJ122, BV98, HSD29 workaround\n" );return 0 ; }
Signature · 1 line
Aaron Tomlin