CVS commit: src/sys/sys

2020-12-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Dec 22 01:58:58 UTC 2020

Modified Files:
src/sys/sys: lock.h

Log Message:
Nothing here came from UCB, it's all NetBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/sys/lock.h

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

Modified files:

Index: src/sys/sys/lock.h
diff -u src/sys/sys/lock.h:1.90 src/sys/sys/lock.h:1.91
--- src/sys/sys/lock.h:1.90	Mon Jul  6 22:32:22 2020
+++ src/sys/sys/lock.h	Tue Dec 22 01:58:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock.h,v 1.90 2020/07/06 22:32:22 rin Exp $	*/
+/*	$NetBSD: lock.h,v 1.91 2020/12/22 01:58:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,41 +30,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Copyright (c) 1995
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code contains ideas from software contributed to Berkeley by
- * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
- * System project at Carnegie-Mellon University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)lock.h	8.12 (Berkeley) 5/19/95
- */
-
 #ifndef	_SYS_LOCK_H_
 #define	_SYS_LOCK_H_
 



CVS commit: src/sys/kern

2020-12-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Dec 22 01:57:29 UTC 2020

Modified Files:
src/sys/kern: kern_lock.c subr_xcall.c

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/subr_xcall.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/kern/kern_lock.c
diff -u src/sys/kern/kern_lock.c:1.171 src/sys/kern/kern_lock.c:1.172
--- src/sys/kern/kern_lock.c:1.171	Sat May  2 09:13:40 2020
+++ src/sys/kern/kern_lock.c	Tue Dec 22 01:57:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lock.c,v 1.171 2020/05/02 09:13:40 martin Exp $	*/
+/*	$NetBSD: kern_lock.c,v 1.172 2020/12/22 01:57:29 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.171 2020/05/02 09:13:40 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.172 2020/12/22 01:57:29 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lockdebug.h"
@@ -215,10 +215,6 @@ _kernel_lock(int nlocks)
 	 * is required to ensure that the result of any mutex_exit()
 	 * by the current LWP becomes visible on the bus before the set
 	 * of ci->ci_biglock_wanted becomes visible.
-	 *
-	 * However, we won't set ci_biglock_wanted until we've spun for
-	 * a bit, as we don't want to make any lock waiters in rw_oncpu()
-	 * or mutex_oncpu() block prematurely.
 	 */
 	membar_producer();
 	owant = ci->ci_biglock_wanted;

Index: src/sys/kern/subr_xcall.c
diff -u src/sys/kern/subr_xcall.c:1.33 src/sys/kern/subr_xcall.c:1.34
--- src/sys/kern/subr_xcall.c:1.33	Thu Dec 19 10:51:54 2019
+++ src/sys/kern/subr_xcall.c	Tue Dec 22 01:57:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_xcall.c,v 1.33 2019/12/19 10:51:54 thorpej Exp $	*/
+/*	$NetBSD: subr_xcall.c,v 1.34 2020/12/22 01:57:29 ad Exp $	*/
 
 /*-
  * Copyright (c) 2007-2010, 2019 The NetBSD Foundation, Inc.
@@ -48,12 +48,12 @@
  *	prohibitive, another way must be found.
  *
  *	Cross calls help to solve these types of problem by allowing
- *	any CPU in the system to request that an arbitrary function be
- *	executed on any other CPU.
+ *	any LWP in the system to request that an arbitrary function be
+ *	executed on a specific CPU.
  *
  * Implementation
  *
- *	A slow mechanism for making 'low priority' cross calls is
+ *	A slow mechanism for making low priority cross calls is
  *	provided.  The function to be executed runs on the remote CPU
  *	within a bound kthread.  No queueing is provided, and the
  *	implementation uses global state.  The function being called may
@@ -64,17 +64,17 @@
  *	CPU, and so has exclusive access to the CPU.  Since this facility
  *	is heavyweight, it's expected that it will not be used often.
  *
- *	Cross calls must not allocate memory, as the pagedaemon uses
- *	them (and memory allocation may need to wait on the pagedaemon).
+ *	Cross calls must not allocate memory, as the pagedaemon uses cross
+ *	calls (and memory allocation may need to wait on the pagedaemon).
  *
  *	A low-overhead mechanism for high priority calls (XC_HIGHPRI) is
- *	also provided.  The function to be executed runs on a software
- *	interrupt context, at IPL_SOFTSERIAL level, and is expected to
+ *	also provided.  The function to be executed runs in software
+ *	interrupt context at IPL_SOFTSERIAL level, and is expected to
  *	be very lightweight, e.g. avoid blocking.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.33 2019/12/19 10:51:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.34 2020/12/22 01:57:29 ad Exp $");
 
 #include 
 #include 



CVS commit: src/sys/arch/arm

2020-06-15 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun 15 18:57:39 UTC 2020

Modified Files:
src/sys/arch/arm/acpi: acpi_pci_graviton.c acpi_pci_layerscape_gen4.c
acpi_pci_machdep.c acpi_pci_n1sdp.c acpipchb.c
src/sys/arch/arm/imx: imxgpio.c

Log Message:
Use sys/cpu.h so that curcpu defined in terms of curlwp->l_cpu works too.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/acpi/acpi_pci_graviton.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c \
src/sys/arch/arm/acpi/acpi_pci_n1sdp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/acpi/acpi_pci_machdep.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/acpi/acpipchb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/imx/imxgpio.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/arm/acpi/acpi_pci_graviton.c
diff -u src/sys/arch/arm/acpi/acpi_pci_graviton.c:1.1 src/sys/arch/arm/acpi/acpi_pci_graviton.c:1.2
--- src/sys/arch/arm/acpi/acpi_pci_graviton.c:1.1	Fri Jan 17 17:06:33 2020
+++ src/sys/arch/arm/acpi/acpi_pci_graviton.c	Mon Jun 15 18:57:39 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: acpi_pci_graviton.c,v 1.1 2020/01/17 17:06:33 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_graviton.c,v 1.2 2020/06/15 18:57:39 ad Exp $ */
 
 /*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_graviton.c,v 1.1 2020/01/17 17:06:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_graviton.c,v 1.2 2020/06/15 18:57:39 ad Exp $");
 
 #include 
 #include 
@@ -40,8 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci_gra
 #include 
 #include 
 #include 
-
-#include 
+#include 
 
 #include 
 #include 

Index: src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c
diff -u src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c:1.2 src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c:1.3
--- src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c:1.2	Sun Feb  2 16:44:25 2020
+++ src/sys/arch/arm/acpi/acpi_pci_layerscape_gen4.c	Mon Jun 15 18:57:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_layerscape_gen4.c,v 1.2 2020/02/02 16:44:25 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_layerscape_gen4.c,v 1.3 2020/06/15 18:57:39 ad Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_layerscape_gen4.c,v 1.2 2020/02/02 16:44:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_layerscape_gen4.c,v 1.3 2020/06/15 18:57:39 ad Exp $");
 
 #include 
 #include 
@@ -45,8 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci_lay
 #include 
 #include 
 #include 
-
-#include 
+#include 
 
 #include 
 #include 
Index: src/sys/arch/arm/acpi/acpi_pci_n1sdp.c
diff -u src/sys/arch/arm/acpi/acpi_pci_n1sdp.c:1.2 src/sys/arch/arm/acpi/acpi_pci_n1sdp.c:1.3
--- src/sys/arch/arm/acpi/acpi_pci_n1sdp.c:1.2	Thu Feb 13 00:02:40 2020
+++ src/sys/arch/arm/acpi/acpi_pci_n1sdp.c	Mon Jun 15 18:57:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_n1sdp.c,v 1.2 2020/02/13 00:02:40 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_n1sdp.c,v 1.3 2020/06/15 18:57:39 ad Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_n1sdp.c,v 1.2 2020/02/13 00:02:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_n1sdp.c,v 1.3 2020/06/15 18:57:39 ad Exp $");
 
 #include 
 #include 
@@ -40,8 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci_n1s
 #include 
 #include 
 #include 
-
-#include 
+#include 
 
 #include 
 #include 

Index: src/sys/arch/arm/acpi/acpi_pci_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.16 src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.17
--- src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.16	Thu Feb 13 00:02:21 2020
+++ src/sys/arch/arm/acpi/acpi_pci_machdep.c	Mon Jun 15 18:57:39 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: acpi_pci_machdep.c,v 1.16 2020/02/13 00:02:21 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_machdep.c,v 1.17 2020/06/15 18:57:39 ad Exp $ */
 
 /*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -32,7 +32,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.16 2020/02/13 00:02:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.17 2020/06/15 18:57:39 ad Exp $");
 
 #include 
 #include 
@@ -44,8 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci_mac
 #include 
 #include 
 #include 
-
-#include 
+#include 
 
 #include 
 

Index: src/sys/arch/arm/acpi/acpipchb.c
diff -u src/sys/arch/arm/acpi/acpipchb.c:1.18 src/sys/arch/arm/acpi/acpipchb.c:1.19
--- 

CVS commit: src/sys/kern

2020-06-15 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun 15 18:44:10 UTC 2020

Modified Files:
src/sys/kern: vfs_lookup.c

Log Message:
lookup_fastforward():

- If the root vnode of a mount is being reclaimed concurrent to a lookup,
  it's possbile to become confounded and bail out of the loop with both
  foundobj=NULL and searchdir=NULL (causing a NULL pointer deref).  If that
  happens everything should be rolled back to the start for retry.  Problem
  found and debugged by hannken@.

- If the terminal node was !VDIR then searchdir was needlessly referenced.
  No functional impact.


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/kern/vfs_lookup.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/kern/vfs_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.223 src/sys/kern/vfs_lookup.c:1.224
--- src/sys/kern/vfs_lookup.c:1.223	Thu Jun  4 03:12:26 2020
+++ src/sys/kern/vfs_lookup.c	Mon Jun 15 18:44:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.223 2020/06/04 03:12:26 riastradh Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.224 2020/06/15 18:44:10 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.223 2020/06/04 03:12:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.224 2020/06/15 18:44:10 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -1382,6 +1382,9 @@ lookup_fastforward(struct namei_state *s
 			if (error != 0) {
 foundobj = NULL;
 error = EOPNOTSUPP;
+			} else {
+terminal = (foundobj->v_type != VLNK &&
+(cnp->cn_flags & ISLASTCN) != 0);
 			}
 			break;
 		}
@@ -1458,7 +1461,16 @@ lookup_fastforward(struct namei_state *s
 		 * fastforward to the beginning and let lookup_once() take
 		 * care of it.
 		 */
-		error2 = vcache_tryvget(searchdir);
+		if (searchdir == NULL) {
+			/*
+			 * It's possible for searchdir to be NULL in the
+			 * case of a root vnode being reclaimed while
+			 * trying to cross a mount.
+			 */
+			error2 = EOPNOTSUPP;
+		} else {
+			error2 = vcache_tryvget(searchdir);
+		}
 		KASSERT(plock != NULL);
 		rw_exit(plock);
 		if (__predict_true(error2 == 0)) {



CVS commit: src/sys/sys

2020-06-15 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun 15 18:04:42 UTC 2020

Modified Files:
src/sys/sys: cpu.h

Log Message:
Fix a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/sys/cpu.h

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

Modified files:

Index: src/sys/sys/cpu.h
diff -u src/sys/sys/cpu.h:1.50 src/sys/sys/cpu.h:1.51
--- src/sys/sys/cpu.h:1.50	Sat Feb 15 07:20:40 2020
+++ src/sys/sys/cpu.h	Mon Jun 15 18:04:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.50 2020/02/15 07:20:40 skrll Exp $	*/
+/*	$NetBSD: cpu.h,v 1.51 2020/06/15 18:04:42 ad Exp $	*/
 
 /*-
  * Copyright (c) 2007 YAMAMOTO Takashi,
@@ -135,8 +135,8 @@ int cpu_ucode_md_open(firmware_handle_t 
 #endif	/* !_LOCORE */
 
 /*
- * Flags for cpu_need_resched.  RESCHED_KERNEL must be greater than
- * RESCHED_USER; see sched_resched_cpu().
+ * Flags for cpu_need_resched.  RESCHED_KPREEMPT must be greater than
+ * RESCHED_UPREEMPT; see sched_resched_cpu().
  */
 #define	RESCHED_REMOTE		0x01	/* request is for a remote CPU */
 #define	RESCHED_IDLE		0x02	/* idle LWP observed */



CVS commit: src/sys/arch/x86/x86

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 23:24:20 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
tsc_get_timecount(): disable the "clock goes backwards" check on i386 for
the moment since it requires 64-bit store to be atomic because of nesting
via interrupt.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/x86/x86/tsc.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/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.49 src/sys/arch/x86/x86/tsc.c:1.50
--- src/sys/arch/x86/x86/tsc.c:1.49	Sat Jun 13 23:58:52 2020
+++ src/sys/arch/x86/x86/tsc.c	Sun Jun 14 23:24:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.49 2020/06/13 23:58:52 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.50 2020/06/14 23:24:20 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.49 2020/06/13 23:58:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.50 2020/06/14 23:24:20 ad Exp $");
 
 #include 
 #include 
@@ -357,6 +357,7 @@ tsc_delay(unsigned int us)
 static u_int
 tsc_get_timecount(struct timecounter *tc)
 {
+#ifdef _LP64 /* requires atomic 64-bit store */
 	static __cpu_simple_lock_t lock = __SIMPLELOCK_UNLOCKED;
 	static int lastwarn;
 	uint64_t cur, prev;
@@ -385,4 +386,7 @@ tsc_get_timecount(struct timecounter *tc
 	}
 	l->l_md.md_tsc = cur;
 	return (uint32_t)cur;
+#else
+	return cpu_counter32();
+#endif
 }



CVS commit: src/sys/kern

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 23:17:01 UTC 2020

Modified Files:
src/sys/kern: subr_pool.c

Log Message:
Arithmetic error in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.271 -r1.272 src/sys/kern/subr_pool.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/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.271 src/sys/kern/subr_pool.c:1.272
--- src/sys/kern/subr_pool.c:1.271	Sun Jun 14 21:34:25 2020
+++ src/sys/kern/subr_pool.c	Sun Jun 14 23:17:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pool.c,v 1.271 2020/06/14 21:34:25 ad Exp $	*/
+/*	$NetBSD: subr_pool.c,v 1.272 2020/06/14 23:17:01 ad Exp $	*/
 
 /*
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018,
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.271 2020/06/14 21:34:25 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.272 2020/06/14 23:17:01 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -3353,7 +3353,7 @@ pool_sysctl(SYSCTLFN_ARGS)
 data.pr_cache_nhit_pcpu += cc->cc_hits;
 data.pr_cache_nmiss_global += cc->cc_pcmisses;
 nfull += cc->cc_nfull; /* 32-bit rollover! */
-data.pr_cache_npartial = cc->cc_npart;
+data.pr_cache_npartial += cc->cc_npart;
 			}
 			data.pr_cache_nfull = nfull;
 		} else {



CVS commit: src/sys/uvm

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 22:25:15 UTC 2020

Modified Files:
src/sys/uvm: uvm_extern.h

Log Message:
g/c vm_page_zero_enable


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 src/sys/uvm/uvm_extern.h

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

Modified files:

Index: src/sys/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.229 src/sys/uvm/uvm_extern.h:1.230
--- src/sys/uvm/uvm_extern.h:1.229	Sat Jun 13 19:55:58 2020
+++ src/sys/uvm/uvm_extern.h	Sun Jun 14 22:25:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.229 2020/06/13 19:55:58 ad Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.230 2020/06/14 22:25:15 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -515,8 +515,6 @@ struct uvmexp_sysctl {
 #ifdef _KERNEL
 /* we need this before including uvm_page.h on some platforms */
 extern struct uvmexp uvmexp;
-/* MD code needs this without including  */
-extern bool vm_page_zero_enable;
 #endif
 
 /*



CVS commit: src/sys/arch/aarch64

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:47:15 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c
src/sys/arch/aarch64/include: pmap.h

Log Message:
- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
  needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
  pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page.  This means PV entries don't need to
  be allocated for private anonymous memory / COW pages / most UBC mappings.
  Dynamic PV entries are then used only for stuff like shared libraries and
  shared memory.

Proposed on port-arm@.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/aarch64/include/pmap.h

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/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.77 src/sys/arch/aarch64/aarch64/pmap.c:1.78
--- src/sys/arch/aarch64/aarch64/pmap.c:1.77	Wed Jun 10 22:24:22 2020
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Jun 14 21:47:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.77 2020/06/10 22:24:22 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.78 2020/06/14 21:47:14 ad Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.77 2020/06/10 22:24:22 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.78 2020/06/14 21:47:14 ad Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -102,8 +102,9 @@ PMAP_COUNTER(pdp_alloc_boot, "page table
 PMAP_COUNTER(pdp_alloc, "page table page allocate (uvm_pagealloc)");
 PMAP_COUNTER(pdp_free, "page table page free (uvm_pagefree)");
 
-PMAP_COUNTER(pv_enter, "pv_entry allocate and link");
-PMAP_COUNTER(pv_remove, "pv_entry free and unlink");
+PMAP_COUNTER(pv_enter, "pv_entry fill");
+PMAP_COUNTER(pv_remove_dyn, "pv_entry free and unlink dynamic");
+PMAP_COUNTER(pv_remove_emb, "pv_entry clear embedded");
 PMAP_COUNTER(pv_remove_nopv, "no pv_entry found when removing pv");
 
 PMAP_COUNTER(activate, "pmap_activate call");
@@ -184,15 +185,6 @@ PMAP_COUNTER(unwire_failure, "pmap_unwir
 
 #define VM_PAGE_TO_PP(pg)	(&(pg)->mdpage.mdpg_pp)
 
-struct pv_entry {
-	LIST_ENTRY(pv_entry) pv_link;
-	struct pmap *pv_pmap;
-	vaddr_t pv_va;
-	paddr_t pv_pa;		/* debug */
-	pt_entry_t *pv_ptep;	/* for fast pte lookup */
-};
-#define pv_next	pv_link.le_next
-
 #define L3INDEXMASK	(L3_SIZE * Ln_ENTRIES - 1)
 #define PDPSWEEP_TRIGGER	512
 
@@ -204,7 +196,7 @@ static void _pmap_remove(struct pmap *, 
 struct pv_entry **);
 static int _pmap_enter(struct pmap *, vaddr_t, paddr_t, vm_prot_t, u_int, bool);
 
-static struct pmap kernel_pmap;
+static struct pmap kernel_pmap __cacheline_aligned;
 
 struct pmap * const kernel_pmap_ptr = _pmap;
 static vaddr_t pmap_maxkvaddr;
@@ -223,27 +215,48 @@ static inline void
 pmap_pv_lock(struct pmap_page *pp)
 {
 
-	mutex_enter(>pp_pvlock);
+	mutex_spin_enter(>pp_pvlock);
 }
 
 static inline void
 pmap_pv_unlock(struct pmap_page *pp)
 {
 
-	mutex_exit(>pp_pvlock);
+	mutex_spin_exit(>pp_pvlock);
 }
 
 
 static inline void
 pm_lock(struct pmap *pm)
 {
-	mutex_enter(>pm_lock);
+	mutex_spin_enter(>pm_lock);
 }
 
 static inline void
 pm_unlock(struct pmap *pm)
 {
-	mutex_exit(>pm_lock);
+	mutex_spin_exit(>pm_lock);
+}
+
+static bool
+pm_reverse_lock(struct pmap *pm, struct pmap_page *pp)
+{
+
+	KASSERT(mutex_owned(>pp_pvlock));
+
+	if (__predict_true(mutex_tryenter(>pm_lock)))
+		return true;
+
+	if (pm != pmap_kernel())
+		pmap_reference(pm);
+	mutex_spin_exit(>pp_pvlock);
+	mutex_spin_enter(>pm_lock);
+	/* nothing, just wait for lock */
+	mutex_spin_exit(>pm_lock);
+	if (pm != pmap_kernel())
+		pmap_destroy(pm);
+	mutex_spin_enter(>pp_pvlock);
+	return false;
 }
 
 static inline struct pmap_page *
@@ -466,14 +479,22 @@ pmap_bootstrap(vaddr_t vstart, vaddr_t v
 
 	CTASSERT(sizeof(kpm->pm_stats.wired_count) == sizeof(long));
 	CTASSERT(sizeof(kpm->pm_stats.resident_count) == sizeof(long));
-#define PMSTAT_INC_WIRED_COUNT(pm)	\
-	atomic_inc_ulong(&(pm)->pm_stats.wired_count)
-#define PMSTAT_DEC_WIRED_COUNT(pm)	\
-	atomic_dec_ulong(&(pm)->pm_stats.wired_count)
-#define PMSTAT_INC_RESIDENT_COUNT(pm)	\
-	atomic_inc_ulong(&(pm)->pm_stats.resident_count)
-#define PMSTAT_DEC_RESIDENT_COUNT(pm)	\
-	atomic_dec_ulong(&(pm)->pm_stats.resident_count)
+#define PMSTAT_INC_WIRED_COUNT(pm) do { \
+	KASSERT(mutex_owned(&(pm)->pm_lock)); \
+	(pm)->pm_stats.wired_count++; \
+} while (/* CONSTCOND */ 0);
+#define PMSTAT_DEC_WIRED_COUNT(pm) do{ \
+	KASSERT(mutex_owned(&(pm)->pm_lock)); \
+	(pm)->pm_stats.wired_count--; \
+} while (/* CONSTCOND */ 0);
+#define PMSTAT_INC_RESIDENT_COUNT(pm) do { \
+	

CVS commit: src

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:41:42 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c
src/sys/sys: cpu_data.h
src/sys/uvm: uvm_glue.c uvm_meter.c uvm_page.c uvm_page.h
uvm_pgflcache.c uvm_pglist.c uvm_stat.c
src/usr.bin/vmstat: vmstat.c

Log Message:
Remove PG_ZERO.  It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


To generate a diff of this commit:
cvs rdiff -u -r1.398 -r1.399 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.51 -r1.52 src/sys/sys/cpu_data.h
cvs rdiff -u -r1.180 -r1.181 src/sys/uvm/uvm_glue.c
cvs rdiff -u -r1.79 -r1.80 src/sys/uvm/uvm_meter.c
cvs rdiff -u -r1.241 -r1.242 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.104 -r1.105 src/sys/uvm/uvm_page.h
cvs rdiff -u -r1.4 -r1.5 src/sys/uvm/uvm_pgflcache.c
cvs rdiff -u -r1.84 -r1.85 src/sys/uvm/uvm_pglist.c
cvs rdiff -u -r1.45 -r1.46 src/sys/uvm/uvm_stat.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/vmstat/vmstat.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.398 src/sys/arch/x86/x86/pmap.c:1.399
--- src/sys/arch/x86/x86/pmap.c:1.398	Wed Jun  3 00:27:46 2020
+++ src/sys/arch/x86/x86/pmap.c	Sun Jun 14 21:41:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.398 2020/06/03 00:27:46 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.399 2020/06/14 21:41:42 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.398 2020/06/03 00:27:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.399 2020/06/14 21:41:42 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -3066,7 +3066,6 @@ pmap_zap_ptp(struct pmap *pmap, struct v
 		if (!pmap_valid_entry(opte)) {
 			continue;
 		}
-		pmap_pte_set(pte, 0);
 
 		/*
 		 * Count the PTE.  If it's not for a managed mapping
@@ -5741,8 +5740,6 @@ pmap_update(struct pmap *pmap)
 		PMAP_DUMMY_LOCK(pmap);
 		uvm_pagerealloc(ptp, NULL, 0);
 		PMAP_DUMMY_UNLOCK(pmap);
-
-		ptp->flags |= PG_ZERO;
 		uvm_pagefree(ptp);
 	}
 	mutex_exit(>pm_lock);

Index: src/sys/sys/cpu_data.h
diff -u src/sys/sys/cpu_data.h:1.51 src/sys/sys/cpu_data.h:1.52
--- src/sys/sys/cpu_data.h:1.51	Thu Jun 11 22:21:05 2020
+++ src/sys/sys/cpu_data.h	Sun Jun 14 21:41:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_data.h,v 1.51 2020/06/11 22:21:05 ad Exp $	*/
+/*	$NetBSD: cpu_data.h,v 1.52 2020/06/14 21:41:42 ad Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -57,12 +57,12 @@ enum cpu_count {
 	CPU_COUNT_FORKS_SHAREVM,
 	CPU_COUNT_COLORHIT,		/* 8 */
 	CPU_COUNT_COLORMISS,
-	CPU_COUNT_PGA_ZEROHIT,
-	CPU_COUNT_PGA_ZEROMISS,
+	CPU_COUNT__UNUSED3,
+	CPU_COUNT__UNUSED4,
 	CPU_COUNT_CPUHIT,
 	CPU_COUNT_CPUMISS,
 	CPU_COUNT_FREEPAGES,
-	CPU_COUNT_ZEROPAGES,
+	CPU_COUNT__UNUSED5,
 	CPU_COUNT_PAGEINS,		/* 16 */
 	CPU_COUNT_FLTUP,
 	CPU_COUNT_FLTNOUP,

Index: src/sys/uvm/uvm_glue.c
diff -u src/sys/uvm/uvm_glue.c:1.180 src/sys/uvm/uvm_glue.c:1.181
--- src/sys/uvm/uvm_glue.c:1.180	Thu Jun 11 19:20:47 2020
+++ src/sys/uvm/uvm_glue.c	Sun Jun 14 21:41:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_glue.c,v 1.180 2020/06/11 19:20:47 ad Exp $	*/
+/*	$NetBSD: uvm_glue.c,v 1.181 2020/06/14 21:41:42 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.180 2020/06/11 19:20:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.181 2020/06/14 21:41:42 ad Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_kstack.h"
@@ -531,7 +531,4 @@ uvm_idle(void)
 
 	if (!ci->ci_want_resched)
 		uvmpdpol_idle(ucpu);
-	if (!ci->ci_want_resched)
-		uvm_pageidlezero();
-
 }

Index: src/sys/uvm/uvm_meter.c
diff -u src/sys/uvm/uvm_meter.c:1.79 src/sys/uvm/uvm_meter.c:1.80
--- src/sys/uvm/uvm_meter.c:1.79	Thu Jun 11 22:21:05 2020
+++ src/sys/uvm/uvm_meter.c	Sun Jun 14 21:41:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_meter.c,v 1.79 2020/06/11 22:21:05 ad Exp $	*/
+/*	$NetBSD: uvm_meter.c,v 1.80 2020/06/14 21:41:42 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.79 2020/06/11 22:21:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.80 2020/06/14 21:41:42 ad Exp $");
 
 #include 
 #include 
@@ -111,7 +111,6 @@ sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
 	u.inactive = inactive;
 	u.paging = uvmexp.paging;
 	u.wired = uvmexp.wired;
-	u.zeropages = cpu_count_get(CPU_COUNT_ZEROPAGES);
 	u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
 	u.reserve_kernel = uvmexp.reserve_kernel;
 	u.freemin = 

CVS commit: src

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:34:25 UTC 2020

Modified Files:
src/sys/kern: subr_pool.c
src/sys/sys: pool.h
src/usr.bin/vmstat: vmstat.c

Log Message:
pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


To generate a diff of this commit:
cvs rdiff -u -r1.270 -r1.271 src/sys/kern/subr_pool.c
cvs rdiff -u -r1.90 -r1.91 src/sys/sys/pool.h
cvs rdiff -u -r1.240 -r1.241 src/usr.bin/vmstat/vmstat.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/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.270 src/sys/kern/subr_pool.c:1.271
--- src/sys/kern/subr_pool.c:1.270	Sun Jun  7 09:45:19 2020
+++ src/sys/kern/subr_pool.c	Sun Jun 14 21:34:25 2020
@@ -1,8 +1,8 @@
-/*	$NetBSD: subr_pool.c,v 1.270 2020/06/07 09:45:19 maxv Exp $	*/
+/*	$NetBSD: subr_pool.c,v 1.271 2020/06/14 21:34:25 ad Exp $	*/
 
 /*
- * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018
- * The NetBSD Foundation, Inc.
+ * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018,
+ * 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.270 2020/06/07 09:45:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.271 2020/06/14 21:34:25 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_pool.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -337,6 +338,9 @@ static struct pool pcg_large_pool;
 static struct pool cache_pool;
 static struct pool cache_cpu_pool;
 
+static pcg_t *volatile pcg_large_cache __cacheline_aligned;
+static pcg_t *volatile pcg_normal_cache __cacheline_aligned;
+
 /* List of all caches. */
 TAILQ_HEAD(,pool_cache) pool_cache_head =
 TAILQ_HEAD_INITIALIZER(pool_cache_head);
@@ -344,14 +348,17 @@ TAILQ_HEAD(,pool_cache) pool_cache_head 
 int pool_cache_disable;		/* global disable for caching */
 static const pcg_t pcg_dummy;	/* zero sized: always empty, yet always full */
 
-static bool	pool_cache_put_slow(pool_cache_cpu_t *, int,
+static bool	pool_cache_put_slow(pool_cache_t, pool_cache_cpu_t *, int,
 void *);
-static bool	pool_cache_get_slow(pool_cache_cpu_t *, int,
+static bool	pool_cache_get_slow(pool_cache_t, pool_cache_cpu_t *, int,
 void **, paddr_t *, int);
 static void	pool_cache_cpu_init1(struct cpu_info *, pool_cache_t);
-static void	pool_cache_invalidate_groups(pool_cache_t, pcg_t *);
+static int	pool_cache_invalidate_groups(pool_cache_t, pcg_t *);
 static void	pool_cache_invalidate_cpu(pool_cache_t, u_int);
 static void	pool_cache_transfer(pool_cache_t);
+static int	pool_pcg_get(pcg_t *volatile *, pcg_t **);
+static int	pool_pcg_put(pcg_t *volatile *, pcg_t *);
+static pcg_t *	pool_pcg_trunc(pcg_t *volatile *);
 
 static int	pool_catchup(struct pool *);
 static void	pool_prime_page(struct pool *, void *,
@@ -1804,7 +1811,8 @@ pool_print1(struct pool *pp, const char 
 	pool_cache_t pc;
 	pcg_t *pcg;
 	pool_cache_cpu_t *cc;
-	uint64_t cpuhit, cpumiss;
+	uint64_t cpuhit, cpumiss, pchit, pcmiss;
+	uint32_t nfull;
 	int i, print_log = 0, print_pagelist = 0, print_cache = 0;
 	char c;
 
@@ -1881,31 +1889,26 @@ pool_print1(struct pool *pp, const char 
 	if (pc != NULL) {
 		cpuhit = 0;
 		cpumiss = 0;
+		pcmiss = 0;
+		nfull = 0;
 		for (i = 0; i < __arraycount(pc->pc_cpus); i++) {
 			if ((cc = pc->pc_cpus[i]) == NULL)
 continue;
 			cpuhit += cc->cc_hits;
 			cpumiss += cc->cc_misses;
+			pcmiss += cc->cc_pcmisses;
+			nfull += cc->cc_nfull;
 		}
+		pchit = cpumiss - pcmiss;
 		(*pr)("\tcpu layer hits %llu misses %llu\n", cpuhit, cpumiss);
-		(*pr)("\tcache layer hits %llu misses %llu\n",
-		pc->pc_hits, pc->pc_misses);
-		(*pr)("\tcache layer entry uncontended %llu contended %llu\n",
-		pc->pc_hits + pc->pc_misses - pc->pc_contended,
-		pc->pc_contended);
-		(*pr)("\tcache layer empty groups %u full groups %u\n",
-		pc->pc_nempty, pc->pc_nfull);
+		(*pr)("\tcache layer hits %llu misses %llu\n", pchit, pcmiss);
+		(*pr)("\tcache layer full groups %u\n", nfull);
 		if (print_cache) {
 			(*pr)("\tfull cache groups:\n");
 			for (pcg = pc->pc_fullgroups; pcg != NULL;
 			pcg = pcg->pcg_next) {
 PR_GROUPLIST(pcg);
 			}
-			(*pr)("\tempty cache groups:\n");
-			for (pcg = pc->pc_emptygroups; pcg != NULL;
-			pcg = pcg->pcg_next) {
-PR_GROUPLIST(pcg);
-			}
 		}
 	}
 #undef PR_GROUPLIST
@@ -2051,7 +2054,6 @@ pool_cache_bootstrap(pool_cache_t pc, si
 			palloc = _allocator_nointr;
 	}
 	pool_init(pp, size, align, align_offset, flags, wchan, palloc, ipl);
-	mutex_init(>pc_lock, MUTEX_DEFAULT, ipl);
 
 	if (ctor == NULL) {
 		ctor 

CVS commit: src/lib/libpthread

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:33:28 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Another bug.  The CAS loop in pthread_cond_signal() could race against the
thread it is trying to awake.  The thread could exit the condvar and then
reinsert itself at the head of the list with a new waiter behind it.  It's
likely possible to fix this in a way that's wait-free but for now just fix
the bug.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/lib/libpthread/pthread_cond.c

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

Modified files:

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.75 src/lib/libpthread/pthread_cond.c:1.76
--- src/lib/libpthread/pthread_cond.c:1.75	Sat Jun 13 17:39:42 2020
+++ src/lib/libpthread/pthread_cond.c	Sun Jun 14 21:33:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.76 2020/06/14 21:33:28 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.76 2020/06/14 21:33:28 ad Exp $");
 
 #include 
 #include 
@@ -54,6 +54,13 @@ __strong_alias(__libc_cond_wait,pthread_
 __strong_alias(__libc_cond_timedwait,pthread_cond_timedwait)
 __strong_alias(__libc_cond_destroy,pthread_cond_destroy)
 
+/*
+ * A dummy waiter that's used to flag that pthread_cond_signal() is in
+ * progress and nobody else should try to modify the waiter list until
+ * it completes.
+ */
+static struct pthread__waiter pthread__cond_dummy;
+
 static clockid_t
 pthread_cond_getclock(const pthread_cond_t *cond)
 {
@@ -111,7 +118,7 @@ int
 pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 		   const struct timespec *abstime)
 {
-	struct pthread__waiter waiter, *next, *waiters;
+	struct pthread__waiter waiter, *next, *head;
 	pthread_t self;
 	int error, cancel;
 	clockid_t clkid = pthread_cond_getclock(cond);
@@ -135,33 +142,39 @@ pthread_cond_timedwait(pthread_cond_t *c
 
 	/* Note this thread as waiting on the CV. */
 	cond->ptc_mutex = mutex;
-	for (waiters = cond->ptc_waiters;; waiters = next) {
+	for (head = cond->ptc_waiters;; head = next) {
+		/* Wait while pthread_cond_signal() in progress. */
+		if (__predict_false(head == __cond_dummy)) {
+			sched_yield();
+			next = cond->ptc_waiters;
+			continue;
+		}
 		waiter.lid = self->pt_lid;
-		waiter.next = waiters;
+		waiter.next = head;
 #ifndef PTHREAD__ATOMIC_IS_MEMBAR
 		membar_producer();
 #endif
-		next = atomic_cas_ptr(>ptc_waiters, waiters, );
-		if (__predict_true(next == waiters)) {
+		next = atomic_cas_ptr(>ptc_waiters, head, );
+		if (__predict_true(next == head)) {
 			break;
 		}
 	}
 
-	/* Drop the interlock */
-	pthread_mutex_unlock(mutex);
+	/* Drop the interlock and wait. */
 	error = 0;
-
+	pthread_mutex_unlock(mutex);
 	while (waiter.lid && !(cancel = self->pt_cancel)) {
 		int rv = _lwp_park(clkid, TIMER_ABSTIME, __UNCONST(abstime),
 		0, NULL, NULL);
 		if (rv == 0) {
 			continue;
 		}
-		if (errno != EINTR && errno != EALREADY && errno != ESRCH) {
+		if (errno != EINTR && errno != EALREADY) {
 			error = errno;
 			break;
 		}
 	}
+	pthread_mutex_lock(mutex);
 
 	/*
 	 * If this thread absorbed a wakeup from pthread_cond_signal() and
@@ -169,11 +182,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 	 *
 	 * And if awoken early, we may still be on the waiter list and must
 	 * remove self.
-	 *
-	 * In all cases do the wakeup without the mutex held otherwise:
-	 *
-	 * - wakeup could be deferred until mutex release
-	 * - it would be mixing up two sets of waitpoints
 	 */
 	if (__predict_false(cancel | error)) {
 		pthread_cond_broadcast(cond);
@@ -183,10 +191,12 @@ pthread_cond_timedwait(pthread_cond_t *c
 		 * Wait until released, otherwise "waiter" is still globally
 		 * visible.
 		 */
+		pthread_mutex_unlock(mutex);
 		while (__predict_false(waiter.lid)) {
 			(void)_lwp_park(CLOCK_MONOTONIC, 0, NULL, 0, NULL,
 			NULL);
 		}
+		pthread_mutex_lock(mutex);
 	} else {
 		pthread__assert(!waiter.lid);
 	}
@@ -195,7 +205,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 	 * If cancelled then exit.  POSIX dictates that the mutex must be
 	 * held if this happens.
 	 */
-	pthread_mutex_lock(mutex);
 	if (cancel) {
 		pthread__cancelled();
 	}
@@ -215,7 +224,7 @@ pthread_cond_wait(pthread_cond_t *cond, 
 int
 pthread_cond_signal(pthread_cond_t *cond)
 {
-	struct pthread__waiter *waiter, *next;
+	struct pthread__waiter *head, *next;
 	pthread_mutex_t *mutex;
 	pthread_t self;
 
@@ -228,28 +237,39 @@ pthread_cond_signal(pthread_cond_t *cond
 	/* Take ownership of one waiter. */
 	self = pthread_self();
 	mutex = cond->ptc_mutex;
-	for (waiter = cond->ptc_waiters;; 

CVS commit: src/lib/libpthread

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:31:11 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Don't need to ignore ESRCH from _lwp_park() any more.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/lib/libpthread/pthread.c

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

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.176 src/lib/libpthread/pthread.c:1.177
--- src/lib/libpthread/pthread.c:1.176	Thu Jun 11 18:42:02 2020
+++ src/lib/libpthread/pthread.c	Sun Jun 14 21:31:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.177 2020/06/14 21:31:11 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.177 2020/06/14 21:31:11 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -1145,7 +1145,6 @@ pthread__park(pthread_t self, pthread_mu
 			switch (rv = errno) {
 			case EINTR:
 			case EALREADY:
-			case ESRCH:
 rv = 0;
 break;
 			case ETIMEDOUT:



CVS commit: src/sys/arch/arm/sunxi

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 16:29:47 UTC 2020

Modified Files:
src/sys/arch/arm/sunxi: sun8i_crypto.c

Log Message:
Fix !DIAGNOSTIC compile.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/sunxi/sun8i_crypto.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/arm/sunxi/sun8i_crypto.c
diff -u src/sys/arch/arm/sunxi/sun8i_crypto.c:1.17 src/sys/arch/arm/sunxi/sun8i_crypto.c:1.18
--- src/sys/arch/arm/sunxi/sun8i_crypto.c:1.17	Sat Jun 13 18:58:26 2020
+++ src/sys/arch/arm/sunxi/sun8i_crypto.c	Sun Jun 14 16:29:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $	*/
+/*	$NetBSD: sun8i_crypto.c,v 1.18 2020/06/14 16:29:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.17 2020/06/13 18:58:26 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.18 2020/06/14 16:29:47 ad Exp $");
 
 #include 
 #include 
@@ -2393,7 +2393,7 @@ sun8i_crypto_callback(struct sun8i_crypt
 struct sun8i_crypto_task *task, void *cookie, int error)
 {
 	struct cryptop *crp = cookie;
-	struct cryptodesc *crd = crp->crp_desc;
+	struct cryptodesc *crd __diagused = crp->crp_desc;
 
 	KASSERT(error != ERESTART);
 	KASSERT(crd != NULL);



CVS commit: src/sys/miscfs/genfs

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 00:25:22 UTC 2020

Modified Files:
src/sys/miscfs/genfs: genfs_io.c

Log Message:
genfs_putpages(): when building a cluster make use of pages in the in the
existing uvm_page_array.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/miscfs/genfs/genfs_io.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/miscfs/genfs/genfs_io.c
diff -u src/sys/miscfs/genfs/genfs_io.c:1.97 src/sys/miscfs/genfs/genfs_io.c:1.98
--- src/sys/miscfs/genfs/genfs_io.c:1.97	Mon May 25 21:15:10 2020
+++ src/sys/miscfs/genfs/genfs_io.c	Sun Jun 14 00:25:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_io.c,v 1.97 2020/05/25 21:15:10 ad Exp $	*/
+/*	$NetBSD: genfs_io.c,v 1.98 2020/06/14 00:25:22 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.97 2020/05/25 21:15:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.98 2020/06/14 00:25:22 ad Exp $");
 
 #include 
 #include 
@@ -1208,6 +1208,11 @@ retry:
 			 *	0
 			 *	UVM_PAGE_ARRAY_FILL_DIRTY
 			 *	UVM_PAGE_ARRAY_FILL_DIRTY|WRITEBACK
+			 *
+			 * XXX this is fragile but it'll work: the array
+			 * was earlier filled sparsely, but UFP_DIRTYONLY
+			 * implies dense.  see corresponding comment in
+			 * uvn_findpages().
 			 */
 
 			npages = MAXPAGES - nback - 1;
@@ -1215,7 +1220,7 @@ retry:
 npages = MIN(npages,
 	 (fshi - off - 1) >> PAGE_SHIFT);
 			uvn_findpages(uobj, off + PAGE_SIZE, ,
-			[nback + 1], NULL,
+			[nback + 1], ,
 			UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY);
 			npages += nback + 1;
 		} else {



CVS commit: src/sys/kern

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 00:20:17 UTC 2020

Modified Files:
src/sys/kern: vfs_vnode.c

Log Message:
If a vnode is marked with VI_EXECMAP then in all likelyhood it has pages.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/kern/vfs_vnode.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/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.124 src/sys/kern/vfs_vnode.c:1.125
--- src/sys/kern/vfs_vnode.c:1.124	Thu Jun 11 22:21:05 2020
+++ src/sys/kern/vfs_vnode.c	Sun Jun 14 00:20:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.124 2020/06/11 22:21:05 ad Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.125 2020/06/14 00:20:17 ad Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.124 2020/06/11 22:21:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.125 2020/06/14 00:20:17 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -897,8 +897,7 @@ vrelel(vnode_t *vp, int flags, int lktyp
  		}
 
 		/* Take care of space accounting. */
-		if ((vp->v_iflag & VI_EXECMAP) != 0 &&
-		vp->v_uobj.uo_npages != 0) {
+		if ((vp->v_iflag & VI_EXECMAP) != 0) {
 			cpu_count(CPU_COUNT_EXECPAGES, -vp->v_uobj.uo_npages);
 		}
 		vp->v_iflag &= ~(VI_TEXT|VI_EXECMAP|VI_WRMAP);
@@ -1707,7 +1706,7 @@ vcache_reclaim(vnode_t *vp)
 
 	rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
 	mutex_enter(vp->v_interlock);
-	if ((vp->v_iflag & VI_EXECMAP) != 0 && vp->v_uobj.uo_npages != 0) {
+	if ((vp->v_iflag & VI_EXECMAP) != 0) {
 		cpu_count(CPU_COUNT_EXECPAGES, -vp->v_uobj.uo_npages);
 	}
 	vp->v_iflag &= ~(VI_TEXT|VI_EXECMAP);



CVS commit: src/sys/sys

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 23:59:16 UTC 2020

Modified Files:
src/sys/sys: param.h

Log Message:
NetBSD 9.99.67 - struct lwp changed on x86


To generate a diff of this commit:
cvs rdiff -u -r1.669 -r1.670 src/sys/sys/param.h

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

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.669 src/sys/sys/param.h:1.670
--- src/sys/sys/param.h:1.669	Fri Jun 12 11:09:49 2020
+++ src/sys/sys/param.h	Sat Jun 13 23:59:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.669 2020/06/12 11:09:49 roy Exp $	*/
+/*	$NetBSD: param.h,v 1.670 2020/06/13 23:59:16 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999006600	/* NetBSD 9.99.66 */
+#define	__NetBSD_Version__	999006700	/* NetBSD 9.99.67 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/arch

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 23:58:52 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S
src/sys/arch/amd64/include: proc.h
src/sys/arch/i386/i386: cpufunc.S
src/sys/arch/i386/include: proc.h
src/sys/arch/x86/x86: tsc.c

Log Message:
Print a rate limited warning if the TSC timecounter goes backwards from the
viewpoint of any single LWP.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/include/proc.h
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/i386/include/proc.h
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/x86/tsc.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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.59 src/sys/arch/amd64/amd64/cpufunc.S:1.60
--- src/sys/arch/amd64/amd64/cpufunc.S:1.59	Mon Jun  1 22:58:06 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Sat Jun 13 23:58:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.59 2020/06/01 22:58:06 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.60 2020/06/13 23:58:51 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -206,8 +206,10 @@ ENTRY(x86_hotpatch)
 END(x86_hotpatch)
 #endif /* !XENPV */
 
-/* Could be exact same as cpu_counter, but KMSAN needs to have the correct
- * size of the return value. */
+/*
+ * Could be exact same as cpu_counter, but KMSAN needs to have the correct
+ * size of the return value.
+ */
 ENTRY(cpu_counter32)
 	movq	CPUVAR(CURLWP), %rcx
 1:
@@ -221,7 +223,6 @@ ENTRY(cpu_counter32)
 2:
 	jmp	1b
 END(cpu_counter32)
-STRONG_ALIAS(tsc_get_timecount, cpu_counter32)
 
 ENTRY(cpu_counter)
 	movq	CPUVAR(CURLWP), %rcx

Index: src/sys/arch/amd64/include/proc.h
diff -u src/sys/arch/amd64/include/proc.h:1.24 src/sys/arch/amd64/include/proc.h:1.25
--- src/sys/arch/amd64/include/proc.h:1.24	Mon Jan 13 00:26:52 2020
+++ src/sys/arch/amd64/include/proc.h	Sat Jun 13 23:58:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.24 2020/01/13 00:26:52 ad Exp $	*/
+/*	$NetBSD: proc.h,v 1.25 2020/06/13 23:58:51 ad Exp $	*/
 
 /*
  * Copyright (c) 1991 Regents of the University of California.
@@ -46,6 +46,7 @@ struct pmap;
 struct vm_page;
 
 struct mdlwp {
+	volatile uint64_t md_tsc;	/* last TSC reading */
 	struct	trapframe *md_regs;	/* registers on current frame */
 	int	md_flags;		/* machine-dependent flags */
 	volatile int md_astpending;

Index: src/sys/arch/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.45 src/sys/arch/i386/i386/cpufunc.S:1.46
--- src/sys/arch/i386/i386/cpufunc.S:1.45	Thu May 28 20:03:19 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Sat Jun 13 23:58:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.45 2020/05/28 20:03:19 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.46 2020/06/13 23:58:52 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.45 2020/05/28 20:03:19 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.46 2020/06/13 23:58:52 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -163,7 +163,7 @@ ENTRY(msr_onfault)
 	ret
 END(msr_onfault)
 
-ENTRY(tsc_get_timecount)
+ENTRY(cpu_counter)
 	pushl	%ebx
 	movl	CPUVAR(CURLWP), %ecx
 1:
@@ -177,10 +177,9 @@ ENTRY(tsc_get_timecount)
 	ret
 2:
 	jmp	1b
-END(tsc_get_timecount)
+END(cpu_counter)
 
-STRONG_ALIAS(cpu_counter, tsc_get_timecount)
-STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, cpu_counter)
 
 ENTRY(breakpoint)
 	pushl	%ebp

Index: src/sys/arch/i386/include/proc.h
diff -u src/sys/arch/i386/include/proc.h:1.47 src/sys/arch/i386/include/proc.h:1.48
--- src/sys/arch/i386/include/proc.h:1.47	Mon Jan 13 00:26:52 2020
+++ src/sys/arch/i386/include/proc.h	Sat Jun 13 23:58:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.47 2020/01/13 00:26:52 ad Exp $	*/
+/*	$NetBSD: proc.h,v 1.48 2020/06/13 23:58:52 ad Exp $	*/
 
 /*
  * Copyright (c) 1991 Regents of the University of California.
@@ -46,6 +46,7 @@ struct vm_page;
 #define	MDL_FPU_IN_CPU		0x0020	/* the FPU state is in the CPU */
 
 struct mdlwp {
+	volatile uint64_t md_tsc;	/* last TSC reading */
 	struct	trapframe *md_regs;	/* registers on current frame */
 	int	md_flags;		/* machine-dependent flags */
 	volatile int md_astpending;	/* AST pending for this process */

Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.48 src/sys/arch/x86/x86/tsc.c:1.49
--- src/sys/arch/x86/x86/tsc.c:1.48	Wed May 27 18:46:15 2020
+++ src/sys/arch/x86/x86/tsc.c	Sat Jun 13 23:58:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.48 2020/05/27 18:46:15 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.49 2020/06/13 23:58:52 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 

CVS commit: src/share/man/man7

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 20:18:00 UTC 2020

Modified Files:
src/share/man/man7: sysctl.7

Log Message:
g/c vm.idlezero


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/share/man/man7/sysctl.7

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.146 src/share/man/man7/sysctl.7:1.147
--- src/share/man/man7/sysctl.7:1.146	Sun May 10 02:32:32 2020
+++ src/share/man/man7/sysctl.7	Sat Jun 13 20:18:00 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.146 2020/05/10 02:32:32 riastradh Exp $
+.\"	$NetBSD: sysctl.7,v 1.147 2020/06/13 20:18:00 ad Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -2589,7 +2589,6 @@ them with
 with the caveat that whatever pages were already written to disk
 unencrypted or encrypted with a compromised key may still be written to
 disk afterward.
-.\" XXX vm.idlezero
 .El
 .Ss The ddb.* subtree ( Dv CTL_DDB )
 The information available for the



CVS commit: src/sys/arch

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 20:01:27 UTC 2020

Modified Files:
src/sys/arch/arc/arc: p_acer_pica_61.c p_dti_arcstation.c p_dti_tyne.c
p_sni_rm200pci.c
src/sys/arch/sparc/sparc: cpu.c
src/sys/arch/x86/x86: cpu.c

Log Message:
g/c vm_page_zero_enable


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arc/arc/p_acer_pica_61.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arc/arc/p_dti_arcstation.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arc/arc/p_dti_tyne.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arc/arc/p_sni_rm200pci.c
cvs rdiff -u -r1.255 -r1.256 src/sys/arch/sparc/sparc/cpu.c
cvs rdiff -u -r1.192 -r1.193 src/sys/arch/x86/x86/cpu.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/arc/arc/p_acer_pica_61.c
diff -u src/sys/arch/arc/arc/p_acer_pica_61.c:1.12 src/sys/arch/arc/arc/p_acer_pica_61.c:1.13
--- src/sys/arch/arc/arc/p_acer_pica_61.c:1.12	Sun Mar  6 14:58:42 2011
+++ src/sys/arch/arc/arc/p_acer_pica_61.c	Sat Jun 13 20:01:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: p_acer_pica_61.c,v 1.12 2011/03/06 14:58:42 tsutsui Exp $	*/
+/*	$NetBSD: p_acer_pica_61.c,v 1.13 2020/06/13 20:01:27 ad Exp $	*/
 /*	$OpenBSD: picabus.c,v 1.11 1999/01/11 05:11:10 millert Exp $	*/
 
 /*
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: p_acer_pica_61.c,v 1.12 2011/03/06 14:58:42 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: p_acer_pica_61.c,v 1.13 2020/06/13 20:01:27 ad Exp $");
 
 #include 
 #include 
@@ -87,15 +87,6 @@ void
 p_acer_pica_61_init(void)
 {
 
-	/*
-	 * PICA-61 has PC-style coherent(?) 128KB L2 cache,
-	 * and mips_L2CachePresent == 0 on this machine.
-	 *
-	 * if page zero in the idle loop is enabled,
-	 * commands dump core due to incoherent cache.
-	 */
-	vm_page_zero_enable = false; /* XXX - should be enabled */
-
 	c_magnum_init();
 
 	/* chipset-dependent jazzio bus configuration */

Index: src/sys/arch/arc/arc/p_dti_arcstation.c
diff -u src/sys/arch/arc/arc/p_dti_arcstation.c:1.18 src/sys/arch/arc/arc/p_dti_arcstation.c:1.19
--- src/sys/arch/arc/arc/p_dti_arcstation.c:1.18	Sun Nov 10 21:16:22 2019
+++ src/sys/arch/arc/arc/p_dti_arcstation.c	Sat Jun 13 20:01:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: p_dti_arcstation.c,v 1.18 2019/11/10 21:16:22 chs Exp $	*/
+/*	$NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $	*/
 /*	$OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $	*/
 
 /*
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.18 2019/11/10 21:16:22 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $");
 
 #define __INTR_PRIVATE
 #include 
@@ -205,14 +205,6 @@ p_dti_arcstation_init(void)
 	ipl_sr_map = dti_arcstation_ipl_sr_map;
 
 	/*
-	 * XXX - should be enabled, if tested.
-	 *
-	 * We use safe default for now, because this platform is untested.
-	 * In other words, the following may not be needed at all.
-	 */
-	vm_page_zero_enable = false;
-
-	/*
 	 * Initialize I/O address offset
 	 */
 	arc_bus_space_init(_bus_io, "rpc44isaio",

Index: src/sys/arch/arc/arc/p_dti_tyne.c
diff -u src/sys/arch/arc/arc/p_dti_tyne.c:1.19 src/sys/arch/arc/arc/p_dti_tyne.c:1.20
--- src/sys/arch/arc/arc/p_dti_tyne.c:1.19	Sun Feb 20 07:52:42 2011
+++ src/sys/arch/arc/arc/p_dti_tyne.c	Sat Jun 13 20:01:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: p_dti_tyne.c,v 1.19 2011/02/20 07:52:42 matt Exp $	*/
+/*	$NetBSD: p_dti_tyne.c,v 1.20 2020/06/13 20:01:27 ad Exp $	*/
 /*	$OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $	*/
 
 /*
@@ -40,7 +40,7 @@
 
 #define __INTR_PRIVATE
 #include 
-__KERNEL_RCSID(0, "$NetBSD: p_dti_tyne.c,v 1.19 2011/02/20 07:52:42 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: p_dti_tyne.c,v 1.20 2020/06/13 20:01:27 ad Exp $");
 
 #include 
 #include 
@@ -200,14 +200,6 @@ p_dti_tyne_init(void)
 	ipl_sr_map = dti_tyne_ipl_sr_map;
 
 	/*
-	 * XXX - should be enabled, if tested.
-	 *
-	 * We use safe default for now, because this platform is untested.
-	 * In other words, the following may not be needed at all.
-	 */
-	vm_page_zero_enable = false;
-
-	/*
 	 * Initialize I/O address offset
 	 */
 	arc_bus_space_init(_bus_io, "tyneisaio",

Index: src/sys/arch/arc/arc/p_sni_rm200pci.c
diff -u src/sys/arch/arc/arc/p_sni_rm200pci.c:1.15 src/sys/arch/arc/arc/p_sni_rm200pci.c:1.16
--- src/sys/arch/arc/arc/p_sni_rm200pci.c:1.15	Sun Feb 20 07:52:42 2011
+++ src/sys/arch/arc/arc/p_sni_rm200pci.c	Sat Jun 13 20:01:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: p_sni_rm200pci.c,v 1.15 2011/02/20 07:52:42 matt Exp $	*/
+/*	$NetBSD: p_sni_rm200pci.c,v 1.16 2020/06/13 20:01:27 ad Exp $	*/
 /*	$OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $	*/
 
 /*
@@ -40,7 +40,7 @@
 
 #define __INTR_PRIVATE
 #include 
-__KERNEL_RCSID(0, "$NetBSD: p_sni_rm200pci.c,v 1.15 2011/02/20 07:52:42 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: 

CVS commit: src/sys/uvm

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 19:55:39 UTC 2020

Modified Files:
src/sys/uvm: uvm_page.c

Log Message:
uvm_pagerealloc(): resurrect the insertion case.


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/uvm/uvm_page.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/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.240 src/sys/uvm/uvm_page.c:1.241
--- src/sys/uvm/uvm_page.c:1.240	Thu Jun 11 22:21:05 2020
+++ src/sys/uvm/uvm_page.c	Sat Jun 13 19:55:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.240 2020/06/11 22:21:05 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.241 2020/06/13 19:55:39 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.240 2020/06/11 22:21:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.241 2020/06/13 19:55:39 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1411,12 +1411,13 @@ uvm_pagereplace(struct vm_page *oldpg, s
  * uvm_pagerealloc: reallocate a page from one object to another
  *
  * => both objects must be locked
- * => both interlocks must be held
  */
 
-void
+int
 uvm_pagerealloc(struct vm_page *pg, struct uvm_object *newobj, voff_t newoff)
 {
+	int error = 0;
+
 	/*
 	 * remove it from the old object
 	 */
@@ -1431,11 +1432,25 @@ uvm_pagerealloc(struct vm_page *pg, stru
 	 */
 
 	if (newobj) {
-		/*
-		 * XXX we have no in-tree users of this functionality
-		 */
-		panic("uvm_pagerealloc: no impl");
+		mutex_enter(>interlock);
+		pg->uobject = newobj;
+		pg->offset = newoff;
+		if (UVM_OBJ_IS_VNODE(newobj)) {
+			pg->flags |= PG_FILE;
+		} else if (UVM_OBJ_IS_AOBJ(newobj)) {
+			pg->flags |= PG_AOBJ;
+		}
+		uvm_pageinsert_object(newobj, pg);
+		mutex_exit(>interlock);
+		error = uvm_pageinsert_tree(newobj, pg);
+		if (error != 0) {
+			mutex_enter(>interlock);
+			uvm_pageremove_object(newobj, pg);
+			mutex_exit(>interlock);
+		}
 	}
+
+	return error;
 }
 
 #ifdef DEBUG



CVS commit: src/sys/uvm

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 19:55:58 UTC 2020

Modified Files:
src/sys/uvm: uvm_extern.h

Log Message:
uvm_pagerealloc(): resurrect the insertion case.


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/sys/uvm/uvm_extern.h

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

Modified files:

Index: src/sys/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.228 src/sys/uvm/uvm_extern.h:1.229
--- src/sys/uvm/uvm_extern.h:1.228	Thu Jun 11 19:20:47 2020
+++ src/sys/uvm/uvm_extern.h	Sat Jun 13 19:55:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.228 2020/06/11 19:20:47 ad Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.229 2020/06/13 19:55:58 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -789,7 +789,7 @@ struct vm_page		*uvm_pagealloc_strat(str
 UVM_PGA_STRAT_NORMAL, 0)
 void			uvm_pagereplace(struct vm_page *,
 			struct vm_page *);
-void			uvm_pagerealloc(struct vm_page *,
+int			uvm_pagerealloc(struct vm_page *,
 			struct uvm_object *, voff_t);
 void			uvm_setpagesize(void);
 



CVS commit: src/sys/arch/evbarm/conf

2020-06-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun 13 16:51:25 UTC 2020

Modified Files:
src/sys/arch/evbarm/conf: ARMADAXP ARMADILLO-IOT-G3 BCM5301X DUOVERO
GENERIC.common N900 OMAP5EVM PANDABOARD PEPPER TISDP2420 VTC100

Log Message:
Comment out "options PMAPCOUNTERS".  It adds much overhead and is mostly of
interest to people hacking on the VM system or pmap.  Proposed on port-arm@.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/evbarm/conf/ARMADAXP
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3 \
src/sys/arch/evbarm/conf/VTC100
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/evbarm/conf/BCM5301X
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/evbarm/conf/DUOVERO
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/evbarm/conf/GENERIC.common
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/evbarm/conf/N900
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/evbarm/conf/OMAP5EVM
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/evbarm/conf/PANDABOARD
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/evbarm/conf/PEPPER
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/evbarm/conf/TISDP2420

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/evbarm/conf/ARMADAXP
diff -u src/sys/arch/evbarm/conf/ARMADAXP:1.27 src/sys/arch/evbarm/conf/ARMADAXP:1.28
--- src/sys/arch/evbarm/conf/ARMADAXP:1.27	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/evbarm/conf/ARMADAXP	Sat Jun 13 16:51:25 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: ARMADAXP,v 1.27 2020/04/18 11:00:38 skrll Exp $
+#	$NetBSD: ARMADAXP,v 1.28 2020/06/13 16:51:25 ad Exp $
 #
 #	ARMADA XP DEV BOARD
 #
@@ -115,7 +115,7 @@ options 	LOCKDEBUG
 options 	DIAGNOSTIC		# internal consistency checks
 #options 	DEBUG
 #options 	UVMHIST		# kernhist for uvm/pmap subsystems
-options 	PMAPCOUNTERS
+#options 	PMAPCOUNTERS
 #options 	VERBOSE_INIT_ARM	# verbose bootstraping messages
 options 	DDB			# in-kernel debugger
 options 	DDB_ONPANIC=1

Index: src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3
diff -u src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3:1.22 src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3:1.23
--- src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3:1.22	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/evbarm/conf/ARMADILLO-IOT-G3	Sat Jun 13 16:51:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: ARMADILLO-IOT-G3,v 1.22 2020/04/18 11:00:38 skrll Exp $
+# $NetBSD: ARMADILLO-IOT-G3,v 1.23 2020/06/13 16:51:25 ad Exp $
 #
 # ARMADILLO-IOT-G3 -- Atmark Techno, Armadillo-IoT G3
 #
@@ -19,7 +19,7 @@ options 	CPU_CORTEX
 options 	CPU_CORTEXA7
 options 	IMX7
 options 	MULTIPROCESSOR
-options 	PMAPCOUNTERS
+#options 	PMAPCOUNTERS
 
 options 	MEMSIZE=512
 options 	MEMSIZE_RESERVED=32	# only reserved 32M for Cortex-M4 core
Index: src/sys/arch/evbarm/conf/VTC100
diff -u src/sys/arch/evbarm/conf/VTC100:1.22 src/sys/arch/evbarm/conf/VTC100:1.23
--- src/sys/arch/evbarm/conf/VTC100:1.22	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/evbarm/conf/VTC100	Sat Jun 13 16:51:25 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: VTC100,v 1.22 2020/04/18 11:00:38 skrll Exp $
+#	$NetBSD: VTC100,v 1.23 2020/06/13 16:51:25 ad Exp $
 #
 #	VTC100 -- NEXCOM VTC100 Kernel
 #
@@ -19,7 +19,7 @@ options 	RTC_OFFSET=0	# hardware clock i
 
 options 	CPU_CORTEXA8
 options 	TI_AM335X
-options 	PMAPCOUNTERS
+#options 	PMAPCOUNTERS
 
 # XXX The Cortex PMC delay() doesn't seem to work.
 #no options	CORTEX_PMC

Index: src/sys/arch/evbarm/conf/BCM5301X
diff -u src/sys/arch/evbarm/conf/BCM5301X:1.35 src/sys/arch/evbarm/conf/BCM5301X:1.36
--- src/sys/arch/evbarm/conf/BCM5301X:1.35	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/evbarm/conf/BCM5301X	Sat Jun 13 16:51:25 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: BCM5301X,v 1.35 2020/04/18 11:00:38 skrll Exp $
+#	$NetBSD: BCM5301X,v 1.36 2020/06/13 16:51:25 ad Exp $
 #
 #	BCM5301X -- Broadcom BCM5301X Eval Board Kernel
 #
@@ -26,7 +26,7 @@ options 	BCMETH_COUNTERS
 options 	CPU_CORTEXA9
 #options 	MEMSIZE=256
 options 	BCM5301X
-options 	PMAPCOUNTERS
+#options 	PMAPCOUNTERS
 options 	BUSDMA_COUNTERS
 makeoptions	KERNEL_BASE_PHYS="0x8010"
 

Index: src/sys/arch/evbarm/conf/DUOVERO
diff -u src/sys/arch/evbarm/conf/DUOVERO:1.17 src/sys/arch/evbarm/conf/DUOVERO:1.18
--- src/sys/arch/evbarm/conf/DUOVERO:1.17	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/evbarm/conf/DUOVERO	Sat Jun 13 16:51:25 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: DUOVERO,v 1.17 2020/04/18 11:00:38 skrll Exp $
+#	$NetBSD: DUOVERO,v 1.18 2020/06/13 16:51:25 ad Exp $
 #
 #	DUOOVERO -- Gumstix. Inc. DuoVero COMS platforms kernel
 #
@@ -19,7 +19,7 @@ options 	OMAP_4430
 options 	MULTIPROCESSOR
 options 	 __HAVE_CPU_UAREA_ALLOC_IDLELWP	# need for MULTIPROCESSOR
 options 	FPU_VFP
-options 	PMAPCOUNTERS
+#options 	PMAPCOUNTERS
 options 	ARM_HAS_VBAR
 options 	__HAVE_MM_MD_DIRECT_MAPPED_PHYS
 makeoptions	CPUFLAGS="-mcpu=cortex-a9 -mfpu=neon"

Index: src/sys/arch/evbarm/conf/GENERIC.common
diff -u src/sys/arch/evbarm/conf/GENERIC.common:1.36 src/sys/arch/evbarm/conf/GENERIC.common:1.37
--- 

CVS commit: src/sys/uvm

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 22:25:51 UTC 2020

Modified Files:
src/sys/uvm: uvm_pglist.c

Log Message:
Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
  each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
  for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
  For the cheap option, give cpu_count_sync() a boolean parameter indicating
  that a cached value is okay, and rate limit the updates for cached values
  to hz.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/uvm/uvm_pglist.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/uvm/uvm_pglist.c
diff -u src/sys/uvm/uvm_pglist.c:1.83 src/sys/uvm/uvm_pglist.c:1.84
--- src/sys/uvm/uvm_pglist.c:1.83	Thu Jun 11 19:20:47 2020
+++ src/sys/uvm/uvm_pglist.c	Thu Jun 11 22:25:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.83 2020/06/11 19:20:47 ad Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.84 2020/06/11 22:25:51 ad Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.83 2020/06/11 19:20:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.84 2020/06/11 22:25:51 ad Exp $");
 
 #include 
 #include 
@@ -98,6 +98,7 @@ uvm_pglist_add(struct vm_page *pg, struc
 #endif
 	LIST_REMOVE(pg, pageq.list);
 	pgb->pgb_nfree--;
+	CPU_COUNT(CPU_COUNT_FREEPAGES, -1);
 	if (pg->flags & PG_ZERO)
 		CPU_COUNT(CPU_COUNT_ZEROPAGES, -1);
 	pg->flags = PG_CLEAN;



CVS commit: src

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 22:21:05 UTC 2020

Modified Files:
src/sys/compat/linux/common: linux_misc.c
src/sys/compat/linux32/common: linux32_sysinfo.c
src/sys/kern: subr_cpu.c vfs_vnode.c vfs_vnops.c
src/sys/miscfs/procfs: procfs_linux.c
src/sys/sys: cpu_data.h
src/sys/uvm: uvm_loan.c uvm_meter.c uvm_page.c uvm_pdaemon.c
uvm_pdpolicy_clock.c uvm_stat.c
src/usr.bin/vmstat: vmstat.c

Log Message:
Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
  each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
  for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one().  It has no users and doesn't save a whole lot.
  For the cheap option, give cpu_count_sync() a boolean parameter indicating
  that a cached value is okay, and rate limit the updates for cached values
  to hz.


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.12 -r1.13 src/sys/compat/linux32/common/linux32_sysinfo.c
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_cpu.c
cvs rdiff -u -r1.123 -r1.124 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.212 -r1.213 src/sys/kern/vfs_vnops.c
cvs rdiff -u -r1.85 -r1.86 src/sys/miscfs/procfs/procfs_linux.c
cvs rdiff -u -r1.50 -r1.51 src/sys/sys/cpu_data.h
cvs rdiff -u -r1.103 -r1.104 src/sys/uvm/uvm_loan.c
cvs rdiff -u -r1.78 -r1.79 src/sys/uvm/uvm_meter.c
cvs rdiff -u -r1.239 -r1.240 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.128 -r1.129 src/sys/uvm/uvm_pdaemon.c
cvs rdiff -u -r1.38 -r1.39 src/sys/uvm/uvm_pdpolicy_clock.c
cvs rdiff -u -r1.44 -r1.45 src/sys/uvm/uvm_stat.c
cvs rdiff -u -r1.239 -r1.240 src/usr.bin/vmstat/vmstat.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/compat/linux/common/linux_misc.c
diff -u src/sys/compat/linux/common/linux_misc.c:1.250 src/sys/compat/linux/common/linux_misc.c:1.251
--- src/sys/compat/linux/common/linux_misc.c:1.250	Thu Jun 11 19:20:46 2020
+++ src/sys/compat/linux/common/linux_misc.c	Thu Jun 11 22:21:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_misc.c,v 1.250 2020/06/11 19:20:46 ad Exp $	*/
+/*	$NetBSD: linux_misc.c,v 1.251 2020/06/11 22:21:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.250 2020/06/11 19:20:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.251 2020/06/11 22:21:05 ad Exp $");
 
 #include 
 #include 
@@ -1347,6 +1347,7 @@ linux_sys_sysinfo(struct lwp *l, const s
 	} */
 	struct linux_sysinfo si;
 	struct loadavg *la;
+	int64_t filepg;
 
 	memset(, 0, sizeof(si));
 	si.uptime = time_uptime;
@@ -1355,9 +1356,14 @@ linux_sys_sysinfo(struct lwp *l, const s
 	si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
 	si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
 	si.totalram = ctob((u_long)physmem);
+	/* uvm_availmem() may sync the counters. */
 	si.freeram = (u_long)uvm_availmem(true) * uvmexp.pagesize;
+	filepg = cpu_count_get(CPU_COUNT_FILECLEAN) +
+	cpu_count_get(CPU_COUNT_FILEDIRTY) +
+	cpu_count_get(CPU_COUNT_FILEUNKNOWN) -
+	cpu_count_get(CPU_COUNT_EXECPAGES);
 	si.sharedram = 0;	/* XXX */
-	si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize;
+	si.bufferram = (u_long)(filepg * uvmexp.pagesize);
 	si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize;
 	si.freeswap = 
 	(u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;

Index: src/sys/compat/linux32/common/linux32_sysinfo.c
diff -u src/sys/compat/linux32/common/linux32_sysinfo.c:1.12 src/sys/compat/linux32/common/linux32_sysinfo.c:1.13
--- src/sys/compat/linux32/common/linux32_sysinfo.c:1.12	Thu Jun 11 19:20:46 2020
+++ src/sys/compat/linux32/common/linux32_sysinfo.c	Thu Jun 11 22:21:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sysinfo.c,v 1.12 2020/06/11 19:20:46 ad Exp $ */
+/*	$NetBSD: linux32_sysinfo.c,v 1.13 2020/06/11 22:21:05 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.12 2020/06/11 19:20:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.13 2020/06/11 22:21:05 ad Exp $");
 
 #include 
 #include 
@@ -69,6 +69,7 @@ linux32_sys_sysinfo(struct lwp *l, const
 	} */
 	struct linux32_sysinfo si;
 	struct loadavg *la;
+	int64_t filepg;
 
 	memset(, 0, sizeof(si));
 	si.uptime = time_uptime;
@@ -77,9 +78,14 @@ linux32_sys_sysinfo(struct lwp *l, const
 	si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
 	si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
 	si.totalram = ctob((u_long)physmem);
+	/* uvm_availmem() may sync 

CVS commit: src

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 19:20:47 UTC 2020

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: arc.c
src/external/cddl/osnet/sys/kern: misc.c
src/sys/arch/alpha/alpha: machdep.c
src/sys/arch/atari/atari: machdep.c
src/sys/arch/cesfic/cesfic: machdep.c
src/sys/arch/emips/emips: machdep.c
src/sys/arch/evbppc/explora: machdep.c
src/sys/arch/evbppc/virtex: machdep.c
src/sys/arch/evbppc/walnut: machdep.c
src/sys/arch/ews4800mips/ews4800mips: machdep.c
src/sys/arch/hp300/hp300: machdep.c
src/sys/arch/hppa/hppa: machdep.c
src/sys/arch/luna68k/luna68k: machdep.c
src/sys/arch/mac68k/mac68k: machdep.c
src/sys/arch/mips/mips: cpu_subr.c
src/sys/arch/mvme68k/mvme68k: machdep.c
src/sys/arch/news68k/news68k: machdep.c
src/sys/arch/next68k/next68k: machdep.c
src/sys/arch/powerpc/booke: booke_machdep.c
src/sys/arch/powerpc/ibm4xx: ibm4xx_machdep.c
src/sys/arch/powerpc/oea: oea_machdep.c
src/sys/arch/riscv/riscv: riscv_machdep.c
src/sys/arch/sgimips/sgimips: machdep.c
src/sys/arch/sh3/sh3: sh3_machdep.c
src/sys/arch/sparc/sparc: machdep.c
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/arch/sun2/sun2: machdep.c
src/sys/arch/sun3/sun3: machdep.c
src/sys/arch/sun3/sun3x: machdep.c
src/sys/arch/vax/vax: machdep.c
src/sys/arch/x68k/x68k: machdep.c
src/sys/compat/linux/common: linux_misc.c
src/sys/compat/linux32/common: linux32_sysinfo.c
src/sys/dev: ccd.c
src/sys/fs/tmpfs: tmpfs_mem.c
src/sys/kern: init_main.c kern_module.c kern_proc.c vfs_bio.c
src/sys/miscfs/procfs: procfs_linux.c
src/sys/rump/librump/rumpkern: vm.c
src/sys/ufs/chfs: chfs_subr.c
src/sys/ufs/lfs: lfs_bio.c
src/sys/uvm: uvm_extern.h uvm_glue.c uvm_meter.c uvm_page.c
uvm_pdaemon.c uvm_pdpolicy_clock.c uvm_pglist.c uvm_stat.c

Log Message:
uvm_availmem(): give it a boolean argument to specify whether a recent
cached value will do, or if the very latest total must be fetched.  It can
be called thousands of times a second and fetching the totals impacts not
only the calling LWP but other CPUs doing unrelated activity in the VM
system.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c
cvs rdiff -u -r1.8 -r1.9 src/external/cddl/osnet/sys/kern/misc.c
cvs rdiff -u -r1.359 -r1.360 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.182 -r1.183 src/sys/arch/atari/atari/machdep.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/cesfic/cesfic/machdep.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/emips/emips/machdep.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/evbppc/explora/machdep.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/evbppc/virtex/machdep.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/evbppc/walnut/machdep.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/ews4800mips/ews4800mips/machdep.c
cvs rdiff -u -r1.233 -r1.234 src/sys/arch/hp300/hp300/machdep.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/hppa/hppa/machdep.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/luna68k/luna68k/machdep.c
cvs rdiff -u -r1.357 -r1.358 src/sys/arch/mac68k/mac68k/machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/mips/mips/cpu_subr.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/mvme68k/mvme68k/machdep.c
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/news68k/news68k/machdep.c
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/next68k/next68k/machdep.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/booke/booke_machdep.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/powerpc/oea/oea_machdep.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/riscv/riscv/riscv_machdep.c
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/sgimips/sgimips/machdep.c
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/sh3/sh3/sh3_machdep.c
cvs rdiff -u -r1.333 -r1.334 src/sys/arch/sparc/sparc/machdep.c
cvs rdiff -u -r1.297 -r1.298 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/sun2/sun2/machdep.c
cvs rdiff -u -r1.211 -r1.212 src/sys/arch/sun3/sun3/machdep.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/sun3/sun3x/machdep.c
cvs rdiff -u -r1.195 -r1.196 src/sys/arch/vax/vax/machdep.c
cvs rdiff -u -r1.202 -r1.203 src/sys/arch/x68k/x68k/machdep.c
cvs rdiff -u -r1.249 -r1.250 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.11 -r1.12 src/sys/compat/linux32/common/linux32_sysinfo.c
cvs rdiff -u -r1.183 -r1.184 src/sys/dev/ccd.c
cvs rdiff -u -r1.12 -r1.13 src/sys/fs/tmpfs/tmpfs_mem.c
cvs rdiff -u -r1.526 -r1.527 src/sys/kern/init_main.c
cvs rdiff -u -r1.150 -r1.151 src/sys/kern/kern_module.c
cvs rdiff -u -r1.254 -r1.255 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.295 -r1.296 src/sys/kern/vfs_bio.c
cvs rdiff -u -r1.84 -r1.85 

CVS commit: src/lib/libpthread

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 18:42:02 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_tsd.c

Log Message:
Drop self->pt_lock before clearing TSD / malloc TSD.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libpthread/pthread_tsd.c

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

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.175 src/lib/libpthread/pthread.c:1.176
--- src/lib/libpthread/pthread.c:1.175	Wed Jun 10 22:45:15 2020
+++ src/lib/libpthread/pthread.c	Thu Jun 11 18:42:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -615,21 +615,18 @@ pthread_exit(void *retval)
 	pthread_mutex_lock(>pt_lock);
 	self->pt_flags |= PT_FLAG_CS_DISABLED;
 	self->pt_cancel = 0;
+	pthread_mutex_unlock(>pt_lock);
 
 	/* Call any cancellation cleanup handlers */
 	if (!PTQ_EMPTY(>pt_cleanup_stack)) {
-		pthread_mutex_unlock(>pt_lock);
 		while (!PTQ_EMPTY(>pt_cleanup_stack)) {
 			cleanup = PTQ_FIRST(>pt_cleanup_stack);
 			PTQ_REMOVE(>pt_cleanup_stack, cleanup, ptc_next);
 			(*cleanup->ptc_cleanup)(cleanup->ptc_arg);
 		}
-		pthread_mutex_lock(>pt_lock);
 	}
 
-	pthread_mutex_unlock(>pt_lock);
 	__cxa_thread_run_atexit();
-	pthread_mutex_lock(>pt_lock);
 
 	/* Perform cleanup of thread-specific data */
 	pthread__destroy_tsd(self);
@@ -641,6 +638,7 @@ pthread_exit(void *retval)
 	 * Signal our exit.  Our stack and pthread_t won't be reused until
 	 * pthread_create() can see from kernel info that this LWP is gone.
 	 */
+	pthread_mutex_lock(>pt_lock);
 	self->pt_exitval = retval;
 	if (self->pt_flags & PT_FLAG_DETACHED) {
 		/* pthread__reap() will drop the lock. */

Index: src/lib/libpthread/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.22 src/lib/libpthread/pthread_tsd.c:1.23
--- src/lib/libpthread/pthread_tsd.c:1.22	Sun Apr 19 20:47:03 2020
+++ src/lib/libpthread/pthread_tsd.c	Thu Jun 11 18:42:02 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $	*/
 
 /*-
- * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001, 2007, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -323,7 +323,6 @@ pthread__destroy_tsd(pthread_t self)
 
 	if (!self->pt_havespecific)
 		return;
-	pthread_mutex_unlock(>pt_lock);
 
 	/* Butenhof, section 5.4.2 (page 167):
 	 * 
@@ -378,7 +377,6 @@ pthread__destroy_tsd(pthread_t self)
 	} while (!done && --iterations);
 
 	self->pt_havespecific = 0;
-	pthread_mutex_lock(>pt_lock);
 }
 
 void



CVS commit: src/lib/libpthread

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 18:41:22 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Adjust memory barriers.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libpthread/pthread_mutex.c

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

Modified files:

Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.80 src/lib/libpthread/pthread_mutex.c:1.81
--- src/lib/libpthread/pthread_mutex.c:1.80	Wed Jun 10 22:45:15 2020
+++ src/lib/libpthread/pthread_mutex.c	Thu Jun 11 18:41:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.80 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.81 2020/06/11 18:41:22 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.80 2020/06/10 22:45:15 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.81 2020/06/11 18:41:22 ad Exp $");
 
 #include 
 #include 
@@ -532,7 +532,7 @@ pthread__mutex_wakeup(pthread_t self, st
 		next = cur->next;
 		pthread__assert(cur->lid != 0);
 		lids[nlid++] = cur->lid;
-		membar_sync();
+		membar_exit();
 		cur->lid = 0;
 		/* No longer safe to touch 'cur' */
 	}
@@ -719,6 +719,9 @@ pthread__mutex_deferwake(pthread_t self,
 	/* Append atomically. */
 	for (o = ptm->ptm_waiters;; o = n) {
 		tail->next = o;
+#ifndef PTHREAD__ATOMIC_IS_MEMBAR
+		membar_producer();
+#endif
 		n = atomic_cas_ptr(>ptm_waiters, o, head);
 		if (__predict_true(n == o)) {
 			break;



CVS commit: src/lib/libpthread

2020-06-10 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun 10 22:45:15 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_int.h
pthread_mutex.c pthread_types.h

Log Message:
- Make pthread_condvar and pthread_mutex work on the stack rather than in
  pthread_t, so there's less chance of bad things happening if someone calls
  (for example) pthread_cond_broadcast() from a signal handler.

- Remove all the deferred waiter handling except for the one case that really
  matters which is transferring waiters from condvar -> mutex on wakeup, and
  do that by splicing the condvar's waiters onto the mutex.

- Remove the mutex waiters bit as it's another complication that's not
  strictly needed.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.73 -r1.74 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.106 -r1.107 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.79 -r1.80 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libpthread/pthread_types.h

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

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.174 src/lib/libpthread/pthread.c:1.175
--- src/lib/libpthread/pthread.c:1.174	Thu Jun  4 00:45:32 2020
+++ src/lib/libpthread/pthread.c	Wed Jun 10 22:45:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.174 2020/06/04 00:45:32 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.174 2020/06/04 00:45:32 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -297,11 +297,7 @@ pthread__initthread(pthread_t t)
 
 	t->pt_self = t;
 	t->pt_magic = PT_MAGIC;
-	t->pt_willpark = 0;
-	t->pt_waiters[0] = 0;
-	t->pt_nwaiters = 0;
 	t->pt_sleepobj = NULL;
-	t->pt_signalled = 0;
 	t->pt_havespecific = 0;
 	t->pt_lwpctl = __dummy_lwpctl;
 
@@ -602,48 +598,6 @@ pthread_resume_np(pthread_t thread)
 	return errno;
 }
 
-/*
- * Wake all deferred waiters hanging off self.
- *
- * It's possible for threads to have called _lwp_exit() before we wake them,
- * because of cancellation and timeout, so ESRCH is tolerated here.  If a
- * thread exits and its LID is reused, and the a thread receives an wakeup
- * meant for the previous incarnation of the LID, no harm will be done.
- */
-void
-pthread__clear_waiters(pthread_t self)
-{
-	int rv;
-
-	pthread__smt_wake();
-
-	switch (self->pt_nwaiters) {
-	case 0:
-		break;
-	case 1:
-		if (self->pt_willpark) {
-			break;
-		}
-		rv = _lwp_unpark(self->pt_waiters[0], NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
-		if (rv != 0 && errno != ESRCH) {
-			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark failed: %d", errno);
-		}
-		break;
-	default:
-		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
-		if (rv != 0 && errno != ESRCH) {
-			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark_all failed: %d", errno);
-		}
-		break;
-	}
-}
-
 void
 pthread_exit(void *retval)
 {
@@ -658,7 +612,6 @@ pthread_exit(void *retval)
 	self = pthread__self();
 
 	/* Disable cancellability. */
-	self->pt_willpark = 0;
 	pthread_mutex_lock(>pt_lock);
 	self->pt_flags |= PT_FLAG_CS_DISABLED;
 	self->pt_cancel = 0;
@@ -692,14 +645,10 @@ pthread_exit(void *retval)
 	if (self->pt_flags & PT_FLAG_DETACHED) {
 		/* pthread__reap() will drop the lock. */
 		pthread__reap(self);
-		pthread__assert(!self->pt_willpark);
-		pthread__clear_waiters(self);
 		_lwp_exit();
 	} else {
 		self->pt_state = PT_STATE_ZOMBIE;
-		pthread__assert(!self->pt_willpark);
 		pthread_mutex_unlock(>pt_lock);
-		pthread__clear_waiters(self);
 		/* Note: name will be freed by the joiner. */
 		_lwp_exit();
 	}
@@ -1166,9 +1115,7 @@ pthread__park(pthread_t self, pthread_mu
 {
 	int rv, error;
 
-	self->pt_willpark = 1;
 	pthread_mutex_unlock(lock);
-	self->pt_willpark = 0;
 
 	/*
 	 * Wait until we are awoken by a pending unpark operation,
@@ -1194,13 +1141,8 @@ pthread__park(pthread_t self, pthread_mu
 		 * If we deferred unparking a thread, arrange to
 		 * have _lwp_park() restart it before blocking.
 		 */
-		pthread__assert(self->pt_nwaiters <= 1);
-		pthread__assert(self->pt_nwaiters != 0 ||
-		self->pt_waiters[0] == 0);
 		error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME,
-		__UNCONST(abstime), self->pt_waiters[0], NULL, NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
+		__UNCONST(abstime), 0, NULL, NULL);
 		if (error != 0) {
 			switch (rv = errno) {
 			case EINTR:
@@ -1230,31 +1172,34 @@ pthread__unpark(pthread_queue_t *queue, 
 	pthread_t target;
 
 	target = PTQ_FIRST(queue);
-	if 

CVS commit: src/sys/arch/aarch64/aarch64

2020-06-10 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun 10 22:24:22 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c

Log Message:
- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/aarch64/aarch64/pmap.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/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.76 src/sys/arch/aarch64/aarch64/pmap.c:1.77
--- src/sys/arch/aarch64/aarch64/pmap.c:1.76	Mon Jun  1 02:42:24 2020
+++ src/sys/arch/aarch64/aarch64/pmap.c	Wed Jun 10 22:24:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.76 2020/06/01 02:42:24 ryo Exp $	*/
+/*	$NetBSD: pmap.c,v 1.77 2020/06/10 22:24:22 ad Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.76 2020/06/01 02:42:24 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.77 2020/06/10 22:24:22 ad Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -1594,7 +1594,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	unsigned int idx;
 	int error = 0;
 	const bool user = (pm != pmap_kernel());
-	bool need_sync_icache, need_update_pv;
+	bool need_sync_icache, need_enter_pv;
 	bool l3only = true;
 
 	UVMHIST_FUNC(__func__);
@@ -1659,10 +1659,10 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 		 * pool_cache_get() may call pmap_kenter() internally.
 		 */
 		spv = pool_cache_get(&_pmap_pv_pool, PR_NOWAIT);
-		need_update_pv = true;
+		need_enter_pv = true;
 	} else {
 		spv = NULL;
-		need_update_pv = false;
+		need_enter_pv = false;
 	}
 
 	pm_lock(pm);
@@ -1764,12 +1764,12 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 		bool need_remove_pv;
 
 		KASSERT(!kenter);	/* pmap_kenter_pa() cannot override */
-#ifdef PMAPCOUNTERS
-		PMAP_COUNT(remappings);
 		if (opte & LX_BLKPAG_OS_WIRED) {
 			PMSTAT_DEC_WIRED_COUNT(pm);
 		}
 		PMSTAT_DEC_RESIDENT_COUNT(pm);
+#ifdef PMAPCOUNTERS
+		PMAP_COUNT(remappings);
 		if (user) {
 			PMAP_COUNT(user_mappings_changed);
 		} else {
@@ -1784,7 +1784,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 		if (pa == l3pte_pa(opte)) {
 			/* old and new pte have same pa, no need to update pv */
 			need_remove_pv = (pp == NULL);
-			need_update_pv = false;
+			need_enter_pv = false;
 			if (need_sync_icache && l3pte_executable(opte, user))
 need_sync_icache = false;
 		} else {
@@ -1831,7 +1831,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 		flags |= VM_PROT_READ;
 
 	mdattr = VM_PROT_READ | VM_PROT_WRITE;
-	if (need_update_pv) {
+	if (need_enter_pv) {
 		error = _pmap_enter_pv(pp, pm, , va, ptep, pa, flags);
 		if (error != 0) {
 			/*



CVS commit: src/tests/lib/libpthread

2020-06-10 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun 10 21:46:50 UTC 2020

Modified Files:
src/tests/lib/libpthread: t_cond.c

Log Message:
Adjust cond_timedwait_race to take account of spurious wakeups (which are
completely legit).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libpthread/t_cond.c

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

Modified files:

Index: src/tests/lib/libpthread/t_cond.c
diff -u src/tests/lib/libpthread/t_cond.c:1.7 src/tests/lib/libpthread/t_cond.c:1.8
--- src/tests/lib/libpthread/t_cond.c:1.7	Sun Jul  3 14:24:59 2016
+++ src/tests/lib/libpthread/t_cond.c	Wed Jun 10 21:46:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $ */
+/* $NetBSD: t_cond.c,v 1.8 2020/06/10 21:46:50 ad Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.8 2020/06/10 21:46:50 ad Exp $");
 
 #include 
 
@@ -329,7 +329,7 @@ pthread_cond_timedwait_func(void *arg)
 		 * Sometimes we catch ESRCH.
 		 * This should never happen.
 		 */
-		ATF_REQUIRE(rv == ETIMEDOUT);
+		ATF_REQUIRE(rv == ETIMEDOUT || rv == 0);
 		PTHREAD_REQUIRE(pthread_mutex_unlock(_mutex));
 	}
 }



CVS commit: src/sys/kern

2020-06-06 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun  6 23:02:25 UTC 2020

Modified Files:
src/sys/kern: subr_physmap.c

Log Message:
uvmexp.ncolors being used where uvmexp.colormask wanted


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/kern/subr_physmap.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/kern/subr_physmap.c
diff -u src/sys/kern/subr_physmap.c:1.2 src/sys/kern/subr_physmap.c:1.3
--- src/sys/kern/subr_physmap.c:1.2	Sat Jan 19 01:04:51 2013
+++ src/sys/kern/subr_physmap.c	Sat Jun  6 23:02:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_physmap.c,v 1.2 2013/01/19 01:04:51 rmind Exp $	*/
+/*	$NetBSD: subr_physmap.c,v 1.3 2020/06/06 23:02:25 ad Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: subr_physmap.c,v 1.2 2013/01/19 01:04:51 rmind Exp $");
+__KERNEL_RCSID(1, "$NetBSD: subr_physmap.c,v 1.3 2020/06/06 23:02:25 ad Exp $");
 
 #include 
 #include 
@@ -316,7 +316,7 @@ physmap_map(void *cookie, vaddr_t *kvap)
 		 * so we map it via the kernel_map.
 		 */
 		pc->pc_kva = uvm_km_alloc(kernel_map, pc->pc_klen,
-		atop(pa) & uvmexp.ncolors,
+		atop(pa) & uvmexp.colormask,
 		UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_COLORMATCH);
 		KASSERT(pc->pc_kva != 0);
 



CVS commit: src/sys/rump/librump/rumpkern

2020-06-06 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun  6 22:31:41 UTC 2020

Modified Files:
src/sys/rump/librump/rumpkern: vm.c

Log Message:
Correction to previous - set VI_PAGES correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 src/sys/rump/librump/rumpkern/vm.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/rump/librump/rumpkern/vm.c
diff -u src/sys/rump/librump/rumpkern/vm.c:1.188 src/sys/rump/librump/rumpkern/vm.c:1.189
--- src/sys/rump/librump/rumpkern/vm.c:1.188	Wed Jun  3 22:25:49 2020
+++ src/sys/rump/librump/rumpkern/vm.c	Sat Jun  6 22:31:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm.c,v 1.188 2020/06/03 22:25:49 ad Exp $	*/
+/*	$NetBSD: vm.c,v 1.189 2020/06/06 22:31:40 ad Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.188 2020/06/03 22:25:49 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.189 2020/06/06 22:31:40 ad Exp $");
 
 #include 
 #include 
@@ -176,7 +176,6 @@ uvm_pagealloc_strat(struct uvm_object *u
 		pool_cache_put(, pg);
 		return NULL;
 	}
-	uobj->uo_npages++;
 
 	if (UVM_OBJ_IS_VNODE(uobj)) {
 		if (uobj->uo_npages == 0) {
@@ -187,6 +186,7 @@ uvm_pagealloc_strat(struct uvm_object *u
 		}
 		pg->flags |= PG_FILE;
 	}
+	uobj->uo_npages++;
 
 	pg->flags = PG_CLEAN|PG_BUSY|PG_FAKE;
 	if (flags & UVM_PGA_ZERO) {



CVS commit: src/sys/kern

2020-06-06 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun  6 22:26:47 UTC 2020

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
lwp_exit(): add a warning about (l != curlwp)


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/kern/kern_lwp.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/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.240 src/sys/kern/kern_lwp.c:1.241
--- src/sys/kern/kern_lwp.c:1.240	Mon Jun  1 13:58:14 2020
+++ src/sys/kern/kern_lwp.c	Sat Jun  6 22:26:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.240 2020/06/01 13:58:14 thorpej Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.241 2020/06/06 22:26:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.240 2020/06/01 13:58:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.241 2020/06/06 22:26:47 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1054,6 +1054,8 @@ lwp_startup(struct lwp *prev, struct lwp
 
 /*
  * Exit an LWP.
+ *
+ * *** WARNING *** This can be called with (l != curlwp) in error paths.
  */
 void
 lwp_exit(struct lwp *l)



CVS commit: src/lib/libpthread

2020-06-06 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun  6 22:24:00 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Adjust previous.  In the condvar case the wakeup might already have been
eaten.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/lib/libpthread/pthread_cond.c

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

Modified files:

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.72 src/lib/libpthread/pthread_cond.c:1.73
--- src/lib/libpthread/pthread_cond.c:1.72	Thu Jun  4 04:40:01 2020
+++ src/lib/libpthread/pthread_cond.c	Sat Jun  6 22:23:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.73 2020/06/06 22:23:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.73 2020/06/06 22:23:59 ad Exp $");
 
 #include 
 #include 
@@ -185,14 +185,14 @@ pthread_cond_timedwait(pthread_cond_t *c
 		pthread_cond_broadcast(cond);
 
 		/*
-		 * Might have raced with another thread to do the wakeup.
-		 * In any case there will be a wakeup for sure.  Eat it and
-		 * wait for pt_condwait to clear.
+		 * Might have raced with another thread to do the wakeup. 
+		 * Wait until released - this thread can't wait on a condvar
+		 * again until the data structures are no longer in us.
 		 */
-		do {
+		while (self->pt_condwait) {
 			(void)_lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, NULL,
 			0, NULL, NULL);
-		} while (self->pt_condwait);
+		}
 	}
 
 	/*



CVS commit: src/sys/rump/librump/rumpkern

2020-06-03 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun  3 22:25:49 UTC 2020

Modified Files:
src/sys/rump/librump/rumpkern: vm.c

Log Message:
PR kern/55032 (rump/rumpkern/t_vm:uvmwait test case now fails)

Work around issues with rump's pagedaemon emulation, including one that's
sensitive to timing effects (i.e. scheduler changes).  While here tidy up
some other stuff around the emulation of page alloc/free.


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 src/sys/rump/librump/rumpkern/vm.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/rump/librump/rumpkern/vm.c
diff -u src/sys/rump/librump/rumpkern/vm.c:1.187 src/sys/rump/librump/rumpkern/vm.c:1.188
--- src/sys/rump/librump/rumpkern/vm.c:1.187	Tue Mar 17 18:31:38 2020
+++ src/sys/rump/librump/rumpkern/vm.c	Wed Jun  3 22:25:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm.c,v 1.187 2020/03/17 18:31:38 ad Exp $	*/
+/*	$NetBSD: vm.c,v 1.188 2020/06/03 22:25:49 ad Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.187 2020/03/17 18:31:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.188 2020/06/03 22:25:49 ad Exp $");
 
 #include 
 #include 
@@ -69,7 +69,6 @@ __KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.187
 #include 
 
 kmutex_t vmpage_lruqueue_lock; /* non-free page lock */
-kmutex_t uvm_fpageqlock; /* free page lock, non-gpl license */
 kmutex_t uvm_swap_data_lock;
 
 struct uvmexp uvmexp;
@@ -172,13 +171,6 @@ uvm_pagealloc_strat(struct uvm_object *u
 	pg->offset = off;
 	pg->uobject = uobj;
 
-	if (UVM_OBJ_IS_VNODE(uobj) && uobj->uo_npages == 0) {
-		struct vnode *vp = (struct vnode *)uobj;
-		mutex_enter(vp->v_interlock);
-		vp->v_iflag |= VI_PAGES;
-		mutex_exit(vp->v_interlock);
-	}
-
 	if (radix_tree_insert_node(>uo_pages, off >> PAGE_SHIFT,
 	pg) != 0) {
 		pool_cache_put(, pg);
@@ -186,6 +178,16 @@ uvm_pagealloc_strat(struct uvm_object *u
 	}
 	uobj->uo_npages++;
 
+	if (UVM_OBJ_IS_VNODE(uobj)) {
+		if (uobj->uo_npages == 0) {
+			struct vnode *vp = (struct vnode *)uobj;
+			mutex_enter(vp->v_interlock);
+			vp->v_iflag |= VI_PAGES;
+			mutex_exit(vp->v_interlock);
+		}
+		pg->flags |= PG_FILE;
+	}
+
 	pg->flags = PG_CLEAN|PG_BUSY|PG_FAKE;
 	if (flags & UVM_PGA_ZERO) {
 		uvm_pagezero(pg);
@@ -201,6 +203,8 @@ uvm_pagealloc_strat(struct uvm_object *u
 		mutex_enter(_lruqueue_lock);
 		TAILQ_INSERT_TAIL(_lruqueue, pg, pageq.queue);
 		mutex_exit(_lruqueue_lock);
+	} else {
+		pg->flags |= PG_AOBJ;
 	}
 
 	return pg;
@@ -220,10 +224,7 @@ uvm_pagefree(struct vm_page *pg)
 	KASSERT(rw_write_held(uobj->vmobjlock));
 
 	mutex_enter(>interlock);
-	if (pg->pqflags & PQ_WANTED) {
-		pg->pqflags &= ~PQ_WANTED;
-		wakeup(pg);
-	}
+	uvm_pagewakeup(pg);
 	mutex_exit(>interlock);
 
 	uobj->uo_npages--;
@@ -367,11 +368,8 @@ uvm_init(void)
 	mutex_init(, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(_lruqueue_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(_swap_data_lock, MUTEX_DEFAULT, IPL_NONE);
-
-	/* just to appease linkage */
-	mutex_init(_fpageqlock, MUTEX_SPIN, IPL_VM);
-
 	mutex_init(, MUTEX_DEFAULT, IPL_NONE);
+
 	cv_init(, "pdaemon");
 	cv_init(, "oomwait");
 
@@ -1141,16 +1139,14 @@ uvm_pageout(void *arg)
 
 	mutex_enter();
 	for (;;) {
-		if (!NEED_PAGEDAEMON()) {
-			kernel_map->flags &= ~VM_MAP_WANTVA;
-		}
-
 		if (pdaemon_waiters) {
 			pdaemon_waiters = 0;
 			cv_broadcast();
 		}
-
-		cv_wait(, );
+		if (!NEED_PAGEDAEMON()) {
+			kernel_map->flags &= ~VM_MAP_WANTVA;
+			cv_wait(, );
+		}
 		uvmexp.pdwoke++;
 
 		/* tell the world that we are hungry */
@@ -1202,22 +1198,6 @@ uvm_pageout(void *arg)
 		mutex_exit(_lruqueue_lock);
 
 		/*
-		 * Ok, someone is running with an object lock held.
-		 * We want to yield the host CPU to make sure the
-		 * thread is not parked on the host.  nanosleep
-		 * for the smallest possible time and hope we're back in
-		 * the game soon.
-		 */
-		if (cleaned == 0) {
-			rumpuser_clock_sleep(RUMPUSER_CLOCK_RELWALL, 0, 1);
-
-			skip = 0;
-
-			/* and here we go again */
-			goto again;
-		}
-
-		/*
 		 * And of course we need to reclaim the page cache
 		 * again to actually release memory.
 		 */
@@ -1249,8 +1229,6 @@ uvm_pageout(void *arg)
 		mutex_enter();
 		if (!succ && cleaned == 0 && pdaemon_waiters &&
 		uvmexp.paging == 0) {
-			rumpuser_dprintf("pagedaemoness: failed to reclaim "
-			"memory ... sleeping (deadlock?)\n");
 			kpause("pddlk", false, hz, );
 		}
 	}



CVS commit: src/lib/libpthread

2020-06-03 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun  3 22:10:24 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_mutex.c

Log Message:
Deal with a couple of problems with threads being awoken early due to
timeouts or cancellation where:

- The restarting thread calls _lwp_exit() before another thread gets around
  to waking it with _lwp_unpark(), leading to ESRCH (observed by joerg@).
  (I may have removed a similar check mistakenly over the weekend.)

- The restarting thread considers itself gone off the sleep queue but
  at the same time another thread is part way through waking it, and hasn't
  fully completed that operation yet by setting thread->pt_mutexwait = 0.
  I think that could have potentially lead to the list of waiters getting
  messed up given the right circumstances.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.70 -r1.71 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.78 -r1.79 src/lib/libpthread/pthread_mutex.c

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

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.172 src/lib/libpthread/pthread.c:1.173
--- src/lib/libpthread/pthread.c:1.172	Tue Jun  2 00:29:53 2020
+++ src/lib/libpthread/pthread.c	Wed Jun  3 22:10:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.173 2020/06/03 22:10:24 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.173 2020/06/03 22:10:24 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -599,9 +599,12 @@ pthread_resume_np(pthread_t thread)
 }
 
 /*
- * In case the thread is exiting at an inopportune time leaving waiters not
- * awoken (because cancelled, for instance) make sure we have no waiters
- * left.
+ * Wake all deferred waiters hanging off self.
+ *
+ * It's possible for threads to have called _lwp_exit() before we wake them,
+ * because of cancellation and timeout, so ESRCH is tolerated here.  If a
+ * thread exits and its LID is reused, and the a thread receives an wakeup
+ * meant for the previous incarnation of the LID, no harm will be done.
  */
 void
 pthread__clear_waiters(pthread_t self)
@@ -620,7 +623,7 @@ pthread__clear_waiters(pthread_t self)
 		rv = _lwp_unpark(self->pt_waiters[0], NULL);
 		self->pt_waiters[0] = 0;
 		self->pt_nwaiters = 0;
-		if (rv != 0) {
+		if (rv != 0 && errno != ESRCH) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
 			"_lwp_unpark failed: %d", errno);
 		}
@@ -629,7 +632,7 @@ pthread__clear_waiters(pthread_t self)
 		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
 		self->pt_waiters[0] = 0;
 		self->pt_nwaiters = 0;
-		if (rv != 0) {
+		if (rv != 0 && errno != ESRCH) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
 			"_lwp_unpark_all failed: %d", errno);
 		}
@@ -1195,6 +1198,7 @@ pthread__park(pthread_t self, pthread_mu
 			switch (rv = errno) {
 			case EINTR:
 			case EALREADY:
+			case ESRCH:
 rv = 0;
 break;
 			case ETIMEDOUT:

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.70 src/lib/libpthread/pthread_cond.c:1.71
--- src/lib/libpthread/pthread_cond.c:1.70	Mon Jun  1 11:44:59 2020
+++ src/lib/libpthread/pthread_cond.c	Wed Jun  3 22:10:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.70 2020/06/01 11:44:59 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.70 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $");
 
 #include 
 #include 
@@ -112,7 +112,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 		   const struct timespec *abstime)
 {
 	pthread_t self, next, waiters;
-	int retval;
+	int retval, cancel;
 	clockid_t clkid = pthread_cond_getclock(cond);
 
 	if (__predict_false(__uselibcstub))
@@ -126,6 +126,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 	mutex->ptm_owner != NULL);
 
 	self = pthread__self();
+	pthread__assert(!self->pt_condwait);
 
 	if (__predict_false(self->pt_cancel)) {
 		pthread__cancelled();
@@ -165,24 +166,42 @@ pthread_cond_timedwait(pthread_cond_t *c
 retval = errno;
 			}
 		}
-	} while (self->pt_condwait && !self->pt_cancel && !retval);
+		cancel = self->pt_cancel;
+	} while (self->pt_condwait && !cancel && !retval);
 
 	/*
-	 * If we have cancelled then exit.  POSIX dictates that
-	 * the mutex must be held when we action the cancellation.
+	 * If this thread absorbed a wakeup from pthread_cond_signal() and
+	 * cannot take the wakeup, we must ensure that another 

CVS commit: src/sys/arch/x86/x86

2020-06-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun  3 00:27:46 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Revert most of 1.396 and go back to using memset()/memcpy().
Do not restore pageidlezero stuff though.


To generate a diff of this commit:
cvs rdiff -u -r1.397 -r1.398 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.397 src/sys/arch/x86/x86/pmap.c:1.398
--- src/sys/arch/x86/x86/pmap.c:1.397	Fri May 29 22:40:15 2020
+++ src/sys/arch/x86/x86/pmap.c	Wed Jun  3 00:27:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.397 2020/05/29 22:40:15 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.398 2020/06/03 00:27:46 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.397 2020/05/29 22:40:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.398 2020/06/03 00:27:46 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1297,8 +1297,7 @@ pmap_bootstrap(vaddr_t kva_start)
 	xen_dummy_user_pgd = xen_dummy_page - KERNBASE;
 
 	/* Zero fill it, the less checks in Xen it requires the better */
-	x86_stos((void *)(xen_dummy_user_pgd + KERNBASE), 0,
-	PAGE_SIZE / sizeof(long));
+	memset((void *)(xen_dummy_user_pgd + KERNBASE), 0, PAGE_SIZE);
 	/* Mark read-only */
 	HYPERVISOR_update_va_mapping(xen_dummy_user_pgd + KERNBASE,
 	pmap_pa2pte(xen_dummy_user_pgd) | PTE_P | pmap_pg_nx,
@@ -1547,7 +1546,7 @@ pmap_init_pcpu(void)
 		pa = pmap_bootstrap_palloc(1);
 		*pte = (pa & PTE_FRAME) | pteflags;
 		pmap_update_pg(tmpva);
-		x86_stos((void *)tmpva, 0, PAGE_SIZE / sizeof(long));
+		memset((void *)tmpva, 0, PAGE_SIZE);
 
 		L4_BASE[L4e_idx+i] = pa | pteflags | PTE_A;
 	}
@@ -1561,7 +1560,7 @@ pmap_init_pcpu(void)
 		pa = pmap_bootstrap_palloc(1);
 		*pte = (pa & PTE_FRAME) | pteflags;
 		pmap_update_pg(tmpva);
-		x86_stos((void *)tmpva, 0, PAGE_SIZE / sizeof(long));
+		memset((void *)tmpva, 0, PAGE_SIZE);
 
 		L3_BASE[L3e_idx+i] = pa | pteflags | PTE_A;
 	}
@@ -1576,7 +1575,7 @@ pmap_init_pcpu(void)
 		pa = pmap_bootstrap_palloc(1);
 		*pte = (pa & PTE_FRAME) | pteflags;
 		pmap_update_pg(tmpva);
-		x86_stos((void *)tmpva, 0, PAGE_SIZE / sizeof(long));
+		memset((void *)tmpva, 0, PAGE_SIZE);
 
 		L2_BASE[L2e_idx+i] = pa | pteflags | PTE_A;
 	}
@@ -1668,7 +1667,7 @@ pmap_init_directmap(struct pmap *kpm)
 		pa = pmap_bootstrap_palloc(1);
 		*pte = (pa & PTE_FRAME) | pteflags;
 		pmap_update_pg(tmpva);
-		x86_stos((void *)tmpva, 0, PAGE_SIZE / sizeof(long));
+		memset((void *)tmpva, 0, PAGE_SIZE);
 
 		L4_BASE[L4e_idx+i] = pa | pteflags | PTE_A;
 	}
@@ -1682,7 +1681,7 @@ pmap_init_directmap(struct pmap *kpm)
 		pa = pmap_bootstrap_palloc(1);
 		*pte = (pa & PTE_FRAME) | pteflags;
 		pmap_update_pg(tmpva);
-		x86_stos((void *)tmpva, 0, PAGE_SIZE / sizeof(long));
+		memset((void *)tmpva, 0, PAGE_SIZE);
 
 		L3_BASE[L3e_idx+i] = pa | pteflags | PTE_A;
 	}
@@ -2632,7 +2631,7 @@ pmap_pdp_init(pd_entry_t *pdir)
 	int s;
 #endif
 
-	x86_stos(pdir, 0, PDP_SIZE * PAGE_SIZE / sizeof(long));
+	memset(pdir, 0, PDP_SIZE * PAGE_SIZE);
 
 	/*
 	 * NOTE: This is all done unlocked, but we will check afterwards
@@ -2675,8 +2674,8 @@ pmap_pdp_init(pd_entry_t *pdir)
 	/* Copy the kernel's top level PDE */
 	npde = nkptp[PTP_LEVELS - 1];
 
-	x86_movs([PDIR_SLOT_KERN], _BASE[PDIR_SLOT_KERN],
-	npde * sizeof(pd_entry_t) / sizeof(long));
+	memcpy([PDIR_SLOT_KERN], _BASE[PDIR_SLOT_KERN],
+	npde * sizeof(pd_entry_t));
 
 	if (VM_MIN_KERNEL_ADDRESS != KERNBASE) {
 		int idx = pl_i(KERNBASE, PTP_LEVELS);
@@ -3811,7 +3810,7 @@ void
 pmap_zero_page(paddr_t pa)
 {
 #if defined(__HAVE_DIRECT_MAP)
-	x86_stos((void *)PMAP_DIRECT_MAP(pa), 0, PAGE_SIZE / sizeof(long));
+	memset((void *)PMAP_DIRECT_MAP(pa), 0, PAGE_SIZE);
 #else
 #if defined(XENPV)
 	if (XEN_VERSION_SUPPORTED(3, 4))
@@ -3835,7 +3834,7 @@ pmap_zero_page(paddr_t pa)
 	pmap_pte_flush();
 	pmap_update_pg(zerova);		/* flush TLB */
 
-	x86_stos((void *)zerova, 0, PAGE_SIZE / sizeof(long));
+	memset((void *)zerova, 0, PAGE_SIZE);
 
 #if defined(DIAGNOSTIC) || defined(XENPV)
 	pmap_pte_set(zpte, 0);/* zap ! */
@@ -3853,7 +3852,7 @@ pmap_copy_page(paddr_t srcpa, paddr_t ds
 	vaddr_t srcva = PMAP_DIRECT_MAP(srcpa);
 	vaddr_t dstva = PMAP_DIRECT_MAP(dstpa);
 
-	x86_movs((void *)dstva, (void *)srcva, PAGE_SIZE / sizeof(long));
+	memcpy((void *)dstva, (void *)srcva, PAGE_SIZE);
 #else
 #if defined(XENPV)
 	if (XEN_VERSION_SUPPORTED(3, 4)) {
@@ -3883,7 +3882,7 @@ pmap_copy_page(paddr_t srcpa, paddr_t ds
 	pmap_update_pg(srcva);
 	pmap_update_pg(dstva);
 
-	x86_movs((void *)dstva, (void *)srcva, PAGE_SIZE / sizeof(long));
+	memcpy((void *)dstva, (void *)srcva, PAGE_SIZE);
 
 #if defined(DIAGNOSTIC) || defined(XENPV)
 	pmap_pte_set(srcpte, 

CVS commit: src/sys/arch/amd64

2020-06-01 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun  1 22:58:06 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S
src/sys/arch/amd64/include: frameasm.h

Log Message:
Reported-by: syzbot+6dd5a230d19f0cbc7...@syzkaller.appspotmail.com

Instrument STOS/MOVS for KMSAN to unbreak it.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/amd64/include/frameasm.h

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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.58 src/sys/arch/amd64/amd64/cpufunc.S:1.59
--- src/sys/arch/amd64/amd64/cpufunc.S:1.58	Wed May 27 20:48:42 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Mon Jun  1 22:58:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.58 2020/05/27 20:48:42 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.59 2020/06/01 22:58:06 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -424,6 +424,7 @@ END(outl)
 ENTRY(x86_stos)
 	movq	%rsi,%rax
 	movq	%rdx,%rcx
+	KMSAN_REP_STOS(8)
 	rep
 	stosq
 	ret
@@ -431,6 +432,7 @@ END(x86_stos)
 
 ENTRY(x86_movs)
 	movq	%rdx,%rcx
+	KMSAN_REP_STOS(8)
 	rep
 	movsq
 	ret

Index: src/sys/arch/amd64/include/frameasm.h
diff -u src/sys/arch/amd64/include/frameasm.h:1.49 src/sys/arch/amd64/include/frameasm.h:1.50
--- src/sys/arch/amd64/include/frameasm.h:1.49	Sun Apr 26 14:49:17 2020
+++ src/sys/arch/amd64/include/frameasm.h	Mon Jun  1 22:58:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: frameasm.h,v 1.49 2020/04/26 14:49:17 maxv Exp $	*/
+/*	$NetBSD: frameasm.h,v 1.50 2020/06/01 22:58:06 ad Exp $	*/
 
 #ifndef _AMD64_MACHINE_FRAMEASM_H
 #define _AMD64_MACHINE_FRAMEASM_H
@@ -222,6 +222,7 @@
 #endif
 
 #ifdef KMSAN
+/* XXX this belongs somewhere else. */
 #define KMSAN_ENTER	\
 	movq	%rsp,%rdi		; \
 	movq	$TF_REGSIZE+16+40,%rsi	; \
@@ -275,11 +276,33 @@
 	popq	%rdx			; \
 	popq	%rcx			; \
 	popq	%rax
+#define KMSAN_REP_STOS(scale)	\
+	pushq	%rax			; \
+	pushq	%rcx			; \
+	pushq	%rdx			; \
+	pushq	%rsi			; \
+	pushq	%rdi			; \
+	pushq	%r8			; \
+	pushq	%r9			; \
+	pushq	%r10			; \
+	pushq	%r11			; \
+	leaq	(,%rcx,scale),%rsi	; \
+	callq	_C_LABEL(__msan_instrument_asm_store); \
+	popq	%r11			; \
+	popq	%r10			; \
+	popq	%r9			; \
+	popq	%r8			; \
+	popq	%rdi			; \
+	popq	%rsi			; \
+	popq	%rdx			; \
+	popq	%rcx			; \
+	popq	%rax
 #else
 #define KMSAN_ENTER		/* nothing */
 #define KMSAN_LEAVE		/* nothing */
 #define KMSAN_INIT_ARG(sz)	/* nothing */
 #define KMSAN_INIT_RET(sz)	/* nothing */
+#define	KMSAN_REP_STOS(scale)	/* nothing */
 #endif
 
 #ifdef KCOV



CVS commit: src/lib/libpthread

2020-06-01 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun  1 11:44:59 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_int.h
pthread_mutex.c pthread_rwlock.c pthread_types.h

Log Message:
In the interests of reliability simplify waiter handling more and redo
condvars to manage the list of waiters with atomic ops.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.69 -r1.70 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.104 -r1.105 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.77 -r1.78 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.40 -r1.41 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -u -r1.23 -r1.24 src/lib/libpthread/pthread_types.h

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

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.170 src/lib/libpthread/pthread.c:1.171
--- src/lib/libpthread/pthread.c:1.170	Sat May 16 22:53:37 2020
+++ src/lib/libpthread/pthread.c	Mon Jun  1 11:44:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -294,12 +294,11 @@ pthread__initthread(pthread_t t)
 	t->pt_self = t;
 	t->pt_magic = PT_MAGIC;
 	t->pt_willpark = 0;
-	t->pt_unpark = 0;
+	t->pt_waiters[0] = 0;
 	t->pt_nwaiters = 0;
 	t->pt_sleepobj = NULL;
 	t->pt_signalled = 0;
 	t->pt_havespecific = 0;
-	t->pt_early = NULL;
 	t->pt_lwpctl = __dummy_lwpctl;
 
 	memcpy(>pt_lockops, pthread__lock_ops, sizeof(t->pt_lockops));
@@ -609,51 +608,32 @@ pthread__clear_waiters(pthread_t self)
 {
 	int rv;
 
-	/* Zero waiters or one waiter in error case (pthread_exit()). */
-	if (self->pt_nwaiters == 0) {
-		if (self->pt_unpark != 0 && self->pt_willpark == 0) {
-			rv = (ssize_t)_lwp_unpark(self->pt_unpark, NULL);
-			self->pt_unpark = 0;
-			if (rv != 0 && errno != EALREADY && errno != EINTR &&
-			errno != ESRCH) {
-pthread__errorfunc(__FILE__, __LINE__, __func__,
-"_lwp_unpark failed");
-			}
-		}
-		return;
-	}
+	pthread__smt_wake();
 
-	/* One waiter or two waiters (the second being a deferred wakeup). */
-	if (self->pt_nwaiters == 1) {
-		if (self->pt_unpark != 0) {
-			/* Fall through to multiple waiters case. */
-			self->pt_waiters[1] = self->pt_unpark;
-			self->pt_nwaiters = 2;
-			self->pt_unpark = 0;
-		} else if (self->pt_willpark) {
-			/* Defer to _lwp_park(). */
-			self->pt_unpark = self->pt_waiters[0];
-			self->pt_nwaiters = 0;
-			return;
-		} else {
-			/* Wake one now. */
-			rv = (ssize_t)_lwp_unpark(self->pt_waiters[0], NULL);
-			self->pt_nwaiters = 0;
-			if (rv != 0 && errno != EALREADY && errno != EINTR &&
-			errno != ESRCH) {
-pthread__errorfunc(__FILE__, __LINE__, __func__,
-"_lwp_unpark failed");
-			}
-			return;
+	switch (self->pt_nwaiters) {
+	case 0:
+		break;
+	case 1:
+		if (self->pt_willpark) {
+			break;
 		}
-	}
-
-	/* Multiple waiters. */
-	rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
-	self->pt_nwaiters = 0;
-	if (rv != 0 && errno != EINTR) {
-		pthread__errorfunc(__FILE__, __LINE__, __func__,
-		"_lwp_unpark_all failed");
+		rv = _lwp_unpark(self->pt_waiters[0], NULL);
+		self->pt_waiters[0] = 0;
+		self->pt_nwaiters = 0;
+		if (rv != 0) {
+			pthread__errorfunc(__FILE__, __LINE__, __func__,
+			"_lwp_unpark failed");
+		}
+		break;
+	default:
+		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
+		self->pt_waiters[0] = 0;
+		self->pt_nwaiters = 0;
+		if (rv != 0) {
+			pthread__errorfunc(__FILE__, __LINE__, __func__,
+			"_lwp_unpark_all failed");
+		}
+		break;
 	}
 }
 
@@ -1115,7 +1095,7 @@ pthread__assertfunc(const char *file, in
 	function ? "\"" : "");
 
 	_sys_write(STDERR_FILENO, buf, (size_t)len);
-	(void)_lwp_kill(_lwp_self(), SIGABRT);
+	(void)raise(SIGABRT);
 	_exit(1);
 }
 
@@ -1163,16 +1143,12 @@ pthread__errorfunc(const char *file, int
  * http://www.sun.com/software/whitepapers/solaris9/multithread.pdf
  */
 
-#define	OOPS(msg)			\
-pthread__errorfunc(__FILE__, __LINE__, __func__, msg)
-
 int
 pthread__park(pthread_t self, pthread_mutex_t *lock,
 	  pthread_queue_t *queue, const struct timespec *abstime,
 	  int cancelpt)
 {
 	int rv, error;
-	void *obj;
 
 	self->pt_willpark = 1;
 	pthread_mutex_unlock(lock);
@@ -1186,26 +1162,15 @@ pthread__park(pthread_t self, pthread_mu
 	 * It is fine to test the value of pt_sleepobj without
 	 * holding any locks, because:
 	 *
-	 * o Only the blocking thread (this thread) ever sets them
+	 * o Only the blocking thread (this thread) ever sets 

CVS commit: src/sys/dev/acpi

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 31 01:39:33 UTC 2020

Modified Files:
src/sys/dev/acpi: acpi_cpu_cstate.c

Log Message:
Disable read of the ACPI timer during idle, fixing performance degradation
observed with acpicpu.  C1 (MWAIT) is the deepest sleep currently enabled so
there should be no functional change.  Also, the computed nap time is run
through hztoms() which seems incorrect as the ACPI timer is running in the
MHz range.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/acpi/acpi_cpu_cstate.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/dev/acpi/acpi_cpu_cstate.c
diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.60 src/sys/dev/acpi/acpi_cpu_cstate.c:1.61
--- src/sys/dev/acpi/acpi_cpu_cstate.c:1.60	Sun Feb  3 03:19:27 2019
+++ src/sys/dev/acpi/acpi_cpu_cstate.c	Sun May 31 01:39:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.60 2019/02/03 03:19:27 mrg Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.60 2019/02/03 03:19:27 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $");
 
 #include 
 #include 
@@ -739,9 +739,18 @@ static void
 acpicpu_cstate_idle_enter(struct acpicpu_softc *sc, int state)
 {
 	struct acpicpu_cstate *cs = >sc_cstate[state];
-	uint32_t end, start, val;
+	uint32_t val;
 
+#ifdef notyet
+	/*
+	 * XXX This has a significant performance impact because the ACPI
+	 * timer seems very slow and with many CPUs becomes a chokepoint. 
+	 * Better to use the TSC (if invariant) or APIC timer instead. 
+	 * Proably even getbintime().  Disabled for now as no functional
+	 * change - only C1 sleep is enabled.
+	 */
 	start = acpitimer_read_fast(NULL);
+#endif
 
 	switch (cs->cs_method) {
 
@@ -756,8 +765,15 @@ acpicpu_cstate_idle_enter(struct acpicpu
 	}
 
 	cs->cs_evcnt.ev_count++;
+
+#ifdef notyet
+	/*
+	 * XXX As above.  Also, hztoms() seems incorrect as the ACPI timer
+	 * is running the MHz region.
+	 */
 	end = acpitimer_read_fast(NULL);
 	sc->sc_cstate_sleep = hztoms(acpitimer_delta(end, start)) * 1000;
+#endif
 }
 
 static bool



CVS commit: src/sys/kern

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 30 20:23:25 UTC 2020

Modified Files:
src/sys/kern: vfs_lookup.c

Log Message:
Fix merge error - adjust assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.221 -r1.222 src/sys/kern/vfs_lookup.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/kern/vfs_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.221 src/sys/kern/vfs_lookup.c:1.222
--- src/sys/kern/vfs_lookup.c:1.221	Sat May 30 20:16:14 2020
+++ src/sys/kern/vfs_lookup.c	Sat May 30 20:23:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.221 2020/05/30 20:16:14 ad Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.222 2020/05/30 20:23:25 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.221 2020/05/30 20:16:14 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.222 2020/05/30 20:23:25 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -935,10 +935,10 @@ lookup_crossmount(struct namei_state *st
 	error = 0;
 
 	KASSERT((cnp->cn_flags & NOCROSSMOUNT) == 0);
-	KASSERT(searchdir != NULL);
 
 	/* First, unlock searchdir (oof). */
 	if (*searchdir_locked) {
+		KASSERT(searchdir != NULL);
 		lktype = VOP_ISLOCKED(searchdir);
 		VOP_UNLOCK(searchdir);
 		*searchdir_locked = false;
@@ -1608,7 +1608,8 @@ namei_oneroot(struct namei_state *state,
 			 * foundobj == NULL.
 			 */
 			/* lookup_once can't have dropped the searchdir */
-			KASSERT(searchdir != NULL);
+			KASSERT(searchdir != NULL ||
+			(cnp->cn_flags & ISLASTCN) != 0);
 			break;
 		}
 



CVS commit: src/sys

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 30 20:16:14 UTC 2020

Modified Files:
src/sys/kern: vfs_cache.c vfs_lookup.c
src/sys/sys: namei.src

Log Message:
A couple of small changes to lookup that cut 5-10% system time from
"build.sh release" on my test system:

- Crossing mount points during lookup is slow because the set up for, and
  act of doing VFS_ROOT() is quite involved.  Use the name cache to help
  with this.  Cache an "impossible" zero-length name with covered vnodes,
  that points to the root of the file system mounted there.  Use it to cross
  mounts.  When cache_purge() is called on either of the vnodes involved the
  cache entry will disappear.  All of the needed calls for that are already
  in place (vnode reclaim, unmount, etc).

- In lookup_fastforward(), if the the last component has been found and the
  parent directory (searchdir) is not going to be returned, then don't get a
  reference to it.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/kern/vfs_cache.c
cvs rdiff -u -r1.220 -r1.221 src/sys/kern/vfs_lookup.c
cvs rdiff -u -r1.57 -r1.58 src/sys/sys/namei.src

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

Modified files:

Index: src/sys/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.145 src/sys/kern/vfs_cache.c:1.146
--- src/sys/kern/vfs_cache.c:1.145	Sat May 30 18:06:17 2020
+++ src/sys/kern/vfs_cache.c	Sat May 30 20:16:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_cache.c,v 1.145 2020/05/30 18:06:17 ad Exp $	*/
+/*	$NetBSD: vfs_cache.c,v 1.146 2020/05/30 20:16:14 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.145 2020/05/30 18:06:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.146 2020/05/30 20:16:14 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -269,6 +269,15 @@ int cache_stat_interval __read_mostly = 
 static struct	sysctllog *cache_sysctllog;
 
 /*
+ * This is a dummy name that cannot usually occur anywhere in the cache nor
+ * file system.  It's used when caching the root vnode of mounted file
+ * systems.  The name is attached to the directory that the file system is
+ * mounted on.
+ */
+static const char cache_mp_name[] = "";
+static const int cache_mp_nlen = sizeof(cache_mp_name) - 1;
+
+/*
  * Red-black tree stuff.
  */
 static const rb_tree_ops_t cache_rbtree_ops = {
@@ -507,6 +516,8 @@ cache_lookup(struct vnode *dvp, const ch
 	bool hit;
 	krw_t op;
 
+	KASSERT(namelen != cache_mp_nlen || name == cache_mp_name);
+
 	/* Establish default result values */
 	if (iswht_ret != NULL) {
 		*iswht_ret = 0;
@@ -630,6 +641,8 @@ cache_lookup_linked(struct vnode *dvp, c
 	uint64_t key;
 	int error;
 
+	KASSERT(namelen != cache_mp_nlen || name == cache_mp_name);
+
 	/* If disabled, or file system doesn't support this, bail out. */
 	if (__predict_false((dvp->v_mount->mnt_iflag & IMNT_NCLOOKUP) == 0)) {
 		return false;
@@ -714,6 +727,7 @@ cache_lookup_linked(struct vnode *dvp, c
 	}
 	if (ncp->nc_vp == NULL) {
 		/* found negative entry; vn is already null from above */
+		KASSERT(namelen != cache_mp_nlen && name != cache_mp_name);
 		COUNT(ncs_neghits);
 	} else {
 		COUNT(ncs_goodhits); /* XXX can be "badhits" */
@@ -797,6 +811,13 @@ cache_revlookup(struct vnode *vp, struct
 		nlen = ncp->nc_nlen;
 
 		/*
+		 * Ignore mountpoint entries.
+		 */
+		if (ncp->nc_nlen == cache_mp_nlen) {
+			continue;
+		}
+
+		/*
 		 * The queue is partially sorted.  Once we hit dots, nothing
 		 * else remains but dots and dotdots, so bail out.
 		 */
@@ -866,6 +887,8 @@ cache_enter(struct vnode *dvp, struct vn
 	struct namecache *ncp, *oncp;
 	int total;
 
+	KASSERT(namelen != cache_mp_nlen || name == cache_mp_name);
+
 	/* First, check whether we can/should add a cache entry. */
 	if ((cnflags & MAKEENTRY) == 0 ||
 	__predict_false(namelen > cache_maxlen)) {
@@ -1002,6 +1025,49 @@ cache_have_id(struct vnode *vp)
 }
 
 /*
+ * Enter a mount point.  cvp is the covered vnode, and rvp is the root of
+ * the mounted file system.
+ */
+void
+cache_enter_mount(struct vnode *cvp, struct vnode *rvp)
+{
+
+	KASSERT(vrefcnt(cvp) > 0);
+	KASSERT(vrefcnt(rvp) > 0);
+	KASSERT(cvp->v_type == VDIR);
+	KASSERT((rvp->v_vflag & VV_ROOT) != 0);
+
+	if (rvp->v_type == VDIR) {
+		cache_enter(cvp, rvp, cache_mp_name, cache_mp_nlen, MAKEENTRY);
+	}
+}
+
+/*
+ * Look up a cached mount point.  Used in the strongly locked path.
+ */
+bool
+cache_lookup_mount(struct vnode *dvp, struct vnode **vn_ret)
+{
+	bool ret;
+
+	ret = cache_lookup(dvp, cache_mp_name, cache_mp_nlen, LOOKUP,
+	MAKEENTRY, NULL, vn_ret);
+	KASSERT((*vn_ret != NULL) == ret);
+	return ret;
+}
+
+/*
+ * Try to cross a mount point.  For use with cache_lookup_linked().
+ */
+bool
+cache_cross_mount(struct vnode **dvp, krwlock_t **plock)
+{
+
+	return cache_lookup_linked(*dvp, 

CVS commit: src/sys

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 30 20:16:34 UTC 2020

Modified Files:
src/sys/rump/include/rump: rump_namei.h
src/sys/sys: namei.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/rump/include/rump/rump_namei.h
cvs rdiff -u -r1.112 -r1.113 src/sys/sys/namei.h

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

Modified files:

Index: src/sys/rump/include/rump/rump_namei.h
diff -u src/sys/rump/include/rump/rump_namei.h:1.45 src/sys/rump/include/rump/rump_namei.h:1.46
--- src/sys/rump/include/rump/rump_namei.h:1.45	Wed May 27 02:04:38 2020
+++ src/sys/rump/include/rump/rump_namei.h	Sat May 30 20:16:34 2020
@@ -1,11 +1,11 @@
-/*	$NetBSD: rump_namei.h,v 1.45 2020/05/27 02:04:38 rin Exp $	*/
+/*	$NetBSD: rump_namei.h,v 1.46 2020/05/30 20:16:34 ad Exp $	*/
 
 
 /*
  * WARNING: GENERATED FILE.  DO NOT EDIT
  * (edit namei.src and run make namei in src/sys/sys)
  *   by:   NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp 
- *   from: NetBSD: namei.src,v 1.57 2020/05/27 02:03:30 rin Exp 
+ *   from: NetBSD: namei.src,v 1.58 2020/05/30 20:16:14 ad Exp 
  */
 
 #ifndef _RUMP_RUMP_NAMEI_H_

Index: src/sys/sys/namei.h
diff -u src/sys/sys/namei.h:1.112 src/sys/sys/namei.h:1.113
--- src/sys/sys/namei.h:1.112	Wed May 27 02:04:37 2020
+++ src/sys/sys/namei.h	Sat May 30 20:16:34 2020
@@ -1,11 +1,11 @@
-/*	$NetBSD: namei.h,v 1.112 2020/05/27 02:04:37 rin Exp $	*/
+/*	$NetBSD: namei.h,v 1.113 2020/05/30 20:16:34 ad Exp $	*/
 
 
 /*
  * WARNING: GENERATED FILE.  DO NOT EDIT
  * (edit namei.src and run make namei in src/sys/sys)
  *   by:   NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp 
- *   from: NetBSD: namei.src,v 1.57 2020/05/27 02:03:30 rin Exp 
+ *   from: NetBSD: namei.src,v 1.58 2020/05/30 20:16:14 ad Exp 
  */
 
 /*
@@ -308,6 +308,9 @@ bool	cache_have_id(struct vnode *);
 void	cache_vnode_init(struct vnode * );
 void	cache_vnode_fini(struct vnode * );
 void	cache_cpu_init(struct cpu_info *);
+void	cache_enter_mount(struct vnode *, struct vnode *);
+bool	cache_cross_mount(struct vnode **, krwlock_t **);
+bool	cache_lookup_mount(struct vnode *, struct vnode **);
 
 void	nchinit(void);
 void	namecache_count_pass2(void);



CVS commit: src/sys/rump/librump/rumpkern

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 30 19:16:53 UTC 2020

Modified Files:
src/sys/rump/librump/rumpkern: lwproc.c

Log Message:
Fix a lock order reversal that caused hangs.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/rump/librump/rumpkern/lwproc.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/rump/librump/rumpkern/lwproc.c
diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.50 src/sys/rump/librump/rumpkern/lwproc.c:1.51
--- src/sys/rump/librump/rumpkern/lwproc.c:1.50	Sat May 23 23:42:44 2020
+++ src/sys/rump/librump/rumpkern/lwproc.c	Sat May 30 19:16:53 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: lwproc.c,v 1.50 2020/05/23 23:42:44 ad Exp $	*/
+/*  $NetBSD: lwproc.c,v 1.51 2020/05/30 19:16:53 ad Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #define RUMP__CURLWP_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.50 2020/05/23 23:42:44 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.51 2020/05/30 19:16:53 ad Exp $");
 
 #include 
 #include 
@@ -343,12 +343,10 @@ lwproc_freelwp(struct lwp *l)
 
 extern kmutex_t unruntime_lock;
 
-/*
- * called with p_lock held, releases lock before return
- */
-static void
-lwproc_makelwp(struct proc *p, struct lwp *l, bool doswitch, bool procmake)
+static struct lwp *
+lwproc_makelwp(struct proc *p, bool doswitch, bool procmake)
 {
+	struct lwp *l = kmem_zalloc(sizeof(*l), KM_SLEEP);
 
 	/*
 	 * Account the new lwp to the owner of the process.
@@ -365,6 +363,9 @@ lwproc_makelwp(struct proc *p, struct lw
 	l->l_mutex = _lock;
 
 	proc_alloc_lwpid(p, l);
+
+	mutex_enter(p->p_lock);
+	KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
 	LIST_INSERT_HEAD(>p_lwps, l, l_sibling);
 
 	l->l_fd = p->p_fd;
@@ -392,12 +393,13 @@ lwproc_makelwp(struct proc *p, struct lw
 	mutex_enter(_lock);
 	LIST_INSERT_HEAD(, l, l_list);
 	mutex_exit(_lock);
+
+	return l;
 }
 
 struct lwp *
 rump__lwproc_alloclwp(struct proc *p)
 {
-	struct lwp *l;
 	bool newproc = false;
 
 	if (p == NULL) {
@@ -405,13 +407,7 @@ rump__lwproc_alloclwp(struct proc *p)
 		newproc = true;
 	}
 
-	l = kmem_zalloc(sizeof(*l), KM_SLEEP);
-
-	mutex_enter(p->p_lock);
-	KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
-	lwproc_makelwp(p, l, false, newproc);
-
-	return l;
+	return lwproc_makelwp(p, false, newproc);
 }
 
 int
@@ -435,8 +431,12 @@ rump_lwproc_newlwp(pid_t pid)
 		kmem_free(l, sizeof(*l));
 		return EBUSY;
 	}
+	mutex_exit(p->p_lock);
 	mutex_exit(_lock);
-	lwproc_makelwp(p, l, true, false);
+
+	/* XXX what holds proc? */
+
+	lwproc_makelwp(p, true, false);
 
 	return 0;
 }
@@ -445,17 +445,13 @@ int
 rump_lwproc_rfork_vmspace(struct vmspace *vm, int flags)
 {
 	struct proc *p;
-	struct lwp *l;
 
 	if (flags & ~(RUMP_RFFDG|RUMP_RFCFDG) ||
 	(~flags & (RUMP_RFFDG|RUMP_RFCFDG)) == 0)
 		return EINVAL;
 
 	p = lwproc_newproc(curproc, vm, flags);
-	l = kmem_zalloc(sizeof(*l), KM_SLEEP);
-	mutex_enter(p->p_lock);
-	KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
-	lwproc_makelwp(p, l, true, true);
+	lwproc_makelwp(p, true, true);
 
 	return 0;
 }



CVS commit: src/sys/kern

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 30 18:06:17 UTC 2020

Modified Files:
src/sys/kern: vfs_cache.c

Log Message:
cache_lookup_linked():

- If the lookup fails return with the same lock held.  There's no bug here
  because either parent or child's lock is sufficient to prevent both from
  disappearing into thin air, but may as well be correct.

- if FSCRED is passed in then skip the auth check.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/kern/vfs_cache.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/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.144 src/sys/kern/vfs_cache.c:1.145
--- src/sys/kern/vfs_cache.c:1.144	Tue May 26 18:38:37 2020
+++ src/sys/kern/vfs_cache.c	Sat May 30 18:06:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_cache.c,v 1.144 2020/05/26 18:38:37 ad Exp $	*/
+/*	$NetBSD: vfs_cache.c,v 1.145 2020/05/30 18:06:17 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.144 2020/05/26 18:38:37 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.145 2020/05/30 18:06:17 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -626,12 +626,10 @@ cache_lookup_linked(struct vnode *dvp, c
 {
 	vnode_impl_t *dvi = VNODE_TO_VIMPL(dvp);
 	struct namecache *ncp;
+	krwlock_t *oldlock, *newlock;
 	uint64_t key;
 	int error;
 
-	/* Establish default results. */
-	*vn_ret = NULL;
-
 	/* If disabled, or file system doesn't support this, bail out. */
 	if (__predict_false((dvp->v_mount->mnt_iflag & IMNT_NCLOOKUP) == 0)) {
 		return false;
@@ -663,32 +661,42 @@ cache_lookup_linked(struct vnode *dvp, c
 	 * on the lock as child -> parent is the wrong direction.
 	 */
 	if (*plock != >vi_nc_lock) {
+		oldlock = *plock;
+		newlock = >vi_nc_lock;
 		if (!rw_tryenter(>vi_nc_lock, RW_READER)) {
 			return false;
 		}
-		if (*plock != NULL) {
-			rw_exit(*plock);
+	} else {
+		oldlock = NULL;
+		newlock = NULL;
+		if (*plock == NULL) {
+			KASSERT(vrefcnt(dvp) > 0);
 		}
-		*plock = >vi_nc_lock;
-	} else if (*plock == NULL) {
-		KASSERT(vrefcnt(dvp) > 0);
 	}
 
 	/*
 	 * First up check if the user is allowed to look up files in this
 	 * directory.
 	 */
-	if (dvi->vi_nc_mode == VNOVAL) {
-		return false;
-	}
-	KASSERT(dvi->vi_nc_uid != VNOVAL && dvi->vi_nc_gid != VNOVAL);
-	error = kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(VEXEC,
-	dvp->v_type, dvi->vi_nc_mode & ALLPERMS), dvp, NULL,
-	genfs_can_access(dvp, cred, dvi->vi_nc_uid, dvi->vi_nc_gid,
-	dvi->vi_nc_mode & ALLPERMS, NULL, VEXEC));
-	if (error != 0) {
-		COUNT(ncs_denied);
-		return false;
+	if (cred != FSCRED) {
+		if (dvi->vi_nc_mode == VNOVAL) {
+			if (newlock != NULL) {
+rw_exit(newlock);
+			}
+			return false;
+		}
+		KASSERT(dvi->vi_nc_uid != VNOVAL && dvi->vi_nc_gid != VNOVAL);
+		error = kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(VEXEC,
+		dvp->v_type, dvi->vi_nc_mode & ALLPERMS), dvp, NULL,
+		genfs_can_access(dvp, cred, dvi->vi_nc_uid, dvi->vi_nc_gid,
+		dvi->vi_nc_mode & ALLPERMS, NULL, VEXEC));
+		if (error != 0) {
+			if (newlock != NULL) {
+rw_exit(newlock);
+			}
+			COUNT(ncs_denied);
+			return false;
+		}
 	}
 
 	/*
@@ -696,6 +704,9 @@ cache_lookup_linked(struct vnode *dvp, c
 	 */
 	ncp = cache_lookup_entry(dvp, name, namelen, key);
 	if (__predict_false(ncp == NULL)) {
+		if (newlock != NULL) {
+			rw_exit(newlock);
+		}
 		COUNT(ncs_miss);
 		SDT_PROBE(vfs, namecache, lookup, miss, dvp,
 		name, namelen, 0, 0);
@@ -704,11 +715,9 @@ cache_lookup_linked(struct vnode *dvp, c
 	if (ncp->nc_vp == NULL) {
 		/* found negative entry; vn is already null from above */
 		COUNT(ncs_neghits);
-		SDT_PROBE(vfs, namecache, lookup, hit, dvp, name, namelen, 0, 0);
-		return true;
+	} else {
+		COUNT(ncs_goodhits); /* XXX can be "badhits" */
 	}
-
-	COUNT(ncs_goodhits); /* XXX can be "badhits" */
 	SDT_PROBE(vfs, namecache, lookup, hit, dvp, name, namelen, 0, 0);
 
 	/*
@@ -717,6 +726,12 @@ cache_lookup_linked(struct vnode *dvp, c
 	 * looking up the next component, or the caller will release it
 	 * manually when finished.
 	 */
+	if (oldlock) {
+		rw_exit(oldlock);
+	}
+	if (newlock) {
+		*plock = newlock;
+	}	
 	*vn_ret = ncp->nc_vp;
 	return true;
 }



CVS commit: src/sys/arch/x86/x86

2020-05-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri May 29 22:40:16 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Reported-by: syzbot+fd9be59aa613bbf4e...@syzkaller.appspotmail.com
Reported-by: syzbot+15dd4dbac6ed159fa...@syzkaller.appspotmail.com
Reported-by: syzbot+38fa02d3b0e46e57c...@syzkaller.appspotmail.com

pmap_remove_all(): need to drain PV pages only after the PTEs are unmapped,
otherwise there can be a context switch with them mapped in.  XXX amd64
should use the direct map.


To generate a diff of this commit:
cvs rdiff -u -r1.396 -r1.397 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.396 src/sys/arch/x86/x86/pmap.c:1.397
--- src/sys/arch/x86/x86/pmap.c:1.396	Wed May 27 19:33:40 2020
+++ src/sys/arch/x86/x86/pmap.c	Fri May 29 22:40:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.396 2020/05/27 19:33:40 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.397 2020/05/29 22:40:15 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.396 2020/05/27 19:33:40 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.397 2020/05/29 22:40:15 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -3145,7 +3145,6 @@ pmap_zap_ptp(struct pmap *pmap, struct v
 #ifdef DIAGNOSTIC
 	rb_tree_init(tree, _rbtree_ops);
 #endif
-	pmap_drain_pv(pmap);
 #else	/* !XENPV */
 	/*
 	 * XXXAD For XEN, it's not clear to me that we can do this, because
@@ -3216,6 +3215,7 @@ pmap_remove_all(struct pmap *pmap)
 			pmap_free_ptp(pmap, ptps[i], va, ptes, pdes);
 		}
 		pmap_unmap_ptes(pmap, pmap2);
+		pmap_drain_pv(pmap);
 		pmap_tlb_shootdown(pmap, -1L, 0, TLBSHOOT_REMOVE_ALL);
 		mutex_exit(>pm_lock);
 



CVS commit: src/sys/kern

2020-05-28 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu May 28 20:29:18 UTC 2020

Modified Files:
src/sys/kern: kern_cpu.c

Log Message:
At least panic with a useful message if there are too many CPUs.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/kern/kern_cpu.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/kern/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.90 src/sys/kern/kern_cpu.c:1.91
--- src/sys/kern/kern_cpu.c:1.90	Sat May 23 23:42:43 2020
+++ src/sys/kern/kern_cpu.c	Thu May 28 20:29:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_cpu.c,v 1.90 2020/05/23 23:42:43 ad Exp $	*/
+/*	$NetBSD: kern_cpu.c,v 1.91 2020/05/28 20:29:18 ad Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.90 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.91 2020/05/28 20:29:18 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_cpu_ucode.h"
@@ -130,7 +130,8 @@ mi_cpu_attach(struct cpu_info *ci)
 
 	KASSERT(maxcpus > 0);
 
-	ci->ci_index = ncpu;
+	if ((ci->ci_index = ncpu) >= maxcpus)
+		panic("Too many CPUs.  Increase MAXCPUS?");
 	kcpuset_set(kcpuset_attached, cpu_index(ci));
 
 	/*



CVS commit: src/sys/arch/i386/i386

2020-05-28 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu May 28 20:03:19 UTC 2020

Modified Files:
src/sys/arch/i386/i386: cpufunc.S

Log Message:
PR port-i386/55314: i386 no longer boots

Oops, EDI and ESI are callee saved on i386.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/i386/i386/cpufunc.S

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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.44 src/sys/arch/i386/i386/cpufunc.S:1.45
--- src/sys/arch/i386/i386/cpufunc.S:1.44	Wed May 27 20:49:14 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Thu May 28 20:03:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.44 2020/05/27 20:49:14 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.45 2020/05/28 20:03:19 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.44 2020/05/27 20:49:14 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.45 2020/05/28 20:03:19 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -322,11 +322,15 @@ END(outl)
 ENTRY(x86_stos)
 	pushl	%ebp
 	movl	%esp,%ebp
+	pushl	%edi
+	pushl	%esi
 	movl	8(%ebp),%edi
 	movl	12(%ebp),%eax
 	movl	16(%ebp),%ecx
 	rep
 	stosl
+	popl	%esi
+	popl	%edi
 	leave
 	ret
 END(x86_stos)
@@ -334,11 +338,15 @@ END(x86_stos)
 ENTRY(x86_movs)
 	pushl	%ebp
 	movl	%esp,%ebp
+	pushl	%edi
+	pushl	%esi
 	movl	8(%ebp),%edi
 	movl	12(%ebp),%esi
 	movl	16(%ebp),%ecx
 	rep
 	movsl
+	popl	%esi
+	popl	%edi
 	leave
 	ret
 END(x86_movs)



CVS commit: src/sys/arch/i386/i386

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 20:49:14 UTC 2020

Modified Files:
src/sys/arch/i386/i386: cpufunc.S

Log Message:
mismatched END pointed out by maxv@


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/i386/i386/cpufunc.S

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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.43 src/sys/arch/i386/i386/cpufunc.S:1.44
--- src/sys/arch/i386/i386/cpufunc.S:1.43	Wed May 27 19:33:40 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Wed May 27 20:49:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.43 2020/05/27 19:33:40 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.44 2020/05/27 20:49:14 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.43 2020/05/27 19:33:40 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.44 2020/05/27 20:49:14 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -341,4 +341,4 @@ ENTRY(x86_movs)
 	movsl
 	leave
 	ret
-END(x86_stos)
+END(x86_movs)



CVS commit: src/sys/arch/amd64/amd64

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 20:48:43 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S

Log Message:
- mismatched END pointed out by maxv@
- ditch the frame, tracer should be able to deal without it in leaf on x86_64


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/amd64/amd64/cpufunc.S

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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.57 src/sys/arch/amd64/amd64/cpufunc.S:1.58
--- src/sys/arch/amd64/amd64/cpufunc.S:1.57	Wed May 27 19:33:40 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Wed May 27 20:48:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.57 2020/05/27 19:33:40 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.58 2020/05/27 20:48:42 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -422,22 +422,16 @@ ENTRY(outl)
 END(outl)
 
 ENTRY(x86_stos)
-	pushq	%rbp
-	movq	%rsp,%rbp
 	movq	%rsi,%rax
 	movq	%rdx,%rcx
 	rep
 	stosq
-	leave
 	ret
 END(x86_stos)
 
 ENTRY(x86_movs)
-	pushq	%rbp
-	movq	%rsp,%rbp
 	movq	%rdx,%rcx
 	rep
 	movsq
-	leave
 	ret
-END(x86_stos)
+END(x86_movs)



CVS commit: src/sys/arch/x86/x86

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 19:40:30 UTC 2020

Modified Files:
src/sys/arch/x86/x86: svs.c

Log Message:
svs_pdir_switch(): Use MOVS to copy the PTES.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/x86/svs.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/x86/x86/svs.c
diff -u src/sys/arch/x86/x86/svs.c:1.36 src/sys/arch/x86/x86/svs.c:1.37
--- src/sys/arch/x86/x86/svs.c:1.36	Wed May 27 19:15:08 2020
+++ src/sys/arch/x86/x86/svs.c	Wed May 27 19:40:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: svs.c,v 1.36 2020/05/27 19:15:08 ad Exp $	*/
+/*	$NetBSD: svs.c,v 1.37 2020/05/27 19:40:29 ad Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.36 2020/05/27 19:15:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.37 2020/05/27 19:40:29 ad Exp $");
 
 #include "opt_svs.h"
 #include "opt_user_ldt.h"
@@ -682,28 +682,16 @@ svs_lwp_switch(struct lwp *oldlwp, struc
 	}
 }
 
-static inline pt_entry_t
-svs_pte_atomic_read(struct pmap *pmap, size_t idx)
-{
-	/*
-	 * XXX: We don't have a basic atomic_fetch_64 function?
-	 */
-	return atomic_cas_64(>pm_pdir[idx], 666, 666);
-}
-
 /*
- * We may come here with the pmap unlocked. So read its PTEs atomically. If
- * a remote CPU is updating them at the same time, it's not a problem: the
- * remote CPU will call svs_pmap_sync afterwards, and our updirpa will be
- * synchronized properly.
+ * We may come here with the pmap unlocked.  If a remote CPU is updating
+ * them at the same time, it's not a problem: the remote CPU will call
+ * svs_pmap_sync afterwards, and our updirpa will be synchronized properly.
  */
 void
 svs_pdir_switch(struct pmap *pmap)
 {
 	struct cpu_info *ci = curcpu();
 	struct svs_utls *utls;
-	pt_entry_t pte;
-	size_t i;
 
 	KASSERT(kpreempt_disabled());
 	KASSERT(pmap != pmap_kernel());
@@ -712,14 +700,9 @@ svs_pdir_switch(struct pmap *pmap)
 	utls = (struct svs_utls *)ci->ci_svs_utls;
 	utls->kpdirpa = pmap_pdirpa(pmap, 0) | svs_pcid_kcr3;
 
+	/* Copy user slots. */
 	mutex_enter(>ci_svs_mtx);
-
-	/* User slots. */
-	for (i = 0; i < PDIR_SLOT_USERLIM; i++) {
-		pte = svs_pte_atomic_read(pmap, i);
-		ci->ci_svs_updir[i] = pte;
-	}
-
+	x86_movs(ci->ci_svs_updir, pmap->pm_pdir, PDIR_SLOT_USERLIM);
 	mutex_exit(>ci_svs_mtx);
 
 	if (svs_pcid) {



CVS commit: src/sys/arch

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 19:33:40 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S locore.S
src/sys/arch/i386/i386: cpufunc.S locore.S
src/sys/arch/x86/include: pmap.h
src/sys/arch/x86/x86: pmap.c

Log Message:
- Add a couple of wrapper functions around STOS and MOVS and use them to zero
  and copy PTEs in preference to memset()/memcpy().

- Remove related SSE / pageidlezero stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.208 -r1.209 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.184 -r1.185 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.395 -r1.396 src/sys/arch/x86/x86/pmap.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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.56 src/sys/arch/amd64/amd64/cpufunc.S:1.57
--- src/sys/arch/amd64/amd64/cpufunc.S:1.56	Wed May 20 18:52:48 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Wed May 27 19:33:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.56 2020/05/20 18:52:48 maxv Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.57 2020/05/27 19:33:40 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -420,3 +420,24 @@ ENTRY(outl)
 	outl	%eax, %dx
 	ret
 END(outl)
+
+ENTRY(x86_stos)
+	pushq	%rbp
+	movq	%rsp,%rbp
+	movq	%rsi,%rax
+	movq	%rdx,%rcx
+	rep
+	stosq
+	leave
+	ret
+END(x86_stos)
+
+ENTRY(x86_movs)
+	pushq	%rbp
+	movq	%rsp,%rbp
+	movq	%rdx,%rcx
+	rep
+	movsq
+	leave
+	ret
+END(x86_stos)

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.208 src/sys/arch/amd64/amd64/locore.S:1.209
--- src/sys/arch/amd64/amd64/locore.S:1.208	Tue May  5 06:32:43 2020
+++ src/sys/arch/amd64/amd64/locore.S	Wed May 27 19:33:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.208 2020/05/05 06:32:43 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.209 2020/05/27 19:33:40 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1560,61 +1560,6 @@ LABEL(syscall_sysret)
 END(syscall_sysret)
 	TEXT_USER_END
 
-/*
- * bool sse2_idlezero_page(void *pg)
- *
- * Zero a page without polluting the cache.  Preemption must be
- * disabled by the caller. Abort if a preemption is pending.
- * Returns true if the page is zeroed, false if not.
- */
-ENTRY(sse2_idlezero_page)
-	pushq	%rbp
-	movq	%rsp,%rbp
-	movl	$(PAGE_SIZE/64), %ecx
-	xorq	%rax, %rax
-	.align	16
-1:
-	cmpl	$0, CPUVAR(RESCHED)
-	jnz	2f
-	movnti	%rax, 0(%rdi)
-	movnti	%rax, 8(%rdi)
-	movnti	%rax, 16(%rdi)
-	movnti	%rax, 24(%rdi)
-	movnti	%rax, 32(%rdi)
-	movnti	%rax, 40(%rdi)
-	movnti	%rax, 48(%rdi)
-	movnti	%rax, 56(%rdi)
-	addq	$64, %rdi
-	decl	%ecx
-	jnz	1b
-	sfence
-	incl	%eax
-	popq	%rbp
-	KMSAN_INIT_RET(1)
-	ret
-2:
-	sfence
-	popq	%rbp
-	KMSAN_INIT_RET(1)
-	ret
-END(sse2_idlezero_page)
-
-/*
- * void pagezero(vaddr_t va)
- *
- * Zero a page.
- */
-ENTRY(pagezero)
-	pushq	%rbp
-	movq	%rsp,%rbp
-	movq	$(PAGE_SIZE / 8),%rcx
-	xorq	%rax,%rax
-	rep
-	stosq
-	leave
-	ret
-END(pagezero)
-
 	TEXT_USER_BEGIN
 
 /*

Index: src/sys/arch/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.42 src/sys/arch/i386/i386/cpufunc.S:1.43
--- src/sys/arch/i386/i386/cpufunc.S:1.42	Wed May 27 18:47:13 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Wed May 27 19:33:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.42 2020/05/27 18:47:13 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.43 2020/05/27 19:33:40 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.42 2020/05/27 18:47:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.43 2020/05/27 19:33:40 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -318,3 +318,27 @@ ENTRY(outl)
 	outl	%eax, %dx
 	ret
 END(outl)
+
+ENTRY(x86_stos)
+	pushl	%ebp
+	movl	%esp,%ebp
+	movl	8(%ebp),%edi
+	movl	12(%ebp),%eax
+	movl	16(%ebp),%ecx
+	rep
+	stosl
+	leave
+	ret
+END(x86_stos)
+
+ENTRY(x86_movs)
+	pushl	%ebp
+	movl	%esp,%ebp
+	movl	8(%ebp),%edi
+	movl	12(%ebp),%esi
+	movl	16(%ebp),%ecx
+	rep
+	movsl
+	leave
+	ret
+END(x86_stos)

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.184 src/sys/arch/i386/i386/locore.S:1.185
--- src/sys/arch/i386/i386/locore.S:1.184	Tue May  5 09:07:35 2020
+++ src/sys/arch/i386/i386/locore.S	Wed May 27 19:33:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.184 2020/05/05 09:07:35 bouyer Exp $	*/
+/*	$NetBSD: locore.S,v 1.185 2020/05/27 19:33:40 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.184 2020/05/05 09:07:35 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.185 2020/05/27 19:33:40 ad Exp $");
 
 #include "opt_copy_symtab.h"
 

CVS commit: src/sys/arch/x86/x86

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 19:26:43 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Reported-by: syzbot+c1770938bb3fa7c08...@syzkaller.appspotmail.com
Reported-by: syzbot+ae26209c7d7f06e0b...@syzkaller.appspotmail.com

Can't defer freeing PV entries for the kernel's pmap until pmap_update(),
as that means taking locks and potentially recursing, and pmap_update()
for the kernel is used in all sorts of sensitive places.


To generate a diff of this commit:
cvs rdiff -u -r1.394 -r1.395 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.394 src/sys/arch/x86/x86/pmap.c:1.395
--- src/sys/arch/x86/x86/pmap.c:1.394	Tue May 26 10:10:31 2020
+++ src/sys/arch/x86/x86/pmap.c	Wed May 27 19:26:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.394 2020/05/26 10:10:31 bouyer Exp $	*/
+/*	$NetBSD: pmap.c,v 1.395 2020/05/27 19:26:43 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.394 2020/05/26 10:10:31 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.395 2020/05/27 19:26:43 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -494,6 +494,7 @@ static int pmap_pvp_ctor(void *, void *,
 static void pmap_pvp_dtor(void *, void *);
 static struct pv_entry *pmap_alloc_pv(struct pmap *);
 static void pmap_free_pv(struct pmap *, struct pv_entry *);
+static void pmap_drain_pv(struct pmap *);
 
 static void pmap_alloc_level(struct pmap *, vaddr_t, long *);
 
@@ -2073,6 +2074,25 @@ pmap_free_pv(struct pmap *pmap, struct p
 }
 
 /*
+ * pmap_drain_pv: free full PV pages.
+ */
+static void
+pmap_drain_pv(struct pmap *pmap)
+{
+	struct pv_page *pvp;
+
+	KASSERT(mutex_owned(>pm_lock));
+
+	while ((pvp = LIST_FIRST(>pm_pvp_full)) != NULL) {
+		LIST_REMOVE(pvp, pvp_list);
+		KASSERT(pvp->pvp_pmap == pmap);
+		KASSERT(pvp->pvp_nfree == PVE_PER_PVP);
+		pvp->pvp_pmap = NULL;
+		pool_cache_put(_pvp_cache, pvp);
+	}
+}
+
+/*
  * pmap_check_pv: verify {VA, PTP} pair is either tracked/untracked by page
  */
 static void
@@ -2940,12 +2960,13 @@ pmap_destroy(struct pmap *pmap)
 	 * handle any deferred frees.
 	 */
 
+	mutex_enter(>pm_lock);
 	if (pmap->pm_pve != NULL) {
-		mutex_enter(>pm_lock);
 		pmap_free_pv(pmap, pmap->pm_pve);
-		mutex_exit(>pm_lock);
 		pmap->pm_pve = NULL;
 	}
+	pmap_drain_pv(pmap);
+	mutex_exit(>pm_lock);
 	pmap_update(pmap);
 
 	/*
@@ -3088,7 +3109,7 @@ pmap_zap_ptp(struct pmap *pmap, struct v
 			mutex_spin_exit(>pp_lock);
 
 			/*
-			 * pve won't be touched again until pmap_update(),
+			 * pve won't be touched again until pmap_drain_pv(),
 			 * so it's still safe to traverse the tree.
 			 */
 			pmap_free_pv(pmap, pve);
@@ -3123,6 +3144,7 @@ pmap_zap_ptp(struct pmap *pmap, struct v
 #ifdef DIAGNOSTIC
 	rb_tree_init(tree, _rbtree_ops);
 #endif
+	pmap_drain_pv(pmap);
 #else	/* !XENPV */
 	/*
 	 * XXXAD For XEN, it's not clear to me that we can do this, because
@@ -4187,6 +4209,7 @@ pmap_remove_locked(struct pmap *pmap, va
 		}
 	}
 	pmap_unmap_ptes(pmap, pmap2);
+	pmap_drain_pv(pmap);
 }
 
 /*
@@ -4432,6 +4455,7 @@ pmap_pp_remove(struct pmap_page *pp, pad
 			pmap_stats_update_bypte(pmap, 0, opte);
 		}
 		pmap_tlb_shootnow();
+		pmap_drain_pv(pmap);
 		mutex_exit(>pm_lock);
 		if (ptp != NULL) {
 			pmap_destroy(pmap);
@@ -5076,6 +5100,7 @@ same_pa:
 	((opte ^ npte) & (PTE_FRAME | PTE_W)) != 0) {
 		pmap_tlb_shootdown(pmap, va, opte, TLBSHOOT_ENTER);
 	}
+	pmap_drain_pv(pmap);
 	mutex_exit(>pm_lock);
 	return 0;
 }
@@ -5322,6 +5347,7 @@ pmap_enter_gnt(struct pmap *pmap, vaddr_
 		KASSERT(pmap_treelookup_pv(pmap, ptp, tree, va) == NULL);
 	}
 
+	pmap_drain_pv(pmap);
 	mutex_exit(>pm_lock);
 	return op->status;
 }
@@ -5716,10 +5742,8 @@ pmap_dump(struct pmap *pmap, vaddr_t sva
 void
 pmap_update(struct pmap *pmap)
 {
-	struct pv_page *pvp;
 	struct pmap_page *pp;
 	struct vm_page *ptp;
-	uintptr_t sum;
 
 	/*
 	 * Initiate any pending TLB shootdowns.  Wait for them to
@@ -5733,18 +5757,12 @@ pmap_update(struct pmap *pmap)
 	 * Now that shootdowns are complete, process deferred frees.  This
 	 * is an unlocked check, but is safe as we're only interested in
 	 * work done in this LWP - we won't get a false negative.
-	 *
-	 * If pmap_kernel(), this can be called from interrupt context or
-	 * while holding a spinlock so we can't wait on the pmap lock.  No
-	 * big deal as we'll catch up eventually (even for user pmaps, in
-	 * pmap_destroy() when there's never contention on the lock).
-	 */
-	sum = (uintptr_t)atomic_load_relaxed(>pm_gc_ptp.lh_first);
-	sum |= (uintptr_t)atomic_load_relaxed(>pm_pvp_full.lh_first);
-	if (__predict_true(sum == 0 || cpu_intr_p() ||
-	!mutex_tryenter(>pm_lock))) {
+	 */
+	if 

CVS commit: src/sys/arch/x86/x86

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 19:15:08 UTC 2020

Modified Files:
src/sys/arch/x86/x86: svs.c

Log Message:
svs_pmap_sync(): Fast-path the curcpu case.  Could be improved further
with a kcpuset iterator thing.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/x86/svs.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/x86/x86/svs.c
diff -u src/sys/arch/x86/x86/svs.c:1.35 src/sys/arch/x86/x86/svs.c:1.36
--- src/sys/arch/x86/x86/svs.c:1.35	Sat May  2 11:37:17 2020
+++ src/sys/arch/x86/x86/svs.c	Wed May 27 19:15:08 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: svs.c,v 1.35 2020/05/02 11:37:17 maxv Exp $	*/
+/*	$NetBSD: svs.c,v 1.36 2020/05/27 19:15:08 ad Exp $	*/
 
 /*
- * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.35 2020/05/02 11:37:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.36 2020/05/27 19:15:08 ad Exp $");
 
 #include "opt_svs.h"
 #include "opt_user_ldt.h"
@@ -575,6 +575,18 @@ svs_pmap_sync(struct pmap *pmap, int ind
 	KASSERT(kpreempt_disabled());
 	KASSERT(index < PDIR_SLOT_USERLIM);
 
+	ci = curcpu();
+	cid = cpu_index(ci);
+
+	mutex_enter(>ci_svs_mtx);
+	KASSERT(kcpuset_isset(pmap->pm_kernel_cpus, cid));
+	ci->ci_svs_updir[index] = pmap->pm_pdir[index];
+	mutex_exit(>ci_svs_mtx);
+
+	if (!kcpuset_isotherset(pmap->pm_kernel_cpus, cid)) {
+		return;
+	}
+
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		cid = cpu_index(ci);
 



CVS commit: src/sys/arch/i386/i386

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 18:47:13 UTC 2020

Modified Files:
src/sys/arch/i386/i386: cpufunc.S

Log Message:
tsc_get_timecount(): fix 64-bit return


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/i386/i386/cpufunc.S

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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.41 src/sys/arch/i386/i386/cpufunc.S:1.42
--- src/sys/arch/i386/i386/cpufunc.S:1.41	Tue May 19 21:40:55 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Wed May 27 18:47:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.42 2020/05/27 18:47:13 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.42 2020/05/27 18:47:13 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -164,19 +164,19 @@ ENTRY(msr_onfault)
 END(msr_onfault)
 
 ENTRY(tsc_get_timecount)
+	pushl	%ebx
 	movl	CPUVAR(CURLWP), %ecx
 1:
-	pushl	L_NCSW(%ecx)
+	movl	L_NCSW(%ecx), %ebx
 	rdtsc
 	addl	CPUVAR(CC_SKEW), %eax
 	adcl	CPUVAR(CC_SKEW+4), %edx
-	popl	%edx
-	cmpl	%edx, L_NCSW(%ecx)
+	cmpl	%ebx, L_NCSW(%ecx)
 	jne	2f
+	popl	%ebx
 	ret
 2:
 	jmp	1b
-	ret
 END(tsc_get_timecount)
 
 STRONG_ALIAS(cpu_counter, tsc_get_timecount)



CVS commit: src/sys/arch/x86/x86

2020-05-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 27 18:46:15 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
tsc_delay(): use tsc_freq in preference to cpu_frequency().


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/x86/tsc.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/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.47 src/sys/arch/x86/x86/tsc.c:1.48
--- src/sys/arch/x86/x86/tsc.c:1.47	Wed May 20 20:19:02 2020
+++ src/sys/arch/x86/x86/tsc.c	Wed May 27 18:46:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.47 2020/05/20 20:19:02 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.48 2020/05/27 18:46:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.47 2020/05/20 20:19:02 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.48 2020/05/27 18:46:15 ad Exp $");
 
 #include 
 #include 
@@ -55,7 +55,7 @@ u_int	tsc_get_timecount(struct timecount
 static void	tsc_delay(unsigned int);
 
 static uint64_t	tsc_dummy_cacheline __cacheline_aligned;
-uint64_t	tsc_freq; /* exported for sysctl */
+uint64_t	tsc_freq __read_mostly;	/* exported for sysctl */
 static int64_t	tsc_drift_max = 1000;	/* max cycles */
 static int64_t	tsc_drift_observed;
 
@@ -346,7 +346,7 @@ tsc_delay(unsigned int us)
 	uint64_t start, delta;
 
 	start = cpu_counter();
-	delta = (uint64_t)us * cpu_frequency(_info_primary) / 100;
+	delta = (uint64_t)us * tsc_freq / 100;
 
 	while ((cpu_counter() - start) < delta) {
 		x86_pause();



CVS commit: src/sys

2020-05-26 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 26 22:06:12 UTC 2020

Modified Files:
src/sys/rump/include/rump: rump_namei.h
src/sys/sys: namei.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/rump/include/rump/rump_namei.h
cvs rdiff -u -r1.110 -r1.111 src/sys/sys/namei.h

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

Modified files:

Index: src/sys/rump/include/rump/rump_namei.h
diff -u src/sys/rump/include/rump/rump_namei.h:1.43 src/sys/rump/include/rump/rump_namei.h:1.44
--- src/sys/rump/include/rump/rump_namei.h:1.43	Tue May 12 23:18:03 2020
+++ src/sys/rump/include/rump/rump_namei.h	Tue May 26 22:06:11 2020
@@ -1,11 +1,11 @@
-/*	$NetBSD: rump_namei.h,v 1.43 2020/05/12 23:18:03 ad Exp $	*/
+/*	$NetBSD: rump_namei.h,v 1.44 2020/05/26 22:06:11 ad Exp $	*/
 
 
 /*
  * WARNING: GENERATED FILE.  DO NOT EDIT
  * (edit namei.src and run make namei in src/sys/sys)
  *   by:   NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp 
- *   from: NetBSD: namei.src,v 1.54 2020/05/12 23:17:41 ad Exp 
+ *   from: NetBSD: namei.src,v 1.56 2020/05/26 22:05:52 ad Exp 
  */
 
 #ifndef _RUMP_RUMP_NAMEI_H_
@@ -35,6 +35,6 @@
 #define RUMP_NAMEI_DOWHITEOUT	0x004
 #define RUMP_NAMEI_REQUIREDIR	0x008
 #define RUMP_NAMEI_CREATEDIR	0x020
-#define RUMP_NAMEI_PARAMASK	0x02ef800
+#define RUMP_NAMEI_PARAMASK	0x02ff800
 
 #endif /* _RUMP_RUMP_NAMEI_H_ */

Index: src/sys/sys/namei.h
diff -u src/sys/sys/namei.h:1.110 src/sys/sys/namei.h:1.111
--- src/sys/sys/namei.h:1.110	Sat May 16 18:31:53 2020
+++ src/sys/sys/namei.h	Tue May 26 22:06:11 2020
@@ -1,11 +1,11 @@
-/*	$NetBSD: namei.h,v 1.110 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: namei.h,v 1.111 2020/05/26 22:06:11 ad Exp $	*/
 
 
 /*
  * WARNING: GENERATED FILE.  DO NOT EDIT
  * (edit namei.src and run make namei in src/sys/sys)
  *   by:   NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp 
- *   from: NetBSD: namei.src,v 1.54 2020/05/12 23:17:41 ad Exp 
+ *   from: NetBSD: namei.src,v 1.56 2020/05/26 22:05:52 ad Exp 
  */
 
 /*
@@ -171,7 +171,7 @@ struct nameidata {
 #define	ISDOTDOT	0x0002000	/* current component name is .. */
 #define	MAKEENTRY	0x0004000	/* entry is to be added to name cache */
 #define	ISLASTCN	0x0008000	/* this is last component of pathname */
-#define	WILLBEDIR	0x001	/* new files will be dirs; */
+NAMIEFL	WILLBEDIR	0x001	/* new files will be dirs */
 #define	ISWHITEOUT	0x002	/* found whiteout */
 #define	DOWHITEOUT	0x004	/* do whiteouts */
 #define	REQUIREDIR	0x008	/* must be a directory */
@@ -371,6 +371,6 @@ struct	nchstats _NAMEI_CACHE_STATS(uint6
 #define NAMEI_DOWHITEOUT	0x004
 #define NAMEI_REQUIREDIR	0x008
 #define NAMEI_CREATEDIR	0x020
-#define NAMEI_PARAMASK	0x02ef800
+#define NAMEI_PARAMASK	0x02ff800
 
 #endif /* !_SYS_NAMEI_H_ */



CVS commit: src/sys/sys

2020-05-26 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 26 22:05:52 UTC 2020

Modified Files:
src/sys/sys: namei.src

Log Message:
Catch up after recent ACL changes


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/sys/namei.src

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

Modified files:

Index: src/sys/sys/namei.src
diff -u src/sys/sys/namei.src:1.55 src/sys/sys/namei.src:1.56
--- src/sys/sys/namei.src:1.55	Sat May 16 18:31:53 2020
+++ src/sys/sys/namei.src	Tue May 26 22:05:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: namei.src,v 1.55 2020/05/16 18:31:53 christos Exp $	*/
+/*	$NetBSD: namei.src,v 1.56 2020/05/26 22:05:52 ad Exp $	*/
 
 /*
  * Copyright (c) 1985, 1989, 1991, 1993
@@ -163,11 +163,12 @@ NAMEIFL	RDONLY		0x0001000	/* lookup with
 NAMEIFL	ISDOTDOT	0x0002000	/* current component name is .. */
 NAMEIFL	MAKEENTRY	0x0004000	/* entry is to be added to name cache */
 NAMEIFL	ISLASTCN	0x0008000	/* this is last component of pathname */
+NAMIEFL	WILLBEDIR	0x001	/* new files will be dirs */
 NAMEIFL	ISWHITEOUT	0x002	/* found whiteout */
 NAMEIFL	DOWHITEOUT	0x004	/* do whiteouts */
 NAMEIFL	REQUIREDIR	0x008	/* must be a directory */
 NAMEIFL	CREATEDIR	0x020	/* trailing slashes are ok */
-NAMEIFL	PARAMASK	0x02ef800	/* mask of parameter descriptors */
+NAMEIFL	PARAMASK	0x02ff800	/* mask of parameter descriptors */
 
 /*
  * Initialization of a nameidata structure.
@@ -290,7 +291,7 @@ bool	cache_lookup_raw(struct vnode *, co
 bool	cache_lookup_linked(struct vnode *, const char *, size_t,
 			struct vnode **, krwlock_t **, kauth_cred_t);
 int	cache_revlookup(struct vnode *, struct vnode **, char **, char *,
-			bool, int);
+			bool, accmode_t);
 int	cache_diraccess(struct vnode *, int);
 void	cache_enter(struct vnode *, struct vnode *,
 			const char *, size_t, uint32_t);



CVS commit: src/sys/uvm

2020-05-26 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 26 21:52:12 UTC 2020

Modified Files:
src/sys/uvm: uvm_page_array.c

Log Message:
uvm_page_array_fill(): return ENOENT in all cases when nothing's left.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/uvm/uvm_page_array.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/uvm/uvm_page_array.c
diff -u src/sys/uvm/uvm_page_array.c:1.8 src/sys/uvm/uvm_page_array.c:1.9
--- src/sys/uvm/uvm_page_array.c:1.8	Mon May 25 22:01:26 2020
+++ src/sys/uvm/uvm_page_array.c	Tue May 26 21:52:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page_array.c,v 1.8 2020/05/25 22:01:26 ad Exp $	*/
+/*	$NetBSD: uvm_page_array.c,v 1.9 2020/05/26 21:52:12 ad Exp $	*/
 
 /*-
  * Copyright (c)2011 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.8 2020/05/25 22:01:26 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.9 2020/05/26 21:52:12 ad Exp $");
 
 #include 
 #include 
@@ -140,6 +140,7 @@ uvm_page_array_fill(struct uvm_page_arra
 	const int flags = ar->ar_flags;
 	const bool dense = (flags & UVM_PAGE_ARRAY_FILL_DENSE) != 0;
 	const bool backward = (flags & UVM_PAGE_ARRAY_FILL_BACKWARD) != 0;
+	int error = 0;
 
 	if (nwant != 0 && nwant < maxpages) {
 		maxpages = nwant;
@@ -172,8 +173,7 @@ uvm_page_array_fill(struct uvm_page_arra
 			 * if dense or looking for tagged entries (or
 			 * working backwards), fail right away.
 			 */
-			uvm_page_array_clear(ar);
-			return ENOENT;
+			npages = 0;
 		} else {
 			/*
 			 * there's nothing else to be found with the current
@@ -187,17 +187,16 @@ uvm_page_array_fill(struct uvm_page_arra
 			npages = 1;
 			ar->ar_pages[0] = NULL;
 		}
+		error = ENOENT;
 	}
 	KASSERT(npages <= maxpages);
 	ar->ar_npages = npages;
 	ar->ar_idx = 0;
 #if defined(DEBUG)
-	for (i = 0; i < ar->ar_npages; i++) {
+	for (i = 0; error == 0 && i < ar->ar_npages; i++) {
 		struct vm_page * const pg = ar->ar_pages[i];
 
-		if (pg == NULL) {
-			continue;
-		}
+		KASSERT(pg != NULL);
 		KDASSERT(pg->uobject == uobj);
 		if (backward) {
 			KDASSERT(pg->offset <= off);
@@ -210,7 +209,7 @@ uvm_page_array_fill(struct uvm_page_arra
 		}
 	}
 #endif /* defined(DEBUG) */
-	return 0;
+	return error;
 }
 
 /*



CVS commit: src/sys/kern

2020-05-26 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 26 18:38:37 UTC 2020

Modified Files:
src/sys/kern: vfs_cache.c vfs_lookup.c vfs_subr.c vfs_vnode.c

Log Message:
Make vcache_tryvget() lockless.  Reviewed by hannken@.


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/kern/vfs_cache.c
cvs rdiff -u -r1.219 -r1.220 src/sys/kern/vfs_lookup.c
cvs rdiff -u -r1.487 -r1.488 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.122 -r1.123 src/sys/kern/vfs_vnode.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/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.143 src/sys/kern/vfs_cache.c:1.144
--- src/sys/kern/vfs_cache.c:1.143	Sat May 16 18:31:50 2020
+++ src/sys/kern/vfs_cache.c	Tue May 26 18:38:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_cache.c,v 1.143 2020/05/16 18:31:50 christos Exp $	*/
+/*	$NetBSD: vfs_cache.c,v 1.144 2020/05/26 18:38:37 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.143 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.144 2020/05/26 18:38:37 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -582,13 +582,8 @@ cache_lookup(struct vnode *dvp, const ch
 		return hit;
 	}
 	vp = ncp->nc_vp;
-	mutex_enter(vp->v_interlock);
-	rw_exit(>vi_nc_lock);
-
-	/*
-	 * Unlocked except for the vnode interlock.  Call vcache_tryvget().
-	 */
 	error = vcache_tryvget(vp);
+	rw_exit(>vi_nc_lock);
 	if (error) {
 		KASSERT(error == EBUSY);
 		/*
@@ -821,9 +816,8 @@ cache_revlookup(struct vnode *vp, struct
 		}
 
 		dvp = ncp->nc_dvp;
-		mutex_enter(dvp->v_interlock);
-		rw_exit(>vi_nc_listlock);
 		error = vcache_tryvget(dvp);
+		rw_exit(>vi_nc_listlock);
 		if (error) {
 			KASSERT(error == EBUSY);
 			if (bufp)

Index: src/sys/kern/vfs_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.219 src/sys/kern/vfs_lookup.c:1.220
--- src/sys/kern/vfs_lookup.c:1.219	Wed Apr 22 21:35:52 2020
+++ src/sys/kern/vfs_lookup.c	Tue May 26 18:38:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.219 2020/04/22 21:35:52 ad Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.220 2020/05/26 18:38:37 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.219 2020/04/22 21:35:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.220 2020/05/26 18:38:37 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -1354,9 +1354,7 @@ lookup_fastforward(struct namei_state *s
 		foundobj->v_type != VDIR ||
 		(foundobj->v_type == VDIR &&
 		foundobj->v_mountedhere != NULL)) {
-			mutex_enter(foundobj->v_interlock);
 			error = vcache_tryvget(foundobj);
-			/* v_interlock now unheld */
 			if (error != 0) {
 foundobj = NULL;
 error = EOPNOTSUPP;
@@ -1381,9 +1379,7 @@ lookup_fastforward(struct namei_state *s
 	 * let lookup_once() take care of it.
 	 */
 	if (searchdir != *searchdir_ret) {
-		mutex_enter(searchdir->v_interlock);
 		error2 = vcache_tryvget(searchdir);
-		/* v_interlock now unheld */
 		KASSERT(plock != NULL);
 		rw_exit(plock);
 		if (__predict_true(error2 == 0)) {

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.487 src/sys/kern/vfs_subr.c:1.488
--- src/sys/kern/vfs_subr.c:1.487	Sat May 16 18:31:50 2020
+++ src/sys/kern/vfs_subr.c	Tue May 26 18:38:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.487 2020/05/16 18:31:50 christos Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.488 2020/05/26 18:38:37 ad Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008, 2019, 2020
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.487 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.488 2020/05/26 18:38:37 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -730,18 +730,15 @@ lazy_sync_vnode(struct vnode *vp)
 	KASSERT(mutex_owned(_data_lock));
 
 	synced = false;
-	/* We are locking in the wrong direction. */
-	if (mutex_tryenter(vp->v_interlock)) {
+	if (vcache_tryvget(vp) == 0) {
 		mutex_exit(_data_lock);
-		if (vcache_tryvget(vp) == 0) {
-			if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) {
-synced = true;
-(void) VOP_FSYNC(vp, curlwp->l_cred,
-FSYNC_LAZY, 0, 0);
-vput(vp);
-			} else
-vrele(vp);
-		}
+		if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) {
+			synced = true;
+			(void) VOP_FSYNC(vp, curlwp->l_cred,
+			FSYNC_LAZY, 0, 0);
+			vput(vp);
+		} else
+			vrele(vp);
 		mutex_enter(_data_lock);
 	}
 	return synced;

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.122 src/sys/kern/vfs_vnode.c:1.123
--- src/sys/kern/vfs_vnode.c:1.122	Mon May 18 08:27:54 2020
+++ src/sys/kern/vfs_vnode.c	Tue May 26 18:38:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.122 2020/05/18 08:27:54 hannken Exp $	*/

CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 22:04:51 UTC 2020

Modified Files:
src/sys/uvm: uvm_aobj.c

Log Message:
uao_get(): in the PGO_SYNCIO case use uvm_page_array and simplify control
flow a little bit.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/uvm/uvm_aobj.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/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.146 src/sys/uvm/uvm_aobj.c:1.147
--- src/sys/uvm/uvm_aobj.c:1.146	Mon May 25 21:15:10 2020
+++ src/sys/uvm/uvm_aobj.c	Mon May 25 22:04:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.146 2020/05/25 21:15:10 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.147 2020/05/25 22:04:51 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.146 2020/05/25 21:15:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.147 2020/05/25 22:04:51 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -799,10 +799,11 @@ uao_get(struct uvm_object *uobj, voff_t 
 int *npagesp, int centeridx, vm_prot_t access_type, int advice, int flags)
 {
 	voff_t current_offset;
-	struct vm_page *ptmp = NULL;	/* Quell compiler warning */
-	int lcv, gotpages, maxpages, swslot = -1, pageidx = -1; /* XXX: gcc */
+	struct vm_page *ptmp;
+	int lcv, gotpages, maxpages, swslot, pageidx;
 	UVMHIST_FUNC("uao_get"); UVMHIST_CALLED(pdhist);
 	bool overwrite = ((flags & PGO_OVERWRITE) != 0);
+	struct uvm_page_array a;
 
 	UVMHIST_LOG(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
 		(uintptr_t)uobj, offset, flags,0);
@@ -828,7 +829,6 @@ uao_get(struct uvm_object *uobj, voff_t 
  	 */
 
 	if (flags & PGO_LOCKED) {
-		struct uvm_page_array a;
 
 		/*
  		 * step 1a: get pages that are already resident.   only do
@@ -890,8 +890,8 @@ uao_get(struct uvm_object *uobj, voff_t 
 		goto done;
 	}
 
-	for (lcv = 0, current_offset = offset ; lcv < maxpages ;
-	lcv++, current_offset += PAGE_SIZE) {
+	uvm_page_array_init(, uobj, 0);
+	for (lcv = 0, current_offset = offset ; lcv < maxpages ;) {
 
 		/*
  		 * we have yet to locate the current page (pps[lcv]).   we
@@ -900,48 +900,14 @@ uao_get(struct uvm_object *uobj, voff_t 
 		 * released.  if that is the case, then we sleep on the page
 		 * until it is no longer busy or released and repeat the lookup.
 		 * if the page we found is neither busy nor released, then we
-		 * busy it (so we own it) and plug it into pps[lcv].   this
-		 * 'break's the following while loop and indicates we are
-		 * ready to move on to the next page in the "lcv" loop above.
- 		 *
- 		 * if we exit the while loop with pps[lcv] set to NULL,
-		 * then it means that we allocated a new busy/fake/clean page
-		 * ptmp in the object and we need to do I/O to fill in the data.
+		 * busy it (so we own it) and plug it into pps[lcv].   we are
+		 * ready to move on to the next page.
  		 */
 
-		/* top of "pps" while loop */
-		for (;;) {
-			/* look for a resident page */
-			ptmp = uvm_pagelookup(uobj, current_offset);
-
-			/* not resident?   allocate one now (if we can) */
-			if (ptmp == NULL) {
-/* get a zeroed page if not in swap */
-pageidx = current_offset >> PAGE_SHIFT;
-swslot = uao_find_swslot(uobj, pageidx);
-ptmp = uao_pagealloc(uobj, current_offset,
-swslot != 0 || overwrite ? 0 :
-UVM_PGA_ZERO);
-
-/* out of RAM? */
-if (ptmp == NULL) {
-	rw_exit(uobj->vmobjlock);
-	UVMHIST_LOG(pdhist,
-	"sleeping, ptmp == NULL\n",0,0,0,0);
-	uvm_wait("uao_getpage");
-	rw_enter(uobj->vmobjlock, RW_WRITER);
-	continue;
-}
-
-/*
- * got new page ready for I/O.  break pps for
- * loop.
- */
-
-pps[lcv] = NULL;
-break;
-			}
+		ptmp = uvm_page_array_fill_and_peek(, current_offset,
+		maxpages - lcv);
 
+		if (ptmp != NULL && ptmp->offset == current_offset) {
 			/* page is there, see if we need to wait on it */
 			if ((ptmp->flags & PG_BUSY) != 0) {
 UVMHIST_LOG(pdhist,
@@ -949,14 +915,15 @@ uao_get(struct uvm_object *uobj, voff_t 
 ptmp->flags,0,0,0);
 uvm_pagewait(ptmp, uobj->vmobjlock, "uao_get");
 rw_enter(uobj->vmobjlock, RW_WRITER);
+uvm_page_array_clear();
 continue;
 			}
 
 			/*
- 			 * if we get here then the page has become resident and
-			 * unbusy between steps 1 and 2.  we busy it now (so we
-			 * own it) and set pps[lcv] (so that we exit the while
-			 * loop).
+ 			 * if we get here then the page is resident and
+			 * unbusy.  we busy it now (so we own it).  if
+			 * overwriting, mark the page dirty up front as
+			 * it will be zapped via an unmanaged mapping.
  			 */
 
 			KASSERT(uvm_pagegetdirty(ptmp) !=
@@ -967,17 +934,35 @@ uao_get(struct uvm_object *uobj, voff_t 
 			/* we own it, caller must un-busy */
 			ptmp->flags |= PG_BUSY;
 			UVM_PAGE_OWN(ptmp, 

CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 22:01:27 UTC 2020

Modified Files:
src/sys/uvm: uvm_page_array.c

Log Message:
Make previous work as intended.  Bad programmer.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/uvm/uvm_page_array.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/uvm/uvm_page_array.c
diff -u src/sys/uvm/uvm_page_array.c:1.7 src/sys/uvm/uvm_page_array.c:1.8
--- src/sys/uvm/uvm_page_array.c:1.7	Mon May 25 21:22:40 2020
+++ src/sys/uvm/uvm_page_array.c	Mon May 25 22:01:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page_array.c,v 1.7 2020/05/25 21:22:40 ad Exp $	*/
+/*	$NetBSD: uvm_page_array.c,v 1.8 2020/05/25 22:01:26 ad Exp $	*/
 
 /*-
  * Copyright (c)2011 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.7 2020/05/25 21:22:40 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.8 2020/05/25 22:01:26 ad Exp $");
 
 #include 
 #include 
@@ -180,12 +180,12 @@ uvm_page_array_fill(struct uvm_page_arra
 			 * set of arguments, in the current version of the
 			 * tree.
 			 *
-			 * minimize repeated tree lookups by "finding" some
-			 * null pointers, in case the caller keeps looping
-			 * (a common use case).
+			 * minimize repeated tree lookups by "finding" a
+			 * null pointer, in case the caller keeps looping (a
+			 * common use case).
 			 */
-			npages = maxpages;
-			memset(ar->ar_pages, 0, sizeof(ar->ar_pages[0]) * npages);
+			npages = 1;
+			ar->ar_pages[0] = NULL;
 		}
 	}
 	KASSERT(npages <= maxpages);
@@ -220,20 +220,17 @@ uvm_page_array_fill(struct uvm_page_arra
  */
 
 struct vm_page *
-uvm_page_array_fill_and_peek(struct uvm_page_array *a, voff_t off,
+uvm_page_array_fill_and_peek(struct uvm_page_array *ar, voff_t off,
 unsigned int nwant)
 {
-	struct vm_page *pg;
 	int error;
 
-	pg = uvm_page_array_peek(a);
-	if (pg != NULL) {
-		return pg;
+	if (ar->ar_idx != ar->ar_npages) {
+		return ar->ar_pages[ar->ar_idx];
 	}
-	error = uvm_page_array_fill(a, off, nwant);
+	error = uvm_page_array_fill(ar, off, nwant);
 	if (error != 0) {
 		return NULL;
 	}
-	pg = uvm_page_array_peek(a);
-	return pg;
+	return uvm_page_array_peek(ar);
 }



CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 21:22:40 UTC 2020

Modified Files:
src/sys/uvm: uvm_page_array.c

Log Message:
Minor correction to previous.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/uvm/uvm_page_array.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/uvm/uvm_page_array.c
diff -u src/sys/uvm/uvm_page_array.c:1.6 src/sys/uvm/uvm_page_array.c:1.7
--- src/sys/uvm/uvm_page_array.c:1.6	Mon May 25 21:15:10 2020
+++ src/sys/uvm/uvm_page_array.c	Mon May 25 21:22:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page_array.c,v 1.6 2020/05/25 21:15:10 ad Exp $	*/
+/*	$NetBSD: uvm_page_array.c,v 1.7 2020/05/25 21:22:40 ad Exp $	*/
 
 /*-
  * Copyright (c)2011 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.6 2020/05/25 21:15:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.7 2020/05/25 21:22:40 ad Exp $");
 
 #include 
 #include 
@@ -195,10 +195,9 @@ uvm_page_array_fill(struct uvm_page_arra
 	for (i = 0; i < ar->ar_npages; i++) {
 		struct vm_page * const pg = ar->ar_pages[i];
 
-		if (!dense && pg == NULL) {
+		if (pg == NULL) {
 			continue;
 		}
-		KDASSERT(pg != NULL);
 		KDASSERT(pg->uobject == uobj);
 		if (backward) {
 			KDASSERT(pg->offset <= off);



CVS commit: src/sys

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 21:15:10 UTC 2020

Modified Files:
src/sys/arch/hppa/hppa: pmap.c
src/sys/miscfs/genfs: genfs_io.c
src/sys/nfs: nfs_subs.c
src/sys/uvm: uvm_aobj.c uvm_object.c uvm_page_array.c uvm_page_array.h
uvm_vnode.c

Log Message:
- Alter the convention for uvm_page_array slightly, so the basic search
  parameters can't change part way through a search: move the "uobj" and
  "flags" arguments over to uvm_page_array_init() and store those with the
  array.

- With that, detect when it's not possible to find any more pages in the
  tree with the given search parameters, and avoid repeated tree lookups if
  the caller loops over uvm_page_array_fill_and_peek().


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/hppa/hppa/pmap.c
cvs rdiff -u -r1.96 -r1.97 src/sys/miscfs/genfs/genfs_io.c
cvs rdiff -u -r1.239 -r1.240 src/sys/nfs/nfs_subs.c
cvs rdiff -u -r1.145 -r1.146 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.22 -r1.23 src/sys/uvm/uvm_object.c
cvs rdiff -u -r1.5 -r1.6 src/sys/uvm/uvm_page_array.c
cvs rdiff -u -r1.2 -r1.3 src/sys/uvm/uvm_page_array.h
cvs rdiff -u -r1.113 -r1.114 src/sys/uvm/uvm_vnode.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/hppa/hppa/pmap.c
diff -u src/sys/arch/hppa/hppa/pmap.c:1.112 src/sys/arch/hppa/hppa/pmap.c:1.113
--- src/sys/arch/hppa/hppa/pmap.c:1.112	Thu Apr 30 06:16:47 2020
+++ src/sys/arch/hppa/hppa/pmap.c	Mon May 25 21:15:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.112 2020/04/30 06:16:47 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.113 2020/05/25 21:15:10 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2020 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.112 2020/04/30 06:16:47 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.113 2020/05/25 21:15:10 ad Exp $");
 
 #include "opt_cputype.h"
 
@@ -1253,11 +1253,10 @@ pmap_destroy(pmap_t pmap)
 		return;
 
 #ifdef DIAGNOSTIC
-	uvm_page_array_init();
+	uvm_page_array_init(, >pm_obj, 0);
 	off = 0;
 	rw_enter(pmap->pm_lock, RW_WRITER);
-	while ((pg = uvm_page_array_fill_and_peek(, >pm_obj, off, 0, 0))
-	!= NULL) {
+	while ((pg = uvm_page_array_fill_and_peek(, off, 0)) != NULL) {
 		pt_entry_t *pde, *epde;
 		struct vm_page *spg;
 		struct pv_entry *pv, *npv;

Index: src/sys/miscfs/genfs/genfs_io.c
diff -u src/sys/miscfs/genfs/genfs_io.c:1.96 src/sys/miscfs/genfs/genfs_io.c:1.97
--- src/sys/miscfs/genfs/genfs_io.c:1.96	Sun May 17 19:38:16 2020
+++ src/sys/miscfs/genfs/genfs_io.c	Mon May 25 21:15:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_io.c,v 1.96 2020/05/17 19:38:16 ad Exp $	*/
+/*	$NetBSD: genfs_io.c,v 1.97 2020/05/25 21:15:10 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.96 2020/05/17 19:38:16 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.97 2020/05/25 21:15:10 ad Exp $");
 
 #include 
 #include 
@@ -1005,7 +1005,8 @@ retry:
 
 	cleanall = true;
 	freeflag = pagedaemon ? PG_PAGEOUT : PG_RELEASED;
-	uvm_page_array_init();
+	uvm_page_array_init(, uobj, dirtyonly ? (UVM_PAGE_ARRAY_FILL_DIRTY |
+	(!async ? UVM_PAGE_ARRAY_FILL_WRITEBACK : 0)) : 0);
 	for (;;) {
 		bool pgprotected;
 
@@ -1017,9 +1018,7 @@ retry:
 		 * wait on pages being written back by other threads as well.
 		 */
 
-		pg = uvm_page_array_fill_and_peek(, uobj, nextoff, 0,
-		dirtyonly ? (UVM_PAGE_ARRAY_FILL_DIRTY |
-		(!async ? UVM_PAGE_ARRAY_FILL_WRITEBACK : 0)) : 0);
+		pg = uvm_page_array_fill_and_peek(, nextoff, 0);
 		if (pg == NULL) {
 			break;
 		}

Index: src/sys/nfs/nfs_subs.c
diff -u src/sys/nfs/nfs_subs.c:1.239 src/sys/nfs/nfs_subs.c:1.240
--- src/sys/nfs/nfs_subs.c:1.239	Sat Apr  4 07:07:20 2020
+++ src/sys/nfs/nfs_subs.c	Mon May 25 21:15:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_subs.c,v 1.239 2020/04/04 07:07:20 mlelstv Exp $	*/
+/*	$NetBSD: nfs_subs.c,v 1.240 2020/05/25 21:15:10 ad Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.239 2020/04/04 07:07:20 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.240 2020/05/25 21:15:10 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_nfs.h"
@@ -1798,10 +1798,10 @@ nfs_clearcommit(struct mount *mp)
 		np->n_pushedhi = 0;
 		np->n_commitflags &=
 		~(NFS_COMMIT_PUSH_VALID | NFS_COMMIT_PUSHED_VALID);
-		uvm_page_array_init();
+		uvm_page_array_init(, >v_uobj, 0);
 		off = 0;
-		while ((pg = uvm_page_array_fill_and_peek(, >v_uobj, off,
-		0, 0)) != NULL) {
+		while ((pg = uvm_page_array_fill_and_peek(, off, 0)) !=
+		NULL) {
 			pg->flags &= ~PG_NEEDCOMMIT;
 			uvm_page_array_advance();
 			off = pg->offset + PAGE_SIZE;

Index: src/sys/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.145 

CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 20:13:00 UTC 2020

Modified Files:
src/sys/uvm: uvm_aobj.c

Log Message:
PR kern/55300: ubciomove triggers page not dirty assertion

If overwriting an existing page, mark it dirty since there may be no
managed mapping to track the modification.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/uvm/uvm_aobj.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/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.144 src/sys/uvm/uvm_aobj.c:1.145
--- src/sys/uvm/uvm_aobj.c:1.144	Fri May 22 19:02:59 2020
+++ src/sys/uvm/uvm_aobj.c	Mon May 25 20:13:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.144 2020/05/22 19:02:59 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.145 2020/05/25 20:13:00 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.144 2020/05/22 19:02:59 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.145 2020/05/25 20:13:00 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -963,6 +963,9 @@ uao_get(struct uvm_object *uobj, voff_t 
 
 			KASSERT(uvm_pagegetdirty(ptmp) !=
 			UVM_PAGE_STATUS_CLEAN);
+			if (overwrite) {
+uvm_pagemarkdirty(ptmp, UVM_PAGE_STATUS_DIRTY);
+			}
 			/* we own it, caller must un-busy */
 			ptmp->flags |= PG_BUSY;
 			UVM_PAGE_OWN(ptmp, "uao_get2");



CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 19:46:20 UTC 2020

Modified Files:
src/sys/uvm: uvm_pdaemon.c

Log Message:
uvm_pageout_done(): do nothing when npages is zero.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/uvm/uvm_pdaemon.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/uvm/uvm_pdaemon.c
diff -u src/sys/uvm/uvm_pdaemon.c:1.126 src/sys/uvm/uvm_pdaemon.c:1.127
--- src/sys/uvm/uvm_pdaemon.c:1.126	Mon Apr 13 15:54:45 2020
+++ src/sys/uvm/uvm_pdaemon.c	Mon May 25 19:46:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pdaemon.c,v 1.126 2020/04/13 15:54:45 maxv Exp $	*/
+/*	$NetBSD: uvm_pdaemon.c,v 1.127 2020/05/25 19:46:20 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.126 2020/04/13 15:54:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.127 2020/05/25 19:46:20 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -355,7 +355,12 @@ void
 uvm_pageout_done(int npages)
 {
 
-	KASSERT(uvmexp.paging >= npages);
+	KASSERT(atomic_load_relaxed() >= npages);
+
+	if (npages == 0) {
+		return;
+	}
+
 	atomic_add_int(, -npages);
 
 	/*



CVS commit: src/sys/uvm

2020-05-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon May 25 19:29:09 UTC 2020

Modified Files:
src/sys/uvm: uvm_bio.c

Log Message:
ubc_uiomove_direct(): if UBC_FAULTBUSY, the left-over portion of the final
page needs to be zeroed.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/uvm/uvm_bio.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/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.116 src/sys/uvm/uvm_bio.c:1.117
--- src/sys/uvm/uvm_bio.c:1.116	Sun May 24 20:05:53 2020
+++ src/sys/uvm/uvm_bio.c	Mon May 25 19:29:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -997,22 +997,40 @@ ubc_uiomove_direct(struct uvm_object *uo
 			error = uvm_direct_process(pgs, npages, off, bytelen,
 			ubc_uiomove_process, uio);
 		}
-		if (error != 0 && overwrite) {
+
+		if (overwrite) {
+			voff_t endoff;
+
 			/*
-			 * if we haven't initialized the pages yet,
-			 * do it now.  it's safe to use memset here
-			 * because we just mapped the pages above.
+			 * if we haven't initialized the pages yet due to an
+			 * error above, do it now.
 			 */
-			printf("%s: error=%d\n", __func__, error);
-			(void) uvm_direct_process(pgs, npages, off, bytelen,
-			ubc_zerorange_process, NULL);
+			if (error != 0) {
+printf("%s: error=%d\n", __func__, error);
+(void) uvm_direct_process(pgs, npages, off,
+bytelen, ubc_zerorange_process, NULL);
+			}
+
+			off += bytelen;
+			todo -= bytelen;
+			endoff = off & (PAGE_SIZE - 1);
+
+			/*
+			 * zero out the remaining portion of the final page
+			 * (if any).
+			 */
+			if (todo == 0 && endoff != 0) {
+vsize_t zlen = PAGE_SIZE - endoff;
+(void) uvm_direct_process(pgs + npages - 1, 1,
+off, zlen, ubc_zerorange_process, NULL);
+			}
+		} else {
+			off += bytelen;
+			todo -= bytelen;
 		}
 
 		ubc_direct_release(uobj, flags, pgs, npages);
 
-		off += bytelen;
-		todo -= bytelen;
-
 		if (error != 0 && ISSET(flags, UBC_PARTIALOK)) {
 			break;
 		}



CVS commit: src/sys/fs/tmpfs

2020-05-24 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 24 20:08:26 UTC 2020

Modified Files:
src/sys/fs/tmpfs: tmpfs_vnops.c

Log Message:
tmpfs_write(): use UBC_FAULTBUSY when extending files, if possible, to avoid
zeroing of newly allocated pages & fault processing.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/fs/tmpfs/tmpfs_vnops.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/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.141 src/sys/fs/tmpfs/tmpfs_vnops.c:1.142
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.141	Tue May 19 22:22:15 2020
+++ src/sys/fs/tmpfs/tmpfs_vnops.c	Sun May 24 20:08:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vnops.c,v 1.141 2020/05/19 22:22:15 ad Exp $	*/
+/*	$NetBSD: tmpfs_vnops.c,v 1.142 2020/05/24 20:08:26 ad Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007, 2020 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.141 2020/05/19 22:22:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.142 2020/05/24 20:08:26 ad Exp $");
 
 #include 
 #include 
@@ -573,7 +573,7 @@ tmpfs_write(void *v)
 	tmpfs_node_t *node;
 	struct uvm_object *uobj;
 	off_t oldsize;
-	int error;
+	int error, ubc_flags;
 
 	KASSERT(VOP_ISLOCKED(vp));
 
@@ -603,6 +603,26 @@ tmpfs_write(void *v)
 			goto out;
 	}
 
+	/*
+	 * If we're extending the file and have data to write that would
+	 * not leave an un-zeroed hole, we can avoid fault processing and
+	 * zeroing of pages on allocation.
+	 *
+	 * Don't do this if the file is mapped and we need to touch an
+	 * existing page, because writing a mapping of the file into itself
+	 * could cause a deadlock on PG_BUSY.
+	 *
+	 * New pages will not become visible until finished here (because
+	 * of PG_BUSY and the vnode lock).
+	 */
+	ubc_flags = UBC_WRITE | UBC_VNODE_FLAGS(vp);
+	if (uio->uio_offset >= oldsize &&
+	((uio->uio_offset & (PAGE_SIZE - 1)) == 0 ||
+	((vp->v_vflag & VV_MAPPED) == 0 &&
+	trunc_page(uio->uio_offset) == trunc_page(oldsize {
+		ubc_flags |= UBC_FAULTBUSY;
+	}
+
 	uobj = node->tn_spec.tn_reg.tn_aobj;
 	error = 0;
 	while (error == 0 && uio->uio_resid > 0) {
@@ -613,7 +633,7 @@ tmpfs_write(void *v)
 			break;
 		}
 		error = ubc_uiomove(uobj, uio, len, IO_ADV_DECODE(ioflag),
-		UBC_WRITE | UBC_VNODE_FLAGS(vp));
+		ubc_flags);
 	}
 	if (error) {
 		(void)tmpfs_reg_resize(vp, oldsize);



CVS commit: src/sys/uvm

2020-05-24 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 24 20:05:54 UTC 2020

Modified Files:
src/sys/uvm: uvm_bio.c

Log Message:
- ubc_uiomove():  Always use direct access in the UBC_FAULTBUSY case, since
  it works basically the same way as !direct minus temporary mappings, and
  there are no concurrency issues.

- ubc_alloc_direct(): In the PGO_OVERWRITE case blocks are allocated
  beforehand.  Avoid waking or activating pages unless needed.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/uvm/uvm_bio.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/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.115 src/sys/uvm/uvm_bio.c:1.116
--- src/sys/uvm/uvm_bio.c:1.115	Sat May 23 11:59:03 2020
+++ src/sys/uvm/uvm_bio.c	Sun May 24 20:05:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.115 2020/05/23 11:59:03 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.115 2020/05/23 11:59:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.116 2020/05/24 20:05:53 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -748,9 +748,13 @@ ubc_uiomove(struct uvm_object *uobj, str
 	 *
 	 * avoid the problem by disallowing direct access if the object
 	 * might be visible somewhere via mmap().
+	 *
+	 * XXX concurrent reads cause thundering herd issues with PG_BUSY. 
+	 * In the future enable by default for writes or if ncpu<=2, and
+	 * make the toggle override that.
 	 */
-
-	if (ubc_direct && (flags & UBC_ISMAPPED) == 0) {
+	if ((ubc_direct && (flags & UBC_ISMAPPED) == 0) ||
+	(flags & UBC_FAULTBUSY) != 0) {
 		return ubc_uiomove_direct(uobj, uio, todo, advice, flags);
 	}
 #endif
@@ -841,7 +845,7 @@ ubc_alloc_direct(struct uvm_object *uobj
 
 	if (flags & UBC_WRITE) {
 		if (flags & UBC_FAULTBUSY)
-			gpflags |= PGO_OVERWRITE;
+			gpflags |= PGO_OVERWRITE | PGO_NOBLOCKALLOC;
 #if 0
 		KASSERT(!UVM_OBJ_NEEDS_WRITEFAULT(uobj));
 #endif
@@ -902,7 +906,10 @@ again:
 		/* Page must be writable by now */
 		KASSERT((pg->flags & PG_RDONLY) == 0 || (flags & UBC_WRITE) == 0);
 
-		/* No managed mapping - mark the page dirty. */
+		/*
+		 * XXX For aobj pages.  No managed mapping - mark the page
+		 * dirty.
+		 */
 		if ((flags & UBC_WRITE) != 0) {
 			uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_DIRTY);	
 		}
@@ -927,10 +934,13 @@ ubc_direct_release(struct uvm_object *uo
 			uvm_pagefree(pg);
 			continue;
 		}
-		uvm_pagelock(pg);
-		uvm_pageactivate(pg);
-		uvm_pagewakeup(pg);
-		uvm_pageunlock(pg);
+
+		if (uvm_pagewanted_p(pg) || uvmpdpol_pageactivate_p(pg)) {
+			uvm_pagelock(pg);
+			uvm_pageactivate(pg);
+			uvm_pagewakeup(pg);
+			uvm_pageunlock(pg);
+		}
 
 		/* Page was changed, no longer fake and neither clean. */
 		if (flags & UBC_WRITE) {



CVS commit: src/sys/uvm

2020-05-24 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 24 19:46:59 UTC 2020

Modified Files:
src/sys/uvm: uvm_page.c uvm_page.h

Log Message:
Add uvm_pagewanted_p(): return true if someone is waiting on the page and
assert caller has correct lock to observe that.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.103 -r1.104 src/sys/uvm/uvm_page.h

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

Modified files:

Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.237 src/sys/uvm/uvm_page.c:1.238
--- src/sys/uvm/uvm_page.c:1.237	Tue May 19 20:46:39 2020
+++ src/sys/uvm/uvm_page.c	Sun May 24 19:46:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.237 2020/05/19 20:46:39 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.238 2020/05/24 19:46:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.237 2020/05/19 20:46:39 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.238 2020/05/24 19:46:59 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1718,8 +1718,8 @@ uvm_pagewait(struct vm_page *pg, krwlock
 	KASSERT(uvm_page_owner_locked_p(pg, false));
 
 	mutex_enter(>interlock);
-	rw_exit(lock);
 	pg->pqflags |= PQ_WANTED;
+	rw_exit(lock);
 	UVM_UNLOCK_AND_WAIT(pg, >interlock, false, wmesg, 0);
 }
 
@@ -1744,6 +1744,21 @@ uvm_pagewakeup(struct vm_page *pg)
 	}
 }
 
+/*
+ * uvm_pagewanted_p: return true if someone is waiting on the page
+ *
+ * => object must be write locked (lock out all concurrent access)
+ */
+
+bool
+uvm_pagewanted_p(struct vm_page *pg)
+{
+
+	KASSERT(uvm_page_owner_locked_p(pg, true));
+
+	return (atomic_load_relaxed(>pqflags) & PQ_WANTED) != 0;
+}
+
 #if defined(UVM_PAGE_TRKOWN)
 /*
  * uvm_page_own: set or release page ownership

Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.103 src/sys/uvm/uvm_page.h:1.104
--- src/sys/uvm/uvm_page.h:1.103	Sun May 17 19:38:17 2020
+++ src/sys/uvm/uvm_page.h	Sun May 24 19:46:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.103 2020/05/17 19:38:17 ad Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.104 2020/05/24 19:46:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -378,6 +378,7 @@ bool uvm_pagecheckdirty(struct vm_page *
 bool uvm_pagereadonly_p(struct vm_page *);
 bool uvm_page_locked_p(struct vm_page *);
 void uvm_pagewakeup(struct vm_page *);
+bool uvm_pagewanted_p(struct vm_page *);
 void uvm_pagewait(struct vm_page *, krwlock_t *, const char *);
 
 int uvm_page_lookup_freelist(struct vm_page *);



CVS commit: src/sys/sys

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 23:37:17 UTC 2020

Modified Files:
src/sys/sys: sched.h

Log Message:
Oops.  If a SCHED_RR thread is preempted and has exceeded its timeslice it
needs to go to the back of the run queue so round-robin actually happens,
otherwise it should go to the front.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/sys/sched.h

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

Modified files:

Index: src/sys/sys/sched.h
diff -u src/sys/sys/sched.h:1.89 src/sys/sys/sched.h:1.90
--- src/sys/sys/sched.h:1.89	Tue May 12 11:21:09 2020
+++ src/sys/sys/sched.h	Sat May 23 23:37:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched.h,v 1.89 2020/05/12 11:21:09 kamil Exp $	*/
+/*	$NetBSD: sched.h,v 1.90 2020/05/23 23:37:17 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2007, 2008, 2019, 2020
@@ -210,6 +210,7 @@ struct schedstate_percpu {
 #ifdef _KERNEL
 
 extern int schedhz;			/* ideally: 16 */
+extern u_int sched_rrticks;
 
 struct proc;
 struct cpu_info;



CVS commit: src/sys/kern

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 22:16:17 UTC 2020

Modified Files:
src/sys/kern: tty_ptm.c

Log Message:
PR kern/55237: Panic: vrelel: bad ref count (9.99.54)

Adjust v_writecount with v_interlock held.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/kern/tty_ptm.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/kern/tty_ptm.c
diff -u src/sys/kern/tty_ptm.c:1.41 src/sys/kern/tty_ptm.c:1.42
--- src/sys/kern/tty_ptm.c:1.41	Sat Nov 30 20:45:49 2019
+++ src/sys/kern/tty_ptm.c	Sat May 23 22:16:17 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: tty_ptm.c,v 1.41 2019/11/30 20:45:49 ad Exp $	*/
+/*	$NetBSD: tty_ptm.c,v 1.42 2020/05/23 22:16:17 ad Exp $	*/
 
 /*-
- * Copyright (c) 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 2004, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.41 2019/11/30 20:45:49 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.42 2020/05/23 22:16:17 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -145,7 +145,9 @@ pty_vn_open(struct vnode *vp, struct lwp
 		return error;
 	}
 
+	mutex_enter(vp->v_interlock);
 	vp->v_writecount++;
+	mutex_exit(vp->v_interlock);
 
 	return 0;
 }



CVS commit: src/sys/sys

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 21:49:43 UTC 2020

Modified Files:
src/sys/sys: param.h

Log Message:
NetBSD 9.99.64 - struct lwp changed


To generate a diff of this commit:
cvs rdiff -u -r1.666 -r1.667 src/sys/sys/param.h

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

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.666 src/sys/sys/param.h:1.667
--- src/sys/sys/param.h:1.666	Sat May 16 18:58:56 2020
+++ src/sys/sys/param.h	Sat May 23 21:49:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.666 2020/05/16 18:58:56 christos Exp $	*/
+/*	$NetBSD: param.h,v 1.667 2020/05/23 21:49:43 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999006300	/* NetBSD 9.99.63 */
+#define	__NetBSD_Version__	999006400	/* NetBSD 9.99.64 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/kern

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 21:24:41 UTC 2020

Modified Files:
src/sys/kern: kern_runq.c sched_4bsd.c sched_m2.c

Log Message:
Oops.  If a SCHED_RR thread is preempted and has exceeded its timeslice it
needs to go to the back of the run queue so round-robin actually happens,
otherwise it should go to the front.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/kern/kern_runq.c
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/sched_4bsd.c
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/sched_m2.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/kern/kern_runq.c
diff -u src/sys/kern/kern_runq.c:1.68 src/sys/kern/kern_runq.c:1.69
--- src/sys/kern/kern_runq.c:1.68	Sat May 23 21:14:55 2020
+++ src/sys/kern/kern_runq.c	Sat May 23 21:24:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $	*/
+/*	$NetBSD: kern_runq.c,v 1.69 2020/05/23 21:24:41 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.69 2020/05/23 21:24:41 ad Exp $");
 
 #include "opt_dtrace.h"
 
@@ -206,9 +206,31 @@ sched_enqueue(struct lwp *l)
 		KASSERT((spc->spc_bitmap[i] & q) == 0);
 		spc->spc_bitmap[i] |= q;
 	}
-	/* Preempted SCHED_RR and SCHED_FIFO LWPs go to the queue head. */
-	if (l->l_class != SCHED_OTHER && (l->l_pflag & LP_PREEMPTING) != 0) {
-		TAILQ_INSERT_HEAD(q_head, l, l_runq);
+
+	/*
+	 * Determine run queue position according to POSIX.  XXX Explicitly
+	 * lowering a thread's priority with pthread_setschedparam() is not
+	 * handled.
+	 */
+	if ((l->l_pflag & LP_PREEMPTING) != 0) {
+		switch (l->l_class) {
+		case SCHED_OTHER:
+			TAILQ_INSERT_TAIL(q_head, l, l_runq);
+			break;
+		case SCHED_FIFO:
+			TAILQ_INSERT_HEAD(q_head, l, l_runq);
+			break;
+		case SCHED_RR:
+			if (getticks() - l->l_rticks >= sched_rrticks) {
+TAILQ_INSERT_TAIL(q_head, l, l_runq);
+			} else {
+TAILQ_INSERT_HEAD(q_head, l, l_runq);
+			}
+			break;
+		default: /* SCHED_OTHER */
+			panic("sched_enqueue: LWP %p has class %d\n",
+			l, l->l_class);
+		}
 	} else {
 		TAILQ_INSERT_TAIL(q_head, l, l_runq);
 	}

Index: src/sys/kern/sched_4bsd.c
diff -u src/sys/kern/sched_4bsd.c:1.43 src/sys/kern/sched_4bsd.c:1.44
--- src/sys/kern/sched_4bsd.c:1.43	Thu Mar 12 10:44:00 2020
+++ src/sys/kern/sched_4bsd.c	Sat May 23 21:24:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched_4bsd.c,v 1.43 2020/03/12 10:44:00 ad Exp $	*/
+/*	$NetBSD: sched_4bsd.c,v 1.44 2020/05/23 21:24:41 ad Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2019, 2020
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.43 2020/03/12 10:44:00 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.44 2020/05/23 21:24:41 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -93,11 +93,11 @@ static void resetpriority(struct lwp *);
 extern unsigned int sched_pstats_ticks; /* defined in kern_synch.c */
 
 /* Number of hardclock ticks per sched_tick() */
-static int rrticks __read_mostly;
+u_int sched_rrticks __read_mostly;
 
 /*
  * Force switch among equal priority processes every 100ms.
- * Called from hardclock every hz/10 == rrticks hardclock ticks.
+ * Called from hardclock every hz/10 == sched_rrticks hardclock ticks.
  */
 /* ARGSUSED */
 void
@@ -107,7 +107,7 @@ sched_tick(struct cpu_info *ci)
 	pri_t pri = PRI_NONE;
 	lwp_t *l;
 
-	spc->spc_ticks = rrticks;
+	spc->spc_ticks = sched_rrticks;
 
 	if (CURCPU_IDLE_P()) {
 		spc_lock(ci);
@@ -534,7 +534,7 @@ static int
 sysctl_sched_rtts(SYSCTLFN_ARGS)
 {
 	struct sysctlnode node;
-	int rttsms = hztoms(rrticks);
+	int rttsms = hztoms(sched_rrticks);
 
 	node = *rnode;
 	node.sysctl_data = 
@@ -555,7 +555,7 @@ SYSCTL_SETUP(sysctl_sched_4bsd_setup, "s
 	if (node == NULL)
 		return;
 
-	rrticks = hz / 10;
+	sched_rrticks = hz / 10;
 
 	sysctl_createv(NULL, 0, , NULL,
 		CTLFLAG_PERMANENT,

Index: src/sys/kern/sched_m2.c
diff -u src/sys/kern/sched_m2.c:1.38 src/sys/kern/sched_m2.c:1.39
--- src/sys/kern/sched_m2.c:1.38	Mon Apr 13 15:54:45 2020
+++ src/sys/kern/sched_m2.c	Sat May 23 21:24:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched_m2.c,v 1.38 2020/04/13 15:54:45 maxv Exp $	*/
+/*	$NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius 
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.38 2020/04/13 15:54:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $");
 
 #include 
 
@@ -68,9 +68,9 @@ __KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v
  */
 static u_int	min_ts;			/* Minimal time-slice */
 static u_int	max_ts;			/* Maximal time-slice */
-static u_int	rt_ts;			/* Real-time time-slice */
 static u_int	

CVS commit: src/sys/kern

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 21:14:56 UTC 2020

Modified Files:
src/sys/kern: kern_runq.c

Log Message:
sched_bestcpu(): There is a fallback CPU, in case the user manages to set
the system up so no CPU is permitted to run a given LWP.  Fix a bug where
that fallback CPU would sometimes get picked even if there was another CPU
that could legitimately run the LWP.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/kern/kern_runq.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/kern/kern_runq.c
diff -u src/sys/kern/kern_runq.c:1.67 src/sys/kern/kern_runq.c:1.68
--- src/sys/kern/kern_runq.c:1.67	Mon Apr 13 16:09:21 2020
+++ src/sys/kern/kern_runq.c	Sat May 23 21:14:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_runq.c,v 1.67 2020/04/13 16:09:21 maxv Exp $	*/
+/*	$NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.67 2020/04/13 16:09:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $");
 
 #include "opt_dtrace.h"
 
@@ -479,7 +479,13 @@ sched_bestcpu(struct lwp *l, struct cpu_
 	 */
 	bestci = pivot;
 	bestspc = >ci_schedstate;
-	bestpri = MAX(bestspc->spc_curpriority, bestspc->spc_maxpriority);
+	if (sched_migratable(l, bestci)) {
+		bestpri = MAX(bestspc->spc_curpriority,
+		bestspc->spc_maxpriority);
+	} else {
+		/* Invalidate the priority. */
+		bestpri = PRI_COUNT;
+	}
 
 	/* In the outer loop scroll through all CPU packages. */
 	pivot = pivot->ci_package1st;



CVS commit: src/sys

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 20:45:11 UTC 2020

Modified Files:
src/sys/kern: kern_lwp.c kern_proc.c kern_turnstile.c sys_lwp.c
src/sys/rump/librump/rumpkern: lwproc.c
src/sys/sys: lwp.h proc.h sleepq.h

Log Message:
- Replace pid_table_lock with a lockless lookup covered by pserialize, with
  the "writer" side being pid_table expansion.  The basic idea is that when
  doing an LWP lookup there is usually already a lock held (p->p_lock), or a
  spin mutex that needs to be taken (l->l_mutex), and either can be used to
  get the found LWP stable and confidently determine that all is correct.

- For user processes LSLARVAL implies the same thing as LSIDL ("not visible
  by ID"), and lookup by ID in proc0 doesn't really happen.  In-tree the new
  state should be understood by top(1), the tty subsystem and so on, and
  would attract the attention of 3rd party kernel grovellers in time, so
  remove it and just rely on LSIDL.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.251 -r1.252 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.39 -r1.40 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.48 -r1.49 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.209 -r1.210 src/sys/sys/lwp.h
cvs rdiff -u -r1.365 -r1.366 src/sys/sys/proc.h
cvs rdiff -u -r1.30 -r1.31 src/sys/sys/sleepq.h

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

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.237 src/sys/kern/kern_lwp.c:1.238
--- src/sys/kern/kern_lwp.c:1.237	Wed Apr 29 01:52:26 2020
+++ src/sys/kern/kern_lwp.c	Sat May 23 20:45:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.237 2020/04/29 01:52:26 thorpej Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.238 2020/05/23 20:45:10 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -65,9 +65,15 @@
  *
  *	LSIDL
  *
- *		Idle: the LWP has been created but has not yet executed,
- *		or it has ceased executing a unit of work and is waiting
- *		to be started again.
+ *		Idle: the LWP has been created but has not yet executed, or
+ *		it has ceased executing a unit of work and is waiting to be
+ *		started again.  This state exists so that the LWP can occupy
+ *		a slot in the process & PID table, but without having to
+ *		worry about being touched; lookups of the LWP by ID will
+ *		fail while in this state.  The LWP will become visible for
+ *		lookup once its state transitions further.  Some special
+ *		kernel threads also (ab)use this state to indicate that they
+ *		are idle (soft interrupts and idle LWPs).
  *
  *	LSSUSPENDED:
  *
@@ -83,16 +89,6 @@
  *	The LP_RUNNING flag in lwp::l_pflag indicates that an LWP is running.
  *	Importantly, it indicates that its state is tied to a CPU.
  *
- *	LSLARVAL:
- *
- *		Born, but not fully mature: the LWP is in the process
- *		of being constructed.  This state exists so that the
- *		LWP can occupy a slot in the PID table, but without
- *		having to worry about being touched; lookups of the
- *		LWP will fail while in this state.  The LWP will become
- *		visible in the PID table once its state transitions
- *		to LSIDL.
- *
  *	LSZOMB:
  *
  *		Dead or dying: the LWP has released most of its resources
@@ -130,8 +126,6 @@
  *
  *	LWPs may transition states in the following ways:
  *
- *	 LARVAL > IDL
- *
  *	 RUN ---> ONPROC		ONPROC -> RUN
  *		> SLEEP
  *		> STOPPED
@@ -223,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.237 2020/04/29 01:52:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.238 2020/05/23 20:45:10 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -266,6 +260,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v
 static pool_cache_t	lwp_cache	__read_mostly;
 struct lwplist		alllwp		__cacheline_aligned;
 
+static int		lwp_ctor(void *, void *, int);
 static void		lwp_dtor(void *, void *);
 
 /* DTrace proc provider probes */
@@ -347,7 +342,7 @@ lwpinit(void)
 	LIST_INIT();
 	lwpinit_specificdata();
 	lwp_cache = pool_cache_init(sizeof(lwp_t), MIN_LWP_ALIGNMENT, 0, 0,
-	"lwppl", NULL, IPL_NONE, NULL, lwp_dtor, NULL);
+	"lwppl", NULL, IPL_NONE, lwp_ctor, lwp_dtor, NULL);
 
 	maxlwp = cpu_maxlwp();
 	sysctl_kern_lwp_setup();
@@ -376,6 +371,27 @@ lwp0_init(void)
 	SYSCALL_TIME_LWP_INIT(l);
 }
 
+/*
+ * Initialize the non-zeroed portion of an lwp_t.
+ */
+static int
+lwp_ctor(void *arg, void *obj, int flags)
+{
+	lwp_t *l = obj;
+
+	l->l_stat = LSIDL;
+	l->l_cpu = curcpu();
+	l->l_mutex = l->l_cpu->ci_schedstate.spc_lwplock;
+	l->l_ts = pool_get(_pool, flags);
+
+	if (l->l_ts == NULL) {
+		return ENOMEM;
+	} else {
+		turnstile_ctor(l->l_ts);
+		return 0;
+	}
+}
+
 static void
 lwp_dtor(void *arg, void *obj)
 {
@@ -389,13 +405,22 @@ lwp_dtor(void *arg, void *obj)
 

CVS commit: src/sys/uvm

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 20:22:42 UTC 2020

Modified Files:
src/sys/uvm: uvm_pglist.c

Log Message:
uvm_pglistfree(): just use uvm_pagefree().


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/uvm/uvm_pglist.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/uvm/uvm_pglist.c
diff -u src/sys/uvm/uvm_pglist.c:1.81 src/sys/uvm/uvm_pglist.c:1.82
--- src/sys/uvm/uvm_pglist.c:1.81	Sun Mar  1 21:43:56 2020
+++ src/sys/uvm/uvm_pglist.c	Sat May 23 20:22:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.81 2020/03/01 21:43:56 ad Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.82 2020/05/23 20:22:42 ad Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.81 2020/03/01 21:43:56 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.82 2020/05/23 20:22:42 ad Exp $");
 
 #include 
 #include 
@@ -560,37 +560,14 @@ uvm_pglistalloc(psize_t size, paddr_t lo
 void
 uvm_pglistfree(struct pglist *list)
 {
-	struct pgfreelist *pgfl;
-	struct pgflbucket *pgb;
 	struct vm_page *pg;
-	int c, b;
 
 	KASSERT(!cpu_intr_p());
 	KASSERT(!cpu_softintr_p());
 
-	/*
-	 * Lock the free list and free each page.
-	 */
-
-	uvm_pgfl_lock();
 	while ((pg = TAILQ_FIRST(list)) != NULL) {
 		TAILQ_REMOVE(list, pg, pageq.queue);
-		pg->flags = (pg->flags & PG_ZERO) | PG_FREE;
-#ifdef DEBUG
-		pg->uobject = (void *)0xdeadbeef;
-		pg->uanon = (void *)0xdeadbeef;
-		if (pg->flags & PG_ZERO)
-			uvm_pagezerocheck(pg);
-#endif /* DEBUG */
-		c = VM_PGCOLOR(pg);
-		b = uvm_page_get_bucket(pg);
-		pgfl = _free[uvm_page_get_freelist(pg)];
-		pgb = pgfl->pgfl_buckets[b];
-		if (pg->flags & PG_ZERO)
-			CPU_COUNT(CPU_COUNT_ZEROPAGES, 1);
-		pgb->pgb_nfree++;
-		LIST_INSERT_HEAD(>pgb_colors[c], pg, pageq.list);
+		uvm_pagefree(pg);
 		STAT_DECR(uvm_pglistalloc_npages);
 	}
-	uvm_pgfl_unlock();
 }



CVS commit: src/sys/uvm

2020-05-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 23 11:59:03 UTC 2020

Modified Files:
src/sys/uvm: uvm_bio.c

Log Message:
- In ubc_alloc() take initial offset into account in the UBC_FAULTBUSY case
  or one too few pages can be mapped.

- In ubc_release() with UBC_FAULTBUSY, chances are that pages are newly
  allocated and freshly enqueued, so avoid uvm_pageactivate() if possible

- Keep track of the pages mapped in ubc_alloc() in an array on the stack,
  and use this to avoid calling pmap_extract() in ubc_release().


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/uvm/uvm_bio.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/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.114 src/sys/uvm/uvm_bio.c:1.115
--- src/sys/uvm/uvm_bio.c:1.114	Tue May 19 22:22:15 2020
+++ src/sys/uvm/uvm_bio.c	Sat May 23 11:59:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.114 2020/05/19 22:22:15 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.115 2020/05/23 11:59:03 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.114 2020/05/19 22:22:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.115 2020/05/23 11:59:03 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 
 #include 
 
 #include 
+#include 
 
 #ifdef PMAP_DIRECT
 #  define UBC_USE_PMAP_DIRECT
@@ -472,7 +473,7 @@ ubc_find_mapping(struct uvm_object *uobj
 
 static void * __noinline
 ubc_alloc(struct uvm_object *uobj, voff_t offset, vsize_t *lenp, int advice,
-int flags)
+int flags, struct vm_page **pgs, int *npagesp)
 {
 	vaddr_t slot_offset, va;
 	struct ubc_map *umap;
@@ -487,6 +488,7 @@ ubc_alloc(struct uvm_object *uobj, voff_
 	umap_offset = (offset & ~((voff_t)ubc_winsize - 1));
 	slot_offset = (vaddr_t)(offset & ((voff_t)ubc_winsize - 1));
 	*lenp = MIN(*lenp, ubc_winsize - slot_offset);
+	KASSERT(*lenp > 0);
 
 	rw_enter(ubc_object.uobj.vmobjlock, RW_WRITER);
 again:
@@ -560,14 +562,14 @@ again:
 	(uintptr_t)umap, umap->refcount, (uintptr_t)va, flags);
 
 	if (flags & UBC_FAULTBUSY) {
-		// XXX add offset from slot_offset?
-		int npages = (*lenp + PAGE_SIZE - 1) >> PAGE_SHIFT;
-		struct vm_page *pgs[npages];
+		int npages = (*lenp + (offset & (PAGE_SIZE - 1)) +
+		PAGE_SIZE - 1) >> PAGE_SHIFT;
 		int gpflags =
 		PGO_SYNCIO|PGO_OVERWRITE|PGO_PASTEOF|PGO_NOBLOCKALLOC|
 		PGO_NOTIMESTAMP;
 		int i;
 		KDASSERT(flags & UBC_WRITE);
+		KASSERT(npages <= *npagesp);
 		KASSERT(umap->refcount == 1);
 
 		UBC_EVCNT_INCR(faultbusy);
@@ -577,7 +579,7 @@ again_faultbusy:
 			umap->flags &= ~UMAP_MAPPING_CACHED;
 			pmap_remove(pmap_kernel(), va, va + ubc_winsize);
 		}
-		memset(pgs, 0, sizeof(pgs));
+		memset(pgs, 0, *npagesp * sizeof(pgs[0]));
 
 		error = (*uobj->pgops->pgo_get)(uobj, trunc_page(offset), pgs,
 		, 0, VM_PROT_READ | VM_PROT_WRITE, advice, gpflags);
@@ -615,6 +617,7 @@ again_faultbusy:
 		}
 		pmap_update(pmap_kernel());
 		umap->flags |= UMAP_PAGES_LOCKED;
+		*npagesp = npages;
 	} else {
 		KASSERT((umap->flags & UMAP_PAGES_LOCKED) == 0);
 	}
@@ -628,7 +631,7 @@ out:
  */
 
 static void __noinline
-ubc_release(void *va, int flags)
+ubc_release(void *va, int flags, struct vm_page **pgs, int npages)
 {
 	struct ubc_map *umap;
 	struct uvm_object *uobj;
@@ -643,13 +646,11 @@ ubc_release(void *va, int flags)
 	KASSERT(uobj != NULL);
 
 	if (umap->flags & UMAP_PAGES_LOCKED) {
-		const voff_t slot_offset = umap->writeoff;
 		const voff_t endoff = umap->writeoff + umap->writelen;
 		const voff_t zerolen = round_page(endoff) - endoff;
-		const u_int npages = (round_page(endoff) -
-		trunc_page(slot_offset)) >> PAGE_SHIFT;
-		struct vm_page *pgs[npages];
 
+		KASSERT(npages == (round_page(endoff) -
+		trunc_page(umap->writeoff)) >> PAGE_SHIFT);
 		KASSERT((umap->flags & UMAP_MAPPING_CACHED) == 0);
 		if (zerolen) {
 			memset((char *)umapva + endoff, 0, zerolen);
@@ -657,21 +658,25 @@ ubc_release(void *va, int flags)
 		umap->flags &= ~UMAP_PAGES_LOCKED;
 		rw_enter(uobj->vmobjlock, RW_WRITER);
 		for (u_int i = 0; i < npages; i++) {
+			struct vm_page *pg = pgs[i];
+#ifdef DIAGNOSTIC
 			paddr_t pa;
-			bool rv __diagused;
-
-			rv = pmap_extract(pmap_kernel(),
-			umapva + slot_offset + (i << PAGE_SHIFT), );
+			bool rv;
+			rv = pmap_extract(pmap_kernel(), umapva +
+			umap->writeoff + (i << PAGE_SHIFT), );
 			KASSERT(rv);
-			pgs[i] = PHYS_TO_VM_PAGE(pa);
-			pgs[i]->flags &= ~PG_FAKE;
-			KASSERTMSG(uvm_pagegetdirty(pgs[i]) ==
+			KASSERT(PHYS_TO_VM_PAGE(pa) == pg);
+#endif
+			pg->flags &= ~PG_FAKE;
+			KASSERTMSG(uvm_pagegetdirty(pg) ==
 			UVM_PAGE_STATUS_DIRTY,
-			"page %p not dirty", pgs[i]);
-			KASSERT(pgs[i]->loan_count == 0);
-			uvm_pagelock(pgs[i]);
-			uvm_pageactivate(pgs[i]);
-			uvm_pageunlock(pgs[i]);
+	

CVS commit: src/sys/uvm

2020-05-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri May 22 19:46:29 UTC 2020

Modified Files:
src/sys/uvm: uvm_glue.c

Log Message:
Remove the ubc_direct hack.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/sys/uvm/uvm_glue.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/uvm/uvm_glue.c
diff -u src/sys/uvm/uvm_glue.c:1.178 src/sys/uvm/uvm_glue.c:1.179
--- src/sys/uvm/uvm_glue.c:1.178	Thu Apr 23 21:53:01 2020
+++ src/sys/uvm/uvm_glue.c	Fri May 22 19:46:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_glue.c,v 1.178 2020/04/23 21:53:01 ad Exp $	*/
+/*	$NetBSD: uvm_glue.c,v 1.179 2020/05/22 19:46:29 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.178 2020/04/23 21:53:01 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.179 2020/05/22 19:46:29 ad Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_kstack.h"
@@ -504,18 +504,6 @@ uvm_scheduler(void)
 	/* Start the freelist cache. */
 	uvm_pgflcache_start();
 
-#ifdef PMAP_DIRECT
-	/*
-	 * XXX Temporary ugly hack.  Just before boot, disable ubc_direct if
-	 * there's more than a couple of CPUs, since it has concurrency
-	 * problems.
-	 */
-	if (ncpu > 2) {
-		extern bool ubc_direct;
-		ubc_direct = false;
-	}
-#endif
-
 	for (;;) {
 		/* Update legacy stats for post-mortem debugging. */
 		uvm_update_uvmexp();



CVS commit: src/sys/uvm

2020-05-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri May 22 19:02:59 UTC 2020

Modified Files:
src/sys/uvm: uvm_aobj.c

Log Message:
uao_get(): handle PGO_OVERWRITE.


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/uvm/uvm_aobj.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/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.143 src/sys/uvm/uvm_aobj.c:1.144
--- src/sys/uvm/uvm_aobj.c:1.143	Wed May 20 12:47:36 2020
+++ src/sys/uvm/uvm_aobj.c	Fri May 22 19:02:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.144 2020/05/22 19:02:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.144 2020/05/22 19:02:59 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -804,6 +804,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 	struct vm_page *ptmp = NULL;	/* Quell compiler warning */
 	int lcv, gotpages, maxpages, swslot = -1, pageidx = -1; /* XXX: gcc */
 	UVMHIST_FUNC("uao_get"); UVMHIST_CALLED(pdhist);
+	bool overwrite = ((flags & PGO_OVERWRITE) != 0);
 
 	UVMHIST_LOG(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
 		(uintptr_t)uobj, offset, flags,0);
@@ -921,7 +922,8 @@ uao_get(struct uvm_object *uobj, voff_t 
 pageidx = current_offset >> PAGE_SHIFT;
 swslot = uao_find_swslot(uobj, pageidx);
 ptmp = uao_pagealloc(uobj, current_offset,
-swslot == 0 ? UVM_PGA_ZERO : 0);
+swslot != 0 || overwrite ? 0 :
+UVM_PGA_ZERO);
 
 /* out of RAM? */
 if (ptmp == NULL) {
@@ -1036,9 +1038,15 @@ uao_get(struct uvm_object *uobj, voff_t 
 
 		/*
 		 * note that we will allow the page being writably-mapped
-		 * (!PG_RDONLY) regardless of access_type.
+		 * (!PG_RDONLY) regardless of access_type.  if overwrite,
+		 * the page can be modified through an unmanaged mapping
+		 * so mark it dirty up front.
 		 */
-		uvm_pagemarkdirty(ptmp, UVM_PAGE_STATUS_UNKNOWN);
+		if (overwrite) {
+			uvm_pagemarkdirty(ptmp, UVM_PAGE_STATUS_DIRTY);
+		} else {
+			uvm_pagemarkdirty(ptmp, UVM_PAGE_STATUS_UNKNOWN);
+		}
 
 		/*
  		 * we got the page!   clear the fake flag (indicates valid



CVS commit: src/sys/arch/x86/x86

2020-05-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu May 21 22:01:42 UTC 2020

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
Fix merge error


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/x86/x86/lapic.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/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.81 src/sys/arch/x86/x86/lapic.c:1.82
--- src/sys/arch/x86/x86/lapic.c:1.81	Thu May 21 21:12:30 2020
+++ src/sys/arch/x86/x86/lapic.c	Thu May 21 22:01:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lapic.c,v 1.81 2020/05/21 21:12:30 ad Exp $	*/
+/*	$NetBSD: lapic.c,v 1.82 2020/05/21 22:01:42 ad Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008, 2020 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.81 2020/05/21 21:12:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.82 2020/05/21 22:01:42 ad Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -781,7 +781,7 @@ lapic_delay(unsigned int usec)
 	while (deltat > 0) {
 		xtick = lapic_gettick();
 		if (lapic_broken_periodic && xtick == 0 && otick == 0) {
-			lapic_initclocks();
+			lapic_reset();
 			xtick = lapic_gettick();
 			if (xtick == 0)
 panic("lapic timer stopped ticking");



CVS commit: src/sys/arch

2020-05-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu May 21 21:12:31 UTC 2020

Modified Files:
src/sys/arch/x86/acpi: acpi_wakeup.c
src/sys/arch/x86/include: i82489var.h
src/sys/arch/x86/x86: cpu.c lapic.c x86_machdep.c
src/sys/arch/xen/x86: cpu.c
src/sys/arch/xen/xen: hypervisor.c xen_clock.c

Log Message:
- Recalibrate the APIC timer using the TSC, once the TSC has in turn been
  recalibrated using the HPET.  This gets the clock interrupt firing more
  closely to HZ.

- Undo change with recent Xen merge and go back to starting the clocks in
  initclocks() on the boot CPU, and in cpu_hatch() on secondary CPUs.

- On reflection don't use HPET delay any more, it works very well but means
  going over the bus.  It's enough to use HPET to calibrate the TSC and
  APIC.

Tested on amd64 native, xen and xen PVH.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/acpi/acpi_wakeup.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x86/include/i82489var.h
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.142 -r1.143 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/xen/xen/hypervisor.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/xen/xen/xen_clock.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/x86/acpi/acpi_wakeup.c
diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.52 src/sys/arch/x86/acpi/acpi_wakeup.c:1.53
--- src/sys/arch/x86/acpi/acpi_wakeup.c:1.52	Sat Feb 22 19:49:11 2020
+++ src/sys/arch/x86/acpi/acpi_wakeup.c	Thu May 21 21:12:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakeup.c,v 1.52 2020/02/22 19:49:11 chs Exp $	*/
+/*	$NetBSD: acpi_wakeup.c,v 1.53 2020/05/21 21:12:30 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.52 2020/02/22 19:49:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.53 2020/05/21 21:12:30 ad Exp $");
 
 #include 
 #include 
@@ -277,7 +277,7 @@ acpi_cpu_sleep(struct cpu_info *ci)
 #if NLAPIC > 0
 	lapic_enable();
 	lapic_set_lvt();
-	lapic_initclocks();
+	lapic_reset();
 #endif
 
 	atomic_or_32(>ci_flags, CPUF_RUNNING);
@@ -351,7 +351,7 @@ acpi_md_sleep(int state)
 #if NLAPIC > 0
 	lapic_enable();
 	lapic_set_lvt();
-	lapic_initclocks();
+	lapic_reset();
 #endif
 #if NIOAPIC > 0
 	ioapic_reenable();

Index: src/sys/arch/x86/include/i82489var.h
diff -u src/sys/arch/x86/include/i82489var.h:1.20 src/sys/arch/x86/include/i82489var.h:1.21
--- src/sys/arch/x86/include/i82489var.h:1.20	Sun Dec  1 08:23:09 2019
+++ src/sys/arch/x86/include/i82489var.h	Thu May 21 21:12:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: i82489var.h,v 1.20 2019/12/01 08:23:09 maxv Exp $	*/
+/*	$NetBSD: i82489var.h,v 1.21 2020/05/21 21:12:30 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -88,8 +88,8 @@ struct cpu_info;
 extern void lapic_boot_init(paddr_t);
 extern void lapic_set_lvt(void);
 extern void lapic_enable(void);
-extern void lapic_calibrate_timer(struct cpu_info *ci);
-extern void lapic_initclocks(void);
+extern void lapic_calibrate_timer(bool);
+extern void lapic_reset(void);
 
 extern uint32_t lapic_readreg(u_int);
 extern void lapic_writereg(u_int, uint32_t);

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.191 src/sys/arch/x86/x86/cpu.c:1.192
--- src/sys/arch/x86/x86/cpu.c:1.191	Tue May 12 06:32:05 2020
+++ src/sys/arch/x86/x86/cpu.c	Thu May 21 21:12:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.191 2020/05/12 06:32:05 msaitoh Exp $	*/
+/*	$NetBSD: cpu.c,v 1.192 2020/05/21 21:12:30 ad Exp $	*/
 
 /*
  * Copyright (c) 2000-2020 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.191 2020/05/12 06:32:05 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.192 2020/05/21 21:12:30 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -456,7 +456,7 @@ cpu_attach(device_t parent, device_t sel
 			lapic_enable();
 			lapic_set_lvt();
 			if (!vm_guest_is_xenpvh_or_pvhvm())
-lapic_calibrate_timer(ci);
+lapic_calibrate_timer(false);
 		}
 #endif
 		kcsan_cpu_init(ci);
@@ -471,7 +471,6 @@ cpu_attach(device_t parent, device_t sel
 		cpu_identify(ci);
 		x86_errata();
 		x86_cpu_idle_init();
-		(*x86_cpu_initclock_func)();
 #ifdef XENPVHVM
 		xen_hvm_init_cpu(ci);
 #endif
@@ -485,7 +484,6 @@ cpu_attach(device_t parent, device_t sel
 #ifdef XENPVHVM
 		xen_hvm_init_cpu(ci);
 #endif
-		(*x86_cpu_initclock_func)();
 		break;
 
 #ifdef MULTIPROCESSOR
@@ -739,14 +737,6 @@ cpu_boot_secondary_processors(void)
 	kcpuset_t *cpus;
 	u_long i;
 
-#if NHPET > 0
-	/* Use HPET delay, and re-calibrate TSC on boot CPU using HPET. */
-	if (hpet_delay_p() && x86_delay == 

CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2020-05-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu May 21 20:43:23 UTC 2020

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
Fix bugs in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.68 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.69
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.68	Wed May 20 20:47:18 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Thu May 21 20:43:23 2020
@@ -5971,7 +5971,6 @@ zfs_netbsd_getpages(void *v)
 	} */ * const ap = v;
 
 	vnode_t *const vp = ap->a_vp;
-	off_t offset = ap->a_offset + (ap->a_centeridx << PAGE_SHIFT);
 	const int flags = ap->a_flags;
 	const bool async = (flags & PGO_SYNCIO) == 0;
 	const bool memwrite = (ap->a_access_type & VM_PROT_WRITE) != 0;
@@ -5983,12 +5982,13 @@ zfs_netbsd_getpages(void *v)
 	vfs_t *mp;
 	struct vm_page *pg;
 	caddr_t va;
-	int npages, found, err = 0;
+	int npages = *ap->a_count, found, err = 0;
 
 	if (flags & PGO_LOCKED) {
- 		uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m, NULL,
+ 		uvn_findpages(uobj, ap->a_offset, , ap->a_m, NULL,
 		UFP_NOWAIT | UFP_NOALLOC | UFP_NOBUSY |
 		(memwrite ? UFP_NORDONLY : 0));
+		KASSERT(npages == *ap->a_count);
 		if (memwrite) {
 			KASSERT(rw_write_held(uobj->vmobjlock));
 			for (int i = 0; i < npages; i++) {
@@ -6010,9 +6010,6 @@ zfs_netbsd_getpages(void *v)
 	if (async) {
 		return 0;
 	}
-	if (*ap->a_count != 1) {
-		return EBUSY;
-	}
 
 	mp = vp->v_mount;
 	fstrans_start(mp);
@@ -6024,18 +6021,20 @@ zfs_netbsd_getpages(void *v)
 	ZFS_VERIFY_ZP(zp);
 
 	rw_enter(rw, RW_WRITER);
-	if (offset >= vp->v_size) {
+	if (ap->a_offset + (npages << PAGE_SHIFT) > round_page(vp->v_size)) {
 		rw_exit(rw);
 		ZFS_EXIT(zfsvfs);
 		fstrans_done(mp);
 		return EINVAL;
 	}
-	npages = *ap->a_count;
-	uvn_findpages(uobj, offset, , ap->a_m, NULL, UFP_ALL);
+	uvn_findpages(uobj, ap->a_offset, , ap->a_m, NULL, UFP_ALL);
+	KASSERT(npages == *ap->a_count);
 
 	for (int i = 0; i < npages; i++) {
 		pg = ap->a_m[i];
 		if (pg->flags & PG_FAKE) {
+			voff_t offset = pg->offset;
+			KASSERT(pg->offset == ap->a_offset + (i << PAGE_SHIFT));
 			rw_exit(rw);
 
 			va = zfs_map_page(pg, S_WRITE);



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs

2020-05-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 20 20:47:18 UTC 2020

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_vnops.c

Log Message:
zfs_netbsd_getpages:

- implement the PGO_LOCKED case
- handle npages > 1 for PGO_SYNCIO


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.67 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.68
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.67	Sat May 16 18:31:46 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Wed May 20 20:47:18 2020
@@ -755,15 +755,14 @@ mappedread(vnode_t *vp, int nbytes, uio_
 			va = zfs_map_page(pp, S_READ);
 			error = uiomove(va + off, bytes, UIO_READ, uio);
 			zfs_unmap_page(pp, va);
+			rw_enter(rw, RW_WRITER);
+			uvm_page_unbusy(, 1);
+			rw_exit(rw);
 		} else {
 			error = dmu_read_uio_dbuf(sa_get_db(zp->z_sa_hdl),
 			uio, bytes);
 		}
 
-		rw_enter(rw, RW_WRITER);
-		uvm_page_unbusy(, 1);
-		rw_exit(rw);
-
 		len -= bytes;
 		off = 0;
 		if (error)
@@ -5987,9 +5986,24 @@ zfs_netbsd_getpages(void *v)
 	int npages, found, err = 0;
 
 	if (flags & PGO_LOCKED) {
-		*ap->a_count = 0;
-		ap->a_m[ap->a_centeridx] = NULL;
-		return EBUSY;
+ 		uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m, NULL,
+		UFP_NOWAIT | UFP_NOALLOC | UFP_NOBUSY |
+		(memwrite ? UFP_NORDONLY : 0));
+		if (memwrite) {
+			KASSERT(rw_write_held(uobj->vmobjlock));
+			for (int i = 0; i < npages; i++) {
+pg = ap->a_m[i];
+if (pg == NULL || pg == PGO_DONTCARE) {
+	continue;
+}
+if (uvm_pagegetdirty(pg) ==
+UVM_PAGE_STATUS_CLEAN) {
+	uvm_pagemarkdirty(pg,
+	UVM_PAGE_STATUS_UNKNOWN);
+}
+			}
+		}
+		return ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0;
 	}
 	rw_exit(rw);
 
@@ -6016,28 +6030,42 @@ zfs_netbsd_getpages(void *v)
 		fstrans_done(mp);
 		return EINVAL;
 	}
-	npages = 1;
-	pg = NULL;
-	uvn_findpages(uobj, offset, , , NULL, UFP_ALL);
+	npages = *ap->a_count;
+	uvn_findpages(uobj, offset, , ap->a_m, NULL, UFP_ALL);
 
-	if (pg->flags & PG_FAKE) {
-		rw_exit(rw);
+	for (int i = 0; i < npages; i++) {
+		pg = ap->a_m[i];
+		if (pg->flags & PG_FAKE) {
+			rw_exit(rw);
 
-		va = zfs_map_page(pg, S_WRITE);
-		err = dmu_read(zfsvfs->z_os, zp->z_id, offset, PAGE_SIZE,
-		va, DMU_READ_PREFETCH);
-		zfs_unmap_page(pg, va);
+			va = zfs_map_page(pg, S_WRITE);
+			err = dmu_read(zfsvfs->z_os, zp->z_id, offset,
+			PAGE_SIZE, va, DMU_READ_PREFETCH);
+			zfs_unmap_page(pg, va);
 
-		rw_enter(rw, RW_WRITER);
-		pg->flags &= ~(PG_FAKE);
-	}
+			rw_enter(rw, RW_WRITER);
+			if (err != 0) {
+for (i = 0; i < npages; i++) {
+	pg = ap->a_m[i];
+	if ((pg->flags & PG_FAKE) != 0) {
+		uvm_pagefree(pg);
+	} else {
+		uvm_page_unbusy(, 1);
+	}
+}
+memset(ap->a_m, 0, sizeof(ap->a_m[0]) *
+npages);
+break;
+			}
+			pg->flags &= ~(PG_FAKE);
+		}
 
-	if (memwrite && uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN) {
-		/* For write faults, start dirtiness tracking. */
-		uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN);
+		if (memwrite && uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN) {
+			/* For write faults, start dirtiness tracking. */
+			uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN);
+		}
 	}
 	rw_exit(rw);
-	ap->a_m[ap->a_centeridx] = pg;
 
 	ZFS_EXIT(zfsvfs);
 	fstrans_done(mp);



CVS commit: src/sys/arch/x86/x86

2020-05-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 20 20:19:02 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
The boot CPU suffers a cache miss during TSC sync, before RDTSC.  Make the
secondary CPU take a miss as well to try and delay it an equal amount.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/x86/tsc.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/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.46 src/sys/arch/x86/x86/tsc.c:1.47
--- src/sys/arch/x86/x86/tsc.c:1.46	Tue May 19 21:56:51 2020
+++ src/sys/arch/x86/x86/tsc.c	Wed May 20 20:19:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.46 2020/05/19 21:56:51 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.47 2020/05/20 20:19:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.46 2020/05/19 21:56:51 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.47 2020/05/20 20:19:02 ad Exp $");
 
 #include 
 #include 
@@ -54,6 +54,7 @@ u_int	tsc_get_timecount(struct timecount
 
 static void	tsc_delay(unsigned int);
 
+static uint64_t	tsc_dummy_cacheline __cacheline_aligned;
 uint64_t	tsc_freq; /* exported for sysctl */
 static int64_t	tsc_drift_max = 1000;	/* max cycles */
 static int64_t	tsc_drift_observed;
@@ -200,7 +201,7 @@ tsc_sync_drift(int64_t drift)
  * Called during startup of APs, by the boot processor.  Interrupts
  * are disabled on entry.
  */
-static void
+static void __noinline
 tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
 {
 	uint64_t bptsc;
@@ -209,10 +210,13 @@ tsc_read_bp(struct cpu_info *ci, uint64_
 		panic("tsc_sync_bp: 1");
 	}
 
-	/* Flag it and read our TSC. */
+	/* Prepare a cache miss for the other side. */
+	(void)atomic_swap_uint((void *)_dummy_cacheline, 0);
+
+	/* Flag our readiness. */
 	atomic_or_uint(>ci_flags, CPUF_SYNCTSC);
 
-	/* Wait for remote to complete, and read ours again. */
+	/* Wait for other side then read our TSC. */
 	while ((ci->ci_flags & CPUF_SYNCTSC) != 0) {
 		__insn_barrier();
 	}
@@ -254,7 +258,7 @@ tsc_sync_bp(struct cpu_info *ci)
  * Called during startup of AP, by the AP itself.  Interrupts are
  * disabled on entry.
  */
-static void
+static void __noinline
 tsc_post_ap(struct cpu_info *ci)
 {
 	uint64_t tsc;
@@ -266,7 +270,12 @@ tsc_post_ap(struct cpu_info *ci)
 
 	/* Instruct primary to read its counter. */
 	atomic_and_uint(>ci_flags, ~CPUF_SYNCTSC);
-	tsc = rdtsc();
+
+	/* Suffer a cache miss, then read TSC. */
+	__insn_barrier();
+	tsc = tsc_dummy_cacheline;
+	__insn_barrier();
+	tsc += rdtsc();
 
 	/* Post result.  Ensure the whole value goes out atomically. */
 	(void)atomic_swap_64(_sync_val, tsc);



CVS commit: src/sys/arch/amd64/amd64

2020-05-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 20 18:39:25 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S

Log Message:
Deal with KMSAN fussiness.  Pointed out by msaitoh@.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/amd64/amd64/cpufunc.S

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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.54 src/sys/arch/amd64/amd64/cpufunc.S:1.55
--- src/sys/arch/amd64/amd64/cpufunc.S:1.54	Tue May 19 21:54:10 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Wed May 20 18:39:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.54 2020/05/19 21:54:10 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.55 2020/05/20 18:39:25 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -206,7 +206,23 @@ ENTRY(x86_hotpatch)
 END(x86_hotpatch)
 #endif /* !XENPV */
 
-ENTRY(tsc_get_timecount)
+/* Could be exact same as cpu_counter but for KASAN fussiness. */
+ENTRY(cpu_counter32)
+	movq	CPUVAR(CURLWP), %rcx
+1:
+	movq	L_NCSW(%rcx), %rdi
+	rdtsc
+	addl	CPUVAR(CC_SKEW), %eax
+	cmpq	%rdi, L_NCSW(%rcx)
+	jne	2f
+	KMSAN_INIT_RET(4)
+	ret
+2:
+	jmp	1b
+END(cpu_counter32)
+STRONG_ALIAS(tsc_get_timecount, cpu_counter32)
+
+ENTRY(cpu_counter)
 	movq	CPUVAR(CURLWP), %rcx
 1:
 	movq	L_NCSW(%rcx), %rdi
@@ -216,14 +232,11 @@ ENTRY(tsc_get_timecount)
 	addq	CPUVAR(CC_SKEW), %rax
 	cmpq	%rdi, L_NCSW(%rcx)
 	jne	2f
-	KMSAN_INIT_RET(4)
+	KMSAN_INIT_RET(8)
 	ret
 2:
 	jmp	1b
-END(tsc_get_timecount)
-
-STRONG_ALIAS(cpu_counter, tsc_get_timecount)
-STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
+END(cpu_counter)
 
 ENTRY(rdmsr_safe)
 	movq	CPUVAR(CURLWP), %r8



CVS commit: src/sys/uvm

2020-05-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 20 18:37:50 UTC 2020

Modified Files:
src/sys/uvm: uvm_loan.c

Log Message:
uvm_loanuobjpages():

- there are no pages to unbusy in the error case
- always clear the caller's page array


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/uvm/uvm_loan.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/uvm/uvm_loan.c
diff -u src/sys/uvm/uvm_loan.c:1.102 src/sys/uvm/uvm_loan.c:1.103
--- src/sys/uvm/uvm_loan.c:1.102	Tue May 19 21:52:04 2020
+++ src/sys/uvm/uvm_loan.c	Wed May 20 18:37:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_loan.c,v 1.102 2020/05/19 21:52:04 ad Exp $	*/
+/*	$NetBSD: uvm_loan.c,v 1.103 2020/05/20 18:37:50 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.102 2020/05/19 21:52:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.103 2020/05/20 18:37:50 ad Exp $");
 
 #include 
 #include 
@@ -538,6 +538,9 @@ uvm_loanuobjchunk(struct uvm_object *uob
 		/* loan out pages.  they will be unbusied whatever happens. */
 		error = uvm_loanpage(pgpp, npages, true);
 		rw_exit(uobj->vmobjlock);
+		if (error != 0) {
+			memset(pgpp, 0, sizeof(pgpp[0]) * npages);
+		}
 		return error;
 
 	case EAGAIN:
@@ -546,11 +549,6 @@ uvm_loanuobjchunk(struct uvm_object *uob
 		goto reget;
 
 	default:
-		if (npages > 0) {
-			rw_enter(uobj->vmobjlock, RW_WRITER);
-			uvm_page_unbusy(pgpp, npages);
-			rw_exit(uobj->vmobjlock);
-		}
 		return error;
 	}
 }
@@ -569,6 +567,7 @@ uvm_loanuobjpages(struct uvm_object *uob
 
 	KASSERT(npages > 0);
 
+	memset(pgpp, 0, sizeof(pgpp[0]) * npages);
 	for (ndone = 0; ndone < npages; ndone += chunk) {
 		chunk = MIN(UVM_LOAN_GET_CHUNK, npages - ndone);
 		error = uvm_loanuobjchunk(uobj, pgoff + (ndone << PAGE_SHIFT),



CVS commit: src/sys

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 22:22:15 UTC 2020

Modified Files:
src/sys/fs/tmpfs: tmpfs_vnops.c
src/sys/uvm: uvm_aobj.c uvm_bio.c uvm_object.c uvm_pager.h uvm_vnode.c

Log Message:
PR kern/32166: pgo_get protocol is ambiguous
Also problems with tmpfs+nfs noted by hannken@.

Don't pass PGO_ALLPAGES to pgo_get, and ignore PGO_DONTCARE in the
!PGO_LOCKED case.  In uao_get() have uvm_pagealloc() take care of page
zeroing and release busy pages on error.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/fs/tmpfs/tmpfs_vnops.c
cvs rdiff -u -r1.141 -r1.142 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.113 -r1.114 src/sys/uvm/uvm_bio.c
cvs rdiff -u -r1.21 -r1.22 src/sys/uvm/uvm_object.c
cvs rdiff -u -r1.48 -r1.49 src/sys/uvm/uvm_pager.h
cvs rdiff -u -r1.112 -r1.113 src/sys/uvm/uvm_vnode.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/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.140 src/sys/fs/tmpfs/tmpfs_vnops.c:1.141
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.140	Sun May 17 19:43:31 2020
+++ src/sys/fs/tmpfs/tmpfs_vnops.c	Tue May 19 22:22:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vnops.c,v 1.140 2020/05/17 19:43:31 ad Exp $	*/
+/*	$NetBSD: tmpfs_vnops.c,v 1.141 2020/05/19 22:22:15 ad Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007, 2020 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.140 2020/05/17 19:43:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.141 2020/05/19 22:22:15 ad Exp $");
 
 #include 
 #include 
@@ -1234,20 +1234,10 @@ tmpfs_getpages(void *v)
 		tmpfs_update_lazily(vp, tflags);
 	}
 
-	/*
-	 * Invoke the pager.
-	 *
-	 * Clean the array of pages before.  XXX: PR/32166
-	 * Note that vnode lock is shared with underlying UVM object.
-	 */
-	if ((flags & PGO_LOCKED) == 0 && pgs) {
-		memset(pgs, 0, sizeof(struct vm_pages *) * npages);
-	}
+	/* Invoke the pager.  The vnode vmobjlock is shared with the UAO. */
 	KASSERT(vp->v_uobj.vmobjlock == uobj->vmobjlock);
-
 	error = (*uobj->pgops->pgo_get)(uobj, offset, pgs, , centeridx,
 	access_type, advice, flags);
-
 #if defined(DEBUG)
 	if (!error && pgs) {
 		KASSERT(pgs[centeridx] != NULL);

Index: src/sys/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.141 src/sys/uvm/uvm_aobj.c:1.142
--- src/sys/uvm/uvm_aobj.c:1.141	Sun May 17 19:38:17 2020
+++ src/sys/uvm/uvm_aobj.c	Tue May 19 22:22:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.141 2020/05/17 19:38:17 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.141 2020/05/17 19:38:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -786,14 +786,12 @@ uao_put(struct uvm_object *uobj, voff_t 
  * 2: page is zero-fill-> allocate a new page and zero it.
  * 3: page is swapped out  -> fetch the page from swap.
  *
- * cases 1 and 2 can be handled with PGO_LOCKED, case 3 cannot.
- * so, if the "center" page hits case 3 (or any page, with PGO_ALLPAGES),
- * then we will need to return EBUSY.
+ * case 1 can be handled with PGO_LOCKED, cases 2 and 3 cannot.
+ * so, if the "center" page hits case 2/3 then we will need to return EBUSY.
  *
  * => prefer map unlocked (not required)
  * => object must be locked!  we will _unlock_ it before starting any I/O.
- * => flags: PGO_ALLPAGES: get all of the pages
- *   PGO_LOCKED: fault data structures are locked
+ * => flags: PGO_LOCKED: fault data structures are locked
  * => NOTE: offset is the offset of pps[0], _NOT_ pps[centeridx]
  * => NOTE: caller must check for released pages!!
  */
@@ -805,7 +803,6 @@ uao_get(struct uvm_object *uobj, voff_t 
 	voff_t current_offset;
 	struct vm_page *ptmp = NULL;	/* Quell compiler warning */
 	int lcv, gotpages, maxpages, swslot, pageidx;
-	bool done;
 	UVMHIST_FUNC("uao_get"); UVMHIST_CALLED(pdhist);
 
 	UVMHIST_LOG(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
@@ -841,7 +838,6 @@ uao_get(struct uvm_object *uobj, voff_t 
  		 */
 
 		uvm_page_array_init();
-		done = true;	/* be optimistic */
 		gotpages = 0;	/* # of pages we got so far */
 		for (lcv = 0; lcv < maxpages; lcv++) {
 			ptmp = uvm_page_array_fill_and_peek(, uobj,
@@ -880,16 +876,9 @@ uao_get(struct uvm_object *uobj, voff_t 
 		 * to unlock and do some waiting or I/O.
  		 */
 
-		if ((flags & PGO_ALLPAGES) != 0) {
-			for (int i = 0; i < maxpages; i++) {
-done &= (pps[i] != NULL);
-			}
-		} else {
-			done = (pps[centeridx] != NULL);
-		}
 		UVMHIST_LOG(pdhist, "<- done (done=%jd)", done, 0,0,0);
 		*npagesp = gotpages;
-		return done ? 0 : EBUSY;
+		return pps[centeridx] != NULL ? 0 : EBUSY;
 	}
 
 	/*
@@ -905,17 +894,6 @@ 

CVS commit: src/sys/arch/x86/x86

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:56:52 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
Ignore x86_delay, for xen


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/x86/x86/tsc.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/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.45 src/sys/arch/x86/x86/tsc.c:1.46
--- src/sys/arch/x86/x86/tsc.c:1.45	Tue May 19 21:43:36 2020
+++ src/sys/arch/x86/x86/tsc.c	Tue May 19 21:56:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.46 2020/05/19 21:56:51 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.46 2020/05/19 21:56:51 ad Exp $");
 
 #include 
 #include 
@@ -175,7 +175,6 @@ tsc_tc_init(void)
 		invariant = false;
 	} else if (vm_guest == VM_GUEST_NO) {
 		delay_func = tsc_delay;
-		x86_delay = tsc_delay;
 	}
 
 	if (tsc_freq != 0) {



CVS commit: src/sys/arch/xen/xen

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:57:25 UTC 2020

Modified Files:
src/sys/arch/xen/xen: xen_machdep.c

Log Message:
Remove duplicate def of tsc_get_timecount().


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/xen/xen_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/xen/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.24 src/sys/arch/xen/xen/xen_machdep.c:1.25
--- src/sys/arch/xen/xen/xen_machdep.c:1.24	Sat May  2 16:44:36 2020
+++ src/sys/arch/xen/xen/xen_machdep.c	Tue May 19 21:57:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.24 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.24 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.25 2020/05/19 21:57:25 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -227,13 +227,6 @@ static void xen_suspend_domain(void);
 static void xen_prepare_suspend(void);
 static void xen_prepare_resume(void);
 
-u_int
-tsc_get_timecount(struct timecounter *tc)
-{
-
-	panic("xen: tsc_get_timecount");
-}
-
 /*
  * this function sets up the machdep.xen.suspend sysctl(7) that
  * controls domain suspend/save.



CVS commit: src/sys/arch/amd64/amd64

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:54:10 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S

Log Message:
xen needs the TSC funcs too


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/amd64/amd64/cpufunc.S

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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.53 src/sys/arch/amd64/amd64/cpufunc.S:1.54
--- src/sys/arch/amd64/amd64/cpufunc.S:1.53	Tue May 19 21:40:55 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Tue May 19 21:54:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.53 2020/05/19 21:40:55 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.54 2020/05/19 21:54:10 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -167,25 +167,6 @@ END(x86_write_flags)
 
 STRONG_ALIAS(x86_write_psl,x86_write_flags)
 
-ENTRY(tsc_get_timecount)
-	movq	CPUVAR(CURLWP), %rcx
-1:
-	movq	L_NCSW(%rcx), %rdi
-	rdtsc
-	shlq	$32, %rdx
-	orq	%rdx, %rax
-	addq	CPUVAR(CC_SKEW), %rax
-	cmpq	%rdi, L_NCSW(%rcx)
-	jne	2f
-	KMSAN_INIT_RET(4)
-	ret
-2:
-	jmp	1b
-END(tsc_get_timecount)
-
-STRONG_ALIAS(cpu_counter, tsc_get_timecount)
-STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
-
 /*
  * %rdi = name
  * %rsi = sel
@@ -225,6 +206,25 @@ ENTRY(x86_hotpatch)
 END(x86_hotpatch)
 #endif /* !XENPV */
 
+ENTRY(tsc_get_timecount)
+	movq	CPUVAR(CURLWP), %rcx
+1:
+	movq	L_NCSW(%rcx), %rdi
+	rdtsc
+	shlq	$32, %rdx
+	orq	%rdx, %rax
+	addq	CPUVAR(CC_SKEW), %rax
+	cmpq	%rdi, L_NCSW(%rcx)
+	jne	2f
+	KMSAN_INIT_RET(4)
+	ret
+2:
+	jmp	1b
+END(tsc_get_timecount)
+
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
+
 ENTRY(rdmsr_safe)
 	movq	CPUVAR(CURLWP), %r8
 	movq	L_PCB(%r8), %r8



CVS commit: src/sys/uvm

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:52:04 UTC 2020

Modified Files:
src/sys/uvm: uvm_loan.c

Log Message:
uvm_loanuobjpages():

- vmobjlock is shared between tmpfs vnodes and UAOs now
- split into two routines, to simplify
- fix error recovery


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/uvm/uvm_loan.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/uvm/uvm_loan.c
diff -u src/sys/uvm/uvm_loan.c:1.101 src/sys/uvm/uvm_loan.c:1.102
--- src/sys/uvm/uvm_loan.c:1.101	Sun May 17 19:38:17 2020
+++ src/sys/uvm/uvm_loan.c	Tue May 19 21:52:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_loan.c,v 1.101 2020/05/17 19:38:17 ad Exp $	*/
+/*	$NetBSD: uvm_loan.c,v 1.102 2020/05/19 21:52:04 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.101 2020/05/17 19:38:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.102 2020/05/19 21:52:04 ad Exp $");
 
 #include 
 #include 
@@ -505,101 +505,81 @@ uvm_loanpage(struct vm_page **pgpp, int 
 #define	UVM_LOAN_GET_CHUNK	16
 
 /*
- * uvm_loanuobjpages: loan pages from a uobj out (O->K)
- *
- * => uobj shouldn't be locked.  (we'll lock it)
- * => fail with EBUSY if we meet a wired page.
+ * uvm_loanuobjchunk: helper for uvm_loanuobjpages()
  */
-int
-uvm_loanuobjpages(struct uvm_object *uobj, voff_t pgoff, int orignpages,
-struct vm_page **origpgpp)
+static int
+uvm_loanuobjchunk(struct uvm_object *uobj, voff_t pgoff, int orignpages,
+struct vm_page **pgpp)
 {
-	int ndone; /* # of pages loaned out */
-	struct vm_page **pgpp;
-	int error;
-	int i;
-	krwlock_t *slock;
-
-	pgpp = origpgpp;
-	for (ndone = 0; ndone < orignpages; ) {
-		int npages;
-		/* npendloan: # of pages busied but not loand out yet. */
-		int npendloan = 0xdead; /* XXX gcc */
-reget:
-		npages = MIN(UVM_LOAN_GET_CHUNK, orignpages - ndone);
-		rw_enter(uobj->vmobjlock, RW_WRITER);
-		error = (*uobj->pgops->pgo_get)(uobj,
-		pgoff + (ndone << PAGE_SHIFT), pgpp, , 0,
-		VM_PROT_READ, 0, PGO_SYNCIO);
-		if (error == EAGAIN) {
-			kpause("loanuopg", false, hz/2, NULL);
-			continue;
-		}
-		if (error)
-			goto fail;
-
-		KASSERT(npages > 0);
+	int error, npages;
 
-		/* loan and unbusy pages */
-		slock = NULL;
-		for (i = 0; i < npages; i++) {
-			krwlock_t *nextslock; /* slock for next page */
-			struct vm_page *pg = *pgpp;
-
-			/* XXX assuming that the page is owned by uobj */
-			KASSERT(pg->uobject != NULL);
-			nextslock = pg->uobject->vmobjlock;
-
-			if (slock != nextslock) {
-if (slock) {
-	KASSERT(npendloan > 0);
-	error = uvm_loanpage(pgpp - npendloan,
-	npendloan, true);
-	rw_exit(slock);
-	if (error)
-		goto fail;
-	ndone += npendloan;
-	KASSERT(origpgpp + ndone == pgpp);
-}
-slock = nextslock;
-npendloan = 0;
-rw_enter(slock, RW_WRITER);
-			}
+	rw_enter(uobj->vmobjlock, RW_WRITER);
+ reget:
+ 	npages = orignpages;
+	error = (*uobj->pgops->pgo_get)(uobj, pgoff, pgpp, , 0,
+	VM_PROT_READ, 0, PGO_SYNCIO);
+	switch (error) {
+	case 0:
+		KASSERT(npages == orignpages);
 
-			if ((pg->flags & PG_RELEASED) != 0) {
+		/* check for released pages */
+		rw_enter(uobj->vmobjlock, RW_WRITER);
+		for (int i = 0; i < npages; i++) {
+			KASSERT(pgpp[i]->uobject->vmobjlock == uobj->vmobjlock);
+			if ((pgpp[i]->flags & PG_RELEASED) != 0) {
 /*
  * release pages and try again.
  */
-rw_exit(slock);
-for (; i < npages; i++) {
-	pg = pgpp[i];
-	slock = pg->uobject->vmobjlock;
-
-	rw_enter(slock, RW_WRITER);
-	uvm_page_unbusy(, 1);
-	rw_exit(slock);
-}
+uvm_page_unbusy(pgpp, npages);
 goto reget;
 			}
+		}
 
-			npendloan++;
-			pgpp++;
-			KASSERT(origpgpp + ndone + npendloan == pgpp);
-		}
-		KASSERT(slock != NULL);
-		KASSERT(npendloan > 0);
-		error = uvm_loanpage(pgpp - npendloan, npendloan, true);
-		rw_exit(slock);
-		if (error)
-			goto fail;
-		ndone += npendloan;
-		KASSERT(origpgpp + ndone == pgpp);
+		/* loan out pages.  they will be unbusied whatever happens. */
+		error = uvm_loanpage(pgpp, npages, true);
+		rw_exit(uobj->vmobjlock);
+		return error;
+
+	case EAGAIN:
+		kpause("loanuopg", false, hz/2, NULL);
+		rw_enter(uobj->vmobjlock, RW_WRITER);
+		goto reget;
+
+	default:
+		if (npages > 0) {
+			rw_enter(uobj->vmobjlock, RW_WRITER);
+			uvm_page_unbusy(pgpp, npages);
+			rw_exit(uobj->vmobjlock);
+		}
+		return error;
 	}
+}
 
-	return 0;
+/*
+ * uvm_loanuobjpages: loan pages from a uobj out (O->K)
+ *
+ * => uobj shouldn't be locked.  (we'll lock it)
+ * => fail with EBUSY if we meet a wired page.
+ */
+int
+uvm_loanuobjpages(struct uvm_object *uobj, voff_t pgoff, int npages,
+struct vm_page **pgpp)
+{
+	int ndone, error, chunk;
 
-fail:
-	uvm_unloan(origpgpp, ndone, UVM_LOAN_TOPAGE);
+	

CVS commit: src/sys/uvm

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:45:35 UTC 2020

Modified Files:
src/sys/uvm: uvm_readahead.c

Log Message:
Drop & re-acquire vmobjlock less often.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/uvm/uvm_readahead.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/uvm/uvm_readahead.c
diff -u src/sys/uvm/uvm_readahead.c:1.12 src/sys/uvm/uvm_readahead.c:1.13
--- src/sys/uvm/uvm_readahead.c:1.12	Sun Mar  8 18:40:29 2020
+++ src/sys/uvm/uvm_readahead.c	Tue May 19 21:45:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_readahead.c,v 1.12 2020/03/08 18:40:29 ad Exp $	*/
+/*	$NetBSD: uvm_readahead.c,v 1.13 2020/05/19 21:45:35 ad Exp $	*/
 
 /*-
  * Copyright (c)2003, 2005, 2009 YAMAMOTO Takashi,
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.12 2020/03/08 18:40:29 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_readahead.c,v 1.13 2020/05/19 21:45:35 ad Exp $");
 
 #include 
 #include 
@@ -126,6 +126,8 @@ ra_startio(struct uvm_object *uobj, off_
 	DPRINTF(("%s: uobj=%p, off=%" PRIu64 ", endoff=%" PRIu64 "\n",
 	__func__, uobj, off, endoff));
 
+	KASSERT(rw_write_held(uobj->vmobjlock));
+
 	/*
 	 * Don't issue read-ahead if the last page of the range is already cached.
 	 * The assumption is that since the access is sequential, the intermediate
@@ -133,9 +135,7 @@ ra_startio(struct uvm_object *uobj, off_
 	 * too. This speeds up I/O using cache, since it avoids lookups and temporary
 	 * allocations done by full pgo_get.
 	 */
-	rw_enter(uobj->vmobjlock, RW_READER);
 	struct vm_page *pg = uvm_pagelookup(uobj, trunc_page(endoff - 1));
-	rw_exit(uobj->vmobjlock);
 	if (pg != NULL) {
 		DPRINTF(("%s:  off=%" PRIu64 ", sz=%zu already cached\n",
 		__func__, off, sz));
@@ -162,9 +162,9 @@ ra_startio(struct uvm_object *uobj, off_
 		 * use UVM_ADV_RANDOM to avoid recursion.
 		 */
 
-		rw_enter(uobj->vmobjlock, RW_WRITER);
 		error = (*uobj->pgops->pgo_get)(uobj, off, NULL,
 		, 0, VM_PROT_READ, UVM_ADV_RANDOM, PGO_NOTIMESTAMP);
+		rw_enter(uobj->vmobjlock, RW_WRITER);
 		DPRINTF(("%s:  off=%" PRIu64 ", bytelen=%zu -> %d\n",
 		__func__, off, bytelen, error));
 		if (error != 0 && error != EBUSY) {
@@ -332,9 +332,7 @@ do_readahead:
 		if (rasize >= RA_MINSIZE) {
 			off_t next;
 
-			rw_exit(uobj->vmobjlock);
 			next = ra_startio(uobj, raoff, rasize);
-			rw_enter(uobj->vmobjlock, RW_WRITER);
 			ra->ra_next = next;
 		}
 	}
@@ -362,6 +360,8 @@ uvm_readahead(struct uvm_object *uobj, o
 	if (size > RA_WINSIZE_MAX) {
 		size = RA_WINSIZE_MAX;
 	}
+	rw_enter(uobj->vmobjlock, RW_WRITER);
 	ra_startio(uobj, off, size);
+	rw_exit(uobj->vmobjlock);
 	return 0;
 }



CVS commit: src/sys/uvm

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:45:57 UTC 2020

Modified Files:
src/sys/uvm: uvm_vnode.c

Log Message:
Don't try to do readahead on tmpfs.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/uvm/uvm_vnode.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/uvm/uvm_vnode.c
diff -u src/sys/uvm/uvm_vnode.c:1.111 src/sys/uvm/uvm_vnode.c:1.112
--- src/sys/uvm/uvm_vnode.c:1.111	Sun Mar 22 18:32:42 2020
+++ src/sys/uvm/uvm_vnode.c	Tue May 19 21:45:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_vnode.c,v 1.111 2020/03/22 18:32:42 ad Exp $	*/
+/*	$NetBSD: uvm_vnode.c,v 1.112 2020/05/19 21:45:57 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.111 2020/03/22 18:32:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.112 2020/05/19 21:45:57 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -182,7 +182,7 @@ uvn_get(struct uvm_object *uobj, voff_t 
 	0, 0);
 
 	if (vp->v_type == VREG && (access_type & VM_PROT_WRITE) == 0
-	&& (flags & PGO_LOCKED) == 0) {
+	&& (flags & PGO_LOCKED) == 0 && vp->v_tag != VT_TMPFS) {
 		uvn_alloc_ractx(uobj);
 		uvm_ra_request(vp->v_ractx, advice, uobj, offset,
 		*npagesp << PAGE_SHIFT);



CVS commit: src/sys/arch/x86/x86

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:43:36 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
If the the TSC timecounter is good then use the TSC for DELAY() too.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/x86/tsc.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/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.44 src/sys/arch/x86/x86/tsc.c:1.45
--- src/sys/arch/x86/x86/tsc.c:1.44	Fri May  8 22:01:55 2020
+++ src/sys/arch/x86/x86/tsc.c	Tue May 19 21:43:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.44 2020/05/08 22:01:55 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.44 2020/05/08 22:01:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $");
 
 #include 
 #include 
@@ -52,6 +52,8 @@ __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.44
 
 u_int	tsc_get_timecount(struct timecounter *);
 
+static void	tsc_delay(unsigned int);
+
 uint64_t	tsc_freq; /* exported for sysctl */
 static int64_t	tsc_drift_max = 1000;	/* max cycles */
 static int64_t	tsc_drift_observed;
@@ -145,9 +147,11 @@ tsc_is_invariant(void)
 }
 
 /*
- * Initialize timecounter(9) of TSC.
- * This function is called after all secondary processors were up and
- * calculated the drift.
+ * Initialize timecounter(9) and DELAY() function of TSC.
+ *
+ * This function is called after all secondary processors were brought up
+ * and drift has been measured, and after any other potential delay funcs
+ * have been installed (e.g. lapic_delay()).
  */
 void
 tsc_tc_init(void)
@@ -169,6 +173,9 @@ tsc_tc_init(void)
 		(long long)tsc_drift_observed);
 		tsc_timecounter.tc_quality = -100;
 		invariant = false;
+	} else if (vm_guest == VM_GUEST_NO) {
+		delay_func = tsc_delay;
+		x86_delay = tsc_delay;
 	}
 
 	if (tsc_freq != 0) {
@@ -324,3 +331,16 @@ cpu_hascounter(void)
 
 	return cpu_feature[0] & CPUID_TSC;
 }
+
+static void
+tsc_delay(unsigned int us)
+{
+	uint64_t start, delta;
+
+	start = cpu_counter();
+	delta = (uint64_t)us * cpu_frequency(_info_primary) / 100;
+
+	while ((cpu_counter() - start) < delta) {
+		x86_pause();
+	}
+}



CVS commit: src/sys/arch

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:40:55 UTC 2020

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S
src/sys/arch/i386/i386: cpufunc.S i386func.S

Log Message:
Make cpu_counter(), cpu_counter32() and tsc_get_timecount() into a single
preemption-safe routine.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/i386/i386func.S

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/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.52 src/sys/arch/amd64/amd64/cpufunc.S:1.53
--- src/sys/arch/amd64/amd64/cpufunc.S:1.52	Fri May  8 21:58:03 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Tue May 19 21:40:55 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: cpufunc.S,v 1.52 2020/05/08 21:58:03 ad Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.53 2020/05/19 21:40:55 ad Exp $	*/
 
 /*
- * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -172,7 +172,9 @@ ENTRY(tsc_get_timecount)
 1:
 	movq	L_NCSW(%rcx), %rdi
 	rdtsc
-	addl	CPUVAR(CC_SKEW), %eax
+	shlq	$32, %rdx
+	orq	%rdx, %rax
+	addq	CPUVAR(CC_SKEW), %rax
 	cmpq	%rdi, L_NCSW(%rcx)
 	jne	2f
 	KMSAN_INIT_RET(4)
@@ -181,6 +183,9 @@ ENTRY(tsc_get_timecount)
 	jmp	1b
 END(tsc_get_timecount)
 
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
+
 /*
  * %rdi = name
  * %rsi = sel
@@ -252,23 +257,6 @@ ENTRY(msr_onfault)
 	ret
 END(msr_onfault)
 
-ENTRY(cpu_counter)
-	xorl	%eax, %eax
-	rdtsc
-	shlq	$32, %rdx
-	orq	%rdx, %rax
-	addq	CPUVAR(CC_SKEW), %rax
-	KMSAN_INIT_RET(8)
-	ret
-END(cpu_counter)
-
-ENTRY(cpu_counter32)
-	rdtsc
-	addl	CPUVAR(CC_SKEW), %eax
-	KMSAN_INIT_RET(4)
-	ret
-END(cpu_counter32)
-
 ENTRY(breakpoint)
 	pushq	%rbp
 	movq	%rsp, %rbp

Index: src/sys/arch/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.40 src/sys/arch/i386/i386/cpufunc.S:1.41
--- src/sys/arch/i386/i386/cpufunc.S:1.40	Sat May  2 17:14:01 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Tue May 19 21:40:55 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: cpufunc.S,v 1.40 2020/05/02 17:14:01 bouyer Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $	*/
 
 /*-
- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.40 2020/05/02 17:14:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -163,18 +163,24 @@ ENTRY(msr_onfault)
 	ret
 END(msr_onfault)
 
-ENTRY(cpu_counter)
+ENTRY(tsc_get_timecount)
+	movl	CPUVAR(CURLWP), %ecx
+1:
+	pushl	L_NCSW(%ecx)
 	rdtsc
 	addl	CPUVAR(CC_SKEW), %eax
 	adcl	CPUVAR(CC_SKEW+4), %edx
+	popl	%edx
+	cmpl	%edx, L_NCSW(%ecx)
+	jne	2f
 	ret
-END(cpu_counter)
-
-ENTRY(cpu_counter32)
-	rdtsc
-	addl	CPUVAR(CC_SKEW), %eax
+2:
+	jmp	1b
 	ret
-END(cpu_counter32)
+END(tsc_get_timecount)
+
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
 
 ENTRY(breakpoint)
 	pushl	%ebp

Index: src/sys/arch/i386/i386/i386func.S
diff -u src/sys/arch/i386/i386/i386func.S:1.21 src/sys/arch/i386/i386/i386func.S:1.22
--- src/sys/arch/i386/i386/i386func.S:1.21	Sat May  4 07:20:22 2019
+++ src/sys/arch/i386/i386/i386func.S	Tue May 19 21:40:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386func.S,v 1.21 2019/05/04 07:20:22 maxv Exp $	*/
+/*	$NetBSD: i386func.S,v 1.22 2020/05/19 21:40:55 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386func.S,v 1.21 2019/05/04 07:20:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386func.S,v 1.22 2020/05/19 21:40:55 ad Exp $");
 
 #include 
 #include 
@@ -137,17 +137,3 @@ ENTRY(lgdt)
 	movl	%eax, %fs
 	jmp	_C_LABEL(x86_flush)
 END(lgdt)
-
-ENTRY(tsc_get_timecount)
-	movl	CPUVAR(CURLWP), %ecx
-1:
-	pushl	L_NCSW(%ecx)
-	rdtsc
-	addl	CPUVAR(CC_SKEW), %eax
-	popl	%edx
-	cmpl	%edx, L_NCSW(%ecx)
-	jne	2f
-	ret
-2:
-	jmp	1b
-END(tsc_get_timecount)



CVS commit: src/sys/arch/x86/x86

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:39:11 UTC 2020

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
lapic_delay() disable preemption since the state is very CPU dependent.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/x86/x86/lapic.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/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.78 src/sys/arch/x86/x86/lapic.c:1.79
--- src/sys/arch/x86/x86/lapic.c:1.78	Sat May  2 16:44:36 2020
+++ src/sys/arch/x86/x86/lapic.c	Tue May 19 21:39:11 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: lapic.c,v 1.78 2020/05/02 16:44:36 bouyer Exp $	*/
+/*	$NetBSD: lapic.c,v 1.79 2020/05/19 21:39:11 ad Exp $	*/
 
 /*-
- * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2000, 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.78 2020/05/02 16:44:36 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.79 2020/05/19 21:39:11 ad Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -727,12 +727,17 @@ static void
 lapic_delay(unsigned int usec)
 {
 	int32_t xtick, otick;
-	int64_t deltat;		/* XXX may want to be 64bit */
+	int64_t deltat;
 
+	/* XXX Bad to disable preemption, but it's tied to the cpu. */
+	kpreempt_disable();
 	otick = lapic_gettick();
 
-	if (usec <= 0)
+	if (usec <= 0) {
+		kpreempt_enable();
 		return;
+	}
+
 	if (usec <= 25)
 		deltat = lapic_delaytab[usec];
 	else
@@ -741,7 +746,7 @@ lapic_delay(unsigned int usec)
 	while (deltat > 0) {
 		xtick = lapic_gettick();
 		if (lapic_broken_periodic && xtick == 0 && otick == 0) {
-			lapic_initclocks();
+			lapic_reset();
 			xtick = lapic_gettick();
 			if (xtick == 0)
 panic("lapic timer stopped ticking");
@@ -754,6 +759,7 @@ lapic_delay(unsigned int usec)
 
 		x86_pause();
 	}
+	kpreempt_enable();
 }
 
 /*



CVS commit: src/sys/arch/x86/x86

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 21:14:20 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Comment


To generate a diff of this commit:
cvs rdiff -u -r1.392 -r1.393 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.392 src/sys/arch/x86/x86/pmap.c:1.393
--- src/sys/arch/x86/x86/pmap.c:1.392	Fri May 15 22:22:44 2020
+++ src/sys/arch/x86/x86/pmap.c	Tue May 19 21:14:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.392 2020/05/15 22:22:44 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.393 2020/05/19 21:14:20 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.392 2020/05/15 22:22:44 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.393 2020/05/19 21:14:20 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -3025,8 +3025,7 @@ pmap_zap_ptp(struct pmap *pmap, struct v
 
 	/*
 	 * Start at the lowest entered VA, and scan until there are no more
-	 * PTEs in the PTPs.  The goal is to disconnect PV entries and patch
-	 * up the pmap's stats.  No PTEs will be modified.
+	 * PTEs in the PTPs.
 	 */
 	tree = _PAGE_TO_PP(ptp)->pp_rb;
 	pve = RB_TREE_MIN(tree);



CVS commit: src/sys/uvm

2020-05-19 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue May 19 20:46:39 UTC 2020

Modified Files:
src/sys/uvm: uvm_page.c

Log Message:
UVM_PAGE_TRKOWN: print the LID too


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/uvm/uvm_page.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/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.236 src/sys/uvm/uvm_page.c:1.237
--- src/sys/uvm/uvm_page.c:1.236	Sun May 17 17:12:28 2020
+++ src/sys/uvm/uvm_page.c	Tue May 19 20:46:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.236 2020/05/17 17:12:28 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.237 2020/05/19 20:46:39 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.236 2020/05/17 17:12:28 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.237 2020/05/19 20:46:39 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1766,8 +1766,8 @@ uvm_page_own(struct vm_page *pg, const c
 		KASSERT((pg->flags & PG_BUSY) != 0);
 		if (pg->owner_tag) {
 			printf("uvm_page_own: page %p already owned "
-			"by proc %d [%s]\n", pg,
-			pg->owner, pg->owner_tag);
+			"by proc %d.%d [%s]\n", pg,
+			pg->owner, pg->lowner, pg->owner_tag);
 			panic("uvm_page_own");
 		}
 		pg->owner = curproc->p_pid;
@@ -2215,8 +2215,8 @@ uvm_page_printit(struct vm_page *pg, boo
 	(*pr)("  pa=0x%lx\n", (long)VM_PAGE_TO_PHYS(pg));
 #if defined(UVM_PAGE_TRKOWN)
 	if (pg->flags & PG_BUSY)
-		(*pr)("  owning process = %d, tag=%s\n",
-		pg->owner, pg->owner_tag);
+		(*pr)("  owning process = %d.%d, tag=%s\n",
+		pg->owner, pg->lowner, pg->owner_tag);
 	else
 		(*pr)("  page not busy, no owner\n");
 #else



  1   2   3   4   5   6   7   8   >