On Tue, Feb 20, 2018 at 02:26:55PM +0100, Christian KÃnig wrote:
You might also want likely(ctx), since ww_mutex without ctx isThanks for the suggestion, going to do this.+static inline bool ww_mutex_is_owned_by(struct ww_mutex *lock,Much better than the previous version. If you want to bike-shed, you can
+ struct ww_acquire_ctx *ctx)
+{
+ if (ctx)
+ return likely(READ_ONCE(lock->ctx) == ctx);
+ else
+ return likely(__mutex_owner(&lock->base) == current);
+}
leave out the 'else' and unindent the last line.
a-typical I would think.
But that would be the ctx case, right? I'm not sure there is a lot ofI do worry about potential users of .ctx = NULL, though. It makes it farWell, one of the addressed use cases is indeed checking for recursive
too easy to do recursive locking, which is something we should strongly
discourage.
locking. But recursive locking is something rather normal for ww_mutex and
we are just exercising an existing code path.
!ctx use out there, and in that case it really is rather like a normal
mutex.
E.g. the most common use case for the ww_mutex is in the graphics driversRight, I remember that much.. :-)
where usespace sends us a list of buffer objects to work with.
Now when userspace sends us duplicates in that buffer list the expectation
is to get -EALREADY from ww_mutex_lock when we try to lock the same ww_mutex
twice.
The intention behind this function is now to a) be able to extend thoseOK, but neither case would in fact need the !ctx case right? That's just
checks to make sure user space doesn't sends us potentially harmful nonsense
and b) allow to check for recursion in TTM during buffer object eviction
which uses ww_mutex_trylock instead of ww_mutex_lock.
there for completeness sake?
But yes, I cannot think of a better fallback there either.