From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
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>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [RFC][PATCHv2 3/7] printk: introduce per-cpu alt_print seq buffer
Date: Thu, 6 Oct 2016 15:08:49 +0200 [thread overview]
Message-ID: <20161006130849.GG13369@pathway.suse.cz> (raw)
In-Reply-To: <20160930151758.8965-4-sergey.senozhatsky@gmail.com>
On Sat 2016-10-01 00:17:54, Sergey Senozhatsky wrote:
> This patch extends the idea of NMI per-cpu buffers to regions
> that may cause recursive printk() calls and possible deadlocks.
> diff --git a/kernel/printk/alt_printk.c b/kernel/printk/alt_printk.c
> index 7178661..4bc1e7d 100644
> --- a/kernel/printk/alt_printk.c
> +++ b/kernel/printk/alt_printk.c
> len = atomic_read(&s->len);
>
> - if (len >= sizeof(s->buffer)) {
> - atomic_inc(&nmi_message_lost);
> + if (len >= sizeof(s->buffer))
> return 0;
> - }
>
> /*
> * Make sure that all old data have been read before the buffer was
> @@ -240,6 +235,83 @@ void alt_printk_flush_on_panic(void)
> alt_printk_flush();
> }
>
> +/*
> + * Safe printk() for NMI context. It uses a per-CPU buffer to
> + * store the message. NMIs are not nested, so there is always only
> + * one writer running. But the buffer might get flushed from another
> + * CPU, so we need to be careful.
> + */
> +static int vprintk_nmi(const char *fmt, va_list args)
> +{
> + struct alt_printk_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
> + int add;
> +
> + add = alt_printk_log_store(s, fmt, args);
> + if (!add)
> + atomic_inc(&nmi_message_lost);
This would could also empty string as an error. A solution might be
update alt_printk_log_store() to return -1 in case of lost log.
Note that vprintk_nmi() still needs to return 0 in this case to
stay compatible with printk().
> +
> + return add;
> +}
> +
> +void printk_nmi_enter(void)
> +{
> + this_cpu_or(alt_printk_ctx, ALT_PRINTK_NMI_CONTEXT_MASK);
> +}
> +
> +void printk_nmi_exit(void)
> +{
> + this_cpu_and(alt_printk_ctx, ~ALT_PRINTK_NMI_CONTEXT_MASK);
> +}
> +
> +/*
> + * Lockless printk(), to avoid deadlocks should the printk() recurse
> + * into itself. It uses a per-CPU buffer to store the message, just like
> + * NMI.
> + */
> +static int vprintk_alt(const char *fmt, va_list args)
> +{
> + struct alt_printk_seq_buf *s = this_cpu_ptr(&alt_print_seq);
> +
> + return alt_printk_log_store(s, fmt, args);
We should handle lost strings here as well. But it can be
done in a followup patch.
> +}
> +
> +/*
> + * Returns with local IRQs disabled.
> + * Can be preempted by NMI.
> + */
> +void alt_printk_enter(void)
> +{
> + unsigned long flags;
> + int entry_count;
> +
> + local_irq_save(flags);
> + if (!(this_cpu_read(alt_printk_ctx) & ALT_PRINTK_CONTEXT_MASK))
> + this_cpu_write(alt_printk_irq_flags, flags);
> + this_cpu_inc(alt_printk_ctx);
> +}
> +
> +/*
> + * Restores local IRQs state saved in alt_printk_enter().
> + * Can be preempted by NMI.
> + */
> +void alt_printk_exit(void)
> +{
> + this_cpu_dec(alt_printk_ctx);
> + if (!(this_cpu_read(alt_printk_ctx) & ALT_PRINTK_CONTEXT_MASK))
> + local_irq_restore(this_cpu_read(alt_printk_irq_flags));
> +}
I will discuss this in your replay that explains the details.
Anyway, it looks much easier now.
Best Regards,
Petr
next prev parent reply other threads:[~2016-10-06 13:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 15:17 [RFC][PATCHv2 0/7] printk: use alt_printk to handle printk() recursive calls Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 1/7] printk: use vprintk_func in vprintk() Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 2/7] printk: rename nmi.c and exported api Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 3/7] printk: introduce per-cpu alt_print seq buffer Sergey Senozhatsky
2016-10-01 2:24 ` Sergey Senozhatsky
2016-10-06 14:56 ` Petr Mladek
2016-10-07 19:40 ` Sergey Senozhatsky
2016-10-10 11:03 ` Petr Mladek
2016-10-06 13:08 ` Petr Mladek [this message]
2016-10-07 19:33 ` Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 4/7] printk: make alt_printk available when config printk set Sergey Senozhatsky
2016-10-06 15:23 ` Petr Mladek
2016-10-07 19:08 ` Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 5/7] printk: use alternative printk buffers Sergey Senozhatsky
2016-09-30 15:17 ` [RFC][PATCHv2 6/7] printk: report printk recursion from alt_printk flush Sergey Senozhatsky
2016-10-06 15:41 ` Petr Mladek
2016-10-07 18:59 ` Sergey Senozhatsky
2016-10-10 11:02 ` Petr Mladek
2016-09-30 15:17 ` [RFC][PATCHv2 7/7] printk: remove zap_locks() function Sergey Senozhatsky
2016-10-06 15:55 ` [RFC][PATCHv2 0/7] printk: use alt_printk to handle printk() recursive calls Petr Mladek
2016-10-07 18:56 ` 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=20161006130849.GG13369@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=calvinowens@fb.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.