From: Yadong Qi <yadong.qi@linux.alibaba.com>
To: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
ying.huang@linux.alibaba.com
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, ryan.roberts@arm.com,
robh@kernel.org, gregkh@linuxfoundation.org,
ptg-linux-kernel@linux.alibaba.com, yadong.qi@linux.alibaba.com,
stable@vger.kernel.org
Subject: [PATCH] arm64: fixmap: fix missing break-before-make in __set_fixmap()
Date: Mon, 23 Nov 2026 17:35:05 +0800 [thread overview]
Message-ID: <20261123093505.974-1-yadong.qi@linux.alibaba.com> (raw)
__set_fixmap() installs a new PTE with __set_pte() but never invalidates
the TLB; only the clear path calls flush_tlb_kernel_range(). The
dsb(ishst)/isb that __set_pte() emits makes the new PTE visible to the
table walker but does not invalidate stale TLB entries. Overwriting a
still-valid slot therefore leaves the old translation cached and
violates break-before-make: accesses may keep hitting the old output
address, and changing the attributes of a cached entry can trigger TLB
conflict aborts or CONSTRAINED UNPREDICTABLE behaviour.
Two in-tree callers overwrite a valid FIX_EARLYCON_MEM_BASE slot:
- earlycon: earlycon_map() maps the UART before match->setup() runs.
If setup fails, con->write is unset, or the DT reg-io-width is
unsupported, the slot stays valid but no console is registered. The
console_is_registered() guard only blocks successful registrations,
so a later attempt (e.g. a failed DT earlycon followed by earlycon=
on the command line) remaps the slot to a different UART.
- samsung_tty: apple_s5l_early_console_setup() overrides the
just-installed entry from PROT_DEVICE_nGnRE (FIXMAP_PAGE_IO) to
PROT_DEVICE_nGnRnE on the normal successful boot path.
Both are valid-to-valid changes (different output address or memory
type), which arm64 requires to be break-before-make.
Fix this in __set_fixmap() by invalidating any existing valid mapping
up front: clear the old PTE and flush the TLB, then install the new PTE
only when setting. The old translation is gone before the new one is
created, so the two can never coexist in the TLB. A first-time mapping
(old entry invalid) skips the invalidation and pays no extra cost, and
clearing a slot is handled by the same step.
This belongs in the callee, as on x86: __set_fixmap() there calls
set_pte_vaddr(), which flushes the TLB unconditionally after writing the
PTE. x86 can flush after the write because it has no break-before-make
requirement; arm64 must invalidate and flush before installing the new
valid entry to avoid TLB conflict aborts.
Fixes: 9aac5887595b ("tty/serial: add generic serial earlycon")
Cc: stable@vger.kernel.org
Reported-by: Huang Ying <ying.huang@linux.alibaba.com>
Signed-off-by: Yadong Qi <yadong.qi@linux.alibaba.com>
---
arch/arm64/mm/fixmap.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c
index f66a0016dd02..5593d7e0d523 100644
--- a/arch/arm64/mm/fixmap.c
+++ b/arch/arm64/mm/fixmap.c
@@ -126,12 +126,19 @@ void __set_fixmap(enum fixed_addresses idx,
ptep = fixmap_pte(addr);
- if (pgprot_val(flags)) {
- __set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
- } else {
+ /*
+ * Break-before-make: when the slot still holds a valid mapping
+ * (e.g. earlycon re-mapping FIX_EARLYCON_MEM_BASE), invalidate the
+ * old entry and flush the TLB entries caching it before a new
+ * mapping is installed, so old and new translations never coexist.
+ */
+ if (pte_valid(__ptep_get(ptep))) {
__pte_clear(&init_mm, addr, ptep);
- flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
+ flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
}
+
+ if (pgprot_val(flags))
+ __set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
}
void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
--
2.43.0
reply other threads:[~2026-11-23 9:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123093505.974-1-yadong.qi@linux.alibaba.com \
--to=yadong.qi@linux.alibaba.com \
--cc=catalin.marinas@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=ptg-linux-kernel@linux.alibaba.com \
--cc=robh@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=will@kernel.org \
--cc=ying.huang@linux.alibaba.com \
/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®