hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/watchdog.c
....@@ -27,6 +27,12 @@
2727 #include <asm/irq_regs.h>
2828 #include <linux/kvm_para.h>
2929
30
+#include <trace/hooks/softlockup.h>
31
+
32
+#if IS_ENABLED(CONFIG_ROCKCHIP_MINIDUMP)
33
+#include <soc/rockchip/rk_minidump.h>
34
+#endif
35
+
3036 static DEFINE_MUTEX(watchdog_mutex);
3137
3238 #if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HAVE_NMI_WATCHDOG)
....@@ -42,14 +48,16 @@
4248 int __read_mostly nmi_watchdog_user_enabled = NMI_WATCHDOG_DEFAULT;
4349 int __read_mostly soft_watchdog_user_enabled = 1;
4450 int __read_mostly watchdog_thresh = 10;
45
-int __read_mostly nmi_watchdog_available;
46
-
47
-struct cpumask watchdog_allowed_mask __read_mostly;
51
+static int __read_mostly nmi_watchdog_available;
4852
4953 struct cpumask watchdog_cpumask __read_mostly;
5054 unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
5155
5256 #ifdef CONFIG_HARDLOCKUP_DETECTOR
57
+
58
+# ifdef CONFIG_SMP
59
+int __read_mostly sysctl_hardlockup_all_cpu_backtrace;
60
+# endif /* CONFIG_SMP */
5361
5462 ATOMIC_NOTIFIER_HEAD(hardlock_notifier_list);
5563
....@@ -85,16 +93,6 @@
8593 }
8694 __setup("nmi_watchdog=", hardlockup_panic_setup);
8795
88
-# ifdef CONFIG_SMP
89
-int __read_mostly sysctl_hardlockup_all_cpu_backtrace;
90
-
91
-static int __init hardlockup_all_cpu_backtrace_setup(char *str)
92
-{
93
- sysctl_hardlockup_all_cpu_backtrace = !!simple_strtol(str, NULL, 0);
94
- return 1;
95
-}
96
-__setup("hardlockup_all_cpu_backtrace=", hardlockup_all_cpu_backtrace_setup);
97
-# endif /* CONFIG_SMP */
9896 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
9997
10098 #ifdef CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU
....@@ -206,6 +204,12 @@
206204
207205 #define SOFTLOCKUP_RESET ULONG_MAX
208206
207
+#ifdef CONFIG_SMP
208
+int __read_mostly sysctl_softlockup_all_cpu_backtrace;
209
+#endif
210
+
211
+static struct cpumask watchdog_allowed_mask __read_mostly;
212
+
209213 /* Global variables, exported for sysctl */
210214 unsigned int __read_mostly softlockup_panic =
211215 CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE;
....@@ -216,19 +220,9 @@
216220 static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);
217221 static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer);
218222 static DEFINE_PER_CPU(bool, softlockup_touch_sync);
219
-static DEFINE_PER_CPU(bool, soft_watchdog_warn);
220223 static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts);
221
-static DEFINE_PER_CPU(unsigned long, soft_lockup_hrtimer_cnt);
222
-static DEFINE_PER_CPU(struct task_struct *, softlockup_task_ptr_saved);
223224 static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);
224225 static unsigned long soft_lockup_nmi_warn;
225
-
226
-static int __init softlockup_panic_setup(char *str)
227
-{
228
- softlockup_panic = simple_strtoul(str, NULL, 0);
229
- return 1;
230
-}
231
-__setup("softlockup_panic=", softlockup_panic_setup);
232226
233227 static int __init nowatchdog_setup(char *str)
234228 {
....@@ -244,16 +238,12 @@
244238 }
245239 __setup("nosoftlockup", nosoftlockup_setup);
246240
247
-#ifdef CONFIG_SMP
248
-int __read_mostly sysctl_softlockup_all_cpu_backtrace;
249
-
250
-static int __init softlockup_all_cpu_backtrace_setup(char *str)
241
+static int __init watchdog_thresh_setup(char *str)
251242 {
252
- sysctl_softlockup_all_cpu_backtrace = !!simple_strtol(str, NULL, 0);
243
+ get_option(&str, &watchdog_thresh);
253244 return 1;
254245 }
255
-__setup("softlockup_all_cpu_backtrace=", softlockup_all_cpu_backtrace_setup);
256
-#endif
246
+__setup("watchdog_thresh=", watchdog_thresh_setup);
257247
258248 static void __lockup_detector_cleanup(void);
259249
....@@ -293,7 +283,7 @@
293283 }
294284
295285 /* Commands for resetting the watchdog */
296
-static void __touch_watchdog(void)
286
+static void update_touch_ts(void)
297287 {
298288 __this_cpu_write(watchdog_touch_ts, get_timestamp());
299289 }
....@@ -426,7 +416,7 @@
426416 if (per_cpu(hard_watchdog_warn, next_cpu) == true)
427417 return;
428418
429
- atomic_notifier_call_chain(&hardlock_notifier_list, 0, NULL);
419
+ atomic_notifier_call_chain(&hardlock_notifier_list, next_cpu, NULL);
430420
431421 if (hardlockup_panic)
432422 panic("Watchdog detected hard LOCKUP on cpu %u", next_cpu);
....@@ -460,9 +450,7 @@
460450 */
461451 static int softlockup_fn(void *data)
462452 {
463
- __this_cpu_write(soft_lockup_hrtimer_cnt,
464
- __this_cpu_read(hrtimer_interrupts));
465
- __touch_watchdog();
453
+ update_touch_ts();
466454 complete(this_cpu_ptr(&softlockup_completion));
467455
468456 return 0;
....@@ -509,7 +497,7 @@
509497
510498 /* Clear the guest paused flag on watchdog reset */
511499 kvm_check_and_clear_guest_paused();
512
- __touch_watchdog();
500
+ update_touch_ts();
513501 return HRTIMER_RESTART;
514502 }
515503
....@@ -529,39 +517,21 @@
529517 if (kvm_check_and_clear_guest_paused())
530518 return HRTIMER_RESTART;
531519
532
- /* only warn once */
533
- if (__this_cpu_read(soft_watchdog_warn) == true) {
534
- /*
535
- * When multiple processes are causing softlockups the
536
- * softlockup detector only warns on the first one
537
- * because the code relies on a full quiet cycle to
538
- * re-arm. The second process prevents the quiet cycle
539
- * and never gets reported. Use task pointers to detect
540
- * this.
541
- */
542
- if (__this_cpu_read(softlockup_task_ptr_saved) !=
543
- current) {
544
- __this_cpu_write(soft_watchdog_warn, false);
545
- __touch_watchdog();
546
- }
547
- return HRTIMER_RESTART;
520
+ /*
521
+ * Prevent multiple soft-lockup reports if one cpu is already
522
+ * engaged in dumping all cpu back traces.
523
+ */
524
+ if (softlockup_all_cpu_backtrace) {
525
+ if (test_and_set_bit_lock(0, &soft_lockup_nmi_warn))
526
+ return HRTIMER_RESTART;
548527 }
549528
550
- if (softlockup_all_cpu_backtrace) {
551
- /* Prevent multiple soft-lockup reports if one cpu is already
552
- * engaged in dumping cpu back traces
553
- */
554
- if (test_and_set_bit(0, &soft_lockup_nmi_warn)) {
555
- /* Someone else will report us. Let's give up */
556
- __this_cpu_write(soft_watchdog_warn, true);
557
- return HRTIMER_RESTART;
558
- }
559
- }
529
+ /* Start period for the next softlockup warning. */
530
+ update_touch_ts();
560531
561532 pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n",
562533 smp_processor_id(), duration,
563534 current->comm, task_pid_nr(current));
564
- __this_cpu_write(softlockup_task_ptr_saved, current);
565535 print_modules();
566536 print_irqtrace_events(current);
567537 if (regs)
....@@ -570,22 +540,18 @@
570540 dump_stack();
571541
572542 if (softlockup_all_cpu_backtrace) {
573
- /* Avoid generating two back traces for current
574
- * given that one is already made above
575
- */
576543 trigger_allbutself_cpu_backtrace();
577
-
578
- clear_bit(0, &soft_lockup_nmi_warn);
579
- /* Barrier to sync with other cpus */
580
- smp_mb__after_atomic();
544
+ clear_bit_unlock(0, &soft_lockup_nmi_warn);
581545 }
582546
547
+ trace_android_vh_watchdog_timer_softlockup(duration, regs, !!softlockup_panic);
583548 add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK);
549
+#if IS_ENABLED(CONFIG_ROCKCHIP_MINIDUMP)
550
+ rk_minidump_update_cpu_regs(regs);
551
+#endif
584552 if (softlockup_panic)
585553 panic("softlockup: hung tasks");
586
- __this_cpu_write(soft_watchdog_warn, true);
587
- } else
588
- __this_cpu_write(soft_watchdog_warn, false);
554
+ }
589555
590556 return HRTIMER_RESTART;
591557 }
....@@ -607,10 +573,10 @@
607573 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
608574 hrtimer->function = watchdog_timer_fn;
609575 hrtimer_start(hrtimer, ns_to_ktime(sample_period),
610
- HRTIMER_MODE_REL_PINNED);
576
+ HRTIMER_MODE_REL_PINNED_HARD);
611577
612578 /* Initialize timestamp */
613
- __touch_watchdog();
579
+ update_touch_ts();
614580 /* Enable the perf event */
615581 if (watchdog_enabled & NMI_WATCHDOG_ENABLED)
616582 watchdog_nmi_enable(cpu);
....@@ -682,7 +648,7 @@
682648 return 0;
683649 }
684650
685
-static void lockup_detector_reconfigure(void)
651
+static void __lockup_detector_reconfigure(void)
686652 {
687653 cpus_read_lock();
688654 watchdog_nmi_stop();
....@@ -702,11 +668,18 @@
702668 __lockup_detector_cleanup();
703669 }
704670
671
+void lockup_detector_reconfigure(void)
672
+{
673
+ mutex_lock(&watchdog_mutex);
674
+ __lockup_detector_reconfigure();
675
+ mutex_unlock(&watchdog_mutex);
676
+}
677
+
705678 /*
706679 * Create the watchdog thread infrastructure and configure the detector(s).
707680 *
708681 * The threads are not unparked as watchdog_allowed_mask is empty. When
709
- * the threads are sucessfully initialized, take the proper locks and
682
+ * the threads are successfully initialized, take the proper locks and
710683 * unpark the threads in the watchdog_cpumask if the watchdog is enabled.
711684 */
712685 static __init void lockup_detector_setup(void)
....@@ -722,13 +695,13 @@
722695 return;
723696
724697 mutex_lock(&watchdog_mutex);
725
- lockup_detector_reconfigure();
698
+ __lockup_detector_reconfigure();
726699 softlockup_initialized = true;
727700 mutex_unlock(&watchdog_mutex);
728701 }
729702
730703 #else /* CONFIG_SOFTLOCKUP_DETECTOR */
731
-static void lockup_detector_reconfigure(void)
704
+static void __lockup_detector_reconfigure(void)
732705 {
733706 cpus_read_lock();
734707 watchdog_nmi_stop();
....@@ -736,9 +709,13 @@
736709 watchdog_nmi_start();
737710 cpus_read_unlock();
738711 }
712
+void lockup_detector_reconfigure(void)
713
+{
714
+ __lockup_detector_reconfigure();
715
+}
739716 static inline void lockup_detector_setup(void)
740717 {
741
- lockup_detector_reconfigure();
718
+ __lockup_detector_reconfigure();
742719 }
743720 #endif /* !CONFIG_SOFTLOCKUP_DETECTOR */
744721
....@@ -778,7 +755,7 @@
778755 {
779756 /* Remove impossible cpus to keep sysctl output clean. */
780757 cpumask_and(&watchdog_cpumask, &watchdog_cpumask, cpu_possible_mask);
781
- lockup_detector_reconfigure();
758
+ __lockup_detector_reconfigure();
782759 }
783760
784761 /*
....@@ -794,7 +771,7 @@
794771 * proc_soft_watchdog | soft_watchdog_user_enabled | SOFT_WATCHDOG_ENABLED
795772 */
796773 static int proc_watchdog_common(int which, struct ctl_table *table, int write,
797
- void __user *buffer, size_t *lenp, loff_t *ppos)
774
+ void *buffer, size_t *lenp, loff_t *ppos)
798775 {
799776 int err, old, *param = table->data;
800777
....@@ -821,7 +798,7 @@
821798 * /proc/sys/kernel/watchdog
822799 */
823800 int proc_watchdog(struct ctl_table *table, int write,
824
- void __user *buffer, size_t *lenp, loff_t *ppos)
801
+ void *buffer, size_t *lenp, loff_t *ppos)
825802 {
826803 return proc_watchdog_common(NMI_WATCHDOG_ENABLED|SOFT_WATCHDOG_ENABLED,
827804 table, write, buffer, lenp, ppos);
....@@ -831,7 +808,7 @@
831808 * /proc/sys/kernel/nmi_watchdog
832809 */
833810 int proc_nmi_watchdog(struct ctl_table *table, int write,
834
- void __user *buffer, size_t *lenp, loff_t *ppos)
811
+ void *buffer, size_t *lenp, loff_t *ppos)
835812 {
836813 if (!nmi_watchdog_available && write)
837814 return -ENOTSUPP;
....@@ -843,7 +820,7 @@
843820 * /proc/sys/kernel/soft_watchdog
844821 */
845822 int proc_soft_watchdog(struct ctl_table *table, int write,
846
- void __user *buffer, size_t *lenp, loff_t *ppos)
823
+ void *buffer, size_t *lenp, loff_t *ppos)
847824 {
848825 return proc_watchdog_common(SOFT_WATCHDOG_ENABLED,
849826 table, write, buffer, lenp, ppos);
....@@ -853,7 +830,7 @@
853830 * /proc/sys/kernel/watchdog_thresh
854831 */
855832 int proc_watchdog_thresh(struct ctl_table *table, int write,
856
- void __user *buffer, size_t *lenp, loff_t *ppos)
833
+ void *buffer, size_t *lenp, loff_t *ppos)
857834 {
858835 int err, old;
859836
....@@ -876,7 +853,7 @@
876853 * been brought online, if desired.
877854 */
878855 int proc_watchdog_cpumask(struct ctl_table *table, int write,
879
- void __user *buffer, size_t *lenp, loff_t *ppos)
856
+ void *buffer, size_t *lenp, loff_t *ppos)
880857 {
881858 int err;
882859