3030 * "Fast Context Switch" i.e. no TLB flush on ctxt-switch
3131 *
3232 * Linux assigns each task a unique ASID. A simple round-robin allocation
33- * of H/w ASID is done using software tracker @asid_cache .
33+ * of H/w ASID is done using software tracker @asid_cpu .
3434 * When it reaches max 255, the allocation cycle starts afresh by flushing
3535 * the entire TLB and wrapping ASID back to zero.
3636 *
3737 * A new allocation cycle, post rollover, could potentially reassign an ASID
3838 * to a different task. Thus the rule is to refresh the ASID in a new cycle.
39- * The 32 bit @asid_cache (and mm->asid) have 8 bits MMU PID and rest 24 bits
39+ * The 32 bit @asid_cpu (and mm->asid) have 8 bits MMU PID and rest 24 bits
4040 * serve as cycle/generation indicator and natural 32 bit unsigned math
4141 * automagically increments the generation when lower 8 bits rollover.
4242 */
4747#define MM_CTXT_FIRST_CYCLE (MM_CTXT_ASID_MASK + 1)
4848#define MM_CTXT_NO_ASID 0UL
4949
50- #define hw_pid (mm ) (mm->context.asid & MM_CTXT_ASID_MASK)
50+ #define asid_mm (mm , cpu ) mm->context.asid[cpu]
51+ #define hw_pid (mm , cpu ) (asid_mm(mm, cpu) & MM_CTXT_ASID_MASK)
5152
52- extern unsigned int asid_cache ;
53+ DECLARE_PER_CPU (unsigned int , asid_cache );
54+ #define asid_cpu (cpu ) per_cpu(asid_cache, cpu)
5355
5456/*
5557 * Get a new ASID if task doesn't have a valid one (unalloc or from prev cycle)
5658 * Also set the MMU PID register to existing/updated ASID
5759 */
5860static inline void get_new_mmu_context (struct mm_struct * mm )
5961{
62+ const unsigned int cpu = smp_processor_id ();
6063 unsigned long flags ;
6164
6265 local_irq_save (flags );
@@ -71,11 +74,11 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
7174 * first need to destroy the context, setting it to invalid
7275 * value.
7376 */
74- if (!((mm -> context . asid ^ asid_cache ) & MM_CTXT_CYCLE_MASK ))
77+ if (!((asid_mm ( mm , cpu ) ^ asid_cpu ( cpu ) ) & MM_CTXT_CYCLE_MASK ))
7578 goto set_hw ;
7679
7780 /* move to new ASID and handle rollover */
78- if (unlikely (!(++ asid_cache & MM_CTXT_ASID_MASK ))) {
81+ if (unlikely (!(++ asid_cpu ( cpu ) & MM_CTXT_ASID_MASK ))) {
7982
8083 flush_tlb_all ();
8184
@@ -84,15 +87,15 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
8487 * If the container itself wrapped around, set it to a non zero
8588 * "generation" to distinguish from no context
8689 */
87- if (!asid_cache )
88- asid_cache = MM_CTXT_FIRST_CYCLE ;
90+ if (!asid_cpu ( cpu ) )
91+ asid_cpu ( cpu ) = MM_CTXT_FIRST_CYCLE ;
8992 }
9093
9194 /* Assign new ASID to tsk */
92- mm -> context . asid = asid_cache ;
95+ asid_mm ( mm , cpu ) = asid_cpu ( cpu ) ;
9396
9497set_hw :
95- write_aux_reg (ARC_REG_PID , hw_pid (mm ) | MMU_ENABLE );
98+ write_aux_reg (ARC_REG_PID , hw_pid (mm , cpu ) | MMU_ENABLE );
9699
97100 local_irq_restore (flags );
98101}
@@ -104,10 +107,24 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
104107static inline int
105108init_new_context (struct task_struct * tsk , struct mm_struct * mm )
106109{
107- mm -> context .asid = MM_CTXT_NO_ASID ;
110+ int i ;
111+
112+ for_each_possible_cpu (i )
113+ asid_mm (mm , i ) = MM_CTXT_NO_ASID ;
114+
108115 return 0 ;
109116}
110117
118+ static inline void destroy_context (struct mm_struct * mm )
119+ {
120+ unsigned long flags ;
121+
122+ /* Needed to elide CONFIG_DEBUG_PREEMPT warning */
123+ local_irq_save (flags );
124+ asid_mm (mm , smp_processor_id ()) = MM_CTXT_NO_ASID ;
125+ local_irq_restore (flags );
126+ }
127+
111128/* Prepare the MMU for task: setup PID reg with allocated ASID
112129 If task doesn't have an ASID (never alloc or stolen, get a new ASID)
113130*/
@@ -131,11 +148,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
131148 */
132149#define activate_mm (prev , next ) switch_mm(prev, next, NULL)
133150
134- static inline void destroy_context (struct mm_struct * mm )
135- {
136- mm -> context .asid = MM_CTXT_NO_ASID ;
137- }
138-
139151/* it seemed that deactivate_mm( ) is a reasonable place to do book-keeping
140152 * for retiring-mm. However destroy_context( ) still needs to do that because
141153 * between mm_release( ) = >deactive_mm( ) and
0 commit comments