Commit 7f3d08b2 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull printk updates from Petr Mladek:

 - Stop synchronizing kernel log buffer readers by logbuf_lock. As a
   result, the access to the buffer is fully lockless now.

   Note that printk() itself still uses locks because it tries to flush
   the messages to the console immediately. Also the per-CPU temporary
   buffers are still there because they prevent infinite recursion and
   serialize backtraces from NMI. All this is going to change in the
   future.

 - kmsg_dump API rework and cleanup as a side effect of the logbuf_lock
   removal.

 - Make bstr_printf() aware that %pf and %pF formats could deference the
   given pointer.

 - Show also page flags by %pGp format.

 - Clarify the documentation for plain pointer printing.

 - Do not show no_hash_pointers warning multiple times.

 - Update Senozhatsky email address.

 - Some clean up.

* tag 'printk-for-5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: (24 commits)
  lib/vsprintf.c: remove leftover 'f' and 'F' cases from bstr_printf()
  printk: clarify the documentation for plain pointer printing
  kernel/printk.c: Fixed mundane typos
  printk: rename vprintk_func to vprintk
  vsprintf: dump full information of page flags in pGp
  mm, slub: don't combine pr_err with INFO
  mm, slub: use pGp to print page flags
  MAINTAINERS: update Senozhatsky email address
  lib/vsprintf: do not show no_hash_pointers message multiple times
  printk: console: remove unnecessary safe buffer usage
  printk: kmsg_dump: remove _nolock() variants
  printk: remove logbuf_lock
  printk: introduce a kmsg_dump iterator
  printk: kmsg_dumper: remove @active field
  printk: add syslog_lock
  printk: use atomic64_t for devkmsg_user.seq
  printk: use seqcount_latch for clear_seq
  printk: introduce CONSOLE_LOG_MAX
  printk: consolidate kmsg_dump_get_buffer/syslog_print_all code
  printk: refactor kmsg_dump_get_buffer()
  ...
parents 916a7596 c8dbea6d
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -79,7 +79,19 @@ Pointers printed without a specifier extension (i.e unadorned %p) are
hashed to prevent leaking information about the kernel memory layout. This
has the added benefit of providing a unique identifier. On 64-bit machines
the first 32 bits are zeroed. The kernel will print ``(ptrval)`` until it
gathers enough entropy. If you *really* want the address see %px below.
gathers enough entropy.

When possible, use specialised modifiers such as %pS or %pB (described below)
to avoid the need of providing an unhashed address that has to be interpreted
post-hoc. If not possible, and the aim of printing the address is to provide
more information for debugging, use %p and boot the kernel with the
``no_hash_pointers`` parameter during debugging, which will print all %p
addresses unmodified. If you *really* always want the unmodified address, see
%px below.

If (and only if) you are printing addresses as a content of a virtual file in
e.g. procfs or sysfs (using e.g. seq_printf(), not printk()) read by a
userspace process, use the %pK modifier described below instead of %p or %px.

Error Pointers
--------------
@@ -139,6 +151,11 @@ For printing kernel pointers which should be hidden from unprivileged
users. The behaviour of %pK depends on the kptr_restrict sysctl - see
Documentation/admin-guide/sysctl/kernel.rst for more details.

This modifier is *only* intended when producing content of a file read by
userspace from e.g. procfs or sysfs, not for dmesg. Please refer to the
section about %p above for discussion about how to manage hashing pointers
in printk().

Unmodified Addresses
--------------------

@@ -153,6 +170,13 @@ equivalent to %lx (or %lu). %px is preferred because it is more uniquely
grep'able. If in the future we need to modify the way the kernel handles
printing pointers we will be better equipped to find the call sites.

Before using %px, consider if using %p is sufficient together with enabling the
``no_hash_pointers`` kernel parameter during debugging sessions (see the %p
description above). One valid scenario for %px might be printing information
immediately before a panic, which prevents any sensitive information to be
exploited anyway, and with %px there would be no need to reproduce the panic
with no_hash_pointers.

Pointer Differences
-------------------

@@ -540,7 +564,7 @@ Flags bitfields such as page flags, gfp_flags

::

	%pGp	referenced|uptodate|lru|active|private
	%pGp	referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff
	%pGg	GFP_USER|GFP_DMA32|GFP_NOWARN
	%pGv	read|exec|mayread|maywrite|mayexec|denywrite

+4 −4
Original line number Diff line number Diff line
@@ -14535,7 +14535,7 @@ F: kernel/sched/psi.c
PRINTK
M:	Petr Mladek <pmladek@suse.com>
M:	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
M:	Sergey Senozhatsky <senozhatsky@chromium.org>
R:	Steven Rostedt <rostedt@goodmis.org>
R:	John Ogness <john.ogness@linutronix.de>
S:	Maintained
@@ -19388,7 +19388,7 @@ F: drivers/net/vrf.c
VSPRINTF
M:	Petr Mladek <pmladek@suse.com>
M:	Steven Rostedt <rostedt@goodmis.org>
M:	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
M:	Sergey Senozhatsky <senozhatsky@chromium.org>
R:	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
R:	Rasmus Villemoes <linux@rasmusvillemoes.dk>
S:	Maintained
@@ -20039,7 +20039,7 @@ F: drivers/staging/media/zoran/
ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER
M:	Minchan Kim <minchan@kernel.org>
M:	Nitin Gupta <ngupta@vflare.org>
R:	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
R:	Sergey Senozhatsky <senozhatsky@chromium.org>
L:	linux-kernel@vger.kernel.org
S:	Maintained
F:	Documentation/admin-guide/blockdev/zram.rst
@@ -20053,7 +20053,7 @@ F: drivers/tty/serial/zs.*
ZSMALLOC COMPRESSED SLAB MEMORY ALLOCATOR
M:	Minchan Kim <minchan@kernel.org>
M:	Nitin Gupta <ngupta@vflare.org>
R:	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
R:	Sergey Senozhatsky <senozhatsky@chromium.org>
L:	linux-mm@kvack.org
S:	Maintained
F:	Documentation/vm/zsmalloc.rst
+5 −3
Original line number Diff line number Diff line
@@ -647,6 +647,7 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
{
	struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf;
	static unsigned int oops_count = 0;
	static struct kmsg_dump_iter iter;
	static bool panicking = false;
	static DEFINE_SPINLOCK(lock);
	unsigned long flags;
@@ -681,13 +682,14 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
		return;

	if (big_oops_buf) {
		kmsg_dump_get_buffer(dumper, false,
		kmsg_dump_rewind(&iter);
		kmsg_dump_get_buffer(&iter, false,
				     big_oops_buf, big_oops_buf_sz, &text_len);
		rc = zip_oops(text_len);
	}
	if (rc != 0) {
		kmsg_dump_rewind(dumper);
		kmsg_dump_get_buffer(dumper, false,
		kmsg_dump_rewind(&iter);
		kmsg_dump_get_buffer(&iter, false,
				     oops_data, oops_data_sz, &text_len);
		err_type = ERR_TYPE_KERNEL_PANIC;
		oops_hdr->version = cpu_to_be16(OOPS_HDR_VERSION);
+3 −3
Original line number Diff line number Diff line
@@ -3001,7 +3001,7 @@ print_address(unsigned long addr)
static void
dump_log_buf(void)
{
	struct kmsg_dumper dumper = { .active = 1 };
	struct kmsg_dump_iter iter;
	unsigned char buf[128];
	size_t len;

@@ -3013,9 +3013,9 @@ dump_log_buf(void)
	catch_memory_errors = 1;
	sync();

	kmsg_dump_rewind_nolock(&dumper);
	kmsg_dump_rewind(&iter);
	xmon_start_pagination();
	while (kmsg_dump_get_line_nolock(&dumper, false, buf, sizeof(buf), &len)) {
	while (kmsg_dump_get_line(&iter, false, buf, sizeof(buf), &len)) {
		buf[len] = '\0';
		printf("%s", buf);
	}
+12 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
#include <linux/kmsg_dump.h>
#include <linux/spinlock.h>
#include <linux/console.h>
#include <linux/string.h>
#include <shared/init.h>
@@ -9,8 +10,11 @@
static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
				enum kmsg_dump_reason reason)
{
	static struct kmsg_dump_iter iter;
	static DEFINE_SPINLOCK(lock);
	static char line[1024];
	struct console *con;
	unsigned long flags;
	size_t len = 0;

	/* only dump kmsg when no console is available */
@@ -29,11 +33,18 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
	if (con)
		return;

	if (!spin_trylock_irqsave(&lock, flags))
		return;

	kmsg_dump_rewind(&iter);

	printf("kmsg_dump:\n");
	while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {
	while (kmsg_dump_get_line(&iter, true, line, sizeof(line), &len)) {
		line[len] = '\0';
		printf("%s", line);
	}

	spin_unlock_irqrestore(&lock, flags);
}

static struct kmsg_dumper kmsg_dumper = {
Loading