Commit 0ae79068 authored by Michael Ellerman's avatar Michael Ellerman
Browse files

powerpc/mm/64s: Consolidate SLB assertions



The code for assert_slb_exists() and assert_slb_notexists() is almost
identical, except for the polarity of the WARN_ON(). In a future patch
we'll need to modify this code, so consolidate it now into a single
function.

Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 3182215d
Loading
Loading
Loading
Loading
+9 −20
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ static inline unsigned long mk_vsid_data(unsigned long ea, int ssize,
	return __mk_vsid_data(get_kernel_vsid(ea, ssize), ssize, flags);
}

static void assert_slb_exists(unsigned long ea)
static void assert_slb_presence(bool present, unsigned long ea)
{
#ifdef CONFIG_DEBUG_VM
	unsigned long tmp;
@@ -66,19 +66,8 @@ static void assert_slb_exists(unsigned long ea)
	WARN_ON_ONCE(mfmsr() & MSR_EE);

	asm volatile("slbfee. %0, %1" : "=r"(tmp) : "r"(ea) : "cr0");
	WARN_ON(tmp == 0);
#endif
}

static void assert_slb_notexists(unsigned long ea)
{
#ifdef CONFIG_DEBUG_VM
	unsigned long tmp;

	WARN_ON_ONCE(mfmsr() & MSR_EE);

	asm volatile("slbfee. %0, %1" : "=r"(tmp) : "r"(ea) : "cr0");
	WARN_ON(tmp != 0);
	WARN_ON(present == (tmp == 0));
#endif
}

@@ -114,7 +103,7 @@ static inline void create_shadowed_slbe(unsigned long ea, int ssize,
	 */
	slb_shadow_update(ea, ssize, flags, index);

	assert_slb_notexists(ea);
	assert_slb_presence(false, ea);
	asm volatile("slbmte  %0,%1" :
		     : "r" (mk_vsid_data(ea, ssize, flags)),
		       "r" (mk_esid_data(ea, ssize, index))
@@ -137,7 +126,7 @@ void __slb_restore_bolted_realmode(void)
		       "r" (be64_to_cpu(p->save_area[index].esid)));
	}

	assert_slb_exists(local_paca->kstack);
	assert_slb_presence(true, local_paca->kstack);
}

/*
@@ -185,7 +174,7 @@ void slb_flush_and_restore_bolted(void)
		     :: "r" (be64_to_cpu(p->save_area[KSTACK_INDEX].vsid)),
			"r" (be64_to_cpu(p->save_area[KSTACK_INDEX].esid))
		     : "memory");
	assert_slb_exists(get_paca()->kstack);
	assert_slb_presence(true, get_paca()->kstack);

	get_paca()->slb_cache_ptr = 0;

@@ -443,9 +432,9 @@ void switch_slb(struct task_struct *tsk, struct mm_struct *mm)
				ea = (unsigned long)
					get_paca()->slb_cache[i] << SID_SHIFT;
				/*
				 * Could assert_slb_exists here, but hypervisor
				 * or machine check could have come in and
				 * removed the entry at this point.
				 * Could assert_slb_presence(true) here, but
				 * hypervisor or machine check could have come
				 * in and removed the entry at this point.
				 */

				slbie_data = ea;
@@ -676,7 +665,7 @@ static long slb_insert_entry(unsigned long ea, unsigned long context,
	 * User preloads should add isync afterwards in case the kernel
	 * accesses user memory before it returns to userspace with rfid.
	 */
	assert_slb_notexists(ea);
	assert_slb_presence(false, ea);
	asm volatile("slbmte %0, %1" : : "r" (vsid_data), "r" (esid_data));

	barrier();