* [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks
@ 2025-12-05 18:34 Marcos Paulo de Souza
2025-12-08 9:15 ` John Ogness
0 siblings, 1 reply; 3+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-05 18:34 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky
Cc: linux-kernel, marcos, Marcos Paulo de Souza
These callbacks are necessary to synchronize ->write_thread callback
against other operations using the same device.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
I found this issue while creating a custom kernel module that implements
the nbcon interfaces.
---
kernel/printk/nbcon.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f..02809c44d7ea 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con)
if (WARN_ON(!con->write_thread))
return false;
+ /* The device_lock() and device_unlock() callbacks are mandatory. */
+ if (WARN_ON(!con->device_lock || !con->device_unlock))
+ return false;
+
rcuwait_init(&con->rcuwait);
init_irq_work(&con->irq_work, nbcon_irq_work);
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_prev_seq), -1UL);
---
base-commit: 322530a9c2ab1da67e5b0988fa29aca64d96ec8f
change-id: 20251205-nbcon-device-cb-fix-7ce745a21ba8
Best regards,
--
Marcos Paulo de Souza <mpdesouza@suse.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks
2025-12-05 18:34 [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks Marcos Paulo de Souza
@ 2025-12-08 9:15 ` John Ogness
2025-12-08 13:30 ` Petr Mladek
0 siblings, 1 reply; 3+ messages in thread
From: John Ogness @ 2025-12-08 9:15 UTC (permalink / raw)
To: Marcos Paulo de Souza, Petr Mladek, Steven Rostedt,
Sergey Senozhatsky
Cc: linux-kernel, marcos, Marcos Paulo de Souza
On 2025-12-05, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> These callbacks are necessary to synchronize ->write_thread callback
> against other operations using the same device.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> I found this issue while creating a custom kernel module that implements
> the nbcon interfaces.
> ---
> kernel/printk/nbcon.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 3fa403f9831f..02809c44d7ea 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con)
> if (WARN_ON(!con->write_thread))
> return false;
>
> + /* The device_lock() and device_unlock() callbacks are mandatory. */
> + if (WARN_ON(!con->device_lock || !con->device_unlock))
> + return false;
> +
The code itself is fine and this is an important contribution. But I
would prefer to combine it with the previous mandatory check. So it
looks more like this:
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f..f096282b0625 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1760,9 +1758,12 @@ bool nbcon_alloc(struct console *con)
/* Synchronize the kthread start. */
lockdep_assert_console_list_lock_held();
- /* The write_thread() callback is mandatory. */
- if (WARN_ON(!con->write_thread))
+ /* Check for mandatory nbcon callbacks. */
+ if (WARN_ON(!con->write_thread ||
+ !con->device_lock ||
+ !con->device_unlock)) {
return false;
+ }
rcuwait_init(&con->rcuwait);
init_irq_work(&con->irq_work, nbcon_irq_work);
John Ogness
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks
2025-12-08 9:15 ` John Ogness
@ 2025-12-08 13:30 ` Petr Mladek
0 siblings, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2025-12-08 13:30 UTC (permalink / raw)
To: John Ogness
Cc: Marcos Paulo de Souza, Steven Rostedt, Sergey Senozhatsky,
linux-kernel, marcos
On Mon 2025-12-08 10:21:09, John Ogness wrote:
> On 2025-12-05, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> > These callbacks are necessary to synchronize ->write_thread callback
> > against other operations using the same device.
> >
> > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> > ---
> > I found this issue while creating a custom kernel module that implements
> > the nbcon interfaces.
Great catch!
> > --- a/kernel/printk/nbcon.c
> > +++ b/kernel/printk/nbcon.c
> > @@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con)
> > if (WARN_ON(!con->write_thread))
> > return false;
> >
> > + /* The device_lock() and device_unlock() callbacks are mandatory. */
> > + if (WARN_ON(!con->device_lock || !con->device_unlock))
> > + return false;
> > +
>
> The code itself is fine and this is an important contribution. But I
> would prefer to combine it with the previous mandatory check. So it
> looks more like this:
>
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 3fa403f9831f..f096282b0625 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1760,9 +1758,12 @@ bool nbcon_alloc(struct console *con)
> /* Synchronize the kthread start. */
> lockdep_assert_console_list_lock_held();
>
> - /* The write_thread() callback is mandatory. */
> - if (WARN_ON(!con->write_thread))
> + /* Check for mandatory nbcon callbacks. */
> + if (WARN_ON(!con->write_thread ||
> + !con->device_lock ||
> + !con->device_unlock)) {
> return false;
> + }
I agree that this looks better. ;-)
>
> rcuwait_init(&con->rcuwait);
> init_irq_work(&con->irq_work, nbcon_irq_work);
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-08 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-05 18:34 [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks Marcos Paulo de Souza
2025-12-08 9:15 ` John Ogness
2025-12-08 13:30 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox