On Sun, Aug 08 2021 at 23:01, Waiman Long wrote:
On 8/8/21 10:12 PM, Xiaoming Ni wrote:No. Putting it in __down_common() is wrong, because that covers only the
Semaphore is sleeping lock. Add might_sleep() to down*() familyI think it is simpler to just put a "might_sleep()" in __down_common()
(with exception of down_trylock()) to detect atomic context sleep.
@@ -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--;
which is the function where sleep can actually happen.
contended case.
But we want to cover the potential sleep, i.e. checking even in the
non-contended case, which is what might_sleep() is about.