Re: [PATCH 2/2] hazptr: Introduce CONFIG_HAZPTR_DEBUG misuse detection

From: Mathieu Desnoyers

Date: Thu Jul 09 2026 - 14:59:45 EST


On 2026-07-09 14:47, Paul E. McKenney wrote:
On Thu, Jul 09, 2026 at 02:29:33PM -0400, Mathieu Desnoyers wrote:
Introduce Hazard Pointers debug assert, which detects misuse of hazard
pointers, namely failure to detach the hazard pointer from its owner
thread before releasing it from a different thread.

Prints the following to the console when a failure is detected:

Thank you, Mathieu!

I am testing this one first to verify the debugging, and then I will
test the patch 1/2 hazptrtorture.c changes to verify the fix.

We are going to need to carefully document the hazard-pointer handling
rules! ;-)

Good point!

So the general rule for the hazptr API is that the hazptr context
is attached to the task that does the hazptr acquire.

The scheduler integration is responsible for ensuring that the
hazptr context is moved to a backup slot in case of context switch,
which takes care of handling task migrations without user intervention.

The case for which the user needs to explicitly invoke "detach from
task" is when the hazptr context is handed off to a _different_ task.
In that case the scheduler really cannot help, so it needs to be
done explicitly.

The debug code I proposed here discovers two scenarios:

- Release vs acquire are done on different tasks without explicit detach
from task (user error),
- Release vs acquire are done on different CPUs, without scheduler
context switch in between. This could happen if the user has
a confused hazptr context ownership model.

Thanks,

Mathieu

--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com