CVS commit: src/sys/kern

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 02:56:12 UTC 2020

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

Log Message:
Make rndctl -E/-C reset entropy accounting.

If we don't trust a source, it's unreasonable to trust any entropy it
previously provided, and we don't have any way to undo only the
effects of that source, so just zero our estimate of the entropy in
the pool and start over.

(However, keep the samples already in the pool -- just treat them as
though they had zero entropy and start gathering more.)


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/kern/kern_entropy.c

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

Modified files:

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.20 src/sys/kern/kern_entropy.c:1.21
--- src/sys/kern/kern_entropy.c:1.20	Sun May 10 01:29:40 2020
+++ src/sys/kern/kern_entropy.c	Sun May 10 02:56:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.20 2020/05/10 01:29:40 riastradh Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.21 2020/05/10 02:56:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.20 2020/05/10 01:29:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.21 2020/05/10 02:56:12 riastradh Exp $");
 
 #include 
 #include 
@@ -1932,6 +1932,40 @@ rndsource_to_user_est(struct krndsource 
 }
 
 /*
+ * entropy_reset_xc(arg1, arg2)
+ *
+ *	Reset the current CPU's pending entropy to zero.
+ */
+static void
+entropy_reset_xc(void *arg1 __unused, void *arg2 __unused)
+{
+	uint32_t extra = entropy_timer();
+	struct entropy_cpu *ec;
+	int s;
+
+	/*
+	 * Acquire the per-CPU state, blocking soft interrupts and
+	 * causing hard interrupts to drop samples on the floor.
+	 */
+	ec = percpu_getref(entropy_percpu);
+	s = splsoftserial();
+	KASSERT(!ec->ec_locked);
+	ec->ec_locked = true;
+	__insn_barrier();
+
+	/* Zero the pending count and enter a cycle count for fun.  */
+	ec->ec_pending = 0;
+	entpool_enter(ec->ec_pool, , sizeof extra);
+
+	/* Release the per-CPU state.  */
+	KASSERT(ec->ec_locked);
+	__insn_barrier();
+	ec->ec_locked = false;
+	splx(s);
+	percpu_putref(entropy_percpu);
+}
+
+/*
  * entropy_ioctl(cmd, data)
  *
  *	Handle various /dev/random ioctl queries.
@@ -2165,7 +2199,9 @@ entropy_ioctl(unsigned long cmd, void *d
 	case RNDCTL: {		/* Modify entropy source flags.  */
 		rndctl_t *rndctl = data;
 		const size_t n = sizeof(rs->name);
+		uint32_t resetflags = RND_FLAG_NO_ESTIMATE|RND_FLAG_NO_COLLECT;
 		uint32_t flags;
+		bool reset = false, request = false;
 
 		CTASSERT(sizeof(rs->name) == sizeof(rndctl->name));
 
@@ -2187,9 +2223,39 @@ entropy_ioctl(unsigned long cmd, void *d
 			}
 			flags = rs->flags & ~rndctl->mask;
 			flags |= rndctl->flags & rndctl->mask;
+			if ((rs->flags & resetflags) == 0 &&
+			(flags & resetflags) != 0)
+reset = true;
+			if ((rs->flags ^ flags) & resetflags)
+request = true;
 			atomic_store_relaxed(>flags, flags);
 		}
 		mutex_exit(>lock);
+
+		/*
+		 * If we disabled estimation or collection, nix all the
+		 * pending entropy and set needed to the maximum.
+		 */
+		if (reset) {
+			xc_broadcast(0, _reset_xc, NULL, NULL);
+			mutex_enter(>lock);
+			E->pending = 0;
+			atomic_store_relaxed(>needed,
+			ENTROPY_CAPACITY*NBBY);
+			mutex_exit(>lock);
+		}
+
+		/*
+		 * If we changed any of the estimation or collection
+		 * flags, request new samples from everyone -- either
+		 * to make up for what we just lost, or to get new
+		 * samples from what we just added.
+		 */
+		if (request) {
+			mutex_enter(>lock);
+			entropy_request(ENTROPY_CAPACITY);
+			mutex_exit(>lock);
+		}
 		break;
 	}
 	case RNDADDDATA: {	/* Enter seed into entropy pool.  */



CVS commit: src/sys/uvm

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 02:38:10 UTC 2020

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

Log Message:
Rename things so the symbol better matches the sysctl name.

No functional change intended, except that the symbol that was
previously `uvm_swap_encryption' is now `uvm_swap_encrypt', backing
the sysctl knob `vm.swap_encrypt'.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 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.188 src/sys/uvm/uvm_swap.c:1.189
--- src/sys/uvm/uvm_swap.c:1.188	Sat May  9 22:00:48 2020
+++ src/sys/uvm/uvm_swap.c	Sun May 10 02:38:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.188 2020/05/09 22:00:48 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.189 2020/05/10 02:38:10 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.188 2020/05/09 22:00:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.189 2020/05/10 02:38:10 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -208,7 +208,7 @@ static struct workqueue *sw_reg_workqueu
 
 /* tuneables */
 u_int uvm_swapisfull_factor = 99;
-bool uvm_swap_encryption = false;
+bool uvm_swap_encrypt = false;
 
 /*
  * prototypes
@@ -231,8 +231,8 @@ static void sw_reg_start(struct swapdev 
 static int uvm_swap_io(struct vm_page **, int, int, int);
 
 static void uvm_swap_genkey(struct swapdev *);
-static void uvm_swap_encrypt(struct swapdev *, void *, int);
-static void uvm_swap_decrypt(struct swapdev *, void *, int);
+static void uvm_swap_encryptpage(struct swapdev *, void *, int);
+static void uvm_swap_decryptpage(struct swapdev *, void *, int);
 
 /*
  * uvm_swap_init: init the swap system data structures and locks
@@ -1800,7 +1800,7 @@ uvm_swap_io(struct vm_page **pps, int st
 
 	write = (flags & B_READ) == 0;
 	async = (flags & B_ASYNC) != 0;
-	swap_encrypt = atomic_load_relaxed(_swap_encryption);
+	swap_encrypt = atomic_load_relaxed(_swap_encrypt);
 
 	/*
 	 * allocate a buf for the i/o.
@@ -1871,7 +1871,7 @@ uvm_swap_io(struct vm_page **pps, int st
 KASSERT(s >= sdp->swd_drumoffset);
 s -= sdp->swd_drumoffset;
 KASSERT(s < sdp->swd_drumsize);
-uvm_swap_encrypt(sdp,
+uvm_swap_encryptpage(sdp,
 (void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 setbit(sdp->swd_encmap, s);
 			}
@@ -1967,7 +1967,7 @@ uvm_swap_io(struct vm_page **pps, int st
 			KASSERT(s < sdp->swd_drumsize);
 			if (isclr(sdp->swd_encmap, s))
 continue;
-			uvm_swap_decrypt(sdp,
+			uvm_swap_decryptpage(sdp,
 			(void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 		}
 	} while (0);
@@ -2014,13 +2014,13 @@ uvm_swap_genkey(struct swapdev *sdp)
 }
 
 /*
- * uvm_swap_encrypt(sdp, kva, slot)
+ * uvm_swap_encryptpage(sdp, kva, slot)
  *
  *	Encrypt one page of data at kva for the specified slot number
  *	in the swap device.
  */
 static void
-uvm_swap_encrypt(struct swapdev *sdp, void *kva, int slot)
+uvm_swap_encryptpage(struct swapdev *sdp, void *kva, int slot)
 {
 	cipherInstance aes;
 	uint8_t preiv[16] = {0}, iv[16];
@@ -2046,13 +2046,13 @@ uvm_swap_encrypt(struct swapdev *sdp, vo
 }
 
 /*
- * uvm_swap_decrypt(sdp, kva, slot)
+ * uvm_swap_decryptpage(sdp, kva, slot)
  *
  *	Decrypt one page of data at kva for the specified slot number
  *	in the swap device.
  */
 static void
-uvm_swap_decrypt(struct swapdev *sdp, void *kva, int slot)
+uvm_swap_decryptpage(struct swapdev *sdp, void *kva, int slot)
 {
 	cipherInstance aes;
 	uint8_t preiv[16] = {0}, iv[16];
@@ -2084,6 +2084,6 @@ SYSCTL_SETUP(sysctl_uvmswap_setup, "sysc
 	sysctl_createv(clog, 0, NULL, NULL,
 	CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_BOOL, "swap_encrypt",
 	SYSCTL_DESCR("Encrypt data when swapped out to disk"),
-	NULL, 0, _swap_encryption, 0,
+	NULL, 0, _swap_encrypt, 0,
 	CTL_VM, CTL_CREATE, CTL_EOL);
 }



CVS commit: src/share/man/man7

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 02:32:32 UTC 2020

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

Log Message:
Mark experimental-default-off knobs clearly as such.


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

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.145 src/share/man/man7/sysctl.7:1.146
--- src/share/man/man7/sysctl.7:1.145	Sun May 10 02:31:29 2020
+++ src/share/man/man7/sysctl.7	Sun May 10 02:32:32 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.145 2020/05/10 02:31:29 riastradh Exp $
+.\"	$NetBSD: sysctl.7,v 1.146 2020/05/10 02:32:32 riastradh Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -2546,12 +2546,11 @@ the fifth is the size of
 Returns an array of
 .Vt struct kinfo_vmentry
 objects.
-.It Li vm.ubc_direct
+.It Li vm.ubc_direct Bq Sy "EXPERIMENTAL" Ns No , default off
 Use direct map for UBC I/O, avoiding need to map and unmap buffer memory.
 Speeds up operation for fast I/O devices like NVMe, especially
 on multi-CPU systems.
 Only available on some architectures.
-Currently still experimental, default is off.
 .It Li vm.uspace ( Dv VM_USPACE )
 The number of bytes allocated for each kernel stack.
 .It Li vm.uvmexp ( Dv VM_UVMEXP )
@@ -2567,7 +2566,7 @@ Return system wide guard size for the ma
 .It Li vm.thread_guard_size
 Return system wide default size for the guard area of all other threads
 of a program.
-.It Li vm.swap_encrypt
+.It Li vm.swap_encrypt Bq Sy "EXPERIMENTAL" Ns No , default off
 If true, encrypt data while swapped out to disk.
 .Pp
 Each swap device maintains an independent AES-256 key, generated when



CVS commit: src/share/man/man7

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 02:31:29 UTC 2020

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

Log Message:
Document vm.swap_encrypt.


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

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.144 src/share/man/man7/sysctl.7:1.145
--- src/share/man/man7/sysctl.7:1.144	Sun May 10 02:30:33 2020
+++ src/share/man/man7/sysctl.7	Sun May 10 02:31:29 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.144 2020/05/10 02:30:33 riastradh Exp $
+.\"	$NetBSD: sysctl.7,v 1.145 2020/05/10 02:31:29 riastradh Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -2493,6 +2493,7 @@ privilege may change the value.
 .It vm.proc.map	struct kinfo_vmentry	no
 .It vm.guard_size	unsigned int	no
 .It vm.thread_guard_size	unsigned int	yes
+.It vm.swap_encrypt	bool	yes
 .El
 .Bl -tag -width "123456"
 .It Li vm.anonmax ( Dv VM_ANONMAX )
@@ -2566,6 +2567,29 @@ Return system wide guard size for the ma
 .It Li vm.thread_guard_size
 Return system wide default size for the guard area of all other threads
 of a program.
+.It Li vm.swap_encrypt
+If true, encrypt data while swapped out to disk.
+.Pp
+Each swap device maintains an independent AES-256 key, generated when
+the first page is swapped to that device.
+Each page is swapped independently using AES-CBC, with an
+initialization vector chosen by the encryption under the AES-256 key of
+the little-endian swap slot number padded to 128 bits with zeros.
+(This is essentially the
+.Xr cgd 4
+.Sq encblkno1
+method.)
+.Pp
+Changes to
+.Li vm.swap_encrypt
+only affect pages of swap newly written out.
+To force encrypting or decrypting all existing swap, or to rekey
+previously encrypted swap, you can remove the swap devices and re-add
+them with
+.Xr swapctl 8 ,
+with the caveat that whatever pages were already written to disk
+unencrypted or encrypted with a compromised key may still be written to
+disk afterward.
 .\" XXX vm.idlezero
 .El
 .Ss The ddb.* subtree ( Dv CTL_DDB )



CVS commit: src/share/man/man7

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 02:30:33 UTC 2020

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

Log Message:
Tweak kern.arandom documentation.


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

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.143 src/share/man/man7/sysctl.7:1.144
--- src/share/man/man7/sysctl.7:1.143	Fri May  1 10:06:09 2020
+++ src/share/man/man7/sysctl.7	Sun May 10 02:30:33 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.143 2020/05/01 10:06:09 nia Exp $
+.\"	$NetBSD: sysctl.7,v 1.144 2020/05/10 02:30:33 riastradh Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -384,13 +384,25 @@ upon loading or unloading the correspond
 .It Li kern.aio_max
 The maximum number of asynchronous I/O operations.
 .It Li kern.arandom ( Dv KERN_ARND )
-This variable returns up to 256 bytes of random data.
-Multiple queries can be used to obtain an infinite amount of
-non-blocking cryptographically secure random data.
-The used random number generator
-.Pf ( RNG )
-is based on
-.Xr cprng_strong 9 .
+Returns independent uniformly distributed bytes at random each time, as
+many as requested up to 256, derived from the system entropy pool; see
+.Xr rnd 4 .
+.Pp
+Reading
+.Li kern.arandom
+is equivalent to reading up to 256 bytes at a time from
+.Pa /dev/urandom :
+reading
+.Li kern.arandom
+never blocks, and once the system entropy pool has full entropy, output
+subsequently read from
+.Li kern.arandom
+is fit for use as cryptographic key material.
+For example, the
+.Xr arc4random 3
+library routine uses
+.Li kern.arandom
+internally to seed a cryptographic pseudorandom number generator.
 .It Li kern.argmax ( Dv KERN_ARGMAX )
 The maximum bytes of argument to
 .Xr execve 2 .



CVS commit: src/sys/kern

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 01:29:40 UTC 2020

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

Log Message:
Fix comments.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/kern/kern_entropy.c

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

Modified files:

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.19 src/sys/kern/kern_entropy.c:1.20
--- src/sys/kern/kern_entropy.c:1.19	Sun May 10 00:08:12 2020
+++ src/sys/kern/kern_entropy.c	Sun May 10 01:29:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.19 2020/05/10 00:08:12 riastradh Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.20 2020/05/10 01:29:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.19 2020/05/10 00:08:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.20 2020/05/10 01:29:40 riastradh Exp $");
 
 #include 
 #include 
@@ -1026,10 +1026,10 @@ entropy_do_consolidate(void)
 }
 
 /*
- * entropy_consolidate_xc(arg1, arg2)
+ * entropy_consolidate_xc(vpool, arg2)
  *
  *	Extract output from the local CPU's input pool and enter it
- *	into the global pool.
+ *	into a temporary pool passed as vpool.
  */
 static void
 entropy_consolidate_xc(void *vpool, void *arg2 __unused)



CVS commit: src/sys/kern

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 10 00:08:12 UTC 2020

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

Log Message:
Use a temporary pool to consolidate entropy atomically.

There was a low-probability race with the entropy consolidation
logic: calls to entropy_extract at the same time as consolidation is
happening might witness partial contributions from the CPUs when
needed=256, say 64 bits at a time.

To avoid this, feed everything from the per-CPU pools into a
temporary pool, and then feed the temporary pool into the global pool
under the lock at the same time as we update needed.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/kern/kern_entropy.c

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

Modified files:

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.18 src/sys/kern/kern_entropy.c:1.19
--- src/sys/kern/kern_entropy.c:1.18	Sat May  9 06:12:32 2020
+++ src/sys/kern/kern_entropy.c	Sun May 10 00:08:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.18 2020/05/09 06:12:32 riastradh Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.19 2020/05/10 00:08:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.18 2020/05/09 06:12:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.19 2020/05/10 00:08:12 riastradh Exp $");
 
 #include 
 #include 
@@ -984,11 +984,14 @@ entropy_do_consolidate(void)
 {
 	static const struct timeval interval = {.tv_sec = 60, .tv_usec = 0};
 	static struct timeval lasttime; /* serialized by E->lock */
+	struct entpool pool;
+	uint8_t buf[ENTPOOL_CAPACITY];
 	unsigned diff;
 	uint64_t ticket;
 
-	/* Gather entropy on all CPUs.  */
-	ticket = xc_broadcast(0, _consolidate_xc, NULL, NULL);
+	/* Gather entropy on all CPUs into a temporary pool.  */
+	memset(, 0, sizeof pool);
+	ticket = xc_broadcast(0, _consolidate_xc, , NULL);
 	xc_wait(ticket);
 
 	/* Acquire the lock to notify waiters.  */
@@ -1000,6 +1003,11 @@ entropy_do_consolidate(void)
 	/* Note when we last consolidated, i.e. now.  */
 	E->timestamp = time_uptime;
 
+	/* Mix what we gathered into the global pool.  */
+	entpool_extract(, buf, sizeof buf);
+	entpool_enter(>pool, buf, sizeof buf);
+	explicit_memset(, 0, sizeof pool);
+
 	/* Count the entropy that was gathered.  */
 	diff = MIN(E->needed, E->pending);
 	atomic_store_relaxed(>needed, E->needed - diff);
@@ -1024,8 +1032,9 @@ entropy_do_consolidate(void)
  *	into the global pool.
  */
 static void
-entropy_consolidate_xc(void *arg1 __unused, void *arg2 __unused)
+entropy_consolidate_xc(void *vpool, void *arg2 __unused)
 {
+	struct entpool *pool = vpool;
 	struct entropy_cpu *ec;
 	uint8_t buf[ENTPOOL_CAPACITY];
 	uint32_t extra[7];
@@ -1063,15 +1072,15 @@ entropy_consolidate_xc(void *arg1 __unus
 
 	/*
 	 * Copy over statistics, and enter the per-CPU extract and the
-	 * extra timing into the global pool, under the global lock.
+	 * extra timing into the temporary pool, under the global lock.
 	 */
 	mutex_enter(>lock);
 	extra[i++] = entropy_timer();
-	entpool_enter(>pool, buf, sizeof buf);
+	entpool_enter(pool, buf, sizeof buf);
 	explicit_memset(buf, 0, sizeof buf);
 	extra[i++] = entropy_timer();
 	KASSERT(i == __arraycount(extra));
-	entpool_enter(>pool, extra, sizeof extra);
+	entpool_enter(pool, extra, sizeof extra);
 	explicit_memset(extra, 0, sizeof extra);
 	mutex_exit(>lock);
 }



CVS commit: src/sys/uvm

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  9 22:00:48 UTC 2020

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

Log Message:
Avoid overflow if a very large number of pages are swapped at once.

Unlikely, but let's make sure we don't hit this ever.


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 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.187 src/sys/uvm/uvm_swap.c:1.188
--- src/sys/uvm/uvm_swap.c:1.187	Sat May  9 21:50:39 2020
+++ src/sys/uvm/uvm_swap.c	Sat May  9 22:00:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.187 2020/05/09 21:50:39 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.188 2020/05/09 22:00:48 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.187 2020/05/09 21:50:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.188 2020/05/09 22:00:48 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1872,7 +1872,7 @@ uvm_swap_io(struct vm_page **pps, int st
 s -= sdp->swd_drumoffset;
 KASSERT(s < sdp->swd_drumsize);
 uvm_swap_encrypt(sdp,
-(void *)(kva + i*PAGE_SIZE), s);
+(void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 setbit(sdp->swd_encmap, s);
 			}
 		} else {
@@ -1967,7 +1967,8 @@ uvm_swap_io(struct vm_page **pps, int st
 			KASSERT(s < sdp->swd_drumsize);
 			if (isclr(sdp->swd_encmap, s))
 continue;
-			uvm_swap_decrypt(sdp, (void *)(kva + i*PAGE_SIZE), s);
+			uvm_swap_decrypt(sdp,
+			(void *)(kva + (vsize_t)i*PAGE_SIZE), s);
 		}
 	} while (0);
 



CVS commit: src/sys/uvm

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  9 21:50:39 UTC 2020

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

Log Message:
Implement swap encryption.

Enabled by sysctl -w vm.swap_encrypt=1.  Key is generated lazily when
we first need to swap a page.  Key is chosen independently for each
swap device.  The ith swap page is encrypted with AES256-CBC using
AES256_k(le32enc(i) || 0^96) as the initialization vector.  Can be
changed at any time; no need for compatibility with on-disk formats.
Costs one bit of memory per page in each swapdev, plus a few hundred
bytes per swapdev to store the expanded AES key.

Shoulda done this decades ago!  Plan to enable this by default;
performance impact is unlikely to matter because it only happens when
you're already swapping anyway.  Much easier to set up than cgd, so
we can rip out all the documentation about carefully setting up
random-keyed cgd at the right time.


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 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.186 src/sys/uvm/uvm_swap.c:1.187
--- src/sys/uvm/uvm_swap.c:1.186	Tue Feb 18 20:23:17 2020
+++ src/sys/uvm/uvm_swap.c	Sat May  9 21:50:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.186 2020/02/18 20:23:17 chs Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.187 2020/05/09 21:50:39 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.186 2020/02/18 20:23:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.187 2020/05/09 21:50:39 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -64,6 +65,8 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v
 
 #include 
 
+#include 
+
 /*
  * uvm_swap.c: manage configuration and i/o to swap space.
  */
@@ -143,6 +146,11 @@ struct swapdev {
 	int			swd_maxactive;	/* max active i/o reqs */
 	struct bufq_state	*swd_tab;	/* buffer list */
 	int			swd_active;	/* number of active buffers */
+
+	uint8_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 */
 };
 
 /*
@@ -200,6 +208,7 @@ static struct workqueue *sw_reg_workqueu
 
 /* tuneables */
 u_int uvm_swapisfull_factor = 99;
+bool uvm_swap_encryption = false;
 
 /*
  * prototypes
@@ -221,6 +230,10 @@ static void sw_reg_start(struct swapdev 
 
 static int uvm_swap_io(struct vm_page **, int, int, int);
 
+static void uvm_swap_genkey(struct swapdev *);
+static void uvm_swap_encrypt(struct swapdev *, void *, int);
+static void uvm_swap_decrypt(struct swapdev *, void *, int);
+
 /*
  * uvm_swap_init: init the swap system data structures and locks
  *
@@ -888,6 +901,13 @@ swap_on(struct lwp *l, struct swapdev *s
 	blist_free(sdp->swd_blist, addr, size);
 
 	/*
+	 * 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_encinit = false;
+
+	/*
 	 * if the vnode we are swapping to is the root vnode
 	 * (i.e. we are swapping to the miniroot) then we want
 	 * to make sure we don't overwrite it.   do a statfs to
@@ -1059,6 +1079,9 @@ 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));
+	explicit_memset(>swd_enckey, 0, sizeof sdp->swd_enckey);
+	explicit_memset(>swd_deckey, 0, sizeof sdp->swd_deckey);
 	kmem_free(sdp, sizeof(*sdp));
 	return (0);
 }
@@ -1769,7 +1792,7 @@ uvm_swap_io(struct vm_page **pps, int st
 	struct	buf *bp;
 	vaddr_t kva;
 	int	error, mapinflags;
-	bool write, async;
+	bool write, async, swap_encrypt;
 	UVMHIST_FUNC("uvm_swap_io"); UVMHIST_CALLED(pdhist);
 
 	UVMHIST_LOG(pdhist, "<- called, startslot=%jd, npages=%jd, flags=%jd",
@@ -1777,6 +1800,7 @@ uvm_swap_io(struct vm_page **pps, int st
 
 	write = (flags & B_READ) == 0;
 	async = (flags & B_ASYNC) != 0;
+	swap_encrypt = atomic_load_relaxed(_swap_encryption);
 
 	/*
 	 * allocate a buf for the i/o.
@@ -1802,9 +1826,68 @@ uvm_swap_io(struct vm_page **pps, int st
 	mapinflags = !write ?
 		UVMPAGER_MAPIN_WAITOK|UVMPAGER_MAPIN_READ :
 		UVMPAGER_MAPIN_WAITOK|UVMPAGER_MAPIN_WRITE;
+	if (write && swap_encrypt)	/* need to encrypt in-place */
+		mapinflags |= UVMPAGER_MAPIN_READ;
 	kva = uvm_pagermapin(pps, npages, mapinflags);
 
 	/*
+	 * encrypt writes in place if requested
+	 */
+
+	if (write) do {
+		struct swapdev *sdp;
+		int i;
+

CVS commit: src/sys/dev/nvmm/x86

2020-05-09 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May  9 16:18:57 UTC 2020

Modified Files:
src/sys/dev/nvmm/x86: nvmm_x86.c nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Improve the CPUID emulation of basic leaves:
 - Hide DCA and PQM, they cannot be used in guests.
 - On Intel, explicitly handle each basic leaf until 0x16.
 - On AMD, explicitly handle each basic leaf until 0x0D.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nvmm/x86/nvmm_x86.c
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

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

Modified files:

Index: src/sys/dev/nvmm/x86/nvmm_x86.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86.c:1.8 src/sys/dev/nvmm/x86/nvmm_x86.c:1.9
--- src/sys/dev/nvmm/x86/nvmm_x86.c:1.8	Sat Nov 16 17:53:46 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86.c	Sat May  9 16:18:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86.c,v 1.8 2019/11/16 17:53:46 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86.c,v 1.9 2020/05/09 16:18:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.8 2019/11/16 17:53:46 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.9 2020/05/09 16:18:57 maxv Exp $");
 
 #include 
 #include 
@@ -233,18 +233,18 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	.eax = ~0,
 	.ebx = ~0,
 	.ecx =
-	/* Excluded: MONITOR, VMX, SMX, EST, TM2, PDCM, PCID, X2APIC,
+	/* Excluded: MONITOR, VMX, SMX, EST, TM2, PDCM, PCID, DCA, X2APIC,
 	 * DEADLINE, RAZ. */
 	CPUID2_SSE3 | CPUID2_PCLMUL |
 	CPUID2_DTES64 | CPUID2_DS_CPL |
 	CPUID2_SSSE3 | CPUID2_CID |
 	CPUID2_SDBG | CPUID2_FMA |
 	CPUID2_CX16 | CPUID2_xTPR |
-	CPUID2_DCA | CPUID2_SSE41 |
-	CPUID2_SSE42 | CPUID2_MOVBE |
-	CPUID2_POPCNT | CPUID2_AES |
-	CPUID2_XSAVE | CPUID2_OSXSAVE |
-	CPUID2_F16C | CPUID2_RDRAND,
+	CPUID2_SSE41 | CPUID2_SSE42 |
+	CPUID2_MOVBE | CPUID2_POPCNT |
+	CPUID2_AES | CPUID2_XSAVE |
+	CPUID2_OSXSAVE | CPUID2_F16C |
+	CPUID2_RDRAND,
 	.edx =
 	/* Excluded: MCE, MTRR, MCA, DS, ACPI, TM. */
 	CPUID_FPU | CPUID_VME |
@@ -265,16 +265,16 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 const struct nvmm_x86_cpuid_mask nvmm_cpuid_0007 = {
 	.eax = ~0,
 	.ebx =
-	/* Excluded: TSC_ADJUST, AVX2, INVPCID, AVX512*, PT, SHA. */
+	/* Excluded: TSC_ADJUST, AVX2, INVPCID, QM, AVX512*, PT, SHA. */
 	CPUID_SEF_FSGSBASE |
 	CPUID_SEF_SGX | CPUID_SEF_BMI1 |
 	CPUID_SEF_HLE | CPUID_SEF_FDPEXONLY |
 	CPUID_SEF_SMEP | CPUID_SEF_BMI2 |
 	CPUID_SEF_ERMS | CPUID_SEF_RTM |
-	CPUID_SEF_QM | CPUID_SEF_FPUCSDS |
-	CPUID_SEF_PQE | CPUID_SEF_RDSEED |
-	CPUID_SEF_ADX | CPUID_SEF_SMAP |
-	CPUID_SEF_CLFLUSHOPT | CPUID_SEF_CLWB,
+	CPUID_SEF_FPUCSDS | CPUID_SEF_PQE |
+	CPUID_SEF_RDSEED | CPUID_SEF_ADX |
+	CPUID_SEF_SMAP | CPUID_SEF_CLFLUSHOPT |
+	CPUID_SEF_CLWB,
 	.ecx =
 	/* Excluded: AVX512*, MAWAU, RDPID. */
 	CPUID_SEF_PREFETCHWT1 | CPUID_SEF_UMIP |

Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.59 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.60
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.59	Thu Apr 30 16:50:17 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Sat May  9 16:18:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.59 2020/04/30 16:50:17 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.60 2020/05/09 16:18:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.59 2020/04/30 16:50:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.60 2020/05/09 16:18:57 maxv Exp $");
 
 #include 
 #include 
@@ -796,20 +796,33 @@ svm_inkernel_handle_cpuid(struct nvmm_cp
 			cpudata->gprs[NVMM_X64_GPR_RCX] &= ~CPUID2_OSXSAVE;
 		}
 		break;
-	case 0x0005:
-	case 0x0006:
+	case 0x0002: /* Empty */
+	case 0x0003: /* Empty */
+	case 0x0004: /* Empty */
+	case 0x0005: /* Monitor/MWait */
+	case 0x0006: /* Power Management Related Features */
 		cpudata->vmcb->state.rax = 0;
 		cpudata->gprs[NVMM_X64_GPR_RBX] = 0;
 		cpudata->gprs[NVMM_X64_GPR_RCX] = 0;
 		cpudata->gprs[NVMM_X64_GPR_RDX] = 0;
 		break;
-	case 0x0007:
+	case 0x0007: /* Structured Extended Features */
 		cpudata->vmcb->state.rax &= nvmm_cpuid_0007.eax;
 		cpudata->gprs[NVMM_X64_GPR_RBX] &= nvmm_cpuid_0007.ebx;
 		cpudata->gprs[NVMM_X64_GPR_RCX] &= nvmm_cpuid_0007.ecx;
 		cpudata->gprs[NVMM_X64_GPR_RDX] &= nvmm_cpuid_0007.edx;
 		break;
-	case 0x000D:
+	case 0x0008: /* Empty */
+	case 0x0009: /* Empty */
+	case 0x000A: /* Empty */
+	case 0x000B: /* Empty */
+	case 0x000C: /* Empty */
+		cpudata->vmcb->state.rax = 0;
+		cpudata->gprs[NVMM_X64_GPR_RBX] = 

CVS commit: src/sys/uvm

2020-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  9 15:13:19 UTC 2020

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

Log Message:
Make the uvm_voaddr structure more compact, only occupying 2 pointers
worth of space, by encoding the type in the lower bits of the object
pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/sys/uvm/uvm_extern.h
cvs rdiff -u -r1.382 -r1.383 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_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.225 src/sys/uvm/uvm_extern.h:1.226
--- src/sys/uvm/uvm_extern.h:1.225	Mon Apr 27 02:47:26 2020
+++ src/sys/uvm/uvm_extern.h	Sat May  9 15:13:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.225 2020/04/27 02:47:26 rin Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.226 2020/05/09 15:13:19 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -613,8 +613,7 @@ extern struct vm_map *phys_map;
  *
  *	This structure encapsulates UVM's unique virtual object address
  *	for an individual byte inside a pageable page. Pageable pages can
- *	be owned by either a uvm_object (UVM_VOADDR_TYPE_OBJECT) or a
- *	vm_anon (UVM_VOADDR_TYPE_ANON).
+ *	be owned by either a uvm_object or a vm_anon.
  *
  *	In each case, the byte offset into the owning object
  *	(uvm_object or vm_anon) is included in the ID, so that
@@ -631,14 +630,7 @@ extern struct vm_map *phys_map;
  *	use.
  */
 struct uvm_voaddr {
-	enum {
-		UVM_VOADDR_TYPE_OBJECT = 1,
-		UVM_VOADDR_TYPE_ANON = 2,
-	} type;
-	union {
-		struct uvm_object *uobj;
-		struct vm_anon *anon;
-	};
+	uintptr_t object;
 	voff_t offset;
 };
 

Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.382 src/sys/uvm/uvm_map.c:1.383
--- src/sys/uvm/uvm_map.c:1.382	Thu Apr 30 04:18:07 2020
+++ src/sys/uvm/uvm_map.c	Sat May  9 15:13:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.382 2020/04/30 04:18:07 thorpej Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.383 2020/05/09 15:13:19 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.382 2020/04/30 04:18:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.383 2020/05/09 15:13:19 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -4781,6 +4781,31 @@ uvm_map_unlock_entry(struct vm_map_entry
 	}
 }
 
+#define	UVM_VOADDR_TYPE_MASK	0x3UL
+#define	UVM_VOADDR_TYPE_UOBJ	0x1UL
+#define	UVM_VOADDR_TYPE_ANON	0x2UL
+#define	UVM_VOADDR_OBJECT_MASK	~UVM_VOADDR_TYPE_MASK
+
+#define	UVM_VOADDR_GET_TYPE(voa)	\
+	((voa)->object & UVM_VOADDR_TYPE_MASK)
+#define	UVM_VOADDR_GET_OBJECT(voa)	\
+	((voa)->object & UVM_VOADDR_OBJECT_MASK)
+#define	UVM_VOADDR_SET_OBJECT(voa, obj, type)\
+do {	\
+	KASSERT(((uintptr_t)(obj) & UVM_VOADDR_TYPE_MASK) == 0);	\
+	(voa)->object = ((uintptr_t)(obj)) | (type);			\
+} while (/*CONSTCOND*/0)
+
+#define	UVM_VOADDR_GET_UOBJ(voa)	\
+	((struct uvm_object *)UVM_VOADDR_GET_OBJECT(voa))
+#define	UVM_VOADDR_SET_UOBJ(voa, uobj)	\
+	UVM_VOADDR_SET_OBJECT(voa, uobj, UVM_VOADDR_TYPE_UOBJ)
+
+#define	UVM_VOADDR_GET_ANON(voa)	\
+	((struct vm_anon *)UVM_VOADDR_GET_OBJECT(voa))
+#define	UVM_VOADDR_SET_ANON(voa, anon)	\
+	UVM_VOADDR_SET_OBJECT(voa, anon, UVM_VOADDR_TYPE_ANON)
+
 /*
  * uvm_voaddr_acquire: returns the virtual object address corresponding
  * to the specified virtual address.
@@ -4936,8 +4961,7 @@ uvm_voaddr_acquire(struct vm_map * const
 			anon->an_ref++;
 			rw_obj_hold(anon->an_lock);
 			KASSERT(anon->an_ref != 0);
-			voaddr->type = UVM_VOADDR_TYPE_ANON;
-			voaddr->anon = anon;
+			UVM_VOADDR_SET_ANON(voaddr, anon);
 			voaddr->offset = va & PAGE_MASK;
 			result = true;
 		}
@@ -4950,8 +4974,7 @@ uvm_voaddr_acquire(struct vm_map * const
 
 		KASSERT(uobj != NULL);
 		(*uobj->pgops->pgo_reference)(uobj);
-		voaddr->type = UVM_VOADDR_TYPE_OBJECT;
-		voaddr->uobj = uobj;
+		UVM_VOADDR_SET_UOBJ(voaddr, uobj);
 		voaddr->offset = entry->offset + (va - entry->start);
 		result = true;
 	}
@@ -4961,7 +4984,9 @@ uvm_voaddr_acquire(struct vm_map * const
 	if (result) {
 		UVMHIST_LOG(maphist,
 		"<- done OK (type=%jd,owner=#%jx,offset=%jx)",
-		voaddr->type, (uintptr_t)voaddr->uobj, voaddr->offset, 0);
+		UVM_VOADDR_GET_TYPE(voaddr),
+		UVM_VOADDR_GET_OBJECT(voaddr),
+		voaddr->offset, 0);
 	} else {
 		UVMHIST_LOG(maphist,"<- done (failed)",0,0,0,0);
 	}
@@ -4977,9 +5002,9 @@ void
 uvm_voaddr_release(struct uvm_voaddr * const voaddr)
 {
 
-	switch (voaddr->type) {
-	case UVM_VOADDR_TYPE_OBJECT: {
-		struct uvm_object * const uobj = voaddr->uobj;
+	switch (UVM_VOADDR_GET_TYPE(voaddr)) {
+	case UVM_VOADDR_TYPE_UOBJ: {
+		struct uvm_object * const uobj = UVM_VOADDR_GET_UOBJ(voaddr);
 
 		KASSERT(uobj != NULL);
 		KASSERT(uobj->pgops->pgo_detach != NULL);
@@ 

CVS commit: src/crypto/external/bsd/openssl/lib/libcrypto

2020-05-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat May  9 13:16:43 UTC 2020

Modified Files:
src/crypto/external/bsd/openssl/lib/libcrypto: crypto.inc evp.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/alpha: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/arm: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/i386: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/powerpc: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/powerpc64:
crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/sparc: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/sparc64: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/vax: crypto.inc
src/crypto/external/bsd/openssl/lib/libcrypto/arch/x86_64: crypto.inc

Log Message:
Define OPENSSL_CPUID_OBJ in general CPPFLAGS instead of CRYPTOCPPFLAGS

This is used in various parts of the distribution, defining it here
avoids future problems with CPU-specific features not being detected.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 \
src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc \
src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc
cvs rdiff -u -r1.4 -r1.5 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/alpha/crypto.inc
cvs rdiff -u -r1.10 -r1.11 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/arm/crypto.inc
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/i386/crypto.inc
cvs rdiff -u -r1.3 -r1.4 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/powerpc/crypto.inc
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/powerpc64/crypto.inc
cvs rdiff -u -r1.11 -r1.12 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/sparc/crypto.inc
cvs rdiff -u -r1.7 -r1.8 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/sparc64/crypto.inc
cvs rdiff -u -r1.3 -r1.4 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/vax/crypto.inc
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/openssl/lib/libcrypto/arch/x86_64/crypto.inc

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

Modified files:

Index: src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc:1.9 src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc:1.10
--- src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc:1.9	Sat Dec  8 22:35:44 2018
+++ src/crypto/external/bsd/openssl/lib/libcrypto/crypto.inc	Sat May  9 13:16:41 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: crypto.inc,v 1.9 2018/12/08 22:35:44 christos Exp $
+#	$NetBSD: crypto.inc,v 1.10 2020/05/09 13:16:41 nia Exp $
 #
 #	@(#) Copyright (c) 1995 Simon J. Gerraty
 #
@@ -37,7 +37,6 @@ SRCS += ${CRYPTO_SRCS}
 CRYPTO_SRCS+=  mem_clr.c
 .else
 CRYPTO_SRCS+=  ${CPUID_SRCS}
-#CRYPTOCPPFLAGS=-DOPENSSL_CPUID_OBJ
 .endif
 
 CRYPTOCPPFLAGS+=-DOPENSSL_NO_STATIC_ENGINE
Index: src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.9 src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.10
--- src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.9	Sat May  9 12:20:50 2020
+++ src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc	Sat May  9 13:16:41 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: evp.inc,v 1.9 2020/05/09 12:20:50 nia Exp $
+#	$NetBSD: evp.inc,v 1.10 2020/05/09 13:16:41 nia Exp $
 #
 #	@(#) Copyright (c) 1995 Simon J. Gerraty
 #
@@ -85,7 +85,6 @@ EVP_AES_SRCS = e_aes.c
 
 .for cryptosrc in ${EVP_AES_SRCS}
 CPPFLAGS.${cryptosrc} += ${AESCPPFLAGS}
-CPPFLAGS.${cryptosrc} += ${CRYPTOCPPFLAGS}
 .endfor
 
 CPPFLAGS.e_aes.c += -I${OPENSSLSRC}/crypto/modes

Index: src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc:1.4 src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc:1.5
--- src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc:1.4	Mon Sep 24 11:03:39 2018
+++ src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/crypto.inc	Sat May  9 13:16:42 2020
@@ -1,9 +1,9 @@
 .PATH.S: ${.PARSEDIR}
 CPUID_SRCS += arm64cpuid.S armcap.c
-CRYPTOCPPFLAGS += -DOPENSSL_CPUID_OBJ
 CPUID = yes
 ARM_MAX_ARCH=8
 CPPFLAGS += -D__ARM_MAX_ARCH__=${ARM_MAX_ARCH}
+CPPFLAGS += -DOPENSSL_CPUID_OBJ
 CFLAGS+= ${${ACTIVE_CC} == "clang" :? -no-integrated-as :}
 .include "../../crypto.inc"
 

Index: src/crypto/external/bsd/openssl/lib/libcrypto/arch/alpha/crypto.inc
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/arch/alpha/crypto.inc:1.2 src/crypto/external/bsd/openssl/lib/libcrypto/arch/alpha/crypto.inc:1.3

CVS commit: src/crypto/external/bsd/openssl/lib/libcrypto

2020-05-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat May  9 12:20:50 UTC 2020

Modified Files:
src/crypto/external/bsd/openssl/lib/libcrypto: evp.inc

Log Message:
Ensure that -DOPENSSL_CPUID_OBJ is passed when compiling AES EVP bits

This way CPUs that support AES-NI actually get detected properly ;_;

(... just one part of the puzzle)


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc

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

Modified files:

Index: src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.8 src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.9
--- src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc:1.8	Sun Sep 23 13:33:04 2018
+++ src/crypto/external/bsd/openssl/lib/libcrypto/evp.inc	Sat May  9 12:20:50 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: evp.inc,v 1.8 2018/09/23 13:33:04 christos Exp $
+#	$NetBSD: evp.inc,v 1.9 2020/05/09 12:20:50 nia Exp $
 #
 #	@(#) Copyright (c) 1995 Simon J. Gerraty
 #
@@ -85,6 +85,7 @@ EVP_AES_SRCS = e_aes.c
 
 .for cryptosrc in ${EVP_AES_SRCS}
 CPPFLAGS.${cryptosrc} += ${AESCPPFLAGS}
+CPPFLAGS.${cryptosrc} += ${CRYPTOCPPFLAGS}
 .endfor
 
 CPPFLAGS.e_aes.c += -I${OPENSSLSRC}/crypto/modes



CVS commit: src/tests/lib/libi386

2020-05-09 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May  9 09:08:41 UTC 2020

Modified Files:
src/tests/lib/libi386: t_user_ldt.c

Log Message:
A kernel without USER_LDT returns ENOSYS, not ENOTSUP.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libi386/t_user_ldt.c

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

Modified files:

Index: src/tests/lib/libi386/t_user_ldt.c
diff -u src/tests/lib/libi386/t_user_ldt.c:1.2 src/tests/lib/libi386/t_user_ldt.c:1.3
--- src/tests/lib/libi386/t_user_ldt.c:1.2	Sun Apr 26 12:13:10 2020
+++ src/tests/lib/libi386/t_user_ldt.c	Sat May  9 09:08:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_user_ldt.c,v 1.2 2020/04/26 12:13:10 maxv Exp $	*/
+/*	$NetBSD: t_user_ldt.c,v 1.3 2020/05/09 09:08:41 maxv Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@ user_ldt_detect(void)
 	int ret;
 
 	ret = i386_get_ldt(0, , 1);
-	user_ldt_supported = (ret != -1) || (errno != ENOTSUP);
+	user_ldt_supported = (ret != -1) || (errno != ENOSYS);
 }
 
 static void



CVS commit: src/sys/dev/nvmm

2020-05-09 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May  9 08:39:07 UTC 2020

Modified Files:
src/sys/dev/nvmm: nvmm.c nvmm_internal.h
src/sys/dev/nvmm/x86: nvmm_x86_vmx.c

Log Message:
On Intel CPUs, CPUID leaf 0xB, too, provides topology information, so
filter it correctly, to avoid inconsistencies if the host has SMT.

This fixes HaikuOS which fetches SMT information from there and would
panic because of the inconsistencies.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/nvmm/nvmm.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/nvmm/nvmm_internal.h
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

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

Modified files:

Index: src/sys/dev/nvmm/nvmm.c
diff -u src/sys/dev/nvmm/nvmm.c:1.27 src/sys/dev/nvmm/nvmm.c:1.28
--- src/sys/dev/nvmm/nvmm.c:1.27	Thu Apr 30 16:50:17 2020
+++ src/sys/dev/nvmm/nvmm.c	Sat May  9 08:39:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.c,v 1.27 2020/04/30 16:50:17 maxv Exp $	*/
+/*	$NetBSD: nvmm.c,v 1.28 2020/05/09 08:39:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.27 2020/04/30 16:50:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.28 2020/05/09 08:39:07 maxv Exp $");
 
 #include 
 #include 
@@ -413,6 +413,8 @@ nvmm_vcpu_create(struct nvmm_owner *owne
 
 	nvmm_vcpu_put(vcpu);
 
+	atomic_inc_uint(>ncpus);
+
 out:
 	nvmm_machine_put(mach);
 	return error;
@@ -437,6 +439,8 @@ nvmm_vcpu_destroy(struct nvmm_owner *own
 	nvmm_vcpu_free(mach, vcpu);
 	nvmm_vcpu_put(vcpu);
 
+	atomic_dec_uint(>ncpus);
+
 out:
 	nvmm_machine_put(mach);
 	return error;

Index: src/sys/dev/nvmm/nvmm_internal.h
diff -u src/sys/dev/nvmm/nvmm_internal.h:1.13 src/sys/dev/nvmm/nvmm_internal.h:1.14
--- src/sys/dev/nvmm/nvmm_internal.h:1.13	Wed Oct 23 07:01:11 2019
+++ src/sys/dev/nvmm/nvmm_internal.h	Sat May  9 08:39:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_internal.h,v 1.13 2019/10/23 07:01:11 maxv Exp $	*/
+/*	$NetBSD: nvmm_internal.h,v 1.14 2020/05/09 08:39:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -83,6 +83,7 @@ struct nvmm_machine {
 	struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
 
 	/* CPU */
+	volatile unsigned int ncpus;
 	struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
 
 	/* Implementation-specific */

Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.54 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.55
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.54	Thu Apr 30 16:56:23 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Sat May  9 08:39:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_vmx.c,v 1.54 2020/04/30 16:56:23 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_vmx.c,v 1.55 2020/05/09 08:39:07 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.54 2020/04/30 16:56:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.55 2020/05/09 08:39:07 maxv Exp $");
 
 #include 
 #include 
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1137,9 +1138,11 @@ error:
 }
 
 static void
-vmx_inkernel_handle_cpuid(struct nvmm_cpu *vcpu, uint64_t eax, uint64_t ecx)
+vmx_inkernel_handle_cpuid(struct nvmm_machine *mach, struct nvmm_cpu *vcpu,
+uint64_t eax, uint64_t ecx)
 {
 	struct vmx_cpudata *cpudata = vcpu->cpudata;
+	unsigned int ncpus;
 	uint64_t cr4;
 
 	switch (eax) {
@@ -1186,6 +1189,33 @@ vmx_inkernel_handle_cpuid(struct nvmm_cp
 		cpudata->gprs[NVMM_X64_GPR_RCX] = 0;
 		cpudata->gprs[NVMM_X64_GPR_RDX] = 0;
 		break;
+	case 0x000B:
+		switch (ecx) {
+		case 0: /* Threads */
+			cpudata->gprs[NVMM_X64_GPR_RAX] = 0;
+			cpudata->gprs[NVMM_X64_GPR_RBX] = 0;
+			cpudata->gprs[NVMM_X64_GPR_RCX] =
+			__SHIFTIN(ecx, CPUID_TOP_LVLNUM) |
+			__SHIFTIN(CPUID_TOP_LVLTYPE_SMT, CPUID_TOP_LVLTYPE);
+			cpudata->gprs[NVMM_X64_GPR_RDX] = vcpu->cpuid;
+			break;
+		case 1: /* Cores */
+			ncpus = atomic_load_relaxed(>ncpus);
+			cpudata->gprs[NVMM_X64_GPR_RAX] = ilog2(ncpus);
+			cpudata->gprs[NVMM_X64_GPR_RBX] = ncpus;
+			cpudata->gprs[NVMM_X64_GPR_RCX] =
+			__SHIFTIN(ecx, CPUID_TOP_LVLNUM) |
+			__SHIFTIN(CPUID_TOP_LVLTYPE_CORE, CPUID_TOP_LVLTYPE);
+			cpudata->gprs[NVMM_X64_GPR_RDX] = vcpu->cpuid;
+			break;
+		default:
+			cpudata->gprs[NVMM_X64_GPR_RAX] = 0;
+			cpudata->gprs[NVMM_X64_GPR_RBX] = 0;
+			cpudata->gprs[NVMM_X64_GPR_RCX] = 0; /* LVLTYPE_INVAL */
+			cpudata->gprs[NVMM_X64_GPR_RDX] = 0;
+			break;
+		}
+		break;
 	case 0x000D:
 		if (vmx_xcr0_mask == 0) {
 			break;
@@ -1267,7 +1297,7 @@ vmx_exit_cpuid(struct nvmm_machine *mach
 	cpudata->gprs[NVMM_X64_GPR_RCX] = descs[2];
 	cpudata->gprs[NVMM_X64_GPR_RDX] = descs[3];
 
-	vmx_inkernel_handle_cpuid(vcpu, eax, ecx);
+	

CVS commit: src/lib/libc/arch/hppa/sys

2020-05-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat May  9 08:25:34 UTC 2020

Modified Files:
src/lib/libc/arch/hppa/sys: __vfork14.S ptrace.S

Log Message:
No need to .import __cerror as SYS.h does it


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/arch/hppa/sys/__vfork14.S
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/hppa/sys/ptrace.S

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

Modified files:

Index: src/lib/libc/arch/hppa/sys/__vfork14.S
diff -u src/lib/libc/arch/hppa/sys/__vfork14.S:1.9 src/lib/libc/arch/hppa/sys/__vfork14.S:1.10
--- src/lib/libc/arch/hppa/sys/__vfork14.S:1.9	Tue May  5 20:43:47 2020
+++ src/lib/libc/arch/hppa/sys/__vfork14.S	Sat May  9 08:25:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: __vfork14.S,v 1.9 2020/05/05 20:43:47 skrll Exp $	*/
+/*	$NetBSD: __vfork14.S,v 1.10 2020/05/09 08:25:33 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -52,8 +52,6 @@ ENTRY(__vfork14, 0)
 	 * syscall entry code in locore.S has been modified
 	 * to do just this for the t4 register.
 	 */
-	.import	__cerror, code
-
 	copy	%rp, %t4
 	ldil	L%SYSCALLGATE, %r1
 	ble	4(%sr2, %r1)

Index: src/lib/libc/arch/hppa/sys/ptrace.S
diff -u src/lib/libc/arch/hppa/sys/ptrace.S:1.6 src/lib/libc/arch/hppa/sys/ptrace.S:1.7
--- src/lib/libc/arch/hppa/sys/ptrace.S:1.6	Mon Apr 28 20:22:56 2008
+++ src/lib/libc/arch/hppa/sys/ptrace.S	Sat May  9 08:25:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.S,v 1.6 2008/04/28 20:22:56 martin Exp $	*/
+/*	$NetBSD: ptrace.S,v 1.7 2020/05/09 08:25:33 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -32,8 +32,6 @@
 #include 
 #include "SYS.h"
 
-	.import __cerror, code
-
 /*
  * int ptrace(int request, pid_t pid, void * addr, int data);
  */



CVS commit: [netbsd-9] src/doc

2020-05-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat May  9 08:21:36 UTC 2020

Modified Files:
src/doc [netbsd-9]: CHANGES-9.1

Log Message:
Tickets #896 and #897


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.54 -r1.1.2.55 src/doc/CHANGES-9.1

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

Modified files:

Index: src/doc/CHANGES-9.1
diff -u src/doc/CHANGES-9.1:1.1.2.54 src/doc/CHANGES-9.1:1.1.2.55
--- src/doc/CHANGES-9.1:1.1.2.54	Thu May  7 18:27:19 2020
+++ src/doc/CHANGES-9.1	Sat May  9 08:21:36 2020
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-9.1,v 1.1.2.54 2020/05/07 18:27:19 martin Exp $
+# $NetBSD: CHANGES-9.1,v 1.1.2.55 2020/05/09 08:21:36 martin Exp $
 
 A complete list of changes from the NetBSD 9.0 release to the NetBSD 9.1
 release:
@@ -2496,3 +2496,17 @@ sys/arch/arm/cortex/gic_v2m.h			1.3
 	Do not store a pointer to the passed in struct pci_attach_args.
 	[jmcneill, ticket #895]
 
+sys/dev/usb/if_cdce.c1.71
+
+	cdce(4): PR 55240: search the descriptors of the appropriate
+	interface to ensure correct match.
+	[skrll, ticket #896]
+
+external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c 1.65
+external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c 1.33
+
+	Operation zfs_znode.c::zfs_zget_cleaner() depends on zil_commit() as
+	a barrier to guarantee the znode cannot be freed before its log entries
+	are resolved.
+	[hannken, ticket #897]
+



CVS commit: [netbsd-9] src/external/cddl/osnet/dist/uts/common/fs/zfs

2020-05-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat May  9 08:20:34 UTC 2020

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs [netbsd-9]: zfs_vnops.c
zfs_znode.c

Log Message:
Pull up following revision(s) (requested by hannken in ticket #897):

external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c: revision 1.33
external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c: revision 1.65

Revert Rev. 1.63 and add a comment why we have to zil_commit() here:

Operation zfs_znode.c::zfs_zget_cleaner() depends on this
zil_commit() as a barrier to guarantee the znode cannot
get freed before its log entries are resolved.

Operation zfs_zget_cleaner() cannot fail, comment and add assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.7 -r1.50.2.8 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
cvs rdiff -u -r1.29 -r1.29.2.1 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.50.2.7 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.50.2.8
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c:1.50.2.7	Mon Mar  9 09:52:00 2020
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c	Sat May  9 08:20:34 2020
@@ -5836,11 +5836,16 @@ zfs_netbsd_reclaim(void *v)
 			zp->z_atime_dirty = 0;
 			dmu_tx_commit(tx);
 		}
-
-		if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
-			zil_commit(zfsvfs->z_log, zp->z_id);
 	}
 
+	/*
+	 * Operation zfs_znode.c::zfs_zget_cleaner() depends on this
+	 * zil_commit() as a barrier to guarantee the znode cannot
+	 * get freed before its log entries are resolved.
+	 */
+	if (zfsvfs->z_log)
+		zil_commit(zfsvfs->z_log, zp->z_id);
+
 	if (zp->z_sa_hdl == NULL)
 		zfs_znode_free(zp);
 	else

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.29 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.29.2.1
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c:1.29	Mon Jun 17 08:08:50 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c	Sat May  9 08:20:34 2020
@@ -1288,6 +1288,12 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_
 	return error;
 }
 
+/*
+ * Get a known cached znode, to be used from zil_commit()->zfs_get_data()
+ * to resolve log entries.  Doesn't take a reference, will never fail and
+ * depends on zfs_vnops.c::zfs_netbsd_reclaim() running a zil_commit()
+ * before the znode gets freed.
+ */
 int
 zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
 {
@@ -1295,31 +1301,26 @@ zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint6
 	sa_handle_t *hdl;
 	dmu_object_info_t doi;
 	znode_t *zp;
-	int err;
 
 	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
 
-	err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, );
-	if (err) {
-		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
-		return (SET_ERROR(err));
-	}
+	VERIFY(0 == sa_buf_hold(zfsvfs->z_os, obj_num, NULL, ));
 
 	dmu_object_info_from_db(db, );
-	if (doi.doi_bonus_type != DMU_OT_SA &&
-	(doi.doi_bonus_type != DMU_OT_ZNODE ||
+	ASSERT(doi.doi_bonus_type == DMU_OT_SA ||
 	(doi.doi_bonus_type == DMU_OT_ZNODE &&
-	doi.doi_bonus_size < sizeof (znode_phys_t {
-		sa_buf_rele(db, NULL);
-		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
-		return (SET_ERROR(EINVAL));
-	}
+	doi.doi_bonus_size >= sizeof (znode_phys_t)));
+
 	hdl = dmu_buf_get_user(db);
 	ASSERT3P(hdl, !=, NULL);
+
 	zp = sa_get_userdata(hdl);
 	ASSERT3U(zp->z_id, ==, obj_num);
+
 	sa_buf_rele(db, NULL);
+
 	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
+
 	*zpp = zp;
 	return (0);
 }



CVS commit: [netbsd-9] src/sys/dev/usb

2020-05-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat May  9 08:16:54 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: if_cdce.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #896):

sys/dev/usb/if_cdce.c: revision 1.71

Search the descriptors of the appropriate interface to ensure correct
match.

PR kern/55240 cdce(4) error "no data interface" when ECM USB IF are
preceded by ACM USB IF


To generate a diff of this commit:
cvs rdiff -u -r1.53.2.1 -r1.53.2.2 src/sys/dev/usb/if_cdce.c

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

Modified files:

Index: src/sys/dev/usb/if_cdce.c
diff -u src/sys/dev/usb/if_cdce.c:1.53.2.1 src/sys/dev/usb/if_cdce.c:1.53.2.2
--- src/sys/dev/usb/if_cdce.c:1.53.2.1	Sun Sep  1 13:00:36 2019
+++ src/sys/dev/usb/if_cdce.c	Sat May  9 08:16:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_cdce.c,v 1.53.2.1 2019/09/01 13:00:36 martin Exp $ */
+/*	$NetBSD: if_cdce.c,v 1.53.2.2 2020/05/09 08:16:54 martin Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul 
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.53.2.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.53.2.2 2020/05/09 08:16:54 martin Exp $");
 
 #include 
 
@@ -145,8 +145,9 @@ cdce_attach(device_t parent, device_t se
 	if (un->un_flags & CDCE_NO_UNION)
 		un->un_iface = uiaa->uiaa_iface;
 	else {
-		ud = (const usb_cdc_union_descriptor_t *)usb_find_desc(un->un_udev,
-		UDESC_CS_INTERFACE, UDESCSUB_CDC_UNION);
+		ud = (const usb_cdc_union_descriptor_t *)usb_find_desc_if(un->un_udev,
+		UDESC_CS_INTERFACE, UDESCSUB_CDC_UNION,
+		usbd_get_interface_descriptor(uiaa->uiaa_iface));
 		if (ud == NULL) {
 			aprint_error_dev(self, "no union descriptor\n");
 			return;
@@ -236,8 +237,9 @@ cdce_attach(device_t parent, device_t se
 		return;
 	}
 
-	ue = (const usb_cdc_ethernet_descriptor_t *)usb_find_desc(dev,
-	UDESC_CS_INTERFACE, UDESCSUB_CDC_ENF);
+	ue = (const usb_cdc_ethernet_descriptor_t *)usb_find_desc_if(dev,
+	UDESC_CS_INTERFACE, UDESCSUB_CDC_ENF,
+	usbd_get_interface_descriptor(uiaa->uiaa_iface));
 	if (!ue || usbd_get_string(dev, ue->iMacAddress, eaddr_str) ||
 	ether_aton_r(un->un_eaddr, sizeof(un->un_eaddr), eaddr_str)) {
 		aprint_normal_dev(self, "faking address\n");



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

2020-05-09 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat May  9 08:01:38 UTC 2020

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

Log Message:
Also set x86_delay to xen_delay, unbreaks PVH


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/xen/xen/hypervisor.c

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

Modified files:

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.83 src/sys/arch/xen/xen/hypervisor.c:1.84
--- src/sys/arch/xen/xen/hypervisor.c:1.83	Fri May  8 17:28:33 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Sat May  9 08:01:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.84 2020/05/09 08:01:38 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.83 2020/05/08 17:28:33 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.84 2020/05/09 08:01:38 bouyer Exp $");
 
 #include 
 #include 
@@ -258,7 +258,7 @@ init_xen_early(void)
 		printk(
 		"Xen HVM: Unable to register HYPERVISOR_shared_info %d\n", err);
 	}
-	delay_func = xen_delay;
+	delay_func = x86_delay = xen_delay;
 	x86_initclock_func = xen_initclocks;
 	x86_cpu_initclock_func = xen_cpu_initclocks;
 	if (hvm_start_info->cmdline_paddr != 0) {
@@ -434,7 +434,7 @@ xen_hvm_init(void)
 	xen_start_info.console.domU.evtchn = xen_hvm_param.value;
 
 
-	delay_func = xen_delay;
+	delay_func = x86_delay = xen_delay;
 	x86_initclock_func = xen_initclocks;
 	x86_cpu_initclock_func = xen_cpu_initclocks;
 



CVS commit: src/sys/kern

2020-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  9 06:12:32 UTC 2020

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

Log Message:
Prune dead branch.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/kern/kern_entropy.c

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

Modified files:

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.17 src/sys/kern/kern_entropy.c:1.18
--- src/sys/kern/kern_entropy.c:1.17	Fri May  8 15:54:11 2020
+++ src/sys/kern/kern_entropy.c	Sat May  9 06:12:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.17 2020/05/08 15:54:11 riastradh Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.18 2020/05/09 06:12:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.17 2020/05/08 15:54:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.18 2020/05/09 06:12:32 riastradh Exp $");
 
 #include 
 #include 
@@ -670,7 +670,7 @@ entropy_account_cpu(struct entropy_cpu *
 		/* Notify waiters that we now have full entropy.  */
 		entropy_notify();
 		entropy_immediate_evcnt.ev_count++;
-	} else if (ec->ec_pending) {
+	} else {
 		/* Record how much we can add to the global pool.  */
 		diff = MIN(ec->ec_pending, ENTROPY_CAPACITY*NBBY - E->pending);
 		E->pending += diff;