Skip to content

Commit 42d5b84

Browse files
committed
MIPS: mm: Unify ASID version checks
Introduce a new check_mmu_context() function to check an mm's ASID version & get a new one if it's outdated, and a check_switch_mmu_context() function which additionally sets up the new ASID & page directory. Simplify switch_mm() & various get_new_mmu_context() callsites in MIPS KVM by making use of the new functions, which will help reduce the amount of code that requires modification to gain MMID support. Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: linux-mips@vger.kernel.org
1 parent 4ebea49 commit 42d5b84

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

arch/mips/include/asm/mmu_context.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9898
}
9999

100100
extern void get_new_mmu_context(struct mm_struct *mm);
101+
extern void check_mmu_context(struct mm_struct *mm);
102+
extern void check_switch_mmu_context(struct mm_struct *mm);
101103

102104
/*
103105
* Initialize the context related info for a new mm_struct
@@ -126,11 +128,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
126128
local_irq_save(flags);
127129

128130
htw_stop();
129-
/* Check if our ASID is of an older version and thus invalid */
130-
if ((cpu_context(cpu, next) ^ asid_cache(cpu)) & asid_version_mask(cpu))
131-
get_new_mmu_context(next);
132-
write_c0_entryhi(cpu_asid(cpu, next));
133-
TLBMISS_HANDLER_SETUP_PGD(next->pgd);
131+
check_switch_mmu_context(next);
134132

135133
/*
136134
* Mark current->active_mm as not "active" anymore.

arch/mips/kvm/trap_emul.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,11 +1056,7 @@ static int kvm_trap_emul_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
10561056
*/
10571057
if (current->flags & PF_VCPU) {
10581058
mm = KVM_GUEST_KERNEL_MODE(vcpu) ? kern_mm : user_mm;
1059-
if ((cpu_context(cpu, mm) ^ asid_cache(cpu)) &
1060-
asid_version_mask(cpu))
1061-
get_new_mmu_context(mm);
1062-
write_c0_entryhi(cpu_asid(cpu, mm));
1063-
TLBMISS_HANDLER_SETUP_PGD(mm->pgd);
1059+
check_switch_mmu_context(mm);
10641060
kvm_mips_suspend_mm(cpu);
10651061
ehb();
10661062
}
@@ -1074,11 +1070,7 @@ static int kvm_trap_emul_vcpu_put(struct kvm_vcpu *vcpu, int cpu)
10741070

10751071
if (current->flags & PF_VCPU) {
10761072
/* Restore normal Linux process memory map */
1077-
if (((cpu_context(cpu, current->mm) ^ asid_cache(cpu)) &
1078-
asid_version_mask(cpu)))
1079-
get_new_mmu_context(current->mm);
1080-
write_c0_entryhi(cpu_asid(cpu, current->mm));
1081-
TLBMISS_HANDLER_SETUP_PGD(current->mm->pgd);
1073+
check_switch_mmu_context(current->mm);
10821074
kvm_mips_resume_mm(cpu);
10831075
ehb();
10841076
}
@@ -1228,9 +1220,7 @@ static void kvm_trap_emul_vcpu_reenter(struct kvm_run *run,
12281220
* Check if ASID is stale. This may happen due to a TLB flush request or
12291221
* a lazy user MM invalidation.
12301222
*/
1231-
if ((cpu_context(cpu, mm) ^ asid_cache(cpu)) &
1232-
asid_version_mask(cpu))
1233-
get_new_mmu_context(mm);
1223+
check_mmu_context(mm);
12341224
}
12351225

12361226
static int kvm_trap_emul_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
@@ -1266,11 +1256,7 @@ static int kvm_trap_emul_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
12661256
cpu = smp_processor_id();
12671257

12681258
/* Restore normal Linux process memory map */
1269-
if (((cpu_context(cpu, current->mm) ^ asid_cache(cpu)) &
1270-
asid_version_mask(cpu)))
1271-
get_new_mmu_context(current->mm);
1272-
write_c0_entryhi(cpu_asid(cpu, current->mm));
1273-
TLBMISS_HANDLER_SETUP_PGD(current->mm->pgd);
1259+
check_switch_mmu_context(current->mm);
12741260
kvm_mips_resume_mm(cpu);
12751261

12761262
htw_start();

arch/mips/kvm/vz.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,10 +2454,10 @@ static void kvm_vz_vcpu_load_tlb(struct kvm_vcpu *vcpu, int cpu)
24542454
* Root ASID dealiases guest GPA mappings in the root TLB.
24552455
* Allocate new root ASID if needed.
24562456
*/
2457-
if (cpumask_test_and_clear_cpu(cpu, &kvm->arch.asid_flush_mask)
2458-
|| (cpu_context(cpu, gpa_mm) ^ asid_cache(cpu)) &
2459-
asid_version_mask(cpu))
2457+
if (cpumask_test_and_clear_cpu(cpu, &kvm->arch.asid_flush_mask))
24602458
get_new_mmu_context(gpa_mm);
2459+
else
2460+
check_mmu_context(gpa_mm);
24612461
}
24622462
}
24632463

arch/mips/mm/context.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ void get_new_mmu_context(struct mm_struct *mm)
1717

1818
cpu_context(cpu, mm) = asid_cache(cpu) = asid;
1919
}
20+
21+
void check_mmu_context(struct mm_struct *mm)
22+
{
23+
unsigned int cpu = smp_processor_id();
24+
25+
/* Check if our ASID is of an older version and thus invalid */
26+
if ((cpu_context(cpu, mm) ^ asid_cache(cpu)) & asid_version_mask(cpu))
27+
get_new_mmu_context(mm);
28+
}
29+
30+
void check_switch_mmu_context(struct mm_struct *mm)
31+
{
32+
unsigned int cpu = smp_processor_id();
33+
34+
check_mmu_context(mm);
35+
write_c0_entryhi(cpu_asid(cpu, mm));
36+
TLBMISS_HANDLER_SETUP_PGD(mm->pgd);
37+
}

0 commit comments

Comments
 (0)