MIPS: MemoryMapID (MMID) & GINVT Support
cover MIPS: MemoryMapID (MMID) & GINVT Support
This series introduces support for MemoryMapIDs (MMIDs) & GINVT instructions. These give us a larger, global namespace for address space IDs & allow for global invalidation of TLB entries without IPIs.
This has been tested on various configurations of the MIPS I6500, which is the first CPU to support these features.
Applies cleanly atop v5.0-rc4.
Paul Burton (14):
MIPS: mm: Define activate_mm() using switch_mm()
MIPS: mm: Remove redundant drop_mmu_context() cpu argument
MIPS: mm: Remove redundant get_new_mmu_context() cpu argument
MIPS: mm: Avoid HTW stop/start when dropping an inactive mm
MIPS: mm: Consolidate drop_mmu_context() has-ASID checks
MIPS: mm: Move drop_mmu_context() comment into appropriate block
MIPS: mm: Remove redundant preempt_disable in local_flush_tlb_mm()
MIPS: mm: Remove local_flush_tlb_mm()
MIPS: mm: Split obj-y to a file per line
MIPS: mm: Un-inline get_new_mmu_context
MIPS: mm: Unify ASID version checks
MIPS: mm: Add set_cpu_context() for ASID assignments
MIPS: Add GINVT instruction helpers
MIPS: MemoryMapID (MMID) Support
arch/mips/Makefile | 2 + arch/mips/include/asm/barrier.h | 19 ++ arch/mips/include/asm/cpu-features.h | 13 ++ arch/mips/include/asm/cpu.h | 1 + arch/mips/include/asm/ginvt.h | 56 ++++++ arch/mips/include/asm/mipsregs.h | 11 + arch/mips/include/asm/mmu.h | 6 +- arch/mips/include/asm/mmu_context.h | 139 +++++++------ arch/mips/include/asm/tlbflush.h | 5 +- arch/mips/kernel/cpu-probe.c | 55 ++++- arch/mips/kernel/smp.c | 67 ++++++- arch/mips/kernel/traps.c | 4 +- arch/mips/kernel/unaligned.c | 1 + arch/mips/kvm/emulate.c | 8 +- arch/mips/kvm/mips.c | 5 + arch/mips/kvm/trap_emul.c | 30 +-- arch/mips/kvm/vz.c | 8 +- arch/mips/lib/dump_tlb.c | 22 +- arch/mips/mm/Makefile | 16 +- arch/mips/mm/c-r4k.c | 8 +- arch/mips/mm/context.c | 288 +++++++++++++++++++++++++++ arch/mips/mm/init.c | 7 + arch/mips/mm/tlb-r3k.c | 14 +- arch/mips/mm/tlb-r4k.c | 71 ++++--- arch/mips/mm/tlb-r8k.c | 10 +- 25 files changed, 698 insertions(+), 168 deletions(-) create mode 100644 arch/mips/include/asm/ginvt.h create mode 100644 arch/mips/mm/context.c
Signature · 1 line
2.20.1
PATCH 1/14 MIPS: mm: Define activate_mm() using switch_mm()
MIPS has separate definitions of activate_mm() & switch_mm() which are identical apart from switch_mm() checking that the ASID is valid before acquiring a new one.
We know that when activate_mm() is called cpu_context(X, mm) will be zero, and this will never be considered a valid ASID because we never allow the ASID version number to be zero, instead beginning with version 1 using asid_first_version(). Therefore switch_mm() will always allocate a new ASID when called for a new task, meaning that it will behave identically to activate_mm().
Take advantage of this to remove the duplication & define activate_mm() using switch_mm() just like many other architectures do.
---
arch/mips/include/asm/mmu_context.h | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-)
arch/mips/include/asm/mmu_context.h +1 -27
@@ -166,35 +166,9 @@ static inline void destroy_context(struct mm_struct *mm)dsemul_mm_cleanup (mm); } +#define activate_mm (prev, next) switch_mm(prev, next, current)#define deactivate_mm (tsk, mm) do { } while (0) -/* -* After we have set current->mm to a new value, this activates -* the context for the new mm so we see the new mappings. -*/ -static inline void -activate_mm (struct mm_struct *prev,struct mm_struct *next) -{ -unsigned long flags; -unsigned int cpu =smp_processor_id (); - -local_irq_save (flags); - -htw_stop (); -/* Unconditionally get a new ASID. */ -get_new_mmu_context (next, cpu); - -write_c0_entryhi (cpu_asid (cpu, next)); -TLBMISS_HANDLER_SETUP_PGD (next->pgd); - -/* mark mmu ownership change */ -cpumask_clear_cpu (cpu,mm_cpumask (prev)); -cpumask_set_cpu (cpu,mm_cpumask (next)); -htw_start (); - -local_irq_restore (flags); -} -/* * If mm is currently active_mm, we can't really drop it. Instead, * we will get a new one for it.
Signature · 1 line
2.20.1
PATCH 2/14 MIPS: mm: Remove redundant drop_mmu_context() cpu argument
In reply to Paul BurtonThe drop_mmu_context() function accepts a cpu argument, but it implicitly expects that this is always equal to smp_processor_id() by allocating & configuring an ASID on the local CPU when the mm is active on the CPU indicated by the cpu argument.
All callers do provide the value of smp_processor_id() to the cpu argument.
Remove the redundant argument and have drop_mmu_context() call smp_processor_id() itself, making it clearer that the cpu variable always represents the local CPU.
---
arch/mips/include/asm/mmu_context.h | 4 +++- arch/mips/mm/c-r4k.c | 2 +- arch/mips/mm/tlb-r3k.c | 4 ++-- arch/mips/mm/tlb-r4k.c | 4 ++-- arch/mips/mm/tlb-r8k.c | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-)
arch/mips/include/asm/mmu_context.h +3 -1
@@ -174,13 +174,15 @@ static inline void destroy_context(struct mm_struct *mm)* we will get a new one for it. */ static inline void -drop_mmu_context (struct mm_struct *mm,unsigned cpu) +drop_mmu_context (struct mm_struct *mm) {unsigned long flags; +unsigned int cpu;local_irq_save (flags);htw_stop (); + cpu =smp_processor_id ();if (cpumask_test_cpu (cpu,mm_cpumask (mm))) {get_new_mmu_context (mm, cpu);write_c0_entryhi (cpu_asid (cpu, mm));
arch/mips/mm/c-r4k.c +1 -1
@@ -700,7 +700,7 @@ static inline void local_r4k_flush_cache_page(void *args)int cpu =smp_processor_id ();if (cpu_context (cpu, mm) !=0 ) -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); }else vaddr ?r4k_blast_icache_page (addr) :r4k_blast_icache_user_page (addr);
arch/mips/mm/tlb-r3k.c +2 -2
@@ -75,7 +75,7 @@ void local_flush_tlb_mm(struct mm_struct *mm)#ifdef DEBUG_TLB printk ("[tlbmm<%lu>]" , (unsigned long )cpu_context (cpu, mm));#endif -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); } }
@@ -117,7 +117,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, }write_c0_entryhi (oldpid); }else { -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); }local_irq_restore (flags); }
arch/mips/mm/tlb-r4k.c +2 -2
@@ -115,7 +115,7 @@ void local_flush_tlb_mm(struct mm_struct *mm) cpu =smp_processor_id ();if (cpu_context (cpu, mm) !=0 ) { -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); }preempt_enable ();
@@ -163,7 +163,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,write_c0_entryhi (oldpid);htw_start (); }else { -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); }flush_micro_tlb ();local_irq_restore (flags);
arch/mips/mm/tlb-r8k.c +2 -2
@@ -55,7 +55,7 @@ void local_flush_tlb_mm(struct mm_struct *mm)int cpu =smp_processor_id ();if (cpu_context (cpu, mm) !=0 ) -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); } void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
@@ -75,7 +75,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,local_irq_save (flags);if (size >TFP_TLB_SIZE /2 ) { -drop_mmu_context (mm, cpu); +drop_mmu_context (mm); goto out_restore; }
Signature · 1 line
2.20.1
PATCH 3/14 MIPS: mm: Remove redundant get_new_mmu_context() cpu argument
In reply to Paul Burtonget_new_mmu_context() accepts a cpu argument, but implicitly assumes that this is always equal to smp_processor_id() by operating on the local CPU's TLB & icache.
Remove the cpu argument and have get_new_mmu_context() call smp_processor_id() instead.
---
arch/mips/include/asm/mmu_context.h | 12 ++++++++---- arch/mips/kvm/emulate.c | 2 +- arch/mips/kvm/trap_emul.c | 10 +++++----- arch/mips/kvm/vz.c | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-)
arch/mips/include/asm/mmu_context.h +8 -4
@@ -100,9 +100,13 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)/* Normal, classic MIPS get_new_mmu_context */ static inline void -get_new_mmu_context (struct mm_struct *mm,unsigned long cpu) +get_new_mmu_context (struct mm_struct *mm) { -u64 asid =asid_cache (cpu); +unsigned int cpu; +u64 asid; + + cpu =smp_processor_id (); + asid =asid_cache (cpu);if (!((asid +=cpu_asid_inc ()) &cpu_asid_mask (&cpu_data[cpu]))) {if (cpu_has_vtag_icache)
@@ -142,7 +146,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,htw_stop ();/* Check if our ASID is of an older version and thus invalid */ if ((cpu_context (cpu, next) ^asid_cache (cpu)) &asid_version_mask (cpu)) -get_new_mmu_context (next, cpu); +get_new_mmu_context (next);write_c0_entryhi (cpu_asid (cpu, next));TLBMISS_HANDLER_SETUP_PGD (next->pgd);
@@ -184,7 +188,7 @@ drop_mmu_context(struct mm_struct *mm) cpu =smp_processor_id ();if (cpumask_test_cpu (cpu,mm_cpumask (mm))) { -get_new_mmu_context (mm, cpu); +get_new_mmu_context (mm);write_c0_entryhi (cpu_asid (cpu, mm)); }else {/* will get a new context next time */
arch/mips/kvm/emulate.c +1 -1
@@ -1016,7 +1016,7 @@ static void kvm_mips_change_entryhi(struct kvm_vcpu *vcpu,*/ preempt_disable (); cpu =smp_processor_id (); -get_new_mmu_context (kern_mm, cpu); +get_new_mmu_context (kern_mm);for_each_possible_cpu (i)if (i != cpu)cpu_context (i, kern_mm) =0 ;
arch/mips/kvm/trap_emul.c +5 -5
@@ -1058,7 +1058,7 @@ static int kvm_trap_emul_vcpu_load(struct kvm_vcpu *vcpu, int cpu) mm =KVM_GUEST_KERNEL_MODE (vcpu) ? kern_mm : user_mm;if ((cpu_context (cpu, mm) ^asid_cache (cpu)) &asid_version_mask (cpu)) -get_new_mmu_context (mm, cpu); +get_new_mmu_context (mm);write_c0_entryhi (cpu_asid (cpu, mm));TLBMISS_HANDLER_SETUP_PGD (mm->pgd);kvm_mips_suspend_mm (cpu);
@@ -1076,7 +1076,7 @@ static int kvm_trap_emul_vcpu_put(struct kvm_vcpu *vcpu, int cpu)/* Restore normal Linux process memory map */ if (((cpu_context (cpu, current->mm) ^asid_cache (cpu)) &asid_version_mask (cpu))) -get_new_mmu_context (current->mm, cpu); +get_new_mmu_context (current->mm);write_c0_entryhi (cpu_asid (cpu, current->mm));TLBMISS_HANDLER_SETUP_PGD (current->mm->pgd);kvm_mips_resume_mm (cpu);
@@ -1113,7 +1113,7 @@ static void kvm_trap_emul_check_requests(struct kvm_vcpu *vcpu, int cpu,/* Generate new ASID for current mode */ if (reload_asid) { mm =KVM_GUEST_KERNEL_MODE (vcpu) ? kern_mm : user_mm; -get_new_mmu_context (mm, cpu); +get_new_mmu_context (mm);htw_stop ();write_c0_entryhi (cpu_asid (cpu, mm));TLBMISS_HANDLER_SETUP_PGD (mm->pgd);
@@ -1230,7 +1230,7 @@ static void kvm_trap_emul_vcpu_reenter(struct kvm_run *run,*/ if ((cpu_context (cpu, mm) ^asid_cache (cpu)) &asid_version_mask (cpu)) -get_new_mmu_context (mm, cpu); +get_new_mmu_context (mm); }static int kvm_trap_emul_vcpu_run (struct kvm_run *run,struct kvm_vcpu *vcpu)
@@ -1268,7 +1268,7 @@ static int kvm_trap_emul_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)/* Restore normal Linux process memory map */ if (((cpu_context (cpu, current->mm) ^asid_cache (cpu)) &asid_version_mask (cpu))) -get_new_mmu_context (current->mm, cpu); +get_new_mmu_context (current->mm);write_c0_entryhi (cpu_asid (cpu, current->mm));TLBMISS_HANDLER_SETUP_PGD (current->mm->pgd);kvm_mips_resume_mm (cpu);
arch/mips/kvm/vz.c +1 -1
@@ -2457,7 +2457,7 @@ static void kvm_vz_vcpu_load_tlb(struct kvm_vcpu *vcpu, int cpu)if (cpumask_test_and_clear_cpu (cpu, &kvm->arch.asid_flush_mask) || (cpu_context (cpu, gpa_mm) ^asid_cache (cpu)) &asid_version_mask (cpu)) -get_new_mmu_context (gpa_mm, cpu); +get_new_mmu_context (gpa_mm); } }
Signature · 1 line
2.20.1
PATCH 4/14 MIPS: mm: Avoid HTW stop/start when dropping an inactive mm
In reply to Paul BurtonIf drop_mmu_context() is called with an mm that is not currently active on the local CPU then there's no need for us to stop & start a hardware page table walker because it can't be fetching entries for the ASID corresponding to the mm we're operating on.
Move the htw_stop() & htw_start() calls into the block which we run only if the mm is currently active, in order to avoid the redundant work.
---
arch/mips/include/asm/mmu_context.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/mips/include/asm/mmu_context.h +3 -2
@@ -184,17 +184,18 @@ drop_mmu_context(struct mm_struct *mm)unsigned int cpu;local_irq_save (flags); -htw_stop (); cpu =smp_processor_id ();if (cpumask_test_cpu (cpu,mm_cpumask (mm))) { +htw_stop ();get_new_mmu_context (mm);write_c0_entryhi (cpu_asid (cpu, mm)); +htw_start (); }else {/* will get a new context next time */ cpu_context (cpu, mm) =0 ; } -htw_start (); +local_irq_restore (flags); }
Signature · 1 line
2.20.1
PATCH 5/14 MIPS: mm: Consolidate drop_mmu_context() has-ASID checks
In reply to Paul BurtonIf an mm does not have an ASID on the local CPU then drop_mmu_context() is always redundant, since there's no context to "drop". Various callers of drop_mmu_context() check whether the mm has been allocated an ASID before making the call. Move that check into drop_mmu_context() and remove it from callers to simplify them.
---
arch/mips/include/asm/mmu_context.h | 4 +++- arch/mips/mm/c-r4k.c | 5 +---- arch/mips/mm/tlb-r3k.c | 8 ++++---- arch/mips/mm/tlb-r4k.c | 10 +--------- arch/mips/mm/tlb-r8k.c | 5 +---- 5 files changed, 10 insertions(+), 22 deletions(-)
arch/mips/include/asm/mmu_context.h +3 -1
@@ -186,7 +186,9 @@ drop_mmu_context(struct mm_struct *mm)local_irq_save (flags); cpu =smp_processor_id (); -if (cpumask_test_cpu (cpu,mm_cpumask (mm))) { +if (!cpu_context (cpu, mm)) { +/* no-op */ + }else if (cpumask_test_cpu (cpu,mm_cpumask (mm))) {htw_stop ();get_new_mmu_context (mm);write_c0_entryhi (cpu_asid (cpu, mm));
arch/mips/mm/c-r4k.c +1 -4
@@ -697,10 +697,7 @@ static inline void local_r4k_flush_cache_page(void *args) }if (exec) {if (vaddr && cpu_has_vtag_icache && mm == current->active_mm) { -int cpu =smp_processor_id (); - -if (cpu_context (cpu, mm) !=0 ) -drop_mmu_context (mm); +drop_mmu_context (mm); }else vaddr ?r4k_blast_icache_page (addr) :r4k_blast_icache_user_page (addr);
arch/mips/mm/tlb-r3k.c +4 -4
@@ -69,14 +69,14 @@ void local_flush_tlb_all(void)void local_flush_tlb_mm (struct mm_struct *mm) { +#ifdef DEBUG_TLB int cpu =smp_processor_id (); -if (cpu_context (cpu, mm) !=0 ) { -#ifdef DEBUG_TLB +if (cpu_context (cpu, mm) !=0 )printk ("[tlbmm<%lu>]" , (unsigned long )cpu_context (cpu, mm));#endif -drop_mmu_context (mm); - } + +drop_mmu_context (mm); } void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
arch/mips/mm/tlb-r4k.c +1 -9
@@ -108,16 +108,8 @@ EXPORT_SYMBOL(local_flush_tlb_all);these entries, we just bump the asid. */ void local_flush_tlb_mm (struct mm_struct *mm) { -int cpu; -preempt_disable (); - - cpu =smp_processor_id (); - -if (cpu_context (cpu, mm) !=0 ) { -drop_mmu_context (mm); - } - +drop_mmu_context (mm);preempt_enable (); }
arch/mips/mm/tlb-r8k.c +1 -4
@@ -52,10 +52,7 @@ void local_flush_tlb_all(void)void local_flush_tlb_mm (struct mm_struct *mm) { -int cpu =smp_processor_id (); - -if (cpu_context (cpu, mm) !=0 ) -drop_mmu_context (mm); +drop_mmu_context (mm); } void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
Signature · 1 line
2.20.1
PATCH 6/14 MIPS: mm: Move drop_mmu_context() comment into appropriate block
In reply to Paul Burtondrop_mmu_context() is preceded by a comment indicating what happens if the mm provided is currently active on the local CPU. Move that comment into the block that executes in this case, adjusting slightly to reflect its new location.
---
arch/mips/include/asm/mmu_context.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/mips/include/asm/mmu_context.h +5 -5
@@ -173,10 +173,6 @@ static inline void destroy_context(struct mm_struct *mm)#define activate_mm (prev, next) switch_mm(prev, next, current)#define deactivate_mm (tsk, mm) do { } while (0) -/* -* If mm is currently active_mm, we can't really drop it. Instead, -* we will get a new one for it. -*/ static inline void drop_mmu_context (struct mm_struct *mm) {
@@ -188,7 +184,11 @@ drop_mmu_context(struct mm_struct *mm) cpu =smp_processor_id ();if (!cpu_context (cpu, mm)) {/* no-op */ - }else if (cpumask_test_cpu (cpu,mm_cpumask (mm))) { + }else if (cpumask_test_cpu (cpu,mm_cpumask (mm))) { +/* +* mm is currently active, so we can't really drop it. +* Instead we bump the ASID. +*/ htw_stop ();get_new_mmu_context (mm);write_c0_entryhi (cpu_asid (cpu, mm));
Signature · 1 line
2.20.1
PATCH 7/14 MIPS: mm: Remove redundant preempt_disable in local_flush_tlb_mm()
In reply to Paul BurtonThe r4k variant of local_flush_tlb_mm() wraps its call to drop_mmu_context() with a preempt_disable() & preempt_enable() pair, but this is redundant since drop_mmu_context() disables interrupts and from Documentation/preempt-locking.txt:
Note that you do not need to explicitly prevent preemption if you are holding any locks or interrupts are disabled, since preemption is implicitly disabled in those cases.
Remove the redundant preempt_disable() & preempt_enable() calls.
---
arch/mips/mm/tlb-r4k.c | 2 -- 1 file changed, 2 deletions(-)
arch/mips/mm/tlb-r4k.c +0 -2
@@ -108,9 +108,7 @@ EXPORT_SYMBOL(local_flush_tlb_all);these entries, we just bump the asid. */ void local_flush_tlb_mm (struct mm_struct *mm) { -preempt_disable ();drop_mmu_context (mm); -preempt_enable (); } void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
Signature · 1 line
2.20.1
PATCH 8/14 MIPS: mm: Remove local_flush_tlb_mm()
In reply to Paul BurtonAll 3 variants of local_flush_tlb_mm() are now effectively simple calls to drop_mmu_context(). Remove them and use drop_mmu_context() directly.
---
arch/mips/include/asm/tlbflush.h | 5 +++-- arch/mips/kernel/smp.c | 4 ++-- arch/mips/mm/tlb-r3k.c | 12 ------------ arch/mips/mm/tlb-r4k.c | 7 ------- arch/mips/mm/tlb-r8k.c | 5 ----- 5 files changed, 5 insertions(+), 28 deletions(-)
arch/mips/include/asm/tlbflush.h +3 -2
@@ -14,7 +14,6 @@* - flush_tlb_kernel_range(start, end) flushes a range of kernel pages */ extern void local_flush_tlb_all (void ); -extern void local_flush_tlb_mm (struct mm_struct *mm);extern void local_flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end); extern void local_flush_tlb_kernel_range(unsigned long start,
@@ -23,6 +22,8 @@ extern void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);extern void local_flush_tlb_one (unsigned long vaddr); +#include <asm/mmu_context.h> +#ifdef CONFIG_SMP extern void flush_tlb_all (void );
@@ -36,7 +37,7 @@ extern void flush_tlb_one(unsigned long vaddr);#else /* CONFIG_SMP */ #define flush_tlb_all () local_flush_tlb_all() -#define flush_tlb_mm (mm) local_flush_tlb_mm(mm) +#define flush_tlb_mm (mm) drop_mmu_context(mm)#define flush_tlb_range (vma, vmaddr, end) local_flush_tlb_range(vma, vmaddr, end)#define flush_tlb_kernel_range (vmaddr,end) \ local_flush_tlb_kernel_range(vmaddr, end)
arch/mips/kernel/smp.c +2 -2
@@ -487,7 +487,7 @@ void flush_tlb_all(void)static void flush_tlb_mm_ipi (void *mm) { -local_flush_tlb_mm ((struct mm_struct *)mm); +drop_mmu_context ((struct mm_struct *)mm); }/*
@@ -540,7 +540,7 @@ void flush_tlb_mm(struct mm_struct *mm)cpu_context (cpu, mm) =0 ; } } -local_flush_tlb_mm (mm); +drop_mmu_context (mm);preempt_enable (); }
arch/mips/mm/tlb-r3k.c +0 -12
@@ -67,18 +67,6 @@ void local_flush_tlb_all(void)local_irq_restore (flags); } -void local_flush_tlb_mm (struct mm_struct *mm) -{ -#ifdef DEBUG_TLB -int cpu =smp_processor_id (); - -if (cpu_context (cpu, mm) !=0 ) -printk ("[tlbmm<%lu>]" , (unsigned long )cpu_context (cpu, mm)); -#endif - -drop_mmu_context (mm); -} -void local_flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
arch/mips/mm/tlb-r4k.c +0 -7
@@ -104,13 +104,6 @@ void local_flush_tlb_all(void) }EXPORT_SYMBOL (local_flush_tlb_all); -/* All entries common to a mm share an asid. To effectively flush -these entries, we just bump the asid. */ -void local_flush_tlb_mm (struct mm_struct *mm) -{ -drop_mmu_context (mm); -} -void local_flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
arch/mips/mm/tlb-r8k.c +0 -5
@@ -50,11 +50,6 @@ void local_flush_tlb_all(void)local_irq_restore (flags); } -void local_flush_tlb_mm (struct mm_struct *mm) -{ -drop_mmu_context (mm); -} -void local_flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
Signature · 1 line
2.20.1
PATCH 9/14 MIPS: mm: Split obj-y to a file per line
In reply to Paul BurtonSplit always-included objects to one per line in order to make it easier to modify the list of included objects.
---
arch/mips/mm/Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/mips/mm/Makefile +12 -3
@@ -3,9 +3,18 @@ # Makefile for the Linux/MIPS-specific parts of the memory manager. # -obj-y += cache.o extable.o fault.o \ - gup.o init.o mmap.o page.o page-funcs.o \ - pgtable.o tlbex.o tlbex-fault.o tlb-funcs.o +obj-y += cache.o +obj-y += extable.o +obj-y += fault.o +obj-y += gup.o +obj-y += init.o +obj-y += mmap.o +obj-y += page.o +obj-y += page-funcs.o +obj-y += pgtable.o +obj-y += tlbex.o +obj-y += tlbex-fault.o +obj-y += tlb-funcs.o ifdef CONFIG_CPU_MICROMIPS obj-y += uasm-micromips.o
Signature · 1 line
2.20.1
PATCH 10/14 MIPS: mm: Un-inline get_new_mmu_context
In reply to Paul BurtonIn preparation for adding MMID support to get_new_mmu_context() which will increase the size of the function somewhat, move it from asm/mmu_context.h into a C file.
---
arch/mips/include/asm/mmu_context.h | 20 +------------------- arch/mips/mm/Makefile | 1 + arch/mips/mm/context.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 arch/mips/mm/context.c
arch/mips/include/asm/mmu_context.h +1 -19
@@ -97,25 +97,7 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) { } - -/* Normal, classic MIPS get_new_mmu_context */ -static inline void -get_new_mmu_context (struct mm_struct *mm) -{ -unsigned int cpu; -u64 asid; - - cpu =smp_processor_id (); - asid =asid_cache (cpu); - -if (!((asid +=cpu_asid_inc ()) &cpu_asid_mask (&cpu_data[cpu]))) { -if (cpu_has_vtag_icache) -flush_icache_all (); -local_flush_tlb_all ();/* start new asid cycle */ - } - -cpu_context (cpu, mm) =asid_cache (cpu) = asid; -} +extern void get_new_mmu_context (struct mm_struct *mm);/* * Initialize the context related info for a new mm_struct
arch/mips/mm/Makefile +1 -0
@@ -4,6 +4,7 @@ # obj-y += cache.o +obj-y += context.o obj-y += extable.o obj-y += fault.o obj-y += gup.o
arch/mips/mm/context.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/mmu_context.h> + +void get_new_mmu_context (struct mm_struct *mm) +{ +unsigned int cpu; +u64 asid; + + cpu =smp_processor_id (); + asid =asid_cache (cpu); + +if (!((asid +=cpu_asid_inc ()) &cpu_asid_mask (&cpu_data[cpu]))) { +if (cpu_has_vtag_icache) +flush_icache_all (); +local_flush_tlb_all ();/* start new asid cycle */ + } + +cpu_context (cpu, mm) =asid_cache (cpu) = asid; +}
Signature · 1 line
2.20.1
PATCH 11/14 MIPS: mm: Unify ASID version checks
In reply to Paul BurtonIntroduce 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.
---
arch/mips/include/asm/mmu_context.h | 8 +++----- arch/mips/kvm/trap_emul.c | 22 ++++------------------ arch/mips/kvm/vz.c | 6 +++--- arch/mips/mm/context.c | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 26 deletions(-)
arch/mips/include/asm/mmu_context.h +3 -5
@@ -98,6 +98,8 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) }extern void get_new_mmu_context (struct mm_struct *mm); +extern void check_mmu_context (struct mm_struct *mm); +extern void check_switch_mmu_context (struct mm_struct *mm);/* * 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,local_irq_save (flags);htw_stop (); -/* Check if our ASID is of an older version and thus invalid */ -if ((cpu_context (cpu, next) ^asid_cache (cpu)) &asid_version_mask (cpu)) -get_new_mmu_context (next); -write_c0_entryhi (cpu_asid (cpu, next)); -TLBMISS_HANDLER_SETUP_PGD (next->pgd); +check_switch_mmu_context (next);/* * Mark current->active_mm as not "active" anymore.
arch/mips/kvm/trap_emul.c +4 -18
@@ -1056,11 +1056,7 @@ static int kvm_trap_emul_vcpu_load(struct kvm_vcpu *vcpu, int cpu)*/ if (current->flags &PF_VCPU ) { mm =KVM_GUEST_KERNEL_MODE (vcpu) ? kern_mm : user_mm; -if ((cpu_context (cpu, mm) ^asid_cache (cpu)) & -asid_version_mask (cpu)) -get_new_mmu_context (mm); -write_c0_entryhi (cpu_asid (cpu, mm)); -TLBMISS_HANDLER_SETUP_PGD (mm->pgd); +check_switch_mmu_context (mm);kvm_mips_suspend_mm (cpu);ehb (); }
@@ -1074,11 +1070,7 @@ static int kvm_trap_emul_vcpu_put(struct kvm_vcpu *vcpu, int cpu)if (current->flags &PF_VCPU ) {/* Restore normal Linux process memory map */ -if (((cpu_context (cpu, current->mm) ^asid_cache (cpu)) & -asid_version_mask (cpu))) -get_new_mmu_context (current->mm); -write_c0_entryhi (cpu_asid (cpu, current->mm)); -TLBMISS_HANDLER_SETUP_PGD (current->mm->pgd); +check_switch_mmu_context (current->mm);kvm_mips_resume_mm (cpu);ehb (); }
@@ -1228,9 +1220,7 @@ static void kvm_trap_emul_vcpu_reenter(struct kvm_run *run,* Check if ASID is stale. This may happen due to a TLB flush request or * a lazy user MM invalidation. */ -if ((cpu_context (cpu, mm) ^asid_cache (cpu)) & -asid_version_mask (cpu)) -get_new_mmu_context (mm); +check_mmu_context (mm); }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) cpu =smp_processor_id ();/* Restore normal Linux process memory map */ -if (((cpu_context (cpu, current->mm) ^asid_cache (cpu)) & -asid_version_mask (cpu))) -get_new_mmu_context (current->mm); -write_c0_entryhi (cpu_asid (cpu, current->mm)); -TLBMISS_HANDLER_SETUP_PGD (current->mm->pgd); +check_switch_mmu_context (current->mm);kvm_mips_resume_mm (cpu);htw_start ();
arch/mips/kvm/vz.c +3 -3
@@ -2454,10 +2454,10 @@ static void kvm_vz_vcpu_load_tlb(struct kvm_vcpu *vcpu, int cpu)* Root ASID dealiases guest GPA mappings in the root TLB. * Allocate new root ASID if needed. */ -if (cpumask_test_and_clear_cpu (cpu, &kvm->arch.asid_flush_mask) - || (cpu_context (cpu, gpa_mm) ^asid_cache (cpu)) & -asid_version_mask (cpu)) +if (cpumask_test_and_clear_cpu (cpu, &kvm->arch.asid_flush_mask))get_new_mmu_context (gpa_mm); +else +check_mmu_context (gpa_mm); } }
arch/mips/mm/context.c +18 -0
@@ -17,3 +17,21 @@ void get_new_mmu_context(struct mm_struct *mm)cpu_context (cpu, mm) =asid_cache (cpu) = asid; } + +void check_mmu_context (struct mm_struct *mm) +{ +unsigned int cpu =smp_processor_id (); + +/* Check if our ASID is of an older version and thus invalid */ +if ((cpu_context (cpu, mm) ^asid_cache (cpu)) &asid_version_mask (cpu)) +get_new_mmu_context (mm); +} + +void check_switch_mmu_context (struct mm_struct *mm) +{ +unsigned int cpu =smp_processor_id (); + +check_mmu_context (mm); +write_c0_entryhi (cpu_asid (cpu, mm)); +TLBMISS_HANDLER_SETUP_PGD (mm->pgd); +}
Signature · 1 line
2.20.1
PATCH 12/14 MIPS: mm: Add set_cpu_context() for ASID assignments
In reply to Paul BurtonWhen 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.
---
arch/mips/include/asm/mmu_context.h | 16 +++++++++++++--- arch/mips/kernel/smp.c | 6 +++--- arch/mips/kvm/emulate.c | 6 +++--- arch/mips/kvm/trap_emul.c | 6 +++--- arch/mips/mm/context.c | 3 ++- 5 files changed, 24 insertions(+), 13 deletions(-)
arch/mips/include/asm/mmu_context.h +13 -3
@@ -88,7 +88,17 @@ static inline u64 asid_first_version(unsigned int cpu)return ~asid_version_mask (cpu) +1 ; } -#define cpu_context (cpu, mm) ((mm)->context.asid[cpu]) +static inline u64 cpu_context (unsigned int cpu,const struct mm_struct *mm) +{ +return mm->context.asid[cpu]; +} + +static inline void set_cpu_context (unsigned int cpu, +struct mm_struct *mm,u64 ctx) +{ + mm->context.asid[cpu] = ctx; +} +#define asid_cache (cpu) (cpu_data[cpu].asid_cache)#define cpu_asid (cpu, mm) \ (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)int i;for_each_possible_cpu (i) -cpu_context (i, mm) =0 ; +set_cpu_context (i, mm,0 ); mm->context.bd_emupage_allocmap =NULL ;spin_lock_init (&mm->context.bd_emupage_lock);
@@ -175,7 +185,7 @@ drop_mmu_context(struct mm_struct *mm)htw_start (); }else {/* will get a new context next time */ -cpu_context (cpu, mm) =0 ; +set_cpu_context (cpu, mm,0 ); }local_irq_restore (flags);
arch/mips/kernel/smp.c +3 -3
@@ -537,7 +537,7 @@ void flush_tlb_mm(struct mm_struct *mm)for_each_online_cpu (cpu) {if (cpu !=smp_processor_id () &&cpu_context (cpu, mm)) -cpu_context (cpu, mm) =0 ; +set_cpu_context (cpu, mm,0 ); } }drop_mmu_context (mm);
@@ -583,7 +583,7 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned l* mm has been completely unused by that CPU. */ if (cpu !=smp_processor_id () &&cpu_context (cpu, mm)) -cpu_context (cpu, mm) = !exec; +set_cpu_context (cpu, mm, !exec); } }local_flush_tlb_range (vma, start, end);
@@ -635,7 +635,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)* by that CPU. */ if (cpu !=smp_processor_id () &&cpu_context (cpu, vma->vm_mm)) -cpu_context (cpu, vma->vm_mm) =1 ; +set_cpu_context (cpu, vma->vm_mm,1 ); } }local_flush_tlb_page (vma, page);
arch/mips/kvm/emulate.c +3 -3
@@ -1019,7 +1019,7 @@ static void kvm_mips_change_entryhi(struct kvm_vcpu *vcpu,get_new_mmu_context (kern_mm);for_each_possible_cpu (i)if (i != cpu) -cpu_context (i, kern_mm) =0 ; +set_cpu_context (i, kern_mm,0 );preempt_enable (); }kvm_write_c0_guest_entryhi (cop0, entryhi);
@@ -1090,8 +1090,8 @@ static void kvm_mips_invalidate_guest_tlb(struct kvm_vcpu *vcpu,if (i == cpu)continue ;if (user) -cpu_context (i, user_mm) =0 ; -cpu_context (i, kern_mm) =0 ; +set_cpu_context (i, user_mm,0 ); +set_cpu_context (i, kern_mm,0 ); }preempt_enable ();
arch/mips/kvm/trap_emul.c +3 -3
@@ -1098,8 +1098,8 @@ static void kvm_trap_emul_check_requests(struct kvm_vcpu *vcpu, int cpu,kvm_mips_flush_gva_pt (kern_mm->pgd,KMF_GPA |KMF_KERN );kvm_mips_flush_gva_pt (user_mm->pgd,KMF_GPA |KMF_USER );for_each_possible_cpu (i) { -cpu_context (i, kern_mm) =0 ; -cpu_context (i, user_mm) =0 ; +set_cpu_context (i, kern_mm,0 ); +set_cpu_context (i, user_mm,0 ); }/* Generate new ASID for current mode */
@@ -1211,7 +1211,7 @@ static void kvm_trap_emul_vcpu_reenter(struct kvm_run *run,if (gasid != vcpu->arch.last_user_gasid) {kvm_mips_flush_gva_pt (user_mm->pgd,KMF_USER );for_each_possible_cpu (i) -cpu_context (i, user_mm) =0 ; +set_cpu_context (i, user_mm,0 ); vcpu->arch.last_user_gasid = gasid; } }
arch/mips/mm/context.c +2 -1
@@ -15,7 +15,8 @@ void get_new_mmu_context(struct mm_struct *mm)local_flush_tlb_all ();/* start new asid cycle */ } -cpu_context (cpu, mm) =asid_cache (cpu) = asid; +set_cpu_context (cpu, mm, asid); +asid_cache (cpu) = asid; }void check_mmu_context (struct mm_struct *mm)
Signature · 1 line
2.20.1
PATCH 13/14 MIPS: Add GINVT instruction helpers
In reply to Paul BurtonAdd a family of ginvt_* functions making it easy to emit a GINVT instruction to globally invalidate TLB entries. We make use of the _ASM_MACRO infrastructure to support emitting the instructions even if the assembler isn't new enough to support them natively.
An associated STYPE_GINV definition & sync_ginv() function are added to emit a sync instruction of type 0x14, which operates as a completion barrier for these new GINVT (and GINVI) instructions.
---
arch/mips/Makefile | 2 ++ arch/mips/include/asm/barrier.h | 19 +++++++++++ arch/mips/include/asm/ginvt.h | 56 ++++++++++++++++++++++++++++++++ arch/mips/include/asm/mipsregs.h | 7 ++++ 4 files changed, 84 insertions(+) create mode 100644 arch/mips/include/asm/ginvt.h
arch/mips/Makefile +2 -0
@@ -233,6 +233,8 @@ toolchain-crc := $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mcrc) cflags-$(toolchain-crc) += -DTOOLCHAIN_SUPPORTS_CRC toolchain-dsp := $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mdsp) cflags-$(toolchain-dsp) += -DTOOLCHAIN_SUPPORTS_DSP +toolchain-ginv := $(call cc-option-yn,$(mips-cflags) -Wa$(comma)-mginv) +cflags-$(toolchain-ginv) += -DTOOLCHAIN_SUPPORTS_GINV # # Firmware support
arch/mips/include/asm/barrier.h +19 -0
@@ -105,6 +105,20 @@*/ #define STYPE_SYNC_MB 0x10 +/* +* stype 0x14 - A completion barrier specific to global invalidations +* +* When a sync instruction of this type completes any preceding GINVI or GINVT +* operation has been globalized & completed on all coherent CPUs. Anything +* that the GINV* instruction should invalidate will have been invalidated on +* all coherent CPUs when this instruction completes. It is implementation +* specific whether the GINV* instructions themselves will ensure completion, +* or this sync type will. +* +* In systems implementing global invalidates (ie. with Config5.GI == 2 or 3) +* this sync type also requires that previous SYNCI operations have completed. +*/ +#define STYPE_GINV 0x14#ifdef CONFIG_CPU_HAS_SYNC #define __sync () \
@@ -222,6 +236,11 @@#define __smp_mb__before_atomic () __smp_mb__before_llsc()#define __smp_mb__after_atomic () smp_llsc_mb() +static inline void sync_ginv (void ) +{ + asmvolatile ("sync\t%0" ::"i" (STYPE_GINV )); +} +#include <asm-generic/barrier.h> #endif /* __ASM_BARRIER_H */
arch/mips/include/asm/ginvt.h new file +56 -0
56 lines not on this page · raw message
arch/mips/include/asm/mipsregs.h +7 -0
@@ -1247,6 +1247,13 @@ __asm__(".macro parse_r var r\n\t" ENC \ ".endm") +/* Instructions with 1 register operand & 1 immediate operand */ +#define _ASM_MACRO_1R1I (OP ,R1 ,I2 ,ENC ) \ + __asm__(".macro " #OP " " #R1 ", " #I2 "\n\t" \ + "parse_r __" #R1 ", \\" #R1 "\n\t" \ + ENC \ + ".endm") +/* Instructions with 2 register operands */ #define _ASM_MACRO_2R (OP ,R1 ,R2 ,ENC ) \ __asm__(".macro " #OP " " #R1 ", " #R2 "\n\t" \
Signature · 1 line
2.20.1
PATCH 14/14 MIPS: MemoryMapID (MMID) Support
In reply to Paul BurtonIntroduce support for using MemoryMapIDs (MMIDs) as an alternative to Address Space IDs (ASIDs). The major difference between the two is that MMIDs are global - ie. an MMID uniquely identifies an address space across all coherent CPUs. In contrast ASIDs are non-global per-CPU IDs, wherein each address space is allocated a separate ASID for each CPU upon which it is used. This global namespace allows a new GINVT instruction be used to globally invalidate TLB entries associated with a particular MMID across all coherent CPUs in the system, removing the need for IPIs to invalidate entries with separate ASIDs on each CPU.
The allocation scheme used here is largely borrowed from arm64 (see arch/arm64/mm/context.c). In essence we maintain a bitmap to track available MMIDs, and MMIDs in active use at the time of a rollover to a new MMID version are preserved in the new version. The allocation scheme requires efficient 64 bit atomics in order to perform reasonably, so this support depends upon CONFIG_GENERIC_ATOMIC64=n (ie. currently it will only be included in MIPS64 kernels).
The first, and currently only, available CPU with support for MMIDs is the MIPS I6500. This CPU supports 16 bit MMIDs, and so for now we cap our MMIDs to 16 bits wide in order to prevent the bitmap growing to absurd sizes if any future CPU does implement 32 bit MMIDs as the architecture manuals suggest is recommended.
When MMIDs are in use we also make use of GINVT instruction which is available due to the global nature of MMIDs. By executing a sequence of GINVT & SYNC 0x14 instructions we can avoid the overhead of an IPI to each remote CPU in many cases. One complication is that GINVT will invalidate wired entries (in all cases apart from type 0, which targets the entire TLB). In order to avoid GINVT invalidating any wired TLB entries we set up, we make sure to create those entries using a reserved MMID (0) that we never associate with any address space.
Also of note is that KVM will require further work in order to support MMIDs & GINVT, since KVM is involved in allocating IDs for guests & in configuring the MMU. That work is not part of this patch, so for now when MMIDs are in use KVM is disabled.
---
arch/mips/include/asm/cpu-features.h | 13 ++ arch/mips/include/asm/cpu.h | 1 + arch/mips/include/asm/mipsregs.h | 4 + arch/mips/include/asm/mmu.h | 6 +- arch/mips/include/asm/mmu_context.h | 54 +++++- arch/mips/kernel/cpu-probe.c | 55 +++++- arch/mips/kernel/smp.c | 57 +++++- arch/mips/kernel/traps.c | 4 +- arch/mips/kernel/unaligned.c | 1 + arch/mips/kvm/mips.c | 5 + arch/mips/lib/dump_tlb.c | 22 ++- arch/mips/mm/c-r4k.c | 3 + arch/mips/mm/context.c | 256 ++++++++++++++++++++++++++- arch/mips/mm/init.c | 7 + arch/mips/mm/tlb-r4k.c | 52 ++++-- 15 files changed, 509 insertions(+), 31 deletions(-)
arch/mips/include/asm/cpu-features.h +13 -0
@@ -590,6 +590,19 @@# define cpu_has_mipsmt_pertccounters 0#endif /* CONFIG_MIPS_MT_SMP */ +/* +* We only enable MMID support for configurations which natively support 64 bit +* atomics because getting good performance from the allocator relies upon +* efficient atomic64_*() functions. +*/ +#ifndef cpu_has_mmid +# ifdef CONFIG_GENERIC_ATOMIC64 +# define cpu_has_mmid 0 +# else +# define cpu_has_mmid __isa_ge_and_opt(6, MIPS_CPU_MMID) +# endif +#endif +/* * Guest capabilities */
arch/mips/include/asm/cpu.h +1 -0
@@ -422,6 +422,7 @@ enum cpu_type_enum { MBIT_ULL(55) /* CPU shares FTLB entries with another */#define MIPS_CPU_MT_PER_TC_PERF_COUNTERS \ MBIT_ULL(56)/* CPU has perf counters implemented per TC (MIPSMT ASE) */ +#define MIPS_CPU_MMID MBIT_ULL(57)/* CPU supports MemoryMapIDs */ /* * CPU ASE encodings
arch/mips/include/asm/mipsregs.h +4 -0
@@ -667,6 +667,7 @@#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)#define MIPS_CONF5_CA2 (_ULCAST_(1) << 14) +#define MIPS_CONF5_MI (_ULCAST_(1) << 17)#define MIPS_CONF5_CRCP (_ULCAST_(1) << 18)#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
@@ -1610,6 +1611,9 @@ do { \#define read_c0_xcontextconfig () __read_ulong_c0_register($4, 3)#define write_c0_xcontextconfig (val) __write_ulong_c0_register($4, 3, val) +#define read_c0_memorymapid () __read_32bit_c0_register($4, 5) +#define write_c0_memorymapid (val) __write_32bit_c0_register($4, 5, val) +#define read_c0_pagemask () __read_32bit_c0_register($5, 0)#define write_c0_pagemask (val) __write_32bit_c0_register($5, 0, val)
arch/mips/include/asm/mmu.h +5 -1
@@ -7,7 +7,11 @@#include <linux/wait.h> typedef struct { - u64 asid[NR_CPUS]; + union { + u64 asid[NR_CPUS]; + atomic64_t mmid; + }; + void *vdso; /* lock to be held whilst modifying fp_bd_emupage_allocmap */
arch/mips/include/asm/mmu_context.h +50 -4
97 lines not on this page · raw message
arch/mips/kernel/cpu-probe.c +54 -1
70 lines not on this page · raw message
arch/mips/kernel/smp.c +52 -5
116 lines not on this page · raw message
arch/mips/kernel/traps.c +3 -1
@@ -2223,7 +2223,9 @@ void per_cpu_trap_init(bool is_boot_cpu) cp0_fdc_irq =-1 ; } -if (!cpu_data[cpu].asid_cache) +if (cpu_has_mmid) + cpu_data[cpu].asid_cache =0 ; +else if (!cpu_data[cpu].asid_cache) cpu_data[cpu].asid_cache =asid_first_version (cpu);mmgrab (&init_mm);
arch/mips/kernel/unaligned.c +1 -0
@@ -89,6 +89,7 @@#include <asm/fpu.h> #include <asm/fpu_emulator.h> #include <asm/inst.h> +#include <asm/mmu_context.h> #include <linux/uaccess.h> #define STR (x) __STR(x)
arch/mips/kvm/mips.c +5 -0
@@ -1723,6 +1723,11 @@ static int __init kvm_mips_init(void) {int ret; +if (cpu_has_mmid) { +pr_warn ("KVM does not yet support MMIDs. KVM Disabled\n" ); +return -EOPNOTSUPP ; + } + ret =kvm_mips_entry_setup ();if (ret)return ret;
arch/mips/lib/dump_tlb.c +17 -5
@@ -10,6 +10,7 @@#include <asm/hazards.h> #include <asm/mipsregs.h> +#include <asm/mmu_context.h> #include <asm/page.h> #include <asm/pgtable.h> #include <asm/tlbdebug.h>
@@ -73,12 +74,13 @@ static inline const char *msk2str(unsigned int mask)static void dump_tlb (int first,int last) { -unsigned long s_entryhi, entryhi, asid; +unsigned long s_entryhi, entryhi, asid, mmid;unsigned long long entrylo0, entrylo1, pa;unsigned int s_index, s_pagemask, s_guestctl1 =0 ;unsigned int pagemask, guestctl1 =0 , c0, c1, i;unsigned long asidmask =cpu_asid_mask (¤t_cpu_data);int asidwidth =DIV_ROUND_UP (ilog2 (asidmask) +1 ,4 ); +unsigned long uninitialized_var (s_mmid );#ifdef CONFIG_32BIT bool xpa = cpu_has_xpa && (read_c0_pagegrain () &PG_ELPA );int pwidth = xpa ?11 :8 ;
@@ -92,7 +94,12 @@ static void dump_tlb(int first, int last) s_pagemask =read_c0_pagemask (); s_entryhi =read_c0_entryhi (); s_index =read_c0_index (); - asid = s_entryhi & asidmask; + +if (cpu_has_mmid) + asid = s_mmid =read_c0_memorymapid (); +else + asid = s_entryhi & asidmask; +if (cpu_has_guestid) s_guestctl1 =read_c0_guestctl1 ();
@@ -105,6 +112,12 @@ static void dump_tlb(int first, int last) entryhi =read_c0_entryhi (); entrylo0 =read_c0_entrylo0 (); entrylo1 =read_c0_entrylo1 (); + +if (cpu_has_mmid) + mmid =read_c0_memorymapid (); +else + mmid = entryhi & asidmask; +if (cpu_has_guestid) guestctl1 =read_c0_guestctl1 ();
@@ -124,8 +137,7 @@ static void dump_tlb(int first, int last)* leave only a single G bit set after a machine check exception * due to duplicate TLB entry. */ -if (!((entrylo0 | entrylo1) &ENTRYLO_G ) && - (entryhi & asidmask) != asid) +if (!((entrylo0 | entrylo1) &ENTRYLO_G ) && (mmid != asid))continue ;/*
@@ -138,7 +150,7 @@ static void dump_tlb(int first, int last)pr_cont ("va=%0*lx asid=%0*lx" , vwidth, (entryhi & ~0x1fffUL ), - asidwidth, entryhi & asidmask); + asidwidth, mmid);if (cpu_has_guestid)pr_cont (" gid=%02lx" , (guestctl1 & MIPS_GCTL1_RID)
arch/mips/mm/c-r4k.c +3 -0
@@ -540,6 +540,9 @@ static inline int has_valid_asid(const struct mm_struct *mm, unsigned int type)unsigned int i;const cpumask_t *mask = cpu_present_mask; +if (cpu_has_mmid) +return cpu_context (0 , mm) !=0 ; +/* cpu_sibling_map[] undeclared when !CONFIG_SMP */ #ifdef CONFIG_SMP /*
arch/mips/mm/context.c +253 -3
280 lines not on this page · raw message
arch/mips/mm/init.c +7 -0
@@ -84,6 +84,7 @@ void setup_zero_pages(void)static void *__kmap_pgprot (struct page *page,unsigned long addr,pgprot_t prot) {enum fixed_addresses idx; +unsigned int uninitialized_var (old_mmid );unsigned long vaddr, flags, entrylo;unsigned long old_ctx;pte_t pte;
@@ -110,6 +111,10 @@ static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)write_c0_entryhi (vaddr & (PAGE_MASK <<1 ));write_c0_entrylo0 (entrylo);write_c0_entrylo1 (entrylo); +if (cpu_has_mmid) { + old_mmid =read_c0_memorymapid (); +write_c0_memorymapid (MMID_KERNEL_WIRED ); + }#ifdef CONFIG_XPA if (cpu_has_xpa) { entrylo = (pte.pte_low & _PFNX_MASK);
@@ -124,6 +129,8 @@ static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)tlb_write_indexed ();tlbw_use_hazard ();write_c0_entryhi (old_ctx); +if (cpu_has_mmid) +write_c0_memorymapid (old_mmid);local_irq_restore (flags);return (void *) vaddr;
arch/mips/mm/tlb-r4k.c +41 -11
111 lines not on this page · raw message
Signature · 1 line
2.20.1
Hello,
Quoted 51 lines · Paul Burton
This series introduces support for MemoryMapIDs (MMIDs) & GINVT instructions. These give us a larger, global namespace for address space IDs & allow for global invalidation of TLB entries without IPIs.
This has been tested on various configurations of the MIPS I6500, which is the first CPU to support these features.
Applies cleanly atop v5.0-rc4.
Paul Burton (14):
MIPS: mm: Defineactivate_mm()usingswitch_mm()
MIPS: mm: Remove redundantdrop_mmu_context()cpu argument
MIPS: mm: Remove redundantget_new_mmu_context()cpu argument
MIPS: mm: Avoid HTW stop/start when dropping an inactive mm
MIPS: mm: Consolidatedrop_mmu_context()has-ASID checks
MIPS: mm: Movedrop_mmu_context()comment into appropriate block
MIPS: mm: Remove redundantpreempt_disableinlocal_flush_tlb_mm()
MIPS: mm: Removelocal_flush_tlb_mm()
MIPS: mm: Split obj-y to a file per line
MIPS: mm: Un-inlineget_new_mmu_context
MIPS: mm: Unify ASID version checks
MIPS: mm: Addset_cpu_context()for ASID assignments
MIPS: Add GINVT instruction helpers
MIPS: MemoryMapID (MMID) Supportarch/mips/Makefile | 2 + arch/mips/include/asm/barrier.h | 19 ++ arch/mips/include/asm/cpu-features.h | 13 ++ arch/mips/include/asm/cpu.h | 1 + arch/mips/include/asm/ginvt.h | 56 ++++++ arch/mips/include/asm/mipsregs.h | 11 + arch/mips/include/asm/mmu.h | 6 +- arch/mips/include/asm/mmu_context.h | 139 +++++++------ arch/mips/include/asm/tlbflush.h | 5 +- arch/mips/kernel/cpu-probe.c | 55 ++++- arch/mips/kernel/smp.c | 67 ++++++- arch/mips/kernel/traps.c | 4 +- arch/mips/kernel/unaligned.c | 1 + arch/mips/kvm/emulate.c | 8 +- arch/mips/kvm/mips.c | 5 + arch/mips/kvm/trap_emul.c | 30 +-- arch/mips/kvm/vz.c | 8 +- arch/mips/lib/dump_tlb.c | 22 +- arch/mips/mm/Makefile | 16 +- arch/mips/mm/c-r4k.c | 8 +- arch/mips/mm/context.c | 288 +++++++++++++++++++++++++++ arch/mips/mm/init.c | 7 + arch/mips/mm/tlb-r3k.c | 14 +- arch/mips/mm/tlb-r4k.c | 71 ++++--- arch/mips/mm/tlb-r8k.c | 10 +- 25 files changed, 698 insertions(+), 168 deletions(-)
Quoted 2 lines
create mode 100644
arch/mips/include/asm/ginvt.h
create mode 100644arch/mips/mm/context.c
Series applied to mips-next.
Thanks,
Paul
[ This message was auto-generated; if you believe anything is incorrect
then please email [email protected] to report it. ]