lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 9 Apr 2015 09:53:11 +0200
From:	Ingo Molnar <mingo@...nel.org>
To:	Jason Low <jason.low2@...com>
Cc:	Peter Zijlstra <peterz@...radead.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Davidlohr Bueso <dave@...olabs.net>,
	Tim Chen <tim.c.chen@...ux.intel.com>,
	Aswin Chandramouleeswaran <aswin@...com>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] locking/rwsem: Use a return variable in
 rwsem_spin_on_owner()


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

> On Thu, 2015-04-09 at 07:37 +0200, Ingo Molnar wrote:
> 
> > The 'break' path does not seem to be equivalent, we used to do:
> > 
> > > -			rcu_read_unlock();
> > > -			return false;
> > 
> > and now we'll do:
> > 
> > > +			ret = false;
> > ...
> > > +	if (!READ_ONCE(sem->owner)) {
> > > +		long count = READ_ONCE(sem->count);
> > 
> > it's harmless (we do one more round of checking), but that's not an 
> > equivalent transformation and slows down the preemption trigger a 
> > (tiny) bit, because the chance that we actually catch the lock when 
> > breaking out early is vanishingly small. (It might in fact do the 
> > wrong thing in returning true if need_resched() is set and we've 
> > switched owners in that small window.)
> > 
> > Given how dissimilar the return path is in this case, I'm not sure 
> > it's worth sharing it. This might be one of the few cases where 
> > separate return statements is the better solution.
> 
> I also preferred the multiple returns for the rwsem variant to avoid
> needing to check sem->owner when it should go to slowpath, as you
> mentioned.
> 
> Now that I think of it though, if we want to have just one return path,
> we can still do that if we add an "out" label.

That's the usual pattern we use, but:

> -		/* abort spinning when need_resched or owner is not running */
> +		/* Abort spinning when need_resched or owner is not running. */
>  		if (!owner->on_cpu || need_resched()) {
>  			rcu_read_unlock();
> -			return false;
> +			ret = false;
> +			goto out;
>  		}

The point is to generally unify the 'out' paths - i.e. to merge it 
with the rcu_read_unlock() as well, so that we have really simple 
gotos and only a single exit path.
 
That's not really doable here without extra overhead AFAICS, so I'd 
suggest we leave it alone ...

I have applied your other patch.

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ