CVS commit: [netbsd-9] src/sys/uvm

2020-10-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  4 18:14:13 UTC 2020

Modified Files:
src/sys/uvm [netbsd-9]: uvm_amap.c uvm_io.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #1095):

sys/uvm/uvm_amap.c: revision 1.124 (via patch)
sys/uvm/uvm_amap.c: revision 1.125 (via patch)
sys/uvm/uvm_io.c: revision 1.29 (via patch)

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.

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.109.4.1 -r1.109.4.2 src/sys/uvm/uvm_amap.c
cvs rdiff -u -r1.28 -r1.28.22.1 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.109.4.1 src/sys/uvm/uvm_amap.c:1.109.4.2
--- src/sys/uvm/uvm_amap.c:1.109.4.1	Wed Aug 19 18:36:59 2020
+++ src/sys/uvm/uvm_amap.c	Sun Oct  4 18:14:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.109.4.1 2020/08/19 18:36:59 martin Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.109.4.2 2020/10/04 18:14:13 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.109.4.1 2020/08/19 18:36:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.109.4.2 2020/10/04 18:14:13 martin Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -1588,7 +1588,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
@@ -1597,11 +1597,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
 	uvm_anon_freelst(amap, tofree);

Index: src/sys/uvm/uvm_io.c
diff -u src/sys/uvm/uvm_io.c:1.28 src/sys/uvm/uvm_io.c:1.28.22.1
--- src/sys/uvm/uvm_io.c:1.28	Wed May 25 17:43:58 2016
+++ src/sys/uvm/uvm_io.c	Sun Oct  4 18:14:13 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.28.22.1 2020/10/04 18:14:13 martin 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.28.22.1 2020/10/04 18:14:13 martin 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: [netbsd-9] src/sys/uvm

2020-08-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug 19 18:36:59 UTC 2020

Modified Files:
src/sys/uvm [netbsd-9]: uvm_amap.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #1057):

sys/uvm/uvm_amap.c: revision 1.123 (via patch)

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.109 -r1.109.4.1 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.109 src/sys/uvm/uvm_amap.c:1.109.4.1
--- src/sys/uvm/uvm_amap.c:1.109	Sun Aug 12 09:29:16 2018
+++ src/sys/uvm/uvm_amap.c	Wed Aug 19 18:36:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_amap.c,v 1.109 2018/08/12 09:29:16 maxv Exp $	*/
+/*	$NetBSD: uvm_amap.c,v 1.109.4.1 2020/08/19 18:36:59 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.109 2018/08/12 09:29:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.109.4.1 2020/08/19 18:36:59 martin Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -317,7 +317,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;
@@ -355,6 +355,36 @@ amap_extend(struct vm_map_entry *entry, 
 	tofree = NULL;
 
 	/*
+	 * 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: [netbsd-9] src/sys/uvm

2020-05-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed May 13 18:05:14 UTC 2020

Modified Files:
src/sys/uvm [netbsd-9]: uvm_page.h

Log Message:
Pull up following revision(s) (requested by chs in ticket #906):

sys/uvm/uvm_page.h: revision 1.99

Include "opt_uvm_page_trkown.h" for UVM_PAGE_TRKOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.84.4.1 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.84 src/sys/uvm/uvm_page.h:1.84.4.1
--- src/sys/uvm/uvm_page.h:1.84	Mon Jan  7 22:48:01 2019
+++ src/sys/uvm/uvm_page.h	Wed May 13 18:05:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.84 2019/01/07 22:48:01 jdolecek Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.84.4.1 2020/05/13 18:05:14 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -64,6 +64,10 @@
 #ifndef _UVM_UVM_PAGE_H_
 #define _UVM_UVM_PAGE_H_
 
+#ifdef _KERNEL_OPT
+#include "opt_uvm_page_trkown.h"
+#endif
+
 #include 
 #include 
 



CVS commit: [netbsd-9] src/sys/uvm

2020-03-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar  8 11:01:22 UTC 2020

Modified Files:
src/sys/uvm [netbsd-9]: uvm_fault.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #764):

sys/uvm/uvm_fault.c: revision 1.207

fix two bugs reported in
https://syzkaller.appspot.com/bug?id=8840dce484094a926e1ec388ffb83acb2fa291c9

 - in uvm_fault_check(), if the map entry is wired, handle the fault the same 
way
   that we would handle UVM_FAULT_WIRE.  faulting on wired mappings is valid
   if the mapped object was truncated and then later grown again.

 - in uvm_fault_unwire_locked(), we must hold the locks for the vm_map_entry
   while calling pmap_extract() in order to avoid races with the mapped object
   being truncated while we are unwiring it.


To generate a diff of this commit:
cvs rdiff -u -r1.206.2.1 -r1.206.2.2 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.206.2.1 src/sys/uvm/uvm_fault.c:1.206.2.2
--- src/sys/uvm/uvm_fault.c:1.206.2.1	Mon Nov 11 17:13:28 2019
+++ src/sys/uvm/uvm_fault.c	Sun Mar  8 11:01:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_fault.c,v 1.206.2.1 2019/11/11 17:13:28 martin Exp $	*/
+/*	$NetBSD: uvm_fault.c,v 1.206.2.2 2020/03/08 11:01:22 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.206.2.1 2019/11/11 17:13:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.206.2.2 2020/03/08 11:01:22 martin Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -996,8 +996,11 @@ uvm_fault_check(
 	 */
 
 	flt->enter_prot = ufi->entry->protection;
-	if (VM_MAPENT_ISWIRED(ufi->entry))
+	if (VM_MAPENT_ISWIRED(ufi->entry)) {
 		flt->wire_mapping = true;
+		flt->wire_paging = true;
+		flt->narrow = true;
+	}
 
 	if (flt->wire_mapping) {
 		flt->access_type = flt->enter_prot; /* full access for wired */
@@ -2442,8 +2445,6 @@ uvm_fault_unwire_locked(struct vm_map *m
 
 	oentry = NULL;
 	for (va = start; va < end; va += PAGE_SIZE) {
-		if (pmap_extract(pmap, va, ) == false)
-			continue;
 
 		/*
 		 * find the map entry for the current address.
@@ -2474,6 +2475,9 @@ uvm_fault_unwire_locked(struct vm_map *m
 		 * if the entry is no longer wired, tell the pmap.
 		 */
 
+		if (!pmap_extract(pmap, va, ))
+			continue;
+
 		if (VM_MAPENT_ISWIRED(entry) == 0)
 			pmap_unwire(pmap, va);
 



CVS commit: [netbsd-9] src/sys/uvm

2020-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb 27 18:24:44 UTC 2020

Modified Files:
src/sys/uvm [netbsd-9]: uvm_pglist.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #732):

sys/uvm/uvm_pglist.c: revision 1.80

Make this compile again with PGALLOC_VERBOSE.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.72.4.1 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.72 src/sys/uvm/uvm_pglist.c:1.72.4.1
--- src/sys/uvm/uvm_pglist.c:1.72	Tue Nov 13 10:31:01 2018
+++ src/sys/uvm/uvm_pglist.c	Thu Feb 27 18:24:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pglist.c,v 1.72 2018/11/13 10:31:01 mrg Exp $	*/
+/*	$NetBSD: uvm_pglist.c,v 1.72.4.1 2020/02/27 18:24:44 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.72 2018/11/13 10:31:01 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.72.4.1 2020/02/27 18:24:44 martin Exp $");
 
 #include 
 #include 
@@ -127,7 +127,7 @@ uvm_pglistalloc_c_ps(uvm_physseg_t psi, 
 	paddr_t cidx = 0;	/* XXX: GCC */
 #endif
 #ifdef PGALLOC_VERBOSE
-	printf("pgalloc: contig %d pgs from psi %zd\n", num, ps - vm_physmem);
+	printf("pgalloc: contig %d pgs from psi %d\n", num, psi);
 #endif
 
 	KASSERT(mutex_owned(_fpageqlock));
@@ -208,8 +208,8 @@ uvm_pglistalloc_c_ps(uvm_physseg_t psi, 
 		 * Found a suitable starting page.  See if the range is free.
 		 */
 #ifdef PGALLOC_VERBOSE
-		printf("%s: ps=%p candidate=%#x end=%#x skip=%#x, align=%#"PRIxPADDR,
-		__func__, ps, candidateidx, end, skip, alignment);
+		printf("%s: psi=%d candidate=%#x end=%#x skip=%#x, align=%#"PRIxPADDR,
+		__func__, psi, candidateidx, end, skip, alignment);
 #endif
 		/*
 		 * We start at the end and work backwards since if we find a



CVS commit: [netbsd-9] src/sys/uvm

2019-12-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Dec 27 06:58:56 UTC 2019

Modified Files:
src/sys/uvm [netbsd-9]: uvm_pager.c

Log Message:
Pull up following revision(s) (requested by ad in ticket #584):

sys/uvm/uvm_pager.c: revision 1.118

PR kern/48044: panic: kernel diagnostic assertion "uvmexp.swpgonly + npages <= 
uvmexp.swpginuse" failed
swpgonly is updated asynchronously with regard to swap use.  We can't assert
this condition with confidence in the post-5.0 world, at least not without
broader changes.  swpgonly's ultimate use is of a heuristic nature so this
is no problem at all.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.111.8.1 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.111 src/sys/uvm/uvm_pager.c:1.111.8.1
--- src/sys/uvm/uvm_pager.c:1.111	Sat Oct 28 00:37:13 2017
+++ src/sys/uvm/uvm_pager.c	Fri Dec 27 06:58:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pager.c,v 1.111 2017/10/28 00:37:13 pgoyette Exp $	*/
+/*	$NetBSD: uvm_pager.c,v 1.111.8.1 2019/12/27 06:58:56 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.111 2017/10/28 00:37:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.111.8.1 2019/12/27 06:58:56 martin Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -469,7 +469,6 @@ uvm_aio_aiodone_pages(struct vm_page **p
 		/* these pages are now only in swap. */
 		mutex_enter(_swap_data_lock);
 		if (error != ENOMEM) {
-			KASSERT(uvmexp.swpgonly + npages <= uvmexp.swpginuse);
 			uvmexp.swpgonly += npages;
 		}
 		mutex_exit(_swap_data_lock);