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: glaubitz@physik.fu-berlin.de, mcree@orcon.net.nz,
ink@unseen.parts, macro@orcam.me.uk,
Magnus Lindholm <linmag7@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2 1/7] alpha: run check_mmu_context() from finish_arch_post_lock_switch()
Date: Mon, 10 Aug 2026 21:34:52 +0200 [thread overview]
Message-ID: <20260810193902.3286353-2-linmag7@gmail.com> (raw)
In-Reply-To: <20260810193902.3286353-1-linmag7@gmail.com>
check_mmu_context() clears asn_lock and acts on need_new_asn, but it
runs only as the tail of switch_to(), after alpha_switch_to() returns.
A newly forked task never gets there: its first context switch resumes
at ret_from_fork, which goes to schedule_tail() and then to user space
rather than returning to the code following alpha_switch_to(). A new
kernel thread reaches schedule_tail() the same way, through
ret_from_kernel_thread().
asn_lock is left set on that CPU, so the forked task runs user space
with it set and interrupts enabled. A TLB shootdown IPI arriving in
that window takes the deferred path, and the need_new_asn handshake
meant to cover that never runs.
finish_task_switch() calls finish_arch_post_lock_switch() with
preemption disabled, on the CPU that ran switch_mm(), so hooking
check_mmu_context() there completes the bookkeeping for both. The
existing call from switch_to() then becomes redundant, since
finish_task_switch() runs immediately afterwards and does the same
work, so drop it.
kthread_use_mm() and sched_force_init_mm() reach the same hook outside
the scheduler's preemption-disabled switch tail, where the CPU may have
changed since switch_mm(). check_mmu_context() acts on per-CPU state,
so testing preemptible() expresses the required condition directly
rather than naming particular callers.
One consequence is worth stating, because the TLB patches that follow
depend on it. After kthread_use_mm() the hook does nothing, so the
asn_lock that ev5_switch_mm() set stays on that CPU until the next real
context switch. A borrowed mm therefore has current->mm set while its
context is not loaded, and the shootdown handlers rely on asn_locked()
being true to take the conservative path for the whole of that window.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
arch/alpha/include/asm/mmu_context.h | 8 ++++++++
arch/alpha/include/asm/switch_to.h | 1 -
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/alpha/include/asm/mmu_context.h b/arch/alpha/include/asm/mmu_context.h
index eee8fe836a59..825d3b9605c9 100644
--- a/arch/alpha/include/asm/mmu_context.h
+++ b/arch/alpha/include/asm/mmu_context.h
@@ -181,6 +181,14 @@ do { \
#define check_mmu_context() do { } while(0)
#endif
+/* Per-CPU state: only safe while still on the switching CPU. */
+#define finish_arch_post_lock_switch finish_arch_post_lock_switch
+static inline void finish_arch_post_lock_switch(void)
+{
+ if (!preemptible())
+ check_mmu_context();
+}
+
__EXTERN_INLINE void
ev5_activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm)
{
diff --git a/arch/alpha/include/asm/switch_to.h b/arch/alpha/include/asm/switch_to.h
index 762b7f975310..35c4b2c9d992 100644
--- a/arch/alpha/include/asm/switch_to.h
+++ b/arch/alpha/include/asm/switch_to.h
@@ -9,7 +9,6 @@ extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct *);
#define switch_to(P,N,L) \
do { \
(L) = alpha_switch_to(virt_to_phys(&task_thread_info(N)->pcb), (P)); \
- check_mmu_context(); \
} while (0)
#endif /* __ALPHA_SWITCH_TO_H */
--
2.53.0
next prev parent reply other threads:[~2026-08-10 19:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 19:34 [PATCH v2 0/7] alpha: fix stale TLB translations breaking copy-on-write and writeback Magnus Lindholm
2026-08-10 19:34 ` Magnus Lindholm [this message]
2026-08-10 19:34 ` [PATCH v2 2/7] alpha: only use a targeted tbi() when the target mm is really current Magnus Lindholm
2026-08-10 19:34 ` [PATCH v2 3/7] alpha: fix the local TLB invalidate in flush_tlb_page() Magnus Lindholm
2026-08-10 19:34 ` [PATCH v2 4/7] alpha: invalidate the local context " Magnus Lindholm
2026-08-10 19:34 ` [PATCH v2 5/7] alpha: fix the local TLB invalidate in the UP flush_tlb_page() Magnus Lindholm
2026-08-10 19:34 ` [PATCH v2 6/7] alpha: invalidate the local context in flush_tlb_mm() Magnus Lindholm
2026-08-10 19:34 ` [PATCH v2 7/7] alpha: invalidate the local context in flush_icache_user_page() 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=20260810193902.3286353-2-linmag7@gmail.com \
--to=linmag7@gmail.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=ink@unseen.parts \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=macro@orcam.me.uk \
--cc=mattst88@gmail.com \
--cc=mcree@orcon.net.nz \
--cc=richard.henderson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox