Skip to contentSkip to conversation

locking:mutex Print warning if trylock in irq context

PATCH In review gaurav jindal 2 participants 3 messages Dec 22, 2017 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 locking:mutex Print warning if trylock in irq context

Since mutex_trylock must not be called from interrupt context, a robustness can be added to this function by throwing a warning if it is called in interrupt context.
It would help to make debugging easier in case of undesired calling of this function.

---

kernel/locking/mutex.c +4 -1
index 858a075..fe1cace 100644
@@ -1176,7 +1176,10 @@ void __sched mutex_lock_io(struct mutex *lock)
  */
 int __sched mutex_trylock(struct mutex *lock)
 {
-	bool locked = __mutex_trylock(lock);
+	bool locked;
+
+	WARN_ONCE(in_irq(), "%s wrongly called in irq context", __func__);
+	locked = __mutex_trylock(lock);
 
 	if (locked)
 		mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
maintainer
#1 lore raw
Quoted 5 lines · gaurav jindal

Since mutex_trylock must not be called from interrupt context, a robustness can be added to this function by throwing a warning if it is called in interrupt context.
It would help to make debugging easier in case of undesired calling of this function.

Or you run with lockdep enabled and not make this thing slower for everybody.

#2 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · gaurav jindal

Since mutex_trylock must not be called from interrupt context, a robustness can be added to this function by throwing a warning if it is called in interrupt context.
It would help to make debugging easier in case of undesired calling of this function.

Or you run with lockdep enabled and not make this thing slower for everybody.

Got the point. thanks for making it clear and consideration.