Re: [PATCH v2 15/16] selftests/membarrier: Check the memory barriers of each thread
From: Mathieu Desnoyers
Date: Fri Dec 04 2026 - 09:33:27 EST
Hi Alexei,
On 2026-12-03, Alexei Starovoitov wrote:
> prev->mm barrier after the store to rq->curr hook
> ---------- ------------------------------------- ----------------
> another mm write_cr3() in switch_mm_irqs_off() tp_btf/tlb_flush
> NULL mmdrop_lazy_tlb_sched() in none
> finish_task_switch()
Thank you, tlb_flush works for the first row. switch_mm_irqs_off()
emits it with TLB_FLUSH_ON_TASK_SWITCH right after each CR3 write.
Planned for the next round:
- Clear the owed barrier in your tlb_flush program, loaded only on
x86. This replaces the kprobes on the CR3 writes.
- Remove the kprobe on the smp_mb() of switch_mm_irqs_off(). This
smp_mb() runs only when the CPU was in lazy TLB mode, so after a
task without mm. That is your second row.
> NULL: I don't see a hook, but it's one branch.
I would rather keep a kprobe for this row. It is the most intricate
part of the check, for two reasons:
- When a kernel thread borrowed the mm of the next task, the switch
writes CR3 only if the TLB went out of date meanwhile. The barrier
it always executes is the drop of the lazy mm reference in
finish_task_switch(). It is an atomic_dec_and_test(), or an
smp_mb() when CONFIG_MMU_LAZY_TLB_REFCOUNT is off. Only comments tie
it to membarrier, in mmdrop(), mmdrop_lazy_tlb() and
finish_task_switch().
- The core serialization after a kernel thread is there too:
membarrier_mm_sync_core_before_usermode(). Patch 16 checks it.
Without a hook there, the check of this switch must be dropped.
global_expedited_lazy_tlb would then check only the IPIs.
So the plan for the next round is to probe only finish_task_switch(),
on x86-64. Patch 15 probes its locked instructions. Patch 16 also
probes its sync_core(). sites[] then has one entry in patch 15, and
two in patch 16. read_kernel(), scan_function(), probe_sites(), the
cookies and the "probe hits were lost" warning stay.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com