Skip to content

Commit d368967

Browse files
committed
Merge tag 'printk-for-6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk fixes from Petr Mladek: - Prevent a potential deadlock when configuring kgdb console - Fix a kernel doc warning * tag 'printk-for-6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: kernel/printk/printk.c: Fix W=1 kernel-doc warning tty: serial: kgdboc: fix mutex locking order for configure_kgdboc()
2 parents a03df4e + 21493c6 commit d368967

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

drivers/tty/serial/kgdboc.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static int configure_kgdboc(void)
171171
int err = -ENODEV;
172172
char *cptr = config;
173173
struct console *cons;
174+
int cookie;
174175

175176
if (!strlen(config) || isspace(config[0])) {
176177
err = 0;
@@ -189,20 +190,9 @@ static int configure_kgdboc(void)
189190
if (kgdboc_register_kbd(&cptr))
190191
goto do_register;
191192

192-
/*
193-
* tty_find_polling_driver() can call uart_set_options()
194-
* (via poll_init) to configure the uart. Take the console_list_lock
195-
* in order to synchronize against register_console(), which can also
196-
* configure the uart via uart_set_options(). This also allows safe
197-
* traversal of the console list.
198-
*/
199-
console_list_lock();
200-
201193
p = tty_find_polling_driver(cptr, &tty_line);
202-
if (!p) {
203-
console_list_unlock();
194+
if (!p)
204195
goto noconfig;
205-
}
206196

207197
/*
208198
* Take console_lock to serialize device() callback with
@@ -211,19 +201,19 @@ static int configure_kgdboc(void)
211201
*/
212202
console_lock();
213203

214-
for_each_console(cons) {
204+
cookie = console_srcu_read_lock();
205+
for_each_console_srcu(cons) {
215206
int idx;
216207
if (cons->device && cons->device(cons, &idx) == p &&
217208
idx == tty_line) {
218209
kgdboc_io_ops.cons = cons;
219210
break;
220211
}
221212
}
213+
console_srcu_read_unlock(cookie);
222214

223215
console_unlock();
224216

225-
console_list_unlock();
226-
227217
kgdb_tty_driver = p;
228218
kgdb_tty_line = tty_line;
229219

drivers/tty/serial/serial_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,9 @@ EXPORT_SYMBOL_GPL(uart_parse_options);
22122212
* @parity: parity character - 'n' (none), 'o' (odd), 'e' (even)
22132213
* @bits: number of data bits
22142214
* @flow: flow control character - 'r' (rts)
2215+
*
2216+
* Locking: Caller must hold console_list_lock in order to serialize
2217+
* early initialization of the serial-console lock.
22152218
*/
22162219
int
22172220
uart_set_options(struct uart_port *port, struct console *co,
@@ -2619,7 +2622,9 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
26192622

26202623
if (!ret && options) {
26212624
uart_parse_options(options, &baud, &parity, &bits, &flow);
2625+
console_list_lock();
26222626
ret = uart_set_options(port, NULL, baud, parity, bits, flow);
2627+
console_list_unlock();
26232628
}
26242629
out:
26252630
mutex_unlock(&tport->mutex);

kernel/printk/printk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool console_srcu_read_lock_is_held(void)
123123
{
124124
return srcu_read_lock_held(&console_srcu);
125125
}
126+
EXPORT_SYMBOL(console_srcu_read_lock_is_held);
126127
#endif
127128

128129
enum devkmsg_log_bits {
@@ -1891,6 +1892,7 @@ static void console_lock_spinning_enable(void)
18911892
/**
18921893
* console_lock_spinning_disable_and_check - mark end of code where another
18931894
* thread was able to busy wait and check if there is a waiter
1895+
* @cookie: cookie returned from console_srcu_read_lock()
18941896
*
18951897
* This is called at the end of the section where spinning is allowed.
18961898
* It has two functions. First, it is a signal that it is no longer

0 commit comments

Comments
 (0)