From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Petr Mladek" <pmladek@suse.com>,
"Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Russell King" <linux@armlinux.org.uk>,
"Tony Lindgren" <tony@atomide.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Arnd Bergmann" <arnd@arndb.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Théo Lebrun" <theo.lebrun@bootlin.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Lino Sanfilippo" <l.sanfilippo@kunbus.com>,
"Konrad Dybcio" <konrad.dybcio@linaro.org>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
linux-serial <linux-serial@vger.kernel.org>
Subject: Re: [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons
Date: Tue, 20 Aug 2024 14:12:15 +0300 (EEST) [thread overview]
Message-ID: <a4bb64e8-126c-6a50-bd39-77926aa6010e@linux.intel.com> (raw)
In-Reply-To: <20240820063001.36405-12-john.ogness@linutronix.de>
[-- Attachment #1: Type: text/plain, Size: 4812 bytes --]
On Tue, 20 Aug 2024, John Ogness wrote:
> Introduce uart_port_set_cons() as a wrapper to set @cons of a
> uart_port. The wrapper sets @cons under the port lock in order
> to prevent @cons from disappearing while another context is
> holding the port lock. This is necessary for a follow-up
> commit relating to the port lock wrappers, which rely on @cons
> not changing between lock and unlock.
>
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> Tested-by: Théo Lebrun <theo.lebrun@bootlin.com> # EyeQ5, AMBA-PL011
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
> ---
> drivers/tty/serial/8250/8250_core.c | 6 +++---
> drivers/tty/serial/amba-pl011.c | 2 +-
> drivers/tty/serial/serial_core.c | 16 ++++++++--------
> include/linux/serial_core.h | 17 +++++++++++++++++
> 4 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 29e4b83e0376..5f9f06911795 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -423,11 +423,11 @@ static int univ8250_console_setup(struct console *co, char *options)
>
> port = &serial8250_ports[co->index].port;
> /* link port to console */
> - port->cons = co;
> + uart_port_set_cons(port, co);
>
> retval = serial8250_console_setup(port, options, false);
> if (retval != 0)
> - port->cons = NULL;
> + uart_port_set_cons(port, NULL);
> return retval;
> }
>
> @@ -485,7 +485,7 @@ static int univ8250_console_match(struct console *co, char *name, int idx,
> continue;
>
> co->index = i;
> - port->cons = co;
> + uart_port_set_cons(port, co);
> return serial8250_console_setup(port, options, true);
> }
>
> diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
> index 8b1644f5411e..7d0134ecd82f 100644
> --- a/drivers/tty/serial/amba-pl011.c
> +++ b/drivers/tty/serial/amba-pl011.c
> @@ -2480,7 +2480,7 @@ static int pl011_console_match(struct console *co, char *name, int idx,
> continue;
>
> co->index = i;
> - port->cons = co;
> + uart_port_set_cons(port, co);
> return pl011_console_setup(co, options);
> }
>
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 9a18d0b95a41..61c7e1268957 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -3168,8 +3168,15 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
> state->uart_port = uport;
> uport->state = state;
>
> + /*
> + * If this port is in use as a console then the spinlock is already
> + * initialised.
> + */
> + if (!uart_console_registered(uport))
> + uart_port_spin_lock_init(uport);
> +
> state->pm_state = UART_PM_STATE_UNDEFINED;
> - uport->cons = drv->cons;
> + uart_port_set_cons(uport, drv->cons);
> uport->minor = drv->tty_driver->minor_start + uport->line;
> uport->name = kasprintf(GFP_KERNEL, "%s%d", drv->dev_name,
> drv->tty_driver->name_base + uport->line);
> @@ -3178,13 +3185,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
> goto out;
> }
>
> - /*
> - * If this port is in use as a console then the spinlock is already
> - * initialised.
> - */
> - if (!uart_console_registered(uport))
> - uart_port_spin_lock_init(uport);
> -
> if (uport->cons && uport->dev)
> of_console_check(uport->dev->of_node, uport->cons->name, uport->line);
>
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 8872cd21e70a..2cf03ff2056a 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -608,6 +608,23 @@ static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned
> spin_unlock_irqrestore(&up->lock, flags);
> }
>
> +/**
> + * uart_port_set_cons - Safely set the @cons field for a uart
> + * @up: The uart port to set
> + * @con: The new console to set to
> + *
> + * This function must be used to set @up->cons. It uses the port lock to
> + * synchronize with the port lock wrappers in order to ensure that the console
> + * cannot change or disappear while another context is holding the port lock.
> + */
> +static inline void uart_port_set_cons(struct uart_port *up, struct console *con)
> +{
> + unsigned long flags;
> +
> + __uart_port_lock_irqsave(up, &flags);
> + up->cons = con;
> + __uart_port_unlock_irqrestore(up, flags);
> +}
> /**
> * uart_port_lock - Lock the UART port
> * @up: Pointer to UART port structure
>
next prev parent reply other threads:[~2024-08-20 11:12 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
2024-08-20 6:29 ` [PATCH printk v8 01/35] printk: Add notation to console_srcu locking John Ogness
2024-08-20 17:49 ` Paul E. McKenney
2024-09-09 17:28 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 02/35] printk: nbcon: Consolidate alloc() and init() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 03/35] printk: Properly deal with nbcon consoles on seq init John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for Petr Mladek
2024-08-20 6:29 ` [PATCH printk v8 04/35] printk: Check printk_deferred_enter()/_exit() usage John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for Sebastian Andrzej Siewior
2024-08-20 6:29 ` [PATCH printk v8 05/35] printk: nbcon: Clarify rules of the owner/waiter matching John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 06/35] printk: nbcon: Remove return value for write_atomic() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 07/35] printk: nbcon: Add detailed doc " John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 08/35] printk: nbcon: Add callbacks to synchronize with driver John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 09/35] printk: nbcon: Use driver synchronization while (un)registering John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-08-20 11:12 ` Ilpo Järvinen [this message]
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 12/35] console: Improve console_srcu_read_flags() comments John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 13/35] nbcon: Add API to acquire context for non-printing operations John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 14/35] serial: core: Acquire nbcon context in port->lock wrapper John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 15/35] printk: nbcon: Do not rely on proxy headers John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 16/35] printk: Make console_is_usable() available to nbcon.c John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 17/35] printk: Let console_is_usable() handle nbcon John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 18/35] printk: Add @flags argument for console_is_usable() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 19/35] printk: nbcon: Add helper to assign priority based on CPU state John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 20/35] printk: nbcon: Provide function to flush using write_atomic() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for Thomas Gleixner
2024-08-20 6:29 ` [PATCH printk v8 21/35] printk: Track registered boot consoles John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 22/35] printk: nbcon: Use nbcon consoles in console_flush_all() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 23/35] printk: Add is_printk_legacy_deferred() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 24/35] printk: nbcon: Flush new records on device_release() John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 25/35] printk: Flush nbcon consoles first on panic John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 26/35] printk: nbcon: Add unsafe flushing " John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 27/35] printk: Avoid console_lock dance if no legacy or boot consoles John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 28/35] printk: Track nbcon consoles John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 29/35] printk: Coordinate direct printing in panic John Ogness
2024-08-20 15:21 ` Petr Mladek
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 30/35] printk: Add helper for flush type logic John Ogness
2024-08-21 9:11 ` Petr Mladek
2024-08-23 5:25 ` John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:29 ` [PATCH printk v8 31/35] printk: nbcon: Implement emergency sections John Ogness
2024-08-27 14:19 ` John Ogness
2024-09-04 10:34 ` Petr Mladek
2024-09-09 17:27 ` [tip: sched/rt] printk: nbcon: Use raw_cpu_ptr() instead of open coding tip-bot2 for John Ogness
2024-09-09 17:27 ` [tip: sched/rt] printk: nbcon: Implement emergency sections tip-bot2 for Thomas Gleixner
2024-08-20 6:29 ` [PATCH printk v8 32/35] panic: Mark emergency section in warn John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for Thomas Gleixner
2024-08-20 6:29 ` [PATCH printk v8 33/35] panic: Mark emergency section in oops John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:30 ` [PATCH printk v8 34/35] rcu: Mark emergency sections in rcu stalls John Ogness
2024-08-20 17:48 ` Paul E. McKenney
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-20 6:30 ` [PATCH printk v8 35/35] lockdep: Mark emergency sections in lockdep splats John Ogness
2024-09-09 17:27 ` [tip: sched/rt] " tip-bot2 for John Ogness
2024-08-21 9:21 ` [PATCH printk v8 00/35] wire up write_atomic() printing Petr Mladek
2024-08-21 9:28 ` Sebastian Andrzej Siewior
2024-08-21 14:09 ` Petr Mladek
2024-08-21 14:20 ` Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4bb64e8-126c-6a50-bd39-77926aa6010e@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bigeasy@linutronix.de \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=konrad.dybcio@linaro.org \
--cc=l.sanfilippo@kunbus.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
--cc=theo.lebrun@bootlin.com \
--cc=tony@atomide.com \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox