Skip to content

Commit 9ea4e04

Browse files
author
CKI KWF Bot
committed
Merge: Update printk to latest v6.12 longterm
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/848 JIRA: https://issues.redhat.com/browse/RHEL-89498 This backport updates the printk (and serial 8250) subsytem in C10s/10.1 to properly reflect what exists in the most recent linux longterm kernels. Additionally, a small patch to make `pr_flush` a public function, permitting the proper flushing of console log buffers on shutdown, has also been pulled in. Signed-off-by: Derek Barbosa <debarbos@redhat.com> Approved-by: Herton R. Krzesinski <herton@redhat.com> Approved-by: Eder Zulian <ezulian@redhat.com> Approved-by: Gabriele Monaco <gmonaco@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents c44bdb2 + 5bcd1bb commit 9ea4e04

File tree

9 files changed

+56
-5
lines changed

9 files changed

+56
-5
lines changed

drivers/tty/serial/8250/8250.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static inline int is_omap1510_8250(struct uart_8250_port *pt)
374374

375375
#ifdef CONFIG_SERIAL_8250_DMA
376376
extern int serial8250_tx_dma(struct uart_8250_port *);
377+
extern void serial8250_tx_dma_flush(struct uart_8250_port *);
377378
extern int serial8250_rx_dma(struct uart_8250_port *);
378379
extern void serial8250_rx_dma_flush(struct uart_8250_port *);
379380
extern int serial8250_request_dma(struct uart_8250_port *);
@@ -406,6 +407,7 @@ static inline int serial8250_tx_dma(struct uart_8250_port *p)
406407
{
407408
return -1;
408409
}
410+
static inline void serial8250_tx_dma_flush(struct uart_8250_port *p) { }
409411
static inline int serial8250_rx_dma(struct uart_8250_port *p)
410412
{
411413
return -1;

drivers/tty/serial/8250/8250_core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,9 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
812812
uart->dl_write = up->dl_write;
813813

814814
if (uart->port.type != PORT_8250_CIR) {
815+
if (uart_console_registered(&uart->port))
816+
pm_runtime_get_sync(uart->port.dev);
817+
815818
if (serial8250_isa_config != NULL)
816819
serial8250_isa_config(0, &uart->port,
817820
&uart->capabilities);

drivers/tty/serial/8250/8250_dma.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ int serial8250_tx_dma(struct uart_8250_port *p)
149149
return ret;
150150
}
151151

152+
void serial8250_tx_dma_flush(struct uart_8250_port *p)
153+
{
154+
struct uart_8250_dma *dma = p->dma;
155+
156+
if (!dma->tx_running)
157+
return;
158+
159+
/*
160+
* kfifo_reset() has been called by the serial core, avoid
161+
* advancing and underflowing in __dma_tx_complete().
162+
*/
163+
dma->tx_size = 0;
164+
165+
dmaengine_terminate_async(dma->txchan);
166+
}
167+
152168
int serial8250_rx_dma(struct uart_8250_port *p)
153169
{
154170
struct uart_8250_dma *dma = p->dma;

drivers/tty/serial/8250/8250_port.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,14 @@ static void serial8250_shutdown(struct uart_port *port)
25232523
serial8250_do_shutdown(port);
25242524
}
25252525

2526+
static void serial8250_flush_buffer(struct uart_port *port)
2527+
{
2528+
struct uart_8250_port *up = up_to_u8250p(port);
2529+
2530+
if (up->dma)
2531+
serial8250_tx_dma_flush(up);
2532+
}
2533+
25262534
static unsigned int serial8250_do_get_divisor(struct uart_port *port,
25272535
unsigned int baud,
25282536
unsigned int *frac)
@@ -3206,6 +3214,7 @@ static const struct uart_ops serial8250_pops = {
32063214
.break_ctl = serial8250_break_ctl,
32073215
.startup = serial8250_startup,
32083216
.shutdown = serial8250_shutdown,
3217+
.flush_buffer = serial8250_flush_buffer,
32093218
.set_termios = serial8250_set_termios,
32103219
.set_ldisc = serial8250_set_ldisc,
32113220
.pm = serial8250_pm,

include/linux/printk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void printk_legacy_allow_panic_sync(void);
204204
extern bool nbcon_device_try_acquire(struct console *con);
205205
extern void nbcon_device_release(struct console *con);
206206
void nbcon_atomic_flush_unsafe(void);
207+
bool pr_flush(int timeout_ms, bool reset_on_progress);
207208
#else
208209
static inline __printf(1, 0)
209210
int vprintk(const char *s, va_list args)
@@ -304,6 +305,11 @@ static inline void nbcon_atomic_flush_unsafe(void)
304305
{
305306
}
306307

308+
static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
309+
{
310+
return true;
311+
}
312+
307313
#endif
308314

309315
bool this_cpu_in_panic(void);

kernel/printk/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,9 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
335335
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped);
336336
void console_prepend_replay(struct printk_message *pmsg);
337337
#endif
338+
339+
#ifdef CONFIG_SMP
340+
bool is_printk_cpu_sync_owner(void);
341+
#else
342+
static inline bool is_printk_cpu_sync_owner(void) { return false; }
343+
#endif

kernel/printk/printk.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static struct latched_seq clear_seq = {
523523
/* record buffer */
524524
#define LOG_ALIGN __alignof__(unsigned long)
525525
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
526-
#define LOG_BUF_LEN_MAX (u32)(1 << 31)
526+
#define LOG_BUF_LEN_MAX ((u32)1 << 31)
527527
static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
528528
static char *log_buf = __log_buf;
529529
static u32 log_buf_len = __LOG_BUF_LEN;
@@ -2436,7 +2436,6 @@ asmlinkage __visible int _printk(const char *fmt, ...)
24362436
}
24372437
EXPORT_SYMBOL(_printk);
24382438

2439-
static bool pr_flush(int timeout_ms, bool reset_on_progress);
24402439
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress);
24412440

24422441
#else /* CONFIG_PRINTK */
@@ -2449,7 +2448,6 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
24492448

24502449
static u64 syslog_seq;
24512450

2452-
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; }
24532451
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; }
24542452

24552453
#endif /* CONFIG_PRINTK */
@@ -4436,7 +4434,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
44364434
* Context: Process context. May sleep while acquiring console lock.
44374435
* Return: true if all usable printers are caught up.
44384436
*/
4439-
static bool pr_flush(int timeout_ms, bool reset_on_progress)
4437+
bool pr_flush(int timeout_ms, bool reset_on_progress)
44404438
{
44414439
return __pr_flush(NULL, timeout_ms, reset_on_progress);
44424440
}
@@ -4892,6 +4890,11 @@ void console_try_replay_all(void)
48924890
static atomic_t printk_cpu_sync_owner = ATOMIC_INIT(-1);
48934891
static atomic_t printk_cpu_sync_nested = ATOMIC_INIT(0);
48944892

4893+
bool is_printk_cpu_sync_owner(void)
4894+
{
4895+
return (atomic_read(&printk_cpu_sync_owner) == raw_smp_processor_id());
4896+
}
4897+
48954898
/**
48964899
* __printk_cpu_sync_wait() - Busy wait until the printk cpu-reentrant
48974900
* spinning lock is not owned by any CPU.

kernel/printk/printk_safe.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ bool is_printk_legacy_deferred(void)
4343
/*
4444
* The per-CPU variable @printk_context can be read safely in any
4545
* context. CPU migration is always disabled when set.
46+
*
47+
* A context holding the printk_cpu_sync must not spin waiting for
48+
* another CPU. For legacy printing, it could be the console_lock
49+
* or the port lock.
4650
*/
4751
return (force_legacy_kthread() ||
4852
this_cpu_read(printk_context) ||
49-
in_nmi());
53+
in_nmi() ||
54+
is_printk_cpu_sync_owner());
5055
}
5156

5257
asmlinkage int vprintk(const char *fmt, va_list args)

kernel/reboot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ void kernel_power_off(void)
697697
migrate_to_reboot_cpu();
698698
syscore_shutdown();
699699
pr_emerg("Power down\n");
700+
pr_flush(1000, true);
700701
kmsg_dump(KMSG_DUMP_SHUTDOWN);
701702
machine_power_off();
702703
}

0 commit comments

Comments
 (0)