CVS commit: src/sys/uvm

2021-07-01 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Thu Jul  1 15:06:01 UTC 2021

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

Log Message:
in uvm_mapent_forkzero(), if the old entry was an object mapping,
appease a debug check by setting the new entry offset to zero along with
setting the new entry object pointer to NULL.

Reported-by: syzbot+de8e4b223a3838c73...@syzkaller.appspotmail.com
Reported-by: syzbot+efaea991addfdcc5a...@syzkaller.appspotmail.com
Reported-by: syzbot+15d1e19dff9209c2e...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.389 -r1.390 src/sys/uvm/uvm_map.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_map.c
diff -u src/sys/uvm/uvm_map.c:1.389 src/sys/uvm/uvm_map.c:1.390
--- src/sys/uvm/uvm_map.c:1.389	Sun Jun 20 07:11:38 2021
+++ src/sys/uvm/uvm_map.c	Thu Jul  1 15:06:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.389 2021/06/20 07:11:38 mrg Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.390 2021/07/01 15:06:01 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.389 2021/06/20 07:11:38 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.390 2021/07/01 15:06:01 chs Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -4451,6 +4451,7 @@ uvm_mapent_forkzero(struct vm_map *new_m
 			new_entry->object.uvm_obj->pgops->pgo_detach(
 			new_entry->object.uvm_obj);
 		new_entry->object.uvm_obj = NULL;
+		new_entry->offset = 0;
 		new_entry->etype &= ~UVM_ET_OBJ;
 	}
 }



CVS commit: src/sys/uvm

2021-06-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jun 20 07:11:39 UTC 2021

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

Log Message:
remove diag-only printf() that fires when an unlinked file is mmapped
and someone runs ps(1) or similar.


To generate a diff of this commit:
cvs rdiff -u -r1.388 -r1.389 src/sys/uvm/uvm_map.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_map.c
diff -u src/sys/uvm/uvm_map.c:1.388 src/sys/uvm/uvm_map.c:1.389
--- src/sys/uvm/uvm_map.c:1.388	Sat Apr 17 21:37:21 2021
+++ src/sys/uvm/uvm_map.c	Sun Jun 20 07:11:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.388 2021/04/17 21:37:21 mrg Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.389 2021/06/20 07:11:38 mrg Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.388 2021/04/17 21:37:21 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.389 2021/06/20 07:11:38 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -5164,11 +5164,6 @@ fill_vmentry(struct lwp *l, struct proc 
 kve->kve_vn_fsid = va.va_fsid;
 error = vnode_to_path(kve->kve_path,
 sizeof(kve->kve_path) / 2, vp, l, p);
-#ifdef DIAGNOSTIC
-if (error)
-	printf("%s: vp %p error %d\n", __func__,
-		vp, error);
-#endif
 			}
 		} else if (UVM_OBJ_IS_KERN_OBJECT(uobj)) {
 			kve->kve_type = KVME_TYPE_KERN;



CVS commit: src/sys/uvm

2021-05-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 31 10:57:02 UTC 2021

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

Log Message:
uvm: Make uvm_extern.h (more) self-contained, needs sys/types.h.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 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.231 src/sys/uvm/uvm_extern.h:1.232
--- src/sys/uvm/uvm_extern.h:1.231	Fri Aug 14 09:06:15 2020
+++ src/sys/uvm/uvm_extern.h	Mon May 31 10:57:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.231 2020/08/14 09:06:15 chs Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.232 2021/05/31 10:57:02 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -72,6 +72,8 @@
  * NOTE: vm system calls are prototyped in syscallargs.h
  */
 
+#include 
+
 /*
  * defines
  */



CVS commit: src/sys/uvm

2021-05-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun May 23 00:36:37 UTC 2021

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

Log Message:
avoid taking locks that aren't initialised.

fixes panic when typing 'reboot' at the askroot prompt.


To generate a diff of this commit:
cvs rdiff -u -r1.203 -r1.204 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.203 src/sys/uvm/uvm_swap.c:1.204
--- src/sys/uvm/uvm_swap.c:1.203	Sat Mar 13 15:29:55 2021
+++ src/sys/uvm/uvm_swap.c	Sun May 23 00:36:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.203 2021/03/13 15:29:55 skrll Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.204 2021/05/23 00:36:36 mrg Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.203 2021/03/13 15:29:55 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.204 2021/05/23 00:36:36 mrg Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -202,6 +202,7 @@ static struct swap_priority swap_priorit
 /* locks */
 static kmutex_t uvm_swap_data_lock __cacheline_aligned;
 static krwlock_t swap_syscall_lock;
+bool uvm_swap_init_done = false;
 
 /* workqueue and use counter for swap to regular files */
 static int sw_reg_count = 0;
@@ -296,6 +297,8 @@ uvm_swap_init(void)
 	pool_init(_pool, sizeof(struct vndbuf), 0, 0, 0, "swp vnd",
 	NULL, IPL_BIO);
 
+	uvm_swap_init_done = true;
+
 	UVMHIST_LOG(pdhist, "<- done", 0, 0, 0, 0);
 }
 
@@ -1141,6 +1144,8 @@ uvm_swap_shutdown(struct lwp *l)
 	struct vnode *vp;
 	int error;
 
+	if (!uvm_swap_init_done)
+		return;
 	printf("turning off swap...");
 	rw_enter(_syscall_lock, RW_WRITER);
 	mutex_enter(_swap_data_lock);



CVS commit: src/sys/uvm/pmap

2021-05-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue May  4 09:05:34 UTC 2021

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Always expose pmap_tlb_update_addr now that all current PMAP_HWPAGEWALKERs
(arm) users provide the required functions.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.43 src/sys/uvm/pmap/pmap_tlb.c:1.44
--- src/sys/uvm/pmap/pmap_tlb.c:1.43	Sat May  1 14:00:57 2021
+++ src/sys/uvm/pmap/pmap_tlb.c	Tue May  4 09:05:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.43 2021/05/01 14:00:57 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.44 2021/05/04 09:05:34 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.43 2021/05/01 14:00:57 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.44 2021/05/04 09:05:34 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -733,7 +733,6 @@ pmap_tlb_shootdown_bystanders(pmap_t pm)
 }
 #endif /* MULTIPROCESSOR && PMAP_TLB_NEED_SHOOTDOWN */
 
-#ifndef PMAP_HWPAGEWALKER
 int
 pmap_tlb_update_addr(pmap_t pm, vaddr_t va, pt_entry_t pte, u_int flags)
 {
@@ -773,7 +772,6 @@ pmap_tlb_update_addr(pmap_t pm, vaddr_t 
 
 	return rv;
 }
-#endif /* !PMAP_HWPAGEWALKER */
 
 void
 pmap_tlb_invalidate_addr(pmap_t pm, vaddr_t va)



CVS commit: src/sys/uvm/pmap

2021-05-01 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat May  1 14:00:57 UTC 2021

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.42 src/sys/uvm/pmap/pmap_tlb.c:1.43
--- src/sys/uvm/pmap/pmap_tlb.c:1.42	Sat May  1 06:56:41 2021
+++ src/sys/uvm/pmap/pmap_tlb.c	Sat May  1 14:00:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.42 2021/05/01 06:56:41 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.43 2021/05/01 14:00:57 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.42 2021/05/01 06:56:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.43 2021/05/01 14:00:57 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -733,6 +733,7 @@ pmap_tlb_shootdown_bystanders(pmap_t pm)
 }
 #endif /* MULTIPROCESSOR && PMAP_TLB_NEED_SHOOTDOWN */
 
+#ifndef PMAP_HWPAGEWALKER
 int
 pmap_tlb_update_addr(pmap_t pm, vaddr_t va, pt_entry_t pte, u_int flags)
 {
@@ -772,6 +773,7 @@ pmap_tlb_update_addr(pmap_t pm, vaddr_t 
 
 	return rv;
 }
+#endif /* !PMAP_HWPAGEWALKER */
 
 void
 pmap_tlb_invalidate_addr(pmap_t pm, vaddr_t va)



CVS commit: src/sys/uvm/pmap

2021-05-01 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat May  1 06:56:41 UTC 2021

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Expose pmap_tlb_update_addr to the PMAP_HWPAGEWALKER platforms


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.41 src/sys/uvm/pmap/pmap_tlb.c:1.42
--- src/sys/uvm/pmap/pmap_tlb.c:1.41	Thu Sep 24 06:45:58 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Sat May  1 06:56:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.41 2020/09/24 06:45:58 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.42 2021/05/01 06:56:41 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.41 2020/09/24 06:45:58 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.42 2021/05/01 06:56:41 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -733,7 +733,6 @@ pmap_tlb_shootdown_bystanders(pmap_t pm)
 }
 #endif /* MULTIPROCESSOR && PMAP_TLB_NEED_SHOOTDOWN */
 
-#ifndef PMAP_HWPAGEWALKER
 int
 pmap_tlb_update_addr(pmap_t pm, vaddr_t va, pt_entry_t pte, u_int flags)
 {
@@ -773,7 +772,6 @@ pmap_tlb_update_addr(pmap_t pm, vaddr_t 
 
 	return rv;
 }
-#endif /* !PMAP_HWPAGEWALKER */
 
 void
 pmap_tlb_invalidate_addr(pmap_t pm, vaddr_t va)



CVS commit: src/sys/uvm

2021-04-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Apr 17 21:37:21 UTC 2021

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

Log Message:
fix error in previous: UVMHIST_PDHIST_SIZE needs to stay next to pdhistbuf[].


To generate a diff of this commit:
cvs rdiff -u -r1.387 -r1.388 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.132 -r1.133 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_map.c
diff -u src/sys/uvm/uvm_map.c:1.387 src/sys/uvm/uvm_map.c:1.388
--- src/sys/uvm/uvm_map.c:1.387	Sat Apr 17 01:53:58 2021
+++ src/sys/uvm/uvm_map.c	Sat Apr 17 21:37:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.387 2021/04/17 01:53:58 mrg Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.388 2021/04/17 21:37:21 mrg Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.387 2021/04/17 01:53:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.388 2021/04/17 21:37:21 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -105,9 +105,6 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 
 #ifndef UVMHIST_MAPHIST_SIZE
 #define UVMHIST_MAPHIST_SIZE 100
 #endif
-#ifndef UVMHIST_PDHIST_SIZE
-#define UVMHIST_PDHIST_SIZE 100
-#endif
 static struct kern_history_ent maphistbuf[UVMHIST_MAPHIST_SIZE];
 UVMHIST_DEFINE(maphist) = UVMHIST_INITIALIZER(maphist, maphistbuf);
 #endif

Index: src/sys/uvm/uvm_pdaemon.c
diff -u src/sys/uvm/uvm_pdaemon.c:1.132 src/sys/uvm/uvm_pdaemon.c:1.133
--- src/sys/uvm/uvm_pdaemon.c:1.132	Sat Apr 17 01:53:58 2021
+++ src/sys/uvm/uvm_pdaemon.c	Sat Apr 17 21:37:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pdaemon.c,v 1.132 2021/04/17 01:53:58 mrg Exp $	*/
+/*	$NetBSD: uvm_pdaemon.c,v 1.133 2021/04/17 21:37:21 mrg Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.132 2021/04/17 01:53:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.133 2021/04/17 21:37:21 mrg Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -88,6 +88,9 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.
 #include 
 
 #ifdef UVMHIST
+#ifndef UVMHIST_PDHIST_SIZE
+#define UVMHIST_PDHIST_SIZE 100
+#endif
 static struct kern_history_ent pdhistbuf[UVMHIST_PDHIST_SIZE];
 UVMHIST_DEFINE(pdhist) = UVMHIST_INITIALIZER(pdhisthist, pdhistbuf);
 #endif



CVS commit: src/sys/uvm

2021-04-01 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Thu Apr  1 06:26:26 UTC 2021

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

Log Message:
Add a sysctl hashstat collector for ubchash.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 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.125 src/sys/uvm/uvm_bio.c:1.126
--- src/sys/uvm/uvm_bio.c:1.125	Sat Mar 13 15:29:55 2021
+++ src/sys/uvm/uvm_bio.c	Thu Apr  1 06:26:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.125 2021/03/13 15:29:55 skrll Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.126 2021/04/01 06:26:26 simonb Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.125 2021/03/13 15:29:55 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.126 2021/04/01 06:26:26 simonb Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 		/* for ilog2() */
 
@@ -61,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 
 static int	ubc_fault(struct uvm_faultinfo *, vaddr_t, struct vm_page **,
 			  int, int, vm_prot_t, int);
 static struct ubc_map *ubc_find_mapping(struct uvm_object *, voff_t);
+static int	ubchash_stats(struct hashstat_sysctl *hs, bool fill);
 #ifdef UBC_USE_PMAP_DIRECT
 static int __noinline ubc_uiomove_direct(struct uvm_object *, struct uio *, vsize_t,
 			  int, int);
@@ -215,6 +217,8 @@ ubc_init(void)
 UVM_ADV_RANDOM, UVM_FLAG_NOMERGE)) != 0) {
 		panic("ubc_init: failed to map ubc_object");
 	}
+
+	hashstat_register("ubchash", ubchash_stats);
 }
 
 void
@@ -1104,3 +1108,35 @@ ubc_purge(struct uvm_object *uobj)
 	}
 	rw_exit(ubc_object.uobj.vmobjlock);
 }
+
+static int
+ubchash_stats(struct hashstat_sysctl *hs, bool fill)
+{
+	struct ubc_map *umap;
+	uint64_t chain;
+
+	strlcpy(hs->hash_name, "ubchash", sizeof(hs->hash_name));
+	strlcpy(hs->hash_desc, "ubc object hash", sizeof(hs->hash_desc));
+	if (!fill)
+		return 0;
+
+	hs->hash_size = ubc_object.hashmask + 1;
+
+	for (size_t i = 0; i < hs->hash_size; i++) {
+		chain = 0;
+		rw_enter(ubc_object.uobj.vmobjlock, RW_READER);
+		LIST_FOREACH(umap, _object.hash[i], hash) {
+			chain++;
+		}
+		rw_exit(ubc_object.uobj.vmobjlock);
+		if (chain > 0) {
+			hs->hash_used++;
+			hs->hash_items += chain;
+			if (chain > hs->hash_maxchain)
+hs->hash_maxchain = chain;
+		}
+		preempt_point();
+	}
+
+	return 0;
+}



CVS commit: src/sys/uvm

2021-03-26 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Mar 26 09:35:18 UTC 2021

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

Log Message:
in uvm_pglistalloc_contig_aggressive(), avoid looking forward past
the end of the target range of the physseg.
fixes PR 56074.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 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.87 src/sys/uvm/uvm_pglist.c:1.88
--- src/sys/uvm/uvm_pglist.c:1.87	Wed Mar 24 06:37:27 2021
+++ src/sys/uvm/uvm_pglist.c	Fri Mar 26 09:35:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.87 2021/03/24 06:37:27 skrll Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.88 2021/03/26 09:35:18 chs Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.87 2021/03/24 06:37:27 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.88 2021/03/26 09:35:18 chs Exp $");
 
 #include 
 #include 
@@ -401,6 +401,9 @@ uvm_pglistalloc_contig_aggressive(int nu
 		 * Look forward for any remaining pages.
 		 */
 
+		if (spa + ptoa(num) > rhi) {
+			continue;
+		}
 		for (; run < num; run++) {
 			pg = PHYS_TO_VM_PAGE(spa + ptoa(run));
 			if ((pg->flags & PG_PGLCA) == 0) {



CVS commit: src/sys/uvm

2021-03-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Mar 24 06:37:27 UTC 2021

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

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/uvm/uvm_pglist.c:1.87
--- src/sys/uvm/uvm_pglist.c:1.86	Wed Oct  7 17:51:50 2020
+++ src/sys/uvm/uvm_pglist.c	Wed Mar 24 06:37:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.86 2020/10/07 17:51:50 chs Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.87 2021/03/24 06:37:27 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.86 2020/10/07 17:51:50 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.87 2021/03/24 06:37:27 skrll Exp $");
 
 #include 
 #include 
@@ -261,7 +261,7 @@ uvm_pglistalloc_c_ps(uvm_physseg_t psi, 
 		 */
 		cnt = roundup2(cnt, alignment);
 		/*
-		 * The number of pages we can skip checking 
+		 * The number of pages we can skip checking
 		 * (might be 0 if cnt > num).
 		 */
 		skip = uimax(num - cnt, 0);
@@ -493,7 +493,7 @@ out:
 	/*
 	 * If that didn't work, try the more aggressive approach.
 	 */
-	
+
 	if (error) {
 		if (waitok) {
 			error = uvm_pglistalloc_contig_aggressive(num, low, high,



CVS commit: src/sys/uvm

2021-03-13 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Mar 13 15:29:56 UTC 2021

Modified Files:
src/sys/uvm: uvm_amap.c uvm_aobj.c uvm_bio.c uvm_device.c uvm_km.c
uvm_map.c uvm_swap.c uvm_vnode.c
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Consistently use %#jx instead of 0x%jx or just %jx in UVMHIST_LOG formats


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/uvm/uvm_amap.c
cvs rdiff -u -r1.152 -r1.153 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.124 -r1.125 src/sys/uvm/uvm_bio.c
cvs rdiff -u -r1.71 -r1.72 src/sys/uvm/uvm_device.c
cvs rdiff -u -r1.159 -r1.160 src/sys/uvm/uvm_km.c
cvs rdiff -u -r1.385 -r1.386 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.202 -r1.203 src/sys/uvm/uvm_swap.c
cvs rdiff -u -r1.117 -r1.118 src/sys/uvm/uvm_vnode.c
cvs rdiff -u -r1.26 -r1.27 src/sys/uvm/pmap/pmap_segtab.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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.125 src/sys/uvm/uvm_amap.c:1.126
--- src/sys/uvm/uvm_amap.c:1.125	Mon Sep 21 18:41:59 2020
+++ src/sys/uvm/uvm_amap.c	Sat Mar 13 15:29:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.125 2020/09/21 18:41:59 chs Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.126 2021/03/13 15:29:55 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.125 2020/09/21 18:41:59 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.126 2021/03/13 15:29:55 skrll Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -827,7 +827,7 @@ amap_copy(struct vm_map *map, struct vm_
 	vsize_t len;
 
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLARGS(maphist, "  (map=%#j, entry=%#j, flags=%jd)",
+	UVMHIST_CALLARGS(maphist, "  (map=%#jx, entry=%#jx, flags=%#jx)",
 	(uintptr_t)map, (uintptr_t)entry, flags, -2);
 
 	KASSERT(map != kernel_map);	/* we use nointr pool */
@@ -903,7 +903,7 @@ amap_copy(struct vm_map *map, struct vm_
 		return;
 	}
 
-	UVMHIST_LOG(maphist,"  amap=%#j, ref=%jd, must copy it",
+	UVMHIST_LOG(maphist,"  amap=%#jx, ref=%jd, must copy it",
 	(uintptr_t)srcamap, srcamap->am_ref, 0, 0);
 
 	/*

Index: src/sys/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.152 src/sys/uvm/uvm_aobj.c:1.153
--- src/sys/uvm/uvm_aobj.c:1.152	Wed Nov  4 01:30:19 2020
+++ src/sys/uvm/uvm_aobj.c	Sat Mar 13 15:29:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.152 2020/11/04 01:30:19 chs Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.153 2021/03/13 15:29:55 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.152 2020/11/04 01:30:19 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.153 2021/03/13 15:29:55 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -810,7 +810,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 	struct uvm_page_array a;
 
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLARGS(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
+	UVMHIST_CALLARGS(pdhist, "aobj=%#jx offset=%jd, flags=%#jx",
 		(uintptr_t)uobj, offset, flags,0);
 
 	/*

Index: src/sys/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.124 src/sys/uvm/uvm_bio.c:1.125
--- src/sys/uvm/uvm_bio.c:1.124	Tue Nov 10 04:27:22 2020
+++ src/sys/uvm/uvm_bio.c	Sat Mar 13 15:29:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.124 2020/11/10 04:27:22 chs Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.125 2021/03/13 15:29:55 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.124 2020/11/10 04:27:22 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.125 2021/03/13 15:29:55 skrll Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -342,7 +342,7 @@ ubc_fault(struct uvm_faultinfo *ufi, vad
 	 */
 
 	access_type = umap->writelen ? VM_PROT_WRITE : VM_PROT_READ;
-	UVMHIST_LOG(ubchist, "va 0x%jx ubc_offset 0x%jx access_type %jd",
+	UVMHIST_LOG(ubchist, "va %#jx ubc_offset %#jx access_type %jd",
 	va, ubc_offset, access_type, 0);
 
 	if ((access_type & VM_PROT_WRITE) != 0) {
@@ -374,9 +374,9 @@ again:
 	memset(pgs, 0, sizeof (pgs));
 	rw_enter(uobj->vmobjlock, RW_WRITER);
 
-	UVMHIST_LOG(ubchist, "slot_offset 0x%jx writeoff 0x%jx writelen 0x%jx ",
+	UVMHIST_LOG(ubchist, "slot_offset %#jx writeoff %#jx writelen %#jx ",
 	slot_offset, umap->writeoff, umap->writelen, 0);
-	UVMHIST_LOG(ubchist, "getpages uobj %#jx offset 0x%jx npages %jd",
+	UVMHIST_LOG(ubchist, "getpages uobj %#jx offset %#jx npages %jd",
 	(uintptr_t)uobj, umap->offset + slot_offset, npages, 0);
 
 	error = (*uobj->pgops->pgo_get)(uobj, umap->offset + slot_offset, pgs,
@@ -409,7 +409,7 @@ again:
 	va = ufi->orig_rvaddr;
 	eva = ufi->orig_rvaddr + (npages << PAGE_SHIFT);
 
-	UVMHIST_LOG(ubchist, "va 0x%jx eva 0x%jx", va, eva, 0, 0);
+	UVMHIST_LOG(ubchist, "va %#jx eva %#jx", va, eva, 0, 

CVS commit: src/sys/uvm/pmap

2021-03-13 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Mar 13 15:29:13 UTC 2021

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

Log Message:
Don't use %jx for 0 or 1 - just use %jd in UVMHIST_LOG format.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/uvm/pmap/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/uvm/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.58 src/sys/uvm/pmap/pmap.c:1.59
--- src/sys/uvm/pmap/pmap.c:1.58	Sun Dec 20 16:38:26 2020
+++ src/sys/uvm/pmap/pmap.c	Sat Mar 13 15:29:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.58 2020/12/20 16:38:26 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.59 2021/03/13 15:29:13 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.58 2020/12/20 16:38:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.59 2021/03/13 15:29:13 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -950,7 +950,7 @@ pmap_update(struct pmap *pmap)
 	pmap_tlb_miss_lock_exit();
 	kpreempt_enable();
 
-	UVMHIST_LOG(pmaphist, " <-- done (kernel=%jx)",
+	UVMHIST_LOG(pmaphist, " <-- done (kernel=%jd)",
 		(pmap == pmap_kernel() ? 1 : 0), 0, 0, 0);
 }
 
@@ -969,7 +969,7 @@ pmap_pte_remove(pmap_t pmap, vaddr_t sva
 	const bool is_kernel_pmap_p = (pmap == pmap_kernel());
 
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLARGS(pmaphist, "(pmap=%#jx kernel=%jx va=%#jx..%#jx)",
+	UVMHIST_CALLARGS(pmaphist, "(pmap=%#jx kernel=%jd va=%#jx..%#jx)",
 	(uintptr_t)pmap, (pmap == pmap_kernel() ? 1 : 0), sva, eva);
 	UVMHIST_LOG(pmaphist, "ptep=%#jx, flags(npte)=%#jx)",
 	(uintptr_t)ptep, flags, 0, 0);
@@ -1113,7 +1113,7 @@ pmap_pte_protect(pmap_t pmap, vaddr_t sv
 	const vm_prot_t prot = (flags & VM_PROT_ALL);
 
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLARGS(pmaphist, "(pmap=%#jx kernel=%jx va=%#jx..%#jx)",
+	UVMHIST_CALLARGS(pmaphist, "(pmap=%#jx kernel=%jd va=%#jx..%#jx)",
 	(uintptr_t)pmap, (pmap == pmap_kernel() ? 1 : 0), sva, eva);
 	UVMHIST_LOG(pmaphist, "ptep=%#jx, flags(npte)=%#jx)",
 	(uintptr_t)ptep, flags, 0, 0);



CVS commit: src/sys/uvm

2021-03-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar  7 08:16:58 UTC 2021

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

Log Message:
 consistency


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/uvm/uvm_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/uvm/uvm_pmap.h
diff -u src/sys/uvm/uvm_pmap.h:1.40 src/sys/uvm/uvm_pmap.h:1.41
--- src/sys/uvm/uvm_pmap.h:1.40	Sat Mar 14 14:05:44 2020
+++ src/sys/uvm/uvm_pmap.h	Sun Mar  7 08:16:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pmap.h,v 1.40 2020/03/14 14:05:44 ad Exp $	*/
+/*	$NetBSD: uvm_pmap.h,v 1.41 2021/03/07 08:16:58 skrll Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -181,7 +181,7 @@ void		pmap_page_protect(struct vm_page *
 paddr_t		pmap_phys_address(paddr_t);
 #endif
 #if !defined(pmap_mmap_flags)
-#define pmap_mmap_flags(x)	0
+#define		pmap_mmap_flags(x)	0
 #endif
 void		pmap_protect(pmap_t, vaddr_t, vaddr_t, vm_prot_t);
 #if !defined(pmap_reference)



CVS commit: src/sys/uvm

2021-02-19 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Feb 19 13:20:44 UTC 2021

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

Log Message:
When turning off swap during reboot we have to lock with LK_RETRY
as regular files got reclaimed during unmount.

Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.201 src/sys/uvm/uvm_swap.c:1.202
--- src/sys/uvm/uvm_swap.c:1.201	Tue Feb 16 09:56:32 2021
+++ src/sys/uvm/uvm_swap.c	Fri Feb 19 13:20:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.202 2021/02/19 13:20:43 hannken Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.202 2021/02/19 13:20:43 hannken Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1155,14 +1155,11 @@ again:
 			printf("\nturning off swap on %s...", sdp->swd_path);
 #endif
 			/* Have to lock and reference vnode for swap_off(). */
-			if (vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE)) {
-error = EBUSY;
-			} else {
-vref(vp);
-error = swap_off(l, sdp);
-vput(vp);
-mutex_enter(_swap_data_lock);
-			}
+			vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE|LK_RETRY);
+			vref(vp);
+			error = swap_off(l, sdp);
+			vput(vp);
+			mutex_enter(_swap_data_lock);
 			if (error) {
 printf("stopping swap on %s failed "
 "with error %d\n", sdp->swd_path, error);



CVS commit: src/sys/uvm/pmap

2020-12-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Dec 21 08:41:38 UTC 2020

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

Log Message:
Remove variable in function declaration argument


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/uvm/pmap/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/uvm/pmap/pmap.h
diff -u src/sys/uvm/pmap/pmap.h:1.18 src/sys/uvm/pmap/pmap.h:1.19
--- src/sys/uvm/pmap/pmap.h:1.18	Sun Dec 20 16:38:26 2020
+++ src/sys/uvm/pmap/pmap.h	Mon Dec 21 08:41:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.18 2020/12/20 16:38:26 skrll Exp $	*/
+/*	$NetBSD: pmap.h,v 1.19 2020/12/21 08:41:38 skrll Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -195,7 +195,7 @@ bool	pmap_page_clear_attributes(struct v
 void	pmap_page_set_attributes(struct vm_page_md *, u_int);
 void	pmap_pvlist_lock_init(size_t);
 #ifdef PMAP_VIRTUAL_CACHE_ALIASES
-void	pmap_page_cache(struct vm_page_md *, bool cached);
+void	pmap_page_cache(struct vm_page_md *, bool);
 #endif
 
 #ifdef __HAVE_PMAP_PV_TRACK



CVS commit: src/sys/uvm

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 15:50:44 UTC 2020

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

Log Message:
Remove VM_MD_TO_PAGE that was accidentally committed in 1.106.  It's going
to be readded with the code that uses it


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.h
diff -u src/sys/uvm/uvm_page.h:1.107 src/sys/uvm/uvm_page.h:1.108
--- src/sys/uvm/uvm_page.h:1.107	Wed Oct  7 17:51:50 2020
+++ src/sys/uvm/uvm_page.h	Sun Dec 20 15:50:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.107 2020/10/07 17:51:50 chs Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.108 2020/12/20 15:50:44 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -406,7 +406,6 @@ int uvm_direct_process(struct vm_page **
 
 #ifdef __HAVE_VM_PAGE_MD
 #define	VM_PAGE_TO_MD(pg)	(&(pg)->mdpage)
-#define	VM_MD_TO_PAGE(md)	(container_of((md), struct vm_page, mdpage))
 #endif
 
 /*



CVS commit: src/sys/uvm

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 11:11:34 UTC 2020

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

Log Message:
Some KNF.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.249 -r1.250 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.249 src/sys/uvm/uvm_page.c:1.250
--- src/sys/uvm/uvm_page.c:1.249	Sun Oct 18 18:31:31 2020
+++ src/sys/uvm/uvm_page.c	Sun Dec 20 11:11:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.250 2020/12/20 11:11:34 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.250 2020/12/20 11:11:34 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -560,7 +560,7 @@ uvm_pageboot_alloc(vsize_t size)
 	addr = pmap_steal_memory(size, _space_start,
 	_space_end);
 
-	return(addr);
+	return addr;
 
 #else /* !PMAP_STEAL_MEMORY */
 
@@ -604,7 +604,7 @@ uvm_pageboot_alloc(vsize_t size)
 		pmap_kenter_pa(vaddr, paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	}
 	pmap_update(pmap_kernel());
-	return(addr);
+	return addr;
 #endif	/* PMAP_STEAL_MEMORY */
 }
 



CVS commit: src/sys/uvm

2020-11-27 Thread Yorick Hardy
Module Name:src
Committed By:   yhardy
Date:   Fri Nov 27 22:32:43 UTC 2020

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

Log Message:
uvm_mremap: reference the appropriate backing object.

The previous approach was appropriate for anonymous
memory and device objects, which continue to work in
the same way.

OK: chs@
Fixes: PR 55237


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/uvm/uvm_mremap.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_mremap.c
diff -u src/sys/uvm/uvm_mremap.c:1.20 src/sys/uvm/uvm_mremap.c:1.21
--- src/sys/uvm/uvm_mremap.c:1.20	Sun Feb 23 15:46:43 2020
+++ src/sys/uvm/uvm_mremap.c	Fri Nov 27 22:32:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_mremap.c,v 1.20 2020/02/23 15:46:43 ad Exp $	*/
+/*	$NetBSD: uvm_mremap.c,v 1.21 2020/11/27 22:32:43 yhardy Exp $	*/
 
 /*-
  * Copyright (c)2006,2007,2009 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_mremap.c,v 1.20 2020/02/23 15:46:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mremap.c,v 1.21 2020/11/27 22:32:43 yhardy Exp $");
 
 #include 
 #include 
@@ -80,10 +80,8 @@ uvm_mapent_extend(struct vm_map *map, va
 			error = E2BIG; /* XXX */
 			goto done;
 		}
-		rw_enter(uobj->vmobjlock, RW_WRITER);
-		KASSERT(uobj->uo_refs > 0);
-		atomic_inc_uint(>uo_refs);
-		rw_exit(uobj->vmobjlock);
+		if (uobj->pgops->pgo_reference)
+			uobj->pgops->pgo_reference(uobj);
 		reserved_entry->object.uvm_obj = uobj;
 		reserved_entry->offset = newoffset;
 	}



CVS commit: src/sys/uvm

2020-11-09 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Nov 10 04:27:22 UTC 2020

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

Log Message:
remove someone's leftover debug printfs.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 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.123 src/sys/uvm/uvm_bio.c:1.124
--- src/sys/uvm/uvm_bio.c:1.123	Sun Oct 18 08:52:15 2020
+++ src/sys/uvm/uvm_bio.c	Tue Nov 10 04:27:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.123 2020/10/18 08:52:15 rin Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.124 2020/11/10 04:27:22 chs Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.123 2020/10/18 08:52:15 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.124 2020/11/10 04:27:22 chs Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -780,7 +780,6 @@ ubc_uiomove(struct uvm_object *uobj, str
 			 * do it now.  it's safe to use memset here
 			 * because we just mapped the pages above.
 			 */
-			printf("%s: error=%d\n", __func__, error);
 			memset(win, 0, bytelen);
 		}
 		ubc_release(win, flags, pgs, npages);
@@ -1009,7 +1008,6 @@ ubc_uiomove_direct(struct uvm_object *uo
 			 * error above, do it now.
 			 */
 			if (error != 0) {
-printf("%s: error=%d\n", __func__, error);
 (void) uvm_direct_process(pgs, npages, off,
 bytelen, ubc_zerorange_process, NULL);
 			}



CVS commit: src/sys/uvm

2020-10-24 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Oct 25 00:05:26 UTC 2020

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

Log Message:
Handle PG_PAGEOUT in uvm_anon_release() too.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/uvm/uvm_anon.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_anon.c
diff -u src/sys/uvm/uvm_anon.c:1.79 src/sys/uvm/uvm_anon.c:1.80
--- src/sys/uvm/uvm_anon.c:1.79	Thu Jul  9 05:57:15 2020
+++ src/sys/uvm/uvm_anon.c	Sun Oct 25 00:05:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_anon.c,v 1.79 2020/07/09 05:57:15 skrll Exp $	*/
+/*	$NetBSD: uvm_anon.c,v 1.80 2020/10/25 00:05:26 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.79 2020/07/09 05:57:15 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.80 2020/10/25 00:05:26 chs Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -371,6 +371,11 @@ uvm_anon_release(struct vm_anon *anon)
 	KASSERT(pg->loan_count == 0);
 	KASSERT(anon->an_ref == 0);
 
+	if ((pg->flags & PG_PAGEOUT) != 0) {
+		pg->flags &= ~PG_PAGEOUT;
+		uvm_pageout_done(1);
+	}
+
 	uvm_pagefree(pg);
 	KASSERT(anon->an_page == NULL);
 	lock = anon->an_lock;



CVS commit: src/sys/uvm

2020-10-18 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Oct 18 18:31:31 UTC 2020

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

Log Message:
In the current code, CPU_COUNT_FREEPAGES counts pages in the global
freelists AND the per-CPU pgflcache free pages caches, and that is the
number of pages that the pagedaemon considers to be available.
However, most pages in the pgflcache per-CPU free page caches are NOT
actually available for any particular allocation, and thus allocating
a page can fail even though the pagedaemon thinks enough pages are
available.  This change makes CPU_COUNT_FREEPAGES only count pages in
the global freelists and not pages in the pgflcache per-CPU free page
caches, thus better aligning the pagedaemon's view of how many pages
are available with the number of pages that can actually be allocated
by any particular request.  This fixes a hang that Christos was hitting.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.5 -r1.6 src/sys/uvm/uvm_pgflcache.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.248 src/sys/uvm/uvm_page.c:1.249
--- src/sys/uvm/uvm_page.c:1.248	Sun Oct 18 18:22:29 2020
+++ src/sys/uvm/uvm_page.c	Sun Oct 18 18:31:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.248 2020/10/18 18:22:29 chs Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.248 2020/10/18 18:22:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1069,6 +1069,7 @@ uvm_pagealloc_pgb(struct uvm_cpu *ucpu, 
 			KASSERT(pg->flags == PG_FREE);
 			pg->flags = PG_BUSY | PG_CLEAN | PG_FAKE;
 			pgb->pgb_nfree--;
+			CPU_COUNT(CPU_COUNT_FREEPAGES, -1);
 
 			/*
 			 * While we have the bucket locked and our data
@@ -1270,7 +1271,6 @@ uvm_pagealloc_strat(struct uvm_object *o
 	 * while still at IPL_VM, update allocation statistics.
 	 */
 
-	CPU_COUNT(CPU_COUNT_FREEPAGES, -1);
 	if (anon) {
 		CPU_COUNT(CPU_COUNT_ANONCLEAN, 1);
 	}
@@ -1567,7 +1567,6 @@ uvm_pagefree(struct vm_page *pg)
 
 	/* Try to send the page to the per-CPU cache. */
 	s = splvm();
-	CPU_COUNT(CPU_COUNT_FREEPAGES, 1);
 	ucpu = curcpu()->ci_data.cpu_uvm;
 	bucket = uvm_page_get_bucket(pg);
 	if (bucket == ucpu->pgflbucket && uvm_pgflcache_free(ucpu, pg)) {
@@ -1585,6 +1584,7 @@ uvm_pagefree(struct vm_page *pg)
 	pg->flags = PG_FREE;
 	LIST_INSERT_HEAD(>pgb_colors[VM_PGCOLOR(pg)], pg, pageq.list);
 	pgb->pgb_nfree++;
+	CPU_COUNT(CPU_COUNT_FREEPAGES, 1);
 	mutex_spin_exit(lock);
 	splx(s);
 }

Index: src/sys/uvm/uvm_pgflcache.c
diff -u src/sys/uvm/uvm_pgflcache.c:1.5 src/sys/uvm/uvm_pgflcache.c:1.6
--- src/sys/uvm/uvm_pgflcache.c:1.5	Sun Jun 14 21:41:42 2020
+++ src/sys/uvm/uvm_pgflcache.c	Sun Oct 18 18:31:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pgflcache.c,v 1.5 2020/06/14 21:41:42 ad Exp $	*/
+/*	$NetBSD: uvm_pgflcache.c,v 1.6 2020/10/18 18:31:31 chs Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pgflcache.c,v 1.5 2020/06/14 21:41:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pgflcache.c,v 1.6 2020/10/18 18:31:31 chs Exp $");
 
 #include "opt_uvm.h"
 #include "opt_multiprocessor.h"
@@ -151,6 +151,7 @@ uvm_pgflcache_fill(struct uvm_cpu *ucpu,
 		pg->pageq.list.le_prev = >lh_first;
 	}
 	pgb->pgb_nfree -= (count - pcc->count);
+	CPU_COUNT(CPU_COUNT_FREEPAGES, -(count - pcc->count));
 	pcc->count = count;
 }
 
@@ -188,6 +189,7 @@ uvm_pgflcache_spill(struct uvm_cpu *ucpu
 		LIST_INSERT_HEAD(head, pcc->pages[pcc->count], pageq.list);
 	}
 	pgb->pgb_nfree += adj;
+	CPU_COUNT(CPU_COUNT_FREEPAGES, adj);
 	mutex_spin_exit(lock);
 }
 



CVS commit: src/sys/uvm

2020-10-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Oct 18 08:52:15 UTC 2020

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

Log Message:
PR kern/55658

Revert rev 1.122:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/uvm/uvm_bio.c#rev1.122

If this commit is applied to NFS client, changes to files in client
side are sometimes invisible in server side, which results in file
corruption.

Demonstrated by test code provided by Anthony Mallet:
https://mail-index.netbsd.org/current-users/2020/10/17/msg039708.html

Whether the test case above passes or not depends on architectures
and size of NFS I/O specified by -r and -w options of mount_nfs(8)
(the default size is 32KB for x86 and 8KB for other archs).

Whereas it fails on amd64 and i386 with the default size, it passes
on other archs (aarch64, arm, alpha, m68k, and powerpc at least) with
their default. On most ports, it fails with some I/O sizes.

However, the condition for failure is still unclear; whereas it fails
with 2KB I/O size on amiga (m68k, 8KB page), it passes with same I/O
size on alpha (8KB page). It may depends on some VM parameters or
details in pmap implementation, or some race conditions are involved.

Great thanks to Anthony Mallet for providing the test code, and sorry
everyone for breakage.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 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.122 src/sys/uvm/uvm_bio.c:1.123
--- src/sys/uvm/uvm_bio.c:1.122	Mon Oct  5 04:48:23 2020
+++ src/sys/uvm/uvm_bio.c	Sun Oct 18 08:52:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.122 2020/10/05 04:48:23 rin Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.123 2020/10/18 08:52:15 rin Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.122 2020/10/05 04:48:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.123 2020/10/18 08:52:15 rin Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -235,7 +235,9 @@ static inline int
 ubc_fault_page(const struct uvm_faultinfo *ufi, const struct ubc_map *umap,
 struct vm_page *pg, vm_prot_t prot, vm_prot_t access_type, vaddr_t va)
 {
+	vm_prot_t mask;
 	int error;
+	bool rdonly;
 
 	KASSERT(rw_write_held(pg->uobject->vmobjlock));
 
@@ -278,11 +280,11 @@ ubc_fault_page(const struct uvm_faultinf
 	pg->offset < umap->writeoff ||
 	pg->offset + PAGE_SIZE > umap->writeoff + umap->writelen);
 
-	KASSERT((access_type & VM_PROT_WRITE) == 0 ||
-	uvm_pagegetdirty(pg) != UVM_PAGE_STATUS_CLEAN);
+	rdonly = uvm_pagereadonly_p(pg);
+	mask = rdonly ? ~VM_PROT_WRITE : VM_PROT_ALL;
 
 	error = pmap_enter(ufi->orig_map->pmap, va, VM_PAGE_TO_PHYS(pg),
-	prot, PMAP_CANFAIL | access_type);
+	prot & mask, PMAP_CANFAIL | (access_type & mask));
 
 	uvm_pagelock(pg);
 	uvm_pageactivate(pg);



CVS commit: src/sys/uvm/pmap

2020-10-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct  8 14:02:40 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap.c pmap_segtab.c

Log Message:
%#jx vs %jx consistency in UVMHIST_LOG


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/uvm/pmap/pmap.c
cvs rdiff -u -r1.25 -r1.26 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.56 src/sys/uvm/pmap/pmap.c:1.57
--- src/sys/uvm/pmap/pmap.c:1.56	Thu Sep 24 06:45:58 2020
+++ src/sys/uvm/pmap/pmap.c	Thu Oct  8 14:02:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.56 2020/09/24 06:45:58 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.57 2020/10/08 14:02:40 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.56 2020/09/24 06:45:58 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.57 2020/10/08 14:02:40 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -407,13 +407,13 @@ pmap_page_syncicache(struct vm_page *pg)
 	VM_PAGEMD_PVLIST_READLOCK(mdpg);
 	pmap_pvlist_check(mdpg);
 
-	UVMHIST_LOG(pmaphist, "pv %jx pv_pmap %jx", (uintptr_t)pv,
+	UVMHIST_LOG(pmaphist, "pv %#jx pv_pmap %#jx", (uintptr_t)pv,
 	(uintptr_t)pv->pv_pmap, 0, 0);
 
 	if (pv->pv_pmap != NULL) {
 		for (; pv != NULL; pv = pv->pv_next) {
 #ifdef MULTIPROCESSOR
-			UVMHIST_LOG(pmaphist, "pv %jx pv_pmap %jx",
+			UVMHIST_LOG(pmaphist, "pv %#jx pv_pmap %#jx",
 			(uintptr_t)pv, (uintptr_t)pv->pv_pmap, 0, 0);
 			kcpuset_merge(onproc, pv->pv_pmap->pm_onproc);
 			if (kcpuset_match(onproc, kcpuset_running)) {
@@ -779,7 +779,7 @@ pmap_page_remove(struct vm_page *pg)
 		npv = pv->pv_next;
 #ifdef PMAP_VIRTUAL_CACHE_ALIASES
 		if (PV_ISKENTER_P(pv)) {
-			UVMHIST_LOG(pmaphist, " pv %#jx pmap %#jx va %jx"
+			UVMHIST_LOG(pmaphist, " pv %#jx pmap %#jx va %#jx"
 			" skip", (uintptr_t)pv, (uintptr_t)pv->pv_pmap,
 			pv->pv_va, 0);
 
@@ -815,8 +815,8 @@ pmap_page_remove(struct vm_page *pg)
 		KASSERTMSG(ptep != NULL, "%#"PRIxVADDR " %#"PRIxVADDR, va,
 		pmap_limits.virtual_end);
 		pt_entry_t pte = *ptep;
-		UVMHIST_LOG(pmaphist, " pv %#jx pmap %#jx va %jx"
-		" pte %jx", (uintptr_t)pv, (uintptr_t)pmap, va,
+		UVMHIST_LOG(pmaphist, " pv %#jx pmap %#jx va %#jx"
+		" pte %#jx", (uintptr_t)pv, (uintptr_t)pmap, va,
 		pte_value(pte));
 		if (!pte_valid_p(pte))
 			continue;
@@ -918,7 +918,7 @@ pmap_update(struct pmap *pmap)
 	pmap_tlb_miss_lock_exit();
 	kpreempt_enable();
 
-	UVMHIST_LOG(pmaphist, " <-- done (kernel=%#jx)",
+	UVMHIST_LOG(pmaphist, " <-- done (kernel=%jx)",
 		(pmap == pmap_kernel() ? 1 : 0), 0, 0, 0);
 }
 

Index: src/sys/uvm/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.25 src/sys/uvm/pmap/pmap_segtab.c:1.26
--- src/sys/uvm/pmap/pmap_segtab.c:1.25	Thu Sep 24 06:45:58 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Thu Oct  8 14:02:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.25 2020/09/24 06:45:58 skrll Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.26 2020/10/08 14:02:40 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.25 2020/09/24 06:45:58 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.26 2020/10/08 14:02:40 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -265,7 +265,7 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 	UVMHIST_FUNC(__func__);
 	UVMHIST_CALLARGS(pmapsegtabhist, "pm=%#jx stpp=%#jx free=%jd",
 	(uintptr_t)pmap, (uintptr_t)stp_p, free_stp, 0);
-	UVMHIST_LOG(pmapsegtabhist, " callback=%jx flags=%jx va=%jx vinc=%jx",
+	UVMHIST_LOG(pmapsegtabhist, " callback=%#jx flags=%jx va=%#jx vinc=%#jx",
 	(uintptr_t)callback, flags, (uintptr_t)va, (uintptr_t)vinc);
 	for (size_t i = (va / vinc) & (PMAP_SEGTABSIZE - 1);
 	 i < PMAP_SEGTABSIZE;
@@ -574,7 +574,7 @@ pmap_pte_reserve(pmap_t pmap, vaddr_t va
 		*pte_p = pte;
 #endif
 		KASSERT(pte == stp->seg_tab[(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1)]);
-		UVMHIST_CALLARGS(pmapsegtabhist, "pm=%#jx va=%#jx -> tab[%jd]=%jx",
+		UVMHIST_CALLARGS(pmapsegtabhist, "pm=%#jx va=%#jx -> tab[%jd]=%#jx",
 		(uintptr_t)pmap, (uintptr_t)va,
 		(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1), (uintptr_t)pte);
 



CVS commit: src/sys/uvm

2020-10-07 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Oct  7 17:51:50 UTC 2020

Modified Files:
src/sys/uvm: uvm_init.c uvm_page.h uvm_pglist.c uvm_swap.c

Log Message:
Add a new, more aggressive allocator for uvm_pglistalloc() to allocate
contiguous physical pages, and try this new allocator if the existing
one fails.  The existing contig allocator only tries to allocate pages
that are already free, which works fine shortly after boot but rarely
works after the system has been up for a while.  The new allocator uses
the pagedaemon to evict pages from memory in the hope that this will
free up a range of pages that satisfies the constraits of the request.
This should help with things like plugging in a USB device, which often
fails for some USB controllers because they can't get contigous memory.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/uvm/uvm_init.c
cvs rdiff -u -r1.106 -r1.107 src/sys/uvm/uvm_page.h
cvs rdiff -u -r1.85 -r1.86 src/sys/uvm/uvm_pglist.c
cvs rdiff -u -r1.199 -r1.200 src/sys/uvm/uvm_swap.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_init.c
diff -u src/sys/uvm/uvm_init.c:1.53 src/sys/uvm/uvm_init.c:1.54
--- src/sys/uvm/uvm_init.c:1.53	Fri Mar  6 20:46:12 2020
+++ src/sys/uvm/uvm_init.c	Wed Oct  7 17:51:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_init.c,v 1.53 2020/03/06 20:46:12 ad Exp $	*/
+/*	$NetBSD: uvm_init.c,v 1.54 2020/10/07 17:51:50 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_init.c,v 1.53 2020/03/06 20:46:12 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_init.c,v 1.54 2020/10/07 17:51:50 chs Exp $");
 
 #include 
 #include 
@@ -107,6 +107,7 @@ uvm_init(void)
 	 */
 
 	uvm_page_init(_start, _end);
+	uvm_pglistalloc_init();
 
 	/*
 	 * Init the map sub-system.

Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.106 src/sys/uvm/uvm_page.h:1.107
--- src/sys/uvm/uvm_page.h:1.106	Sun Sep 20 10:30:05 2020
+++ src/sys/uvm/uvm_page.h	Wed Oct  7 17:51:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.106 2020/09/20 10:30:05 skrll Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.107 2020/10/07 17:51:50 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -259,6 +259,7 @@ struct vm_page {
 #define	PG_FREE		0x4000	/* page is on free list */
 #define	PG_MARKER	0x8000	/* dummy marker page */
 #define	PG_PAGER1	0x0001	/* pager-specific flag */
+#define	PG_PGLCA	0x0002	/* allocated by uvm_pglistalloc_contig */
 
 #define	PG_STAT		(PG_ANON|PG_AOBJ|PG_FILE)
 #define	PG_SWAPBACKED	(PG_ANON|PG_AOBJ)
@@ -268,7 +269,7 @@ struct vm_page {
 	"\5PAGEOUT\6RELEASED\7FAKE\10RDONLY" \
 	"\11ZERO\12TABLED\13AOBJ\14ANON" \
 	"\15FILE\16READAHEAD\17FREE\20MARKER" \
-	"\21PAGER1"
+	"\21PAGER1\22PGLCA"
 
 /*
  * Flags stored in pg->pqflags, which is protected by pg->interlock.
@@ -330,6 +331,7 @@ struct vm_page {
  */
 
 void uvm_page_init(vaddr_t *, vaddr_t *);
+void uvm_pglistalloc_init(void);
 #if defined(UVM_PAGE_TRKOWN)
 void uvm_page_own(struct vm_page *, const char *);
 #endif

Index: src/sys/uvm/uvm_pglist.c
diff -u src/sys/uvm/uvm_pglist.c:1.85 src/sys/uvm/uvm_pglist.c:1.86
--- src/sys/uvm/uvm_pglist.c:1.85	Sun Jun 14 21:41:42 2020
+++ src/sys/uvm/uvm_pglist.c	Wed Oct  7 17:51:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.85 2020/06/14 21:41:42 ad Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.86 2020/10/07 17:51:50 chs Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.85 2020/06/14 21:41:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.86 2020/10/07 17:51:50 chs Exp $");
 
 #include 
 #include 
@@ -59,6 +59,8 @@ u_long	uvm_pglistalloc_npages;
 #define	STAT_DECR(v)
 #endif
 
+kmutex_t uvm_pglistalloc_contig_lock;
+
 /*
  * uvm_pglistalloc: allocate a list of pages
  *
@@ -293,13 +295,161 @@ uvm_pglistalloc_c_ps(uvm_physseg_t psi, 
 }
 
 static int
+uvm_pglistalloc_contig_aggressive(int num, paddr_t low, paddr_t high,
+paddr_t alignment, paddr_t boundary, struct pglist *rlist)
+{
+	struct vm_page *pg;
+	struct pglist tmp;
+	paddr_t pa, off, spa, amask, bmask, rlo, rhi;
+	uvm_physseg_t upm;
+	int error, i, run, acnt;
+
+	/*
+	 * Allocate pages the normal way and for each new page, check if
+	 * the page completes a range satisfying the request.
+	 * The pagedaemon will evict pages as we go and we are very likely
+	 * to get compatible pages eventually.
+	 */
+
+	error = ENOMEM;
+	TAILQ_INIT();
+	acnt = atop(alignment);
+	amask = ~(alignment - 1);
+	bmask = ~(boundary - 1);
+	KASSERT(bmask <= amask);
+	mutex_enter(_pglistalloc_contig_lock);
+	while (uvm_reclaimable()) {
+		pg = uvm_pagealloc(NULL, 0, NULL, 0);
+		if (pg == NULL) {
+			uvm_wait("pglac2");
+			continue;
+		}
+		

CVS commit: src/sys/uvm

2020-10-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Oct  5 04:48:24 UTC 2020

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

Log Message:
PR kern/55658

ubc_fault_page(): Ignore PG_RDONLY flag and always pmap_enter() the page
with the permissions of the original access_type.

It is the file system's responsibility to allocate blocks that is being
modified by write(), before calling into UBC to fill the pages for that
range. KASSERT() is added there to confirm that no clean page is mapped
writable.

Fix infinite loop in uvm_fault_internal(), observed on 16KB-page systems,
where it continues to try to make a partially-backed page writable.

No regression in ATF and KASSERT() does not fire on several architectures,
as far as I can see.

Fix suggested by chs. Thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 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.121 src/sys/uvm/uvm_bio.c:1.122
--- src/sys/uvm/uvm_bio.c:1.121	Thu Jul  9 09:24:32 2020
+++ src/sys/uvm/uvm_bio.c	Mon Oct  5 04:48:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.121 2020/07/09 09:24:32 rin Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.122 2020/10/05 04:48:23 rin Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.121 2020/07/09 09:24:32 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.122 2020/10/05 04:48:23 rin Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -235,9 +235,7 @@ static inline int
 ubc_fault_page(const struct uvm_faultinfo *ufi, const struct ubc_map *umap,
 struct vm_page *pg, vm_prot_t prot, vm_prot_t access_type, vaddr_t va)
 {
-	vm_prot_t mask;
 	int error;
-	bool rdonly;
 
 	KASSERT(rw_write_held(pg->uobject->vmobjlock));
 
@@ -280,11 +278,11 @@ ubc_fault_page(const struct uvm_faultinf
 	pg->offset < umap->writeoff ||
 	pg->offset + PAGE_SIZE > umap->writeoff + umap->writelen);
 
-	rdonly = uvm_pagereadonly_p(pg);
-	mask = rdonly ? ~VM_PROT_WRITE : VM_PROT_ALL;
+	KASSERT((access_type & VM_PROT_WRITE) == 0 ||
+	uvm_pagegetdirty(pg) != UVM_PAGE_STATUS_CLEAN);
 
 	error = pmap_enter(ufi->orig_map->pmap, va, VM_PAGE_TO_PHYS(pg),
-	prot & mask, PMAP_CANFAIL | (access_type & mask));
+	prot, PMAP_CANFAIL | access_type);
 
 	uvm_pagelock(pg);
 	uvm_pageactivate(pg);



CVS commit: src/sys/uvm/pmap

2020-09-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Sep 24 06:45:58 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap.c pmap_segtab.c pmap_tlb.c

Log Message:
Whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/uvm/pmap/pmap.c
cvs rdiff -u -r1.24 -r1.25 src/sys/uvm/pmap/pmap_segtab.c
cvs rdiff -u -r1.40 -r1.41 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.55 src/sys/uvm/pmap/pmap.c:1.56
--- src/sys/uvm/pmap/pmap.c:1.55	Thu Aug 20 05:54:32 2020
+++ src/sys/uvm/pmap/pmap.c	Thu Sep 24 06:45:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.55 2020/08/20 05:54:32 mrg Exp $	*/
+/*	$NetBSD: pmap.c,v 1.56 2020/09/24 06:45:58 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.55 2020/08/20 05:54:32 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.56 2020/09/24 06:45:58 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -408,7 +408,7 @@ pmap_page_syncicache(struct vm_page *pg)
 	pmap_pvlist_check(mdpg);
 
 	UVMHIST_LOG(pmaphist, "pv %jx pv_pmap %jx", (uintptr_t)pv,
-	 (uintptr_t)pv->pv_pmap, 0, 0);
+	(uintptr_t)pv->pv_pmap, 0, 0);
 
 	if (pv->pv_pmap != NULL) {
 		for (; pv != NULL; pv = pv->pv_next) {

Index: src/sys/uvm/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.24 src/sys/uvm/pmap/pmap_segtab.c:1.25
--- src/sys/uvm/pmap/pmap_segtab.c:1.24	Thu Sep 10 02:12:57 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Thu Sep 24 06:45:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.24 2020/09/10 02:12:57 rin Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.25 2020/09/24 06:45:58 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.24 2020/09/10 02:12:57 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.25 2020/09/24 06:45:58 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -192,7 +192,7 @@ pmap_check_ptes(pt_entry_t *pte, const c
 	j, pte_value(pte[j]), 0, 0);
 #endif
 			panic("%s: pte[%zu] entry at %p not 0 (%#"PRIxPTE")",
-			  caller, i, [i], pte_value(pte[i]));
+			caller, i, [i], pte_value(pte[i]));
 		}
 #endif
 }

Index: src/sys/uvm/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.40 src/sys/uvm/pmap/pmap_tlb.c:1.41
--- src/sys/uvm/pmap/pmap_tlb.c:1.40	Sat Aug 22 14:51:44 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Thu Sep 24 06:45:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.40 2020/08/22 14:51:44 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.41 2020/09/24 06:45:58 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.40 2020/08/22 14:51:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.41 2020/09/24 06:45:58 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -757,8 +757,8 @@ pmap_tlb_update_addr(pmap_t pm, vaddr_t 
 		(flags & PMAP_TLB_INSERT) != 0);
 		pmap_tlb_asid_check();
 		UVMHIST_LOG(maphist,
-		 "   %jd <-- tlb_update_addr(%#jx, %#jx, %#jx, ...)",
-		 rv, va, pai->pai_asid, pte_value(pte));
+		"   %jd <-- tlb_update_addr(%#jx, %#jx, %#jx, ...)",
+		rv, va, pai->pai_asid, pte_value(pte));
 		KASSERTMSG((flags & PMAP_TLB_INSERT) == 0 || rv == 1,
 		"pmap %p (asid %u) va %#"PRIxVADDR" pte %#"PRIxPTE" rv %d",
 		pm, pai->pai_asid, va, pte_value(pte), rv);



CVS commit: src/sys/uvm

2020-09-21 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Mon Sep 21 18:41:59 UTC 2020

Modified Files:
src/sys/uvm: uvm_amap.c uvm_io.c

Log Message:
the previous fix for PR 55366 in uvm_amap.c 1.124 was incomplete:
 - amap_adjref_anons() must also ignore AMAP_REFALL when updating
   the ppref, not just when deciding whether or not to initialize ppref.
 - UVM_EXTRACT_QREF relies on AMAP_REFALL to work properly,
   and since we can't use AMAP_REFALL then we can't use QREF either.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/uvm/uvm_amap.c
cvs rdiff -u -r1.28 -r1.29 src/sys/uvm/uvm_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/uvm/uvm_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.124 src/sys/uvm/uvm_amap.c:1.125
--- src/sys/uvm/uvm_amap.c:1.124	Sun Sep 20 23:03:01 2020
+++ src/sys/uvm/uvm_amap.c	Mon Sep 21 18:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.124 2020/09/20 23:03:01 chs Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.125 2020/09/21 18:41:59 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.124 2020/09/20 23:03:01 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.125 2020/09/21 18:41:59 chs Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -1602,11 +1602,7 @@ amap_adjref_anons(struct vm_amap *amap, 
 
 #ifdef UVM_AMAP_PPREF
 	if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
-		if (all) {
-			amap_pp_adjref(amap, 0, amap->am_nslot, refv);
-		} else {
-			amap_pp_adjref(amap, offset, len, refv);
-		}
+		amap_pp_adjref(amap, offset, len, refv);
 	}
 #endif
 	amap_unlock(amap);

Index: src/sys/uvm/uvm_io.c
diff -u src/sys/uvm/uvm_io.c:1.28 src/sys/uvm/uvm_io.c:1.29
--- src/sys/uvm/uvm_io.c:1.28	Wed May 25 17:43:58 2016
+++ src/sys/uvm/uvm_io.c	Mon Sep 21 18:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_io.c,v 1.28 2016/05/25 17:43:58 christos Exp $	*/
+/*	$NetBSD: uvm_io.c,v 1.29 2020/09/21 18:41:59 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_io.c,v 1.28 2016/05/25 17:43:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_io.c,v 1.29 2020/09/21 18:41:59 chs Exp $");
 
 #include 
 #include 
@@ -87,6 +87,10 @@ uvm_io(struct vm_map *map, struct uio *u
 	error = 0;
 
 	flags |= UVM_EXTRACT_QREF | UVM_EXTRACT_CONTIG | UVM_EXTRACT_FIXPROT;
+
+	/* XXX cannot use QREF with without AMAP_REFALL, and REFALL is unsafe */
+	flags &= ~UVM_EXTRACT_QREF;
+
 	/*
 	 * step 1: main loop...  while we've got data to move
 	 */



CVS commit: src/sys/uvm

2020-09-20 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Sep 20 23:03:01 UTC 2020

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

Log Message:
Effectively disable the AMAP_REFALL flag because it is unsafe.
This flag tells the amap code that it does not need to allocate ppref
as part of adding or removing a reference, but that is only correct
if the range of the reference being added or removed is the same
as the range of all other references to the amap, and the point of
this flag is exactly to try to optimize the case where the range is
different and thus this flag would not be correct to use.
Fixes PR 55366.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/uvm/uvm_amap.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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.123 src/sys/uvm/uvm_amap.c:1.124
--- src/sys/uvm/uvm_amap.c:1.123	Tue Aug 18 10:40:20 2020
+++ src/sys/uvm/uvm_amap.c	Sun Sep 20 23:03:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.123 2020/08/18 10:40:20 chs Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.124 2020/09/20 23:03:01 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.123 2020/08/18 10:40:20 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.124 2020/09/20 23:03:01 chs Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -1593,7 +1593,7 @@ amap_adjref_anons(struct vm_amap *amap, 
 	 * so that the ppref values match the current amap refcount.
 	 */
 
-	if (amap->am_ppref == NULL && !all && len != amap->am_nslot) {
+	if (amap->am_ppref == NULL) {
 		amap_pp_establish(amap, offset);
 	}
 #endif



CVS commit: src/sys/uvm

2020-09-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Sep 20 10:30:05 UTC 2020

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

Log Message:
G/C uvm_pagezerocheck


To generate a diff of this commit:
cvs rdiff -u -r1.246 -r1.247 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.105 -r1.106 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.246 src/sys/uvm/uvm_page.c:1.247
--- src/sys/uvm/uvm_page.c:1.246	Sat Aug 15 01:27:22 2020
+++ src/sys/uvm/uvm_page.c	Sun Sep 20 10:30:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.246 2020/08/15 01:27:22 tnn Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.247 2020/09/20 10:30:05 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.246 2020/08/15 01:27:22 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.247 2020/09/20 10:30:05 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -447,14 +447,6 @@ uvm_page_init(vaddr_t *kvm_startp, vaddr
 
 	*kvm_startp = round_page(virtual_space_start);
 	*kvm_endp = trunc_page(virtual_space_end);
-#ifdef DEBUG
-	/*
-	 * steal kva for uvm_pagezerocheck().
-	 */
-	uvm_zerocheckkva = *kvm_startp;
-	*kvm_startp += PAGE_SIZE;
-	mutex_init(_zerochecklock, MUTEX_DEFAULT, IPL_VM);
-#endif /* DEBUG */
 
 	/*
 	 * init various thresholds.
@@ -1427,42 +1419,6 @@ uvm_pagerealloc(struct vm_page *pg, stru
 	return error;
 }
 
-#ifdef DEBUG
-/*
- * check if page is zero-filled
- */
-void
-uvm_pagezerocheck(struct vm_page *pg)
-{
-	int *p, *ep;
-
-	KASSERT(uvm_zerocheckkva != 0);
-
-	/*
-	 * XXX assuming pmap_kenter_pa and pmap_kremove never call
-	 * uvm page allocator.
-	 *
-	 * it might be better to have "CPU-local temporary map" pmap interface.
-	 */
-	mutex_spin_enter(_zerochecklock);
-	pmap_kenter_pa(uvm_zerocheckkva, VM_PAGE_TO_PHYS(pg), VM_PROT_READ, 0);
-	p = (int *)uvm_zerocheckkva;
-	ep = (int *)((char *)p + PAGE_SIZE);
-	pmap_update(pmap_kernel());
-	while (p < ep) {
-		if (*p != 0)
-			panic("zero page isn't zero-filled");
-		p++;
-	}
-	pmap_kremove(uvm_zerocheckkva, PAGE_SIZE);
-	mutex_spin_exit(_zerochecklock);
-	/*
-	 * pmap_update() is not necessary here because no one except us
-	 * uses this VA.
-	 */
-}
-#endif /* DEBUG */
-
 /*
  * uvm_pagefree: free page
  *

Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.105 src/sys/uvm/uvm_page.h:1.106
--- src/sys/uvm/uvm_page.h:1.105	Sun Jun 14 21:41:42 2020
+++ src/sys/uvm/uvm_page.h	Sun Sep 20 10:30:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.105 2020/06/14 21:41:42 ad Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.106 2020/09/20 10:30:05 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -404,6 +404,7 @@ int uvm_direct_process(struct vm_page **
 
 #ifdef __HAVE_VM_PAGE_MD
 #define	VM_PAGE_TO_MD(pg)	(&(pg)->mdpage)
+#define	VM_MD_TO_PAGE(md)	(container_of((md), struct vm_page, mdpage))
 #endif
 
 /*
@@ -470,10 +471,6 @@ uvm_page_set_bucket(struct vm_page *pg, 
 	pg->phys_addr |= __SHIFTIN(b, UVM_PHYSADDR_BUCKET);
 }
 
-#ifdef DEBUG
-void uvm_pagezerocheck(struct vm_page *);
-#endif /* DEBUG */
-
 #endif /* _KERNEL */
 
 #endif /* _UVM_UVM_PAGE_H_ */



CVS commit: src/sys/uvm/pmap

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 02:12:57 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Cast pointer arguments of UVMHIST_CALLARGS() into uintptr_t.

Appease GCC9 -Wpointer-to-int-cast on ILP32 environments.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.23 src/sys/uvm/pmap/pmap_segtab.c:1.24
--- src/sys/uvm/pmap/pmap_segtab.c:1.23	Sat Aug 22 15:34:51 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Thu Sep 10 02:12:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.23 2020/08/22 15:34:51 skrll Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.24 2020/09/10 02:12:57 rin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.23 2020/08/22 15:34:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.24 2020/09/10 02:12:57 rin Exp $");
 
 /*
  *	Manages physical address maps.
@@ -246,7 +246,7 @@ pmap_segtab_free(pmap_segtab_t *stp)
 {
 	UVMHIST_FUNC(__func__);
 
-	UVMHIST_CALLARGS(pmapsegtabhist, "stp=%#jx", stp, 0, 0, 0);
+	UVMHIST_CALLARGS(pmapsegtabhist, "stp=%#jx", (uintptr_t)stp, 0, 0, 0);
 
 	mutex_spin_enter(_segtab_lock);
 	stp->seg_seg[0] = pmap_segtab_info.free_segtab;
@@ -346,7 +346,8 @@ pmap_segtab_alloc(void)
 		stp->seg_seg[0] = NULL;
 		SEGTAB_ADD(nget, 1);
 		found_on_freelist = true;
-		UVMHIST_CALLARGS(pmapsegtabhist, "freelist stp=%#jx", stp, 0, 0, 0);
+		UVMHIST_CALLARGS(pmapsegtabhist, "freelist stp=%#jx",
+		(uintptr_t)stp, 0, 0, 0);
 	}
 	mutex_spin_exit(_segtab_lock);
 
@@ -364,7 +365,8 @@ pmap_segtab_alloc(void)
 		const paddr_t stp_pa = VM_PAGE_TO_PHYS(stp_pg);
 
 		stp = (pmap_segtab_t *)PMAP_MAP_POOLPAGE(stp_pa);
-		UVMHIST_CALLARGS(pmapsegtabhist, "new stp=%#jx", stp, 0, 0, 0);
+		UVMHIST_CALLARGS(pmapsegtabhist, "new stp=%#jx",
+		(uintptr_t)stp, 0, 0, 0);
 		const size_t n = NBPG / sizeof(*stp);
 		if (n > 1) {
 			/*
@@ -574,7 +576,7 @@ pmap_pte_reserve(pmap_t pmap, vaddr_t va
 		KASSERT(pte == stp->seg_tab[(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1)]);
 		UVMHIST_CALLARGS(pmapsegtabhist, "pm=%#jx va=%#jx -> tab[%jd]=%jx",
 		(uintptr_t)pmap, (uintptr_t)va,
-		(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1), pte);
+		(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1), (uintptr_t)pte);
 
 		pmap_check_ptes(pte, __func__);
 		pte += (va >> PGSHIFT) & (NPTEPG - 1);



CVS commit: src/sys/uvm/pmap

2020-08-22 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Aug 22 15:32:36 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Remove the #if defined(__mips_n64) && PAGE_SIZE == 8192 and make the
check MI - all PTs are PAGE_SIZE aligned


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.21 src/sys/uvm/pmap/pmap_segtab.c:1.22
--- src/sys/uvm/pmap/pmap_segtab.c:1.21	Sat Aug 22 13:59:16 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Sat Aug 22 15:32:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.21 2020/08/22 13:59:16 skrll Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.22 2020/08/22 15:32:36 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.21 2020/08/22 13:59:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.22 2020/08/22 15:32:36 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -171,6 +171,13 @@ pmap_check_stp(pmap_segtab_t *stp, const
 static void
 pmap_check_ptes(pt_entry_t *pte, const char *caller)
 {
+	/*
+	 * All pte arrays should be page aligned.
+	 */
+	if (((uintptr_t)pte & PAGE_MASK) != 0) {
+		panic("%s: pte entry at %p not page aligned", caller, pte);
+	}
+
 #ifdef DEBUG
 	for (size_t i = 0; i < NPTEPG; i++)
 		if (!pte_zero_p(pte[i])) {
@@ -283,17 +290,6 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 			continue;
 		pmap_check_ptes(pte, __func__);
 
-#if defined(__mips_n64) && PAGE_SIZE == 8192
-		/*
-		 * XXX This is evil.  If vinc is 100 we are in
-		 * the last level, and this pte should be page aligned.
-		 */
-		if (vinc == 0x100 && ((uintptr_t)pte & PAGE_MASK) != 0) {
-			panic("%s: pte entry at %p not page aligned",
-			__func__, pte);
-		}
-#endif
-
 		/*
 		 * If our caller wants a callback, do so.
 		 */



CVS commit: src/sys/uvm/pmap

2020-08-22 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Aug 22 14:51:44 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Whitespace - line continutation alignment


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.39 src/sys/uvm/pmap/pmap_tlb.c:1.40
--- src/sys/uvm/pmap/pmap_tlb.c:1.39	Wed Aug 19 06:11:49 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Sat Aug 22 14:51:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.39 2020/08/19 06:11:49 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.40 2020/08/22 14:51:44 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.39 2020/08/19 06:11:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.40 2020/08/22 14:51:44 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -629,7 +629,7 @@ pmap_tlb_shootdown_process(void)
 	   (nobody) << 3 * TLBINV_NOBODY)			\
 	 | (  (one) << 3 * TLBINV_ONE)			\
 	 | (  (alluser) << 3 * TLBINV_ALLUSER)			\
-	 | ((allkernel) << 3 * TLBINV_ALLKERNEL)			\
+	 | ((allkernel) << 3 * TLBINV_ALLKERNEL)		\
 	 | (  (all) << 3 * TLBINV_ALL)) >> 3 * (op)) & 7)
 
 #define	TLBINV_USER_MAP(op)	\



CVS commit: src/sys/uvm/pmap

2020-08-22 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Aug 22 13:59:16 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.20 src/sys/uvm/pmap/pmap_segtab.c:1.21
--- src/sys/uvm/pmap/pmap_segtab.c:1.20	Thu Aug 20 23:36:45 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Sat Aug 22 13:59:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.20 2020/08/20 23:36:45 mrg Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.21 2020/08/22 13:59:16 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.20 2020/08/20 23:36:45 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.21 2020/08/22 13:59:16 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -132,7 +132,7 @@ struct pmap_segtab_info {
 kmutex_t pmap_segtab_lock __cacheline_aligned;
 
 /*
- * Check that a seg_tab[] array is empty.  
+ * Check that a seg_tab[] array is empty.
  *
  * This is used when allocating or freeing a pmap_segtab_t.  The stp
  * should be unused -- meaning, none of the seg_tab[] pointers are
@@ -182,7 +182,7 @@ pmap_check_ptes(pt_entry_t *pte, const c
 if (!pte_zero_p(pte[j]))
 	UVMHIST_LOG(pmapsegtabhist,
 	"pte[%zu] = %#"PRIxPTE,
-	j, pte_value(pte[j]), 0, 0); 
+	j, pte_value(pte[j]), 0, 0);
 #endif
 			panic("%s: pte[%zu] entry at %p not 0 (%#"PRIxPTE")",
 			  caller, i, [i], pte_value(pte[i]));
@@ -281,7 +281,7 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 		pt_entry_t *pte = stp->seg_tab[i];
 		if (pte == NULL)
 			continue;
-		pmap_check_ptes(pte, __func__); 
+		pmap_check_ptes(pte, __func__);
 
 #if defined(__mips_n64) && PAGE_SIZE == 8192
 		/*



CVS commit: src/sys/uvm/pmap

2020-08-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Aug 20 23:36:45 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
fix hpcmips and evbppc builds (wrong type in panic()).


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.19 src/sys/uvm/pmap/pmap_segtab.c:1.20
--- src/sys/uvm/pmap/pmap_segtab.c:1.19	Thu Aug 20 05:54:32 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Thu Aug 20 23:36:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.19 2020/08/20 05:54:32 mrg Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.20 2020/08/20 23:36:45 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.19 2020/08/20 05:54:32 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.20 2020/08/20 23:36:45 mrg Exp $");
 
 /*
  *	Manages physical address maps.
@@ -184,7 +184,7 @@ pmap_check_ptes(pt_entry_t *pte, const c
 	"pte[%zu] = %#"PRIxPTE,
 	j, pte_value(pte[j]), 0, 0); 
 #endif
-			panic("%s: pte[%ju] entry at %pu not 0 (%#"PRIxPTE")",
+			panic("%s: pte[%zu] entry at %p not 0 (%#"PRIxPTE")",
 			  caller, i, [i], pte_value(pte[i]));
 		}
 #endif



CVS commit: src/sys/uvm/pmap

2020-08-19 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Aug 20 05:54:32 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap.c pmap.h pmap_segtab.c

Log Message:
move pmap segtab history into a new history of only 1000 entries,
but will overflow much slower than the main pmap history.

move various debug info into kernhist.  make pte array checker
into an array and use it in pmap_segtab_release() and
pmap_pte_reserve().  move check before MD callback(), incase it
wants to change ptes for some reason (they're passed in, but
this callback is currently always NULL.)

clean up some history logs to reduce the number of lines required.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/uvm/pmap/pmap.c
cvs rdiff -u -r1.16 -r1.17 src/sys/uvm/pmap/pmap.h
cvs rdiff -u -r1.18 -r1.19 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.54 src/sys/uvm/pmap/pmap.c:1.55
--- src/sys/uvm/pmap/pmap.c:1.54	Wed Aug 19 07:29:01 2020
+++ src/sys/uvm/pmap/pmap.c	Thu Aug 20 05:54:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.54 2020/08/19 07:29:01 simonb Exp $	*/
+/*	$NetBSD: pmap.c,v 1.55 2020/08/20 05:54:32 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.54 2020/08/19 07:29:01 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.55 2020/08/20 05:54:32 mrg Exp $");
 
 /*
  *	Manages physical address maps.
@@ -217,8 +217,10 @@ struct pmap_limits pmap_limits = {	/* VA
 #ifdef UVMHIST
 static struct kern_history_ent pmapexechistbuf[1];
 static struct kern_history_ent pmaphistbuf[1];
+static struct kern_history_ent pmapsegtabhistbuf[1000];
 UVMHIST_DEFINE(pmapexechist);
 UVMHIST_DEFINE(pmaphist);
+UVMHIST_DEFINE(pmapsegtabhist);
 #endif
 
 /*
@@ -587,6 +589,7 @@ pmap_init(void)
 {
 	UVMHIST_INIT_STATIC(pmapexechist, pmapexechistbuf);
 	UVMHIST_INIT_STATIC(pmaphist, pmaphistbuf);
+	UVMHIST_INIT_STATIC(pmapsegtabhist, pmapsegtabhistbuf);
 
 	UVMHIST_FUNC(__func__);
 	UVMHIST_CALLED(pmaphist);

Index: src/sys/uvm/pmap/pmap.h
diff -u src/sys/uvm/pmap/pmap.h:1.16 src/sys/uvm/pmap/pmap.h:1.17
--- src/sys/uvm/pmap/pmap.h:1.16	Fri Aug  7 07:19:45 2020
+++ src/sys/uvm/pmap/pmap.h	Thu Aug 20 05:54:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.16 2020/08/07 07:19:45 skrll Exp $	*/
+/*	$NetBSD: pmap.h,v 1.17 2020/08/20 05:54:32 mrg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -78,6 +78,7 @@
 #ifdef UVMHIST
 UVMHIST_DECL(pmapexechist);
 UVMHIST_DECL(pmaphist);
+UVMHIST_DECL(pmapsegtabhist);
 #endif
 
 /*

Index: src/sys/uvm/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.18 src/sys/uvm/pmap/pmap_segtab.c:1.19
--- src/sys/uvm/pmap/pmap_segtab.c:1.18	Tue Aug 18 11:48:21 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Thu Aug 20 05:54:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.18 2020/08/18 11:48:21 simonb Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.19 2020/08/20 05:54:32 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.18 2020/08/18 11:48:21 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.19 2020/08/20 05:54:32 mrg Exp $");
 
 /*
  *	Manages physical address maps.
@@ -131,16 +131,32 @@ struct pmap_segtab_info {
 
 kmutex_t pmap_segtab_lock __cacheline_aligned;
 
+/*
+ * Check that a seg_tab[] array is empty.  
+ *
+ * This is used when allocating or freeing a pmap_segtab_t.  The stp
+ * should be unused -- meaning, none of the seg_tab[] pointers are
+ * not NULL, as it transitions from either freshly allocated segtab from
+ * pmap pool, an unused allocated page segtab alloc from the SMP case,
+ * where two CPUs attempt to allocate the same underlying segtab, the
+ * release of a segtab entry to the freelist, or for SMP, where reserve
+ * also frees a freshly allocated but unused entry.
+ */
 static void
 pmap_check_stp(pmap_segtab_t *stp, const char *caller, const char *why)
 {
 #ifdef DEBUG
 	for (size_t i = 0; i < PMAP_SEGTABSIZE; i++) {
-		if (stp->seg_tab[i] != 0) {
+		if (stp->seg_tab[i] != NULL) {
+#define DEBUG_NOISY
 #ifdef DEBUG_NOISY
+			UVMHIST_FUNC(__func__);
+			UVMHIST_CALLARGS(pmapsegtabhist, "stp=%#jx",
+			(uintptr_t)stp, 0, 0, 0);
 			for (size_t j = i; j < PMAP_SEGTABSIZE; j++)
-printf("%s: pm_segtab.seg_tab[%zu] = %p\n",
-caller, j, stp->seg_tab[j]);
+if (stp->seg_tab[j] != NULL)
+	printf("%s: stp->seg_tab[%zu] = %p\n",
+	caller, j, stp->seg_tab[j]);
 #endif
 			panic("%s: pm_segtab.seg_tab[%zu] != 0 (%p): %s",
 			caller, i, stp->seg_tab[i], why);
@@ -149,6 +165,31 @@ pmap_check_stp(pmap_segtab_t *stp, const
 #endif
 }
 
+/*
+ * Check that an array of ptes is actually zero.
+ */
+static void
+pmap_check_ptes(pt_entry_t *pte, const char 

CVS commit: src/sys/uvm

2020-08-19 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Aug 19 15:36:41 UTC 2020

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

Log Message:
in uao_get(), if we unlock the uobj to read a page from swap,
we must clear the cached page array because it is now stale.
also add a missing call to uvm_page_array_fini() if the I/O fails.
fixes PR 55493.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 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.150 src/sys/uvm/uvm_aobj.c:1.151
--- src/sys/uvm/uvm_aobj.c:1.150	Wed Aug 19 07:29:00 2020
+++ src/sys/uvm/uvm_aobj.c	Wed Aug 19 15:36:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.150 2020/08/19 07:29:00 simonb Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.151 2020/08/19 15:36:41 chs Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.150 2020/08/19 07:29:00 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.151 2020/08/19 15:36:41 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -982,6 +982,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 			 * unlock object for i/o, relock when done.
 			 */
 
+			uvm_page_array_clear();
 			rw_exit(uobj->vmobjlock);
 			error = uvm_swap_get(ptmp, swslot, PGO_SYNCIO);
 			rw_enter(uobj->vmobjlock, RW_WRITER);
@@ -1015,6 +1016,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 	uvm_page_unbusy(pps, lcv);
 }
 memset(pps, 0, maxpages * sizeof(pps[0]));
+uvm_page_array_fini();
 return error;
 			}
 #else /* defined(VMSWAP) */



CVS commit: src/sys/uvm/pmap

2020-08-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Aug 19 06:11:49 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c pmap_tlb.h

Log Message:
KNF.  Add some whitespace to the TLBINV_MAP macro and tlb_invalidate_op
enum.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/uvm/pmap/pmap_tlb.c
cvs rdiff -u -r1.14 -r1.15 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.38 src/sys/uvm/pmap/pmap_tlb.c:1.39
--- src/sys/uvm/pmap/pmap_tlb.c:1.38	Wed Aug 19 06:08:27 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Wed Aug 19 06:11:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.38 2020/08/19 06:08:27 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.39 2020/08/19 06:11:49 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.38 2020/08/19 06:08:27 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.39 2020/08/19 06:11:49 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -626,11 +626,11 @@ pmap_tlb_shootdown_process(void)
  * can be loaded in a single instruction.
  */
 #define	TLBINV_MAP(op, nobody, one, alluser, allkernel, all)	\
-	   (nobody) << 3*TLBINV_NOBODY)			\
-	 | (  (one) << 3*TLBINV_ONE)			\
-	 | (  (alluser) << 3*TLBINV_ALLUSER)			\
-	 | ((allkernel) << 3*TLBINV_ALLKERNEL)			\
-	 | (  (all) << 3*TLBINV_ALL)) >> 3*(op)) & 7)
+	   (nobody) << 3 * TLBINV_NOBODY)			\
+	 | (  (one) << 3 * TLBINV_ONE)			\
+	 | (  (alluser) << 3 * TLBINV_ALLUSER)			\
+	 | ((allkernel) << 3 * TLBINV_ALLKERNEL)			\
+	 | (  (all) << 3 * TLBINV_ALL)) >> 3 * (op)) & 7)
 
 #define	TLBINV_USER_MAP(op)	\
 	TLBINV_MAP(op, TLBINV_ONE, TLBINV_ALLUSER, TLBINV_ALLUSER,	\

Index: src/sys/uvm/pmap/pmap_tlb.h
diff -u src/sys/uvm/pmap/pmap_tlb.h:1.14 src/sys/uvm/pmap/pmap_tlb.h:1.15
--- src/sys/uvm/pmap/pmap_tlb.h:1.14	Sat Aug  1 07:14:05 2020
+++ src/sys/uvm/pmap/pmap_tlb.h	Wed Aug 19 06:11:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.h,v 1.14 2020/08/01 07:14:05 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.h,v 1.15 2020/08/19 06:11:49 skrll Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -104,11 +104,11 @@ struct pmap_asid_info {
 	- offsetof(struct pmap, pm_pai[tlbinfo_index(ti)])))
 
 enum tlb_invalidate_op {
-	TLBINV_NOBODY=0,
-	TLBINV_ONE=1,
-	TLBINV_ALLUSER=2,
-	TLBINV_ALLKERNEL=3,
-	TLBINV_ALL=4
+	TLBINV_NOBODY = 0,
+	TLBINV_ONE = 1,
+	TLBINV_ALLUSER = 2,
+	TLBINV_ALLKERNEL = 3,
+	TLBINV_ALL = 4
 };
 
 struct pmap_tlb_info {



CVS commit: src/sys/uvm/pmap

2020-08-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Aug 19 06:08:27 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Unwrap short line KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.37 src/sys/uvm/pmap/pmap_tlb.c:1.38
--- src/sys/uvm/pmap/pmap_tlb.c:1.37	Wed Aug 19 06:07:03 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Wed Aug 19 06:08:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.37 2020/08/19 06:07:03 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.38 2020/08/19 06:08:27 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.37 2020/08/19 06:07:03 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.38 2020/08/19 06:08:27 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -551,8 +551,7 @@ pmap_tlb_shootdown_process(void)
 #endif
 
 	KASSERT(cpu_intr_p());
-	KASSERTMSG(ci->ci_cpl >= IPL_SCHED,
-	"%s: cpl (%d) < IPL_SCHED (%d)",
+	KASSERTMSG(ci->ci_cpl >= IPL_SCHED, "%s: cpl (%d) < IPL_SCHED (%d)",
 	__func__, ci->ci_cpl, IPL_SCHED);
 
 	TLBINFO_LOCK(ti);



CVS commit: src/sys/uvm/pmap

2020-08-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Aug 19 06:07:03 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
Fix inverted logic test in pmap_tlb_shootdown_process for if the victim
is onproc.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.36 src/sys/uvm/pmap/pmap_tlb.c:1.37
--- src/sys/uvm/pmap/pmap_tlb.c:1.36	Tue Aug 11 06:54:14 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Wed Aug 19 06:07:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.36 2020/08/11 06:54:14 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.37 2020/08/19 06:07:03 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.36 2020/08/11 06:54:14 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.37 2020/08/19 06:07:03 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -564,7 +564,7 @@ pmap_tlb_shootdown_process(void)
 		 */
 		struct pmap_asid_info * const pai = PMAP_PAI(ti->ti_victim, ti);
 		KASSERT(ti->ti_victim != pmap_kernel());
-		if (!pmap_tlb_intersecting_onproc_p(ti->ti_victim, ti)) {
+		if (pmap_tlb_intersecting_onproc_p(ti->ti_victim, ti)) {
 			/*
 			 * The victim is an active pmap so we will just
 			 * invalidate its TLB entries.



CVS commit: src/sys/uvm/pmap

2020-08-18 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Aug 18 11:48:21 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Fix small tyop in a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.17 src/sys/uvm/pmap/pmap_segtab.c:1.18
--- src/sys/uvm/pmap/pmap_segtab.c:1.17	Tue Aug 18 07:25:46 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Tue Aug 18 11:48:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.17 2020/08/18 07:25:46 skrll Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.18 2020/08/18 11:48:21 simonb Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.17 2020/08/18 07:25:46 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.18 2020/08/18 11:48:21 simonb Exp $");
 
 /*
  *	Manages physical address maps.
@@ -237,7 +237,7 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 			continue;
 
 		/*
-		 * If our caller want a callback, do so.
+		 * If our caller wants a callback, do so.
 		 */
 		if (callback != NULL) {
 			(*callback)(pmap, va, va + vinc, pte, flags);



CVS commit: src/sys/uvm

2020-08-18 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Aug 18 10:40:20 UTC 2020

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

Log Message:
fix amap_extend() to handle amaps where we previously failed to allocate
the ppref memory.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/uvm/uvm_amap.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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.122 src/sys/uvm/uvm_amap.c:1.123
--- src/sys/uvm/uvm_amap.c:1.122	Thu Jul  9 05:57:15 2020
+++ src/sys/uvm/uvm_amap.c	Tue Aug 18 10:40:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.122 2020/07/09 05:57:15 skrll Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.123 2020/08/18 10:40:20 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.122 2020/07/09 05:57:15 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.123 2020/08/18 10:40:20 chs Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -353,7 +353,7 @@ amap_extend(struct vm_map_entry *entry, 
 	struct vm_amap *amap = entry->aref.ar_amap;
 	int slotoff = entry->aref.ar_pageoff;
 	int slotmapped, slotadd, slotneed, slotadded, slotalloc;
-	int slotadj, slotarea;
+	int slotadj, slotarea, slotendoff;
 	int oldnslots;
 #ifdef UVM_AMAP_PPREF
 	int *newppref, *oldppref;
@@ -388,6 +388,36 @@ amap_extend(struct vm_map_entry *entry, 
 	}
 
 	/*
+	 * Because this amap only has 1 ref, we know that there is
+	 * only one vm_map_entry pointing to it, and the one entry is
+	 * using slots between slotoff and slotoff + slotmapped.  If
+	 * we have been using ppref then we know that only slots in
+	 * the one map entry's range can have anons, since ppref
+	 * allowed us to free any anons outside that range as other map
+	 * entries which used this amap were removed. But without ppref,
+	 * we couldn't know which slots were still needed by other map
+	 * entries, so we couldn't free any anons as we removed map
+	 * entries, and so any slot from 0 to am_nslot can have an
+	 * anon.  But now that we know there is only one map entry
+	 * left and we know its range, we can free up any anons
+	 * outside that range.  This is necessary because the rest of
+	 * this function assumes that there are no anons in the amap
+	 * outside of the one map entry's range.
+	 */
+
+	slotendoff = slotoff + slotmapped;
+	if (amap->am_ppref == PPREF_NONE) {
+		amap_wiperange(amap, 0, slotoff);
+		amap_wiperange(amap, slotendoff, amap->am_nslot - slotendoff);
+	}
+	for (i = 0; i < slotoff; i++) {
+		KASSERT(amap->am_anon[i] == NULL);
+	}
+	for (i = slotendoff; i < amap->am_nslot - slotendoff; i++) {
+		KASSERT(amap->am_anon[i] == NULL);
+	}
+
+	/*
 	 * case 1: we already have enough slots in the map and thus
 	 * only need to bump the reference counts on the slots we are
 	 * adding.



CVS commit: src/sys/uvm/pmap

2020-08-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Aug 18 07:25:46 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
Improve a panic message ever so slightly


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.16 src/sys/uvm/pmap/pmap_segtab.c:1.17
--- src/sys/uvm/pmap/pmap_segtab.c:1.16	Mon Aug 17 08:56:27 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Tue Aug 18 07:25:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.16 2020/08/17 08:56:27 mrg Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.17 2020/08/18 07:25:46 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.16 2020/08/17 08:56:27 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.17 2020/08/18 07:25:46 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -245,7 +245,7 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 #ifdef DEBUG
 		for (size_t j = 0; j < NPTEPG; j++) {
 			if (!pte_zero_p(pte[j]))
-panic("%s: pte entry %p not 0 (%#"PRIxPTE")",
+panic("%s: pte entry at %p not 0 (%#"PRIxPTE")",
 __func__, [j], pte_value(pte[j]));
 		}
 #endif



CVS commit: src/sys/uvm/pmap

2020-08-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Aug 17 08:56:27 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_segtab.c

Log Message:
add pmaphist calls around seg_tab[] manipulation.  hopefully will
help find what causes this:

panic: pmap_segtab_alloc: pm_segtab.seg_tab[1010] != 0 (0x98004eeb6068): 
from free list


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/uvm/pmap/pmap_segtab.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/pmap/pmap_segtab.c
diff -u src/sys/uvm/pmap/pmap_segtab.c:1.15 src/sys/uvm/pmap/pmap_segtab.c:1.16
--- src/sys/uvm/pmap/pmap_segtab.c:1.15	Fri Aug  7 07:19:45 2020
+++ src/sys/uvm/pmap/pmap_segtab.c	Mon Aug 17 08:56:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.15 2020/08/07 07:19:45 skrll Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.16 2020/08/17 08:56:27 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.15 2020/08/07 07:19:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.16 2020/08/17 08:56:27 mrg Exp $");
 
 /*
  *	Manages physical address maps.
@@ -210,12 +210,18 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 {
 	pmap_segtab_t *stp = *stp_p;
 
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(pmaphist, "pm=%#jx stpp=%#jx free=%jd",
+	(uintptr_t)pmap, (uintptr_t)stp_p, free_stp, 0);
+	UVMHIST_LOG(pmaphist, " callback=%jx flags=%jx va=%jx vinc=%jx",
+	(uintptr_t)callback, flags, (uintptr_t)va, (uintptr_t)vinc);
 	for (size_t i = (va / vinc) & (PMAP_SEGTABSIZE - 1);
 	 i < PMAP_SEGTABSIZE;
 	 i++, va += vinc) {
 #ifdef _LP64
 		if (vinc > NBSEG) {
 			if (stp->seg_seg[i] != NULL) {
+UVMHIST_LOG(pmaphist, " recursing", 0, 0, 0, 0);
 pmap_segtab_release(pmap, >seg_seg[i],
 true, callback, flags, va, vinc / NSEGPG);
 KASSERT(stp->seg_seg[i] == NULL);
@@ -255,6 +261,7 @@ pmap_segtab_release(pmap_t pmap, pmap_se
 #endif
 
 		stp->seg_tab[i] = NULL;
+		UVMHIST_LOG(pmaphist, " zeroing tab[%jd]", i, 0, 0, 0);
 	}
 
 	if (free_stp) {
@@ -448,6 +455,10 @@ pmap_pte_reserve(pmap_t pmap, vaddr_t va
 	pmap_segtab_t *stp = pmap->pm_segtab;
 	pt_entry_t *pte;
 
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(pmaphist, "pm=%#jx va=%#jx flags=%jx",
+	(uintptr_t)pmap, (uintptr_t)va, flags, 0);
+
 	pte = pmap_pte_lookup(pmap, va);
 	if (__predict_false(pte == NULL)) {
 #ifdef _LP64
@@ -513,6 +524,8 @@ pmap_pte_reserve(pmap_t pmap, vaddr_t va
 		*pte_p = pte;
 #endif
 		KASSERT(pte == stp->seg_tab[(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1)]);
+		UVMHIST_LOG(pmaphist, " set tab[%jd]=%jx",
+		(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1), pte, 0, 0);
 
 #ifdef DEBUG
 		for (size_t i = 0; i < NPTEPG; i++) {



CVS commit: src/sys/uvm

2020-08-15 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Aug 16 00:24:41 UTC 2020

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

Log Message:
in uvm_findpage(), when uvm_page_array_fill_and_peek() returns a page
that is not the one we want and we make an assertion about dirtiness,
check the dirty status of the page we wanted rather than the page we got.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/uvm/uvm_vnode.c:1.117
--- src/sys/uvm/uvm_vnode.c:1.116	Fri Aug 14 09:06:15 2020
+++ src/sys/uvm/uvm_vnode.c	Sun Aug 16 00:24:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_vnode.c,v 1.116 2020/08/14 09:06:15 chs Exp $	*/
+/*	$NetBSD: uvm_vnode.c,v 1.117 2020/08/16 00:24:41 chs Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.116 2020/08/14 09:06:15 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.117 2020/08/16 00:24:41 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -313,12 +313,13 @@ uvn_findpage(struct uvm_object *uobj, vo
 		 */
 		pg = uvm_page_array_fill_and_peek(a, offset, nleft);
 		if (pg != NULL && pg->offset != offset) {
+			struct vm_page __diagused *tpg;
 			KASSERT(
 			((a->ar_flags & UVM_PAGE_ARRAY_FILL_BACKWARD) != 0)
 			== (pg->offset < offset));
-			KASSERT(uvm_pagelookup(uobj, offset) == NULL ||
+			KASSERT((tpg = uvm_pagelookup(uobj, offset)) == NULL ||
 ((a->ar_flags & UVM_PAGE_ARRAY_FILL_DIRTY) != 0 &&
- !uvm_obj_page_dirty_p(pg)));
+ !uvm_obj_page_dirty_p(tpg)));
 			pg = NULL;
 			if ((a->ar_flags & UVM_PAGE_ARRAY_FILL_DENSE) != 0) {
 UVMHIST_LOG(ubchist, "dense", 0,0,0,0);



CVS commit: src/sys/uvm

2020-08-15 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sat Aug 15 07:24:10 UTC 2020

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

Log Message:
use uint64_t rather than int for storing the index of a page within an object.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/uvm/uvm_object.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_object.c
diff -u src/sys/uvm/uvm_object.c:1.24 src/sys/uvm/uvm_object.c:1.25
--- src/sys/uvm/uvm_object.c:1.24	Fri Aug 14 09:06:15 2020
+++ src/sys/uvm/uvm_object.c	Sat Aug 15 07:24:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_object.c,v 1.24 2020/08/14 09:06:15 chs Exp $	*/
+/*	$NetBSD: uvm_object.c,v 1.25 2020/08/15 07:24:09 chs Exp $	*/
 
 /*
  * Copyright (c) 2006, 2010, 2019 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_object.c,v 1.24 2020/08/14 09:06:15 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_object.c,v 1.25 2020/08/15 07:24:09 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -259,7 +259,7 @@ static inline bool
 uvm_obj_page_tag_p(struct vm_page *pg, int tag)
 {
 	struct uvm_object *uobj = pg->uobject;
-	int pgidx = pg->offset >> PAGE_SHIFT;
+	uint64_t pgidx = pg->offset >> PAGE_SHIFT;
 
 	KASSERT(uobj != NULL);
 	KASSERT(rw_lock_held(uobj->vmobjlock));
@@ -270,7 +270,7 @@ static inline void
 uvm_obj_page_set_tag(struct vm_page *pg, int tag)
 {
 	struct uvm_object *uobj = pg->uobject;
-	int pgidx = pg->offset >> PAGE_SHIFT;
+	uint64_t pgidx = pg->offset >> PAGE_SHIFT;
 
 	KASSERT(uobj != NULL);
 	KASSERT(rw_write_held(uobj->vmobjlock));
@@ -281,7 +281,7 @@ static inline void
 uvm_obj_page_clear_tag(struct vm_page *pg, int tag)
 {
 	struct uvm_object *uobj = pg->uobject;
-	int pgidx = pg->offset >> PAGE_SHIFT;
+	uint64_t pgidx = pg->offset >> PAGE_SHIFT;
 
 	KASSERT(uobj != NULL);
 	KASSERT(rw_write_held(uobj->vmobjlock));



CVS commit: src/sys/uvm

2020-08-14 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Aug 15 01:27:22 UTC 2020

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

Log Message:
add a __diagused to fix non-DIAGNOSTIC kernel


To generate a diff of this commit:
cvs rdiff -u -r1.245 -r1.246 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.245 src/sys/uvm/uvm_page.c:1.246
--- src/sys/uvm/uvm_page.c:1.245	Fri Aug 14 09:06:15 2020
+++ src/sys/uvm/uvm_page.c	Sat Aug 15 01:27:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.245 2020/08/14 09:06:15 chs Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.246 2020/08/15 01:27:22 tnn Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.245 2020/08/14 09:06:15 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.246 2020/08/15 01:27:22 tnn Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1790,7 +1790,7 @@ struct vm_page *
 uvm_pagelookup(struct uvm_object *obj, voff_t off)
 {
 	struct vm_page *pg;
-	bool ddb = false;
+	bool ddb __diagused = false;
 #ifdef DDB
 	extern int db_active;
 	ddb = db_active != 0;



CVS commit: src/sys/uvm/pmap

2020-08-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Aug 11 06:54:14 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.c

Log Message:
s/pmaphist/maphist/ for now


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.35 src/sys/uvm/pmap/pmap_tlb.c:1.36
--- src/sys/uvm/pmap/pmap_tlb.c:1.35	Tue Aug 11 06:09:44 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Tue Aug 11 06:54:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.35 2020/08/11 06:09:44 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.36 2020/08/11 06:54:14 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.35 2020/08/11 06:09:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.36 2020/08/11 06:54:14 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -215,7 +215,7 @@ static void
 pmap_tlb_pai_check(struct pmap_tlb_info *ti, bool locked_p)
 {
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLARGS(pmaphist, "(ti=%#jx)", (uintptr_t)ti, 0, 0, 0);
+	UVMHIST_CALLARGS(maphist, "(ti=%#jx)", (uintptr_t)ti, 0, 0, 0);
 
 #ifdef DIAGNOSTIC
 	struct pmap_asid_info *pai;
@@ -236,7 +236,7 @@ pmap_tlb_pai_check(struct pmap_tlb_info 
 	if (!locked_p)
 		TLBINFO_UNLOCK(ti);
 #endif
-	UVMHIST_LOG(pmaphist, " <-- done", 0, 0, 0, 0);
+	UVMHIST_LOG(maphist, " <-- done", 0, 0, 0, 0);
 }
 
 static void



CVS commit: src/sys/uvm/pmap

2020-08-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Aug 11 06:09:44 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap.c pmap_tlb.c

Log Message:
More UVMHIST_LOG.  Remove some commented output printfs.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/uvm/pmap/pmap.c
cvs rdiff -u -r1.34 -r1.35 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.52 src/sys/uvm/pmap/pmap.c:1.53
--- src/sys/uvm/pmap/pmap.c:1.52	Tue Aug 11 05:43:45 2020
+++ src/sys/uvm/pmap/pmap.c	Tue Aug 11 06:09:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.52 2020/08/11 05:43:45 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.53 2020/08/11 06:09:44 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.52 2020/08/11 05:43:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.53 2020/08/11 06:09:44 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -388,6 +388,8 @@ pmap_page_set_attributes(struct vm_page_
 static void
 pmap_page_syncicache(struct vm_page *pg)
 {
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLED(pmaphist);
 #ifndef MULTIPROCESSOR
 	struct pmap * const curpmap = curlwp->l_proc->p_vmspace->vm_map.pmap;
 #endif
@@ -403,9 +405,14 @@ pmap_page_syncicache(struct vm_page *pg)
 	VM_PAGEMD_PVLIST_READLOCK(mdpg);
 	pmap_pvlist_check(mdpg);
 
+	UVMHIST_LOG(pmaphist, "pv %jx pv_pmap %jx\n", (uintptr_t)pv,
+	 (uintptr_t)pv->pv_pmap, 0, 0);
+
 	if (pv->pv_pmap != NULL) {
 		for (; pv != NULL; pv = pv->pv_next) {
 #ifdef MULTIPROCESSOR
+			UVMHIST_LOG(pmaphist, "pv %jx pv_pmap %jx\n",
+			(uintptr_t)pv, (uintptr_t)pv->pv_pmap, 0, 0);
 			kcpuset_merge(onproc, pv->pv_pmap->pm_onproc);
 			if (kcpuset_match(onproc, kcpuset_running)) {
 break;

Index: src/sys/uvm/pmap/pmap_tlb.c
diff -u src/sys/uvm/pmap/pmap_tlb.c:1.34 src/sys/uvm/pmap/pmap_tlb.c:1.35
--- src/sys/uvm/pmap/pmap_tlb.c:1.34	Sun Aug  9 06:26:49 2020
+++ src/sys/uvm/pmap/pmap_tlb.c	Tue Aug 11 06:09:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.34 2020/08/09 06:26:49 skrll Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.35 2020/08/11 06:09:44 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.34 2020/08/09 06:26:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.35 2020/08/11 06:09:44 skrll Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -214,6 +214,9 @@ pmap_tlb_intersecting_onproc_p(pmap_t pm
 static void
 pmap_tlb_pai_check(struct pmap_tlb_info *ti, bool locked_p)
 {
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(pmaphist, "(ti=%#jx)", (uintptr_t)ti, 0, 0, 0);
+
 #ifdef DIAGNOSTIC
 	struct pmap_asid_info *pai;
 	if (!locked_p)
@@ -233,6 +236,7 @@ pmap_tlb_pai_check(struct pmap_tlb_info 
 	if (!locked_p)
 		TLBINFO_UNLOCK(ti);
 #endif
+	UVMHIST_LOG(pmaphist, " <-- done", 0, 0, 0, 0);
 }
 
 static void
@@ -268,9 +272,13 @@ pmap_tlb_pai_reset(struct pmap_tlb_info 
 	 */
 	if (PMAP_TLB_FLUSH_ASID_ON_RESET) {
 #ifndef MULTIPROCESSOR
+		UVMHIST_LOG(maphist, " ... asid %u flushed", pai->pai_asid, 0,
+		0, 0);
 		tlb_invalidate_asids(pai->pai_asid, pai->pai_asid);
 #endif
 		if (TLBINFO_ASID_INUSE_P(ti, pai->pai_asid)) {
+			UVMHIST_LOG(maphist, " ... asid marked unused",
+			pai->pai_asid, 0, 0, 0);
 			TLBINFO_ASID_MARK_UNUSED(ti, pai->pai_asid);
 			ti->ti_asids_free++;
 		}
@@ -363,13 +371,13 @@ pmap_tlb_info_init(struct pmap_tlb_info 
 #endif /* MULTIPROCESSOR */
 	KASSERT(ti == _tlb0_info);
 	KASSERT(ti->ti_lock == _tlb0_lock);
-	//printf("ti_lock %p ", ti->ti_lock);
+
 	mutex_init(ti->ti_lock, MUTEX_DEFAULT, IPL_SCHED);
 #if defined(MULTIPROCESSOR) && PMAP_TLB_MAX > 1
 	kcpuset_create(>ti_kcpuset, true);
 	kcpuset_set(ti->ti_kcpuset, cpu_index(curcpu()));
 #endif
-	//printf("asid ");
+
 	if (ti->ti_asid_max == 0) {
 		ti->ti_asid_max = pmap_md_tlb_asid_max();
 		ti->ti_asids_free = TLBINFO_ASID_INITIAL_FREE(ti->ti_asid_max);
@@ -991,12 +999,13 @@ pmap_tlb_asid_deactivate(pmap_t pm)
 	}
 #endif
 	curcpu()->ci_pmap_asid_cur = KERNEL_PID;
-	UVMHIST_LOG(maphist, " <-- done (pm=%#jx)", (uintptr_t)pm, 0, 0, 0);
 	tlb_set_asid(KERNEL_PID);
+
 	pmap_tlb_pai_check(cpu_tlb_info(curcpu()), false);
 #if defined(DEBUG)
 	pmap_tlb_asid_check();
 #endif
+	UVMHIST_LOG(maphist, " <-- done (pm=%#jx)", (uintptr_t)pm, 0, 0, 0);
 }
 
 void



CVS commit: src/sys/uvm/pmap

2020-08-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Aug 11 05:43:45 UTC 2020

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

Log Message:
Fix a comment


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/uvm/pmap/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/uvm/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.51 src/sys/uvm/pmap/pmap.c:1.52
--- src/sys/uvm/pmap/pmap.c:1.51	Fri Aug  7 07:19:45 2020
+++ src/sys/uvm/pmap/pmap.c	Tue Aug 11 05:43:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.51 2020/08/07 07:19:45 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.52 2020/08/11 05:43:45 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.51 2020/08/07 07:19:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.52 2020/08/11 05:43:45 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -1309,8 +1309,6 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 
 	/*
 	 * Now validate mapping with desired protection/wiring.
-	 * Assume uniform modified and referenced status for all
-	 * MIPS pages in a MACH page.
 	 */
 	if (wired) {
 		pmap->pm_stats.wired_count++;



CVS commit: src/sys/uvm/pmap

2020-08-01 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Aug  1 07:14:05 UTC 2020

Modified Files:
src/sys/uvm/pmap: pmap_tlb.h

Log Message:
Provide a TLBINFO_OWNED


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/uvm/pmap/pmap_tlb.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/pmap/pmap_tlb.h
diff -u src/sys/uvm/pmap/pmap_tlb.h:1.13 src/sys/uvm/pmap/pmap_tlb.h:1.14
--- src/sys/uvm/pmap/pmap_tlb.h:1.13	Mon Feb 19 22:01:15 2018
+++ src/sys/uvm/pmap/pmap_tlb.h	Sat Aug  1 07:14:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.h,v 1.13 2018/02/19 22:01:15 jdolecek Exp $	*/
+/*	$NetBSD: pmap_tlb.h,v 1.14 2020/08/01 07:14:05 skrll Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -96,6 +96,7 @@ struct pmap_asid_info {
 
 #define	TLBINFO_LOCK(ti)		mutex_spin_enter((ti)->ti_lock)
 #define	TLBINFO_UNLOCK(ti)		mutex_spin_exit((ti)->ti_lock)
+#define	TLBINFO_OWNED(ti)		mutex_owned((ti)->ti_lock)
 #define	PMAP_PAI_ASIDVALID_P(pai, ti)	((pai)->pai_asid != 0)
 #define	PMAP_PAI(pmap, ti)		(&(pmap)->pm_pai[tlbinfo_index(ti)])
 #define	PAI_PMAP(pai, ti)	\



CVS commit: src/sys/uvm

2020-07-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jul 23 19:07:01 UTC 2020

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

Log Message:
unifdef -U_LKM


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/uvm/uvm_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/uvm/uvm_param.h
diff -u src/sys/uvm/uvm_param.h:1.40 src/sys/uvm/uvm_param.h:1.41
--- src/sys/uvm/uvm_param.h:1.40	Thu Jun 25 18:20:18 2020
+++ src/sys/uvm/uvm_param.h	Thu Jul 23 19:07:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_param.h,v 1.40 2020/06/25 18:20:18 jdolecek Exp $	*/
+/*	$NetBSD: uvm_param.h,v 1.41 2020/07/23 19:07:01 skrll Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -133,11 +133,11 @@
 
 /*
  * If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
- * non-constant PAGE_SIZE, et al for LKMs.
+ * non-constant PAGE_SIZE, et al for modules.
  */
 #if (MIN_PAGE_SIZE != MAX_PAGE_SIZE)
 #define	__uvmexp_pagesize
-#if defined(_LKM) || defined(_MODULE)
+#if defined(_MODULE)
 #undef PAGE_SIZE
 #undef PAGE_MASK
 #undef PAGE_SHIFT



CVS commit: src/sys/uvm/pmap

2020-07-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jul 18 16:12:09 UTC 2020

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

Log Message:
Always call pmap_segtab_activate in pmap_activate.  pmap_segtab_activate
does the right thing if called with non-curlwp.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/uvm/pmap/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/uvm/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.49 src/sys/uvm/pmap/pmap.c:1.50
--- src/sys/uvm/pmap/pmap.c:1.49	Sun Apr 12 15:36:18 2020
+++ src/sys/uvm/pmap/pmap.c	Sat Jul 18 16:12:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.49 2020/04/12 15:36:18 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.50 2020/07/18 16:12:09 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.49 2020/04/12 15:36:18 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.50 2020/07/18 16:12:09 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -723,9 +723,7 @@ pmap_activate(struct lwp *l)
 	kpreempt_disable();
 	pmap_tlb_miss_lock_enter();
 	pmap_tlb_asid_acquire(pmap, l);
-	if (l == curlwp) {
-		pmap_segtab_activate(pmap, l);
-	}
+	pmap_segtab_activate(pmap, l);
 	pmap_tlb_miss_lock_exit();
 	kpreempt_enable();
 



CVS commit: src/sys/uvm

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 15:08:26 UTC 2020

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

Log Message:
Fix typo. Use PRIxPADDR rather than casting.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/uvm/uvm_physseg.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_physseg.c
diff -u src/sys/uvm/uvm_physseg.c:1.16 src/sys/uvm/uvm_physseg.c:1.17
--- src/sys/uvm/uvm_physseg.c:1.16	Mon Jul 13 10:46:10 2020
+++ src/sys/uvm/uvm_physseg.c	Wed Jul 15 15:08:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_physseg.c,v 1.16 2020/07/13 10:46:10 mrg Exp $ */
+/* $NetBSD: uvm_physseg.c,v 1.17 2020/07/15 15:08:26 rin Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -1209,8 +1209,8 @@ uvm_page_physload(paddr_t start, paddr_t
 	if (free_list >= VM_NFREELIST || free_list < VM_FREELIST_DEFAULT)
 		panic("uvm_page_physload: bad free list %d", free_list);
 	if (start >= end)
-		panic("uvm_page_physload: start[%llx] >= en[%llx]d",
-		(unsigned long long)start, (unsigned long long)end);
+		panic("uvm_page_physload: start[%" PRIxPADDR "] >= end[%"
+		PRIxPADDR "]", start, end);
 
 	if (uvm_physseg_plug(start, end - start, ) == false) {
 		panic("uvm_physseg_plug() failed at boot.");



CVS commit: src/sys/uvm

2020-07-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 13 10:46:10 UTC 2020

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

Log Message:
paddr_t can't be printed by "%lx" in some platforms.

fix the eg, i386 build.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/uvm/uvm_physseg.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_physseg.c
diff -u src/sys/uvm/uvm_physseg.c:1.15 src/sys/uvm/uvm_physseg.c:1.16
--- src/sys/uvm/uvm_physseg.c:1.15	Mon Jul 13 05:52:50 2020
+++ src/sys/uvm/uvm_physseg.c	Mon Jul 13 10:46:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_physseg.c,v 1.15 2020/07/13 05:52:50 mrg Exp $ */
+/* $NetBSD: uvm_physseg.c,v 1.16 2020/07/13 10:46:10 mrg Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -1209,7 +1209,8 @@ uvm_page_physload(paddr_t start, paddr_t
 	if (free_list >= VM_NFREELIST || free_list < VM_FREELIST_DEFAULT)
 		panic("uvm_page_physload: bad free list %d", free_list);
 	if (start >= end)
-		panic("uvm_page_physload: start[%lx] >= en[%lx]d", start, end);
+		panic("uvm_page_physload: start[%llx] >= en[%llx]d",
+		(unsigned long long)start, (unsigned long long)end);
 
 	if (uvm_physseg_plug(start, end - start, ) == false) {
 		panic("uvm_physseg_plug() failed at boot.");



CVS commit: src/sys/uvm

2020-07-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 13 05:52:50 UTC 2020

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

Log Message:
actually show the start/end that failed start < end in uvm_page_physload().


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/uvm/uvm_physseg.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_physseg.c
diff -u src/sys/uvm/uvm_physseg.c:1.14 src/sys/uvm/uvm_physseg.c:1.15
--- src/sys/uvm/uvm_physseg.c:1.14	Sun Mar 15 21:06:30 2020
+++ src/sys/uvm/uvm_physseg.c	Mon Jul 13 05:52:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_physseg.c,v 1.14 2020/03/15 21:06:30 ad Exp $ */
+/* $NetBSD: uvm_physseg.c,v 1.15 2020/07/13 05:52:50 mrg Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -1209,7 +1209,7 @@ uvm_page_physload(paddr_t start, paddr_t
 	if (free_list >= VM_NFREELIST || free_list < VM_FREELIST_DEFAULT)
 		panic("uvm_page_physload: bad free list %d", free_list);
 	if (start >= end)
-		panic("uvm_page_physload: start >= end");
+		panic("uvm_page_physload: start[%lx] >= en[%lx]d", start, end);
 
 	if (uvm_physseg_plug(start, end - start, ) == false) {
 		panic("uvm_physseg_plug() failed at boot.");



CVS commit: src/sys/uvm

2020-07-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Jul  9 09:24:33 UTC 2020

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

Log Message:
PR kern/55467
tmpfs calls pmap_kenter_pa(9) with virtual address with page offset

Bisectioning revealed that the failure starts with this commit:

sys/fs/tmpfs/tmpfs_vnops.c rev 1.142:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/fs/tmpfs/tmpfs_vnops.c#rev1.142

by which tmpfs became to use UBC_FAULTBUSY flag for ubc_uiomove(9).
If this flag is specified, pmap_kenter_pa(9) is called with virtual
address with page offset via ubc_alloc(9):

https://nxr.netbsd.org/xref/src/sys/uvm/uvm_bio.c#616

Most ports seem to neglect silently page offset of va argument for
pmap_kenter_pa(9). However, it causes KASSERT failure correctly for
powerpc/booke. So, truncate page offset there.

Now, tmpfs works just fine on evbppc-booke, and I've confirmed that
no new failures are detected by ATF.

Discussed with chs@. Thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 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.120 src/sys/uvm/uvm_bio.c:1.121
--- src/sys/uvm/uvm_bio.c:1.120	Thu Jul  9 05:57:15 2020
+++ src/sys/uvm/uvm_bio.c	Thu Jul  9 09:24:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.120 2020/07/09 05:57:15 skrll Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.121 2020/07/09 09:24:32 rin Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.120 2020/07/09 05:57:15 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.121 2020/07/09 09:24:32 rin Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -613,7 +613,8 @@ again_faultbusy:
 rw_exit(uobj->vmobjlock);
 pgs[i] = pg;
 			}
-			pmap_kenter_pa(va + slot_offset + (i << PAGE_SHIFT),
+			pmap_kenter_pa(
+			va + trunc_page(slot_offset) + (i << PAGE_SHIFT),
 			VM_PAGE_TO_PHYS(pg),
 			VM_PROT_READ | VM_PROT_WRITE, 0);
 		}



CVS commit: src/sys/uvm

2020-07-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jul  9 05:57:15 UTC 2020

Modified Files:
src/sys/uvm: uvm_amap.c uvm_anon.c uvm_aobj.c uvm_bio.c uvm_device.c
uvm_fault.c uvm_km.c uvm_map.c uvm_page.c uvm_pager.c uvm_pdaemon.c
uvm_swap.c uvm_vnode.c

Log Message:
Consistently use UVMHIST(__func__)

Convert UVMHIST_{CALLED,LOG} into UVMHIST_CALLARGS


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/uvm/uvm_amap.c
cvs rdiff -u -r1.78 -r1.79 src/sys/uvm/uvm_anon.c
cvs rdiff -u -r1.148 -r1.149 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.119 -r1.120 src/sys/uvm/uvm_bio.c
cvs rdiff -u -r1.70 -r1.71 src/sys/uvm/uvm_device.c
cvs rdiff -u -r1.227 -r1.228 src/sys/uvm/uvm_fault.c
cvs rdiff -u -r1.158 -r1.159 src/sys/uvm/uvm_km.c
cvs rdiff -u -r1.384 -r1.385 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.243 -r1.244 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.127 -r1.128 src/sys/uvm/uvm_pager.c
cvs rdiff -u -r1.129 -r1.130 src/sys/uvm/uvm_pdaemon.c
cvs rdiff -u -r1.196 -r1.197 src/sys/uvm/uvm_swap.c
cvs rdiff -u -r1.114 -r1.115 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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.121 src/sys/uvm/uvm_amap.c:1.122
--- src/sys/uvm/uvm_amap.c:1.121	Wed Jul  8 13:26:22 2020
+++ src/sys/uvm/uvm_amap.c	Thu Jul  9 05:57:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.121 2020/07/08 13:26:22 skrll Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.122 2020/07/09 05:57:15 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.121 2020/07/08 13:26:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.122 2020/07/09 05:57:15 skrll Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -235,7 +235,7 @@ amap_alloc(vaddr_t sz, vaddr_t padsz, in
 {
 	struct vm_amap *amap;
 	int slots, padslots;
-	UVMHIST_FUNC("amap_alloc"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 
 	AMAP_B2SLOT(slots, sz);
 	AMAP_B2SLOT(padslots, padsz);
@@ -321,7 +321,7 @@ amap_free(struct vm_amap *amap)
 {
 	int slots;
 
-	UVMHIST_FUNC("amap_free"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 
 	KASSERT(amap->am_ref == 0 && amap->am_nused == 0);
 	KASSERT((amap->am_flags & AMAP_SWAPOFF) == 0);
@@ -363,9 +363,8 @@ amap_extend(struct vm_map_entry *entry, 
 	const km_flag_t kmflags =
 	(flags & AMAP_EXTEND_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
 
-	UVMHIST_FUNC("amap_extend"); UVMHIST_CALLED(maphist);
-
-	UVMHIST_LOG(maphist, "  (entry=%#jx, addsize=%#jx, flags=%#jx)",
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(maphist, "  (entry=%#jx, addsize=%#jx, flags=%#jx)",
 	(uintptr_t)entry, addsize, flags, 0);
 
 	/*
@@ -725,8 +724,8 @@ amap_wipeout(struct vm_amap *amap)
 {
 	u_int lcv;
 
-	UVMHIST_FUNC("amap_wipeout"); UVMHIST_CALLED(maphist);
-	UVMHIST_LOG(maphist,"(amap=%#jx)", (uintptr_t)amap, 0,0,0);
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(maphist,"(amap=%#jx)", (uintptr_t)amap, 0,0,0);
 
 	KASSERT(rw_write_held(amap->am_lock));
 	KASSERT(amap->am_ref == 0);
@@ -797,9 +796,9 @@ amap_copy(struct vm_map *map, struct vm_
 	krwlock_t *oldlock;
 	vsize_t len;
 
-	UVMHIST_FUNC("amap_copy"); UVMHIST_CALLED(maphist);
-	UVMHIST_LOG(maphist, "  (map=%#j, entry=%#j, flags=%jd)",
-		(uintptr_t)map, (uintptr_t)entry, flags, 0);
+	UVMHIST_FUNC(__func__);
+	UVMHIST_CALLARGS(maphist, "  (map=%#j, entry=%#j, flags=%jd)",
+	(uintptr_t)map, (uintptr_t)entry, flags, -2);
 
 	KASSERT(map != kernel_map);	/* we use nointr pool */
 
@@ -1416,7 +1415,7 @@ amap_lookup(struct vm_aref *aref, vaddr_
 	struct vm_anon *an;
 	u_int slot;
 
-	UVMHIST_FUNC("amap_lookup"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 	KASSERT(rw_lock_held(amap->am_lock));
 
 	AMAP_B2SLOT(slot, offset);
@@ -1445,7 +1444,7 @@ amap_lookups(struct vm_aref *aref, vaddr
 	struct vm_amap *amap = aref->ar_amap;
 	u_int slot;
 
-	UVMHIST_FUNC("amap_lookups"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 	KASSERT(rw_lock_held(amap->am_lock));
 
 	AMAP_B2SLOT(slot, offset);
@@ -1483,7 +1482,7 @@ amap_add(struct vm_aref *aref, vaddr_t o
 	struct vm_amap *amap = aref->ar_amap;
 	u_int slot;
 
-	UVMHIST_FUNC("amap_add"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 	KASSERT(rw_write_held(amap->am_lock));
 	KASSERT(anon->an_lock == amap->am_lock);
 
@@ -1525,7 +1524,7 @@ amap_unadd(struct vm_aref *aref, vaddr_t
 	struct vm_amap *amap = aref->ar_amap;
 	u_int slot, ptr, last;
 
-	UVMHIST_FUNC("amap_unadd"); UVMHIST_CALLED(maphist);
+	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 	KASSERT(rw_write_held(amap->am_lock));
 
 	AMAP_B2SLOT(slot, offset);
@@ -1593,7 +1592,7 @@ amap_adjref_anons(struct vm_amap *amap, 
 void
 amap_ref(struct vm_amap 

CVS commit: src/sys/uvm

2020-07-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul  8 13:26:22 UTC 2020

Modified Files:
src/sys/uvm: uvm_amap.c uvm_anon.c uvm_aobj.c uvm_bio.c uvm_km.c
uvm_pager.c uvm_swap.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/uvm/uvm_amap.c
cvs rdiff -u -r1.77 -r1.78 src/sys/uvm/uvm_anon.c
cvs rdiff -u -r1.147 -r1.148 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.118 -r1.119 src/sys/uvm/uvm_bio.c
cvs rdiff -u -r1.157 -r1.158 src/sys/uvm/uvm_km.c
cvs rdiff -u -r1.126 -r1.127 src/sys/uvm/uvm_pager.c
cvs rdiff -u -r1.195 -r1.196 src/sys/uvm/uvm_swap.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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.120 src/sys/uvm/uvm_amap.c:1.121
--- src/sys/uvm/uvm_amap.c:1.120	Sun May 17 15:07:22 2020
+++ src/sys/uvm/uvm_amap.c	Wed Jul  8 13:26:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.120 2020/05/17 15:07:22 ad Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.121 2020/07/08 13:26:22 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.120 2020/05/17 15:07:22 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.121 2020/07/08 13:26:22 skrll Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -859,7 +859,7 @@ amap_copy(struct vm_map *map, struct vm_
 	}
 
 	/*
-	 * First check and see if we are the only map entry referencing 
+	 * First check and see if we are the only map entry referencing
 	 * he amap we currently have.  If so, then just take it over instead
 	 * of copying it.  Note that we are reading am_ref without lock held
 	 * as the value value can only be one if we have the only reference
@@ -1388,7 +1388,7 @@ amap_swap_off(int startslot, int endslot
 		if (am) {
 			amap_unlock(am);
 		}
-		
+
 		mutex_enter(_list_lock);
 		KASSERT(LIST_NEXT(_prev, am_list) == _next ||
 		LIST_NEXT(LIST_NEXT(_prev, am_list), am_list) ==

Index: src/sys/uvm/uvm_anon.c
diff -u src/sys/uvm/uvm_anon.c:1.77 src/sys/uvm/uvm_anon.c:1.78
--- src/sys/uvm/uvm_anon.c:1.77	Sun Mar 22 18:32:42 2020
+++ src/sys/uvm/uvm_anon.c	Wed Jul  8 13:26:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_anon.c,v 1.77 2020/03/22 18:32:42 ad Exp $	*/
+/*	$NetBSD: uvm_anon.c,v 1.78 2020/07/08 13:26:22 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.77 2020/03/22 18:32:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.78 2020/07/08 13:26:22 skrll Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -235,7 +235,7 @@ uvm_anon_lockloanpg(struct vm_anon *anon
 /*
  * someone locking the object has a chance to
  * lock us right now
- * 
+ *
  * XXX Better than yielding but inadequate.
  */
 mutex_exit(>interlock);

Index: src/sys/uvm/uvm_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.147 src/sys/uvm/uvm_aobj.c:1.148
--- src/sys/uvm/uvm_aobj.c:1.147	Mon May 25 22:04:51 2020
+++ src/sys/uvm/uvm_aobj.c	Wed Jul  8 13:26:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.147 2020/05/25 22:04:51 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.148 2020/07/08 13:26:22 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.147 2020/05/25 22:04:51 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.148 2020/07/08 13:26:22 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -965,7 +965,7 @@ uao_get(struct uvm_object *uobj, voff_t 
 		}
 
 		/*
- 		 * if swslot == 0, page hasn't existed before and is zeroed. 
+ 		 * if swslot == 0, page hasn't existed before and is zeroed.
  		 * otherwise we have a "fake/busy/clean" page that we just
  		 * allocated.  do the needed "i/o", reading from swap.
  		 */

Index: src/sys/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.118 src/sys/uvm/uvm_bio.c:1.119
--- src/sys/uvm/uvm_bio.c:1.118	Thu Jun 25 14:04:30 2020
+++ src/sys/uvm/uvm_bio.c	Wed Jul  8 13:26:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.118 2020/06/25 14:04:30 jdolecek Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.119 2020/07/08 13:26:22 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.118 2020/06/25 14:04:30 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.119 2020/07/08 13:26:22 skrll Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -747,12 +747,12 @@ ubc_uiomove(struct uvm_object *uobj, str
 	/*
 	 * during direct access pages need to be held busy to prevent them
 	 * changing identity, and therefore if we read or write an object
-	 * into a mapped view of same we could deadlock while faulting. 
+	 * into a mapped view of same we could deadlock while faulting.
 	 *
 	 * avoid the 

CVS commit: src/sys/uvm/pmap

2020-07-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul  8 12:12:16 UTC 2020

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

Log Message:
Comment updates


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/uvm/pmap/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/uvm/pmap/pmap.h
diff -u src/sys/uvm/pmap/pmap.h:1.14 src/sys/uvm/pmap/pmap.h:1.15
--- src/sys/uvm/pmap/pmap.h:1.14	Sun Mar 15 11:36:24 2020
+++ src/sys/uvm/pmap/pmap.h	Wed Jul  8 12:12:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.14 2020/03/15 11:36:24 rin Exp $	*/
+/*	$NetBSD: pmap.h,v 1.15 2020/07/08 12:12:16 skrll Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -103,6 +103,11 @@ typedef union pmap_segtab {
 struct pmap;
 typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
 	pt_entry_t *, uintptr_t);
+
+/*
+ * Common part of the bootstraping the system enough to run with
+ * virtual memory.
+ */
 void pmap_bootstrap_common(void);
 pt_entry_t *pmap_pte_lookup(struct pmap *, vaddr_t);
 pt_entry_t *pmap_pte_reserve(struct pmap *, vaddr_t, int);
@@ -182,9 +187,6 @@ extern pmap_segtab_t pmap_kern_segtab;
 #define	pmap_wired_count(pmap) 	((pmap)->pm_stats.wired_count)
 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
 
-/*
- *	Bootstrap the system enough to run with virtual memory.
- */
 bool	pmap_remove_all(pmap_t);
 void	pmap_set_modified(paddr_t);
 bool	pmap_page_clear_attributes(struct vm_page_md *, u_int);



CVS commit: src/sys/uvm

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jun 29 23:40:28 UTC 2020

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

Log Message:
uvm: Make sure swap encryption IV is 128-bit-aligned on stack.

Will help hardware-assisted AES.


To generate a diff of this commit:
cvs rdiff -u -r1.194 -r1.195 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.194 src/sys/uvm/uvm_swap.c:1.195
--- src/sys/uvm/uvm_swap.c:1.194	Mon Jun 29 23:33:46 2020
+++ src/sys/uvm/uvm_swap.c	Mon Jun 29 23:40:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.194 2020/06/29 23:33:46 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.195 2020/06/29 23:40:28 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.194 2020/06/29 23:33:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.195 2020/06/29 23:40:28 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -2089,7 +2089,7 @@ uvm_swap_genkey(struct swapdev *sdp)
 static void
 uvm_swap_encryptpage(struct swapdev *sdp, void *kva, int slot)
 {
-	uint8_t preiv[16] = {0}, iv[16];
+	uint8_t preiv[16] __aligned(16) = {0}, iv[16] __aligned(16);
 
 	/* iv := AES_k(le32enc(slot) || 0^96) */
 	le32enc(preiv, slot);
@@ -2111,7 +2111,7 @@ uvm_swap_encryptpage(struct swapdev *sdp
 static void
 uvm_swap_decryptpage(struct swapdev *sdp, void *kva, int slot)
 {
-	uint8_t preiv[16] = {0}, iv[16];
+	uint8_t preiv[16] __aligned(16) = {0}, iv[16] __aligned(16);
 
 	/* iv := AES_k(le32enc(slot) || 0^96) */
 	le32enc(preiv, slot);



CVS commit: src/sys/uvm

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jun 29 23:33:46 UTC 2020

Modified Files:
src/sys/uvm: files.uvm uvm_swap.c

Log Message:
uvm(9): Switch from legacy rijndael API to new aes API.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/uvm/files.uvm
cvs rdiff -u -r1.193 -r1.194 src/sys/uvm/uvm_swap.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/files.uvm
diff -u src/sys/uvm/files.uvm:1.34 src/sys/uvm/files.uvm:1.35
--- src/sys/uvm/files.uvm:1.34	Sun May 10 22:28:09 2020
+++ src/sys/uvm/files.uvm	Mon Jun 29 23:33:46 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.uvm,v 1.34 2020/05/10 22:28:09 pgoyette Exp $
+#	$NetBSD: files.uvm,v 1.35 2020/06/29 23:33:46 riastradh Exp $
 
 #
 # UVM options
@@ -8,7 +8,7 @@ defflag opt_uvmhist.h		UVMHIST_PRINT: KE
 defparam opt_uvmhist.h		UVMHIST_MAPHIST_SIZE UVMHIST_PDHIST_SIZE
 defflag opt_uvm.h		USE_TOPDOWN_VM UVMMAP_COUNTERS
 defparam opt_uvm.h		UVM_RESERVED_PAGES_PER_CPU
-defflag opt_vmswap.h		VMSWAP : rijndael
+defflag opt_vmswap.h		VMSWAP : aes
 defflag opt_readahead.h		READAHEAD_STATS
 defflag opt_ubc.h		UBC_STATS
 defparam opt_pagermap.h		PAGER_MAP_SIZE

Index: src/sys/uvm/uvm_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.193 src/sys/uvm/uvm_swap.c:1.194
--- src/sys/uvm/uvm_swap.c:1.193	Sun May 24 14:11:49 2020
+++ src/sys/uvm/uvm_swap.c	Mon Jun 29 23:33:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.193 2020/05/24 14:11:49 jdolecek Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.194 2020/06/29 23:33:46 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.193 2020/05/24 14:11:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.194 2020/06/29 23:33:46 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -65,7 +65,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v
 
 #include 
 
-#include 
+#include 
 
 /*
  * uvm_swap.c: manage configuration and i/o to swap space.
@@ -148,8 +148,8 @@ struct swapdev {
 	int			swd_active;	/* number of active buffers */
 
 	volatile uint32_t	*swd_encmap;	/* bitmap of encrypted slots */
-	keyInstance		swd_enckey;	/* AES key expanded for enc */
-	keyInstance		swd_deckey;	/* AES key expanded for dec */
+	struct aesenc		swd_enckey;	/* AES key expanded for enc */
+	struct aesdec		swd_deckey;	/* AES key expanded for dec */
 	bool			swd_encinit;	/* true if keys initialized */
 };
 
@@ -2073,8 +2073,8 @@ uvm_swap_genkey(struct swapdev *sdp)
 	KASSERT(!sdp->swd_encinit);
 
 	cprng_strong(kern_cprng, key, sizeof key, 0);
-	rijndael_makeKey(>swd_enckey, DIR_ENCRYPT, 256, key);
-	rijndael_makeKey(>swd_deckey, DIR_DECRYPT, 256, key);
+	aes_setenckey256(>swd_enckey, key);
+	aes_setdeckey256(>swd_deckey, key);
 	explicit_memset(key, 0, sizeof key);
 
 	sdp->swd_encinit = true;
@@ -2089,27 +2089,17 @@ uvm_swap_genkey(struct swapdev *sdp)
 static void
 uvm_swap_encryptpage(struct swapdev *sdp, void *kva, int slot)
 {
-	cipherInstance aes;
 	uint8_t preiv[16] = {0}, iv[16];
-	int ok __diagused, nbits __diagused;
 
 	/* iv := AES_k(le32enc(slot) || 0^96) */
 	le32enc(preiv, slot);
-	ok = rijndael_cipherInit(, MODE_ECB, NULL);
-	KASSERT(ok);
-	nbits = rijndael_blockEncrypt(, >swd_enckey, preiv,
-	/*length in bits*/128, iv);
-	KASSERT(nbits == 128);
+	aes_enc(>swd_enckey, (const void *)preiv, iv, AES_256_NROUNDS);
 
 	/* *kva := AES-CBC_k(iv, *kva) */
-	ok = rijndael_cipherInit(, MODE_CBC, iv);
-	KASSERT(ok);
-	nbits = rijndael_blockEncrypt(, >swd_enckey, kva,
-	/*length in bits*/PAGE_SIZE*NBBY, kva);
-	KASSERT(nbits == PAGE_SIZE*NBBY);
+	aes_cbc_enc(>swd_enckey, kva, kva, PAGE_SIZE, iv,
+	AES_256_NROUNDS);
 
 	explicit_memset(, 0, sizeof iv);
-	explicit_memset(, 0, sizeof aes);
 }
 
 /*
@@ -2121,28 +2111,17 @@ uvm_swap_encryptpage(struct swapdev *sdp
 static void
 uvm_swap_decryptpage(struct swapdev *sdp, void *kva, int slot)
 {
-	cipherInstance aes;
 	uint8_t preiv[16] = {0}, iv[16];
-	int ok __diagused, nbits __diagused;
 
 	/* iv := AES_k(le32enc(slot) || 0^96) */
 	le32enc(preiv, slot);
-	ok = rijndael_cipherInit(, MODE_ECB, NULL);
-	KASSERT(ok);
-	nbits = rijndael_blockEncrypt(, >swd_enckey, preiv,
-	/*length in bits*/128, iv);
-	KASSERTMSG(nbits == 128, "nbits=%d expected %d\n", nbits, 128);
+	aes_enc(>swd_enckey, (const void *)preiv, iv, AES_256_NROUNDS);
 
 	/* *kva := AES-CBC^{-1}_k(iv, *kva) */
-	ok = rijndael_cipherInit(, MODE_CBC, iv);
-	KASSERT(ok);
-	nbits = rijndael_blockDecrypt(, >swd_deckey, kva,
-	/*length in bits*/PAGE_SIZE*NBBY, kva);
-	KASSERTMSG(nbits == PAGE_SIZE*NBBY,
-	"nbits=%d expected %d\n", nbits, PAGE_SIZE*NBBY);
+	aes_cbc_dec(>swd_deckey, kva, kva, PAGE_SIZE, iv,
+	AES_256_NROUNDS);
 
 	explicit_memset(, 0, sizeof iv);
-	explicit_memset(, 0, sizeof aes);
 }
 
 SYSCTL_SETUP(sysctl_uvmswap_setup, "sysctl uvmswap 

CVS commit: src/sys/uvm

2020-06-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Jun 25 18:20:18 UTC 2020

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

Log Message:
uvm_emap_size was removed a while ago


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/uvm/uvm_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/uvm/uvm_param.h
diff -u src/sys/uvm/uvm_param.h:1.39 src/sys/uvm/uvm_param.h:1.40
--- src/sys/uvm/uvm_param.h:1.39	Thu Jun 25 16:36:43 2020
+++ src/sys/uvm/uvm_param.h	Thu Jun 25 18:20:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_param.h,v 1.39 2020/06/25 16:36:43 mlelstv Exp $	*/
+/*	$NetBSD: uvm_param.h,v 1.40 2020/06/25 18:20:18 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -213,7 +213,6 @@ extern unsigned int user_thread_stack_gu
 
 extern int		ubc_nwins;	/* number of UBC mapping windows */
 extern const int	ubc_winshift;	/* shift for a UBC mapping window */
-extern u_int		uvm_emap_size;	/* size of emap */
 
 #else
 /* out-of-kernel versions of round_page and trunc_page */



CVS commit: src/sys/uvm

2020-06-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Jun 25 16:36:43 UTC 2020

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

Log Message:
If ubc_winshift gets constified, the extern declaration must be too.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/uvm/uvm_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/uvm/uvm_param.h
diff -u src/sys/uvm/uvm_param.h:1.38 src/sys/uvm/uvm_param.h:1.39
--- src/sys/uvm/uvm_param.h:1.38	Wed Aug 22 01:05:24 2018
+++ src/sys/uvm/uvm_param.h	Thu Jun 25 16:36:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_param.h,v 1.38 2018/08/22 01:05:24 msaitoh Exp $	*/
+/*	$NetBSD: uvm_param.h,v 1.39 2020/06/25 16:36:43 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -212,7 +212,7 @@ extern unsigned int user_thread_stack_gu
 #endif
 
 extern int		ubc_nwins;	/* number of UBC mapping windows */
-extern int		ubc_winshift;	/* shift for a UBC mapping window */
+extern const int	ubc_winshift;	/* shift for a UBC mapping window */
 extern u_int		uvm_emap_size;	/* size of emap */
 
 #else



CVS commit: src/sys/uvm

2020-06-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Jun 25 14:04:30 UTC 2020

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

Log Message:
make ubc_winshift / ubc_winsize constant, and based on whatever is bigger
of (1 << UBC_WINSHIFT, MAX_PAGE_SIZE)

given that default UBC_WINSHIFT is 13, this changes behaviour only
for mips and powerpc (BookE/OEA), which will now have twice as much
memory used for UBC windows; if this ever becomes a problem, it's
possible to reduce ubc_nwins in MD code similar to what is done on sparc

this eliminates variable-length arrays in ubc_fault(),
ubc_uiomove(), and ubc_zerorange() so that the stack usage can be
determined and checked in compile time


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 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.117 src/sys/uvm/uvm_bio.c:1.118
--- src/sys/uvm/uvm_bio.c:1.117	Mon May 25 19:29:08 2020
+++ src/sys/uvm/uvm_bio.c	Thu Jun 25 14:04:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.118 2020/06/25 14:04:30 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.117 2020/05/25 19:29:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.118 2020/06/25 14:04:30 jdolecek Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 
 #include 
 #include 
 #include 
+#include 		/* for ilog2() */
 
 #include 
 #include 
@@ -120,9 +121,13 @@ const struct uvm_pagerops ubc_pager = {
 	/* ... rest are NULL */
 };
 
+/* Use value at least as big as maximum page size supported by architecture */
+#define UBC_MAX_WINSHIFT	\
+((1 << UBC_WINSHIFT) > MAX_PAGE_SIZE ? UBC_WINSHIFT : ilog2(MAX_PAGE_SIZE))
+
 int ubc_nwins = UBC_NWINS;
-int ubc_winshift __read_mostly = UBC_WINSHIFT;
-int ubc_winsize __read_mostly;
+const int ubc_winshift = UBC_MAX_WINSHIFT;
+const int ubc_winsize = 1 << UBC_MAX_WINSHIFT;
 #if defined(PMAP_PREFER)
 int ubc_nqueues;
 #define UBC_NQUEUES ubc_nqueues
@@ -161,9 +166,7 @@ ubc_init(void)
 	/*
 	 * Make sure ubc_winshift is sane.
 	 */
-	if (ubc_winshift < PAGE_SHIFT)
-		ubc_winshift = PAGE_SHIFT;
-	ubc_winsize = 1 << ubc_winshift;
+	KASSERT(ubc_winshift >= PAGE_SHIFT);
 
 	/*
 	 * init ubc_object.
@@ -304,7 +307,7 @@ ubc_fault(struct uvm_faultinfo *ufi, vad
 	struct uvm_object *uobj;
 	struct ubc_map *umap;
 	vaddr_t va, eva, ubc_offset, slot_offset;
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
+	struct vm_page *pgs[howmany(ubc_winsize, MIN_PAGE_SIZE)];
 	int i, error, npages;
 	vm_prot_t prot;
 
@@ -732,7 +735,7 @@ ubc_uiomove(struct uvm_object *uobj, str
 int flags)
 {
 	const bool overwrite = (flags & UBC_FAULTBUSY) != 0;
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
+	struct vm_page *pgs[howmany(ubc_winsize, MIN_PAGE_SIZE)];
 	voff_t off;
 	int error, npages;
 
@@ -798,7 +801,7 @@ ubc_uiomove(struct uvm_object *uobj, str
 void
 ubc_zerorange(struct uvm_object *uobj, off_t off, size_t len, int flags)
 {
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
+	struct vm_page *pgs[howmany(ubc_winsize, MIN_PAGE_SIZE)];
 	int npages;
 
 #ifdef UBC_USE_PMAP_DIRECT
@@ -975,7 +978,7 @@ ubc_uiomove_direct(struct uvm_object *uo
 	const bool overwrite = (flags & UBC_FAULTBUSY) != 0;
 	voff_t off;
 	int error, npages;
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
+	struct vm_page *pgs[howmany(ubc_winsize, MIN_PAGE_SIZE)];
 
 	KASSERT(todo <= uio->uio_resid);
 	KASSERT(((flags & UBC_WRITE) != 0 && uio->uio_rw == UIO_WRITE) ||
@@ -1043,7 +1046,7 @@ static void __noinline
 ubc_zerorange_direct(struct uvm_object *uobj, off_t off, size_t todo, int flags)
 {
 	int error, npages;
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
+	struct vm_page *pgs[howmany(ubc_winsize, MIN_PAGE_SIZE)];
 
 	flags |= UBC_WRITE;
 



CVS commit: src/sys/uvm

2020-06-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Jun 25 09:58:44 UTC 2020

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

Log Message:
use maximum-size fixed size array instead of variable-length array
in uvm_aio_aiodone() so that the stack usage can be determined and
checked in compile time; this is not called recursively not
particularly deep in call stack, so there is no need to save every
last drop of stack space here


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/uvm/uvm_pager.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_pager.c
diff -u src/sys/uvm/uvm_pager.c:1.125 src/sys/uvm/uvm_pager.c:1.126
--- src/sys/uvm/uvm_pager.c:1.125	Sun Apr 19 21:53:38 2020
+++ src/sys/uvm/uvm_pager.c	Thu Jun 25 09:58:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pager.c,v 1.125 2020/04/19 21:53:38 ad Exp $	*/
+/*	$NetBSD: uvm_pager.c,v 1.126 2020/06/25 09:58:44 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.125 2020/04/19 21:53:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.126 2020/06/25 09:58:44 jdolecek Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -516,17 +516,19 @@ uvm_aio_aiodone_pages(struct vm_page **p
  * uvm_aio_aiodone: do iodone processing for async i/os.
  * this should be called in thread context, not interrupt context.
  */
-
 void
 uvm_aio_aiodone(struct buf *bp)
 {
-	int npages = bp->b_bufsize >> PAGE_SHIFT;
-	struct vm_page *pgs[npages];
+	const int npages = bp->b_bufsize >> PAGE_SHIFT;
+	struct vm_page *pgs[howmany(MAXPHYS, MIN_PAGE_SIZE)];
 	int i, error;
 	bool write;
 	UVMHIST_FUNC("uvm_aio_aiodone"); UVMHIST_CALLED(ubchist);
 	UVMHIST_LOG(ubchist, "bp %#jx", (uintptr_t)bp, 0,0,0);
 
+	KASSERT(bp->b_bufsize <= MAXPHYS);
+	KASSERT(npages <= __arraycount(pgs));
+
 	error = bp->b_error;
 	write = (bp->b_flags & B_READ) == 0;
 



CVS commit: src/sys/uvm

2020-06-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jun 17 06:24:16 UTC 2020

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

Log Message:
 not needed here.


To generate a diff of this commit:
cvs rdiff -u -r1.242 -r1.243 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.242 src/sys/uvm/uvm_page.c:1.243
--- src/sys/uvm/uvm_page.c:1.242	Sun Jun 14 21:41:42 2020
+++ src/sys/uvm/uvm_page.c	Wed Jun 17 06:24:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.242 2020/06/14 21:41:42 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.243 2020/06/17 06:24:15 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.242 2020/06/14 21:41:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.243 2020/06/17 06:24:15 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -111,7 +111,6 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 



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/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/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/sys/uvm

2020-05-30 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 30 08:50:31 UTC 2020

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

Log Message:
Avoid passing file paths in panic strings, this results in extra long
output that is annoying and that syzbot classifies as independent reports
due to the instances having different build paths.


To generate a diff of this commit:
cvs rdiff -u -r1.383 -r1.384 src/sys/uvm/uvm_map.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_map.c
diff -u src/sys/uvm/uvm_map.c:1.383 src/sys/uvm/uvm_map.c:1.384
--- src/sys/uvm/uvm_map.c:1.383	Sat May  9 15:13:19 2020
+++ src/sys/uvm/uvm_map.c	Sat May 30 08:50:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.383 2020/05/09 15:13:19 thorpej Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.384 2020/05/30 08:50:31 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.383 2020/05/09 15:13:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.384 2020/05/30 08:50:31 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -296,9 +296,8 @@ static struct vm_map_entry *
 static void	uvm_mapent_copy(struct vm_map_entry *, struct vm_map_entry *);
 static void	uvm_mapent_free(struct vm_map_entry *);
 #if defined(DEBUG)
-static void	_uvm_mapent_check(const struct vm_map_entry *, const char *,
-		int);
-#define	uvm_mapent_check(map)	_uvm_mapent_check(map, __FILE__, __LINE__)
+static void	_uvm_mapent_check(const struct vm_map_entry *, int);
+#define	uvm_mapent_check(map)	_uvm_mapent_check(map, __LINE__)
 #else /* defined(DEBUG) */
 #define	uvm_mapent_check(e)	/* nothing */
 #endif /* defined(DEBUG) */
@@ -827,7 +826,7 @@ uvm_mapent_copy(struct vm_map_entry *src
 
 #if defined(DEBUG)
 static void
-_uvm_mapent_check(const struct vm_map_entry *entry, const char *file, int line)
+_uvm_mapent_check(const struct vm_map_entry *entry, int line)
 {
 
 	if (entry->start >= entry->end) {
@@ -856,7 +855,7 @@ _uvm_mapent_check(const struct vm_map_en
 	return;
 
 bad:
-	panic("%s: bad entry %p (%s:%d)", __func__, entry, file, line);
+	panic("%s: bad entry %p, line %d", __func__, entry, line);
 }
 #endif /* defined(DEBUG) */
 



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

2020-05-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun May 24 14:11:49 UTC 2020

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

Log Message:
fix KASAN PoolUseAfterFree for async write - can't read bp after VOP_STRATEGY()

problem found and fix provided by Paul Ripke


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.192 src/sys/uvm/uvm_swap.c:1.193
--- src/sys/uvm/uvm_swap.c:1.192	Fri May 22 11:54:05 2020
+++ src/sys/uvm/uvm_swap.c	Sun May 24 14:11:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.192 2020/05/22 11:54:05 jdolecek Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.193 2020/05/24 14:11:49 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.192 2020/05/22 11:54:05 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.193 2020/05/24 14:11:49 jdolecek Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1985,7 +1985,7 @@ uvm_swap_io(struct vm_page **pps, int st
 		 * Reads are always synchronous; if this changes, we
 		 * need to add an asynchronous path for decryption.
 		 */
-		KASSERT((bp->b_flags & B_READ) == 0);
+		KASSERT(write);
 		return 0;
 	}
 



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

2020-05-22 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri May 22 11:54:05 UTC 2020

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

Log Message:
DRY code in uvm_swap_io() for the write loop


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.191 src/sys/uvm/uvm_swap.c:1.192
--- src/sys/uvm/uvm_swap.c:1.191	Thu May 21 16:50:25 2020
+++ src/sys/uvm/uvm_swap.c	Fri May 22 11:54:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.191 2020/05/21 16:50:25 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.192 2020/05/22 11:54:05 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.191 2020/05/21 16:50:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.192 2020/05/22 11:54:05 jdolecek Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1914,25 +1914,19 @@ uvm_swap_io(struct vm_page **pps, int st
 		KASSERT(sdp->swd_encinit);
 		mutex_exit(_swap_data_lock);
 
-		if (swap_encrypt) {
-			for (i = 0; i < npages; i++) {
-int s = startslot + i;
-KDASSERT(swapdrum_sdp_is(s, sdp));
-KASSERT(s >= sdp->swd_drumoffset);
-s -= sdp->swd_drumoffset;
-KASSERT(s < sdp->swd_drumsize);
+		for (i = 0; i < npages; i++) {
+			int s = startslot + i;
+			KDASSERT(swapdrum_sdp_is(s, sdp));
+			KASSERT(s >= sdp->swd_drumoffset);
+			s -= sdp->swd_drumoffset;
+			KASSERT(s < sdp->swd_drumsize);
+
+			if (swap_encrypt) {
 uvm_swap_encryptpage(sdp,
 (void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 atomic_or_32(>swd_encmap[s/32],
 __BIT(s%32));
-			}
-		} else {
-			for (i = 0; i < npages; i++) {
-int s = startslot + i;
-KDASSERT(swapdrum_sdp_is(s, sdp));
-KASSERT(s >= sdp->swd_drumoffset);
-s -= sdp->swd_drumoffset;
-KASSERT(s < sdp->swd_drumsize);
+			} else {
 atomic_and_32(>swd_encmap[s/32],
 ~__BIT(s%32));
 			}



CVS commit: src/sys/uvm

2020-05-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 21 16:50:25 UTC 2020

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

Log Message:
Let's not waste time decrypting garbage, shall we?

Skip to the end if the transfer failed.


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.190 src/sys/uvm/uvm_swap.c:1.191
--- src/sys/uvm/uvm_swap.c:1.190	Wed May 20 17:48:34 2020
+++ src/sys/uvm/uvm_swap.c	Thu May 21 16:50:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.190 2020/05/20 17:48:34 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.191 2020/05/21 16:50:25 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.190 2020/05/20 17:48:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.191 2020/05/21 16:50:25 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -2000,6 +2000,8 @@ uvm_swap_io(struct vm_page **pps, int st
 	 */
 
 	error = biowait(bp);
+	if (error)
+		goto out;
 
 	/*
 	 * decrypt reads in place if needed
@@ -2042,7 +2044,7 @@ uvm_swap_io(struct vm_page **pps, int st
 			(void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 		}
 	} while (0);
-
+out:
 	/*
 	 * kill the pager mapping
 	 */



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

2020-05-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 20 17:48:34 UTC 2020

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

Log Message:
Make swap encryption MP-safe.

Not entirely sure the rest of the swap system is MP-safe, but let's
not make it worse!

XXX Why is swap_syscall_lock an rwlock?  We don't seem to take the
reader lock ever.


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/sys/uvm/uvm_swap.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_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.189 src/sys/uvm/uvm_swap.c:1.190
--- src/sys/uvm/uvm_swap.c:1.189	Sun May 10 02:38:10 2020
+++ src/sys/uvm/uvm_swap.c	Wed May 20 17:48:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.189 2020/05/10 02:38:10 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.190 2020/05/20 17:48:34 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.189 2020/05/10 02:38:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.190 2020/05/20 17:48:34 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -147,7 +147,7 @@ struct swapdev {
 	struct bufq_state	*swd_tab;	/* buffer list */
 	int			swd_active;	/* number of active buffers */
 
-	uint8_t			*swd_encmap;	/* bitmap of encrypted slots */
+	volatile uint32_t	*swd_encmap;	/* bitmap of encrypted slots */
 	keyInstance		swd_enckey;	/* AES key expanded for enc */
 	keyInstance		swd_deckey;	/* AES key expanded for dec */
 	bool			swd_encinit;	/* true if keys initialized */
@@ -234,6 +234,19 @@ static void uvm_swap_genkey(struct swapd
 static void uvm_swap_encryptpage(struct swapdev *, void *, int);
 static void uvm_swap_decryptpage(struct swapdev *, void *, int);
 
+static size_t
+encmap_size(size_t npages)
+{
+	struct swapdev *sdp;
+	const size_t bytesperword = sizeof(sdp->swd_encmap[0]);
+	const size_t bitsperword = NBBY * bytesperword;
+	const size_t nbits = npages; /* one bit for each page */
+	const size_t nwords = howmany(nbits, bitsperword);
+	const size_t nbytes = nwords * bytesperword;
+
+	return nbytes;
+}
+
 /*
  * uvm_swap_init: init the swap system data structures and locks
  *
@@ -304,6 +317,9 @@ swaplist_insert(struct swapdev *sdp, str
 	struct swappri *spp, *pspp;
 	UVMHIST_FUNC("swaplist_insert"); UVMHIST_CALLED(pdhist);
 
+	KASSERT(rw_write_held(_syscall_lock));
+	KASSERT(mutex_owned(_swap_data_lock));
+
 	/*
 	 * find entry at or after which to insert the new device.
 	 */
@@ -356,6 +372,10 @@ swaplist_find(struct vnode *vp, bool rem
 	struct swapdev *sdp;
 	struct swappri *spp;
 
+	KASSERT(rw_lock_held(_syscall_lock));
+	KASSERT(remove ? rw_write_held(_syscall_lock) : 1);
+	KASSERT(mutex_owned(_swap_data_lock));
+
 	/*
 	 * search the lists for the requested vp
 	 */
@@ -386,6 +406,9 @@ swaplist_trim(void)
 {
 	struct swappri *spp, *nextspp;
 
+	KASSERT(rw_write_held(_syscall_lock));
+	KASSERT(mutex_owned(_swap_data_lock));
+
 	LIST_FOREACH_SAFE(spp, _priority, spi_swappri, nextspp) {
 		if (!TAILQ_EMPTY(>spi_swapdev))
 			continue;
@@ -407,6 +430,8 @@ swapdrum_getsdp(int pgno)
 	struct swapdev *sdp;
 	struct swappri *spp;
 
+	KASSERT(mutex_owned(_swap_data_lock));
+
 	LIST_FOREACH(spp, _priority, spi_swappri) {
 		TAILQ_FOREACH(sdp, >spi_swapdev, swd_next) {
 			if (sdp->swd_flags & SWF_FAKE)
@@ -420,6 +445,23 @@ swapdrum_getsdp(int pgno)
 	return NULL;
 }
 
+/*
+ * swapdrum_sdp_is: true iff the swap device for pgno is sdp
+ *
+ * => for use in positive assertions only; result is not stable
+ */
+static bool __debugused
+swapdrum_sdp_is(int pgno, struct swapdev *sdp)
+{
+	bool result;
+
+	mutex_enter(_swap_data_lock);
+	result = swapdrum_getsdp(pgno) == sdp;
+	mutex_exit(_swap_data_lock);
+
+	return result;
+}
+
 void swapsys_lock(krw_t op)
 {
 	rw_enter(_syscall_lock, op);
@@ -904,7 +946,7 @@ swap_on(struct lwp *l, struct swapdev *s
 	 * allocate space to for swap encryption state and mark the
 	 * keys uninitialized so we generate them lazily
 	 */
-	sdp->swd_encmap = kmem_zalloc(howmany(npages, NBBY), KM_SLEEP);
+	sdp->swd_encmap = kmem_zalloc(encmap_size(npages), KM_SLEEP);
 	sdp->swd_encinit = false;
 
 	/*
@@ -1011,6 +1053,9 @@ swap_off(struct lwp *l, struct swapdev *
 	UVMHIST_FUNC("swap_off"); UVMHIST_CALLED(pdhist);
 	UVMHIST_LOG(pdhist, "  dev=%jx, npages=%jd", sdp->swd_dev,npages, 0, 0);
 
+	KASSERT(rw_write_held(_syscall_lock));
+	KASSERT(mutex_owned(_swap_data_lock));
+
 	/* disable the swap area being removed */
 	sdp->swd_flags &= ~SWF_ENABLE;
 	uvmexp.swpgavail -= npages;
@@ -1079,7 +1124,8 @@ swap_off(struct lwp *l, struct swapdev *
 	vmem_free(swapmap, sdp->swd_drumoffset, sdp->swd_drumsize);
 	blist_destroy(sdp->swd_blist);
 	bufq_free(sdp->swd_tab);
-	kmem_free(sdp->swd_encmap, howmany(sdp->swd_npages, NBBY));
+	kmem_free(__UNVOLATILE(sdp->swd_encmap),
+	

CVS commit: src/sys/uvm

2020-05-20 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 20 12:47:36 UTC 2020

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

Log Message:
Suppress GCC warnings and fix a UVMHIST_LOG() statement.

Kernels ALL/amd64 and ALL/i386 and port sparc64 build again.


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.142 src/sys/uvm/uvm_aobj.c:1.143
--- src/sys/uvm/uvm_aobj.c:1.142	Tue May 19 22:22:15 2020
+++ src/sys/uvm/uvm_aobj.c	Wed May 20 12:47:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.142 2020/05/19 22:22:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.143 2020/05/20 12:47:36 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -802,7 +802,7 @@ 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;
+	int lcv, gotpages, maxpages, swslot = -1, pageidx = -1; /* XXX: gcc */
 	UVMHIST_FUNC("uao_get"); UVMHIST_CALLED(pdhist);
 
 	UVMHIST_LOG(pdhist, "aobj=%#jx offset=%jd, flags=%jd",
@@ -876,7 +876,8 @@ uao_get(struct uvm_object *uobj, voff_t 
 		 * to unlock and do some waiting or I/O.
  		 */
 
-		UVMHIST_LOG(pdhist, "<- done (done=%jd)", done, 0,0,0);
+		UVMHIST_LOG(pdhist, "<- done (done=%jd)",
+		(pps[centeridx] != NULL), 0,0,0);
 		*npagesp = gotpages;
 		return pps[centeridx] != NULL ? 0 : EBUSY;
 	}



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



CVS commit: src/sys/uvm

2020-05-17 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 17 17:12:28 UTC 2020

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

Log Message:
Don't set PG_AOBJ on a page unless UVM_OBJ_IS_AOBJ(), otherwise it can
catch pages from e.g. uvm_loanzero_object.


To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 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.235 src/sys/uvm/uvm_page.c:1.236
--- src/sys/uvm/uvm_page.c:1.235	Sun May 17 15:11:57 2020
+++ src/sys/uvm/uvm_page.c	Sun May 17 17:12:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.235 2020/05/17 15:11:57 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.236 2020/05/17 17:12:28 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.235 2020/05/17 15:11:57 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.236 2020/05/17 17:12:28 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -220,10 +220,8 @@ uvm_pageinsert_object(struct uvm_object 
 	if ((pg->flags & PG_STAT) != 0) {
 		/* Cannot use uvm_pagegetdirty(): not yet in radix tree. */
 		const unsigned int status = pg->flags & (PG_CLEAN | PG_DIRTY);
-		const bool isaobj = (pg->flags & PG_AOBJ) != 0;
 
-		if (!isaobj) {
-			KASSERT((pg->flags & PG_FILE) != 0);
+		if ((pg->flags & PG_FILE) != 0) {
 			if (uobj->uo_npages == 0) {
 struct vnode *vp = (struct vnode *)uobj;
 mutex_enter(vp->v_interlock);
@@ -285,10 +283,8 @@ uvm_pageremove_object(struct uvm_object 
 	if ((pg->flags & PG_STAT) != 0) {
 		/* Cannot use uvm_pagegetdirty(): no longer in radix tree. */
 		const unsigned int status = pg->flags & (PG_CLEAN | PG_DIRTY);
-		const bool isaobj = (pg->flags & PG_AOBJ) != 0;
 
-		if (!isaobj) {
-			KASSERT((pg->flags & PG_FILE) != 0);
+		if ((pg->flags & PG_FILE) != 0) {
 			if (uobj->uo_npages == 1) {
 struct vnode *vp = (struct vnode *)uobj;
 mutex_enter(vp->v_interlock);
@@ -1336,7 +1332,7 @@ uvm_pagealloc_strat(struct uvm_object *o
 		 */
 		if (UVM_OBJ_IS_VNODE(obj)) {
 			pg->flags |= PG_FILE;
-		} else {
+		} else if (UVM_OBJ_IS_AOBJ(obj)) {
 			pg->flags |= PG_AOBJ;
 		}
 		uvm_pageinsert_object(obj, pg);



CVS commit: src/sys/uvm

2020-05-17 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 17 15:11:57 UTC 2020

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

Log Message:
- If the hardware provided NUMA info, then use it to decide how to set up
  the allocator's buckets, instead of doing round robin distribution.  There
  are open questions here but this is better than doing nothing.

- Kernel reserve pages are for the kernel not realtime threads.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/uvm/uvm.h
cvs rdiff -u -r1.234 -r1.235 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.h
diff -u src/sys/uvm/uvm.h:1.76 src/sys/uvm/uvm.h:1.77
--- src/sys/uvm/uvm.h:1.76	Sat Mar 14 20:23:51 2020
+++ src/sys/uvm/uvm.h	Sun May 17 15:11:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm.h,v 1.76 2020/03/14 20:23:51 ad Exp $	*/
+/*	$NetBSD: uvm.h,v 1.77 2020/05/17 15:11:57 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -107,7 +107,6 @@ struct uvm {
 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
 	u_int	bucketcount;
 	bool	page_init_done;		/* true if uvm_page_init() finished */
-	bool	numa_alloc;		/* use NUMA page allocation strategy */
 
 		/* page daemon trigger */
 	int pagedaemon;			/* daemon sleeps on this */

Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.234 src/sys/uvm/uvm_page.c:1.235
--- src/sys/uvm/uvm_page.c:1.234	Tue Mar 17 18:31:39 2020
+++ src/sys/uvm/uvm_page.c	Sun May 17 15:11:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.234 2020/03/17 18:31:39 ad Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.235 2020/05/17 15:11:57 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.234 2020/03/17 18:31:39 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.235 2020/05/17 15:11:57 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -749,7 +749,6 @@ uvm_page_numa_lookup(struct vm_page *pg)
 	static bool warned;
 	paddr_t pa;
 
-	KASSERT(uvm.numa_alloc);
 	KASSERT(uvm_page_numa_region != NULL);
 
 	pa = VM_PAGE_TO_PHYS(pg);
@@ -852,7 +851,7 @@ uvm_page_redim(int newncolors, int newnb
 	uvm_page_get_bucket(pg) == ob);
 	KASSERT(fl ==
 	uvm_page_get_freelist(pg));
-	if (uvm.numa_alloc) {
+	if (uvm_page_numa_region != NULL) {
 		nb = uvm_page_numa_lookup(pg);
 	} else {
 		nb = atop(VM_PAGE_TO_PHYS(pg))
@@ -919,8 +918,7 @@ uvm_page_rebucket(void)
 	/*
 	 * If we have more than one NUMA node, and the maximum NUMA node ID
 	 * is less than PGFL_MAX_BUCKETS, then we'll use NUMA distribution
-	 * for free pages.  uvm_pagefree() will not reassign pages to a
-	 * different bucket on free.
+	 * for free pages.
 	 */
 	min_numa = (u_int)-1;
 	max_numa = 0;
@@ -933,28 +931,19 @@ uvm_page_rebucket(void)
 		}
 	}
 	if (min_numa != max_numa && max_numa < PGFL_MAX_BUCKETS) {
-#ifdef NUMA
-		/*
-		 * We can do this, and it seems to work well, but until
-		 * further experiments are done we'll stick with the cache
-		 * locality strategy.
-		 */
 		aprint_debug("UVM: using NUMA allocation scheme\n");
 		for (CPU_INFO_FOREACH(cii, ci)) {
 			ci->ci_data.cpu_uvm->pgflbucket = ci->ci_numa_id;
 		}
-		uvm.numa_alloc = true;
 	 	uvm_page_redim(uvmexp.ncolors, max_numa + 1);
 	 	return;
-#endif
 	}
 
 	/*
 	 * Otherwise we'll go with a scheme to maximise L2/L3 cache locality
 	 * and minimise lock contention.  Count the total number of CPU
 	 * packages, and then try to distribute the buckets among CPU
-	 * packages evenly.  uvm_pagefree() will reassign pages to the
-	 * freeing CPU's preferred bucket on free.
+	 * packages evenly.
 	 */
 	npackage = curcpu()->ci_nsibling[CPUREL_PACKAGE1ST];
 
@@ -1220,18 +1209,13 @@ uvm_pagealloc_strat(struct uvm_object *o
 	 * [3]  only pagedaemon "reserved" pages remain and
 	 *the requestor isn't the pagedaemon.
 	 * we make kernel reserve pages available if called by a
-	 * kernel thread or a realtime thread.
+	 * kernel thread.
 	 */
 	l = curlwp;
-	if (__predict_true(l != NULL) && lwp_eprio(l) >= PRI_KTHREAD) {
+	if (__predict_true(l != NULL) && (l->l_flag & LW_SYSTEM) != 0) {
 		flags |= UVM_PGA_USERESERVE;
 	}
 
-	/* If the allocator's running in NUMA mode, go with NUMA strategy. */
-	if (uvm.numa_alloc && strat == UVM_PGA_STRAT_NORMAL) {
-		strat = UVM_PGA_STRAT_NUMA;
-	}
-
  again:
 	switch (strat) {
 	case UVM_PGA_STRAT_NORMAL:
@@ -1270,10 +1254,11 @@ uvm_pagealloc_strat(struct uvm_object *o
 
 	case UVM_PGA_STRAT_NUMA:
 		/*
-		 * NUMA strategy: allocating from the correct bucket is more
-		 * important than observing freelist priority.  Look only to
-		 * the current NUMA node; if that fails, we need to look to
-		 * other NUMA nodes, so retry with the normal strategy.
+		 * NUMA strategy (experimental): allocating from the correct
+		 * 

CVS commit: src/sys/uvm

2020-05-17 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 17 15:07:22 UTC 2020

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

Log Message:
Mark amappl with PR_LARGECACHE.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/uvm/uvm_amap.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_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.119 src/sys/uvm/uvm_amap.c:1.120
--- src/sys/uvm/uvm_amap.c:1.119	Fri Mar 20 19:08:54 2020
+++ src/sys/uvm/uvm_amap.c	Sun May 17 15:07:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.119 2020/03/20 19:08:54 ad Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.120 2020/05/17 15:07:22 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.119 2020/03/20 19:08:54 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.120 2020/05/17 15:07:22 ad Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -305,8 +305,9 @@ uvm_amap_init(void)
 
 	mutex_init(_list_lock, MUTEX_DEFAULT, IPL_NONE);
 
-	pool_cache_bootstrap(_amap_cache, sizeof(struct vm_amap), 0, 0, 0,
-	"amappl", NULL, IPL_NONE, amap_ctor, amap_dtor, NULL);
+	pool_cache_bootstrap(_amap_cache, sizeof(struct vm_amap), 0, 0,
+	PR_LARGECACHE, "amappl", NULL, IPL_NONE, amap_ctor, amap_dtor,
+	NULL);
 }
 
 /*



CVS commit: src/sys/uvm

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

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

Log Message:
Reported-by: syzbot+3e3c7cfa8093f8de0...@syzkaller.appspotmail.com

Comment out an assertion that's now bogus and add a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/sys/uvm/uvm_fault.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_fault.c
diff -u src/sys/uvm/uvm_fault.c:1.225 src/sys/uvm/uvm_fault.c:1.226
--- src/sys/uvm/uvm_fault.c:1.225	Mon Apr 13 22:22:19 2020
+++ src/sys/uvm/uvm_fault.c	Fri May 15 22:35:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_fault.c,v 1.225 2020/04/13 22:22:19 ad Exp $	*/
+/*	$NetBSD: uvm_fault.c,v 1.226 2020/05/15 22:35:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.225 2020/04/13 22:22:19 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.226 2020/05/15 22:35:05 ad Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -1701,9 +1701,13 @@ uvm_fault_upper_enter(
 		 * but rather that the pmap should be designed such that it
 		 * never needs to fail when the new mapping is replacing an
 		 * existing mapping and the new page has no existing mappings.
+		 *
+		 * XXX This can't be asserted safely any more because many
+		 * LWPs and/or many processes could simultaneously fault on
+		 * the same VA and some might succeed.
 		 */
 
-		KASSERT(!pmap_extract(pmap, va, NULL));
+		/* KASSERT(!pmap_extract(pmap, va, NULL)); */
 
 		/*
 		 * ensure that the page is queued in the case that



CVS commit: src/sys/uvm

2020-05-15 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri May 15 22:27:04 UTC 2020

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

Log Message:
PR kern/55268: tmpfs is slow

uao_get(): in the PGO_LOCKED case, we're okay to allocate a new page as long
as the caller holds a write lock.  PGO_NOBUSY doesn't put a stop to that.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 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.139 src/sys/uvm/uvm_aobj.c:1.140
--- src/sys/uvm/uvm_aobj.c:1.139	Sun Mar 22 18:32:42 2020
+++ src/sys/uvm/uvm_aobj.c	Fri May 15 22:27:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.139 2020/03/22 18:32:42 ad Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.140 2020/05/15 22:27:04 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.139 2020/03/22 18:32:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.140 2020/05/15 22:27:04 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -827,6 +827,7 @@ uao_get(struct uvm_object *uobj, voff_t 
  	 */
 
 	if (flags & PGO_LOCKED) {
+		krw_t lktype = rw_lock_op(uobj->vmobjlock);
 
 		/*
  		 * step 1a: get pages that are already resident.   only do
@@ -845,11 +846,11 @@ uao_get(struct uvm_object *uobj, voff_t 
 
 			/*
  			 * if page is new, attempt to allocate the page,
-			 * zero-fill'd.  we can only do this if busying
-			 * pages, as otherwise the object is read locked.
+			 * zero-fill'd.  we can only do this if the caller
+			 * holds a write lock.
  			 */
 
-			if ((flags & PGO_NOBUSY) == 0 && ptmp == NULL &&
+			if (ptmp == NULL && lktype == RW_WRITER &&
 			uao_find_swslot(uobj,
 			current_offset >> PAGE_SHIFT) == 0) {
 ptmp = uao_pagealloc(uobj, current_offset,
@@ -859,6 +860,8 @@ uao_get(struct uvm_object *uobj, voff_t 
 	ptmp->flags &= ~(PG_FAKE);
 	uvm_pagemarkdirty(ptmp,
 	UVM_PAGE_STATUS_UNKNOWN);
+	if ((flags & PGO_NOBUSY) != 0)
+		ptmp->flags &= ~PG_BUSY;
 	goto gotpage;
 }
 			}



  1   2   3   4   5   6   7   >