Re: Question on mutex code

2015-03-15 Thread Matthias Bonne
On 03/16/15 00:10, Rabin Vincent wrote: On Sun, Mar 15, 2015 at 11:49:07PM +0200, Matthias Bonne wrote: So the counter is set to 1 before taking the spinlock, which I think might cause the race. Did I miss something? Yes, you miss the fact that __mutex_slowpath_needs_to_unlock() is 0 for the

Re: Question on mutex code

2015-03-15 Thread Matthias Bonne
On 03/15/15 03:09, Davidlohr Bueso wrote: On Sat, 2015-03-14 at 18:03 -0700, Davidlohr Bueso wrote: Good analysis, but not quite accurate for one simple fact: mutex trylocks _only_ use fastpaths (obviously just depend on the counter cmpxchg to 0), so you never fallback to the slowpath you are me

Re: Question on mutex code

2015-03-14 Thread Matthias Bonne
On 03/10/15 16:59, valdis.kletni...@vt.edu wrote: On Tue, 10 Mar 2015 14:03:59 +0100, Yann Droneaud said: Consider the following sequence of events: 0. Suppose a mutex is locked by task A and has no waiters. 1. Task B calls mutex_trylock(). 2. mutex_trylock() calls the architecture-specific

Re: Question on mutex code

2015-03-14 Thread Matthias Bonne
On 03/10/15 15:03, Yann Droneaud wrote: Hi, Le mercredi 04 mars 2015 à 02:13 +0200, Matthias Bonne a écrit : I am trying to understand how mutexes work in the kernel, and I think there might be a race between mutex_trylock() and mutex_unlock(). More specifically, the race is between the