From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Derek Barbosa <debarbos@redhat.com>,
printk@lists.linux.dev, linux-kernel@vger.kernel.org,
Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH printk] printk: Avoid multiple unregistration in unregister_console_locked()
Date: Fri, 30 Oct 2026 14:52:01 +0100 [thread overview]
Message-ID: <auShAQbJAwSqI6gu@pathway> (raw)
In-Reply-To: <87y0bgwm0y.fsf@jogness.linutronix.deq>
On Thu 2026-10-29 16:48:53, John Ogness wrote:
> On 2026-10-29, Sashiko wrote:
> >> @@ -4471,6 +4493,9 @@ static int __init printk_late_init(void)
> >> }
> >>
> >> unregister_console_locked(con);
> >> +
> >> + /* Changed console list, may require printer threads to start/stop. */
> >> + printk_kthreads_check_locked();
> >> }
> >
> > Should printk_kthreads_check_locked() be called after the
> > hlist_for_each_entry_safe(con, tmp, &console_list, node) loop in
> > printk_late_init() rather than inside the loop body?
> >
> > In kernel/printk/printk.c:printk_late_init():
> >
> > hlist_for_each_entry_safe(con, tmp, &console_list, node) {
> > if (!(con->flags & CON_BOOT))
> > continue;
> > ...
> > unregister_console_locked(con);
> >
> > /* Changed console list, may require printer threads to start/stop. */
> > printk_kthreads_check_locked();
> > }
> > console_list_unlock();
> >
> > Because printk_kthreads_check_locked() is placed inside the loop,
> > unregistering the last boot console sets have_boot_console to false and
> > immediately attempts to start printer kthreads while the loop is still
> > iterating over console_list.
> >
> > If kthread creation in legacy_kthread_create() or nbcon_kthread_create()
> > fails for the console stored in tmp, printk_kthreads_check_locked() calls
> > unregister_console_locked() on that console, removing it with
> > hlist_del_init_rcu(), freeing nbcon resources, and invoking console->exit().
> > On the next iteration of printk_late_init(), con is set to tmp, accessing the
> > already-unregistered console and terminating the walk early because
> > hlist_del_init_rcu() cleared tmp->next.
>
> Geez, sorry. Obviously printk_kthreads_check_locked() needs to be
> outside of the hlist_for_each_entry_safe(console_list) loop. That was
> the whole point of the series!
>
> I will wait a day for v2 in case there is any feedback regarding my
> comments (or lack thereof).
JFYI, the comments look good to me.
It is quite twisted problem. I have got lost again when looking at
this patch. I am not surprised that the 1st version was not right. ;-)
Best Regards,
Petr
next parent reply other threads:[~2026-10-30 13:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87y0bgwm0y.fsf@jogness.linutronix.deq>
2026-10-30 13:52 ` Petr Mladek [this message]
2026-10-29 15:24 [PATCH printk] printk: Avoid multiple unregistration in unregister_console_locked() John Ogness
2026-10-29 15:42 ` John Ogness
2026-10-29 21:31 ` Derek Barbosa
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=auShAQbJAwSqI6gu@pathway \
--to=pmladek@suse.com \
--cc=debarbos@redhat.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=printk@lists.linux.dev \
--cc=rostedt@goodmis.org \
--cc=sashiko-bot@kernel.org \
--cc=senozhatsky@chromium.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.