From: Linu Cherian <linu.cherian@arm.com>
To: Sayali Kulkarni <sk@gentwo.org>
Cc: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, will@kernel.org,
ryan.roberts@arm.com, yang@os.amperecomputing.com, cl@gentwo.org,
sskulkarni@amperecomputing.com
Subject: Re: [PATCH v2] arm64: tlbflush: Reset active_cpu on ASID rollover
Date: Thu, 18 Jun 2026 20:51:05 +0530 [thread overview]
Message-ID: <ajQM4bkKfWdPowpM@a079125.arm.com> (raw)
In-Reply-To: <20260612232254.2856649-1-sk@gentwo.org>
Hi,
On Fri, Jun 12, 2026 at 04:21:06PM -0700, Sayali Kulkarni wrote:
> From: Sayali Kulkarni <sskulkarni@amperecomputing.com>
>
> 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@amperecomputing.com> (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);
Can the above store race with the store to active_cpu in another thread,
that updates it to ACTIVE_CPU_MULTIPLE ?
Lets say we have two threads both initially running in CPU 0,
Thread 1: Runs in CPU 0
Encounters a rollover, updates mm->context.active_cpu to ACTIVE_CPU_NONE and
updates mm->context.id to new asid.
Thread 2: Scheduled to run on CPU 1 for the first time
Observes the updated mm->context.id that belongs to the current
generation(after the rollover) and hence proceeds to switch_mm_fastpath
and ends up updating the active_cpu to ACTIVE_CPU_MULTIPLE.
If Thread 1 and Thread 2 races, then active_cpu can get corrupted ?
The reason this could be possible is that, write to active_cpu and
mm->context.id can get reordered and we need to enforce ordering for
correctness ?
Do you see this as a valid scenario ?
--
Thanks,
Linu Cherian.
prev parent reply other threads:[~2026-06-18 15:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 21:34 arm64: tlbflush: Reset active_cpu on ASID rollover sk
2026-06-09 21:34 ` [PATCH 1/2] arm64: tlbflush: Don't broadcast if mm was only active on local cpu sk
2026-06-11 15:29 ` Catalin Marinas
2026-06-14 9:44 ` Will Deacon
2026-06-09 21:34 ` [PATCH 2/2] arm64: tlbflush: Reset active_cpu on ASID rollover sk
2026-06-10 20:57 ` kernel test robot
2026-06-11 15:37 ` Catalin Marinas
2026-06-12 23:21 ` [PATCH v2] " Sayali Kulkarni
2026-06-18 15:21 ` Linu Cherian [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=ajQM4bkKfWdPowpM@a079125.arm.com \
--to=linu.cherian@arm.com \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ryan.roberts@arm.com \
--cc=sk@gentwo.org \
--cc=sskulkarni@amperecomputing.com \
--cc=will@kernel.org \
--cc=yang@os.amperecomputing.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