From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jan Kara <jack@suse.cz>, Tejun Heo <tj@kernel.org>,
Calvin Owens <calvinowens@fb.com>,
Thomas Gleixner <tglx@linutronix.de>,
Mel Gorman <mgorman@techsingularity.net>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Laura Abbott <labbott@redhat.com>,
Andy Lutomirski <luto@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [RFC][PATCHv4 4/6] printk: report lost messages in printk safe/nmi contexts
Date: Thu, 1 Dec 2016 11:10:42 +0900 [thread overview]
Message-ID: <20161201021005.GE12039@jagdpanzerIV> (raw)
In-Reply-To: <20161125110730.GH24103@pathway.suse.cz>
On (11/25/16 12:07), Petr Mladek wrote:
[..]
> > +static void report_message_lost(atomic_t *num_lost, char *fmt)
> > +{
> > + int lost = atomic_xchg(num_lost, 0);
> > +
> > + if (lost) {
> > + char msg[56];
>
> I would really like to avoid a hard coded buffer size. Such things
> are likely to bite us in the future.
why would scnprintf() overflow.
> I thought about reshuffling a lot of logic, adding more wrappers,
> ... But the solution might be easy in the end, see below.
>
> > +
> > + scnprintf(msg, sizeof(msg), fmt, lost);
> > +
> > + printk_safe_flush_line(msg, strlen(msg));
>
> This made my brain spin a lot. I wondered if it did what we wanted
> and it was safe.
>
> On one hand, it is supposed to work because use exactly this
> function in __printk_safe_flush() where you call this from.
>
> One question is if it does what we want in different contexts.
> Let's look at it:
>
> 1. It calls printk_deferred() in NMI context. There is a risk
> of a deadlock. But it is called only from
> printk_safe_flush_on_panic() which is the last resort. Therefore
> it does exactly what we want.
>
> 2. It calls printk()->printk_func()->vprintk_emit() in normal context.
> It is what we want in normal context.
>
> 3. It calls printk()->printk_func()->v printk_safe() in printk_safe
> context. This does not look correct. IMHO, this might happen
> only printk_safe_flush_on_panic() and we want to use
> printk_deferred() here as well.
[..]
> The easiest solution would be to simply call printk_deferred()
> here. Everything will be deferred after the async printk() patchset
> anyway.
>
> I would even use printk_deferred() in printk_safe_flush_line()
> for each context. It is not optimal but it works very well
> and it makes the code much more straightforward.
yes, good point.
we can call deferred printk for anything there; or replace that in_nmi()
check with the `printk_safe_context != 0' one, and then route the message
via printk or printk_deferred.
[..]
> > * Flush data from the associated per-CPU buffer. The function
> > * can be called either via IRQ work or independently.
> > @@ -147,6 +183,9 @@ static void __printk_safe_flush(struct irq_work *work)
> >
> > i = 0;
> > more:
> > + report_nmi_message_lost();
> > + report_safe_message_lost();
>
> Please, move this at the end of this function.
ok.
-ss
next prev parent reply other threads:[~2016-12-01 2:10 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-27 15:49 [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls Sergey Senozhatsky
2016-10-27 15:49 ` [RFC][PATCHv4 1/6] printk: use vprintk_func in vprintk() Sergey Senozhatsky
2016-11-24 16:28 ` Petr Mladek
2016-10-27 15:49 ` [RFC][PATCHv4 2/6] printk: rename nmi.c and exported api Sergey Senozhatsky
2016-11-24 16:35 ` Petr Mladek
2016-12-01 1:07 ` Sergey Senozhatsky
2016-12-01 12:12 ` Petr Mladek
2016-10-27 15:49 ` [RFC][PATCHv4 3/6] printk: introduce per-cpu safe_print seq buffer Sergey Senozhatsky
2016-11-24 16:58 ` Petr Mladek
2016-12-01 1:08 ` Sergey Senozhatsky
2016-12-01 5:32 ` Sergey Senozhatsky
2016-10-27 15:49 ` [RFC][PATCHv4 4/6] printk: report lost messages in printk safe/nmi contexts Sergey Senozhatsky
2016-11-25 11:07 ` Petr Mladek
2016-12-01 2:10 ` Sergey Senozhatsky [this message]
2016-12-01 12:50 ` Petr Mladek
2016-10-27 15:49 ` [RFC][PATCHv4 5/6] printk: use printk_safe buffers Sergey Senozhatsky
2016-11-25 14:28 ` Petr Mladek
2016-12-01 2:14 ` Sergey Senozhatsky
2016-10-27 15:49 ` [RFC][PATCHv4 6/6] printk: remove zap_locks() function Sergey Senozhatsky
2016-11-25 15:01 ` Petr Mladek
2016-11-25 15:17 ` Peter Zijlstra
2016-12-01 2:34 ` Sergey Senozhatsky
2016-12-01 5:42 ` Peter Zijlstra
2016-12-01 13:36 ` Petr Mladek
2016-12-02 1:11 ` Sergey Senozhatsky
2016-12-01 2:18 ` Sergey Senozhatsky
2016-12-01 12:50 ` Sergey Senozhatsky
2016-12-01 13:15 ` Petr Mladek
2016-10-28 3:30 ` [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls Linus Torvalds
2016-10-28 4:05 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161201021005.GE12039@jagdpanzerIV \
--to=sergey.senozhatsky.work@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=calvinowens@fb.com \
--cc=jack@suse.cz \
--cc=keescook@chromium.org \
--cc=labbott@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).