From: Peter Zijlstra <peterz@infradead.org>
To: Byungchul Park <byungchul.park@lge.com>
Cc: willy@linux.intel.com, akpm@linux-foundation.org,
mingo@kernel.org, linux-kernel@vger.kernel.org,
akinobu.mita@gmail.com, jack@suse.cz,
sergey.senozhatsky.work@gmail.com, peter@hurleysoftware.com
Subject: Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up()
Date: Wed, 17 Feb 2016 11:40:49 +0100 [thread overview]
Message-ID: <20160217104049.GB25010@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1455700311-2308-1-git-send-email-byungchul.park@lge.com>
On Wed, Feb 17, 2016 at 06:11:51PM +0900, Byungchul Park wrote:
> change from v2 to v3
> - the way to solve it in v2 is racy, so I changed the approach entirely.
> - just make semaphore's trylock use spinlock's trylock.
>
> change from v1 to v2
> - remove unnecessary overhead by the redundant spin(un)lock.
>
> Since I faced a infinite recursive printk() bug, I've tried to propose
> patches the title of which is "lib/spinlock_debug.c: prevent a recursive
> cycle in the debug code". But I noticed the root problem cannot be fixed
> by that, through some discussion thanks to Sergey and Peter. So I focused
> on preventing the deadlock.
>
> -----8<-----
> From 43e029ca920890ac644e30d873be69cf5d01efdb Mon Sep 17 00:00:00 2001
> From: Byungchul Park <byungchul.park@lge.com>
> Date: Wed, 17 Feb 2016 17:22:18 +0900
> Subject: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up()
>
> One of semaphore acquisition functions, down_trylock() is implemented
> using raw_spin_lock_irqsave(&sem->lock) even though it's enough to use
> raw_spin_trylock_irqsave(). Furthermore, using raw_spin_lock_irqsave()
> can cause a unnecessary deadlock as described below. Just make it use
> the spinlock trylock to implement the semaphore trylock so that we can
> avoid the unnecessary deadlock happened.
>
> The scenario the bad thing can happen is,
>
> printk
> console_trylock
> console_unlock
> up_console_sem
> up
> raw_spin_lock_irqsave(&sem->lock, flags)
> __up
> wake_up_process
> try_to_wake_up
> raw_spin_lock_irqsave(&p->pi_lock)
> __spin_lock_debug
> spin_dump
> printk
> console_trylock
> raw_spin_lock_irqsave(&sem->lock, flags)
> >>> DEADLOCK <<<
>
> Signed-off-by: Byungchul Park <byungchul.park@lge.com>
Mucking with the semaphore implementation just because printk() is
terminally broken shite really doesn't fly.
next prev parent reply other threads:[~2016-02-17 10:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 9:11 Byungchul Park
2016-02-17 9:28 ` Ingo Molnar
2016-02-18 8:00 ` Byungchul Park
2016-03-09 2:00 ` Byungchul Park
2016-03-09 6:07 ` Byungchul Park
2016-03-10 0:38 ` Byungchul Park
2016-03-10 1:12 ` Byungchul Park
2016-02-17 10:40 ` Peter Zijlstra [this message]
2016-02-18 8:13 ` Byungchul Park
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=20160217104049.GB25010@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=byungchul.park@lge.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peter@hurleysoftware.com \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=willy@linux.intel.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
Powered by JetHome