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:   Tue, 16 Apr 2019 18:15:22 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Waiman Long <longman@...hat.com>
Cc:     Ingo Molnar <mingo@...hat.com>, Will Deacon <will.deacon@....com>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, x86@...nel.org,
        Davidlohr Bueso <dave@...olabs.net>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Tim Chen <tim.c.chen@...ux.intel.com>,
        huang ying <huang.ying.caritas@...il.com>
Subject: Re: [PATCH v4 07/16] locking/rwsem: Implement lock handoff to
 prevent lock starvation

On Tue, Apr 16, 2019 at 05:49:37PM +0200, Peter Zijlstra wrote:
> See, if you first write that function in the form:
> 
> 	long new;
> 
> 	do {
> 		new = count | RWSEM_WRITER_LOCKED;
> 
> 		if (count & RWSEM_LOCK_MASK)
> 			return false;
> 
> 		if (list_is_singular(&sem->wait_list))
> 			new &= ~RWSEM_FLAG_WAITERS;
> 
> 	} while (atomic_long_try_cmpxchg_acquire(&sem->count, &count, new));
> 
> 	rwsem_set_owner(sem);
> 	return true;
> 
> And then add the HANDOFF bits like:
> 
> 	long new;
> 
> 	do {
> +		bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
> 
> +		new = (count | RWSEM_WRITER_LOCKED) & ~RWSEM_FLAG_HANDOFF;
> 
> 		if (count & RWSEM_LOCK_MASK) {
> +			if (has_handoff && wstate != WRITER_HANDOFF)
> +				return false;
> 			new |= RWSEM_FLAG_HANDOFF;
> 		}
> 
> +		if (has_handoff && wstate == WRITER_NOT_FIRST)
> +			return false;
> 
> 		if (list_is_singular(&sem->wait_list))
> 			new &= ~RWSEM_FLAG_WAITERS;
> 
> 	} while (atomic_long_try_cmpxchg_acquire(&sem->count, &count, new));

obviously that should be !

> 
> 	rwsem_set_owner(sem);
> 	return true;
> 
> it almost looks like sensible code.

Powered by blists - more mailing lists