[PATCH v2] arm64: tlbflush: Reset active_cpu on ASID rollover

From: Sayali Kulkarni

Date: Fri Jun 12 2026 - 19:23:40 EST


From: Sayali Kulkarni <sskulkarni@xxxxxxxxxxxxxxxxxxx>

Hi Catalin,

Thank you for the review. I’ve addressed your feedback in v2:

- Moved `WRITE_ONCE(mm->context.active_cpu, ACTIVE_CPU_NONE)` from `check_and_switch_context()` to `new_context()` after the `set_asid` label. At this point, a brand new ASID has been allocated that no CPU has ever used, so the reset is safe even for multi-threaded processes where other CPUs may still be running with the old ASID via `reserved_asids`.
- Updated the commit message to correct the safety reasoning: `flush_context()` only sets `tlb_flush_pending`; it does not issue a global TLB flush.

Thanks,
Sayali


Once active_cpu flips to ACTIVE_CPU_MULTIPLE it never resets, even if
the process settles back to one CPU. Reset it to ACTIVE_CPU_NONE in
new_context() after a new ASID is allocated at the set_asid label.

At this point a brand new ASID has been assigned that no CPU has ever
used, so ACTIVE_CPU_NONE accurately reflects reality. Any other threads
of the same process continue running with the old ASID via
reserved_asids and are unaffected.

This gives processes a fresh chance at the local-only flush fast path
after each ASID generation rollover.

Signed-off-by: Sayali Kulkarni <sskulkarni@xxxxxxxxxxxxxxxxxxx> (Ampere)
---
arch/arm64/mm/context.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index f34ed78393e0..46c7fd07b9bf 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -209,6 +209,7 @@ static u64 new_context(struct mm_struct *mm)
set_asid:
__set_bit(asid, asid_map);
cur_idx = asid;
+ WRITE_ONCE(mm->context.active_cpu, ACTIVE_CPU_NONE);
return asid2ctxid(asid, generation);
}

--
2.47.3