linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@mips.com>
To: "linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>
Cc: Paul Burton <pburton@wavecomp.com>
Subject: [PATCH 11/14] MIPS: mm: Unify ASID version checks
Date: Sat, 2 Feb 2019 01:43:25 +0000	[thread overview]
Message-ID: <20190202014242.30680-12-paul.burton@mips.com> (raw)
In-Reply-To: <20190202014242.30680-1-paul.burton@mips.com>

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>
---

 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(-)

diff --git a/arch/mips/include/asm/mmu_context.h b/arch/mips/include/asm/mmu_context.h
index cb39a39d02f6..336682fb48de 100644
--- a/arch/mips/include/asm/mmu_context.h
+++ b/arch/mips/include/asm/mmu_context.h
@@ -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.
diff --git a/arch/mips/kvm/trap_emul.c b/arch/mips/kvm/trap_emul.c
index 503c2fb7e4da..22ffe72a9e4b 100644
--- a/arch/mips/kvm/trap_emul.c
+++ b/arch/mips/kvm/trap_emul.c
@@ -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();
diff --git a/arch/mips/kvm/vz.c b/arch/mips/kvm/vz.c
index d98c12a22eac..dde20887a70d 100644
--- a/arch/mips/kvm/vz.c
+++ b/arch/mips/kvm/vz.c
@@ -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);
 	}
 }
 
diff --git a/arch/mips/mm/context.c b/arch/mips/mm/context.c
index b5af471006f0..4dd976acf41d 100644
--- a/arch/mips/mm/context.c
+++ b/arch/mips/mm/context.c
@@ -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);
+}
-- 
2.20.1


  parent reply	other threads:[~2019-02-02  1:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-02  1:43 [PATCH 00/14] MIPS: MemoryMapID (MMID) & GINVT Support Paul Burton
2019-02-02  1:43 ` [PATCH 01/14] MIPS: mm: Define activate_mm() using switch_mm() Paul Burton
2019-02-02  1:43 ` [PATCH 02/14] MIPS: mm: Remove redundant drop_mmu_context() cpu argument Paul Burton
2019-02-02  1:43 ` [PATCH 03/14] MIPS: mm: Remove redundant get_new_mmu_context() " Paul Burton
2019-02-02  1:43 ` [PATCH 04/14] MIPS: mm: Avoid HTW stop/start when dropping an inactive mm Paul Burton
2019-02-02  1:43 ` [PATCH 05/14] MIPS: mm: Consolidate drop_mmu_context() has-ASID checks Paul Burton
2019-02-02  1:43 ` [PATCH 06/14] MIPS: mm: Move drop_mmu_context() comment into appropriate block Paul Burton
2019-02-02  1:43 ` [PATCH 07/14] MIPS: mm: Remove redundant preempt_disable in local_flush_tlb_mm() Paul Burton
2019-02-02  1:43 ` [PATCH 08/14] MIPS: mm: Remove local_flush_tlb_mm() Paul Burton
2019-02-02  1:43 ` [PATCH 09/14] MIPS: mm: Split obj-y to a file per line Paul Burton
2019-02-02  1:43 ` [PATCH 10/14] MIPS: mm: Un-inline get_new_mmu_context Paul Burton
2019-02-02  1:43 ` [PATCH 12/14] MIPS: mm: Add set_cpu_context() for ASID assignments Paul Burton
2019-02-02  1:43 ` Paul Burton [this message]
2019-02-02  1:43 ` [PATCH 13/14] MIPS: Add GINVT instruction helpers Paul Burton
2019-02-02  1:43 ` [PATCH 14/14] MIPS: MemoryMapID (MMID) Support Paul Burton
2019-02-04 21:18 ` [PATCH 00/14] MIPS: MemoryMapID (MMID) & GINVT Support Paul Burton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190202014242.30680-12-paul.burton@mips.com \
    --to=paul.burton@mips.com \
    --cc=linux-mips@vger.kernel.org \
    --cc=pburton@wavecomp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).