[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87mui43jgk.fsf@linutronix.de>
Date: Wed, 26 Jun 2019 09:16:11 +0200
From: John Ogness <john.ogness@...utronix.de>
To: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc: Petr Mladek <pmladek@...e.com>, linux-kernel@...r.kernel.org,
Peter Zijlstra <peterz@...radead.org>,
Steven Rostedt <rostedt@...dmis.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Andrea Parri <andrea.parri@...rulasolutions.com>,
Thomas Gleixner <tglx@...utronix.de>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation
On 2019-06-26, Sergey Senozhatsky <sergey.senozhatsky.work@...il.com> wrote:
> [..]
>> > CPU0 CPU1
>> > printk(...)
>> > sz = vscprintf(NULL, "Comm %s\n", current->comm);
>> > ia64_mca_modify_comm()
>> > snprintf(comm, sizeof(comm), "%s %d", current->comm, previous_current->pid);
>> > memcpy(current->comm, comm, sizeof(current->comm));
>> > if ((buf = prb_reserve(... sz))) {
>> > vscnprintf(buf, "Comm %s\n", current->comm);
>> > ^^^^^^^^^^^^^^ ->comm has changed.
>> > Nothing critical, we
>> > should not corrupt
>> > anything, but we will
>> > truncate ->comm if its
>> > new size is larger than
>> > what it used to be when
>> > we did vscprintf(NULL).
>> > prb_commit(...);
>> > }
>
> [..]
>> In my v1 rfc series, I avoided this issue by having a separate dedicated
>> ringbuffer (rb_sprintf) that was used to allocate a temporary max-size
>> (2KB) buffer for sprinting to. Then _that_ was used for the real
>> ringbuffer input (strlen, prb_reserve, memcpy, prb_commit). That would
>> still be the approach of my choice.
>
> In other words per-CPU buffering, AKA printk_safe ;)
Actually, no. I made use of a printk_ringbuffer (which is global). It
was used for temporary memory allocation for sprintf, but the result was
immediately written into the printk buffer from the same context. In
contrast, printk_safe triggers a different context to handle the
insertion.
It is still my intention to eliminate the buffering component of
printk_safe.
After we get a lockless ringbuffer that we are happy with, my next
series to integrate the buffer into printk will again use the sprint_rb
solution to avoid the issue discussed in this thread. Perhaps it would
be best to continue this discussion after I've posted that series.
John Ogness
Powered by blists - more mailing lists