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]
Message-ID: <YIZ0+hNh0SMQoOkh@hirez.programming.kicks-ass.net>
Date:   Mon, 26 Apr 2021 10:08:26 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Waiman Long <longman@...hat.com>
Cc:     Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
        Boqun Feng <boqun.feng@...il.com>,
        linux-kernel@...r.kernel.org, Borislav Petkov <bp@...e.de>,
        Ali Saidi <alisaidi@...zon.com>,
        Steve Capper <steve.capper@....com>
Subject: Re: [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup

On Sun, Apr 25, 2021 at 04:06:37PM -0400, Waiman Long wrote:

>  void queued_write_lock_slowpath(struct qrwlock *lock)
>  {
> -	int cnts;
> +	int cnts = 0;
>  
>  	/* Put the writer into the wait queue */
>  	arch_spin_lock(&lock->wait_lock);
>  
>  	/* Try to acquire the lock directly if no reader is present */
>  	if (!atomic_read(&lock->cnts) &&
> -	    (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0))
> +	    atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED))
>  		goto unlock;

Would not something like:

	if (!(cnts = atomic_read(&lock->cnts)) &&
	    atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)
		goto unlock;

Be clearer?

>  
> -	/* Set the waiting flag to notify readers that a writer is pending */
> -	atomic_add(_QW_WAITING, &lock->cnts);
> +	/*
> +	 * Set the waiting flag to notify readers that a writer is pending
> +	 *
> +	 * As only one writer who is the wait_lock owner can set the waiting
> +	 * flag which will be cleared later on when acquiring the write lock,
> +	 * we can easily replace atomic_or() by an atomic_add() if there is
> +	 * an architecture where an atomic_add() performs better than an
> +	 * atomic_or().

That might be a little overboard on the comment, but sure :-) I don't
think there's any arch that doesn't have atomic_or(), like I wrote
elsewhere, the one that's often an issue is atomic_fetch_or().

> +	 */
> +	atomic_or(_QW_WAITING, &lock->cnts);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ