[PATCH 22/28] hazptrtorture: Fix hazptr ownership issue

From: Paul E. McKenney

Date: Fri Sep 18 2026 - 20:04:02 EST


From: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

hazptr_torture_acquire is invoked from IPI on remote CPUs. It needs to
immediately detach the hazptr from its local task so it can be released
from other tasks.

Without this fix, the hazptrtorture test fails loudly with a OOPS. It
passes with the fix applied.

[ This applies on top of linux-rcu dev branch at
commit e5ee2ea2d00ae5a0ca53ccf9c9100f2357e1bd08 ]

[ paulmck: s/hazptr_detach_from_task/hazptr_detach/ per Mathieu. ]

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Cc: Boqun Feng <boqun@xxxxxxxxxx>
Cc: <rcu@xxxxxxxxxxxxxxx>
Cc: <lkmm@xxxxxxxxxxxxxxx>
---
kernel/rcu/hazptrtorture.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/kernel/rcu/hazptrtorture.c b/kernel/rcu/hazptrtorture.c
index e21c5ce3d4dc..72aeb50668e9 100644
--- a/kernel/rcu/hazptrtorture.c
+++ b/kernel/rcu/hazptrtorture.c
@@ -370,6 +370,11 @@ static void hazptr_torture_acquire(void *hppp_in)
struct hazptr_pending *hppp = hppp_in;

hppp->hpp_htp = cur_ops->readlock(&hppp->hpp_hc);
+ /*
+ * Acquiring a hazard pointer from a remote CPU.
+ * Detach hazptr from its task so it can be released by another task.
+ */
+ hazptr_detach(&hppp->hpp_hc);
atomic_long_inc(per_cpu_ptr(&hazptr_torture_acquires_irq, raw_smp_processor_id()));
}

@@ -411,6 +416,10 @@ hazptr_torture_reader_tail(struct hazptr_pending *hppp, struct torture_random_st
preempt_enable();
if (irq_release && !(torture_random(trsp) % irq_release)) {
guard(preempt)();
+ /*
+ * Handling release from a remote CPU.
+ * Detach hazptr from its task so it can be released by another task.
+ */
hazptr_detach(&hppp->hpp_hc);
cpu = cpumask_next_wrap(smp_processor_id(), cpu_online_mask);
smp_call_function_single(cpu, hazptr_torture_release, hppp, 1);
@@ -429,6 +438,10 @@ static void hazptr_torture_defer(struct hazptr_pending *hppp, struct torture_ran
struct llist_head *llhp;

guard(preempt)();
+ /*
+ * Handling release from a remote CPU.
+ * Detach hazptr from its task so it can be released by another task.
+ */
hazptr_detach(&hppp->hpp_hc);
cpu = cpumask_next_wrap(cpu, cpu_online_mask);
llhp = per_cpu_ptr(&hazptr_pending, cpu);
--
2.40.1