mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Boqun Feng" <boqun@kernel.org>
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Bradley Morgan" <brads@mainlining.org>,
	"Gary Guo" <gary@garyguo.net>, <rcu@vger.kernel.org>,
	<lkmm@lists.linux.dev>
Subject: Re: [PATCH hazptr 4/4] hazptr: Introduce "try acquire" fast path, fallback to overflow list
Date: Sun, 27 Sep 2026 23:39:00 +0100	[thread overview]
Message-ID: <DLQGJZK4LIAO.3TAY3HZ6PR76Z@garyguo.net> (raw)
In-Reply-To: <5c78c338-1be6-456b-b963-bcfc62748aab@efficios.com>

On Sun Sep 27, 2026 at 6:15 PM BST, Mathieu Desnoyers wrote:
> On 2026-09-27 12:40, Boqun Feng wrote:
>
>> I want to point out this is not true for the lockdep use case, because
>> the we need to protect a hash list deletion there, and we use the
>> address of the hash bucket there. It's proven fine in practice because
>> the readers are rare (we only call the reader is_dynamic_key() in
>> register_lock_class(), that is every time you have a new lock class to
>> register).
>> 
>> Maybe what we want to say here is that "if the users guarantee no steady
>> flow of the same hazard pointer value, we guarantee forward progress".
>> Thoughts?
>
> AFAIU, your approach to protect lockdep linked lists is to use the
> address of the hash bucket to protect the traversal. As this address is 
> invariant (global array item address), that address should be fine
> to fulfill hazptr requirements, but it has downsides: rather than
> protecting the specific nodes being retired, the whole hash chain is
> protected. This means that, as you point out, many readers retiring
> nodes from a given bucket (except the first node) could end up holding a
> continuous stream of hazptr for a given hazptr value, preventing
> progress of hazptr synchronize.
>
> It's also coarser: per-bucket rather than per-node.
>
> Am I missing something here ?
>
> One honest question: is this pattern something we expect to
> see often ? If so, then we may want to introduce a notion of
> hazptr protection "period" flip (similar to some RCU implementations),
> where we tag the low bit of the slot pointer (0 vs 1), and alternate
> between the two periods in synchronize. This would prevent a steady-flow
> of same-value readers from preventing synchronize forward progress.

Slightly off topic, but I have a use-case in mind (in case you're not already
aware) where the address is fixed like the lockdep class, but it does not suffer
the forward progress guarantee.

I have been wanting to use hazptr for revocable for quite a while (I think I
chatted with Boqun about this last LPC). For the revocable use case, the
protected pointer is fixed, however there is an additional boolean flag to
determine if the resource been revoked or not.

Something like this:

    void *revocable_try_access(struct revocable *rev) {
        struct hazptr_ctx ctx = {};
        if (READ_ONCE(rev->revoked))
            return NULL;
        // note the & cancels out with the * in acquire, so the address is fixed.
        hazptr_acquire(&ctx, &rev);
        if (READ_ONCE(rev->revoked))
            return NULL;
        return rev->res;
    }

    void revocable_revoke(struct revocable *rev) {
        WRITE_ONCE(rev->revoked, true);
        hazptr_synchronize(&rev);
    }

So while the address is fixed, we have a different field to do the unpublishing
part.

For some context, the current Rust revocable implementation uses RCU, but this
is limiting the case where it can be used. The current C revocable series in
https://lore.kernel.org/all/20260912123529.7951-1-tzungbi@kernel.org/ uses SRCU.

I think this use case is a good one for hazptr, in fact, I have encouraged Alvin
Sun to try it out and you can see an implementation (Rust) in here:
https://lore.kernel.org/rust-for-linux/20260326-b4-tyr-debugfs-v1-6-074badd18716@linux.dev/
Although, over the course of the year, we have been reducing the amount of
revocable usage and shifting to represent things with lifetime..

Best,
Gary

  parent reply	other threads:[~2026-09-27 22:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 15:51 [PATCH hazptr 0/4] Hazard pointer updates Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 1/4] hazptr: Fix two-phase hazptr_synchronize race with detach Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 2/4] compiler.h: Introduce ptr_eq() to preserve address dependency Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 3/4] Documentation: RCU: Refer to ptr_eq() Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 4/4] hazptr: Introduce "try acquire" fast path, fallback to overflow list Mathieu Desnoyers
2026-09-27 16:40   ` Boqun Feng
2026-09-27 17:15     ` Mathieu Desnoyers
2026-09-27 17:24       ` Boqun Feng
2026-09-27 17:36         ` Mathieu Desnoyers
2026-09-27 18:16           ` Boqun Feng
2026-09-27 17:26       ` Boqun Feng
2026-09-27 22:39       ` Gary Guo [this message]
2026-09-28  9:12         ` Boqun Feng
2026-09-28  9:27     ` Kunwu Chan
2026-09-27 16:07 ` [PATCH hazptr 0/4] Hazard pointer updates Bradley Morgan
2026-09-27 16:27   ` Mathieu Desnoyers
2026-09-27 16:33     ` Bradley Morgan
2026-09-27 16:45       ` Mathieu Desnoyers
2026-09-27 16:15 ` Boqun Feng
2026-09-27 16:20   ` Mathieu Desnoyers
2026-09-27 16:22     ` Bradley Morgan

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=DLQGJZK4LIAO.3TAY3HZ6PR76Z@garyguo.net \
    --to=gary@garyguo.net \
    --cc=boqun@kernel.org \
    --cc=brads@mainlining.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmm@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.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®