Commit 4fc92254 authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon

arm64: mm: Add asid_gen_match() helper

Add a macro to check if an ASID is from the current generation, since a
subsequent patch will introduce a third user for this test.
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
Link: https://lore.kernel.org/r/20200519175502.2504091-6-jean-philippe@linaro.orgSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent bd4298c7
...@@ -92,6 +92,9 @@ static void set_reserved_asid_bits(void) ...@@ -92,6 +92,9 @@ static void set_reserved_asid_bits(void)
bitmap_clear(asid_map, 0, NUM_USER_ASIDS); bitmap_clear(asid_map, 0, NUM_USER_ASIDS);
} }
#define asid_gen_match(asid) \
(!(((asid) ^ atomic64_read(&asid_generation)) >> asid_bits))
static void flush_context(void) static void flush_context(void)
{ {
int i; int i;
...@@ -220,8 +223,7 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu) ...@@ -220,8 +223,7 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
* because atomic RmWs are totally ordered for a given location. * because atomic RmWs are totally ordered for a given location.
*/ */
old_active_asid = atomic64_read(&per_cpu(active_asids, cpu)); old_active_asid = atomic64_read(&per_cpu(active_asids, cpu));
if (old_active_asid && if (old_active_asid && asid_gen_match(asid) &&
!((asid ^ atomic64_read(&asid_generation)) >> asid_bits) &&
atomic64_cmpxchg_relaxed(&per_cpu(active_asids, cpu), atomic64_cmpxchg_relaxed(&per_cpu(active_asids, cpu),
old_active_asid, asid)) old_active_asid, asid))
goto switch_mm_fastpath; goto switch_mm_fastpath;
...@@ -229,7 +231,7 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu) ...@@ -229,7 +231,7 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
raw_spin_lock_irqsave(&cpu_asid_lock, flags); raw_spin_lock_irqsave(&cpu_asid_lock, flags);
/* Check that our ASID belongs to the current generation. */ /* Check that our ASID belongs to the current generation. */
asid = atomic64_read(&mm->context.id); asid = atomic64_read(&mm->context.id);
if ((asid ^ atomic64_read(&asid_generation)) >> asid_bits) { if (!asid_gen_match(asid)) {
asid = new_context(mm); asid = new_context(mm);
atomic64_set(&mm->context.id, asid); atomic64_set(&mm->context.id, asid);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment