Skip to content

Commit a3a5b76

Browse files
yeyunfeng-devctmarinas
authored andcommitted
arm64: mm: Rename asid2idx() to ctxid2asid()
The commit 0c8ea53 ("arm64: mm: Allocate ASIDs in pairs") introduce the asid2idx and idx2asid macro, but these macros are not really useful after the commit f88f42f ("arm64: context: Free up kernel ASIDs if KPTI is not in use"). The code "(asid & ~ASID_MASK)" can be instead by a macro, which is the same code with asid2idx(). So rename it to ctxid2asid() for a better understanding. Also we add asid2ctxid() macro, the contextid can be generated based on the asid and generation through this macro. Signed-off-by: Yunfeng Ye <[email protected]> Reviewed-by: Kefeng Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 7afccde commit a3a5b76

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

arch/arm64/mm/context.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static unsigned long *pinned_asid_map;
3535
#define ASID_FIRST_VERSION (1UL << asid_bits)
3636

3737
#define NUM_USER_ASIDS ASID_FIRST_VERSION
38-
#define asid2idx(asid) ((asid) & ~ASID_MASK)
39-
#define idx2asid(idx) asid2idx(idx)
38+
#define ctxid2asid(asid) ((asid) & ~ASID_MASK)
39+
#define asid2ctxid(asid, genid) ((asid) | (genid))
4040

4141
/* Get the ASIDBits supported by the current CPU */
4242
static u32 get_cpu_asid_bits(void)
@@ -120,7 +120,7 @@ static void flush_context(void)
120120
*/
121121
if (asid == 0)
122122
asid = per_cpu(reserved_asids, i);
123-
__set_bit(asid2idx(asid), asid_map);
123+
__set_bit(ctxid2asid(asid), asid_map);
124124
per_cpu(reserved_asids, i) = asid;
125125
}
126126

@@ -162,7 +162,7 @@ static u64 new_context(struct mm_struct *mm)
162162
u64 generation = atomic64_read(&asid_generation);
163163

164164
if (asid != 0) {
165-
u64 newasid = generation | (asid & ~ASID_MASK);
165+
u64 newasid = asid2ctxid(ctxid2asid(asid), generation);
166166

167167
/*
168168
* If our current ASID was active during a rollover, we
@@ -183,7 +183,7 @@ static u64 new_context(struct mm_struct *mm)
183183
* We had a valid ASID in a previous life, so try to re-use
184184
* it if possible.
185185
*/
186-
if (!__test_and_set_bit(asid2idx(asid), asid_map))
186+
if (!__test_and_set_bit(ctxid2asid(asid), asid_map))
187187
return newasid;
188188
}
189189

@@ -209,7 +209,7 @@ static u64 new_context(struct mm_struct *mm)
209209
set_asid:
210210
__set_bit(asid, asid_map);
211211
cur_idx = asid;
212-
return idx2asid(asid) | generation;
212+
return asid2ctxid(asid, generation);
213213
}
214214

215215
void check_and_switch_context(struct mm_struct *mm)
@@ -300,13 +300,13 @@ unsigned long arm64_mm_context_get(struct mm_struct *mm)
300300
}
301301

302302
nr_pinned_asids++;
303-
__set_bit(asid2idx(asid), pinned_asid_map);
303+
__set_bit(ctxid2asid(asid), pinned_asid_map);
304304
refcount_set(&mm->context.pinned, 1);
305305

306306
out_unlock:
307307
raw_spin_unlock_irqrestore(&cpu_asid_lock, flags);
308308

309-
asid &= ~ASID_MASK;
309+
asid = ctxid2asid(asid);
310310

311311
/* Set the equivalent of USER_ASID_BIT */
312312
if (asid && arm64_kernel_unmapped_at_el0())
@@ -327,7 +327,7 @@ void arm64_mm_context_put(struct mm_struct *mm)
327327
raw_spin_lock_irqsave(&cpu_asid_lock, flags);
328328

329329
if (refcount_dec_and_test(&mm->context.pinned)) {
330-
__clear_bit(asid2idx(asid), pinned_asid_map);
330+
__clear_bit(ctxid2asid(asid), pinned_asid_map);
331331
nr_pinned_asids--;
332332
}
333333

0 commit comments

Comments
 (0)