Re: [PATCH printk v2 08/26] printk: nbcon: Implement processing in port->lock wrapper

From: Andy Shevchenko
Date: Mon Feb 19 2024 - 07:16:41 EST


On Sun, Feb 18, 2024 at 08:03:08PM +0106, John Ogness wrote:
> Currently the port->lock wrappers uart_port_lock(),
> uart_port_unlock() (and their variants) only lock/unlock
> the spin_lock.
>
> If the port is an nbcon console, the wrappers must also
> acquire/release the console and mark the region as unsafe. This
> allows general port->lock synchronization to be synchronized
> with the nbcon console ownership.
>
> Add a flag to struct uart_port to track nbcon console ownership.

..

> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -6,6 +6,7 @@
> #include <linux/console.h>
> #include <linux/delay.h>
> #include <linux/slab.h>
> +#include <linux/serial_core.h>

The headers in this file is a mess. But here you can at least keep the piece
ordered, can you?

..

> +static inline bool uart_is_nbcon(struct uart_port *up)
> +{
> + int cookie;
> + bool ret;
> +
> + if (!uart_console(up))
> + return false;
> +
> + cookie = console_srcu_read_lock();
> + ret = (console_srcu_read_flags(up->cons) & CON_NBCON);

The outer parentheses are redundant.

> + console_srcu_read_unlock(cookie);
> + return ret;
> +}

..

> +void uart_nbcon_acquire(struct uart_port *up)
> +{
> + struct console *con = up->cons;
> + struct nbcon_context ctxt;
> +
> + if (!uart_is_nbcon(up))
> + return;

> + WARN_ON_ONCE(up->nbcon_locked_port);

+ include linux/bug.h

> + do {
> + do {
> + memset(&ctxt, 0, sizeof(ctxt));

+ include linux/string.h

> + ctxt.console = con;
> + ctxt.prio = NBCON_PRIO_NORMAL;
> + } while (!nbcon_context_try_acquire(&ctxt));
> +
> + } while (!nbcon_context_enter_unsafe(&ctxt));
> +
> + up->nbcon_locked_port = true;
> +}
> +EXPORT_SYMBOL_GPL(uart_nbcon_acquire);

+ include linux/export.h

--
With Best Regards,
Andy Shevchenko