aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2008-08-08 15:47:09 -0400
committerIngo Molnar <mingo@elte.hu>2008-08-11 07:46:53 -0400
commitb845b517b5e3706a3729f6ea83b88ab85f0725b0 (patch)
tree4311e4c2e6c3fdbdbe89149d1501944294186455
parent796aadeb1b2db9b5d463946766c5bbfd7717158c (diff)
printk: robustify printk
Avoid deadlocks against rq->lock and xtime_lock by deferring the klogd wakeup by polling from the timer tick. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--include/linux/kernel.h4
-rw-r--r--kernel/printk.c19
-rw-r--r--kernel/time/tick-sched.c2
-rw-r--r--kernel/timer.c1
4 files changed, 23 insertions, 3 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index aaa998f65c7a..113ac8d0425f 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -200,6 +200,8 @@ extern struct ratelimit_state printk_ratelimit_state;
200extern int printk_ratelimit(void); 200extern int printk_ratelimit(void);
201extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 201extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
202 unsigned int interval_msec); 202 unsigned int interval_msec);
203extern void printk_tick(void);
204extern int printk_needs_cpu(int);
203#else 205#else
204static inline int vprintk(const char *s, va_list args) 206static inline int vprintk(const char *s, va_list args)
205 __attribute__ ((format (printf, 1, 0))); 207 __attribute__ ((format (printf, 1, 0)));
@@ -211,6 +213,8 @@ static inline int printk_ratelimit(void) { return 0; }
211static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 213static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
212 unsigned int interval_msec) \ 214 unsigned int interval_msec) \
213 { return false; } 215 { return false; }
216static inline void printk_tick(void) { }
217static inline int printk_needs_cpu(int) { return 0; }
214#endif 218#endif
215 219
216extern void asmlinkage __attribute__((format(printf, 1, 2))) 220extern void asmlinkage __attribute__((format(printf, 1, 2)))
diff --git a/kernel/printk.c b/kernel/printk.c
index b51b1567bb55..655cc2ca10cc 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -982,10 +982,25 @@ int is_console_locked(void)
982 return console_locked; 982 return console_locked;
983} 983}
984 984
985void wake_up_klogd(void) 985static DEFINE_PER_CPU(int, printk_pending);
986
987void printk_tick(void)
986{ 988{
987 if (!oops_in_progress && waitqueue_active(&log_wait)) 989 if (__get_cpu_var(printk_pending)) {
990 __get_cpu_var(printk_pending) = 0;
988 wake_up_interruptible(&log_wait); 991 wake_up_interruptible(&log_wait);
992 }
993}
994
995int printk_needs_cpu(int cpu)
996{
997 return per_cpu(printk_pending, cpu);
998}
999
1000void wake_up_klogd(void)
1001{
1002 if (waitqueue_active(&log_wait))
1003 __get_cpu_var(printk_pending) = 1;
989} 1004}
990 1005
991/** 1006/**
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 825b4c00fe44..c13d4f182370 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -255,7 +255,7 @@ void tick_nohz_stop_sched_tick(int inidle)
255 next_jiffies = get_next_timer_interrupt(last_jiffies); 255 next_jiffies = get_next_timer_interrupt(last_jiffies);
256 delta_jiffies = next_jiffies - last_jiffies; 256 delta_jiffies = next_jiffies - last_jiffies;
257 257
258 if (rcu_needs_cpu(cpu)) 258 if (rcu_needs_cpu(cpu) || printk_needs_cpu(cpu))
259 delta_jiffies = 1; 259 delta_jiffies = 1;
260 /* 260 /*
261 * Do not stop the tick, if we are only one off 261 * Do not stop the tick, if we are only one off
diff --git a/kernel/timer.c b/kernel/timer.c
index 03bc7f1f1593..510fe69351ca 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -978,6 +978,7 @@ void update_process_times(int user_tick)
978 run_local_timers(); 978 run_local_timers();
979 if (rcu_pending(cpu)) 979 if (rcu_pending(cpu))
980 rcu_check_callbacks(cpu, user_tick); 980 rcu_check_callbacks(cpu, user_tick);
981 printk_tick();
981 scheduler_tick(); 982 scheduler_tick();
982 run_posix_cpu_timers(p); 983 run_posix_cpu_timers(p);
983} 984}