Re: [PATCH printk v4 03/39] printk: Prepare for SRCU console list protection

From: John Ogness
Date: Tue Nov 15 2022 - 06:34:40 EST


On 2022-11-15, Petr Mladek <pmladek@xxxxxxxx> wrote:
> On Mon 2022-11-14 17:34:56, John Ogness wrote:
>> Provide an NMI-safe SRCU protected variant to walk the console list.
>>
>> Note that all console fields are now set before adding the console
>> to the list to avoid the console becoming visible by SCRU readers
>> before being fully initialized.
>>
>> This is a preparatory change for a new console infrastructure which
>> operates independent of the console BKL.
>>
>> --- a/kernel/printk/printk.c
>> +++ b/kernel/printk/printk.c
>> @@ -3254,7 +3303,7 @@ int unregister_console(struct console *console)
>> return -ENODEV;
>> }
>>
>> - hlist_del_init(&console->node);
>> + hlist_del_init_rcu(&console->node);
>
> This should be hlist_del_rcu() here so that a list walker that it just
> processing this console could see the rest of the list.

hlist_del_init_rcu() does not prevent the rest of the list from being
seen. It only unlinks @pprev for future iterators.

> It seems that hlist_unhashed() checks only node.pprev pointer
> so that we even do not need to initialize it.
>
> We discussed this in v3 in the patch implementing
> console_force_preferred_locked(), see
> https://lore.kernel.org/r/Y20aBwNWT19YDeib@alley.
> I forgot that unregister_console() might have the same problem.

For console_force_preferred_locked() it was about making sure that the
console always appears registered, even though it is temporarily removed
from the console list.

For unregister_console() we want it to be seen as removed from the
console list.

John