Skip to content

Commit 3daa48d

Browse files
committed
ARC: [ASID] get_new_mmu_context() to conditionally allocate new ASID
ASID allocation changes/1 This patch does 2 things: (1) get_new_mmu_context() NOW moves mm->ASID to a new value ONLY if it was from a prev allocation cycle/generation OR if mm had no ASID allocated (vs. before would unconditionally moving to a new ASID) Callers desiring unconditional update of ASID, e.g.local_flush_tlb_mm() (for parent's address space invalidation at fork) need to first force the parent to an unallocated ASID. (2) get_new_mmu_context() always sets the MMU PID reg with unchanged/new ASID value. The gains are: - consolidation of all asid alloc logic into get_new_mmu_context() - avoiding code duplication in switch_mm() for PID reg setting - Enables future change to fold activate_mm() into switch_mm() Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent 5bd87ad commit 3daa48d

2 files changed

Lines changed: 25 additions & 33 deletions

File tree

‎arch/arc/include/asm/mmu_context.h‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ extern struct mm_struct *asid_mm_map[NUM_ASID + 1];
6969
extern int asid_cache;
7070

7171
/*
72-
* Assign a new ASID to task. If the task already has an ASID, it is
73-
* relinquished.
72+
* Get a new ASID if task doesn't have a valid one (unalloc or from prev cycle)
73+
* Also set the MMU PID register to existing/updated ASID
7474
*/
7575
static inline void get_new_mmu_context(struct mm_struct *mm)
7676
{
@@ -79,6 +79,17 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
7979

8080
local_irq_save(flags);
8181

82+
/*
83+
* Move to new ASID if it was not from current alloc-cycle/generation.
84+
*
85+
* Note: Callers needing new ASID unconditionally, independent of
86+
* generation, e.g. local_flush_tlb_mm() for forking parent,
87+
* first need to destroy the context, setting it to invalid
88+
* value.
89+
*/
90+
if (mm->context.asid <= asid_cache)
91+
goto set_hw;
92+
8293
/*
8394
* Relinquish the currently owned ASID (if any).
8495
* Doing unconditionally saves a cmp-n-branch; for already unused
@@ -99,9 +110,9 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
99110
* task with ASID from prev allocation cycle (before ASID roll-over).
100111
*
101112
* This might look wrong - if we are re-using some other task's ASID,
102-
* won't we use it's stale TLB entries too. Actually switch_mm( ) takes
113+
* won't we use it's stale TLB entries too. Actually the algorithm takes
103114
* care of such a case: it ensures that task with ASID from prev alloc
104-
* cycle, when scheduled will refresh it's ASID: see switch_mm( ) below
115+
* cycle, when scheduled will refresh it's ASID
105116
* The stealing scenario described here will only happen if that task
106117
* didn't get a chance to refresh it's ASID - implying stale entries
107118
* won't exist.
@@ -114,7 +125,8 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
114125
asid_mm_map[asid_cache] = mm;
115126
mm->context.asid = asid_cache;
116127

117-
write_aux_reg(ARC_REG_PID, asid_cache | MMU_ENABLE);
128+
set_hw:
129+
write_aux_reg(ARC_REG_PID, mm->context.asid | MMU_ENABLE);
118130

119131
local_irq_restore(flags);
120132
}
@@ -141,28 +153,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
141153
write_aux_reg(ARC_REG_SCRATCH_DATA0, next->pgd);
142154
#endif
143155

144-
/*
145-
* Get a new ASID if task doesn't have a valid one. Possible when
146-
* -task never had an ASID (fresh after fork)
147-
* -it's ASID was stolen - past an ASID roll-over.
148-
* -There's a third obscure scenario (if this task is running for the
149-
* first time afer an ASID rollover), where despite having a valid
150-
* ASID, we force a get for new ASID - see comments at top.
151-
*
152-
* Both the non-alloc scenario and first-use-after-rollover can be
153-
* detected using the single condition below: NO_ASID = 256
154-
* while asid_cache is always a valid ASID value (0-255).
155-
*/
156-
if (next->context.asid > asid_cache) {
157-
get_new_mmu_context(next);
158-
} else {
159-
/*
160-
* XXX: This will never happen given the chks above
161-
* BUG_ON(next->context.asid > MAX_ASID);
162-
*/
163-
write_aux_reg(ARC_REG_PID, next->context.asid | MMU_ENABLE);
164-
}
165-
156+
get_new_mmu_context(next);
166157
}
167158

168159
static inline void destroy_context(struct mm_struct *mm)

‎arch/arc/mm/tlb.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ noinline void local_flush_tlb_mm(struct mm_struct *mm)
258258
return;
259259

260260
/*
261-
* Workaround for Android weirdism:
262-
* A binder VMA could end up in a task such that vma->mm != tsk->mm
263-
* old code would cause h/w - s/w ASID to get out of sync
261+
* - Move to a new ASID, but only if the mm is still wired in
262+
* (Android Binder ended up calling this for vma->mm != tsk->mm,
263+
* causing h/w - s/w ASID to get out of sync)
264+
* - Also get_new_mmu_context() new implementation allocates a new
265+
* ASID only if it is not allocated already - so unallocate first
264266
*/
265-
if (current->mm != mm)
266-
destroy_context(mm);
267-
else
267+
destroy_context(mm);
268+
if (current->mm == mm)
268269
get_new_mmu_context(mm);
269270
}
270271

0 commit comments

Comments
 (0)