All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Mohr <andi@lisas.de>
To: Waiman Long <Waiman.Long@hpe.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH -v2 1/4] locking/drm/i915: Kill mutex trickery
Date: Fri, 26 Aug 2016 05:25:09 +0200	[thread overview]
Message-ID: <20160826032509.GA29502@rhlx01.hs-esslingen.de> (raw)

Hi,

[no properly binding reference via In-Reply-To: available thus manually re-creating, sorry]

> > But initerim I guess we could set our own owner field and check that
> > to keep the duct-tape from getting off completely.
> > -Daniel
> 
> Another alternative is to provide a standard mutex API that returns the
> owner of the lock if there is a real need for this capability. Peeking
> into lock internal is not a good practice.

>From personal experience here I would suggest that
the core issue here is that
this would create an inherently race-window-tainted API,
which clearly is something to be avoided:

The point is that the lock *owner* value is *volatile*
whenever it is *not* our own context instance
that is currently holding the lock
while querying this API
(i.e., thus not guaranteeing that the owner value will *not* be changed interim!),
since in such a situation
(not-privately-locked case!!)
lock ownership may change at any point from under
our just-observed result value.

Returning such inherently racy information from a publicly offered mutex API
is, errrrr, not so good, to put it rather mildly.

So, it seems the most we could provide
which would offer a reliable, non-racy API protocol
is something like:

static bool mutex_is_locked_by_us(struct mutex *mutex)

since during execution of this processing it would be guaranteed that:
- either we do have the lock, thus *we* *RELIABLY* are and will be "the owner"
- or we simply do not have it, thus *we* *RELIABLY* are and will be "not the owner"


[but note that in that case
this mutex API implementation code would have
a potentially unholy dependency on task stuff such as "current",
but which it probably already has anyway]

HTH,

Andreas Mohr

             reply	other threads:[~2016-08-26  3:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26  3:25 Andreas Mohr [this message]
2016-08-26  9:10 ` [RFC][PATCH -v2 1/4] locking/drm/i915: Kill mutex trickery Peter Zijlstra
2016-08-26 14:33   ` Waiman Long
  -- strict thread matches above, loose matches on Subject: below --
2016-08-25 18:37 [RFC][PATCH -v2 0/4] locking/mutex: Rewrite basic mutex Peter Zijlstra
2016-08-25 18:37 ` [RFC][PATCH -v2 1/4] locking/drm/i915: Kill mutex trickery Peter Zijlstra
2016-08-25 19:36   ` Daniel Vetter
2016-08-25 19:59     ` Waiman Long

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=20160826032509.GA29502@rhlx01.hs-esslingen.de \
    --to=andi@lisas.de \
    --cc=Waiman.Long@hpe.com \
    --cc=daniel.vetter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.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.