public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation: kernel-locking: mutex_trylock cannot be used in interrupt context
@ 2010-08-18 22:08 Stefan Richter
  2010-08-19  0:52 ` Rusty Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Richter @ 2010-08-18 22:08 UTC (permalink / raw)
  To: linux-kernel, Rusty Russell, Matthew Wilcox; +Cc: Randy Dunlap, linux-doc

Chapter 6 is right about mutex_trylock, but chapter 10 wasn't.
This error was introduced during semaphore-to-mutex conversion of the
Unreliable guide. :-)

If user context which performs mutex_lock() or mutex_trylock() is
preempted by interrupt context which performs mutex_trylock() on the
same mutex instance, a deadlock occurs.  This is because these functions
do not disable local IRQs when they operate on mutex->wait_lock.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 Documentation/DocBook/kernel-locking.tmpl |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: b/Documentation/DocBook/kernel-locking.tmpl
===================================================================
--- a/Documentation/DocBook/kernel-locking.tmpl
+++ b/Documentation/DocBook/kernel-locking.tmpl
@@ -1922,9 +1922,12 @@ machines due to caching.
       <function>mutex_lock()</function>
       </para>
       <para>
-       There is a <function>mutex_trylock()</function> which can be
-       used inside interrupt context, as it will not sleep.
+       There is a <function>mutex_trylock()</function> which does not
+       sleep.  Still, it must not be used inside interrupt context since
+       its implementation is not safe for that.
        <function>mutex_unlock()</function> will also never sleep.
+       It cannot be used in interrupt context either since a mutex
+       must be released by the same task that acquired it.
       </para>
      </listitem>
     </itemizedlist>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Documentation: kernel-locking: mutex_trylock cannot be used in interrupt context
  2010-08-18 22:08 [PATCH] Documentation: kernel-locking: mutex_trylock cannot be used in interrupt context Stefan Richter
@ 2010-08-19  0:52 ` Rusty Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2010-08-19  0:52 UTC (permalink / raw)
  To: Stefan Richter; +Cc: linux-kernel, Matthew Wilcox, Randy Dunlap, linux-doc

On Thu, 19 Aug 2010 07:38:15 am Stefan Richter wrote:
> Chapter 6 is right about mutex_trylock, but chapter 10 wasn't.
> This error was introduced during semaphore-to-mutex conversion of the
> Unreliable guide. :-)
> 
> If user context which performs mutex_lock() or mutex_trylock() is
> preempted by interrupt context which performs mutex_trylock() on the
> same mutex instance, a deadlock occurs.  This is because these functions
> do not disable local IRQs when they operate on mutex->wait_lock.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>

I'm assuming Andrew Morton or Randy Dunlap will pick this up...

Thanks!
Rusty.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-19  0:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-18 22:08 [PATCH] Documentation: kernel-locking: mutex_trylock cannot be used in interrupt context Stefan Richter
2010-08-19  0:52 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox