Re: [PATCH 2/2] locking/rwsem: Use a return variable in rwsem_spin_on_owner()

Ingo Molnar
2015-04-10T09:04:48Z

* Jason Low <jason.low2@hp.com> wrote:

> +static inline bool owner_running(struct rw_semaphore *sem, struct task_struct *owner)
> +{
> + bool ret;
> +
> +#ifdef CONFIG_DEBUG_PAGEALLOC
> + rcu_read_lock();
> +#endif
> + if (READ_ONCE(sem->owner) == owner) {
> + /*
> + * Ensure we emit the owner->on_cpu dereference
> + * after checking sem->owner still matches owner.
> + */
> + barrier();
> + ret = owner->on_cpu;
> + } else {
> + /* Owner changed. */
> + ret = false;
> + }
> +
> +#ifdef CONFIG_DEBUG_PAGEALLOC
> + rcu_read_unlock();
> +#endif
> + return ret;
> +}

So I really don't like this due to the assymetric RCU pattern. (Also,
the fact that we might read from already freed kernel memory here
needs big honking comments.)

But, I think we can do this differently, see the patch I just sent:

[PATCH] mutex: Speed up mutex_spin_on_owner() by not taking the RCU lock

that should I think work just as well, without having to introduce
owner_running() as the whole mutex_spin_on_owner() logic is kept
pretty simple.

Thanks,

Ingo