<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/printk.c, branch v3.8</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v3.8</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v3.8'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2013-01-31T04:46:56Z</updated>
<entry>
<title>Revert "console: implement lockdep support for console_lock"</title>
<updated>2013-01-31T04:46:56Z</updated>
<author>
<name>Dave Airlie</name>
<email>airlied@gmail.com</email>
</author>
<published>2013-01-31T03:27:03Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ff0d05bf73620eb7dc8aee7423e992ef87870bdf'/>
<id>urn:sha1:ff0d05bf73620eb7dc8aee7423e992ef87870bdf</id>
<content type='text'>
This reverts commit daee779718a319ff9f83e1ba3339334ac650bb22.

I'll requeue this after the console locking fixes, so lockdep
is useful again for people until fbcon is fixed.

Signed-off-by: Dave Airlie &lt;airlied@redhat.com&gt;
</content>
</entry>
<entry>
<title>printk: fix incorrect length from print_time() when seconds &gt; 99999</title>
<updated>2013-01-05T00:11:48Z</updated>
<author>
<name>Roland Dreier</name>
<email>roland@purestorage.com</email>
</author>
<published>2013-01-04T23:35:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=35dac27cedd14c3b6fcd4ba7bc3c31738cfd1831'/>
<id>urn:sha1:35dac27cedd14c3b6fcd4ba7bc3c31738cfd1831</id>
<content type='text'>
print_prefix() passes a NULL buf to print_time() to get the length of
the time prefix; when printk times are enabled, the current code just
returns the constant 15, which matches the format "[%5lu.%06lu] " used
to print the time value.  However, this is obviously incorrect when the
whole seconds part of the time gets beyond 5 digits (100000 seconds is a
bit more than a day of uptime).

The simple fix is to use snprintf(NULL, 0, ...) to calculate the actual
length of the time prefix.  This could be micro-optimized but it seems
better to have simpler, more readable code here.

The bug leads to the syslog system call miscomputing which messages fit
into the userspace buffer.  If there are enough messages to fill
log_buf_len and some have a timestamp &gt;= 100000, dmesg may fail with:

    # dmesg
    klogctl: Bad address

When this happens, strace shows that the failure is indeed EFAULT due to
the kernel mistakenly accessing past the end of dmesg's buffer, since
dmesg asks the kernel how big a buffer it needs, allocates a bit more,
and then gets an error when it asks the kernel to fill it:

    syslog(0xa, 0, 0)                       = 1048576
    mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa4d25d2000
    syslog(0x3, 0x7fa4d25d2010, 0x100008)   = -1 EFAULT (Bad address)

As far as I can see, the bug has been there as long as print_time(),
which comes from commit 084681d14e42 ("printk: flush continuation lines
immediately to console") in 3.5-rc5.

Signed-off-by: Roland Dreier &lt;roland@purestorage.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Sylvain Munaut &lt;s.munaut@whatever-company.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>printk: boot_delay should only affect output</title>
<updated>2012-12-18T01:15:13Z</updated>
<author>
<name>Andrew Cooks</name>
<email>acooks@gmail.com</email>
</author>
<published>2012-12-17T23:59:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=2fa72c8fa5d03c4e07894ccb9f0be72e8687a455'/>
<id>urn:sha1:2fa72c8fa5d03c4e07894ccb9f0be72e8687a455</id>
<content type='text'>
The boot_delay parameter affects all printk(), even if the log level
prevents visible output from the call.  It results in delays greater than
the user intended without purpose.

This patch changes the behaviour of boot_delay to only delay output.

Signed-off-by: Andrew Cooks &lt;acooks@gmail.com&gt;
Acked-by: Randy Dunlap &lt;rdunlap@infradead.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>console: use might_sleep in console_lock</title>
<updated>2012-10-24T03:14:55Z</updated>
<author>
<name>Daniel Vetter</name>
<email>daniel.vetter@ffwll.ch</email>
</author>
<published>2012-09-17T23:03:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6b898c07cb1d5bd8344a8044288bb4ae3873da74'/>
<id>urn:sha1:6b898c07cb1d5bd8344a8044288bb4ae3873da74</id>
<content type='text'>
Instead of BUG_ON(in_interrupt()), since that doesn't check for all
the newfangled stuff like preempt.

Note that this is valid since the console_sem is essentially used like
a real mutex with only two twists:
- we allow trylock from hardirq context
- across suspend/resume we lock the logical console_lock, but drop the
  semaphore protecting the locking state.

Now that doesn't guarantee that no one is playing tricks in
single-thread atomic contexts at suspend/resume/boot time, but
- I couldn't find anything suspicious with some grepping,
- might_sleep shouldn't die,
- and I think the upside of catching more potential issues is worth
  the risk of getting a might_sleep backtrace that would have been
  save (and then dealing with that fallout).

Cc: Dave Airlie &lt;airlied@gmail.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Cc: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Daniel Vetter &lt;daniel.vetter@ffwll.ch&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>console: implement lockdep support for console_lock</title>
<updated>2012-10-22T23:12:20Z</updated>
<author>
<name>Daniel Vetter</name>
<email>daniel.vetter@ffwll.ch</email>
</author>
<published>2012-09-22T17:52:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=daee779718a319ff9f83e1ba3339334ac650bb22'/>
<id>urn:sha1:daee779718a319ff9f83e1ba3339334ac650bb22</id>
<content type='text'>
Dave Airlie recently discovered a locking bug in the fbcon layer,
where a timer_del_sync (for the blinking cursor) deadlocks with the
timer itself, since both (want to) hold the console_lock:

https://lkml.org/lkml/2012/8/21/36

Unfortunately the console_lock isn't a plain mutex and hence has no
lockdep support. Which resulted in a few days wasted of tracking down
this bug (complicated by the fact that printk doesn't show anything
when the console is locked) instead of noticing the bug much earlier
with the lockdep splat.

Hence I've figured I need to fix that for the next deadlock involving
console_lock - and with kms/drm growing ever more complex locking
that'll eventually happen.

Now the console_lock has rather funky semantics, so after a quick irc
discussion with Thomas Gleixner and Dave Airlie I've quickly ditched
the original idead of switching to a real mutex (since it won't work)
and instead opted to annotate the console_lock with lockdep
information manually.

There are a few special cases:
- The console_lock state is protected by the console_sem, and usually
  grabbed/dropped at _lock/_unlock time. But the suspend/resume code
  drops the semaphore without dropping the console_lock (see
  suspend_console/resume_console). But since the same thread that did
  the suspend will do the resume, we don't need to fix up anything.

- In the printk code there's a special trylock, only used to kick off
  the logbuffer printk'ing in console_unlock. But all that happens
  while lockdep is disable (since printk does a few other evil
  tricks). So no issue there, either.

- The console_lock can also be acquired form irq context (but only
  with a trylock). lockdep already handles that.

This all leaves us with annotating the normal console_lock, _unlock
and _trylock functions.

And yes, it works - simply unloading a drm kms driver resulted in
lockdep complaining about the deadlock in fbcon_deinit:

======================================================
[ INFO: possible circular locking dependency detected ]
3.6.0-rc2+ #552 Not tainted
-------------------------------------------------------
kms-reload/3577 is trying to acquire lock:
 ((&amp;info-&gt;queue)){+.+...}, at: [&lt;ffffffff81058c70&gt;] wait_on_work+0x0/0xa7

but task is already holding lock:
 (console_lock){+.+.+.}, at: [&lt;ffffffff81264686&gt;] bind_con_driver+0x38/0x263

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-&gt; #1 (console_lock){+.+.+.}:
       [&lt;ffffffff81087440&gt;] lock_acquire+0x95/0x105
       [&lt;ffffffff81040190&gt;] console_lock+0x59/0x5b
       [&lt;ffffffff81209cb6&gt;] fb_flashcursor+0x2e/0x12c
       [&lt;ffffffff81057c3e&gt;] process_one_work+0x1d9/0x3b4
       [&lt;ffffffff810584a2&gt;] worker_thread+0x1a7/0x24b
       [&lt;ffffffff8105ca29&gt;] kthread+0x7f/0x87
       [&lt;ffffffff813b1204&gt;] kernel_thread_helper+0x4/0x10

-&gt; #0 ((&amp;info-&gt;queue)){+.+...}:
       [&lt;ffffffff81086cb3&gt;] __lock_acquire+0x999/0xcf6
       [&lt;ffffffff81087440&gt;] lock_acquire+0x95/0x105
       [&lt;ffffffff81058cab&gt;] wait_on_work+0x3b/0xa7
       [&lt;ffffffff81058dd6&gt;] __cancel_work_timer+0xbf/0x102
       [&lt;ffffffff81058e33&gt;] cancel_work_sync+0xb/0xd
       [&lt;ffffffff8120a3b3&gt;] fbcon_deinit+0x11c/0x1dc
       [&lt;ffffffff81264793&gt;] bind_con_driver+0x145/0x263
       [&lt;ffffffff81264a45&gt;] unbind_con_driver+0x14f/0x195
       [&lt;ffffffff8126540c&gt;] store_bind+0x1ad/0x1c1
       [&lt;ffffffff8127cbb7&gt;] dev_attr_store+0x13/0x1f
       [&lt;ffffffff8116d884&gt;] sysfs_write_file+0xe9/0x121
       [&lt;ffffffff811145b2&gt;] vfs_write+0x9b/0xfd
       [&lt;ffffffff811147b7&gt;] sys_write+0x3e/0x6b
       [&lt;ffffffff813b0039&gt;] system_call_fastpath+0x16/0x1b

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(console_lock);
                               lock((&amp;info-&gt;queue));
                               lock(console_lock);
  lock((&amp;info-&gt;queue));

 *** DEADLOCK ***

v2: Mark the lockdep_map static, noticed by Jani Nikula.

Cc: Dave Airlie &lt;airlied@gmail.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Cc: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Daniel Vetter &lt;daniel.vetter@ffwll.ch&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>printk: Fix scheduling-while-atomic problem in console_cpu_notify()</title>
<updated>2012-10-17T01:17:44Z</updated>
<author>
<name>Paul E. McKenney</name>
<email>paulmck@linux.vnet.ibm.com</email>
</author>
<published>2012-10-16T04:35:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=85eae82a0855d49852b87deac8653e4ebc8b291f'/>
<id>urn:sha1:85eae82a0855d49852b87deac8653e4ebc8b291f</id>
<content type='text'>
The console_cpu_notify() function runs with interrupts disabled in the
CPU_DYING case.  It therefore cannot block, for example, as will happen
when it calls console_lock().  Therefore, remove the CPU_DYING leg of
the switch statement to avoid this problem.

Signed-off-by: Paul E. McKenney &lt;paulmck@linux.vnet.ibm.com&gt;
Reviewed-by: Srivatsa S. Bhat &lt;srivatsa.bhat@linux.vnet.ibm.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>printk: Fix calculation of length used to discard records</title>
<updated>2012-08-12T18:25:50Z</updated>
<author>
<name>Jeff Mahoney</name>
<email>jeffm@suse.com</email>
</author>
<published>2012-08-10T19:07:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e3756477aec028427fec767957c0d4b6cfb87208'/>
<id>urn:sha1:e3756477aec028427fec767957c0d4b6cfb87208</id>
<content type='text'>
While tracking down a weird buffer overflow issue in a program that
looked to be sane, I started double checking the length returned by
syslog(SYSLOG_ACTION_READ_ALL, ...) to make sure it wasn't overflowing
the buffer.

Sure enough, it was.  I saw this in strace:

  11339 syslog(SYSLOG_ACTION_READ_ALL, "&lt;5&gt;[244017.708129] REISERFS (dev"..., 8192) = 8279

It turns out that the loops that calculate how much space the entries
will take when they're copied don't include the newlines and prefixes
that will be included in the final output since prev flags is passed as
zero.

This patch properly accounts for it and fixes the overflow.

CC: stable@kernel.org
Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>printk: only look for prefix levels in kernel messages</title>
<updated>2012-07-31T00:25:14Z</updated>
<author>
<name>Joe Perches</name>
<email>joe@perches.com</email>
</author>
<published>2012-07-30T21:40:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=088a52aac810655c1db1e40331e4936946701e9c'/>
<id>urn:sha1:088a52aac810655c1db1e40331e4936946701e9c</id>
<content type='text'>
vprintk_emit() prefix parsing should only be done for internal kernel
messages.  This allows existing behavior to be kept in all cases.

Signed-off-by: Joe Perches &lt;joe@perches.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>printk: add generic functions to find KERN_&lt;LEVEL&gt; headers</title>
<updated>2012-07-31T00:25:13Z</updated>
<author>
<name>Joe Perches</name>
<email>joe@perches.com</email>
</author>
<published>2012-07-30T21:40:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=acc8fa41ad31c576cdbc569cc3e0e443b1b98b44'/>
<id>urn:sha1:acc8fa41ad31c576cdbc569cc3e0e443b1b98b44</id>
<content type='text'>
The current form of a KERN_&lt;LEVEL&gt; is "&lt;.&gt;".

Add printk_get_level and printk_skip_level functions to handle these
formats.

These functions centralize tests of KERN_&lt;LEVEL&gt; so a future modification
can change the KERN_&lt;LEVEL&gt; style and shorten the number of bytes consumed
by these headers.

[akpm@linux-foundation.org: fix build error and warning]
Signed-off-by: Joe Perches &lt;joe@perches.com&gt;
Cc: Kay Sievers &lt;kay.sievers@vrfy.org&gt;
Cc: Wu Fengguang &lt;wfg@linux.intel.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>kmsg: /dev/kmsg - properly return possible copy_from_user() failure</title>
<updated>2012-07-31T00:25:13Z</updated>
<author>
<name>Kay Sievers</name>
<email>kay@vrfy.org</email>
</author>
<published>2012-07-30T21:40:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cdf53441368cc02ee4aa8a8343a5dc25132836f0'/>
<id>urn:sha1:cdf53441368cc02ee4aa8a8343a5dc25132836f0</id>
<content type='text'>
Reported-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Kay Sievers &lt;kay@vrfy.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
