Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dedeb002 authored by Hugh Dickins's avatar Hugh Dickins Committed by David S. Miller
Browse files

[SPARC64] mm: context switch ptlock



sparc64 is unique among architectures in taking the page_table_lock in
its context switch (well, cris does too, but erroneously, and it's not
yet SMP anyway).

This seems to be a private affair between switch_mm and activate_mm,
using page_table_lock as a per-mm lock, without any relation to its uses
elsewhere.  That's fine, but comment it as such; and unlock sooner in
switch_mm, more like in activate_mm (preemption is disabled here).

There is a block of "if (0)"ed code in smp_flush_tlb_pending which would
have liked to rely on the page_table_lock, in switch_mm and elsewhere;
but its comment explains how dup_mmap's flush_tlb_mm defeated it.  And
though that could have been changed at any time over the past few years,
now the chance vanishes as we push the page_table_lock downwards, and
perhaps split it per page table page.  Just delete that block of code.

Which leaves the mysterious spin_unlock_wait(&oldmm->page_table_lock)
in kernel/fork.c copy_mm.  Textual analysis (supported by Nick Piggin)
suggests that the comment was written by DaveM, and that it relates to
the defeated approach in the sparc64 smp_flush_tlb_pending.  Just delete
this block too.

Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b8ae4865
Loading
Loading
Loading
Loading
+5 −26
Original line number Original line Diff line number Diff line
@@ -883,34 +883,13 @@ void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long
	u32 ctx = CTX_HWBITS(mm->context);
	u32 ctx = CTX_HWBITS(mm->context);
	int cpu = get_cpu();
	int cpu = get_cpu();


	if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1) {
	if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1)
		mm->cpu_vm_mask = cpumask_of_cpu(cpu);
		mm->cpu_vm_mask = cpumask_of_cpu(cpu);
		goto local_flush_and_out;
	else
	} else {
		/* This optimization is not valid.  Normally
		 * we will be holding the page_table_lock, but
		 * there is an exception which is copy_page_range()
		 * when forking.  The lock is held during the individual
		 * page table updates in the parent, but not at the
		 * top level, which is where we are invoked.
		 */
		if (0) {
			cpumask_t this_cpu_mask = cpumask_of_cpu(cpu);

			/* By virtue of running under the mm->page_table_lock,
			 * and mmu_context.h:switch_mm doing the same, the
			 * following operation is safe.
			 */
			if (cpus_equal(mm->cpu_vm_mask, this_cpu_mask))
				goto local_flush_and_out;
		}
	}

		smp_cross_call_masked(&xcall_flush_tlb_pending,
		smp_cross_call_masked(&xcall_flush_tlb_pending,
				      ctx, nr, (unsigned long) vaddrs,
				      ctx, nr, (unsigned long) vaddrs,
				      mm->cpu_vm_mask);
				      mm->cpu_vm_mask);


local_flush_and_out:
	__flush_tlb_pending(ctx, nr, vaddrs);
	__flush_tlb_pending(ctx, nr, vaddrs);


	put_cpu();
	put_cpu();
+24 −22
Original line number Original line Diff line number Diff line
@@ -87,38 +87,36 @@ extern void __flush_tlb_mm(unsigned long, unsigned long);
static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
{
{
	unsigned long ctx_valid;
	unsigned long ctx_valid;
	int cpu;


	/* Note: page_table_lock is used here to serialize switch_mm
	 * and activate_mm, and their calls to get_new_mmu_context.
	 * This use of page_table_lock is unrelated to its other uses.
	 */ 
	spin_lock(&mm->page_table_lock);
	spin_lock(&mm->page_table_lock);
	if (CTX_VALID(mm->context))
	ctx_valid = CTX_VALID(mm->context);
		ctx_valid = 1;
        else
		ctx_valid = 0;

	if (!ctx_valid || (old_mm != mm)) {
	if (!ctx_valid)
	if (!ctx_valid)
		get_new_mmu_context(mm);
		get_new_mmu_context(mm);
	spin_unlock(&mm->page_table_lock);


	if (!ctx_valid || (old_mm != mm)) {
		load_secondary_context(mm);
		load_secondary_context(mm);
		reload_tlbmiss_state(tsk, mm);
		reload_tlbmiss_state(tsk, mm);
	}
	}


	{
		int cpu = smp_processor_id();

	/* Even if (mm == old_mm) we _must_ check
	/* Even if (mm == old_mm) we _must_ check
	 * the cpu_vm_mask.  If we do not we could
	 * the cpu_vm_mask.  If we do not we could
	 * corrupt the TLB state because of how
	 * corrupt the TLB state because of how
	 * smp_flush_tlb_{page,range,mm} on sparc64
	 * smp_flush_tlb_{page,range,mm} on sparc64
	 * and lazy tlb switches work. -DaveM
	 * and lazy tlb switches work. -DaveM
	 */
	 */
	cpu = smp_processor_id();
	if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
	if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
		cpu_set(cpu, mm->cpu_vm_mask);
		cpu_set(cpu, mm->cpu_vm_mask);
		__flush_tlb_mm(CTX_HWBITS(mm->context),
		__flush_tlb_mm(CTX_HWBITS(mm->context),
			       SECONDARY_CONTEXT);
			       SECONDARY_CONTEXT);
	}
	}
}
}
	spin_unlock(&mm->page_table_lock);
}


#define deactivate_mm(tsk,mm)	do { } while (0)
#define deactivate_mm(tsk,mm)	do { } while (0)


@@ -127,6 +125,10 @@ static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm
{
{
	int cpu;
	int cpu;


	/* Note: page_table_lock is used here to serialize switch_mm
	 * and activate_mm, and their calls to get_new_mmu_context.
	 * This use of page_table_lock is unrelated to its other uses.
	 */ 
	spin_lock(&mm->page_table_lock);
	spin_lock(&mm->page_table_lock);
	if (!CTX_VALID(mm->context))
	if (!CTX_VALID(mm->context))
		get_new_mmu_context(mm);
		get_new_mmu_context(mm);
+0 −7
Original line number Original line Diff line number Diff line
@@ -470,13 +470,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
	if (clone_flags & CLONE_VM) {
	if (clone_flags & CLONE_VM) {
		atomic_inc(&oldmm->mm_users);
		atomic_inc(&oldmm->mm_users);
		mm = oldmm;
		mm = oldmm;
		/*
		 * There are cases where the PTL is held to ensure no
		 * new threads start up in user mode using an mm, which
		 * allows optimizing out ipis; the tlb_gather_mmu code
		 * is an example.
		 */
		spin_unlock_wait(&oldmm->page_table_lock);
		goto good_mm;
		goto good_mm;
	}
	}