All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, WANG Xuerui <kernel@xen0n.name>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 08/16] LoongArch: membarrier: Add full memory barrier in switch_mm()
Date: Fri, 4 Dec 2026 09:35:36 -0500	[thread overview]
Message-ID: <054ad46a-46bd-4e04-8479-4bc3b19637fb@efficios.com> (raw)
In-Reply-To: <CAAhV-H4ybY_k2Erf1AQgOLXn0-MGSW5kosF+K3K2S7vuixtB0Q@mail.gmail.com>

Hi Huacai,

On 2026-12-04, Huacai Chen wrote:
> I should say sorry because my previous reply has some mistakes.
> Writing to PGDL/PGDH/ASID doesn't imply a "dbar 0", instead, it
> implies a "ibar 0".
> But "ibar 0" is also enough for the current purpose. It doesn't block
> previous read, but blocks previous write, and for hazard protection it
> flush (not just stall) the pipeline, so blocks succeeding read and
> write.
> So the effect is similar to "dbar 0b11000", and it will still be true
> in future (yes, I think our manuals should be updated).

Thank you for the correction.

I agree that "dbar 0b11000" is enough here. membarrier needs the
store to rq->curr to be ordered before the user-space accesses which
follow. That store is a write, so the reads which stay unordered do
not matter. I checked it with the Linux kernel memory model. I added
a fence which orders previous writes before all later accesses, and
nothing else. The membarrier scenario of patch 8 cannot fail with it.
It fails with "dbar 0b10010", the barrier of smp_store_release().
I can send these litmus tests if you want them.

The model assumes one more property. Before a later access runs, the
previous stores must be visible to the other CPUs. Ordering them on
the local CPU only is not enough. Is that what "blocks previous write"
means?

Two more questions:

1. Can this guarantee be written down, in the manual or in a document
   from Loongson which the kernel can cite? Without it, a later
   change to switch_mm_irqs_off() can drop these CSR writes, and
   nobody will know that membarrier needs them.

2. Does it also hold in a KVM guest, when the guest writes PGDL and
   ASID?

If the answers are yes, the planned next version drops this patch. It
adds a comment in atomic_update_pgd_asid() instead. The comment says
that membarrier relies on these CSR writes as a barrier, and cites
the document. Patch 10 ("Documentation/membarrier: Update the
per-architecture barrier list") then names these CSR writes as the
LoongArch barrier. Would you ack such a comment?

Until the guarantee is written down, I would rather keep the smp_mb().
It runs only when the next mm is registered for an expedited
membarrier command, so other processes do not pay for it.

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com

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

Thread overview: 29+ 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 ` Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 01/16] sched/membarrier: Fix stale runqueue state after a lazy mm switch Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 02/16] sched/membarrier: Report only completed registrations Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 03/16] selftests/membarrier: Rebuild the tests when their header changes Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 04/16] selftests/membarrier: Issue the sync core command in its test Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 05/16] selftests/membarrier: Run the tests on nohz_full kernels Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 06/16] selftests/membarrier: Test which CPUs the expedited commands interrupt Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 07/16] selftests/membarrier: Test command arguments and registration lifetime Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 08/16] LoongArch: membarrier: Add full memory barrier in switch_mm() Mathieu Desnoyers
2026-11-29  4:00   ` Huacai Chen
2026-12-03 16:41     ` Mathieu Desnoyers
2026-12-04  5:03       ` Huacai Chen
2026-12-04 14:35         ` Mathieu Desnoyers [this message]
2026-11-27 18:58 ` [PATCH v2 09/16] parisc: " Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 10/16] Documentation/membarrier: Update the per-architecture barrier list Mathieu Desnoyers
2026-11-27 18:58   ` Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 11/16] Documentation/features: Update the membarrier sync core requirements Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 12/16] x86/entry: Remove stale membarrier sync core comments Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 13/16] selftests/membarrier: Add litmus tests of the memory ordering Mathieu Desnoyers
2026-11-27 18:58 ` [PATCH v2 14/16] MAINTAINERS: Add the membarrier selftests to MEMBARRIER SUPPORT 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
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=054ad46a-46bd-4e04-8479-4bc3b19637fb@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.