From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jan Kara <jack@suse.com>, Tejun Heo <tj@kernel.org>,
Kyle McMartin <kyle@kernel.org>,
Dave Jones <davej@codemonkey.org.uk>,
Calvin Owens <calvinowens@fb.com>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [RFC][PATCH v3 4/4] printk: set may_schedule for some of console_trylock callers
Date: Thu, 11 Feb 2016 15:41:05 +0100 [thread overview]
Message-ID: <20160211144105.GM3305@pathway.suse.cz> (raw)
In-Reply-To: <1453536913-9545-5-git-send-email-sergey.senozhatsky@gmail.com>
On Sat 2016-01-23 17:15:13, Sergey Senozhatsky wrote:
> console_unlock() allows to cond_resched() if its caller has
> set `console_may_schedule' to 1, since
> 'commit 8d91f8b15361 ("printk: do cond_resched() between lines while
> outputting to consoles")'.
>
> The rules are:
> -- console_lock() always sets `console_may_schedule' to 1
> -- console_trylock() always sets `console_may_schedule' to 0
>
> However, console_trylock() callers (among them is printk()) do
> not always call printk() from atomic contexts, and some of them
> can cond_resched() in console_unlock(), so console_trylock()
> can set `console_may_schedule' to 1 for such processes.
>
> For !CONFIG_PREEMPT_COUNT kernels, however, console_trylock()
> always sets `console_may_schedule' to 0.
>
> It's possible to drop explicit preempt_disable()/preempt_enable()
> in vprintk_emit(), because console_unlock() and console_trylock()
> are now smart enough:
> a) console_unlock() does not cond_resched() when it's unsafe
> (console_trylock() takes care of that)
> b) console_unlock() does can_use_console() check.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
> kernel/printk/printk.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 99925ce..097ca8b 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1769,20 +1769,12 @@ asmlinkage int vprintk_emit(int facility, int level,
> if (!in_sched) {
> lockdep_off();
> /*
> - * Disable preemption to avoid being preempted while holding
> - * console_sem which would prevent anyone from printing to
> - * console
> - */
> - preempt_disable();
> -
> - /*
> * Try to acquire and then immediately release the console
> * semaphore. The release will print out buffers and wake up
> * /dev/kmsg and syslog() users.
> */
> if (console_trylock())
> console_unlock();
> - preempt_enable();
> lockdep_on();
> }
>
> @@ -2115,7 +2107,16 @@ int console_trylock(void)
> return 0;
> }
> console_locked = 1;
> - console_may_schedule = 0;
> + /*
> + * On !PREEMPT_COUNT kernels we can't reliably detect if it's safe
> + * to schedule -- e.g. calling printk while holding a spin_lock,
> + * because preempt_disable()/preempt_enable() are just barriers and
> + * don't modify preempt_count() there. console_may_schedule is
> + * always 0 on !PREEMPT_COUNT kernels.
> + */
> + console_may_schedule = !oops_in_progress &&
> + preemptible() &&
> + !rcu_preempt_depth();
> return 1;
We discussed this a lot but I am still a bit nervous ;-)
Avoid scheduling when oops_in_progress makes sense.
preemptible() takes care of preemption and IRQ contexts.
The comment above explains that it is safe to use here.
The check for rcu_preempt_depth() makes sense. But is it
safe, please?
rcu_preempt_depth() returns 0 if CONFIG_PREEMPT_RCU is not
enabled. It means that you are not able to detect RCU read
section and it might cause problems.
I rather add Paul into CC.
Best Regards,
Petr
next prev parent reply other threads:[~2016-02-11 14:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-23 8:15 [RFC][PATCH v3 0/4] let printk()/console_trylock() callers to cond_resched() Sergey Senozhatsky
2016-01-23 8:15 ` [RFC][PATCH v3 1/4] printk: move can_use_console out of console_trylock_for_printk Sergey Senozhatsky
2016-02-10 16:48 ` Petr Mladek
2016-02-11 7:57 ` Sergey Senozhatsky
2016-01-23 8:15 ` [RFC][PATCH v3 2/4] printk: do not console_cont_flush() on every jump to again Sergey Senozhatsky
2016-02-10 16:58 ` Petr Mladek
2016-02-11 8:03 ` Sergey Senozhatsky
2016-01-23 8:15 ` [RFC][PATCH v3 3/4] printk: remove console_trylock_for_printk Sergey Senozhatsky
2016-02-11 12:33 ` Petr Mladek
2016-01-23 8:15 ` [RFC][PATCH v3 4/4] printk: set may_schedule for some of console_trylock callers Sergey Senozhatsky
2016-02-11 14:41 ` Petr Mladek [this message]
2016-02-11 15:02 ` Sergey Senozhatsky
2016-02-11 16:10 ` Petr Mladek
2016-02-12 5:11 ` Sergey Senozhatsky
2016-02-03 3:49 ` [RFC][PATCH v3 0/4] let printk()/console_trylock() callers to cond_resched() 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=20160211144105.GM3305@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=calvinowens@fb.com \
--cc=davej@codemonkey.org.uk \
--cc=jack@suse.com \
--cc=kyle@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
--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 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®