Re: [QUESTION] printk: time namespaces and printk timestamps
From: Petr Mladek
Date: Mon May 25 2026 - 05:31:42 EST
On Mon 2026-05-25 10:47:46, Thomas Weißschuh wrote:
> On 2026-05-25 10:37:40+0200, Petr Mladek wrote:
> > On Sat 2026-05-23 17:20:45, Thomas Weißschuh wrote:
> > > It looks like the monotonic timestamps of printk records do not take the
> > > callers time namespace into account when emitted through /dev/kmsg,
> > > /proc/kmsg and syslog(2).
> > >
> > > To me this looks like a bug. What do you think? Should it be changed?
> >
> > To be honest, I have never heard about time namespaces before ;-)
> >
> > So, you propose to use the timestamp with the namespace-specific
> > offset when a message is added from the given namespace, e.g. via:
> >
> > echo "This message is from another time space" > /dev/kmsg
> >
> > Do I get it correctly?
>
> My idea was rather to do the conversion when *reading* the message from
> a time namespaced user process.
I see. But it might produce messages with negative timestamps. I am
not sure if it is a good idea. I guess that many tools might get
confused.
> > I see two potential problems:
> >
> > 1. printk() historically used a monotonic clock. I am not sure if any
> > usespace application depends on it but there is a risk of breaking
> > something.
>
> >From the perspective of the namespaced process currently the timestamps
> from printk may in fact not be CLOCK_MONOTONIC.
The messages stored in the kernel ring buffer currently always have
monotonic timestamps.
I guess that you talk about matching kernel messages with other
userspace logs. But they might be inconsistent also because
of using different clocks...
There were several discussions in the past about storing more
timestamps from different clocks in the printk ring buffer.
But it never went anywhere.
Best Regards,
Petr