alpha: fix stale TLB translations breaking copy-on-write and writeback
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest8 patches 5 repliesIn review
- v48 patches 5 repliesSuperseded
- v37 patches 4 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 7 patches | 2 replies | Superseded | |
| v1 | 7 patches | 0 replies | Superseded |
Changes in v5 from the cover letter
- No functional changes; only comments, changelogs and review metadata.
- Drop stale Message-ID trailers from patches 1 and 3-8.
- Mention do_shoot_lazy_tlb() in patch 1's comment and changelog, and explain that Alpha does not select MMU_LAZY_TLB_SHOOTDOWN.
- Clarify patch 2's hook comment: kthread_use_mm() can call it with preemption enabled, but Alpha has no kernel preemption.
- Refer explicitly to patch 1 in patch 3's changelog.
- Rewrap patch 4's opening paragraph.
- Add Matt's Reviewed-by to patch 2 following his v4 review; retain the existing tags on the other seven patches. Matt has now reviewed the whole series and compile-tested v4 at every commit on SMP and UP.
- Update the companion-series reference to MMU v4.
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/8 | alpha: load the MMU context when switch_mm() switches the current taskarch/ | +12 | 2 replies | |
| 2/8 | alpha: run check_mmu_context() from finish_arch_post_lock_switch()arch/ arch/ | +13 | 2 replies | |
| 3/8 | alpha: only use a targeted tbi() when the target mm is really currentarch/ | +2 | 0 replies | |
| 4/8 | alpha: invalidate the local context in flush_tlb_page()arch/ | +3 | 0 replies | |
| 5/8 | alpha: fix the local TLB invalidate in flush_tlb_page()arch/ | +2 | 0 replies | |
| 6/8 | alpha: fix the local TLB invalidate in the UP flush_tlb_page()arch/ | +2 | 0 replies | |
| 7/8 | alpha: invalidate the local context in flush_tlb_mm()arch/ | +3 | 0 replies | |
| 8/8 | alpha: invalidate the local context in flush_icache_user_page()arch/ | +3 | 0 replies |
Reviews trailers per patch
All 8 patches have a Reviewed-by or Acked-by.
| Patch | Matt Turner |
|---|---|
| 1/8 | T-b R-b |
| 2/8 | R-b |
| 3/8 | R-b |
| 4/8 | R-b |
| 5/8 | R-b |
| 6/8 | R-b |
| 7/8 | R-b |
| 8/8 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v5 0/8] alpha: fix stale TLB translations breaking copy-on-write and writeback
On Alpha, stale TLB translations can break copy-on-write and shared-mapping
writeback: a multi-threaded process can lose its own stores, read data belonging to its child, or lose writes through a shared file mapping. The copy-on-write failures need more than one CPU; the writeback failure also happens on a uniprocessor.
This is the first of two series, based on for-next at 33465f6ab697 ("alpha: support the remaining kernel compression formats"). Apply all eight patches here, then the two patches in "alpha: complete the direct-mm shootdown fixes" v4. There is no interleaving or external prerequisite for this first series.
Patch 1 moves here from v2 of the direct-switch series:
https://lore.kernel.org/linux-alpha/[email protected]/
It loads the context when switch_mm() is called directly for current, before kthread_use_mm() can reach the hook added by patch 2. This closes the dependency that previously required applying one patch from the other series first. Its functional code and Matt's review and test tags are unchanged; v5 expands its comment and changelog to name all three callers.
Patch 2 completes the deferred-ASN handshake from finish_arch_post_lock_switch(), including the first switch to a newly created task. Its old location after alpha_switch_to() was bypassed when a new task reached schedule_tail(), leaving asn_lock set.
The hook runs after interrupts are enabled. Set need_new_asn whether switch_mm() reused or allocated an ASN, so a deferred IPI cannot leave a live hardware context with a zero slot. This is also required before the second series uses those slots to decide whether to skip shootdowns. Drop the preemptible() guard: Alpha has no kernel preemption and the direct-switch callers do not sleep before the hook, including when RCU_STRICT_GRACE_PERIOD enables PREEMPT_COUNT.
Patches 3, 5 and 6 test current->mm before issuing targeted tbi(), since a lazy active_mm does not establish which ASN is actually loaded. Patches 4, 7 and 8 retire the calling CPU's context when the local current-context test fails; smp_call_function() only visits the other CPUs.
Patch 4 deliberately precedes patch 5. The missing else branch must be present before lazy callers are routed to it, so no intermediate commit loses their local invalidate. This matters on EV7 where a foreign-context tbi() appeared to work. The full-mm and icache callers retain their active_mm tests because those paths load a new context instead of using a targeted tbi(). The second series separately changes their IPI handlers to retire slots on lazy CPUs rather than keeping those slots visible.
Testing
The combined TLB v5 and MMU v4 stack passed cross-build checks with GCC 15.0.1 for arch/alpha/kernel/, arch/alpha/mm/, kernel/sched/core.o and kernel/kthread.o: ALPHA_GENERIC SMP and UP with COMPACTION=n, and SMP with COMPACTION=y, RCU_STRICT_GRACE_PERIOD=y and PREEMPT_COUNT=y. Full ES40 kernel builds with COMPACTION=y and COMPACTION=n also passed. All ten patches
pass checkpatch without warnings, and sequential application reproduces the committed trees at both series boundaries.
The combined TLB v5 and MMU v4 stack also passed an ES40 SMP run with three CPUs online and COMPACTION=y: nine lost-store rounds, nine stale-read rounds and ten mkclean4 writeback rounds on ext4. Compaction ran throughout; pgmigrate_success increased by 7424. No new kernel warnings or errors were observed in the captured log. This exercises the migration path. A second boot with COMPACTION=n also passed nine lost-store, nine stale-read and ten writeback rounds, exercising the direct flush_tlb_page() writeback path. No new kernel warnings or errors were observed in that run either. UP was compile-tested only. The historical results below are from earlier revisions.
Historical results from the earlier stale-TLB series, on an ES40, EV68AL (21264C) Tsunami with three CPUs, v7.2-rc2 and v7.2-rc6:
before after
smoke test, stale-read check 7 of 9 rounds 0 of 9
lost stores 11 of 40 0 of 400
writeback (mkclean4), SMP [*] 10 of 10 0 of 10 writeback (mkclean4), UP [*] every round 0 of 8
tst-malloc-fork-deadlock-
malloc-check 8 of 10 fail 25/25 pass
[*] CONFIG_COMPACTION=n.
alpha-cow-smoketest.c uses pthreads and forked children. Each thread owns its slot, and the main thread reads only after joining. Slots are 128 bytes apart so threads share a page; writing once and reading repeatedly avoids hiding stale translations with another faulting write. It does not fail when restricted to one CPU.
mkclean4.c exercises patches 4 and 5 together on SMP, and patch 6 on UP. It compares a small MAP_SHARED mapping with its backing file after background writeback, with the writer and flusher pinned to the same CPU on SMP. It needs root and COMPACTION=n. With COMPACTION=y, Alpha overrides ptep_clear_flush() to use migrate_flush_tlb_page(), so folio_mkclean() does not exercise flush_tlb_page(). Earlier unpatched COMPACTION=y runs passed 103 rounds; separate regression runs under continuous compaction migrated 368522 folios without failures.
Matt's earlier ES47 (EV7) testing on v7.3-rc1 with one CPU online found no regressions in fork/COW, writeback and gdb breakpoint tests on SMP and UP builds. He could not reproduce the unpatched writeback failure despite counters showing foreign-context targeted invalidates. The fix rests on the tbi() contract, not on every implementation exhibiting the failure.
Patches 7 and 8 still have no isolated reproducer. A gdb breakpoint exerciser covered patch 8's path for regressions. Matt suggested move_pages() on another process's hugetlb mapping, with the caller pinned to the CPU the target last ran on, as a possible reproducer for patch 7. That is unverified; the proposed hugetlb support is not in this base.
Changes since v4:
- No functional changes; only comments, changelogs and review metadata.
- Drop stale Message-ID trailers from patches 1 and 3-8.
- Mention do_shoot_lazy_tlb() in patch 1's comment and changelog, and explain that Alpha does not select MMU_LAZY_TLB_SHOOTDOWN.
- Clarify patch 2's hook comment: kthread_use_mm() can call it with preemption enabled, but Alpha has no kernel preemption.
- Refer explicitly to patch 1 in patch 3's changelog.
- Rewrap patch 4's opening paragraph.
- Add Matt's Reviewed-by to patch 2 following his v4 review; retain the existing tags on the other seven patches. Matt has now reviewed the whole series and compile-tested v4 at every commit on SMP and UP.
- Update the companion-series reference to MMU v4.
Changes since v3:
- Move the reviewed direct-load fix from MMU v2 to patch 1, making the TLB and MMU series applicable in sequence.
- Drop the post-switch hook's preemptible() guard.
- Set need_new_asn on both reused and newly allocated ASN paths.
- Put the missing local flush_tlb_page() else branch before changing
the current->mm test, as requested by Matt.
- Rebase on for-next and update numbering and dependency descriptions.
- Mention the proposed hugetlb caller without claiming a new reproducer.
- Drop the old review tag from the materially changed hook patch; retain tags on the other patches.
Thanks to Matt Turner for the review and EV7 testing.
v4: https://lore.kernel.org/linux-alpha/[email protected]/
v3: https://lore.kernel.org/linux-alpha/[email protected]/
Magnus Lindholm (8):
alpha: load the MMU context when switch_mm() switches the current task
alpha: run check_mmu_context() from finish_arch_post_lock_switch()
alpha: only use a targeted tbi() when the target mm is really current
alpha: invalidate the local context in flush_tlb_page()
alpha: fix the local TLB invalidate in flush_tlb_page()
alpha: fix the local TLB invalidate in the UP flush_tlb_page()
alpha: invalidate the local context in flush_tlb_mm()
alpha: invalidate the local context in flush_icache_user_page()
arch/alpha/include/asm/mmu_context.h | 28 +++++++++++++++++++++++++--- arch/alpha/include/asm/switch_to.h | 1 - arch/alpha/include/asm/tlbflush.h | 3 ++- arch/alpha/kernel/smp.c | 15 +++++++++++++-- 4 files changed, 40 insertions(+), 7 deletions(-)
base-commit: 33465f6ab697abceafd9a340067a544d551c4412
Signature · 1 line
2.43.0