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 C

Re: Question on mutex code

2015-03-15 Thread Davidlohr Bueso
On Sun, 2015-03-15 at 15:18 -0700, Davidlohr Bueso wrote: > Correct, in debug this is most likely true, yet safe because everything ^^^ false, again the same reasoning. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of

Re: Question on mutex code

2015-03-15 Thread Davidlohr Bueso
On Sun, 2015-03-15 at 23:49 +0200, Matthias Bonne wrote: > 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 c

Re: Question on mutex code

2015-03-15 Thread Rabin Vincent
On Sun, Mar 15, 2015 at 11:49:07PM +0200, Matthias Bonne wrote: > So both mutex_trylock() and mutex_unlock() always use the slow paths. > The slowpath for mutex_unlock() is __mutex_unlock_slowpath(), which > simply calls __mutex_unlock_common_slowpath(), and the latter starts > like this: > >

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 Davidlohr Bueso
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 mentioning, > thus the race is non existe

Re: Question on mutex code

2015-03-14 Thread Davidlohr Bueso
On Sun, 2015-03-15 at 01:05 +0200, Matthias Bonne wrote: > 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

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 functi

Re: Question on mutex code

2015-03-10 Thread Valdis . Kletnieks
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 > > __mutex_fastpath_

Re: Question on mutex code

2015-03-10 Thread Yann Droneaud
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 functions > __mutex_trylock_slowpath and __