Linux Trace Kernel
 help / color / mirror / Atom feed
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: Fri, 4 Dec 2026 09:33:09 -0500	[thread overview]
Message-ID: <44dc1de4-8a13-454d-9317-e129b0268bec@efficios.com> (raw)
In-Reply-To: <DNBNMFYXZ875.S209ZT3GLW1J@gmail.com>

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

  reply	other threads:[~2026-12-04 14:33 UTC|newest]

Thread overview: 9+ 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
2026-12-04  4:13       ` Alexei Starovoitov
2026-12-04 14:33         ` 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=44dc1de4-8a13-454d-9317-e129b0268bec@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