LKML Archive on
 help / color / Atom feed
From: Davidlohr Bueso <>
Cc:,,, Davidlohr Bueso <>
Subject: [PATCH -tip] locking/mutex: Complain upon api misuse wrt interrupt context
Date: Thu, 24 Oct 2019 20:36:34 -0700
Message-ID: <> (raw)

Sprinkle warning checks, under CONFIG_DEBUG_MUTEXES. While the mutex
rules and semantics are explicitly documented, this allows to expose
any abusers and robustifies the whole thing. While trylock and unlock
are non-blocking, calling from irq context is still forbidden (lock
must be within the same context as unlock).

Signed-off-by: Davidlohr Bueso <>
 kernel/locking/mutex.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 468a9b8422e3..7e9c316c646c 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -733,6 +733,9 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne
 void __sched mutex_unlock(struct mutex *lock)
+	WARN_ON(in_interrupt());
 	if (__mutex_unlock_fast(lock))
@@ -1413,6 +1416,7 @@ int __sched mutex_trylock(struct mutex *lock)
 	DEBUG_LOCKS_WARN_ON(lock->magic != lock);
+	WARN_ON(in_interrupt());
 	locked = __mutex_trylock(lock);

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25  3:36 Davidlohr Bueso [this message]
2019-10-25  8:10 ` Peter Zijlstra
2019-10-25 17:27   ` Davidlohr Bueso
2019-10-30 10:03 ` [tip: locking/core] locking/mutex: Complain upon mutex API misuse in IRQ contexts tip-bot2 for Davidlohr Bueso

Reply instructions:

You may reply publically 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone