* owner not checked in mutex_unlock
@ 2016-03-10 9:29 Chetan Nanda
2016-03-15 13:48 ` Cihangir Akturk
0 siblings, 1 reply; 4+ messages in thread
From: Chetan Nanda @ 2016-03-10 9:29 UTC (permalink / raw)
To: kernelnewbies
Hi,
As per book (Linux kernel development)
"Whoever locked a mutex must unlock it.That is, you cannot lock a mutex in one
context and then unlock it in another
"
but 'mutex_unlock' code is not checking the owner field at all.
Also, I tried with locking the mutex from normal process context and
unlocking from separate context (work context) and it is allowed
without any error from kernel.
Is it the mutex user responsibility to keep track of it? Ideally
mutex_unlock should check if owner is same as current?
Thanks,
Chetan Nanda
^ permalink raw reply [flat|nested] 4+ messages in thread
* owner not checked in mutex_unlock
2016-03-10 9:29 owner not checked in mutex_unlock Chetan Nanda
@ 2016-03-15 13:48 ` Cihangir Akturk
2016-03-15 13:59 ` Chetan Nanda
0 siblings, 1 reply; 4+ messages in thread
From: Cihangir Akturk @ 2016-03-15 13:48 UTC (permalink / raw)
To: kernelnewbies
On Thu, Mar 10, 2016 at 02:59:31PM +0530, Chetan Nanda wrote:
> Hi,
>
> As per book (Linux kernel development)
>
> "Whoever locked a mutex must unlock it.That is, you cannot lock a mutex in one
> context and then unlock it in another
> "
> but 'mutex_unlock' code is not checking the owner field at all.
If you look at the definition of mutex structure in mutex.h:50,
you'll see that the owner field will be compiled in if one of
CONFIG_DEBUG_MUTEXES or CONFIG_MUTEX_SPIN_ON_OWNER is defined.
And debug_mutex_unlock function in mutex-debug.c:72 will check
the owner and emits warning if it finds out that the mutex isn't
unlocked by its owner.
http://lxr.free-electrons.com/source/include/linux/mutex.h#L50
http://lxr.free-electrons.com/source/kernel/locking/mutex-debug.c#L72
>
> Also, I tried with locking the mutex from normal process context and
> unlocking from separate context (work context) and it is allowed
> without any error from kernel.
>
> Is it the mutex user responsibility to keep track of it? Ideally
> mutex_unlock should check if owner is same as current?
^ permalink raw reply [flat|nested] 4+ messages in thread
* owner not checked in mutex_unlock
2016-03-15 13:48 ` Cihangir Akturk
@ 2016-03-15 13:59 ` Chetan Nanda
2016-03-15 14:42 ` Cihangir Akturk
0 siblings, 1 reply; 4+ messages in thread
From: Chetan Nanda @ 2016-03-15 13:59 UTC (permalink / raw)
To: kernelnewbies
On 15-Mar-2016 7:19 pm, "Cihangir Akturk" <cakturk@gmail.com> wrote:
>
> On Thu, Mar 10, 2016 at 02:59:31PM +0530, Chetan Nanda wrote:
> > Hi,
> >
> > As per book (Linux kernel development)
> >
> > "Whoever locked a mutex must unlock it.That is, you cannot lock a mutex
in one
> > context and then unlock it in another
> > "
> > but 'mutex_unlock' code is not checking the owner field at all.
>
> If you look at the definition of mutex structure in mutex.h:50,
> you'll see that the owner field will be compiled in if one of
> CONFIG_DEBUG_MUTEXES or CONFIG_MUTEX_SPIN_ON_OWNER is defined.
>
> And debug_mutex_unlock function in mutex-debug.c:72 will check
> the owner and emits warning if it finds out that the mutex isn't
> unlocked by its owner.
>
> http://lxr.free-electrons.com/source/include/linux/mutex.h#L50
> http://lxr.free-electrons.com/source/kernel/locking/mutex-debug.c#L72
>
Thanks for your mail, in my kernel CONFIG_MUTEX_SPIN_ON_OWNER is enabled
but CONFIG_DEBUG_MUTEX is not enabled.
So there are no warning messages in logs.
Also, it don't seems to be a real performance hit by adding a single check
of owner with current in unlock code.
> >
> > Also, I tried with locking the mutex from normal process context and
> > unlocking from separate context (work context) and it is allowed
> > without any error from kernel.
> >
> > Is it the mutex user responsibility to keep track of it? Ideally
> > mutex_unlock should check if owner is same as current?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160315/d4f447f7/attachment.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* owner not checked in mutex_unlock
2016-03-15 13:59 ` Chetan Nanda
@ 2016-03-15 14:42 ` Cihangir Akturk
0 siblings, 0 replies; 4+ messages in thread
From: Cihangir Akturk @ 2016-03-15 14:42 UTC (permalink / raw)
To: kernelnewbies
On Tue, Mar 15, 2016 at 07:29:59PM +0530, Chetan Nanda wrote:
> On 15-Mar-2016 7:19 pm, "Cihangir Akturk" <cakturk@gmail.com> wrote:
> >
> > On Thu, Mar 10, 2016 at 02:59:31PM +0530, Chetan Nanda wrote:
> > > Hi,
> > >
> > > As per book (Linux kernel development)
> > >
> > > "Whoever locked a mutex must unlock it.That is, you cannot lock a mutex
> in one
> > > context and then unlock it in another
> > > "
> > > but 'mutex_unlock' code is not checking the owner field at all.
> >
> > If you look at the definition of mutex structure in mutex.h:50,
> > you'll see that the owner field will be compiled in if one of
> > CONFIG_DEBUG_MUTEXES or CONFIG_MUTEX_SPIN_ON_OWNER is defined.
> >
> > And debug_mutex_unlock function in mutex-debug.c:72 will check
> > the owner and emits warning if it finds out that the mutex isn't
> > unlocked by its owner.
> >
> > http://lxr.free-electrons.com/source/include/linux/mutex.h#L50
> > http://lxr.free-electrons.com/source/kernel/locking/mutex-debug.c#L72
> >
> Thanks for your mail, in my kernel CONFIG_MUTEX_SPIN_ON_OWNER is enabled
> but CONFIG_DEBUG_MUTEX is not enabled.
> So there are no warning messages in logs.
I am not an expert but this might be related to debug_locks variable
defined in http://lxr.free-electrons.com/source/lib/debug_locks.c#L24
>
> Also, it don't seems to be a real performance hit by adding a single check
> of owner with current in unlock code.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-15 14:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 9:29 owner not checked in mutex_unlock Chetan Nanda
2016-03-15 13:48 ` Cihangir Akturk
2016-03-15 13:59 ` Chetan Nanda
2016-03-15 14:42 ` Cihangir Akturk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.