Skip to content

Commit 0b317c3

Browse files
committed
MIPS: mm: Add set_cpu_context() for ASID assignments
When we gain MMID support we'll be storing MMIDs as atomic64_t values and accessing them via atomic64_* functions. This necessitates that we don't use cpu_context() as the left hand side of an assignment, ie. as a modifiable lvalue. In preparation for this introduce a new set_cpu_context() function & replace all assignments with cpu_context() on their left hand side with an equivalent call to set_cpu_context(). To enforce that cpu_context() should not be used for assignments, we rewrite it as a static inline function. Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: linux-mips@vger.kernel.org
1 parent 42d5b84 commit 0b317c3

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

arch/mips/include/asm/mmu_context.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@ static inline u64 asid_first_version(unsigned int cpu)
8888
return ~asid_version_mask(cpu) + 1;
8989
}
9090

91-
#define cpu_context(cpu, mm) ((mm)->context.asid[cpu])
91+
static inline u64 cpu_context(unsigned int cpu, const struct mm_struct *mm)
92+
{
93+
return mm->context.asid[cpu];
94+
}
95+
96+
static inline void set_cpu_context(unsigned int cpu,
97+
struct mm_struct *mm, u64 ctx)
98+
{
99+
mm->context.asid[cpu] = ctx;
100+
}
101+
92102
#define asid_cache(cpu) (cpu_data[cpu].asid_cache)
93103
#define cpu_asid(cpu, mm) \
94104
(cpu_context((cpu), (mm)) & cpu_asid_mask(&cpu_data[cpu]))
@@ -111,7 +121,7 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
111121
int i;
112122

113123
for_each_possible_cpu(i)
114-
cpu_context(i, mm) = 0;
124+
set_cpu_context(i, mm, 0);
115125

116126
mm->context.bd_emupage_allocmap = NULL;
117127
spin_lock_init(&mm->context.bd_emupage_lock);
@@ -175,7 +185,7 @@ drop_mmu_context(struct mm_struct *mm)
175185
htw_start();
176186
} else {
177187
/* will get a new context next time */
178-
cpu_context(cpu, mm) = 0;
188+
set_cpu_context(cpu, mm, 0);
179189
}
180190

181191
local_irq_restore(flags);

arch/mips/kernel/smp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void flush_tlb_mm(struct mm_struct *mm)
537537

538538
for_each_online_cpu(cpu) {
539539
if (cpu != smp_processor_id() && cpu_context(cpu, mm))
540-
cpu_context(cpu, mm) = 0;
540+
set_cpu_context(cpu, mm, 0);
541541
}
542542
}
543543
drop_mmu_context(mm);
@@ -583,7 +583,7 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned l
583583
* mm has been completely unused by that CPU.
584584
*/
585585
if (cpu != smp_processor_id() && cpu_context(cpu, mm))
586-
cpu_context(cpu, mm) = !exec;
586+
set_cpu_context(cpu, mm, !exec);
587587
}
588588
}
589589
local_flush_tlb_range(vma, start, end);
@@ -635,7 +635,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
635635
* by that CPU.
636636
*/
637637
if (cpu != smp_processor_id() && cpu_context(cpu, vma->vm_mm))
638-
cpu_context(cpu, vma->vm_mm) = 1;
638+
set_cpu_context(cpu, vma->vm_mm, 1);
639639
}
640640
}
641641
local_flush_tlb_page(vma, page);

arch/mips/kvm/emulate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ static void kvm_mips_change_entryhi(struct kvm_vcpu *vcpu,
10191019
get_new_mmu_context(kern_mm);
10201020
for_each_possible_cpu(i)
10211021
if (i != cpu)
1022-
cpu_context(i, kern_mm) = 0;
1022+
set_cpu_context(i, kern_mm, 0);
10231023
preempt_enable();
10241024
}
10251025
kvm_write_c0_guest_entryhi(cop0, entryhi);
@@ -1090,8 +1090,8 @@ static void kvm_mips_invalidate_guest_tlb(struct kvm_vcpu *vcpu,
10901090
if (i == cpu)
10911091
continue;
10921092
if (user)
1093-
cpu_context(i, user_mm) = 0;
1094-
cpu_context(i, kern_mm) = 0;
1093+
set_cpu_context(i, user_mm, 0);
1094+
set_cpu_context(i, kern_mm, 0);
10951095
}
10961096

10971097
preempt_enable();

arch/mips/kvm/trap_emul.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,8 @@ static void kvm_trap_emul_check_requests(struct kvm_vcpu *vcpu, int cpu,
10981098
kvm_mips_flush_gva_pt(kern_mm->pgd, KMF_GPA | KMF_KERN);
10991099
kvm_mips_flush_gva_pt(user_mm->pgd, KMF_GPA | KMF_USER);
11001100
for_each_possible_cpu(i) {
1101-
cpu_context(i, kern_mm) = 0;
1102-
cpu_context(i, user_mm) = 0;
1101+
set_cpu_context(i, kern_mm, 0);
1102+
set_cpu_context(i, user_mm, 0);
11031103
}
11041104

11051105
/* Generate new ASID for current mode */
@@ -1211,7 +1211,7 @@ static void kvm_trap_emul_vcpu_reenter(struct kvm_run *run,
12111211
if (gasid != vcpu->arch.last_user_gasid) {
12121212
kvm_mips_flush_gva_pt(user_mm->pgd, KMF_USER);
12131213
for_each_possible_cpu(i)
1214-
cpu_context(i, user_mm) = 0;
1214+
set_cpu_context(i, user_mm, 0);
12151215
vcpu->arch.last_user_gasid = gasid;
12161216
}
12171217
}

arch/mips/mm/context.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ void get_new_mmu_context(struct mm_struct *mm)
1515
local_flush_tlb_all(); /* start new asid cycle */
1616
}
1717

18-
cpu_context(cpu, mm) = asid_cache(cpu) = asid;
18+
set_cpu_context(cpu, mm, asid);
19+
asid_cache(cpu) = asid;
1920
}
2021

2122
void check_mmu_context(struct mm_struct *mm)

0 commit comments

Comments
 (0)