Skip to content

Commit d876315

Browse files
committed
Merge tag 'printk-for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk updates from Petr Mladek: - Refactor printk code for formatting messages that are shown on consoles. This is a preparatory step for introducing atomic consoles which could not share the global buffers - Prevent memory leak when removing printk index in debugfs - Dump also the newest printk message by the sample gdbmacro - Fix a compiler warning * tag 'printk-for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: printf: fix errname.c list kernel/printk/index.c: fix memory leak with using debugfs_lookup() printk: Use scnprintf() to print the message about the dropped messages on a console printk: adjust string limit macros printk: use printk_buffers for devkmsg printk: introduce console_prepend_dropped() for dropped messages printk: introduce printk_get_next_message() and printk_message printk: introduce struct printk_buffers console: Document struct console console: Use BIT() macros for @flags values printk: move size limit macros into internal.h docs: gdbmacros: print newest record
2 parents cd43b50 + 392143c commit d876315

File tree

7 files changed

+313
-168
lines changed

7 files changed

+313
-168
lines changed

Documentation/admin-guide/kdump/gdbmacros.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ define dmesg
312312
set var $prev_flags = $info->flags
313313
end
314314

315-
set var $id = ($id + 1) & $id_mask
316315
if ($id == $end_id)
317316
loop_break
318317
end
318+
set var $id = ($id + 1) & $id_mask
319319
end
320320
end
321321
document dmesg

include/linux/console.h

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define _LINUX_CONSOLE_H_ 1
1616

1717
#include <linux/atomic.h>
18+
#include <linux/bits.h>
1819
#include <linux/rculist.h>
1920
#include <linux/types.h>
2021

@@ -125,37 +126,82 @@ static inline int con_debug_leave(void)
125126
/*
126127
* The interface for a console, or any other device that wants to capture
127128
* console messages (printer driver?)
128-
*
129-
* If a console driver is marked CON_BOOT then it will be auto-unregistered
130-
* when the first real console is registered. This is for early-printk drivers.
131129
*/
132130

133-
#define CON_PRINTBUFFER (1)
134-
#define CON_CONSDEV (2) /* Preferred console, /dev/console */
135-
#define CON_ENABLED (4)
136-
#define CON_BOOT (8)
137-
#define CON_ANYTIME (16) /* Safe to call when cpu is offline */
138-
#define CON_BRL (32) /* Used for a braille device */
139-
#define CON_EXTENDED (64) /* Use the extended output format a la /dev/kmsg */
131+
/**
132+
* cons_flags - General console flags
133+
* @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate
134+
* output of messages that were already shown by boot
135+
* consoles or read by userspace via syslog() syscall.
136+
* @CON_CONSDEV: Indicates that the console driver is backing
137+
* /dev/console.
138+
* @CON_ENABLED: Indicates if a console is allowed to print records. If
139+
* false, the console also will not advance to later
140+
* records.
141+
* @CON_BOOT: Marks the console driver as early console driver which
142+
* is used during boot before the real driver becomes
143+
* available. It will be automatically unregistered
144+
* when the real console driver is registered unless
145+
* "keep_bootcon" parameter is used.
146+
* @CON_ANYTIME: A misnomed historical flag which tells the core code
147+
* that the legacy @console::write callback can be invoked
148+
* on a CPU which is marked OFFLINE. That is misleading as
149+
* it suggests that there is no contextual limit for
150+
* invoking the callback. The original motivation was
151+
* readiness of the per-CPU areas.
152+
* @CON_BRL: Indicates a braille device which is exempt from
153+
* receiving the printk spam for obvious reasons.
154+
* @CON_EXTENDED: The console supports the extended output format of
155+
* /dev/kmesg which requires a larger output buffer.
156+
*/
157+
enum cons_flags {
158+
CON_PRINTBUFFER = BIT(0),
159+
CON_CONSDEV = BIT(1),
160+
CON_ENABLED = BIT(2),
161+
CON_BOOT = BIT(3),
162+
CON_ANYTIME = BIT(4),
163+
CON_BRL = BIT(5),
164+
CON_EXTENDED = BIT(6),
165+
};
140166

167+
/**
168+
* struct console - The console descriptor structure
169+
* @name: The name of the console driver
170+
* @write: Write callback to output messages (Optional)
171+
* @read: Read callback for console input (Optional)
172+
* @device: The underlying TTY device driver (Optional)
173+
* @unblank: Callback to unblank the console (Optional)
174+
* @setup: Callback for initializing the console (Optional)
175+
* @exit: Callback for teardown of the console (Optional)
176+
* @match: Callback for matching a console (Optional)
177+
* @flags: Console flags. See enum cons_flags
178+
* @index: Console index, e.g. port number
179+
* @cflag: TTY control mode flags
180+
* @ispeed: TTY input speed
181+
* @ospeed: TTY output speed
182+
* @seq: Sequence number of the next ringbuffer record to print
183+
* @dropped: Number of unreported dropped ringbuffer records
184+
* @data: Driver private data
185+
* @node: hlist node for the console list
186+
*/
141187
struct console {
142-
char name[16];
143-
void (*write)(struct console *, const char *, unsigned);
144-
int (*read)(struct console *, char *, unsigned);
145-
struct tty_driver *(*device)(struct console *, int *);
146-
void (*unblank)(void);
147-
int (*setup)(struct console *, char *);
148-
int (*exit)(struct console *);
149-
int (*match)(struct console *, char *name, int idx, char *options);
150-
short flags;
151-
short index;
152-
int cflag;
153-
uint ispeed;
154-
uint ospeed;
155-
u64 seq;
156-
unsigned long dropped;
157-
void *data;
158-
struct hlist_node node;
188+
char name[16];
189+
void (*write)(struct console *co, const char *s, unsigned int count);
190+
int (*read)(struct console *co, char *s, unsigned int count);
191+
struct tty_driver *(*device)(struct console *co, int *index);
192+
void (*unblank)(void);
193+
int (*setup)(struct console *co, char *options);
194+
int (*exit)(struct console *co);
195+
int (*match)(struct console *co, char *name, int idx, char *options);
196+
short flags;
197+
short index;
198+
int cflag;
199+
uint ispeed;
200+
uint ospeed;
201+
u64 seq;
202+
unsigned long dropped;
203+
void *data;
204+
struct hlist_node node;
159205
};
160206

161207
#ifdef CONFIG_LOCKDEP

include/linux/printk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ static inline const char *printk_skip_headers(const char *buffer)
4444
return buffer;
4545
}
4646

47-
#define CONSOLE_EXT_LOG_MAX 8192
48-
4947
/* printk's without a loglevel use this.. */
5048
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
5149

kernel/printk/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void pi_create_file(struct module *mod)
145145
#ifdef CONFIG_MODULES
146146
static void pi_remove_file(struct module *mod)
147147
{
148-
debugfs_remove(debugfs_lookup(pi_get_module_name(mod), dfs_index));
148+
debugfs_lookup_and_remove(pi_get_module_name(mod), dfs_index);
149149
}
150150

151151
static int pi_module_notify(struct notifier_block *nb, unsigned long op,

kernel/printk/internal.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write,
1414

1515
#ifdef CONFIG_PRINTK
1616

17+
#ifdef CONFIG_PRINTK_CALLER
18+
#define PRINTK_PREFIX_MAX 48
19+
#else
20+
#define PRINTK_PREFIX_MAX 32
21+
#endif
22+
23+
/*
24+
* the maximum size of a formatted record (i.e. with prefix added
25+
* per line and dropped messages or in extended message format)
26+
*/
27+
#define PRINTK_MESSAGE_MAX 2048
28+
29+
/* the maximum size allowed to be reserved for a record */
30+
#define PRINTKRB_RECORD_MAX 1024
31+
1732
/* Flags for a single printk record. */
1833
enum printk_info_flags {
1934
LOG_NEWLINE = 2, /* text ended with a newline */
@@ -48,6 +63,10 @@ u16 printk_parse_prefix(const char *text, int *level,
4863
enum printk_info_flags *flags);
4964
#else
5065

66+
#define PRINTK_PREFIX_MAX 0
67+
#define PRINTK_MESSAGE_MAX 0
68+
#define PRINTKRB_RECORD_MAX 0
69+
5170
/*
5271
* In !PRINTK builds we still export console_sem
5372
* semaphore and some of console functions (console_unlock()/etc.), so
@@ -58,3 +77,29 @@ u16 printk_parse_prefix(const char *text, int *level,
5877

5978
static inline bool printk_percpu_data_ready(void) { return false; }
6079
#endif /* CONFIG_PRINTK */
80+
81+
/**
82+
* struct printk_buffers - Buffers to read/format/output printk messages.
83+
* @outbuf: After formatting, contains text to output.
84+
* @scratchbuf: Used as temporary ringbuffer reading and string-print space.
85+
*/
86+
struct printk_buffers {
87+
char outbuf[PRINTK_MESSAGE_MAX];
88+
char scratchbuf[PRINTKRB_RECORD_MAX];
89+
};
90+
91+
/**
92+
* struct printk_message - Container for a prepared printk message.
93+
* @pbufs: printk buffers used to prepare the message.
94+
* @outbuf_len: The length of prepared text in @pbufs->outbuf to output. This
95+
* does not count the terminator. A value of 0 means there is
96+
* nothing to output and this record should be skipped.
97+
* @seq: The sequence number of the record used for @pbufs->outbuf.
98+
* @dropped: The number of dropped records from reading @seq.
99+
*/
100+
struct printk_message {
101+
struct printk_buffers *pbufs;
102+
unsigned int outbuf_len;
103+
u64 seq;
104+
unsigned long dropped;
105+
};

0 commit comments

Comments
 (0)