Patchwork [PATCH/RFC,v5,4/5] : core: Add dump device to call on oopses and panics

login
register
mail settings
Submitter David Woodhouse
Date Nov. 30, 2009, 10:23 a.m.
Message ID <1259576611.19465.374.camel@macbook.infradead.org>
Download mbox | patch
Permalink /patch/39792/
State New
Headers show

Comments

David Woodhouse - Nov. 30, 2009, 10:23 a.m.
On Mon, 2009-11-30 at 10:51 +0200, Artem Bityutskiy wrote:
> On Mon, 2009-11-30 at 08:46 +0100, Jörn Engel wrote:
> > On Mon, 30 November 2009 09:27:51 +0200, Artem Bityutskiy wrote:
> > > 
> > > To me it looks like 'log_end' is not supposed to wrap. What makes you
> > > think it can? In which cases it can?
> > 
> > It is a 32bit variable.  Would do you expect happens once you reach
> > 0xffffffff and add 1?
> 
> Yes, now I see log_end is an ever increasing variable.
> 
> How about this patch on top of the existing one (untested):

I suspect you should be modelling this more closely on the code in
do_syslog() for case 3. The end is at (log_end & LOG_BUF_MASK), and you
have (logged_chars) to write.

This mean that you won't write messages to the log which were 'cleared'
by 'dmesg -c', but that's acceptable, I think.

Why are you setting s1 to "" in the case where l1 is zero, btw? Can't it
be NULL?
David Woodhouse - Nov. 30, 2009, 10:27 a.m.
On Mon, 2009-11-30 at 10:23 +0000, David Woodhouse wrote:
> +       /* Theoretically, the log could move on after we do this, but
> +          there's not a log we can do about that. The new messages
> +          will overwrite the start of what we dump. */
> +       spin_lock_irqsave(&logbuf_lock, flags);
> +       end = log_end & LOG_BUF_MASK;
> +       chars = logged_chars;
> +       spin_unlock_irqrestore(&logbuf_lock, flags); 

Actually that's not true -- we _could_ hold the logbuf_lock until the
end of the function. Not entirely sure we _want_ to though...

Patch

diff --git a/kernel/printk.c b/kernel/printk.c
index f711b99..d150c57 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1486,26 +1486,33 @@  static const char *kmsg_to_str(enum kmsg_dump_reason reason)
  */
 void kmsg_dump(enum kmsg_dump_reason reason)
 {
-	unsigned long len = ACCESS_ONCE(log_end);
+	unsigned long end;
+	unsigned chars;
 	struct kmsg_dumper *dumper;
 	const char *s1, *s2;
 	unsigned long l1, l2;
 	unsigned long flags;
 
-	s1 = "";
-	l1 = 0;
-	s2 = log_buf;
-	l2 = len;
-
-	/* Have we rotated around the circular buffer? */
-	if (len > log_buf_len) {
-		unsigned long pos = len & LOG_BUF_MASK;
+	/* Theoretically, the log could move on after we do this, but
+	   there's not a log we can do about that. The new messages
+	   will overwrite the start of what we dump. */
+	spin_lock_irqsave(&logbuf_lock, flags);
+	end = log_end & LOG_BUF_MASK;
+	chars = logged_chars;
+	spin_unlock_irqrestore(&logbuf_lock, flags);
 
-		s1 = log_buf + pos;
-		l1 = log_buf_len - pos;
+	if (logged_chars > end) {
+		s1 = log_buf + log_buf_len - logged_chars + end;
+		l1 = logged_chars - end;
 
 		s2 = log_buf;
-		l2 = pos;
+		l2 = end;
+	} else {
+		s1 = "";
+		l1 = 0;
+
+		s2 = log_buf + end - logged_chars;
+		l2 = logged_chars;
 	}
 
 	if (!spin_trylock_irqsave(&dump_list_lock, flags)) {