mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>,
	linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
	Haakon Bugge <haakon.bugge@oracle.com>,
	David Laight <david.laight.linux@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Yafang Shao <laoar.shao@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH v3] locking/osq_lock: Ensure proper locking semantics for osq_lock/osq_unlock()
Date: Tue, 15 Sep 2026 10:26:55 +0200	[thread overview]
Message-ID: <20260915082655.GX4121339@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260914202102.551333-1-longman@redhat.com>

On Mon, Sep 14, 2026 at 04:21:02PM -0400, Waiman Long wrote:
> The osq_lock is special in the sense that lock transfer from one CPU to
> the next can happen either over the common optimistic_spin_queue.tail
> value with uncontended lock or over a lock waiter's own percpu
> optimistic_spin_node.locked flag when the lock is contended.
> 
> To ensure proper lock synchronization, we need to provide
> the acquire/release semantics for the osq_lock/osq_unlock()
> functions in both cases. This is currently the case for the
> common optimistic_spin_queue.tail value, but not for the percpu
> optimistic_spin_node.locked flag as the proper barriers can be missing.
> 
> The "node->locked" read in osq_lock() was relaxed by commit 036cc30c6b6a
> ("locking/osq: No need for load/acquire when acquire-polling") a while
> ago as the smp_load_acquire() loop was causing a performance hit due to
> the repeated acquire barriers in the loop and it argued that an earlier
> atomic_xchg() call could provide the needed barrier and reordering
> wasn't a problem in the way osq_lock is being used by mutex and rwsem
> for queuing purpose only. That atomic_xchg() barrier does not work
> as a proper acquire barrier for osq_lock() if the lock hasn't been
> acquired or isn't ready to be acquired when the barrier ends. So an
> acquire barrier is still needed in order to have proper locking semantics.
> 
> The performance impact stated in that patch is due to repeated issuance
> of acquire barrier which can be expensive depending on the architectures
> and the actual processor used. It was not clear what machine and what
> benchmark was being used to produce the performance data. Anyway, with
> the new smp_cond_load_acquire() helper, only one acquire barrier is
> issued at the end of the loop. So even if there is a performance impact,
> it should be less than a repeating one.
> 
> As for the two percpu optimistic_spin_node.locked setting in osq_unlock(),
> they are currently preceded by a full barrier xchg() call which can
> provide the needed release barrier. Add comments saying that a release
> barrier is needed for the proper functioning of the unlock operation
> to alert people from accidentally remove the barrier when the code is
> updated.
> 
> Fixes: 036cc30c6b6a ("locking/osq: No need for load/acquire when acquire-polling")
> Tested-by: Håkon Bugge <haakon.bugge@oracle.com>
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  kernel/locking/osq_lock.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> [v2] Reword the commit log and keep the WRITE_ONCE() in osq_unlock()
>      with comments.
> [v3] Fix the comment above smp_cond_load_acquire().

I still see no reason why this should be applied. Or even have this
Fixes tag.

  reply	other threads:[~2026-09-15  8:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 20:21 Waiman Long
2026-09-15  8:26 ` Peter Zijlstra [this message]
2026-09-15 17:53   ` Waiman Long
2026-09-15 18:08     ` David Laight
2026-09-15 20:29       ` Waiman Long
2026-09-16  7:33     ` Peter Zijlstra
2026-09-16  7:46     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915082655.GX4121339@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=boqun@kernel.org \
    --cc=dave@stgolabs.net \
    --cc=david.laight.linux@gmail.com \
    --cc=haakon.bugge@oracle.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®