From: Magnus Lindholm <linmag7@gmail.com>
To: richard.henderson@linaro.org, mattst88@gmail.com,
linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org
Cc: linmag7@gmail.com
Subject: [PATCH 0/3] alpha: load the MMU context on a direct mm switch
Date: Fri, 4 Sep 2026 18:23:28 +0200 [thread overview]
Message-ID: <20260904162424.376504-1-linmag7@gmail.com> (raw)
Three fixes for how alpha handles an mm that is switched in directly
rather than by the scheduler.
Patch 1 removes a stale clearing loop in migrate_flush_tlb_page() that
patch 2 depends on being gone. Patch 2 stops the TLB shootdown shortcut
from skipping a CPU that is borrowing an mm through kthread_use_mm(),
using mm->context[cpu] as a lockless publication of which CPUs may be
using the mm once patch 1 makes every write to it single-writer. Patch 3
then makes those direct mm switches actually load the MMU context, which
they currently do not: kthread_use_mm() and sched_force_init_mm() call
switch_mm_irqs_off() directly rather than through the scheduler, so the
hardware context is never installed and the task keeps running under
whatever was loaded before.
Reproducing it. A KUnit test was written for patch 3; source can be made
available on request. It uses kunit_attach_mm(), which calls
kthread_use_mm(), and then compares the loaded context against current->mm:
# alpha_use_mm_loads_context: EXPECTATION FAILED
Expected pcb->ptbr == mm_to_ptbr(current->mm), but
pcb->ptbr == 384 (0x180)
mm_to_ptbr(current->mm) == 12555 (0x310b)
0x180 is swapper_pg_dir: the kernel thread is running on the page tables
it had before the switch. The pcb.asn check in the same test passes,
which is the signature - ev5_switch_mm() does write the ASN, so it is the
load that is missing rather than the bookkeeping.
Do not detect this by dereferencing the borrowed mm's user addresses.
do_page_fault() resolves faults against current->mm and never reloads the
context, so with a stale ptbr the same access faults indefinitely.
Testing. ES40, EV68AL (21264C) Tsunami, 3 CPUs, v7.2-rc6.
before after
KUnit alpha_mmu_context 0 of 2 pass 2 of 2 pass
Patch 2 was measured rather than argued. Dropping the shortcut outright
is the obvious fix and costs far too much, so it tests mm->context[cpu]
instead:
fork/s, single-threaded shortcut as before 1360
shortcut removed 1050 -23%
patch 1 1360
Medians of seven, seven and twelve runs, spread 1352-1367, 1046-1052 and
1340-1366. The unchanged throughput shows the shortcut remains effective
for this workload, and neither the barrier nor the context marking shows
above the noise on this machine.
No regressions in the wider suite: glibc malloc-check 25/25 and four
related tests 10/10 each, the copy-on-write and writeback reproducers
from the previous series clean, and the same again under continuous
compaction with 359768 folios migrated during the run.
One adjacent problem is deliberately not addressed. enter_lazy_tlb() sets
pcb.ptbr for the borrowed mm without setting pcb.asn, so a kernel thread
switched in through PAL_swpctx loads one address space's page tables
against another's ASN. I have not found an observable failure from that
mismatch outside kernel-thread user accesses, which go through
kthread_use_mm() and are a matched pair after patch 2. Changing it would
mean touching the VPTB self-map behaviour on every lazy switch, with no
reproducer to justify the risk.
Patches 2 and 3 have no Cc: stable: kthread_use_mm() is the only
reachable caller on alpha through KUnit's kunit_attach_mm():
lib/tests/usercopy_kunit.c, lib/tests/kunit_iov_iter.c,
mm/kasan/kasan_test_c.c and drivers/android/tests/binder_alloc_kunit.c all
map user memory that way; sched_force_init_mm() and the driver callers
need configs or hardware alpha does not have. No ordinary alpha kernel
reaches either fix.
Patch 1 is different. migrate_flush_tlb_page() runs under plain
CONFIG_COMPACTION, and the clearing loop it removes can fire from ordinary
lazy-TLB retention on a single-threaded process's previous CPU, not just
kthread borrowing. The compaction stress testing above exercises that path
and has not caught it doing observable harm, so patch 1 also carries no Cc:
stable, but for that reason, not for being unreachable.
This applies on top of the "alpha: fix stale TLB translations breaking
copy-on-write and writeback" series and depends on it: patch 2 rewrites the
same flush_tlb_page() and flush_tlb_mm() shortcuts that series touches, and
does not apply without it.
https://lore.kernel.org/linux-alpha/20260810193902.3286353-1-linmag7@gmail.com/
Magnus Lindholm (3):
alpha: do not clear remote MMU contexts in migrate_flush_tlb_page()
alpha: do not skip TLB shootdown IPIs for kthread-borrowed mms
alpha: load the MMU context when switch_mm() switches the current task
arch/alpha/include/asm/mmu_context.h | 11 +++++--
arch/alpha/kernel/smp.c | 48 ++++++++++++++--------------
arch/alpha/mm/fault.c | 2 +-
arch/alpha/mm/tlbflush.c | 16 ----------
4 files changed, 34 insertions(+), 43 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
2.55.0
next reply other threads:[~2026-09-04 16:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 16:23 Magnus Lindholm [this message]
2026-09-04 16:23 ` [PATCH 1/3] alpha: do not clear remote MMU contexts in migrate_flush_tlb_page() Magnus Lindholm
2026-09-04 16:23 ` [PATCH 2/3] alpha: do not skip TLB shootdown IPIs for kthread-borrowed mms Magnus Lindholm
2026-09-04 16:23 ` [PATCH 3/3] alpha: load the MMU context when switch_mm() switches the current task Magnus Lindholm
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=20260904162424.376504-1-linmag7@gmail.com \
--to=linmag7@gmail.com \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=richard.henderson@linaro.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
all inboxes | Powered by JetHome®