From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Stephen Rothwell <sfr@canb.auug.org.au>,
Andrew Morton <akpm@linux-foundation.org>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Stephen Boyd <swboyd@chromium.org>,
Alexander Potapenko <glider@google.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH next v3 1/2] dump_stack: move cpu lock to printk.c
Date: Wed, 16 Jun 2021 13:21:00 +0200 [thread overview]
Message-ID: <YMnenOBTUclLld9i@alley> (raw)
In-Reply-To: <87mtrqnu74.fsf@jogness.linutronix.de>
On Wed 2021-06-16 09:35:35, John Ogness wrote:
> On 2021-06-16, Sergey Senozhatsky <senozhatsky@chromium.org> wrote:
> It isn't about limiting. It is about tracking. The current dump_stack()
> handles it correctly because the tracking is done in the stack frame of
> the caller (in @was_locked of dump_stack_lvl()). My previous versions
> also handled it correctly by using the same technique.
>
> With this series version I moved the tracking into a global variable
> @printk_cpulock_nested, which is fine, except that a boolean is not
> capable of tracking more than 1 nesting. Which means that
> __printk_cpu_unlock() would release cpu lock ownership too soon.
>
> Doing this correctly is a simple change:
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index e67dc510fa1b..5376216e4f3d 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3535,7 +3535,7 @@ EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
>
> #ifdef CONFIG_SMP
> static atomic_t printk_cpulock_owner = ATOMIC_INIT(-1);
> -static bool printk_cpulock_nested;
> +static atomic_t printk_cpulock_nested = ATOMIC_INIT(0);
>
> /**
> * __printk_wait_on_cpu_lock() - Busy wait until the printk cpu-reentrant
> @@ -3596,7 +3598,7 @@ int __printk_cpu_trylock(void)
>
> } else if (old == cpu) {
> /* This CPU is already the owner. */
> - printk_cpulock_nested = true;
> + atomic_inc(&printk_cpulock_nested);
> return 1;
> }
>
> @@ -3613,8 +3615,8 @@ EXPORT_SYMBOL(__printk_cpu_trylock);
> */
> void __printk_cpu_unlock(void)
> {
> - if (printk_cpulock_nested) {
> - printk_cpulock_nested = false;
> + if (atomic_read(&printk_cpulock_nested)) {
> + atomic_dec(&printk_cpulock_nested);
I think about handling printk_cpulock_nested with only one
atomic operation. Something like:
if (atomic_dec_return(&printk_cpulock_level) == 0)
atomic_set_release(&printk_cpulock_owner, -1);
It would require always incremanting the number in lock, e.g.
old = atomic_cmpxchg(&printk_cpulock_owner, -1, cpu);
if (old == -1 || old == cpu) {
atomic_inc(&printk_cpulock_level);
return 1;
}
But I am not sure if it is really better. Feel free to keep
your variant.
> return;
> }
>
> > Shall this be a separate patch?
>
> I would prefer a v4 because I also noticed that this patch accidentally
> implements atomic_set_release() instead of moving over the atomit_set()
> from dump_stack(). That also needs to be corrected, otherwise the next
> patch in the series makes no sense.
Yes, this needs to get fixed as well.
Otherwise, the patch looks good to me. I haven't found any other
problems, except for the two already mentioned (count nested levels,
introduce atomic_set_release() in 2nd patch).
Best Regards,
Petr
next prev parent reply other threads:[~2021-06-16 11:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 17:49 [PATCH next v3 0/2] introduce printk cpu lock John Ogness
2021-06-15 17:49 ` [PATCH next v3 1/2] dump_stack: move cpu lock to printk.c John Ogness
2021-06-15 21:33 ` John Ogness
2021-06-16 7:06 ` Sergey Senozhatsky
2021-06-16 7:29 ` John Ogness
2021-06-16 11:21 ` Petr Mladek [this message]
2021-06-16 13:40 ` John Ogness
2021-06-16 11:55 ` Sergey Senozhatsky
2021-06-15 17:49 ` [PATCH next v3 2/2] printk: fix cpu lock ordering John Ogness
2021-06-16 11:30 ` Petr Mladek
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=YMnenOBTUclLld9i@alley \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=bristot@redhat.com \
--cc=glider@google.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=sfr@canb.auug.org.au \
--cc=swboyd@chromium.org \
--cc=tglx@linutronix.de \
/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