From: Kunwu Chan <kunwu.chan@gmail.com>
To: paulmck@kernel.org, corbet@lwn.net, mingo@redhat.com,
frederic@kernel.org, neeraj.upadhyay@kernel.org,
josh@joshtriplett.org, urezki@gmail.com, dave@stgolabs.net,
lianux.mm@gmail.com
Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com,
will@kernel.org, peterz@infradead.org, boqun@kernel.org,
npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk,
luc.maranget@inria.fr, akiyks@gmail.com, dlustig@nvidia.com,
joelagnelf@nvidia.com, skhan@linuxfoundation.org,
rdunlap@infradead.org, longman@redhat.com, rostedt@goodmis.org,
mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com,
qiang.zhang@linux.dev, kunwu.chan@gmail.com,
brads@mainlining.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, lkmm@lists.linux.dev,
linux-doc@vger.kernel.org, rcu@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH RFC v2 06/15] hazptr: elide redundant first drain pass
Date: Sat, 3 Oct 2026 01:08:38 +0800 [thread overview]
Message-ID: <20261002170847.3653663-7-kunwu.chan@gmail.com> (raw)
In-Reply-To: <20261002170847.3653663-1-kunwu.chan@gmail.com>
Each scan cycle drained both wildcard generations: the
unpublished "other" generation (pass 1) and the pre-flip current
generation (pass 2). Pass 1 is not needed for correctness, so
flip the wildcard first and drain only the old generation while
building the Bloom filter.
An acquire that read the old wildcard before the flip may publish
it into its slot after the drain has passed that slot. Such a
straggling acquire cannot have loaded the pre-unpublish pointer;
see the following LKMM test for the ordering argument.
Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
kernel/hazptr.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/kernel/hazptr.c b/kernel/hazptr.c
index 799784f698ed..86336f229f57 100644
--- a/kernel/hazptr.c
+++ b/kernel/hazptr.c
@@ -365,24 +365,19 @@ static bool hazptr_scan_walk(void *watch, struct hazptr_bloom *bloom)
}
/*
- * Wait until no per-CPU slot or overflow-list slot holds @wc.
- * Callers must ensure that the wildcard value in use by new acquires
- * differs from @wc, so that the set of slots holding @wc only
- * shrinks, which guarantees forward progress.
- */
-static void hazptr_drain_wildcard(void *wc)
-{
- while (hazptr_scan_walk(wc, NULL))
- cond_resched();
-}
-
-/*
- * Move pending waiters to ->scanning and perform a two-phase
- * wildcard scan shared by all waiters.
+ * Move pending waiters to ->scanning, flip the wildcard, then
+ * drain the old generation while collecting observed addresses
+ * into the Bloom filter. New acquires use the new generation,
+ * so old-generation slots normally only drain.
+ *
+ * An acquire that read the old wildcard before the flip may
+ * publish it after the scanner has passed its slot, but cannot
+ * have loaded the pre-unpublish pointer. See
+ * Documentation/litmus-tests/hazptr/hazptr-wildcard-flip-escape.litmus.
*/
static void hazptr_scan_do_cycle(void)
{
- void *scan_wildcard, *old_wildcard;
+ void *old_wildcard;
struct hazptr_waiter *w, *n;
LIST_HEAD(done);
@@ -397,16 +392,11 @@ static void hazptr_scan_do_cycle(void)
return;
}
- /* Pass 1: drain the unpublished wildcard. */
- scan_wildcard = flip_wildcard(READ_ONCE(hazptr_wildcard));
- hazptr_drain_wildcard(scan_wildcard);
-
- /* Flip so new acquires use the new generation. */
- WRITE_ONCE(hazptr_wildcard, scan_wildcard);
- old_wildcard = flip_wildcard(scan_wildcard);
+ old_wildcard = READ_ONCE(hazptr_wildcard);
+ WRITE_ONCE(hazptr_wildcard, flip_wildcard(old_wildcard));
/*
- * Pass 2: drain the old wildcard while collecting observed
+ * Drain the old wildcard while collecting observed
* addresses into the Bloom filter.
*/
while (hazptr_scan_walk(old_wildcard, &hazptr_scan.bloom))
--
2.43.0
next prev parent reply other threads:[~2026-10-02 17:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 17:08 [PATCH RFC v2 00/15] hazptr: batch synchronize operations through a shared scan Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 01/15] hazptr: add shared scan kthread Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 02/15] hazptr: use Bloom filter for shared scan waiters Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 03/15] hazptr: scan all per-CPU slots before overflow lists Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 04/15] hazptr: add scoped_guard() support Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 05/15] hazptr: add debug option to force the acquire slow path Kunwu Chan
2026-10-02 17:08 ` Kunwu Chan [this message]
2026-10-02 17:08 ` [PATCH RFC v2 07/15] Documentation/litmus-tests: add hazptr wildcard-flip escape test Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 08/15] locking/lockdep: use hazptr to wait for dynamic key lookups Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 09/15] rcuscale: add hazptr scale type Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 10/15] hazptr: fix kernel-doc of hazptr_release() Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 11/15] Documentation/litmus-tests: add hazptr acquire-before-scan test Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 12/15] hazptrtorture: add slowpath and lockdep scenarios Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 13/15] hazptrtorture: add READERS4 and READERS0 torture configs Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 14/15] hazptrtorture: add 128- and 256-CPU configs Kunwu Chan
2026-10-02 17:08 ` [PATCH RFC v2 15/15] selftests/rcutorture: add hazptr torture test script Kunwu Chan
2026-10-02 17:12 ` [PATCH RFC v2 00/15] hazptr: batch synchronize operations through a shared scan 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=20261002170847.3653663-7-kunwu.chan@gmail.com \
--to=kunwu.chan@gmail.com \
--cc=akiyks@gmail.com \
--cc=boqun@kernel.org \
--cc=brads@mainlining.org \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=dhowells@redhat.com \
--cc=dlustig@nvidia.com \
--cc=frederic@kernel.org \
--cc=j.alglave@ucl.ac.uk \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=josh@joshtriplett.org \
--cc=lianux.mm@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lkmm@lists.linux.dev \
--cc=longman@redhat.com \
--cc=luc.maranget@inria.fr \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=npiggin@gmail.com \
--cc=parri.andrea@gmail.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=stern@rowland.harvard.edu \
--cc=urezki@gmail.com \
--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®