mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* klogd dies, possible emit_log_char() vs do_syslog(..READ..) race.
@ 2011-07-26  1:08 Peter Chubb
  2011-07-26 16:01 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Chubb @ 2011-07-26  1:08 UTC (permalink / raw)
  To: peterz, akpm, torvalds; +Cc: linux-kernel

Hi,

   Since mid May, my klogd has been turning into a 100% CPU hog at
   regular intervals.  Turns out that sometimes reads from /proc/kmsg
   return with zero bytes read --- pointing to a race between
   do_syslog(SYSLOG_ACTION_READ...) and emit_log_char().
   (In Debian, klogd is invoked with a dd frontend, as
      dd if=/proc/kmsg of=/var/run/klogd bs=1
   where /var/run/klogd is a named pipe; this dd dies when it reads
   zero bytes).

   There's history in the  Debian bug tracker,
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=308580 

   I tried an obvious and very ugly band-aid (appended) and the
   problem went away. 

   It seems to me that log_buf_end must be wrapping and be a little
   less than log_buf_start, then when emit_log_char() updates
   log_buf_end it can become equal, causing do_syslog() to return zero
   bytes read.  This'd have to happen between the
   wait_event_interruptible() and the taking of logbuf_lock in
   do_syslog().

   I can't see how this can happen though.  emit_log_char() should
   reset log_start so it can not happen.
   


diff --git a/kernel/printk.c b/kernel/printk.c
index 37dff34..0e44138 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -358,6 +358,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
 			error = -EFAULT;
 			goto out;
 		}
+	again:
 		error = wait_event_interruptible(log_wait,
 							(log_start - log_end));
 		if (error)
@@ -377,6 +378,8 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
 		spin_unlock_irq(&logbuf_lock);
 		if (!error)
 			error = i;
+		if (error == 0)
+			goto again;
 		break;
 	/* Read/clear last kernel messages */
 	case SYSLOG_ACTION_READ_CLEAR:


--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-27  2:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26  1:08 klogd dies, possible emit_log_char() vs do_syslog(..READ..) race Peter Chubb
2011-07-26 16:01 ` Peter Zijlstra
2011-07-27  2:11   ` Peter Chubb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®