From: Catalin Marinas <catalin.marinas@arm.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Lai Jiangshan <jiangshan.ljs@antgroup.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Thomas Huth <thuth@redhat.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm64: mm: Stop using the previous ASID for init_mm
Date: Wed, 25 Nov 2026 18:41:27 +0000 [thread overview]
Message-ID: <awcr1wwqmkr7ilXp@arm.com> (raw)
In-Reply-To: <20261027100231.31184-1-jiangshanlai@gmail.com>
On Tue, Oct 27, 2026 at 06:02:27PM +0800, Lai Jiangshan wrote:
> From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
>
> Switching to init_mm should prevent further accesses through the
> previous address space's translations.
>
> Commit e53f21bce4d3 ("arm64: Use the reserved TTBR0 if context switching
> to the init_mm") avoided installing init_mm.pgd as a user page table.
> At the time, the ASID was held in TTBR0, so installing the reserved
> TTBR0 also switched to ASID 0.
>
> Since commit 7655abb95386 ("arm64: mm: Move ASID from TTBR0 to TTBR1"),
> installing the reserved TTBR0 no longer changes the active ASID.
> Consequently, switching to init_mm leaves the CPU using the previous
> address space's ASID. An empty page table does not prevent TLB hits
> for that ASID.
>
> This can retain access beyond the lifetime of the backing pages.
> During fullmm teardown, user data pages can be freed before their
> cached translations are invalidated. If those pages are subsequently
> reused for kernel data, an erroneous uaccess that hits a surviving
> translation can read or corrupt that data instead of faulting.
>
> Fixes: 7655abb95386 ("arm64: mm: Move ASID from TTBR0 to TTBR1")
> Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
Sorry for the delay. I looked at this again and it is indeed a bug but I
doubt you can trigger it. It relies on some erroneous uaccess to the old
pages. It also doesn't bring new TLB entries associated with the wrong
ASID. The CPU hotplug window is pretty small. The efi_virtmap_unload()
can also end up with the init_mm if no user spare ran.
Worth fixing though.
> diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
> index 803b68758152..7e56099c5fbb 100644
> --- a/arch/arm64/include/asm/mmu_context.h
> +++ b/arch/arm64/include/asm/mmu_context.h
> @@ -235,15 +235,6 @@ enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
>
> static inline void __switch_mm(struct mm_struct *next)
> {
> - /*
> - * init_mm.pgd does not contain any user mappings and it is always
> - * active for kernel addresses in TTBR1. Just set the reserved TTBR0.
> - */
> - if (next == &init_mm) {
> - cpu_set_reserved_ttbr0();
> - return;
> - }
> -
> check_and_switch_context(next);
> }
>
> diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
> index 0f4a28b87469..a96ebe904dd7 100644
> --- a/arch/arm64/mm/context.c
> +++ b/arch/arm64/mm/context.c
> @@ -218,6 +218,16 @@ void check_and_switch_context(struct mm_struct *mm)
> unsigned int cpu;
> u64 asid, old_active_asid;
>
> + /*
> + * init_mm.pgd contains kernel mappings, so use the reserved page
> + * tables for TTBR0 and switch TTBR1 to ASID 0. Leave active_asids
> + * unchanged to preserve the ASID rollover bookkeeping.
> + */
> + if (mm == &init_mm) {
> + cpu_do_switch_mm(__pa_symbol(reserved_pg_dir), mm);
> + return;
> + }
I don't think we need the full cpu_do_switch_mm() machinery here. Can we
not simply set the reserved ASID in __switch_mm()? Something like:
if (next == &init_mm) {
unsigned long ttbr1 = read_sysreg(ttbr1_el1);
cpu_set_reserved_ttbr0_nosync();
write_sysreg(ttbr1 & ~TTBRx_EL1_ASID_MASK, ttbr1_el1);
isb();
return;
}
Or just add the above to a new cpu_set_reserved_ttbr0_asid() function
and call it. I think that's the only case where we need to set the
reserved ASID.
Thanks.
--
Catalin
prev parent reply other threads:[~2026-11-25 18:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 10:02 Lai Jiangshan
2026-10-29 21:04 ` Catalin Marinas
2026-11-20 10:48 ` Lai Jiangshan
2026-10-30 6:30 ` Anshuman Khandual
2026-10-30 10:15 ` Vladimir Murzin
2026-11-25 18:41 ` Catalin Marinas [this message]
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=awcr1wwqmkr7ilXp@arm.com \
--to=catalin.marinas@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=jiangshan.ljs@antgroup.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=thuth@redhat.com \
--cc=will@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
all inboxes | Powered by JetHome®