From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Boqun Feng <boqun@kernel.org>
Subject: [PATCH RFC v2 24/24] hazptr: Upgrade kernel-doc headers
Date: Wed, 15 Jul 2026 17:18:09 -0700 [thread overview]
Message-ID: <20260716001809.11084-24-paulmck@kernel.org> (raw)
In-Reply-To: <23e34c2e-67fd-45da-b130-e70a131a59ea@paulmck-laptop>
Upgrade the kernel-doc headers for hazptr_acquire(), hazptr_release(),
and hazptr_detach_from_task().
[ paulmck: s/hazptr_detach_from_task/hazptr_detach/ per Mathieu. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Boqun Feng <boqun@kernel.org>
---
include/linux/hazptr.h | 75 ++++++++++++++++++++++++++++++++++++------
1 file changed, 65 insertions(+), 10 deletions(-)
diff --git a/include/linux/hazptr.h b/include/linux/hazptr.h
index 70db3ca7b95be0..80232eb6a592d5 100644
--- a/include/linux/hazptr.h
+++ b/include/linux/hazptr.h
@@ -75,12 +75,16 @@ DECLARE_PER_CPU(struct hazptr_percpu_slots, hazptr_percpu_slots);
void *__hazptr_acquire(struct hazptr_ctx *ctx, void * const * addr_p);
-/*
- * hazptr_synchronize: Wait until @addr is released from all slots.
+/**
+ * hazptr_synchronize: Wait for release from hazard-pointer protection
+ *
+ * @addr: The address to be released from hazard-pointer protection
*
- * Wait to observe that each slot contains a value that differs from
- * @addr before returning.
- * Should be called from preemptible context.
+ * Wait for the specified @addr to be released from protection from all
+ * hazard pointers. The caller should make @addr inaccessible to all
+ * hazard-pointer readers before invoking this function.
+ *
+ * Must be called from preemptible context.
*/
void hazptr_synchronize(void *addr);
@@ -126,6 +130,28 @@ void hazptr_promote_to_backup_slot(struct hazptr_ctx *ctx, struct hazptr_slot *s
ctx->slot = backup_slot;
}
+/**
+ * hazptr_detach - Allow a hazard pointer to be released in some other context
+ *
+ * @ctx: The hazard-pointer context to be detached.
+ *
+ * By default, a given hazptr_acquire() and the corresponding
+ * hazptr_release() must run in a single execution context, for example,
+ * the context of a single task or a single interrupt handler. When you
+ * have acquired a hazard pointer in one context and need to release it
+ * in another, you must invoke hazptr_detach() on that hazard pointer's
+ * context. It is permissible to invoke hazptr_detach() multiple times
+ * on the same @ctx while it is protecting the same pointer, however,
+ * the first invocation absolutely must be in the same context that did
+ * the hazptr_acquire(), and must take place after the return from that
+ * hazptr_acquire().
+ *
+ * For example, if a hazard pointer is acquired by a task and released
+ * by a timer handler, that task would need to pass the hazard pointer's
+ * context to hazptr_detach() after return from the hazptr_acquire() and
+ * before arming the timer (or at least before the handler had a chance
+ * to access that hazard-pointer context).
+ */
static inline
void hazptr_detach(struct hazptr_ctx *ctx)
{
@@ -160,12 +186,25 @@ void hazptr_note_context_switch(void)
}
}
-/*
- * hazptr_acquire: Load pointer at address and protect with hazard pointer.
+/**
+ * hazptr_acquire - Load pointer at address and protect with hazard pointer.
+ *
+ * @ctx: The hazard-pointer context to be passed to hazptr_release().
+ * @addr_p: Pointer to the pointer that is to be hazard-pointer protected.
*
* Load @addr_p, and protect the loaded pointer with hazard pointer.
- * When using hazptr_acquire from interrupt handlers, the acquired slots
- * need to be released before returning from the interrupt handler.
+ * This protection is roughly similar to (but way faster than) that of a
+ * reference counter, and ends with a later call to hazptr_release().
+ *
+ * By default, the call to hazptr_release() must be running in the same
+ * execution context as the corresponding hazptr_acquire(), for example,
+ * within the same task or interrupt handler. When it is necessary to
+ * instead call hazptr_release() from some other context, pass @ctx to
+ * hazptr_detach() in the original context after invoking hazptr_acquire()
+ * but before making the hazard pointer available to that other context.
+ *
+ * It is not permissible to invoke hazptr_acquire() twice on the same @ctx
+ * without an intervening hazptr_release().
*
* Returns a non-NULL protected address if the loaded pointer is non-NULL.
* Returns NULL if the loaded pointer is NULL.
@@ -233,7 +272,23 @@ void hazptr_release_debug(struct hazptr_ctx *ctx, void *addr)
static inline void hazptr_release_debug(struct hazptr_ctx *ctx, void *addr) { }
#endif
-/* Release the protected hazard pointer from @slot. */
+/**
+ * hazptr_release - Release the specified hazard pointer
+ *
+ * @ctx: The hazard-pointer context that was passed to hazptr_acquire().
+ * @addr_p: The pointer that is to be hazard-pointer unprotected.
+ *
+ * Release the protected hazard pointer recorded in @ctx.
+ *
+ * By default, hazptr_release() must execute in the same execution context
+ * that invoked the corresponding hazptr_acquire(), for example, within the
+ * same task or the same interrupt handler. However, if this restriction
+ * is problematic for your use case, please see hazptr_detach().
+ *
+ * It is permissible (though unwise from a maintainability viewpoint)
+ * to invoke hazptr_release() twice on the same @ctx without an intervening
+ * hazptr_acquire().
+ */
static inline
void hazptr_release(struct hazptr_ctx *ctx, void *addr)
{
--
2.40.1
prev parent reply other threads:[~2026-07-16 0:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 0:18 [PATCH RFC v2 0/24] Simple hazard-pointer implementation and torture tests Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 01/24] hazptr: Implement Hazard Pointers Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 02/24] hazptr: Add refscale test Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 03/24] torture: Add a hazptrtorture.c torture test Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 04/24] hazptrtorture: Add testing of on-stack hazptr_ctx structures Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 05/24] hazptrtorture: Add microsecond-scale sleep in readers Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 06/24] hazptrtorture: Enable system-independent CPU overcommit Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 07/24] torture: Add a stutter_will_wait() function Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 08/24] hazptrtorture: Use mnemonic local variables for context information Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 09/24] hazptrtorture: Split hazptr_torture_reader_tail() from hazptr_torture_reader() Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 10/24] hazptrtorture: Add kthread to release deferred hazard pointers Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 11/24] hazptrtorture: Defer release of " Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 12/24] hazptrtorture: Add irq_acquire to acquire hazptr from irq Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 13/24] hazptrtorture: Use task_state_to_char() for task-state reporting Paul E. McKenney
2026-07-16 0:17 ` [PATCH RFC v2 14/24] hazptrtorture: Pass hazptr_pending to hazptr_torture_reader_tail() Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 15/24] hazptrtorture: Add the ability to disable the writer kthread Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 16/24] hazptrtorture: Add irq_release to release hazptr from irq Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 17/24] hazptrtorture: Accumulate operation statistics Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 18/24] doc: Add hazptrtorture module parameters Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 19/24] hazptr: Permit detaching hazard pointers from contexts Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 20/24] hazptrtorture: Detach deferred and IPIed hazard pointers Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 21/24] hazptr: Introduce CONFIG_HAZPTR_DEBUG misuse detection Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 22/24] hazptrtorture: Fix hazptr ownership issue Paul E. McKenney
2026-07-16 0:18 ` [PATCH RFC v2 23/24] hazptrtorture: Enable CONFIG_HAZPTR_DEBUG Paul E. McKenney
2026-07-16 0:18 ` Paul E. McKenney [this message]
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=20260716001809.11084-24-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=boqun@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.