On Fri, Dec 04, 2026 at 12:01:51PM -0800, Chris Down wrote:
> Since commit 0d97bae9abbe ("netconsole: register one console per > target") the console of a target is called netcons_<target name>. Only > 15 characters of that fit in the name of a console and a target made > through configfs always has index 0, so targets whose names start with > the same seven characters get consoles with the same name and index. > For example, with targets called target_alpha and target_beta: > > # grep netcons /proc/consoles > netcons_target_0 -W- (E N ) > netcons_target_0 -W- (E N ) > > The targets which netcons_torture.sh creates all register as > netcons_netcons0 in the same way. A target called cmdline5 which was > not set up by netconsole= is cut to netcons_cmdline0 as well, and that > is already the console of the first target from the command line. > > That commit said that names could collide, and on its own all this > means is that /proc/consoles can't tell these consoles apart. It > becomes a real problem once something is keyed by the name. The > per-console loglevel series [0] adds /sys/class/console/<name><index> > for each console, which is also where the replay trigger for > netconsole is expected to go [1]. With that series applied on top, > enabling target_beta above prints a stack trace with > > sysfs: cannot create duplicate filename '/devices/virtual/console/netcons_target_0' > > and the target is left without a directory in /sys/class/console, so > there is no way to set its loglevel. > > To fix this, let's give a new target the lowest index which no other > target with the same console name has. The targets above become > netcons_target_0 and netcons_target_1. A console name shorter than 15 > characters, like netcons_foo, can only belong to one target, so target > foo keeps index 0 and is still netcons_foo0. > > The index is chosen when the target is created, and not when its > console is registered, so that the console keeps its name while the > target is disabled and enabled again. Choosing it means looking at > every other target. A target is on target_list or > target_cleanup_list, except while process_resume_target() has taken it > off both, which it does with dynamic_netconsole_mutex held. > make_netconsole_target() thus takes that mutex and > target_cleanup_list_lock as well as target_list_lock. > > Numbering all the consoles from one counter would be simpler, but then > target foo is no longer always netcons_foo0, and target a with index > 10 would show up under the same name as target a1 with index 0. > > I ran into this while testing the per-console loglevel series on top > of net-next, with the two targets above. With this patch they get > different names in /proc/consoles and, with that series applied, a > directory each in /sys/class/console. The netconsole selftests still > pass.
> [0]: https://lore.kernel.org/r/84b8…@chrisdown.name > [1]: https://lore.kernel.org/r/at84…@gmail.com >
Convert them to Link tags in a form of Link: $URL [0] and so on... With that, drop the blank line.
> Fixes: 0d97bae9abbe ("netconsole: register one console per target") > Signed-off-by: Chris Down <chr…@chrisdown.name> > ---
...
> +/* Return the lowest index that no target uses together with the console name > + * @name. A target is on target_list or on target_cleanup_list, unless > + * process_resume_target() is resuming it under dynamic_netconsole_mutex, so > + * the caller holds that mutex and the locks of both lists. > + */
You should decide consistently which style (network or usual) of multi-line comment should this driver use. ...
> + lockdep_assert_held(&dynamic_netconsole_mutex); > + lockdep_assert_held(&target_cleanup_list_lock); > + lockdep_assert_held(&target_list_lock);
Would __must_hold() also help compiler to catch some problematic cases at compile-time? ...
> /* > * Group operations and type for netconsole_subsys. > */
You see, this is different style. ...
> + /* netcons_<name> is cut to fit, so targets can share it. printk shows > + * the index after the name, which is 0 unless the name is taken. > + */
Same here.
-- With Best Regards, Andy Shevchenko