All of lore.kernel.org
 help / color / mirror / Atom feed
From: cakturk@gmail.com (Cihangir Akturk)
To: kernelnewbies@lists.kernelnewbies.org
Subject: owner not checked in mutex_unlock
Date: Tue, 15 Mar 2016 15:48:57 +0200	[thread overview]
Message-ID: <20160315134857.GA12831@portege.ulakbim.gov.tr> (raw)
In-Reply-To: <CAPrYoTGO8DaT=sbEbix1He-aBztCfmO6SuiBCnzYvTsr71D8-Q@mail.gmail.com>

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?

  reply	other threads:[~2016-03-15 13:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10  9:29 owner not checked in mutex_unlock Chetan Nanda
2016-03-15 13:48 ` Cihangir Akturk [this message]
2016-03-15 13:59   ` Chetan Nanda
2016-03-15 14:42     ` Cihangir Akturk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160315134857.GA12831@portege.ulakbim.gov.tr \
    --to=cakturk@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.