Re: [PATCH v2 15/16] selftests/membarrier: Check the memory barriers of each thread
From: Alexei Starovoitov
Date: Thu Dec 03 2026 - 23:13:22 EST
On Thu, Dec 03, 2026 at 08:44 AM Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx> wrote:
> Is this split acceptable to you? Or do you see a way to observe the
> scheduler barrier without kprobes on instructions?
Split is fine. I don't insist, but try get rid of kprobes...
sched_switch sets OWES_BARRIER in two cases. On x86-64:
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()
Another mm: loaded_mm != next.
NULL: I don't see a hook, but it's one branch.
Then read_kernel(), scan_function(), probe_sites(), sites[], the
cookies and the "probe hits were lost" warning can go away.
What is lost is the sync_core() check of patch 16 after a kernel thread.
tlb_flush is defined on x86 only. Hence the "?" in SEC(). Turn autoload
on for x86.
/* switch_mm_irqs_off() wrote CR3. */
SEC("?tp_btf/tlb_flush")
int BPF_PROG(tlb_flush, int reason)
{
struct cpu_state *state;
__u32 zero = 0;
if (reason != TLB_FLUSH_ON_TASK_SWITCH)
return 0;
state = bpf_map_lookup_elem(&cpu_state, &zero);
if (state)
state->owed = 0;
return 0;
}