Re: [PATCH v5] printk: Userspace format enumeration support

From: Chris Down
Date: Wed Apr 21 2021 - 09:20:13 EST


Rasmus Villemoes writes:
One (ugly) way to handle this would be to have a new "level" field in
the printk index entry, with semantics that if it's some sentinel value,
look at the format itself for the format, otherwise if it's some other
value, the level field itself is the level.

This will work, but it's pretty ugly. Any better suggestions? :-)

Well, that was more or less exactly what I suggested when I wrote

One could also record the function a format is being used with - without
that, the display probably can't show a reasonable <level> for those
dev_* function.

But, I think the real question is, why are we/you interested in the
level at all? Isn't the format string itself enough for the purpose of
tracking which printks have come and gone? IOW, what about, on the
display side, simply skipping over some KERN_* prefix if present?

Hmm, as Petr suggested, it's largely so that we can determine whether it will be emitted at the current console loglevel. Otherwise, even if the printk site is present, it might not ever get emitted. To that extent I am pretty convinced it's necessary to reliably achieve the goals in the changelog.

Judging by the conversation there's no immediately obvious better way, so unless you or Petr object, I'll send a patch in the v6 series which implements the "ugly" way with dev_printk support as the first user. That should make it easier to add other printk-likes in future as needed.