linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] semaphore: Add might_sleep() to down_*() family
@ 2021-08-09  2:12 Xiaoming Ni
  2021-08-09  3:01 ` Waiman Long
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Xiaoming Ni @ 2021-08-09  2:12 UTC (permalink / raw)
  To: linux-kernel, peterz, mingo, will, longman, boqun.feng
  Cc: nixiaoming, wangle6, xiaoqian9, shaolexi

Semaphore is sleeping lock. Add might_sleep() to down*() family
(with exception of down_trylock()) to detect atomic context sleep.

Previously discussed with Peter Zijlstra, see link:
 https://lore.kernel.org/lkml/20210806082320.GD22037@worktop.programming.kicks-ass.net

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 kernel/locking/semaphore.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c
index 9aa855a96c4a..9ee381e4d2a4 100644
--- a/kernel/locking/semaphore.c
+++ b/kernel/locking/semaphore.c
@@ -54,6 +54,7 @@ void down(struct semaphore *sem)
 {
 	unsigned long flags;
 
+	might_sleep();
 	raw_spin_lock_irqsave(&sem->lock, flags);
 	if (likely(sem->count > 0))
 		sem->count--;
@@ -77,6 +78,7 @@ int down_interruptible(struct semaphore *sem)
 	unsigned long flags;
 	int result = 0;
 
+	might_sleep();
 	raw_spin_lock_irqsave(&sem->lock, flags);
 	if (likely(sem->count > 0))
 		sem->count--;
@@ -103,6 +105,7 @@ int down_killable(struct semaphore *sem)
 	unsigned long flags;
 	int result = 0;
 
+	might_sleep();
 	raw_spin_lock_irqsave(&sem->lock, flags);
 	if (likely(sem->count > 0))
 		sem->count--;
@@ -157,6 +160,7 @@ int down_timeout(struct semaphore *sem, long timeout)
 	unsigned long flags;
 	int result = 0;
 
+	might_sleep();
 	raw_spin_lock_irqsave(&sem->lock, flags);
 	if (likely(sem->count > 0))
 		sem->count--;
-- 
2.27.0


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

end of thread, other threads:[~2021-09-01  8:37 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09  2:12 [PATCH] semaphore: Add might_sleep() to down_*() family Xiaoming Ni
2021-08-09  3:01 ` Waiman Long
2021-08-09  3:51   ` Xiaoming Ni
2021-08-09 12:52     ` Waiman Long
2021-08-09 14:33       ` Xiaoming Ni
2021-08-13 17:27   ` Thomas Gleixner
2021-08-13 18:47     ` Waiman Long
2021-08-13 14:43 ` Will Deacon
2021-08-23  9:39 ` [tip: locking/core] locking/semaphore: " tip-bot2 for Xiaoming Ni
2021-08-31 11:13 ` [PATCH] semaphore: " Guenter Roeck
2021-08-31 11:39   ` Hanjun Guo
2021-08-31 12:20     ` Thomas Gleixner
2021-08-31 11:40   ` Peter Zijlstra
2021-08-31 12:13   ` Thomas Gleixner
2021-08-31 12:34     ` Will Deacon
2021-08-31 17:42     ` Guenter Roeck
2021-09-01  8:37     ` [tip: smp/urgent] drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION() tip-bot2 for Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).