From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>,
Aniket Gattani <aniketgattani@google.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
"Paul E. McKenney" <paulmck@kernel.org>,
bpf@vger.kernel.org, Naveen N Rao <naveen@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Masami Hiramatsu <mhiramat@kernel.org>,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 15/16] selftests/membarrier: Check the memory barriers of each thread
Date: Thu, 3 Dec 2026 11:44:46 -0500 [thread overview]
Message-ID: <c2c22a4d-c254-4247-9822-0773d03270dd@efficios.com> (raw)
In-Reply-To: <DN6E6AI3KW0Y.GIGIAPTDZFS@gmail.com>
Hi Alexei,
On 2026-11-27 18:45, Alexei Starovoitov wrote:
> A bunch of x86 specific kprobes?
> Wow. I haven't seen such a heavy duty selftest before.
> I'm glad that it works, but I asked my bot for a simpler solution...
>
> ipi_mb(), ipi_sync_core() and ipi_rseq() are straight-line code.
> smp_mb() is their first statement. A call of the handler is an
> executed barrier.
> csd_do_func() has trace_csd_function_entry(func, csd) right before
> func(info).
>
> count the IPIs there instead:
Thank you for the review and for the code.
I agree about the IPIs. On an SMP kernel, every call of a membarrier
IPI handler goes through csd_do_func(), also on the local CPU.
Your argument also holds for other kprobes of the test:
- The two smp_mb() of the system call, from guard(mb) in
membarrier_global_expedited() and membarrier_private_expedited().
These functions return before the guard only on an error, with one
online CPU, or when the mm has a single user. The test fails on an
error, and its mm always has several users. With one online CPU, it
already does not expect these barriers.
- The core serialization in ipi_sync_core() (patch 16). On x86,
sync_core_before_usermode() skips it only with page table isolation.
The test already skips this check then. The other architectures
serialize the core when they return to user-space, as
include/linux/sync_core.h says.
It does not hold for the scheduler barrier (scenario C in
kernel/sched/membarrier.c). This barrier comes after the store to
rq->curr, before the thread returns to user-space. membarrier sends no
IPI to a CPU which runs a kernel thread or a process it does not
target. A thread can be scheduled in on such a CPU just after
membarrier read rq->curr of that CPU. This barrier is then the only
one the thread gets.
This barrier is not at the entry of a function, nor at a tracepoint.
The comment after the store to rq->curr in __schedule() lists where
each architecture puts it. On x86-64 it is in switch_mm_irqs_off(), or
in finish_task_switch() after a kernel thread. Both functions reach it
only on some paths. sched_switch fires for every switch, with or
without the barrier. So your sched_switch program counts the
switches, not the barriers.
> read_kernel(), scan_function(), probe_sites(), sites[], the cookies,
> set_optprobes(), the signal handlers and the "probe hits were lost"
> warning go away.
Planned for the next round:
- Count the IPIs with your csd_function_entry program, on all
architectures. A call of ipi_sync_core() also counts as a core
serialization.
- Skip the IPI checks when the __ksym address of a handler is 0. This
happens with kernel.kptr_restrict = 2, which hides the addresses in
/proc/kallsyms even from root. Skip them on a !CONFIG_SMP kernel
too: kernel/up.c calls the handler without the tracepoint.
- Remove the kprobes of the IPI handlers and of the system call. This
also stops the whole test from skipping when the compiler inlines
membarrier_global_expedited().
- Keep the kprobes of the scheduler barrier, on x86-64 only. Other
architectures skip this check. So these stay, for x86-64:
read_kernel(), scan_function(), probe_sites(), sites[], the cookies
and the "probe hits were lost" warning.
- Skip only the scheduler checks when one of their sites cannot be
probed. Today, any such site makes the whole test skip.
- Remove set_optprobes() and its signal handlers, if the tests show no
lost IPI count with optimized kprobes. They exist because an
optimized kprobe runs its BPF program with interrupts on. The kprobe
of an IPI handler which interrupts that program is then missed. A
tracepoint program still runs there.
Is this split acceptable to you? Or do you see a way to observe the
scheduler barrier without kprobes on instructions?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2026-12-03 16:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 18:58 [PATCH v2 00/16] membarrier: fixes, selftests and documentation Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 15/16] selftests/membarrier: Check the memory barriers of each thread Mathieu Desnoyers
2026-11-27 19:15 ` sashiko-bot
2026-11-27 19:27 ` Mathieu Desnoyers
2026-11-27 23:45 ` Alexei Starovoitov
2026-12-03 16:44 ` Mathieu Desnoyers [this message]
2026-11-27 18:58 ` [PATCH v2 16/16] selftests/membarrier: Check the core serialization of the sync core command Mathieu Desnoyers
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=c2c22a4d-c254-4247-9822-0773d03270dd@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=alexei.starovoitov@gmail.com \
--cc=aniketgattani@google.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=naveen@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=shuah@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox