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 12/14] MIPS: mm: Add set_cpu_context() for ASID assignments
Date: Sat, 2 Feb 2019 01:43:25 +0000	[thread overview]
Message-ID: <20190202014242.30680-13-paul.burton@mips.com> (raw)
In-Reply-To: <20190202014242.30680-1-paul.burton@mips.com>

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

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

diff --git a/arch/mips/include/asm/mmu_context.h b/arch/mips/include/asm/mmu_context.h
index 336682fb48de..a0f29df8ced8 100644
--- a/arch/mips/include/asm/mmu_context.h
+++ b/arch/mips/include/asm/mmu_context.h
@@ -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);
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index d7088ca31e43..f9dbd95e1d68 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -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);
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index ca8347372427..0074427b04fb 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -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();
diff --git a/arch/mips/kvm/trap_emul.c b/arch/mips/kvm/trap_emul.c
index 22ffe72a9e4b..73daa6ad33af 100644
--- a/arch/mips/kvm/trap_emul.c
+++ b/arch/mips/kvm/trap_emul.c
@@ -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;
 		}
 	}
diff --git a/arch/mips/mm/context.c b/arch/mips/mm/context.c
index 4dd976acf41d..dcaceee179f7 100644
--- a/arch/mips/mm/context.c
+++ b/arch/mips/mm/context.c
@@ -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)
-- 
2.20.1


  parent reply	other threads:[~2019-02-02  1:43 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 ` Paul Burton [this message]
2019-02-02  1:43 ` [PATCH 11/14] MIPS: mm: Unify ASID version checks Paul Burton
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-13-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).