All of lore.kernel.org
 help / color / mirror / Atom feed
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>
Subject: [PATCH 4/6] alpha: only use a targeted tbi() when the target mm is really current (UP)
Date: Sun,  9 Aug 2026 10:49:36 +0200	[thread overview]
Message-ID: <20260809085208.3262799-5-linmag7@gmail.com> (raw)
In-Reply-To: <20260809085208.3262799-1-linmag7@gmail.com>

The uniprocessor flush_tlb_page() has the same defect the previous patch
fixed for SMP:

	if (mm == current->active_mm)
		flush_tlb_current_page(mm, vma, addr);
	else
		flush_tlb_other(mm);

For a non-executable vma flush_tlb_current_page() issues tbi(2, addr),
which acts on the address space context currently loaded, so it reaches
the mm's translations only when that context belongs to it. Under lazy
TLB an idle or kernel task keeps the mm as its active_mm while a different
ASN is loaded, so the tbi() invalidates the wrong context and the stale
translation survives.

Use current->mm instead, as for SMP.

This is not theoretical on a uniprocessor. folio_mkclean() runs in the
writeback flusher kworker, which borrows the mm, and with one CPU that
kworker necessarily shares it with the thread holding the translation.  A
test that writes a small MAP_SHARED file while background writeback cleans
it loses data on every round: the mapping holds one value and the file
another.

flush_tlb_mm() and flush_icache_user_page() need no equivalent change
here.  Both use __load_new_mm_context(), which allocates and loads a fresh
context rather than relying on a targeted tbi() against whatever ASN
happened to be loaded.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/alpha/include/asm/tlbflush.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/include/asm/tlbflush.h b/arch/alpha/include/asm/tlbflush.h
index 0c8529997f54..6593a64090f1 100644
--- a/arch/alpha/include/asm/tlbflush.h
+++ b/arch/alpha/include/asm/tlbflush.h
@@ -87,7 +87,14 @@ flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
 {
 	struct mm_struct *mm = vma->vm_mm;
 
-	if (mm == current->active_mm)
+	/*
+	 * tbi() acts on the address space context currently loaded, so it
+	 * reaches MM's translations only when a thread of MM is current.
+	 * Under lazy TLB an idle or kernel task keeps MM as its active_mm
+	 * with a different ASN loaded, and a targeted tbi() would then
+	 * invalidate the wrong context.
+	 */
+	if (mm == current->mm)
 		flush_tlb_current_page(mm, vma, addr);
 	else
 		flush_tlb_other(mm);
-- 
2.53.0


  parent reply	other threads:[~2026-08-09  8:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09  8:49 [PATCH 0/6] alpha: fix stale TLB translations breaking copy-on-write and writeback Magnus Lindholm
2026-08-09  8:49 ` [PATCH 1/6] alpha: run check_mmu_context() from finish_arch_post_lock_switch() Magnus Lindholm
2026-08-09  8:49 ` [PATCH 2/6] alpha: only use a targeted tbi() when the target mm is really current Magnus Lindholm
2026-08-09  8:49 ` [PATCH 3/6] alpha: fix the local TLB invalidate in flush_tlb_page() Magnus Lindholm
2026-08-09  8:49 ` Magnus Lindholm [this message]
2026-08-09  8:49 ` [PATCH 5/6] alpha: invalidate the local context in flush_tlb_mm() Magnus Lindholm
2026-08-09  8:49 ` [PATCH 6/6] 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=20260809085208.3262799-5-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 \
    /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.