Module Name:    src
Committed By:   simonb
Date:           Sun Aug 23 10:23:38 UTC 2020

Modified Files:
        src/sys/arch/mips/include: mips_param.h proc.h
        src/sys/arch/mips/mips: mipsX_subr.S vm_machdep.c

Log Message:
Use a 16kB USPACE (and larger kernel stack) for LP64 kernels.  Invert
the logic for setting the USPACE size.  Define a desired USPACE size
(16kB for LP64, 8kB otherwise) then divide by PAGE_SIZE to get UPAGES.

Fixes random segmap lossage, since the uarea usually sits immediately
above the segmap for a process.  Thanks to mrg@, skrll@ and dholland@
for testing, debugging and general help tracking down this problem.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/mips/include/mips_param.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/mips/include/proc.h
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/mips/mips/mipsX_subr.S
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/mips/mips/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/include/mips_param.h
diff -u src/sys/arch/mips/include/mips_param.h:1.45 src/sys/arch/mips/include/mips_param.h:1.46
--- src/sys/arch/mips/include/mips_param.h:1.45	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/mips_param.h	Sun Aug 23 10:23:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_param.h,v 1.45 2020/07/26 08:08:41 simonb Exp $	*/
+/*	$NetBSD: mips_param.h,v 1.46 2020/08/23 10:23:38 simonb Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -117,12 +117,18 @@
 #endif
 #define	NSEGPG		(1 << SEGLENGTH)
 
-#if PGSHIFT >= 13
-#define	UPAGES		1		/* pages of u-area */
+#ifdef _LP64
+#define	__MIN_USPACE	16384		/* LP64 needs a 16kB stack */
 #else
-#define	UPAGES		2		/* pages of u-area */
+/*
+ * Note for the non-LP64 case, cpu_switch_resume has the assumption
+ * that UPAGES == 2.  For MIPS-I we wire USPACE in TLB #0 and #1.
+ * For MIPS3+ we wire USPACE in the the TLB #0 pair.
+ */
+#define	__MIN_USPACE	8192		/* otherwise use an 8kB stack */
 #endif
-#define	USPACE		(UPAGES*NBPG)	/* size of u-area in bytes */
+#define	USPACE		MAX(__MIN_USPACE, PAGE_SIZE)
+#define	UPAGES		(USPACE / PAGE_SIZE) /* number of pages for u-area */
 #define	USPACE_ALIGN	USPACE		/* make sure it starts on a even VA */
 
 /*

Index: src/sys/arch/mips/include/proc.h
diff -u src/sys/arch/mips/include/proc.h:1.29 src/sys/arch/mips/include/proc.h:1.30
--- src/sys/arch/mips/include/proc.h:1.29	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/proc.h	Sun Aug 23 10:23:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.29 2020/07/26 08:08:41 simonb Exp $	*/
+/*	$NetBSD: proc.h,v 1.30 2020/08/23 10:23:38 simonb Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -52,7 +52,7 @@ struct mdlwp {
 	vaddr_t	md_ss_addr;		/* single step address for ptrace */
 	int	md_ss_instr;		/* single step instruction for ptrace */
 	volatile int md_astpending;	/* AST pending on return to userland */
-	int	md_upte[2];		/* ptes for mapping u page */
+	int	md_upte[UPAGES];	/* ptes for mapping u page */
 };
 
 struct mdproc {

Index: src/sys/arch/mips/mips/mipsX_subr.S
diff -u src/sys/arch/mips/mips/mipsX_subr.S:1.108 src/sys/arch/mips/mips/mipsX_subr.S:1.109
--- src/sys/arch/mips/mips/mipsX_subr.S:1.108	Sat Jun 13 12:53:42 2020
+++ src/sys/arch/mips/mips/mipsX_subr.S	Sun Aug 23 10:23:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mipsX_subr.S,v 1.108 2020/06/13 12:53:42 simonb Exp $	*/
+/*	$NetBSD: mipsX_subr.S,v 1.109 2020/08/23 10:23:38 simonb Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -2707,12 +2707,14 @@ END(MIPSX(lwp_trampoline))
  * Disable the optimisation for PGSHIFT == 14 (aka ENABLE_MIPS_16KB_PAGE)
  * as the code needs fixing for this case
  *
- * _LP64 with UPAGES == 1 is always direct mappable; everything else can have
- * non-direct mappable USPACE.
+ * A TLB entry isn't used for the following cases:
+ *  - 16kB USPACE
+ *  - LP64 - USPACE is always accessed directly via XKPHYS
  */
 
 LEAF_NOPROFILE(MIPSX(cpu_switch_resume))
-#if (PGSHIFT < 14)
+#if !defined(_LP64)
+#if (PAGE_SIZE < 16384)
 #if (USPACE > PAGE_SIZE) || !defined(_LP64)
 	INT_L	a1, L_MD_UPTE_0(a0)		# a1 = upte[0]
 #if (PGSHIFT & 1)
@@ -2789,7 +2791,8 @@ MIPSX(entry0set):
 	COP0_SYNC
 MIPSX(resume):
 #endif /* (USPACE > PAGE_SIZE) || !defined(_LP64) */
-#endif /* PGSHIFT < 14 */
+#endif /* PAGE_SIZE < 16384 */
+#endif /* ! LP64 */
 #ifdef MIPSNNR2
 	PTR_L	v0, L_PRIVATE(a0)		# get lwp private
 	_MTC0	v0, MIPS_COP_0_USERLOCAL	# make available for rdhwr

Index: src/sys/arch/mips/mips/vm_machdep.c
diff -u src/sys/arch/mips/mips/vm_machdep.c:1.161 src/sys/arch/mips/mips/vm_machdep.c:1.162
--- src/sys/arch/mips/mips/vm_machdep.c:1.161	Sun Aug  9 07:09:35 2020
+++ src/sys/arch/mips/mips/vm_machdep.c	Sun Aug 23 10:23:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.161 2020/08/09 07:09:35 skrll Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.162 2020/08/23 10:23:38 simonb Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.161 2020/08/09 07:09:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.162 2020/08/23 10:23:38 simonb Exp $");
 
 #include "opt_ddb.h"
 #include "opt_cputype.h"
@@ -120,11 +120,6 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 		l2->l_md.md_upte[i] = 0;
 	}
 	if (!pmap_md_direct_mapped_vaddr_p(ua2)) {
-		/*
-		 * UPAGES has to be 2 for 4KB PAGE_SIZE
-		 * UPAGES has to be 1 for >= 8KB PAGE_SIZE
-		 */
-		CTASSERT((PGSHIFT == 12) == (UPAGES == 2));
 		pt_entry_t * const pte = pmap_pte_lookup(pmap_kernel(), ua2);
 		const uint32_t x = MIPS_HAS_R4K_MMU
 		    ? (MIPS3_PG_RO | MIPS3_PG_WIRED)

Reply via email to