From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Konstantin Khlebnikov <koct9i@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Petr Mladek <pmladek@suse.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH] kernel/printk: prevent deadlock at calling kmsg_dump from NMI context
Date: Mon, 15 Jul 2019 16:54:52 +0900 [thread overview]
Message-ID: <20190715075452.GA1875@jagdpanzerIV> (raw)
In-Reply-To: <d3958637-a03d-f899-63ef-8d0d50e78a1e@yandex-team.ru>
On (07/15/19 10:38), Konstantin Khlebnikov wrote:
> > > Indeed, panic is especially handled and looks fine.
> > >
> > > Sanity check in my patch could be relaxed:
> > >
> > > if (WARN_ON_ONCE(reason != KMSG_DUMP_PANIC && in_nmi()))
> > > return;
> >
> > How critical kmsg_dump() is? We deadlock only if NMI->kmsg_dump()
> > happens on the CPU which already holds the logbuf_lock; in any
> > other case logbuf_lock is owned by another CPU which is expected
> > to unlock it eventually. So it doesn't look like disabling all
> > NMI->kmsg_dump() is the only way to fix it.
> >
> > When we lock logbuf_lock we increment per-CPU printk_context
> > (PRINTK_SAFE_CONTEXT_MASK bits); when we unlock logbuf_lock
> > we decrement printk_context. Thus we always can tell if the
> > logbuf_lock was locked on the very same CPU - this_cpu printk_context
> > has PRINTK_SAFE_CONTEXT_MASK bits sets - and we are about to deadlock
> > in a nested context (NMI), or the lock was locked on another CPU and
> > it's "safe" to spin on logbuf_lock and wait for logbuf_lock to become
> > available.
>
> I see no users who dumps dmesg from NMI context except panic.
> This shouldn't happen. But might happen is something goes very wrong.
I see. OK, if NMI->kmsg_dump() never happens (except for panic) then
we are fine, I guess.
-ss
next prev parent reply other threads:[~2019-07-15 7:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-12 14:54 Konstantin Khlebnikov
2019-07-13 6:09 ` Sergey Senozhatsky
2019-07-13 6:46 ` Konstantin Khlebnikov
2019-07-13 13:19 ` Sergey Senozhatsky
2019-07-13 14:03 ` Konstantin Khlebnikov
2019-07-15 2:33 ` Sergey Senozhatsky
2019-07-15 7:38 ` Konstantin Khlebnikov
2019-07-15 7:54 ` Sergey Senozhatsky [this message]
2019-07-15 7:54 ` Petr Mladek
2019-07-15 8:12 ` Konstantin Khlebnikov
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=20190715075452.GA1875@jagdpanzerIV \
--to=sergey.senozhatsky.work@gmail.com \
--cc=khlebnikov@yandex-team.ru \
--cc=koct9i@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
/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
all inboxes | Powered by JetHome®