CVS commit: src/doc

2020-06-29 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue Jun 30 05:19:19 UTC 2020

Modified Files:
src/doc: 3RDPARTY

Log Message:
Lua 5.4.0 is out


To generate a diff of this commit:
cvs rdiff -u -r1.1731 -r1.1732 src/doc/3RDPARTY

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1731 src/doc/3RDPARTY:1.1732
--- src/doc/3RDPARTY:1.1731	Mon Jun 15 17:04:03 2020
+++ src/doc/3RDPARTY	Tue Jun 30 05:19:19 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1731 2020/06/15 17:04:03 roy Exp $
+#	$NetBSD: 3RDPARTY,v 1.1732 2020/06/30 05:19:19 sevan Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -832,10 +832,10 @@ into inetd. The provided libwrap2netbsd 
 
 Package:	Lua
 Version:	Lua 5.3.5
-Current Vers:	Lua 5.3.5
+Current Vers:	Lua 5.4.0
 Maintainer:	PUC Rio
 Home Page:	http://www.lua.org/
-Date:		2020-06-13
+Date:		2020-06-30
 Mailing List:
 Responsible:	mbalmer, lneto, salazar, alnsn
 License:	MIT



CVS commit: src/tests/dev/cgd

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 30 04:17:31 UTC 2020

Modified Files:
src/tests/dev/cgd: t_cgd_adiantum.c

Log Message:
Missed a spot -- one more 32-bit sign-compare issue.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/dev/cgd/t_cgd_adiantum.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/dev/cgd/t_cgd_adiantum.c
diff -u src/tests/dev/cgd/t_cgd_adiantum.c:1.2 src/tests/dev/cgd/t_cgd_adiantum.c:1.3
--- src/tests/dev/cgd/t_cgd_adiantum.c:1.2	Tue Jun 30 04:15:46 2020
+++ src/tests/dev/cgd/t_cgd_adiantum.c	Tue Jun 30 04:17:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cgd_adiantum.c,v 1.2 2020/06/30 04:15:46 riastradh Exp $	*/
+/*	$NetBSD: t_cgd_adiantum.c,v 1.3 2020/06/30 04:17:31 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -348,7 +348,7 @@ ATF_TC_BODY(cgd_adiantum, tc)
 		RL(nwrit = rump_sys_pwrite(cgdfd, C[i].ptxt, C[i].secsize,
 			C[i].blkno * C[i].secsize));
 		RL(unconfigure_cgd(cgdfd));
-		if (nwrit != C[i].secsize) {
+		if ((size_t)nwrit != C[i].secsize) {
 			atf_tc_fail_nonfatal("truncated write: %zd != %u",
 			nwrit, C[i].secsize);
 			continue;



CVS commit: src/tests/dev/cgd

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 30 04:15:46 UTC 2020

Modified Files:
src/tests/dev/cgd: t_cgd_adiantum.c

Log Message:
Fix sign-compare issue on 32-bit systems.

Built fine on amd64, where all unsigned values are representable in
ssize_t, but I didn't try building on i386, where they're not.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/dev/cgd/t_cgd_adiantum.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/dev/cgd/t_cgd_adiantum.c
diff -u src/tests/dev/cgd/t_cgd_adiantum.c:1.1 src/tests/dev/cgd/t_cgd_adiantum.c:1.2
--- src/tests/dev/cgd/t_cgd_adiantum.c:1.1	Mon Jun 29 23:44:01 2020
+++ src/tests/dev/cgd/t_cgd_adiantum.c	Tue Jun 30 04:15:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cgd_adiantum.c,v 1.1 2020/06/29 23:44:01 riastradh Exp $	*/
+/*	$NetBSD: t_cgd_adiantum.c,v 1.2 2020/06/30 04:15:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -357,7 +357,7 @@ ATF_TC_BODY(cgd_adiantum, tc)
 		/* read the ciphertext out from the underlying file */
 		RL(nread = pread(dkfd, buf, C[i].secsize,
 			C[i].blkno * C[i].secsize));
-		if (nread != C[i].secsize) {
+		if ((size_t)nread != C[i].secsize) {
 			atf_tc_fail_nonfatal("truncated read: %zd != %u",
 			nread, C[i].secsize);
 			continue;
@@ -375,7 +375,7 @@ ATF_TC_BODY(cgd_adiantum, tc)
 		RL(nread = rump_sys_pread(cgdfd, buf, C[i].secsize,
 			C[i].blkno * C[i].secsize));
 		RL(unconfigure_cgd(cgdfd));
-		if (nread != C[i].secsize) {
+		if ((size_t)nread != C[i].secsize) {
 			atf_tc_fail_nonfatal("truncated read: %zd != %u",
 			nread, C[i].secsize);
 			continue;



CVS commit: src/sys

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 30 04:14:56 UTC 2020

Modified Files:
src/sys/netipsec: files.netipsec xform_esp.c
src/sys/opencrypto: cryptodev.c cryptosoft_xform.c xform.c xform.h

Log Message:
Rename enc_xform_rijndael128 -> enc_xform_aes.

Update netipsec dependency.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/netipsec/files.netipsec
cvs rdiff -u -r1.99 -r1.100 src/sys/netipsec/xform_esp.c
cvs rdiff -u -r1.105 -r1.106 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.29 -r1.30 src/sys/opencrypto/cryptosoft_xform.c
cvs rdiff -u -r1.30 -r1.31 src/sys/opencrypto/xform.c
cvs rdiff -u -r1.20 -r1.21 src/sys/opencrypto/xform.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/netipsec/files.netipsec
diff -u src/sys/netipsec/files.netipsec:1.14 src/sys/netipsec/files.netipsec:1.15
--- src/sys/netipsec/files.netipsec:1.14	Wed Apr 22 09:15:40 2020
+++ src/sys/netipsec/files.netipsec	Tue Jun 30 04:14:55 2020
@@ -1,7 +1,7 @@
-#	$Id: files.netipsec,v 1.14 2020/04/22 09:15:40 rin Exp $
+#	$Id: files.netipsec,v 1.15 2020/06/30 04:14:55 riastradh Exp $
 #
 #
-defflag opt_ipsec.h	IPSEC:	opencrypto, rijndael
+defflag opt_ipsec.h	IPSEC:	opencrypto, aes
 defflag opt_ipsec.h	IPSEC_DEBUG
 defflag opt_ipsec.h	IPSEC_TX_TOS_CLEAR
 

Index: src/sys/netipsec/xform_esp.c
diff -u src/sys/netipsec/xform_esp.c:1.99 src/sys/netipsec/xform_esp.c:1.100
--- src/sys/netipsec/xform_esp.c:1.99	Fri Nov  1 04:23:21 2019
+++ src/sys/netipsec/xform_esp.c	Tue Jun 30 04:14:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xform_esp.c,v 1.99 2019/11/01 04:23:21 knakahara Exp $	*/
+/*	$NetBSD: xform_esp.c,v 1.100 2020/06/30 04:14:55 riastradh Exp $	*/
 /*	$FreeBSD: xform_esp.c,v 1.2.2.1 2003/01/24 05:11:36 sam Exp $	*/
 /*	$OpenBSD: ip_esp.c,v 1.69 2001/06/26 06:18:59 angelos Exp $ */
 
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.99 2019/11/01 04:23:21 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.100 2020/06/30 04:14:55 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -112,7 +112,7 @@ esp_algorithm_lookup(int alg)
 	case SADB_EALG_3DESCBC:
 		return _xform_3des;
 	case SADB_X_EALG_AES:
-		return _xform_rijndael128;
+		return _xform_aes;
 	case SADB_X_EALG_BLOWFISHCBC:
 		return _xform_blf;
 	case SADB_X_EALG_CAST128CBC:
@@ -1061,7 +1061,7 @@ esp_attach(void)
 	esp_max_ivlen = 0;
 	MAXIV(enc_xform_des);		/* SADB_EALG_DESCBC */
 	MAXIV(enc_xform_3des);		/* SADB_EALG_3DESCBC */
-	MAXIV(enc_xform_rijndael128);	/* SADB_X_EALG_AES */
+	MAXIV(enc_xform_aes);		/* SADB_X_EALG_AES */
 	MAXIV(enc_xform_blf);		/* SADB_X_EALG_BLOWFISHCBC */
 	MAXIV(enc_xform_cast5);		/* SADB_X_EALG_CAST128CBC */
 	MAXIV(enc_xform_skipjack);	/* SADB_X_EALG_SKIPJACK */

Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.105 src/sys/opencrypto/cryptodev.c:1.106
--- src/sys/opencrypto/cryptodev.c:1.105	Mon Apr 13 00:27:17 2020
+++ src/sys/opencrypto/cryptodev.c	Tue Jun 30 04:14:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.105 2020/04/13 00:27:17 chs Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.106 2020/06/30 04:14:55 riastradh Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $	*/
 /*	$OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $	*/
 
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.105 2020/04/13 00:27:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.106 2020/06/30 04:14:55 riastradh Exp $");
 
 #include 
 #include 
@@ -1576,7 +1576,7 @@ cryptodev_session(struct fcrypt *fcr, st
 		txform = _xform_skipjack;
 		break;
 	case CRYPTO_AES_CBC:
-		txform = _xform_rijndael128;
+		txform = _xform_aes;
 		break;
 	case CRYPTO_CAMELLIA_CBC:
 		txform = _xform_camellia;

Index: src/sys/opencrypto/cryptosoft_xform.c
diff -u src/sys/opencrypto/cryptosoft_xform.c:1.29 src/sys/opencrypto/cryptosoft_xform.c:1.30
--- src/sys/opencrypto/cryptosoft_xform.c:1.29	Mon Jun 29 23:34:48 2020
+++ src/sys/opencrypto/cryptosoft_xform.c	Tue Jun 30 04:14:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft_xform.c,v 1.29 2020/06/29 23:34:48 riastradh Exp $ */
+/*	$NetBSD: cryptosoft_xform.c,v 1.30 2020/06/30 04:14:55 riastradh Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $	*/
 
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.29 2020/06/29 23:34:48 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.30 2020/06/30 04:14:55 riastradh Exp $");
 
 #include 
 #include 
@@ -206,7 +206,7 @@ static const struct swcr_enc_xform swcr_
 };
 
 static const struct swcr_enc_xform swcr_enc_xform_aes = {
-	_xform_rijndael128,
+	_xform_aes,
 	aes_encrypt,
 	aes_decrypt,
 	aes_setkey,

Index: 

CVS commit: src/doc

2020-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 30 00:26:12 UTC 2020

Modified Files:
src/doc: CHANGES

Log Message:
Note kernel AES rework.


To generate a diff of this commit:
cvs rdiff -u -r1.2705 -r1.2706 src/doc/CHANGES

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
diff -u src/doc/CHANGES:1.2705 src/doc/CHANGES:1.2706
--- src/doc/CHANGES:1.2705	Sun Jun 21 23:53:59 2020
+++ src/doc/CHANGES	Tue Jun 30 00:26:12 2020
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2705 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2706 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -224,3 +224,19 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	evbarm: Add support for loading modules with the bootloader.
 		[jmcneill 20200221]
 	evbarm: Added boot.cfg support to efiboot [jmcneill 20200211]
+	kernel: Remove all variable-time AES and replace it by constant-time
+		aes_ct from BearSSL or a CPU-dependent implementation,
+		selected at boot time according to CPU capabilities.
+		[riastradh 20200629]
+	amd64: Add support for AES-NI in kernel. [riastradh 20200629]
+	x86: Add support for bitsliced AES with SSE2 in kernel.
+		[riastradh 20200629]
+	x86: Add support for permutation-based AES (vpaes) with SSSE3 in
+		kernel. [riastradh 20200629]
+	x86: Add support for VIA ACE AES in kernel (not just via opencrypto).
+		[riastradh 20200629]
+	arm: Add support for ARMv8.0-AES in kernel. [riastradh 20200629]
+	arm: Add support for permutation-based AES (vpaes) with ARM NEON in
+		kernel. [riastradh 20200629]
+	cgd(4): Add support for Adiantum cipher, providing much better software
+		performance than AES-CBC or AES-XTS. [riastradh 20200629]



CVS commit: src/sys/arch

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

Modified Files:
src/sys/arch/amd64/conf: ALL
src/sys/arch/x86/x86: via_padlock.c

Log Message:
Make padlock(4) compile on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/via_padlock.c

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

Modified files:

Index: src/sys/arch/amd64/conf/ALL
diff -u src/sys/arch/amd64/conf/ALL:1.154 src/sys/arch/amd64/conf/ALL:1.155
--- src/sys/arch/amd64/conf/ALL:1.154	Wed Jun 24 03:38:54 2020
+++ src/sys/arch/amd64/conf/ALL	Mon Jun 29 23:58:44 2020
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.154 2020/06/24 03:38:54 thorpej Exp $
+# $NetBSD: ALL,v 1.155 2020/06/29 23:58:44 riastradh Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.154 $"
+#ident		"ALL-$Revision: 1.155 $"
 
 maxusers	64		# estimated number of users
 
@@ -35,7 +35,7 @@ acpicpu*	at cpu?		# ACPI CPU (including 
 coretemp*	at cpu?		# Intel on-die thermal sensor
 est0		at cpu0		# Intel Enhanced SpeedStep (non-ACPI)
 odcm0		at cpu0		# On-demand clock modulation
-#padlock0	at cpu0		# VIA PadLock
+padlock0	at cpu0		# VIA PadLock
 powernow0	at cpu0		# AMD PowerNow! and Cool'n'Quiet (non-ACPI)
 viac7temp*	at cpu?		# VIA C7 temperature sensor
 vmt0		at cpu0		# VMware Tools

Index: src/sys/arch/x86/x86/via_padlock.c
diff -u src/sys/arch/x86/x86/via_padlock.c:1.30 src/sys/arch/x86/x86/via_padlock.c:1.31
--- src/sys/arch/x86/x86/via_padlock.c:1.30	Mon Jun 29 23:38:02 2020
+++ src/sys/arch/x86/x86/via_padlock.c	Mon Jun 29 23:58:44 2020
@@ -1,5 +1,5 @@
 /*	$OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $	*/
-/*	$NetBSD: via_padlock.c,v 1.30 2020/06/29 23:38:02 riastradh Exp $ */
+/*	$NetBSD: via_padlock.c,v 1.31 2020/06/29 23:58:44 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2003 Jason Wright
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.30 2020/06/29 23:38:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.31 2020/06/29 23:58:44 riastradh Exp $");
 
 #include 
 #include 
@@ -351,7 +351,7 @@ via_padlock_cbc(void *cw, void *src, voi
 	lcr0(cr0 & ~(CR0_EM|CR0_TS));
 
 	/* Do the deed */
-	__asm __volatile("pushfl; popfl");	/* force key reload */
+	__asm __volatile("pushf; popf");	/* force key reload */
 	__asm __volatile(".byte 0xf3, 0x0f, 0xa7, 0xd0" : /* rep xcrypt-cbc */
 			: "a" (iv), "b" (key), "c" (rep), "d" (cw), "S" (src), "D" (dst)
 			: "memory", "cc");



CVS commit: src/sys/crypto/aes/arch/arm

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

Modified Files:
src/sys/crypto/aes/arch/arm: aes_neon.c files.aesneon
Added Files:
src/sys/crypto/aes/arch/arm: aes_neon_32.S

Log Message:
Provide hand-written AES NEON assembly for arm32.

gcc does a lousy job at compiling 128-bit NEON intrinsics on arm32;
hand-writing it made it about 12x faster, by avoiding a zillion loads
and stores to spill everything and the kitchen sink onto the stack.
(But gcc does fine on aarch64, presumably because it has twice as
many registers and doesn't have to deal with q2=d4/d5 overlapping.)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/arm/aes_neon.c \
src/sys/crypto/aes/arch/arm/files.aesneon
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/arm/aes_neon_32.S

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

Modified files:

Index: src/sys/crypto/aes/arch/arm/aes_neon.c
diff -u src/sys/crypto/aes/arch/arm/aes_neon.c:1.1 src/sys/crypto/aes/arch/arm/aes_neon.c:1.2
--- src/sys/crypto/aes/arch/arm/aes_neon.c:1.1	Mon Jun 29 23:56:31 2020
+++ src/sys/crypto/aes/arch/arm/aes_neon.c	Mon Jun 29 23:57:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_neon.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $	*/
+/*	$NetBSD: aes_neon.c,v 1.2 2020/06/29 23:57:56 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aes_neon.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_neon.c,v 1.2 2020/06/29 23:57:56 riastradh Exp $");
 
 #include 
 
@@ -47,6 +47,12 @@ __KERNEL_RCSID(1, "$NetBSD: aes_neon.c,v
 
 #include "aes_neon_impl.h"
 
+#ifdef __aarch64__
+#define	__aarch64_used
+#else
+#define	__aarch64_used	__unused
+#endif
+
 static const uint8x16_t
 mc_forward[4] = {
 	{0x01,0x02,0x03,0x00,0x05,0x06,0x07,0x04,
@@ -58,7 +64,7 @@ mc_forward[4] = {
 	{0x0D,0x0E,0x0F,0x0C,0x01,0x02,0x03,0x00,
 	 0x05,0x06,0x07,0x04,0x09,0x0A,0x0B,0x08},
 },
-mc_backward[4] = {
+mc_backward[4] __aarch64_used = {
 	{0x03,0x00,0x01,0x02,0x07,0x04,0x05,0x06,
 	 0x0B,0x08,0x09,0x0A,0x0F,0x0C,0x0D,0x0E},
 	{0x0F,0x0C,0x0D,0x0E,0x03,0x00,0x01,0x02,
@@ -68,7 +74,7 @@ mc_backward[4] = {
 	{0x07,0x04,0x05,0x06,0x0B,0x08,0x09,0x0A,
 	 0x0F,0x0C,0x0D,0x0E,0x03,0x00,0x01,0x02},
 },
-ipt[2] = {
+ipt[2] __aarch64_used = {
 	{0x00,0x70,0x2A,0x5A,0x98,0xE8,0xB2,0xC2,
 	 0x08,0x78,0x22,0x52,0x90,0xE0,0xBA,0xCA},
 	{0x00,0x4D,0x7C,0x31,0x7D,0x30,0x01,0x4C,
@@ -80,55 +86,55 @@ opt[2] = {
 	{0x00,0xEC,0xBC,0x50,0x51,0xBD,0xED,0x01,
 	 0xE0,0x0C,0x5C,0xB0,0xB1,0x5D,0x0D,0xE1},
 },
-dipt[2] = {
+dipt[2] __aarch64_used = {
 	{0x00,0x5F,0x54,0x0B,0x04,0x5B,0x50,0x0F,
 	 0x1A,0x45,0x4E,0x11,0x1E,0x41,0x4A,0x15},
 	{0x00,0x65,0x05,0x60,0xE6,0x83,0xE3,0x86,
 	 0x94,0xF1,0x91,0xF4,0x72,0x17,0x77,0x12},
 },
-sb1[2] = {
+sb1[2] __aarch64_used = {
 	{0x00,0x3E,0x50,0xCB,0x8F,0xE1,0x9B,0xB1,
 	 0x44,0xF5,0x2A,0x14,0x6E,0x7A,0xDF,0xA5},
 	{0x00,0x23,0xE2,0xFA,0x15,0xD4,0x18,0x36,
 	 0xEF,0xD9,0x2E,0x0D,0xC1,0xCC,0xF7,0x3B},
 },
-sb2[2] = {
+sb2[2] __aarch64_used = {
 	{0x00,0x24,0x71,0x0B,0xC6,0x93,0x7A,0xE2,
 	 0xCD,0x2F,0x98,0xBC,0x55,0xE9,0xB7,0x5E},
 	{0x00,0x29,0xE1,0x0A,0x40,0x88,0xEB,0x69,
 	 0x4A,0x23,0x82,0xAB,0xC8,0x63,0xA1,0xC2},
 },
-sbo[2] = {
+sbo[2] __aarch64_used = {
 	{0x00,0xC7,0xBD,0x6F,0x17,0x6D,0xD2,0xD0,
 	 0x78,0xA8,0x02,0xC5,0x7A,0xBF,0xAA,0x15},
 	{0x00,0x6A,0xBB,0x5F,0xA5,0x74,0xE4,0xCF,
 	 0xFA,0x35,0x2B,0x41,0xD1,0x90,0x1E,0x8E},
 },
-dsb9[2] = {
+dsb9[2] __aarch64_used = {
 	{0x00,0xD6,0x86,0x9A,0x53,0x03,0x1C,0x85,
 	 0xC9,0x4C,0x99,0x4F,0x50,0x1F,0xD5,0xCA},
 	{0x00,0x49,0xD7,0xEC,0x89,0x17,0x3B,0xC0,
 	 0x65,0xA5,0xFB,0xB2,0x9E,0x2C,0x5E,0x72},
 },
-dsbd[2] = {
+dsbd[2] __aarch64_used = {
 	{0x00,0xA2,0xB1,0xE6,0xDF,0xCC,0x57,0x7D,
 	 0x39,0x44,0x2A,0x88,0x13,0x9B,0x6E,0xF5},
 	{0x00,0xCB,0xC6,0x24,0xF7,0xFA,0xE2,0x3C,
 	 0xD3,0xEF,0xDE,0x15,0x0D,0x18,0x31,0x29},
 },
-dsbb[2] = {
+dsbb[2] __aarch64_used = {
 	{0x00,0x42,0xB4,0x96,0x92,0x64,0x22,0xD0,
 	 0x04,0xD4,0xF2,0xB0,0xF6,0x46,0x26,0x60},
 	{0x00,0x67,0x59,0xCD,0xA6,0x98,0x94,0xC1,
 	 0x6B,0xAA,0x55,0x32,0x3E,0x0C,0xFF,0xF3},
 },
-dsbe[2] = {
+dsbe[2] __aarch64_used = {
 	{0x00,0xD0,0xD4,0x26,0x96,0x92,0xF2,0x46,
 	 0xB0,0xF6,0xB4,0x64,0x04,0x60,0x42,0x22},
 	{0x00,0xC1,0xAA,0xFF,0xCD,0xA6,0x55,0x0C,
 	 0x32,0x3E,0x59,0x98,0x6B,0xF3,0x67,0x94},
 },
-dsbo[2] = {
+dsbo[2] __aarch64_used = {
 	{0x00,0x40,0xF9,0x7E,0x53,0xEA,0x87,0x13,
 	 0x2D,0x3E,0x94,0xD4,0xB9,0x6D,0xAA,0xC7},
 	{0x00,0x1D,0x44,0x93,0x0F,0x56,0xD7,0x12,
@@ -164,7 +170,7 @@ deskew[2] = {
 	{0x00,0x69,0xEA,0x83,0xDC,0xB5,0x36,0x5F,
 	 0x77,0x1E,0x9D,0xF4,0xAB,0xC2,0x41,0x28},
 },
-sr[4] = {
+sr[4] __aarch64_used = {
 	{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
 	 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
 	{0x00,0x05,0x0A,0x0F,0x04,0x09,0x0E,0x03,
@@ -533,6 +539,14 @@ 

CVS commit: src/sys

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

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c
src/sys/arch/aarch64/conf: files.aarch64
src/sys/arch/arm/conf: files.arm
src/sys/arch/arm/vfp: vfp_init.c
Added Files:
src/sys/crypto/aes/arch/arm: aes_neon.c aes_neon.h aes_neon_impl.c
aes_neon_impl.h aes_neon_subr.c arm_neon.h files.aesneon

Log Message:
New permutation-based AES implementation using ARM NEON.

Also derived from Mike Hamburg's public-domain vpaes code.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/aarch64/aarch64/cpu.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/aarch64/conf/files.aarch64
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/arm/conf/files.arm
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/arm/vfp/vfp_init.c
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/arm/aes_neon.c \
src/sys/crypto/aes/arch/arm/aes_neon.h \
src/sys/crypto/aes/arch/arm/aes_neon_impl.c \
src/sys/crypto/aes/arch/arm/aes_neon_impl.h \
src/sys/crypto/aes/arch/arm/aes_neon_subr.c \
src/sys/crypto/aes/arch/arm/arm_neon.h \
src/sys/crypto/aes/arch/arm/files.aesneon

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.49 src/sys/arch/aarch64/aarch64/cpu.c:1.50
--- src/sys/arch/aarch64/aarch64/cpu.c:1.49	Mon Jun 29 23:31:41 2020
+++ src/sys/arch/aarch64/aarch64/cpu.c	Mon Jun 29 23:56:30 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.49 2020/06/29 23:31:41 riastradh Exp $ */
+/* $NetBSD: cpu.c,v 1.50 2020/06/29 23:56:30 riastradh Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.49 2020/06/29 23:31:41 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.50 2020/06/29 23:56:30 riastradh Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -45,6 +45,7 @@ __KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.49
 #include 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -601,16 +602,24 @@ cpu_setup_aes(device_t dv, struct cpu_in
 {
 	struct aarch64_sysctl_cpu_id *id = >ci_id;
 
-	/* Verify that it is supported.  */
+	/* Check for ARMv8.0-AES support.  */
 	switch (__SHIFTOUT(id->ac_aa64isar0, ID_AA64ISAR0_EL1_AES)) {
 	case ID_AA64ISAR0_EL1_AES_AES:
 	case ID_AA64ISAR0_EL1_AES_PMUL:
-		break;
-	default:
+		aes_md_init(_armv8_impl);
 		return;
+	default:
+		break;
 	}
 
-	aes_md_init(_armv8_impl);
+	/* Failing that, check for SIMD support.  */
+	switch (__SHIFTOUT(id->ac_aa64pfr0, ID_AA64PFR0_EL1_ADVSIMD)) {
+	case ID_AA64PFR0_EL1_ADV_SIMD_IMPL:
+		aes_md_init(_neon_impl);
+		return;
+	default:
+		break;
+	}
 }
 
 #ifdef MULTIPROCESSOR

Index: src/sys/arch/aarch64/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.23 src/sys/arch/aarch64/conf/files.aarch64:1.24
--- src/sys/arch/aarch64/conf/files.aarch64:1.23	Mon Jun 29 23:31:41 2020
+++ src/sys/arch/aarch64/conf/files.aarch64	Mon Jun 29 23:56:30 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.23 2020/06/29 23:31:41 riastradh Exp $
+#	$NetBSD: files.aarch64,v 1.24 2020/06/29 23:56:30 riastradh Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -141,3 +141,6 @@ file	dev/tprof/tprof_armv8.c			tprof	nee
 
 # ARMv8.0-AES
 include "crypto/aes/arch/arm/files.aesarmv8"
+
+# vpaes with ARM NEON
+include "crypto/aes/arch/arm/files.aesneon"

Index: src/sys/arch/arm/conf/files.arm
diff -u src/sys/arch/arm/conf/files.arm:1.157 src/sys/arch/arm/conf/files.arm:1.158
--- src/sys/arch/arm/conf/files.arm:1.157	Sat Apr 18 11:00:38 2020
+++ src/sys/arch/arm/conf/files.arm	Mon Jun 29 23:56:31 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.arm,v 1.157 2020/04/18 11:00:38 skrll Exp $
+#	$NetBSD: files.arm,v 1.158 2020/06/29 23:56:31 riastradh Exp $
 
 # temporary define to allow easy moving to ../arch/arm/arm32
 defflagARM32
@@ -262,3 +262,7 @@ file	arch/arm/arm/linux_trap.c		compat_l
 
 # profiling support
 file	dev/tprof/tprof_armv7.c			tprof
+
+# vpaes with ARM NEON -- disabled for now pending arm32 kernel fpu
+# support and ctf
+include "crypto/aes/arch/arm/files.aesneon"

Index: src/sys/arch/arm/vfp/vfp_init.c
diff -u src/sys/arch/arm/vfp/vfp_init.c:1.65 src/sys/arch/arm/vfp/vfp_init.c:1.66
--- src/sys/arch/arm/vfp/vfp_init.c:1.65	Mon Jun 29 23:54:06 2020
+++ src/sys/arch/arm/vfp/vfp_init.c	Mon Jun 29 23:56:31 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: vfp_init.c,v 1.65 2020/06/29 23:54:06 riastradh Exp $ */
+/*  $NetBSD: vfp_init.c,v 1.66 2020/06/29 23:56:31 riastradh Exp $ */
 
 /*
  * Copyright (c) 2008 ARM Ltd
@@ -32,7 +32,7 @@
 #include "opt_cputypes.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.65 2020/06/29 23:54:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.66 2020/06/29 23:56:31 riastradh Exp 

CVS commit: src/sys/arch/arm

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

Modified Files:
src/sys/arch/arm/arm32: cpu.c
src/sys/arch/arm/include: cpu.h
src/sys/arch/arm/vfp: vfp_init.c

Log Message:
Implement fpu_kern_enter/leave for arm32.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/arch/arm/arm32/cpu.c
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/arm/include/cpu.h
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/arm/vfp/vfp_init.c

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

Modified files:

Index: src/sys/arch/arm/arm32/cpu.c
diff -u src/sys/arch/arm/arm32/cpu.c:1.145 src/sys/arch/arm/arm32/cpu.c:1.146
--- src/sys/arch/arm/arm32/cpu.c:1.145	Sat Jun 20 07:10:36 2020
+++ src/sys/arch/arm/arm32/cpu.c	Mon Jun 29 23:54:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.145 2020/06/20 07:10:36 skrll Exp $	*/
+/*	$NetBSD: cpu.c,v 1.146 2020/06/29 23:54:05 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995 Mark Brinicombe.
@@ -46,7 +46,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.145 2020/06/20 07:10:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.146 2020/06/29 23:54:05 riastradh Exp $");
 
 #include 
 
@@ -229,6 +229,8 @@ cpu_attach(device_t dv, cpuid_t id)
 #endif
 
 	vfp_attach(ci);		/* XXX SMP */
+
+	ci->ci_kfpu_spl = -1;
 }
 
 enum cpu_class {

Index: src/sys/arch/arm/include/cpu.h
diff -u src/sys/arch/arm/include/cpu.h:1.110 src/sys/arch/arm/include/cpu.h:1.111
--- src/sys/arch/arm/include/cpu.h:1.110	Sun Mar 29 09:06:38 2020
+++ src/sys/arch/arm/include/cpu.h	Mon Jun 29 23:54:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.110 2020/03/29 09:06:38 skrll Exp $	*/
+/*	$NetBSD: cpu.h,v 1.111 2020/06/29 23:54:06 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -168,6 +168,8 @@ struct cpu_info {
 	int		ci_want_resched;/* resched() was called */
 	int		ci_intr_depth;	/* */
 
+	int ci_kfpu_spl;
+
 	struct cpu_softc *
 			ci_softc;	/* platform softc */
 

Index: src/sys/arch/arm/vfp/vfp_init.c
diff -u src/sys/arch/arm/vfp/vfp_init.c:1.64 src/sys/arch/arm/vfp/vfp_init.c:1.65
--- src/sys/arch/arm/vfp/vfp_init.c:1.64	Tue Oct 29 16:18:23 2019
+++ src/sys/arch/arm/vfp/vfp_init.c	Mon Jun 29 23:54:06 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: vfp_init.c,v 1.64 2019/10/29 16:18:23 joerg Exp $ */
+/*  $NetBSD: vfp_init.c,v 1.65 2020/06/29 23:54:06 riastradh Exp $ */
 
 /*
  * Copyright (c) 2008 ARM Ltd
@@ -32,7 +32,7 @@
 #include "opt_cputypes.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.64 2019/10/29 16:18:23 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.65 2020/06/29 23:54:06 riastradh Exp $");
 
 #include 
 #include 
@@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 		/* for pmap.h */
 
@@ -658,4 +659,72 @@ vfp_setcontext(struct lwp *l, const mcon
 	sizeof(mcp->__fpu.__vfpregs.__vfp_fstmx));
 }
 
+void
+fpu_kern_enter(void)
+{
+	struct lwp *l = curlwp;
+	struct cpu_info *ci;
+	uint32_t fpexc;
+	int s;
+
+	/*
+	 * Block all interrupts.  We must block preemption since -- if
+	 * this is a user thread -- there is nowhere to save the kernel
+	 * fpu state, and if we want this to be usable in interrupts,
+	 * we can't let interrupts interfere with the fpu state in use
+	 * since there's nowhere for them to save it.
+	 */
+	s = splhigh();
+	ci = curcpu();
+	KASSERT(ci->ci_kfpu_spl == -1);
+	ci->ci_kfpu_spl = s;
+
+	/*
+	 * If we are in a softint and have a pinned lwp, the fpu state
+	 * is that of the pinned lwp, so save it there.
+	 */
+	if ((l->l_pflag & LP_INTR) && (l->l_switchto != NULL))
+		l = l->l_switchto;
+	if (vfp_used_p(l))
+		vfp_savecontext(l);
+
+	/* Enable the fpu.  */
+	fpexc = armreg_fpexc_read();
+	fpexc |= VFP_FPEXC_EN;
+	fpexc &= ~VFP_FPEXC_EX;
+	armreg_fpexc_write(fpexc);
+}
+
+void
+fpu_kern_leave(void)
+{
+	static const struct vfpreg zero_vfpreg;
+	struct cpu_info *ci = curcpu();
+	int s;
+	uint32_t fpexc;
+
+	KASSERT(ci->ci_cpl == IPL_HIGH);
+	KASSERT(ci->ci_kfpu_spl != -1);
+
+	/*
+	 * Zero the fpu registers; otherwise we might leak secrets
+	 * through Spectre-class attacks to userland, even if there are
+	 * no bugs in fpu state management.
+	 */
+	load_vfpregs(_vfpreg);
+
+	/*
+	 * Disable the fpu so that the kernel can't accidentally use
+	 * it again.
+	 */
+	fpexc = armreg_fpexc_read();
+	fpexc &= ~VFP_FPEXC_EN;
+	armreg_fpexc_write(fpexc);
+
+	/* Restore interrupts.  */
+	s = ci->ci_kfpu_spl;
+	ci->ci_kfpu_spl = -1;
+	splx(s);
+}
+
 #endif /* FPU_VFP */



CVS commit: src/sys

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

Modified Files:
src/sys/arch/aarch64/aarch64: fpu.c
src/sys/crypto/aes/arch/arm: aes_armv8.c
Added Files:
src/sys/arch/arm/include: fpu.h
Removed Files:
src/sys/arch/aarch64/include: fpu.h

Log Message:
Move aarch64/fpu.h to arm/fpu.h.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/aarch64/fpu.c
cvs rdiff -u -r1.1 -r0 src/sys/arch/aarch64/include/fpu.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/include/fpu.h
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/arm/aes_armv8.c

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/fpu.c
diff -u src/sys/arch/aarch64/aarch64/fpu.c:1.4 src/sys/arch/aarch64/aarch64/fpu.c:1.5
--- src/sys/arch/aarch64/aarch64/fpu.c:1.4	Mon Jun 29 23:22:27 2020
+++ src/sys/arch/aarch64/aarch64/fpu.c	Mon Jun 29 23:53:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.4 2020/06/29 23:22:27 riastradh Exp $ */
+/* $NetBSD: fpu.c,v 1.5 2020/06/29 23:53:12 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,14 +31,15 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.4 2020/06/29 23:22:27 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.5 2020/06/29 23:53:12 riastradh Exp $");
 
 #include 
 #include 
 #include 
 #include 
 
-#include 
+#include 
+
 #include 
 #include 
 #include 

Index: src/sys/crypto/aes/arch/arm/aes_armv8.c
diff -u src/sys/crypto/aes/arch/arm/aes_armv8.c:1.1 src/sys/crypto/aes/arch/arm/aes_armv8.c:1.2
--- src/sys/crypto/aes/arch/arm/aes_armv8.c:1.1	Mon Jun 29 23:31:41 2020
+++ src/sys/crypto/aes/arch/arm/aes_armv8.c	Mon Jun 29 23:53:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_armv8.c,v 1.1 2020/06/29 23:31:41 riastradh Exp $	*/
+/*	$NetBSD: aes_armv8.c,v 1.2 2020/06/29 23:53:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aes_armv8.c,v 1.1 2020/06/29 23:31:41 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_armv8.c,v 1.2 2020/06/29 23:53:12 riastradh Exp $");
 
 #include 
 #include 
@@ -36,8 +36,9 @@ __KERNEL_RCSID(1, "$NetBSD: aes_armv8.c,
 #include 
 #include 
 
+#include 
+
 #include 
-#include 
 
 static void
 aesarmv8_setenckey(struct aesenc *enc, const uint8_t key[static 16],

Added files:

Index: src/sys/arch/arm/include/fpu.h
diff -u /dev/null src/sys/arch/arm/include/fpu.h:1.1
--- /dev/null	Mon Jun 29 23:53:12 2020
+++ src/sys/arch/arm/include/fpu.h	Mon Jun 29 23:53:12 2020
@@ -0,0 +1,35 @@
+/*	$NetBSD: fpu.h,v 1.1 2020/06/29 23:53:12 riastradh Exp $	*/
+
+/*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	_SYS_ARCH_ARM_FPU_H
+#define	_SYS_ARCH_ARM_FPU_H
+
+void fpu_kern_enter(void);
+void fpu_kern_leave(void);
+
+#endif	/* _SYS_ARCH_ARM_FPU_H */



CVS commit: src/sys

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

Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/x86: identcpu.c
src/sys/crypto/aes/arch/x86: immintrin.h
Added Files:
src/sys/crypto/aes/arch/x86: aes_ssse3.c aes_ssse3.h aes_ssse3_impl.c
aes_ssse3_impl.h aes_ssse3_subr.c files.aee3

Log Message:
New permutation-based AES implementation using SSSE3.

This covers a lot of CPUs -- particularly lower-end CPUs over the
past decade which lack AES-NI.

Derived from Mike Hamburg's public domain vpaes software; see
 for details.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/x86/aes_ssse3.c \
src/sys/crypto/aes/arch/x86/aes_ssse3.h \
src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c \
src/sys/crypto/aes/arch/x86/aes_ssse3_impl.h \
src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c \
src/sys/crypto/aes/arch/x86/files.aee3
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/x86/immintrin.h

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

Modified files:

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.115 src/sys/arch/x86/conf/files.x86:1.116
--- src/sys/arch/x86/conf/files.x86:1.115	Mon Jun 29 23:47:54 2020
+++ src/sys/arch/x86/conf/files.x86	Mon Jun 29 23:51:35 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.115 2020/06/29 23:47:54 riastradh Exp $
+#	$NetBSD: files.x86,v 1.116 2020/06/29 23:51:35 riastradh Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -174,3 +174,6 @@ include "crypto/aes/arch/x86/files.aesvi
 
 # Bitsliced AES with SSE2
 include "crypto/aes/arch/x86/files.aessse2"
+
+# Permutation-based AES with PSHUFB
+include "crypto/aes/arch/x86/files.aee3"

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.110 src/sys/arch/x86/x86/identcpu.c:1.111
--- src/sys/arch/x86/x86/identcpu.c:1.110	Mon Jun 29 23:47:54 2020
+++ src/sys/arch/x86/x86/identcpu.c	Mon Jun 29 23:51:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.110 2020/06/29 23:47:54 riastradh Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.111 2020/06/29 23:51:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.110 2020/06/29 23:47:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.111 2020/06/29 23:51:35 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -1006,6 +1007,10 @@ cpu_probe(struct cpu_info *ci)
 #endif
 		if (cpu_feature[4] & CPUID_VIA_HAS_ACE)
 			aes_md_init(_via_impl);
+		else if (i386_has_sse && i386_has_sse2 &&
+		(cpu_feature[1] & CPUID2_SSE3) &&
+		(cpu_feature[1] & CPUID2_SSSE3))
+			aes_md_init(_ssse3_impl);
 		else if (i386_has_sse && i386_has_sse2)
 			aes_md_init(_sse2_impl);
 	} else {

Index: src/sys/crypto/aes/arch/x86/immintrin.h
diff -u src/sys/crypto/aes/arch/x86/immintrin.h:1.1 src/sys/crypto/aes/arch/x86/immintrin.h:1.2
--- src/sys/crypto/aes/arch/x86/immintrin.h:1.1	Mon Jun 29 23:47:54 2020
+++ src/sys/crypto/aes/arch/x86/immintrin.h	Mon Jun 29 23:51:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: immintrin.h,v 1.1 2020/06/29 23:47:54 riastradh Exp $	*/
+/*	$NetBSD: immintrin.h,v 1.2 2020/06/29 23:51:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@ typedef unsigned long long __v2du __attr
 typedef int __v4si __attribute__((__vector_size__(16)));
 typedef float __v4sf __attribute__((__vector_size__(16)));
 typedef short __v8hi __attribute__((__vector_size__(16)));
+typedef char __v16qi __attribute__((__vector_size__(16)));
 
 #elif defined(__clang__)
 
@@ -66,6 +67,7 @@ typedef unsigned long long __v2du __attr
 typedef int __v4si __attribute__((__vector_size__(16)));
 typedef float __v4sf __attribute__((__vector_size__(16)));
 typedef short __v8hi __attribute__((__vector_size__(16)));
+typedef char __v16qi __attribute__((__vector_size__(16)));
 
 #define	_INTRINSATTR			  \
 	__attribute__((__always_inline__, __nodebug__, __target__("sse2"),\
@@ -79,6 +81,18 @@ typedef short __v8hi __attribute__((__ve
 
 #endif
 
+#define	_SSSE3_ATTR	__attribute__((target("ssse3")))
+
+#if defined(__GNUC__) && !defined(__clang__)
+#define	_mm_alignr_epi8(hi,lo,bytes)	  \
+	(__m128i)__builtin_ia32_palignr128((__v2di)(__m128i)(hi),	  \
+	(__v2di)(__m128i)(lo), 8*(int)(bytes))
+#elif defined(__clang__)
+#define	_mm_alignr_epi8(hi,lo,bytes)	  \
+	(__m128i)__builtin_ia32_palignr128((__v16qi)(__m128i)(hi),	 

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

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

Modified Files:
src/sys/crypto/aes/arch/x86: aes_sse2.h aes_sse2_impl.c aes_sse2_impl.h
files.aessse2
Added Files:
src/sys/crypto/aes/arch/x86: aes_sse2_subr.c

Log Message:
Split SSE2 logic into separate units.

Ensure that there are no paths into files compiled with -msse -msse2
at all except via fpu_kern_enter.

I didn't run into a practical problem with this, but let's not leave
a ticking time bomb for subsequent toolchain changes in case the mere
declaration of local __m128i variables causes trouble.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/x86/aes_sse2.h \
src/sys/crypto/aes/arch/x86/aes_sse2_impl.c \
src/sys/crypto/aes/arch/x86/aes_sse2_impl.h \
src/sys/crypto/aes/arch/x86/files.aessse2
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/x86/aes_sse2_subr.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/crypto/aes/arch/x86/aes_sse2.h
diff -u src/sys/crypto/aes/arch/x86/aes_sse2.h:1.1 src/sys/crypto/aes/arch/x86/aes_sse2.h:1.2
--- src/sys/crypto/aes/arch/x86/aes_sse2.h:1.1	Mon Jun 29 23:47:54 2020
+++ src/sys/crypto/aes/arch/x86/aes_sse2.h	Mon Jun 29 23:50:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_sse2.h,v 1.1 2020/06/29 23:47:54 riastradh Exp $	*/
+/*	$NetBSD: aes_sse2.h,v 1.2 2020/06/29 23:50:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -31,6 +31,31 @@
 
 #include 
 
+/*
+ * These functions MUST NOT use any vector registers for parameters or
+ * results -- the caller is compiled with -mno-sse  in the kernel,
+ * and dynamically turns on the vector unit just before calling them.
+ * Internal subroutines that use the vector unit for parameters are
+ * declared in aes_sse2_impl.h instead.
+ */
+
+void aes_sse2_setkey(uint64_t[static 30], const void *, uint32_t);
+
+void aes_sse2_enc(const struct aesenc *, const uint8_t in[static 16],
+uint8_t[static 16], uint32_t);
+void aes_sse2_dec(const struct aesdec *, const uint8_t in[static 16],
+uint8_t[static 16], uint32_t);
+void aes_sse2_cbc_enc(const struct aesenc *, const uint8_t[static 16],
+uint8_t[static 16], size_t nbytes, uint8_t[static 16], uint32_t);
+void aes_sse2_cbc_dec(const struct aesdec *, const uint8_t[static 16],
+uint8_t[static 16], size_t nbytes, uint8_t[static 16], uint32_t);
+void aes_sse2_xts_enc(const struct aesenc *, const uint8_t[static 16],
+uint8_t[static 16], size_t nbytes, uint8_t[static 16], uint32_t);
+void aes_sse2_xts_dec(const struct aesdec *, const uint8_t[static 16],
+uint8_t[static 16], size_t nbytes, uint8_t[static 16], uint32_t);
+
+int aes_sse2_selftest(void);
+
 extern struct aes_impl aes_sse2_impl;
 
 #endif	/* _CRYPTO_AES_ARCH_X86_AES_SSE2_H */
Index: src/sys/crypto/aes/arch/x86/aes_sse2_impl.c
diff -u src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.1 src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.1	Mon Jun 29 23:47:54 2020
+++ src/sys/crypto/aes/arch/x86/aes_sse2_impl.c	Mon Jun 29 23:50:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_sse2_impl.c,v 1.1 2020/06/29 23:47:54 riastradh Exp $	*/
+/*	$NetBSD: aes_sse2_impl.c,v 1.2 2020/06/29 23:50:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,11 +27,10 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aes_sse2_impl.c,v 1.1 2020/06/29 23:47:54 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_sse2_impl.c,v 1.2 2020/06/29 23:50:05 riastradh Exp $");
 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -41,532 +40,99 @@ __KERNEL_RCSID(1, "$NetBSD: aes_sse2_imp
 #include 
 #include 
 
-#include "aes_sse2_impl.h"
-
 static void
-aes_sse2_setkey(uint64_t rk[static 30], const void *key, uint32_t nrounds)
+aes_sse2_setenckey_impl(struct aesenc *enc, const uint8_t *key,
+uint32_t nrounds)
 {
-	size_t key_len;
-
-	switch (nrounds) {
-	case 10:
-		key_len = 16;
-		break;
-	case 12:
-		key_len = 24;
-		break;
-	case 14:
-		key_len = 32;
-		break;
-	default:
-		panic("invalid AES nrounds: %u", nrounds);
-	}
 
 	fpu_kern_enter();
-	aes_sse2_keysched(rk, key, key_len);
-	fpu_kern_leave();
-}
-
-static void
-aes_sse2_setenckey(struct aesenc *enc, const uint8_t *key, uint32_t nrounds)
-{
-
 	aes_sse2_setkey(enc->aese_aes.aes_rk64, key, nrounds);
+	fpu_kern_leave();
 }
 
 static void
-aes_sse2_setdeckey(struct aesdec *dec, const uint8_t *key, uint32_t nrounds)
+aes_sse2_setdeckey_impl(struct aesdec *dec, const uint8_t *key,
+uint32_t nrounds)
 {
 
+	fpu_kern_enter();
 	/*
 	 * BearSSL computes InvMixColumns on the fly -- no need for
 	 * distinct decryption round keys.
 	 */
 	aes_sse2_setkey(dec->aesd_aes.aes_rk64, key, nrounds);
+	fpu_kern_leave();
 }
 
 static void
-aes_sse2_enc(const struct aesenc *enc, const uint8_t in[static 16],
+aes_sse2_enc_impl(const 

CVS commit: src/sys

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

Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/x86: identcpu.c
src/sys/crypto/aes: aes.h
Added Files:
src/sys/crypto/aes/arch/x86: aes_sse2.c aes_sse2.h aes_sse2_dec.c
aes_sse2_enc.c aes_sse2_impl.c aes_sse2_impl.h files.aessse2
immintrin.h immintrin_ext.h

Log Message:
New SSE2-based bitsliced AES implementation.

This should work on essentially all x86 CPUs of the last two decades,
and may improve throughput over the portable C aes_ct implementation
from BearSSL by

(a) reducing the number of vector operations in sequence, and
(b) batching four rather than two blocks in parallel.

Derived from BearSSL'S aes_ct64 implementation adjusted so that where
aes_ct64 uses 64-bit q[0],...,q[7], aes_sse2 uses (q[0], q[4]), ...,
(q[3], q[7]), each tuple representing a pair of 64-bit quantities
stacked in a single 128-bit register.  This translation was done very
naively, and mostly reduces the cost of ShiftRows and data movement
without doing anything to address the S-box or (Inv)MixColumns, which
spread all 64-bit quantities across separate registers and ignore the
upper halves.

Unfortunately, SSE2 -- which is all that is guaranteed on all amd64
CPUs -- doesn't have PSHUFB, which would help out a lot more.  For
example, vpaes relies on that.  Perhaps there are enough CPUs out
there with PSHUFB but not AES-NI to make it worthwhile to import or
adapt vpaes too.

Note: This includes local definitions of various Intel compiler
intrinsics for gcc and clang in terms of their __builtin_* ,
because the necessary header files are not available during the
kernel build.  This is a kludge -- we should fix it properly; the
present approach is expedient but not ideal.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/aes.h
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/x86/aes_sse2.c \
src/sys/crypto/aes/arch/x86/aes_sse2.h \
src/sys/crypto/aes/arch/x86/aes_sse2_dec.c \
src/sys/crypto/aes/arch/x86/aes_sse2_enc.c \
src/sys/crypto/aes/arch/x86/aes_sse2_impl.c \
src/sys/crypto/aes/arch/x86/aes_sse2_impl.h \
src/sys/crypto/aes/arch/x86/files.aessse2 \
src/sys/crypto/aes/arch/x86/immintrin.h \
src/sys/crypto/aes/arch/x86/immintrin_ext.h

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

Modified files:

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.114 src/sys/arch/x86/conf/files.x86:1.115
--- src/sys/arch/x86/conf/files.x86:1.114	Mon Jun 29 23:39:30 2020
+++ src/sys/arch/x86/conf/files.x86	Mon Jun 29 23:47:54 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.114 2020/06/29 23:39:30 riastradh Exp $
+#	$NetBSD: files.x86,v 1.115 2020/06/29 23:47:54 riastradh Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -171,3 +171,6 @@ include "crypto/aes/arch/x86/files.aesni
 
 # VIA ACE
 include "crypto/aes/arch/x86/files.aesvia"
+
+# Bitsliced AES with SSE2
+include "crypto/aes/arch/x86/files.aessse2"

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.109 src/sys/arch/x86/x86/identcpu.c:1.110
--- src/sys/arch/x86/x86/identcpu.c:1.109	Mon Jun 29 23:39:30 2020
+++ src/sys/arch/x86/x86/identcpu.c	Mon Jun 29 23:47:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.109 2020/06/29 23:39:30 riastradh Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.110 2020/06/29 23:47:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.109 2020/06/29 23:39:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.110 2020/06/29 23:47:54 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
 #include 
 
 #include 
+#include 
 #include 
 
 #include 
@@ -1005,6 +1006,8 @@ cpu_probe(struct cpu_info *ci)
 #endif
 		if (cpu_feature[4] & CPUID_VIA_HAS_ACE)
 			aes_md_init(_via_impl);
+		else if (i386_has_sse && i386_has_sse2)
+			aes_md_init(_sse2_impl);
 	} else {
 		/*
 		 * If not first. Warn about cpu_feature mismatch for

Index: src/sys/crypto/aes/aes.h
diff -u src/sys/crypto/aes/aes.h:1.1 src/sys/crypto/aes/aes.h:1.2
--- src/sys/crypto/aes/aes.h:1.1	Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes.h	Mon Jun 29 23:47:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes.h,v 1.1 2020/06/29 23:27:52 riastradh Exp $	*/
+/*	$NetBSD: aes.h,v 1.2 2020/06/29 23:47:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -37,8 +37,9 @@
  *
  *	Expanded round keys.
  */
-struct aes {
+union aes {
 	uint32_t	aes_rk[60];
+	uint64_t	aes_rk64[30];
 } 

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/crypto/aes/arch/x86

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

Modified Files:
src/sys/crypto/aes/arch/x86: aes_via.c

Log Message:
VIA AES: Batch AES-XTS computation into eight blocks at a time.

Experimental -- performance improvement is not clearly worth the
complexity.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/x86/aes_via.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/crypto/aes/arch/x86/aes_via.c
diff -u src/sys/crypto/aes/arch/x86/aes_via.c:1.1 src/sys/crypto/aes/arch/x86/aes_via.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_via.c:1.1	Mon Jun 29 23:39:30 2020
+++ src/sys/crypto/aes/arch/x86/aes_via.c	Mon Jun 29 23:41:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_via.c,v 1.1 2020/06/29 23:39:30 riastradh Exp $	*/
+/*	$NetBSD: aes_via.c,v 1.2 2020/06/29 23:41:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aes_via.c,v 1.1 2020/06/29 23:39:30 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_via.c,v 1.2 2020/06/29 23:41:35 riastradh Exp $");
 
 #include 
 #include 
@@ -119,8 +119,8 @@ aesvia_setdeckey(struct aesdec *dec, con
 }
 
 static inline void
-aesvia_enc1(const struct aesenc *enc, const uint8_t in[static 16],
-uint8_t out[static 16], uint32_t cw0)
+aesvia_encN(const struct aesenc *enc, const uint8_t in[static 16],
+uint8_t out[static 16], size_t nblocks, uint32_t cw0)
 {
 	const uint32_t cw[4] __aligned(16) = {
 		[0] = (cw0
@@ -128,7 +128,6 @@ aesvia_enc1(const struct aesenc *enc, co
 		| C3_CRYPT_CWLO_ENCRYPT
 		| C3_CRYPT_CWLO_NORMAL),
 	};
-	size_t nblocks = 1;
 
 	KASSERT(((uintptr_t)enc & 0xf) == 0);
 	KASSERT(((uintptr_t)in & 0xf) == 0);
@@ -141,8 +140,8 @@ aesvia_enc1(const struct aesenc *enc, co
 }
 
 static inline void
-aesvia_dec1(const struct aesdec *dec, const uint8_t in[static 16],
-uint8_t out[static 16], uint32_t cw0)
+aesvia_decN(const struct aesdec *dec, const uint8_t in[static 16],
+uint8_t out[static 16], size_t nblocks, uint32_t cw0)
 {
 	const uint32_t cw[4] __aligned(16) = {
 		[0] = (cw0
@@ -150,7 +149,6 @@ aesvia_dec1(const struct aesdec *dec, co
 		| C3_CRYPT_CWLO_DECRYPT
 		| C3_CRYPT_CWLO_NORMAL),
 	};
-	size_t nblocks = 1;
 
 	KASSERT(((uintptr_t)dec & 0xf) == 0);
 	KASSERT(((uintptr_t)in & 0xf) == 0);
@@ -180,7 +178,7 @@ aesvia_enc(const struct aesenc *enc, con
 	if uintptr_t)in | (uintptr_t)out) & 0xf) == 0 &&
 	((uintptr_t)in & 0xff0) != 0xff0) {
 		enc_aligned_evcnt.ev_count++;
-		aesvia_enc1(enc, in, out, cw0);
+		aesvia_encN(enc, in, out, 1, cw0);
 	} else {
 		enc_unaligned_evcnt.ev_count++;
 		/*
@@ -194,7 +192,7 @@ aesvia_enc(const struct aesenc *enc, con
 		uint8_t outbuf[16] __aligned(16);
 
 		memcpy(inbuf, in, 16);
-		aesvia_enc1(enc, inbuf, outbuf, cw0);
+		aesvia_encN(enc, inbuf, outbuf, 1, cw0);
 		memcpy(out, outbuf, 16);
 
 		explicit_memset(inbuf, 0, sizeof inbuf);
@@ -221,7 +219,7 @@ aesvia_dec(const struct aesdec *dec, con
 	if uintptr_t)in | (uintptr_t)out) & 0xf) == 0 &&
 	((uintptr_t)in & 0xff0) != 0xff0) {
 		dec_aligned_evcnt.ev_count++;
-		aesvia_dec1(dec, in, out, cw0);
+		aesvia_decN(dec, in, out, 1, cw0);
 	} else {
 		dec_unaligned_evcnt.ev_count++;
 		/*
@@ -235,7 +233,7 @@ aesvia_dec(const struct aesdec *dec, con
 		uint8_t outbuf[16] __aligned(16);
 
 		memcpy(inbuf, in, 16);
-		aesvia_dec1(dec, inbuf, outbuf, cw0);
+		aesvia_decN(dec, inbuf, outbuf, 1, cw0);
 		memcpy(out, outbuf, 16);
 
 		explicit_memset(inbuf, 0, sizeof inbuf);
@@ -245,7 +243,7 @@ aesvia_dec(const struct aesdec *dec, con
 }
 
 static inline void
-aesvia_cbc_enc1(const struct aesenc *enc, const uint8_t in[static 16],
+aesvia_cbc_encN(const struct aesenc *enc, const uint8_t in[static 16],
 uint8_t out[static 16], size_t nblocks, uint8_t **ivp, uint32_t cw0)
 {
 	const uint32_t cw[4] __aligned(16) = {
@@ -274,7 +272,7 @@ aesvia_cbc_enc1(const struct aesenc *enc
 }
 
 static inline void
-aesvia_cbc_dec1(const struct aesdec *dec, const uint8_t in[static 16],
+aesvia_cbc_decN(const struct aesdec *dec, const uint8_t in[static 16],
 uint8_t out[static 16], size_t nblocks, uint8_t iv[static 16],
 uint32_t cw0)
 {
@@ -340,7 +338,7 @@ aesvia_cbc_enc(const struct aesenc *enc,
 	if uintptr_t)in | (uintptr_t)out | (uintptr_t)iv) & 0xf) == 0) {
 		cbcenc_aligned_evcnt.ev_count++;
 		uint8_t *ivp = iv;
-		aesvia_cbc_enc1(enc, in, out, nbytes/16, , cw0);
+		aesvia_cbc_encN(enc, in, out, nbytes/16, , cw0);
 		memcpy(iv, ivp, 16);
 	} else {
 		cbcenc_unaligned_evcnt.ev_count++;
@@ -351,7 +349,7 @@ aesvia_cbc_enc(const struct aesenc *enc,
 		for (; nbytes; nbytes -= 16, in += 16, out += 16) {
 			memcpy(tmp, in, 16);
 			xor128(tmp, tmp, cv);
-			aesvia_enc1(enc, tmp, cv, cw0);
+			aesvia_encN(enc, tmp, cv, 1, cw0);
 			memcpy(out, cv, 16);
 		}
 		

CVS commit: src/sys

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

Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/x86: identcpu.c
Added Files:
src/sys/crypto/aes/arch/x86: aes_via.c aes_via.h files.aesvia

Log Message:
Add AES implementation with VIA ACE.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/x86/aes_via.c \
src/sys/crypto/aes/arch/x86/aes_via.h \
src/sys/crypto/aes/arch/x86/files.aesvia

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

Modified files:

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.113 src/sys/arch/x86/conf/files.x86:1.114
--- src/sys/arch/x86/conf/files.x86:1.113	Mon Jun 29 23:38:02 2020
+++ src/sys/arch/x86/conf/files.x86	Mon Jun 29 23:39:30 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.113 2020/06/29 23:38:02 riastradh Exp $
+#	$NetBSD: files.x86,v 1.114 2020/06/29 23:39:30 riastradh Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -168,3 +168,6 @@ file	arch/x86/pci/pci_addr_fixup.c	pci_a
 
 # AES-NI
 include "crypto/aes/arch/x86/files.aesni"
+
+# VIA ACE
+include "crypto/aes/arch/x86/files.aesvia"

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.108 src/sys/arch/x86/x86/identcpu.c:1.109
--- src/sys/arch/x86/x86/identcpu.c:1.108	Mon Jun 29 23:29:39 2020
+++ src/sys/arch/x86/x86/identcpu.c	Mon Jun 29 23:39:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.108 2020/06/29 23:29:39 riastradh Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.109 2020/06/29 23:39:30 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.108 2020/06/29 23:29:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.109 2020/06/29 23:39:30 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
 #include 
 
 #include 
+#include 
 
 #include 
 
@@ -1000,7 +1001,10 @@ cpu_probe(struct cpu_info *ci)
 #ifdef __x86_64__	/* not yet implemented on i386 */
 		if (cpu_feature[1] & CPUID2_AES)
 			aes_md_init(_ni_impl);
+		else
 #endif
+		if (cpu_feature[4] & CPUID_VIA_HAS_ACE)
+			aes_md_init(_via_impl);
 	} else {
 		/*
 		 * If not first. Warn about cpu_feature mismatch for

Added files:

Index: src/sys/crypto/aes/arch/x86/aes_via.c
diff -u /dev/null src/sys/crypto/aes/arch/x86/aes_via.c:1.1
--- /dev/null	Mon Jun 29 23:39:31 2020
+++ src/sys/crypto/aes/arch/x86/aes_via.c	Mon Jun 29 23:39:30 2020
@@ -0,0 +1,626 @@
+/*	$NetBSD: aes_via.c,v 1.1 2020/06/29 23:39:30 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(1, "$NetBSD: aes_via.c,v 1.1 2020/06/29 23:39:30 riastradh Exp $");
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void
+aesvia_reload_keys(void)
+{
+
+	asm volatile("pushf; popf");
+}
+
+static uint32_t
+aesvia_keylen_cw0(unsigned nrounds)
+{
+
+	/*
+	 * Determine the control word bits for the key size / number of
+	 * rounds.  For AES-128, the hardware can do key expansion on
+	 * the fly; for AES-192 and AES-256, software must do it.
+	 */
+	switch (nrounds) {
+	case AES_128_NROUNDS:
+		return C3_CRYPT_CWLO_KEY128;
+	case 

CVS commit: src/sys/arch/x86

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

Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/include: via_padlock.h
src/sys/arch/x86/x86: via_padlock.c

Log Message:
padlock(4): Remove legacy rijndael API use.

This doesn't actually need to compute AES -- it just needs the
standard AES key schedule, so use the BearSSL constant-time key
schedule implementation.

XXX Compile-tested only.
XXX The byte-order business here seems highly questionable.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/include/via_padlock.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/via_padlock.c

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

Modified files:

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.112 src/sys/arch/x86/conf/files.x86:1.113
--- src/sys/arch/x86/conf/files.x86:1.112	Mon Jun 29 23:29:39 2020
+++ src/sys/arch/x86/conf/files.x86	Mon Jun 29 23:38:02 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.112 2020/06/29 23:29:39 riastradh Exp $
+#	$NetBSD: files.x86,v 1.113 2020/06/29 23:38:02 riastradh Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -59,7 +59,7 @@ device	odcm
 attach	odcm at cpufeaturebus
 file	arch/x86/x86/odcm.c		odcm
 
-device	padlock: opencrypto, rijndael
+device	padlock: opencrypto, aes
 attach	padlock at cpufeaturebus
 file	arch/x86/x86/via_padlock.c	padlock
 

Index: src/sys/arch/x86/include/via_padlock.h
diff -u src/sys/arch/x86/include/via_padlock.h:1.9 src/sys/arch/x86/include/via_padlock.h:1.10
--- src/sys/arch/x86/include/via_padlock.h:1.9	Sat Feb 27 00:54:59 2016
+++ src/sys/arch/x86/include/via_padlock.h	Mon Jun 29 23:38:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: via_padlock.h,v 1.9 2016/02/27 00:54:59 tls Exp $	*/
+/*	$NetBSD: via_padlock.h,v 1.10 2020/06/29 23:38:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2003 Jason Wright
@@ -25,7 +25,8 @@
 
 #include 
 #include 
-#include 
+
+#include 
 
 /* VIA C3 xcrypt-* instruction context control options */
 #define C3_CRYPT_CWLO_ROUND_M		0x000f
@@ -43,9 +44,8 @@
 #define C3_CRYPT_CWLO_KEY256		0x080e  /* 256bit, 15 rds */
 
 struct via_padlock_session {
-uint32_t	ses_ekey[4 * (RIJNDAEL_MAXNR + 1) + 4];	/* 128 bit aligned */
-uint32_t	ses_dkey[4 * (RIJNDAEL_MAXNR + 1) + 4];	/* 128 bit aligned */
-uint8_t	ses_iv[16];/* 128 bit aligned */
+uint32_t	ses_ekey[4*(AES_256_NROUNDS + 1)];
+uint32_t	ses_dkey[4*(AES_256_NROUNDS + 1)];
 uint32_t	ses_cw0;
 struct swcr_data	*swd;
 int	ses_klen;

Index: src/sys/arch/x86/x86/via_padlock.c
diff -u src/sys/arch/x86/x86/via_padlock.c:1.29 src/sys/arch/x86/x86/via_padlock.c:1.30
--- src/sys/arch/x86/x86/via_padlock.c:1.29	Sun Jun 14 23:20:15 2020
+++ src/sys/arch/x86/x86/via_padlock.c	Mon Jun 29 23:38:02 2020
@@ -1,5 +1,5 @@
 /*	$OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $	*/
-/*	$NetBSD: via_padlock.c,v 1.29 2020/06/14 23:20:15 riastradh Exp $ */
+/*	$NetBSD: via_padlock.c,v 1.30 2020/06/29 23:38:02 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2003 Jason Wright
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.29 2020/06/14 23:20:15 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.30 2020/06/29 23:38:02 riastradh Exp $");
 
 #include 
 #include 
@@ -37,10 +37,11 @@ __KERNEL_RCSID(0, "$NetBSD: via_padlock.
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -174,14 +175,29 @@ via_padlock_crypto_newsession(void *arg,
 	for (c = cri; c != NULL; c = c->cri_next) {
 		switch (c->cri_alg) {
 		case CRYPTO_AES_CBC:
+			memset(ses->ses_ekey, 0, sizeof(ses->ses_ekey));
+			memset(ses->ses_dkey, 0, sizeof(ses->ses_dkey));
+
 			switch (c->cri_klen) {
 			case 128:
+br_aes_ct_keysched_stdenc(ses->ses_ekey,
+c->cri_key, 16);
+br_aes_ct_keysched_stddec(ses->ses_dkey,
+c->cri_key, 16);
 cw0 = C3_CRYPT_CWLO_KEY128;
 break;
 			case 192:
+br_aes_ct_keysched_stdenc(ses->ses_ekey,
+c->cri_key, 24);
+br_aes_ct_keysched_stddec(ses->ses_dkey,
+c->cri_key, 24);
 cw0 = C3_CRYPT_CWLO_KEY192;
 break;
 			case 256:
+br_aes_ct_keysched_stdenc(ses->ses_ekey,
+c->cri_key, 32);
+br_aes_ct_keysched_stddec(ses->ses_dkey,
+c->cri_key, 32);
 cw0 = C3_CRYPT_CWLO_KEY256;
 break;
 			default:
@@ -194,16 +210,11 @@ via_padlock_crypto_newsession(void *arg,
 			ses->ses_klen = c->cri_klen;
 			ses->ses_cw0 = cw0;
 
-			/* Build expanded keys for both directions */
-			rijndaelKeySetupEnc(ses->ses_ekey, c->cri_key,
-			c->cri_klen);
-			rijndaelKeySetupDec(ses->ses_dkey, c->cri_key,
-			c->cri_klen);
-			for (i = 0; i < 4 * 

CVS commit: src/sys/crypto/aes

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

Modified Files:
src/sys/crypto/aes: aes_bear.h aes_ct.c aes_ct_dec.c aes_impl.c

Log Message:
Provide the standard AES key schedule.

Different AES implementations prefer different variations on it, but
some of them -- notably VIA -- require the standard key schedule to
be available and don't provide hardware support for computing it
themselves.  So adapt BearSSL's logic to generate the standard key
schedule (and decryption keys, with InvMixColumns), rather than the
bitsliced key schedule that BearSSL uses natively.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/aes_bear.h \
src/sys/crypto/aes/aes_ct.c src/sys/crypto/aes/aes_ct_dec.c \
src/sys/crypto/aes/aes_impl.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/crypto/aes/aes_bear.h
diff -u src/sys/crypto/aes/aes_bear.h:1.1 src/sys/crypto/aes/aes_bear.h:1.2
--- src/sys/crypto/aes/aes_bear.h:1.1	Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes_bear.h	Mon Jun 29 23:36:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_bear.h,v 1.1 2020/06/29 23:27:52 riastradh Exp $	*/
+/*	$NetBSD: aes_bear.h,v 1.2 2020/06/29 23:36:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -45,6 +45,12 @@ void	br_aes_ct_skey_expand(uint32_t *, u
 void	br_aes_ct_bitslice_encrypt(unsigned, const uint32_t *, uint32_t *);
 void	br_aes_ct_bitslice_decrypt(unsigned, const uint32_t *, uint32_t *);
 
+/* NetBSD additions */
+
+void	br_aes_ct_inv_mix_columns(uint32_t *);
+u_int	br_aes_ct_keysched_stdenc(uint32_t *, const void *, size_t);
+u_int	br_aes_ct_keysched_stddec(uint32_t *, const void *, size_t);
+
 extern struct aes_impl	aes_bear_impl;
 
 #endif	/* _CRYPTO_AES_AES_BEAR_H */
Index: src/sys/crypto/aes/aes_ct.c
diff -u src/sys/crypto/aes/aes_ct.c:1.1 src/sys/crypto/aes/aes_ct.c:1.2
--- src/sys/crypto/aes/aes_ct.c:1.1	Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes_ct.c	Mon Jun 29 23:36:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aes_ct.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $	*/
+/*	$NetBSD: aes_ct.c,v 1.2 2020/06/29 23:36:59 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2016 Thomas Pornin 
@@ -25,10 +25,12 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aes_ct.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ct.c,v 1.2 2020/06/29 23:36:59 riastradh Exp $");
 
 #include 
 
+#include 
+
 #include 
 
 /* see inner.h */
@@ -333,3 +335,92 @@ br_aes_ct_skey_expand(uint32_t *skey,
 		skey[v + 1] = y | (y >> 1);
 	}
 }
+
+/* NetBSD additions, for computing the standard AES key schedule */
+
+unsigned
+br_aes_ct_keysched_stdenc(uint32_t *skey, const void *key, size_t key_len)
+{
+	unsigned num_rounds;
+	int i, j, k, nk, nkf;
+	uint32_t tmp;
+
+	switch (key_len) {
+	case 16:
+		num_rounds = 10;
+		break;
+	case 24:
+		num_rounds = 12;
+		break;
+	case 32:
+		num_rounds = 14;
+		break;
+	default:
+		/* abort(); */
+		return 0;
+	}
+	nk = (int)(key_len >> 2);
+	nkf = (int)((num_rounds + 1) << 2);
+	tmp = 0;
+	for (i = 0; i < nk; i ++) {
+		tmp = br_dec32le((const unsigned char *)key + (i << 2));
+		skey[i] = tmp;
+	}
+	for (i = nk, j = 0, k = 0; i < nkf; i ++) {
+		if (j == 0) {
+			tmp = (tmp << 24) | (tmp >> 8);
+			tmp = sub_word(tmp) ^ Rcon[k];
+		} else if (nk > 6 && j == 4) {
+			tmp = sub_word(tmp);
+		}
+		tmp ^= skey[i - nk];
+		skey[i] = tmp;
+		if (++ j == nk) {
+			j = 0;
+			k ++;
+		}
+	}
+	return num_rounds;
+}
+
+unsigned
+br_aes_ct_keysched_stddec(uint32_t *skey, const void *key, size_t key_len)
+{
+	uint32_t tkey[60];
+	uint32_t q[8];
+	unsigned num_rounds;
+	unsigned i;
+
+	num_rounds = br_aes_ct_keysched_stdenc(skey, key, key_len);
+	if (num_rounds == 0)
+		return 0;
+
+	tkey[0] = skey[4*num_rounds + 0];
+	tkey[1] = skey[4*num_rounds + 1];
+	tkey[2] = skey[4*num_rounds + 2];
+	tkey[3] = skey[4*num_rounds + 3];
+	for (i = 1; i < num_rounds; i++) {
+		q[2*0] = skey[4*i + 0];
+		q[2*1] = skey[4*i + 1];
+		q[2*2] = skey[4*i + 2];
+		q[2*3] = skey[4*i + 3];
+		q[1] = q[3] = q[5] = q[7] = 0;
+
+		br_aes_ct_ortho(q);
+		br_aes_ct_inv_mix_columns(q);
+		br_aes_ct_ortho(q);
+
+		tkey[4*(num_rounds - i) + 0] = q[2*0];
+		tkey[4*(num_rounds - i) + 1] = q[2*1];
+		tkey[4*(num_rounds - i) + 2] = q[2*2];
+		tkey[4*(num_rounds - i) + 3] = q[2*3];
+	}
+	tkey[4*num_rounds + 0] = skey[0];
+	tkey[4*num_rounds + 1] = skey[1];
+	tkey[4*num_rounds + 2] = skey[2];
+	tkey[4*num_rounds + 3] = skey[3];
+
+	memcpy(skey, tkey, 4*(num_rounds + 1)*sizeof(uint32_t));
+	explicit_memset(tkey, 0, 4*(num_rounds + 1)*sizeof(uint32_t));
+	return num_rounds;
+}
Index: src/sys/crypto/aes/aes_ct_dec.c
diff -u src/sys/crypto/aes/aes_ct_dec.c:1.1 src/sys/crypto/aes/aes_ct_dec.c:1.2
--- src/sys/crypto/aes/aes_ct_dec.c:1.1	Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes_ct_dec.c	Mon Jun 29 23:36:59 2020
@@ -1,4 +1,4 @@
-/*	

CVS commit: src/sys/dev

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

Modified Files:
src/sys/dev: cgd.c cgd_crypto.c cgd_crypto.h

Log Message:
cgd(4): Align IVs on the stack.

This will make it easier for some hardware crypto support.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/dev/cgd.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/cgd_crypto.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/cgd_crypto.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/dev/cgd.c
diff -u src/sys/dev/cgd.c:1.136 src/sys/dev/cgd.c:1.137
--- src/sys/dev/cgd.c:1.136	Mon Jun 29 23:35:26 2020
+++ src/sys/dev/cgd.c	Mon Jun 29 23:36:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.136 2020/06/29 23:35:26 riastradh Exp $ */
+/* $NetBSD: cgd.c,v 1.137 2020/06/29 23:36:06 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.136 2020/06/29 23:35:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.137 2020/06/29 23:36:06 riastradh Exp $");
 
 #include 
 #include 
@@ -1587,7 +1587,7 @@ cgd_cipher(struct cgd_softc *sc, void *d
 	cfunc_cipher	*cipher = sc->sc_cfuncs->cf_cipher;
 	size_t		blocksize = sc->sc_cdata.cf_blocksize;
 	size_t		todo;
-	char		blkno_buf[CGD_MAXBLOCKSIZE];
+	char		blkno_buf[CGD_MAXBLOCKSIZE] __aligned(CGD_BLOCKALIGN);
 
 	DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir));
 

Index: src/sys/dev/cgd_crypto.c
diff -u src/sys/dev/cgd_crypto.c:1.24 src/sys/dev/cgd_crypto.c:1.25
--- src/sys/dev/cgd_crypto.c:1.24	Mon Jun 29 23:33:05 2020
+++ src/sys/dev/cgd_crypto.c	Mon Jun 29 23:36:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd_crypto.c,v 1.24 2020/06/29 23:33:05 riastradh Exp $ */
+/* $NetBSD: cgd_crypto.c,v 1.25 2020/06/29 23:36:06 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.24 2020/06/29 23:33:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.25 2020/06/29 23:36:06 riastradh Exp $");
 
 #include 
 #include 
@@ -167,7 +167,7 @@ cgd_cipher_aes_cbc(void *privdata, void 
 const void *blkno, int dir)
 {
 	struct aes_privdata	*apd = privdata;
-	uint8_t			 iv[CGD_AES_BLOCK_SIZE] = {0};
+	uint8_t iv[CGD_AES_BLOCK_SIZE] __aligned(CGD_AES_BLOCK_SIZE) = {0};
 
 	/* Compute the CBC IV as AES_k(blkno).  */
 	aes_enc(>ap_enckey, blkno, iv, apd->ap_nrounds);

Index: src/sys/dev/cgd_crypto.h
diff -u src/sys/dev/cgd_crypto.h:1.12 src/sys/dev/cgd_crypto.h:1.13
--- src/sys/dev/cgd_crypto.h:1.12	Sat Jun 13 22:15:06 2020
+++ src/sys/dev/cgd_crypto.h	Mon Jun 29 23:36:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd_crypto.h,v 1.12 2020/06/13 22:15:06 riastradh Exp $ */
+/* $NetBSD: cgd_crypto.h,v 1.13 2020/06/29 23:36:06 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -39,6 +39,8 @@
 #define CGD_3DES_BLOCK_SIZE	8
 #define CGD_BF_BLOCK_SIZE	8
 
+#define	CGD_BLOCKALIGN		16
+
 typedef void *(cfunc_init)(size_t, const void *, size_t *);
 typedef void  (cfunc_destroy)(void *);
 typedef void  (cfunc_cipher)(void *, void *, const void *, size_t,



CVS commit: src/sys/dev

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

Modified Files:
src/sys/dev: cgd.c

Log Message:
cgd(4): Print which key size is broken when a self-test fails.

Can be gleaned from the test index but this is a little quicker.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/dev/cgd.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/cgd.c
diff -u src/sys/dev/cgd.c:1.135 src/sys/dev/cgd.c:1.136
--- src/sys/dev/cgd.c:1.135	Wed Jun 17 20:44:45 2020
+++ src/sys/dev/cgd.c	Mon Jun 29 23:35:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.135 2020/06/17 20:44:45 riastradh Exp $ */
+/* $NetBSD: cgd.c,v 1.136 2020/06/29 23:35:26 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.135 2020/06/17 20:44:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.136 2020/06/29 23:35:26 riastradh Exp $");
 
 #include 
 #include 
@@ -1699,8 +1699,8 @@ cgd_selftest(void)
 		if (memcmp(buf, selftests[i].ctxt, txtlen) != 0) {
 			hexdump(printf, "was", buf, txtlen);
 			hexdump(printf, "exp", selftests[i].ctxt, txtlen);
-			panic("cgd %s encryption is broken [%zu]",
-			selftests[i].alg, i);
+			panic("cgd %s-%d encryption is broken [%zu]",
+			selftests[i].alg, keylen, i);
 		}
 
 		cgd_cipher(, buf, buf, txtlen, selftests[i].blkno,
@@ -1708,8 +1708,8 @@ cgd_selftest(void)
 		if (memcmp(buf, selftests[i].ptxt, txtlen) != 0) {
 			hexdump(printf, "was", buf, txtlen);
 			hexdump(printf, "exp", selftests[i].ptxt, txtlen);
-			panic("cgd %s decryption is broken [%zu]",
-			selftests[i].alg, i);
+			panic("cgd %s-%d decryption is broken [%zu]",
+			selftests[i].alg, keylen, i);
 		}
 
 		kmem_free(buf, txtlen);



CVS commit: src/sys/opencrypto

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

Modified Files:
src/sys/opencrypto: aesxcbcmac.c aesxcbcmac.h cryptosoft.c
cryptosoft_xform.c files.opencrypto gmac.c gmac.h xform.c

Log Message:
opencrypto: Switch from legacy rijndael API to new aes API.

While here, apply various rijndael->aes renames, reduce the size
of aesxcbc_ctx by 480 bytes, and convert some malloc->kmem.

Leave in the symbol enc_xform_rijndael128 for now, though, so this
doesn't break any kernel ABI.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/opencrypto/aesxcbcmac.c \
src/sys/opencrypto/gmac.h
cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/aesxcbcmac.h
cvs rdiff -u -r1.55 -r1.56 src/sys/opencrypto/cryptosoft.c
cvs rdiff -u -r1.28 -r1.29 src/sys/opencrypto/cryptosoft_xform.c
cvs rdiff -u -r1.29 -r1.30 src/sys/opencrypto/files.opencrypto \
src/sys/opencrypto/xform.c
cvs rdiff -u -r1.3 -r1.4 src/sys/opencrypto/gmac.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/opencrypto/aesxcbcmac.c
diff -u src/sys/opencrypto/aesxcbcmac.c:1.2 src/sys/opencrypto/aesxcbcmac.c:1.3
--- src/sys/opencrypto/aesxcbcmac.c:1.2	Mon Sep 26 14:50:54 2016
+++ src/sys/opencrypto/aesxcbcmac.c	Mon Jun 29 23:34:48 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $ */
+/* $NetBSD: aesxcbcmac.c,v 1.3 2020/06/29 23:34:48 riastradh Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, 1998 and 2003 WIDE Project.
@@ -30,11 +30,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.3 2020/06/29 23:34:48 riastradh Exp $");
 
 #include 
 #include 
-#include 
+
+#include 
 
 #include 
 
@@ -47,24 +48,31 @@ aes_xcbc_mac_init(void *vctx, const uint
 	{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
 	static const uint8_t k3seed[AES_BLOCKSIZE] =
 	{ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 };
-	u_int32_t r_ks[(RIJNDAEL_MAXNR+1)*4];
+	struct aesenc r_ks;
 	aesxcbc_ctx *ctx;
 	uint8_t k1[AES_BLOCKSIZE];
 
 	ctx = vctx;
 	memset(ctx, 0, sizeof(*ctx));
 
-	if ((ctx->r_nr = rijndaelKeySetupEnc(r_ks, key, keylen * 8)) == 0)
-		return -1;
-	rijndaelEncrypt(r_ks, ctx->r_nr, k1seed, k1);
-	rijndaelEncrypt(r_ks, ctx->r_nr, k2seed, ctx->k2);
-	rijndaelEncrypt(r_ks, ctx->r_nr, k3seed, ctx->k3);
-	if (rijndaelKeySetupEnc(ctx->r_k1s, k1, AES_BLOCKSIZE * 8) == 0)
-		return -1;
-	if (rijndaelKeySetupEnc(ctx->r_k2s, ctx->k2, AES_BLOCKSIZE * 8) == 0)
-		return -1;
-	if (rijndaelKeySetupEnc(ctx->r_k3s, ctx->k3, AES_BLOCKSIZE * 8) == 0)
-		return -1;
+	switch (keylen) {
+	case 16:
+		ctx->r_nr = aes_setenckey128(_ks, key);
+		break;
+	case 24:
+		ctx->r_nr = aes_setenckey192(_ks, key);
+		break;
+	case 32:
+		ctx->r_nr = aes_setenckey256(_ks, key);
+		break;
+	}
+	aes_enc(_ks, k1seed, k1, ctx->r_nr);
+	aes_enc(_ks, k2seed, ctx->k2, ctx->r_nr);
+	aes_enc(_ks, k3seed, ctx->k3, ctx->r_nr);
+	aes_setenckey128(>r_k1s, k1);
+
+	explicit_memset(_ks, 0, sizeof(r_ks));
+	explicit_memset(k1, 0, sizeof(k1));
 
 	return 0;
 }
@@ -83,7 +91,7 @@ aes_xcbc_mac_loop(void *vctx, const uint
 	if (ctx->buflen == sizeof(ctx->buf)) {
 		for (i = 0; i < sizeof(ctx->e); i++)
 			ctx->buf[i] ^= ctx->e[i];
-		rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, ctx->e);
+		aes_enc(>r_k1s, ctx->buf, ctx->e, ctx->r_nr);
 		ctx->buflen = 0;
 	}
 	if (ctx->buflen + len < sizeof(ctx->buf)) {
@@ -96,7 +104,7 @@ aes_xcbc_mac_loop(void *vctx, const uint
 		sizeof(ctx->buf) - ctx->buflen);
 		for (i = 0; i < sizeof(ctx->e); i++)
 			ctx->buf[i] ^= ctx->e[i];
-		rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, ctx->e);
+		aes_enc(>r_k1s, ctx->buf, ctx->e, ctx->r_nr);
 		addr += sizeof(ctx->buf) - ctx->buflen;
 		ctx->buflen = 0;
 	}
@@ -105,7 +113,7 @@ aes_xcbc_mac_loop(void *vctx, const uint
 		memcpy(buf, addr, AES_BLOCKSIZE);
 		for (i = 0; i < sizeof(buf); i++)
 			buf[i] ^= ctx->e[i];
-		rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, buf, ctx->e);
+		aes_enc(>r_k1s, buf, ctx->e, ctx->r_nr);
 		addr += AES_BLOCKSIZE;
 	}
 	if (addr < ep) {
@@ -129,7 +137,7 @@ aes_xcbc_mac_result(uint8_t *addr, void 
 			ctx->buf[i] ^= ctx->e[i];
 			ctx->buf[i] ^= ctx->k2[i];
 		}
-		rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, digest);
+		aes_enc(>r_k1s, ctx->buf, digest, ctx->r_nr);
 	} else {
 		for (i = ctx->buflen; i < sizeof(ctx->buf); i++)
 			ctx->buf[i] = (i == ctx->buflen) ? 0x80 : 0x00;
@@ -137,7 +145,7 @@ aes_xcbc_mac_result(uint8_t *addr, void 
 			ctx->buf[i] ^= ctx->e[i];
 			ctx->buf[i] ^= ctx->k3[i];
 		}
-		rijndaelEncrypt(ctx->r_k1s, ctx->r_nr, ctx->buf, digest);
+		aes_enc(>r_k1s, ctx->buf, digest, ctx->r_nr);
 	}
 
 	memcpy(addr, digest, sizeof(digest));
Index: src/sys/opencrypto/gmac.h
diff -u src/sys/opencrypto/gmac.h:1.2 src/sys/opencrypto/gmac.h:1.3
--- src/sys/opencrypto/gmac.h:1.2	Thu Jun  9 14:47:42 2011
+++ 

CVS commit: src/sys

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

Modified Files:
src/sys/conf: files
src/sys/dev: cgd_crypto.c

Log Message:
cgd(4): Switch from legacy rijndael API to new aes API.


To generate a diff of this commit:
cvs rdiff -u -r1.1269 -r1.1270 src/sys/conf/files
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/cgd_crypto.c

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

Modified files:

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1269 src/sys/conf/files:1.1270
--- src/sys/conf/files:1.1269	Mon Jun 29 23:27:52 2020
+++ src/sys/conf/files	Mon Jun 29 23:33:05 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1269 2020/06/29 23:27:52 riastradh Exp $
+#	$NetBSD: files,v 1.1270 2020/06/29 23:33:05 riastradh Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20171118
@@ -1395,7 +1395,7 @@ file	dev/ic/amdccp.c			amdccp
 defpseudodev vnd:	disk
 defflag opt_vnd.h	VND_COMPRESSION
 defpseudo ccd:		disk
-defpseudodev cgd:	disk, des, blowfish, cast128, rijndael
+defpseudodev cgd:	disk, des, blowfish, cast128, aes
 defpseudodev md:	disk
 defpseudodev fss:	disk
 

Index: src/sys/dev/cgd_crypto.c
diff -u src/sys/dev/cgd_crypto.c:1.23 src/sys/dev/cgd_crypto.c:1.24
--- src/sys/dev/cgd_crypto.c:1.23	Sat Jun 13 22:15:06 2020
+++ src/sys/dev/cgd_crypto.c	Mon Jun 29 23:33:05 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd_crypto.c,v 1.23 2020/06/13 22:15:06 riastradh Exp $ */
+/* $NetBSD: cgd_crypto.c,v 1.24 2020/06/29 23:33:05 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.23 2020/06/13 22:15:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.24 2020/06/29 23:33:05 riastradh Exp $");
 
 #include 
 #include 
@@ -45,9 +45,9 @@ __KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c
 
 #include 
 
+#include 
 #include 
 #include 
-#include 
 
 /*
  * The general framework provides only one generic function.
@@ -114,8 +114,9 @@ cryptfuncs_find(const char *alg)
  */
 
 struct aes_privdata {
-	keyInstance	ap_enckey;
-	keyInstance	ap_deckey;
+	struct aesenc	ap_enckey;
+	struct aesdec	ap_deckey;
+	uint32_t	ap_nrounds;
 };
 
 static void *
@@ -132,8 +133,23 @@ cgd_cipher_aes_cbc_init(size_t keylen, c
 	if (*blocksize != 128)
 		return NULL;
 	ap = kmem_zalloc(sizeof(*ap), KM_SLEEP);
-	rijndael_makeKey(>ap_enckey, DIR_ENCRYPT, keylen, key);
-	rijndael_makeKey(>ap_deckey, DIR_DECRYPT, keylen, key);
+	switch (keylen) {
+	case 128:
+		aes_setenckey128(>ap_enckey, key);
+		aes_setdeckey128(>ap_deckey, key);
+		ap->ap_nrounds = AES_128_NROUNDS;
+		break;
+	case 192:
+		aes_setenckey192(>ap_enckey, key);
+		aes_setdeckey192(>ap_deckey, key);
+		ap->ap_nrounds = AES_192_NROUNDS;
+		break;
+	case 256:
+		aes_setenckey256(>ap_enckey, key);
+		aes_setdeckey256(>ap_deckey, key);
+		ap->ap_nrounds = AES_256_NROUNDS;
+		break;
+	}
 	return ap;
 }
 
@@ -152,25 +168,18 @@ cgd_cipher_aes_cbc(void *privdata, void 
 {
 	struct aes_privdata	*apd = privdata;
 	uint8_t			 iv[CGD_AES_BLOCK_SIZE] = {0};
-	cipherInstance		 cipher;
-	int			 cipher_ok __diagused;
 
 	/* Compute the CBC IV as AES_k(blkno).  */
-	cipher_ok = rijndael_cipherInit(, MODE_ECB, NULL);
-	KASSERT(cipher_ok > 0);
-	rijndael_blockEncrypt(, >ap_enckey, blkno, /*nbits*/128,
-	iv);
+	aes_enc(>ap_enckey, blkno, iv, apd->ap_nrounds);
 
-	cipher_ok = rijndael_cipherInit(, MODE_CBC, iv);
-	KASSERT(cipher_ok > 0);
 	switch (dir) {
 	case CGD_CIPHER_ENCRYPT:
-		rijndael_blockEncrypt(, >ap_enckey, src,
-		/*nbits*/nbytes * 8, dst);
+		aes_cbc_enc(>ap_enckey, src, dst, nbytes, iv,
+		apd->ap_nrounds);
 		break;
 	case CGD_CIPHER_DECRYPT:
-		rijndael_blockDecrypt(, >ap_deckey, src,
-		/*nbits*/nbytes * 8, dst);
+		aes_cbc_dec(>ap_deckey, src, dst, nbytes, iv,
+		apd->ap_nrounds);
 		break;
 	default:
 		panic("%s: unrecognised direction %d", __func__, dir);
@@ -182,9 +191,10 @@ cgd_cipher_aes_cbc(void *privdata, void 
  */
 
 struct aesxts {
-	keyInstance	ax_enckey;
-	keyInstance	ax_deckey;
-	keyInstance	ax_tweakkey;
+	struct aesenc	ax_enckey;
+	struct aesdec	ax_deckey;
+	struct aesenc	ax_tweakkey;
+	uint32_t	ax_nrounds;
 };
 
 static void *
@@ -207,9 +217,20 @@ cgd_cipher_aes_xts_init(size_t keylen, c
 	key = xtskey;
 	key2 = key + keylen / CHAR_BIT;
 
-	rijndael_makeKey(>ax_enckey, DIR_ENCRYPT, keylen, key);
-	rijndael_makeKey(>ax_deckey, DIR_DECRYPT, keylen, key);
-	rijndael_makeKey(>ax_tweakkey, DIR_ENCRYPT, keylen, key2);
+	switch (keylen) {
+	case 128:
+		aes_setenckey128(>ax_enckey, key);
+		aes_setdeckey128(>ax_deckey, key);
+		aes_setenckey128(>ax_tweakkey, key2);
+		ax->ax_nrounds = AES_128_NROUNDS;
+		break;
+	case 256:
+		aes_setenckey256(>ax_enckey, key);
+		aes_setdeckey256(>ax_deckey, key);
+		aes_setenckey256(>ax_tweakkey, key2);
+		ax->ax_nrounds = AES_256_NROUNDS;
+		break;
+	}
 
 	return ax;
 }
@@ -229,25 +250,18 @@ 

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

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

Modified Files:
src/sys/arch/i386/conf: files.i386
src/sys/arch/i386/pci: glxsb.c

Log Message:
glxsb(4): Remove rijndael dependency.

This doesn't actually seem to depend on it in any way.

XXX Compile-tested only.


To generate a diff of this commit:
cvs rdiff -u -r1.403 -r1.404 src/sys/arch/i386/conf/files.i386
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/i386/pci/glxsb.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/i386/conf/files.i386
diff -u src/sys/arch/i386/conf/files.i386:1.403 src/sys/arch/i386/conf/files.i386:1.404
--- src/sys/arch/i386/conf/files.i386:1.403	Sat Apr 25 15:26:16 2020
+++ src/sys/arch/i386/conf/files.i386	Mon Jun 29 23:32:24 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i386,v 1.403 2020/04/25 15:26:16 bouyer Exp $
+#	$NetBSD: files.i386,v 1.404 2020/06/29 23:32:24 riastradh Exp $
 #
 # new style config file for i386 architecture
 #
@@ -416,7 +416,7 @@ obsolete	defparam opt_vesafb.h	VESAFB_WI
 obsolete	defflag	opt_vesafb.h	VESAFB_PM
 
 # AMD Geode LX Security Block
-device	glxsb: opencrypto, rijndael
+device	glxsb: opencrypto
 attach	glxsb at pci
 file	arch/i386/pci/glxsb.c		glxsb
 

Index: src/sys/arch/i386/pci/glxsb.c
diff -u src/sys/arch/i386/pci/glxsb.c:1.15 src/sys/arch/i386/pci/glxsb.c:1.16
--- src/sys/arch/i386/pci/glxsb.c:1.15	Sun Jun 14 23:19:11 2020
+++ src/sys/arch/i386/pci/glxsb.c	Mon Jun 29 23:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: glxsb.c,v 1.15 2020/06/14 23:19:11 riastradh Exp $	*/
+/*	$NetBSD: glxsb.c,v 1.16 2020/06/29 23:32:24 riastradh Exp $	*/
 /* $OpenBSD: glxsb.c,v 1.7 2007/02/12 14:31:45 tom Exp $ */
 
 /*
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: glxsb.c,v 1.15 2020/06/14 23:19:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: glxsb.c,v 1.16 2020/06/29 23:32:24 riastradh Exp $");
 
 #include 
 #include 
@@ -44,7 +44,6 @@ __KERNEL_RCSID(0, "$NetBSD: glxsb.c,v 1.
 #include 
 
 #include 
-#include 
 
 #define SB_GLD_MSR_CAP		0x58002000	/* RO - Capabilities */
 #define SB_GLD_MSR_CONFIG	0x58002001	/* RW - Master Config */



CVS commit: src/sys

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

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c
src/sys/arch/aarch64/conf: files.aarch64
Added Files:
src/sys/crypto/aes/arch/arm: aes_armv8.c aes_armv8.h aes_armv8_64.S
files.aesarmv8

Log Message:
Implement AES in kernel using ARMv8.0-AES on aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/aarch64/aarch64/cpu.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/conf/files.aarch64
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/arm/aes_armv8.c \
src/sys/crypto/aes/arch/arm/aes_armv8.h \
src/sys/crypto/aes/arch/arm/aes_armv8_64.S \
src/sys/crypto/aes/arch/arm/files.aesarmv8

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.48 src/sys/arch/aarch64/aarch64/cpu.c:1.49
--- src/sys/arch/aarch64/aarch64/cpu.c:1.48	Mon Jun 29 23:22:27 2020
+++ src/sys/arch/aarch64/aarch64/cpu.c	Mon Jun 29 23:31:41 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.48 2020/06/29 23:22:27 riastradh Exp $ */
+/* $NetBSD: cpu.c,v 1.49 2020/06/29 23:31:41 riastradh Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.48 2020/06/29 23:22:27 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.49 2020/06/29 23:31:41 riastradh Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -44,6 +44,8 @@ __KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.48
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -70,6 +72,7 @@ static void cpu_init_counter(struct cpu_
 static void cpu_setup_id(struct cpu_info *);
 static void cpu_setup_sysctl(device_t, struct cpu_info *);
 static void cpu_setup_rng(device_t, struct cpu_info *);
+static void cpu_setup_aes(device_t, struct cpu_info *);
 
 #ifdef MULTIPROCESSOR
 #define NCPUINFO	MAXCPUS
@@ -158,6 +161,7 @@ cpu_attach(device_t dv, cpuid_t id)
 
 	cpu_setup_sysctl(dv, ci);
 	cpu_setup_rng(dv, ci);
+	cpu_setup_aes(dv, ci);
 }
 
 struct cpuidtab {
@@ -589,6 +593,26 @@ cpu_setup_rng(device_t dv, struct cpu_in
 	RND_FLAG_DEFAULT|RND_FLAG_HASCB);
 }
 
+/*
+ * setup the AES implementation
+ */
+static void
+cpu_setup_aes(device_t dv, struct cpu_info *ci)
+{
+	struct aarch64_sysctl_cpu_id *id = >ci_id;
+
+	/* Verify that it is supported.  */
+	switch (__SHIFTOUT(id->ac_aa64isar0, ID_AA64ISAR0_EL1_AES)) {
+	case ID_AA64ISAR0_EL1_AES_AES:
+	case ID_AA64ISAR0_EL1_AES_PMUL:
+		break;
+	default:
+		return;
+	}
+
+	aes_md_init(_armv8_impl);
+}
+
 #ifdef MULTIPROCESSOR
 void
 cpu_hatch(struct cpu_info *ci)

Index: src/sys/arch/aarch64/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.22 src/sys/arch/aarch64/conf/files.aarch64:1.23
--- src/sys/arch/aarch64/conf/files.aarch64:1.22	Sat Apr 18 11:00:37 2020
+++ src/sys/arch/aarch64/conf/files.aarch64	Mon Jun 29 23:31:41 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.22 2020/04/18 11:00:37 skrll Exp $
+#	$NetBSD: files.aarch64,v 1.23 2020/06/29 23:31:41 riastradh Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -138,3 +138,6 @@ file	arch/aarch64/aarch64/netbsd32_sysca
 
 # profiling support
 file	dev/tprof/tprof_armv8.c			tprof	needs-flag
+
+# ARMv8.0-AES
+include "crypto/aes/arch/arm/files.aesarmv8"

Added files:

Index: src/sys/crypto/aes/arch/arm/aes_armv8.c
diff -u /dev/null src/sys/crypto/aes/arch/arm/aes_armv8.c:1.1
--- /dev/null	Mon Jun 29 23:31:42 2020
+++ src/sys/crypto/aes/arch/arm/aes_armv8.c	Mon Jun 29 23:31:41 2020
@@ -0,0 +1,259 @@
+/*	$NetBSD: aes_armv8.c,v 1.1 2020/06/29 23:31:41 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * 

CVS commit: src/sys

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

Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/x86: identcpu.c
Added Files:
src/sys/crypto/aes/arch/x86: aes_ni.c aes_ni.h aes_ni_64.S files.aesni

Log Message:
Add x86 AES-NI support.

Limited to amd64 for now.  In principle, AES-NI should work in 32-bit
mode, and there may even be some 32-bit-only CPUs that support
AES-NI, but that requires work to adapt the assembly.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/arch/x86/aes_ni.c \
src/sys/crypto/aes/arch/x86/aes_ni.h \
src/sys/crypto/aes/arch/x86/aes_ni_64.S \
src/sys/crypto/aes/arch/x86/files.aesni

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

Modified files:

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.111 src/sys/arch/x86/conf/files.x86:1.112
--- src/sys/arch/x86/conf/files.x86:1.111	Wed May  6 19:45:12 2020
+++ src/sys/arch/x86/conf/files.x86	Mon Jun 29 23:29:39 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.111 2020/05/06 19:45:12 bouyer Exp $
+#	$NetBSD: files.x86,v 1.112 2020/06/29 23:29:39 riastradh Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -165,3 +165,6 @@ file	arch/x86/pci/pciide_machdep.c	pciid
 
 file	arch/x86/pci/pci_bus_fixup.c	pci_bus_fixup
 file	arch/x86/pci/pci_addr_fixup.c	pci_addr_fixup
+
+# AES-NI
+include "crypto/aes/arch/x86/files.aesni"

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.107 src/sys/arch/x86/x86/identcpu.c:1.108
--- src/sys/arch/x86/x86/identcpu.c:1.107	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/x86/x86/identcpu.c	Mon Jun 29 23:29:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.107 2020/04/25 15:26:18 bouyer Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.108 2020/06/29 23:29:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.107 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.108 2020/06/29 23:29:39 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -39,6 +39,8 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
 #include 
 #include 
 
+#include 
+
 #include 
 
 #include 
@@ -995,6 +997,10 @@ cpu_probe(struct cpu_info *ci)
 		/* Early patch of text segment. */
 		x86_patch(true);
 #endif
+#ifdef __x86_64__	/* not yet implemented on i386 */
+		if (cpu_feature[1] & CPUID2_AES)
+			aes_md_init(_ni_impl);
+#endif
 	} else {
 		/*
 		 * If not first. Warn about cpu_feature mismatch for

Added files:

Index: src/sys/crypto/aes/arch/x86/aes_ni.c
diff -u /dev/null src/sys/crypto/aes/arch/x86/aes_ni.c:1.1
--- /dev/null	Mon Jun 29 23:29:40 2020
+++ src/sys/crypto/aes/arch/x86/aes_ni.c	Mon Jun 29 23:29:40 2020
@@ -0,0 +1,252 @@
+/*	$NetBSD: aes_ni.c,v 1.1 2020/06/29 23:29:40 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(1, "$NetBSD: aes_ni.c,v 1.1 2020/06/29 23:29:40 riastradh Exp $");
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static void
+aesni_setenckey(struct aesenc *enc, const uint8_t key[static 16],
+uint32_t nrounds)
+{
+
+	switch (nrounds) {
+	case 10:
+		aesni_setenckey128(enc, key);
+		break;
+	case 12:
+		

CVS commit: src/sys

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

Modified Files:
src/sys/conf: files
src/sys/rump/kern/lib/libcrypto: Makefile
Added Files:
src/sys/crypto/aes: aes.h aes_bear.c aes_bear.h aes_ct.c aes_ct_dec.c
aes_ct_enc.c aes_impl.c aes_rijndael.c aes_selftest.c files.aes
Removed Files:
src/sys/crypto/rijndael: files.rijndael rijndael-alg-fst.c
rijndael-api-fst.c rijndael.c rijndael_local.h

Log Message:
Rework AES in kernel to finally address CVE-2005-1797.

1. Rip out old variable-time reference implementation.
2. Replace it by BearSSL's constant-time 32-bit logic.
   => Obtained from commit dda1f8a0c46e15b4a235163470ff700b2f13dcc5.
   => We could conditionally adopt the 64-bit logic too, which would
  likely give a modest performance boost on 64-bit platforms
  without AES-NI, but that's a bit more trouble.
3. Select the AES implementation at boot-time; allow an MD override.
   => Use self-tests to verify basic correctness at boot.
   => The implementation selection policy is rather rudimentary at
  the moment but it is isolated to one place so it's easy to
  change later on.

This (a) plugs a host of timing attacks on, e.g., cgd, and (b) paves
the way to take advantage of CPU support for AES -- both things we
should've done a decade ago.  Downside: Computing AES takes 2-3x the
CPU time.  But that's what hardware support will be coming for.

Rudimentary measurement of performance impact done by:

mount -t tmpfs tmpfs /tmp
dd if=/dev/zero of=/tmp/disk bs=1m count=512
vnconfig -cv vnd0 /tmp/disk
cgdconfig -s cgd0 /dev/vnd0 aes-cbc 256 < /dev/zero
dd if=/dev/rcgd0d of=/dev/null bs=64k
dd if=/dev/zero of=/dev/rcgd0d bs=64k

The AES-CBC encryption performance impact is closer to 3x because it
is inherently sequential; the AES-CBC decryption impact is closer to
2x because the bitsliced AES logic can process two blocks at once.

Discussed on tech-kern:

https://mail-index.NetBSD.org/tech-kern/2020/06/18/msg026505.html


To generate a diff of this commit:
cvs rdiff -u -r1.1268 -r1.1269 src/sys/conf/files
cvs rdiff -u -r0 -r1.1 src/sys/crypto/aes/aes.h src/sys/crypto/aes/aes_bear.c \
src/sys/crypto/aes/aes_bear.h src/sys/crypto/aes/aes_ct.c \
src/sys/crypto/aes/aes_ct_dec.c src/sys/crypto/aes/aes_ct_enc.c \
src/sys/crypto/aes/aes_impl.c src/sys/crypto/aes/aes_rijndael.c \
src/sys/crypto/aes/aes_selftest.c src/sys/crypto/aes/files.aes
cvs rdiff -u -r1.7 -r0 src/sys/crypto/rijndael/files.rijndael \
src/sys/crypto/rijndael/rijndael-alg-fst.c
cvs rdiff -u -r1.25 -r0 src/sys/crypto/rijndael/rijndael-api-fst.c
cvs rdiff -u -r1.8 -r0 src/sys/crypto/rijndael/rijndael.c
cvs rdiff -u -r1.6 -r0 src/sys/crypto/rijndael/rijndael_local.h
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/kern/lib/libcrypto/Makefile

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

Modified files:

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1268 src/sys/conf/files:1.1269
--- src/sys/conf/files:1.1268	Sun Jun  7 09:45:19 2020
+++ src/sys/conf/files	Mon Jun 29 23:27:52 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1268 2020/06/07 09:45:19 maxv Exp $
+#	$NetBSD: files,v 1.1269 2020/06/29 23:27:52 riastradh Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20171118
@@ -200,10 +200,10 @@ defflag	opt_machdep.h		MACHDEP
 # use it.
 
 # Individual crypto transforms
+include "crypto/aes/files.aes"
 include "crypto/des/files.des"
 include "crypto/blowfish/files.blowfish"
 include "crypto/cast128/files.cast128"
-include "crypto/rijndael/files.rijndael"
 include "crypto/skipjack/files.skipjack"
 include "crypto/camellia/files.camellia"
 # General-purpose crypto processing framework.

Index: src/sys/rump/kern/lib/libcrypto/Makefile
diff -u src/sys/rump/kern/lib/libcrypto/Makefile:1.6 src/sys/rump/kern/lib/libcrypto/Makefile:1.7
--- src/sys/rump/kern/lib/libcrypto/Makefile:1.6	Thu Dec  5 03:57:55 2019
+++ src/sys/rump/kern/lib/libcrypto/Makefile	Mon Jun 29 23:27:52 2020
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.6 2019/12/05 03:57:55 riastradh Exp $
+#	$NetBSD: Makefile,v 1.7 2020/06/29 23:27:52 riastradh Exp $
 #
 
-.PATH:	${.CURDIR}/../../../../crypto/blowfish\
+.PATH:	${.CURDIR}/../../../../crypto/aes\
+	${.CURDIR}/../../../../crypto/blowfish\
 	${.CURDIR}/../../../../crypto/camellia\
 	${.CURDIR}/../../../../crypto/cast128\
 	${.CURDIR}/../../../../crypto/des\
-	${.CURDIR}/../../../../crypto/rijndael\
 	${.CURDIR}/../../../../crypto/skipjack
 
 LIB=	rumpkern_crypto
@@ -23,8 +23,14 @@ SRCS+=	cast128.c
 # DES
 SRCS+=	des_ecb.c des_setkey.c des_enc.c des_cbc.c des_module.c
 
-# rijndael
-SRCS+=	rijndael-alg-fst.c rijndael-api-fst.c rijndael.c
+# AES
+SRCS+=	aes_bear.c
+SRCS+=	aes_ct.c
+SRCS+=	aes_ct_dec.c
+SRCS+=	aes_ct_enc.c
+SRCS+=	aes_impl.c
+SRCS+=	aes_rijndael.c
+SRCS+=	aes_selftest.c
 
 # skipjack
 SRCS+=	skipjack.c


CVS commit: src/sys/arch/aarch64

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

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c fpu.c
src/sys/arch/aarch64/include: cpu.h machdep.h
Added Files:
src/sys/arch/aarch64/include: fpu.h

Log Message:
Draft fpu_kern_enter/leave on aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/aarch64/aarch64/cpu.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/fpu.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/aarch64/include/fpu.h
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/include/machdep.h

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.47 src/sys/arch/aarch64/aarch64/cpu.c:1.48
--- src/sys/arch/aarch64/aarch64/cpu.c:1.47	Sun Jun 14 16:10:18 2020
+++ src/sys/arch/aarch64/aarch64/cpu.c	Mon Jun 29 23:22:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.47 2020/06/14 16:10:18 riastradh Exp $ */
+/* $NetBSD: cpu.c,v 1.48 2020/06/29 23:22:27 riastradh Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.47 2020/06/14 16:10:18 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.48 2020/06/29 23:22:27 riastradh Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -133,6 +133,8 @@ cpu_attach(device_t dv, cpuid_t id)
 	ci->ci_dev = dv;
 	dv->dv_private = ci;
 
+	ci->ci_kfpu_spl = -1;
+
 	arm_cpu_do_topology(ci);
 	cpu_identify(ci->ci_dev, ci);
 

Index: src/sys/arch/aarch64/aarch64/fpu.c
diff -u src/sys/arch/aarch64/aarch64/fpu.c:1.3 src/sys/arch/aarch64/aarch64/fpu.c:1.4
--- src/sys/arch/aarch64/aarch64/fpu.c:1.3	Wed Nov  7 06:47:38 2018
+++ src/sys/arch/aarch64/aarch64/fpu.c	Mon Jun 29 23:22:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.3 2018/11/07 06:47:38 riastradh Exp $ */
+/* $NetBSD: fpu.c,v 1.4 2020/06/29 23:22:27 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,13 +31,15 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.3 2018/11/07 06:47:38 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.4 2020/06/29 23:22:27 riastradh Exp $");
 
 #include 
 #include 
 #include 
 #include 
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -172,3 +174,68 @@ fpu_state_release(lwp_t *l)
 	reg_cpacr_el1_write(CPACR_FPEN_NONE);
 	__asm __volatile ("isb");
 }
+
+void
+fpu_kern_enter(void)
+{
+	struct lwp *l = curlwp;
+	struct cpu_info *ci;
+	int s;
+
+	/*
+	 * Block all interrupts.  We must block preemption since -- if
+	 * this is a user thread -- there is nowhere to save the kernel
+	 * fpu state, and if we want this to be usable in interrupts,
+	 * we can't let interrupts interfere with the fpu state in use
+	 * since there's nowhere for them to save it.
+	 */
+	s = splhigh();
+	ci = curcpu();
+	KASSERT(ci->ci_kfpu_spl == -1);
+	ci->ci_kfpu_spl = s;
+
+	/*
+	 * If we are in a softint and have a pinned lwp, the fpu state
+	 * is that of the pinned lwp, so save it there.
+	 */
+	if ((l->l_pflag & LP_INTR) && (l->l_switchto != NULL))
+		l = l->l_switchto;
+	if (fpu_used_p(l))
+		fpu_save(l);
+
+	/*
+	 * Enable the fpu, and wait until it is enabled before
+	 * executing any further instructions.
+	 */
+	reg_cpacr_el1_write(CPACR_FPEN_ALL);
+	arm_isb();
+}
+
+void
+fpu_kern_leave(void)
+{
+	static const struct fpreg zero_fpreg;
+	struct cpu_info *ci = curcpu();
+	int s;
+
+	KASSERT(ci->ci_cpl == IPL_HIGH);
+	KASSERT(ci->ci_kfpu_spl != -1);
+
+	/*
+	 * Zero the fpu registers; otherwise we might leak secrets
+	 * through Spectre-class attacks to userland, even if there are
+	 * no bugs in fpu state management.
+	 */
+	load_fpregs(_fpreg);
+
+	/*
+	 * Disable the fpu so that the kernel can't accidentally use
+	 * it again.
+	 */
+	reg_cpacr_el1_write(CPACR_FPEN_NONE);
+	arm_isb();
+
+	s = ci->ci_kfpu_spl;
+	ci->ci_kfpu_spl = -1;
+	splx(s);
+}

Index: src/sys/arch/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.22 src/sys/arch/aarch64/include/cpu.h:1.23
--- src/sys/arch/aarch64/include/cpu.h:1.22	Tue Mar 10 01:17:33 2020
+++ src/sys/arch/aarch64/include/cpu.h	Mon Jun 29 23:22:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.22 2020/03/10 01:17:33 christos Exp $ */
+/* $NetBSD: cpu.h,v 1.23 2020/06/29 23:22:27 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -89,6 +89,8 @@ struct cpu_info {
 	volatile u_int ci_astpending;
 	volatile u_int ci_intr_depth;
 
+	int ci_kfpu_spl;
+
 	/* event counters */
 	struct evcnt ci_vfp_use;
 	struct evcnt ci_vfp_reuse;

Index: src/sys/arch/aarch64/include/machdep.h
diff -u src/sys/arch/aarch64/include/machdep.h:1.11 src/sys/arch/aarch64/include/machdep.h:1.12
--- src/sys/arch/aarch64/include/machdep.h:1.11	Sat May 23 18:08:59 2020
+++ 

CVS commit: src

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

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S
src/sys/dev/scsipi: if_se.c
src/usr.sbin/postinstall: postinstall.in

Log Message:
Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/amd64/amd64/amd64_trap.S
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/scsipi/if_se.c
cvs rdiff -u -r1.29 -r1.30 src/usr.sbin/postinstall/postinstall.in

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

Modified files:

Index: src/sys/arch/amd64/amd64/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.52 src/sys/arch/amd64/amd64/amd64_trap.S:1.53
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.52	Sun Jun 21 16:57:18 2020
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Mon Jun 29 23:04:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.52 2020/06/21 16:57:18 bouyer Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.53 2020/06/29 23:04:56 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -452,7 +452,7 @@ IDTVEC(trap16)
 	/* traps are called with interrupts enabled, and we may have been
 	 * interrupted just before the CLI in the trap macro.
 	 * we have to check if a FPU reload is needed.
-	 */ 
+	 */
 	movqCPUVAR(CURLWP),%r14
 	HANDLE_DEFERRED_FPU
 #endif /* XENPV */

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.107 src/sys/dev/scsipi/if_se.c:1.108
--- src/sys/dev/scsipi/if_se.c:1.107	Mon Jun 22 17:38:27 2020
+++ src/sys/dev/scsipi/if_se.c	Mon Jun 29 23:04:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.107 2020/06/22 17:38:27 jdc Exp $	*/
+/*	$NetBSD: if_se.c,v 1.108 2020/06/29 23:04:57 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.107 2020/06/22 17:38:27 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.108 2020/06/29 23:04:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -374,7 +374,7 @@ seattach(device_t parent, device_t self,
 		sedetach(sc->sc_dev, 0);
 		return; /* Error */
 	}
-	
+
 	snprintf(wqname, sizeof(wqname), "%sRx", device_xname(sc->sc_dev));
 	rv = workqueue_create(>sc_recv_wq, wqname, se_recv_worker, sc,
 	PRI_SOFTNET, IPL_NET, WQ_MPSAFE);

Index: src/usr.sbin/postinstall/postinstall.in
diff -u src/usr.sbin/postinstall/postinstall.in:1.29 src/usr.sbin/postinstall/postinstall.in:1.30
--- src/usr.sbin/postinstall/postinstall.in:1.29	Mon Jun 22 06:55:41 2020
+++ src/usr.sbin/postinstall/postinstall.in	Mon Jun 29 23:04:57 2020
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall.in,v 1.29 2020/06/22 06:55:41 rin Exp $
+# $NetBSD: postinstall.in,v 1.30 2020/06/29 23:04:57 riastradh Exp $
 #
 # Copyright (c) 2002-2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -873,7 +873,7 @@ do_blocklist()
 {
 	[ -n "$1" ] || err 3 "USAGE: do_blocklist  fix|check"
 	local op="$1"
-	
+
 	# if we are actually using blocklistd
 	for i in /var/db/blacklist.db /etc/blacklistd.conf; do
 		local old="${DEST_DIR}${i}"



CVS commit: src/usr.bin/printf

2020-06-29 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Jun 29 22:50:11 UTC 2020

Modified Files:
src/usr.bin/printf: printf.1

Log Message:
Add quotes around command substitution in the example
so that it works regardless of IFS and buts.
Requested by kre@


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/printf/printf.1

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

Modified files:

Index: src/usr.bin/printf/printf.1
diff -u src/usr.bin/printf/printf.1:1.34 src/usr.bin/printf/printf.1:1.35
--- src/usr.bin/printf/printf.1:1.34	Fri Jun 26 22:05:05 2020
+++ src/usr.bin/printf/printf.1	Mon Jun 29 22:50:11 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: printf.1,v 1.34 2020/06/26 22:05:05 uwe Exp $
+.\"	$NetBSD: printf.1,v 1.35 2020/06/29 22:50:11 uwe Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -473,4 +473,4 @@ invocation uses the octal string as part
 For example, the following command outputs the character whose code
 is 0x0a, which is a newline in ASCII:
 .Pp
-.Dl printf $(printf \(aq\e\e%o\(aq 0x0a)
+.Dl printf \*q$(printf \(aq\e\e%o\(aq 0x0a)\*q



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

2020-06-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 29 21:45:50 UTC 2020

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

Log Message:
when using two linked requests for I/O (i.e. when backend doesn't support
INDIRECT segments), make sure to clear req_bp for both of them

fixes a misfired assertion in BLKIF_OP_FLUSH_DISKCACHE - PR port-xen/55431


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/xen/xen/xbd_xenbus.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/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.127 src/sys/arch/xen/xen/xbd_xenbus.c:1.128
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.127	Wed May 13 16:17:46 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Mon Jun 29 21:45:50 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $  */
+/*  $NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.127 2020/05/13 16:17:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.128 2020/06/29 21:45:50 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -832,6 +832,7 @@ again:
 		}
 
 		bp = xbdreq->req_bp;
+		xbdreq->req_bp = NULL;
 		KASSERT(bp != NULL && bp->b_data != NULL);
 		DPRINTF(("%s(%p): b_bcount = %ld\n", __func__,
 		bp, (long)bp->b_bcount));
@@ -887,7 +888,7 @@ again:
 
 		if (__predict_false(bp->b_data != xbdreq->req_data))
 			xbd_unmap_align(sc, xbdreq, true);
-		xbdreq->req_bp = xbdreq->req_data = NULL;
+		xbdreq->req_data = NULL;
 
 		dk_done(>sc_dksc, bp);
 



CVS commit: src/tests/lib/libc/stdlib

2020-06-29 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Mon Jun 29 20:53:40 UTC 2020

Modified Files:
src/tests/lib/libc/stdlib: t_mbtowc.c

Log Message:
Avoid copyright issues and name the listed author as the copyright holder.

In a private email, Miloslav had agreed that if they had written the
test, then it can be licensed bsd-2-clause. I am going to assume this
is true as the file names Miloslav as the author.

This test was likely sent to tcsh (not netbsd) that had changed bug
report systems since.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/stdlib/t_mbtowc.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/libc/stdlib/t_mbtowc.c
diff -u src/tests/lib/libc/stdlib/t_mbtowc.c:1.2 src/tests/lib/libc/stdlib/t_mbtowc.c:1.3
--- src/tests/lib/libc/stdlib/t_mbtowc.c:1.2	Sat Jun 27 10:19:43 2020
+++ src/tests/lib/libc/stdlib/t_mbtowc.c	Mon Jun 29 20:53:40 2020
@@ -1,22 +1,23 @@
-/*	$NetBSD: t_mbtowc.c,v 1.2 2020/06/27 10:19:43 jruoho Exp $ */
+/*	$NetBSD: t_mbtowc.c,v 1.3 2020/06/29 20:53:40 maya Exp $ */
 
 /*-
- * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 2005 Miloslav Trmac
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
+
  * 1. Redistributions of source code must retain the above copyright
  *notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *notice, this list of conditions and the following disclaimer in the
  *documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS



CVS commit: src/sys/arch/ia64/include

2020-06-29 Thread Sean Cole
Module Name:src
Committed By:   scole
Date:   Mon Jun 29 17:09:33 UTC 2020

Modified Files:
src/sys/arch/ia64/include: mcontext.h

Log Message:
Fix for last checkin, don't try use non-existent register from a (currently) 
dummy struct


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/ia64/include/mcontext.h

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

Modified files:

Index: src/sys/arch/ia64/include/mcontext.h
diff -u src/sys/arch/ia64/include/mcontext.h:1.11 src/sys/arch/ia64/include/mcontext.h:1.12
--- src/sys/arch/ia64/include/mcontext.h:1.11	Mon Jun 29 01:37:27 2020
+++ src/sys/arch/ia64/include/mcontext.h	Mon Jun 29 17:09:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.11 2020/06/29 01:37:27 scole Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.12 2020/06/29 17:09:33 scole Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -114,7 +114,7 @@ typedef struct __mcontext {
 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.mc_special.sp)  /* gregs[12] */
 #define _UC_MACHINE_FP(uc)	0 /* Not supported in target */
 #define	_UC_MACHINE_PC(uc)	((uc)->uc_mcontext.mc_special.iip)
-#define	_UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[8])
+#define	_UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.mc_scratch.gr8) /* gregs[8] */
 #define _UC_MACHINE_SET_PC(uc, pc)	(uc)->uc_mcontext.mc_special.iip = (pc)
 
 #if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \



CVS commit: src/tests/lib/libc

2020-06-29 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Mon Jun 29 14:22:11 UTC 2020

Modified Files:
src/tests/lib/libc/stdio: Makefile
src/tests/lib/libc/stdlib: Makefile

Log Message:
Use -Wl,--no-fatal-warnings for the mktemp(3) test.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libc/stdio/Makefile
cvs rdiff -u -r1.30 -r1.31 src/tests/lib/libc/stdlib/Makefile

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/libc/stdio/Makefile
diff -u src/tests/lib/libc/stdio/Makefile:1.13 src/tests/lib/libc/stdio/Makefile:1.14
--- src/tests/lib/libc/stdio/Makefile:1.13	Sat Jun 27 09:45:57 2020
+++ src/tests/lib/libc/stdio/Makefile	Mon Jun 29 14:22:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.13 2020/06/27 09:45:57 jruoho Exp $
+# $NetBSD: Makefile,v 1.14 2020/06/29 14:22:11 jruoho Exp $
 
 .include 
 
@@ -15,6 +15,4 @@ TESTS_C+=	t_printf
 TESTS_C+=	t_scanf
 COPTS.t_printf.c += -Wno-format-nonliteral
 
-LDADD.t_mktemp+=	-Wl,--no-fatal-warnings
-
 .include 

Index: src/tests/lib/libc/stdlib/Makefile
diff -u src/tests/lib/libc/stdlib/Makefile:1.30 src/tests/lib/libc/stdlib/Makefile:1.31
--- src/tests/lib/libc/stdlib/Makefile:1.30	Sat Jun 27 10:14:10 2020
+++ src/tests/lib/libc/stdlib/Makefile	Mon Jun 29 14:22:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.30 2020/06/27 10:14:10 jruoho Exp $
+# $NetBSD: Makefile,v 1.31 2020/06/29 14:22:11 jruoho Exp $
 
 .include 
 
@@ -35,6 +35,7 @@ CPPFLAGS.t_strtod.c+=  -D__TEST_FENV
 LDADD.t_strtod=			-lm
 DPADD.t_strtod+=		${LIBM}
 
-LDADD.t_getenv_thread=		-lpthread
+LDADD.t_getenv_thread=	-lpthread
+LDADD.t_mktemp+=	-Wl,--no-fatal-warnings
 
 .include 



CVS commit: src/usr.bin/cal

2020-06-29 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Mon Jun 29 14:01:14 UTC 2020

Modified Files:
src/usr.bin/cal: cal.c

Log Message:
Use two-letter weekday abbreviations in the heading

This matches output from ncal (a.k.a. cal) as found in FreeBSD and
bsdmainutils. (Why had "T" been found more ambiguous than "S" already?)


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/cal/cal.c

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

Modified files:

Index: src/usr.bin/cal/cal.c
diff -u src/usr.bin/cal/cal.c:1.29 src/usr.bin/cal/cal.c:1.30
--- src/usr.bin/cal/cal.c:1.29	Tue Jun 16 22:54:10 2015
+++ src/usr.bin/cal/cal.c	Mon Jun 29 14:01:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $	*/
+/*	$NetBSD: cal.c,v 1.30 2020/06/29 14:01:14 kim Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)cal.c	8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $");
+__RCSID("$NetBSD: cal.c,v 1.30 2020/06/29 14:01:14 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,8 +88,8 @@ static const char *month_names[12] = {
 	"July", "August", "September", "October", "November", "December",
 };
 
-static const char *day_headings = " S  M Tu  W Th  F  S";
-static const char *j_day_headings = "  S   M  Tu   W  Th   F   S";
+static const char *day_headings = "Su Mo Tu We Th Fr Sa";
+static const char *j_day_headings = " Su  Mo  Tu  We  Th  Fr  Sa";
 
 /* leap years according to the julian calendar */
 #define j_leap_year(y, m, d) \



CVS commit: src/share/wscons/fonts

2020-06-29 Thread Frederic Cambus
Module Name:src
Committed By:   fcambus
Date:   Mon Jun 29 09:57:46 UTC 2020

Modified Files:
src/share/wscons/fonts: spleen-5x8.fnt.uue

Log Message:
Update Spleen wscons fonts to version 1.8.0, bringing the following
improvements:

- Improve ampersand character, making it more consistent with other
  sizes (5x8 version)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/wscons/fonts/spleen-5x8.fnt.uue

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

Modified files:

Index: src/share/wscons/fonts/spleen-5x8.fnt.uue
diff -u src/share/wscons/fonts/spleen-5x8.fnt.uue:1.1 src/share/wscons/fonts/spleen-5x8.fnt.uue:1.2
--- src/share/wscons/fonts/spleen-5x8.fnt.uue:1.1	Sun Jun 28 14:26:18 2020
+++ src/share/wscons/fonts/spleen-5x8.fnt.uue	Mon Jun 29 09:57:46 2020
@@ -5,7 +5,7 @@ M```
 M
 M
 M("`@("``
-M(`!04%!0^%!0^%``('"@8#`PX"`0D*`@0%"0@"!04&"@D&@`("`@
+M(`!04%!0^%!0^%``('"@8#`PX"`0D*`@0%"0@"!04&"HD&@`("`@
 M```0($!`0$`@$$`@$!`0$"!```"08/!@D"`@^"`@("!`
 M`/`@`!`0("!`0("``&"0L-"08```(&`@("!P``!@D!!@
 M@/```&"0(!"08```@*"@\"`@``#P@.`0$.```&"`X)"08```\)`0($!```!@



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

2020-06-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 29 09:56:51 UTC 2020

Modified Files:
src/sys/arch/amd64/include: param.h

Log Message:
increase UPAGES (used for lwp kernel stack) for SVS so the the
amount of actually usable kernel stack is the same for SVS and
non-SVS kernels (currently 12 KiB)

discussed with maxv@, part of investigation for PR kern/S55402


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/include/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/arch/amd64/include/param.h
diff -u src/sys/arch/amd64/include/param.h:1.37 src/sys/arch/amd64/include/param.h:1.38
--- src/sys/arch/amd64/include/param.h:1.37	Tue Mar 17 17:18:49 2020
+++ src/sys/arch/amd64/include/param.h	Mon Jun 29 09:56:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.37 2020/03/17 17:18:49 maxv Exp $	*/
+/*	$NetBSD: param.h,v 1.38 2020/06/29 09:56:51 jdolecek Exp $	*/
 
 #ifdef __x86_64__
 
@@ -12,6 +12,7 @@
 #if defined(_KERNEL_OPT)
 #include "opt_kasan.h"
 #include "opt_kmsan.h"
+#include "opt_svs.h"
 #endif
 #endif
 
@@ -69,6 +70,8 @@
 
 #if defined(KASAN) || defined(KMSAN)
 #define	UPAGES		8
+#elif defined(SVS)
+#define	UPAGES		6		/* 1 page used internally by SVS */
 #else
 #define	UPAGES		5		/* pages of u-area (1 for redzone) */
 #endif



CVS commit: src/sys/dev/wsfont

2020-06-29 Thread Frederic Cambus
Module Name:src
Committed By:   fcambus
Date:   Mon Jun 29 09:45:35 UTC 2020

Modified Files:
src/sys/dev/wsfont: spleen5x8.h

Log Message:
Update Spleen kernel fonts to version 1.8.0, bringing the following
improvements:

- Improve ampersand character, making it more consistent with other
  sizes (5x8 version)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/wsfont/spleen5x8.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/dev/wsfont/spleen5x8.h
diff -u src/sys/dev/wsfont/spleen5x8.h:1.4 src/sys/dev/wsfont/spleen5x8.h:1.5
--- src/sys/dev/wsfont/spleen5x8.h:1.4	Sun Jun 21 15:48:17 2020
+++ src/sys/dev/wsfont/spleen5x8.h	Mon Jun 29 09:45:35 2020
@@ -1,8 +1,8 @@
-/*	$NetBSD: spleen5x8.h,v 1.4 2020/06/21 15:48:17 fcambus Exp $ */
+/*	$NetBSD: spleen5x8.h,v 1.5 2020/06/29 09:45:35 fcambus Exp $ */
 /*	$OpenBSD: spleen5x8.h,v 1.2 2018/12/02 14:47:23 fcambus Exp $ */
 
 /*
- * Copyright (c) 2018-2019 Frederic Cambus 
+ * Copyright (c) 2018-2020 Frederic Cambus 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -101,7 +101,7 @@ static u_char spleen5x8_data[] = {
 	0x50, 	/* .*.* */
 	0x50, 	/* .*.* */
 	0x60, 	/* .**. */
-	0xa0, 	/* *.*. */
+	0xa8, 	/* *.*.*... */
 	0x90, 	/* *..* */
 	0x68, 	/* .**.*... */
 	0x00, 	/*  */



CVS commit: src/sys/dev/i2c

2020-06-29 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 29 09:24:07 UTC 2020

Modified Files:
src/sys/dev/i2c: sdtemp.c

Log Message:
 Check the return value of iic_acquire_bus(). This function may fail.

 One of the case is driver's detaching phase on shutdown. mutex_tryenter()
might fail and return with EBUSY. To avoid calling iic_release_bus() without
taking lock, check the return value of iic_acquire_bus().


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/i2c/sdtemp.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/i2c/sdtemp.c
diff -u src/sys/dev/i2c/sdtemp.c:1.37 src/sys/dev/i2c/sdtemp.c:1.38
--- src/sys/dev/i2c/sdtemp.c:1.37	Mon Jun 29 06:01:30 2020
+++ src/sys/dev/i2c/sdtemp.c	Mon Jun 29 09:24:07 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $*/
+/*  $NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.38 2020/06/29 09:24:07 msaitoh Exp $");
 
 #include 
 #include 
@@ -218,7 +218,9 @@ sdtemp_match(device_t parent, cfdata_t c
 	 * Verify that we can read the manufacturer ID, Device ID and the
 	 * capability
 	 */
-	iic_acquire_bus(sc.sc_tag, 0);
+	error = iic_acquire_bus(sc.sc_tag, 0);
+	if (error)
+		return 0;
 	error = sdtemp_read_16(, SDTEMP_REG_MFG_ID,  ) |
 		sdtemp_read_16(, SDTEMP_REG_DEV_REV, ) |
 		sdtemp_read_16(, SDTEMP_REG_CAPABILITY, );
@@ -258,7 +260,10 @@ sdtemp_attach(device_t parent, device_t 
 	sc->sc_address = ia->ia_addr;
 	sc->sc_dev = self;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error)
+		return;
+
 	if ((error = sdtemp_read_16(sc, SDTEMP_REG_MFG_ID,  )) != 0 ||
 	(error = sdtemp_read_16(sc, SDTEMP_REG_DEV_REV, )) != 0) {
 		iic_release_bus(sc->sc_tag, 0);
@@ -426,7 +431,9 @@ sdtemp_get_limits(struct sysmon_envsys *
 	uint16_t lim;
 
 	*props = 0;
-	iic_acquire_bus(sc->sc_tag, 0);
+	if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+		return;
+
 	if (sdtemp_read_16(sc, SDTEMP_REG_LOWER_LIM, ) == 0 && lim != 0) {
 		limits->sel_warnmin = sdtemp_decode_temp(sc, lim);
 		*props |= PROP_WARNMIN;
@@ -456,7 +463,9 @@ sdtemp_set_limits(struct sysmon_envsys *
 		limits = >sc_deflims;
 		props  = >sc_defprops;
 	}
-	iic_acquire_bus(sc->sc_tag, 0);
+	if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+		return;
+
 	if (*props & PROP_WARNMIN) {
 		val = __UK2C(limits->sel_warnmin);
 		(void)sdtemp_write_16(sc, SDTEMP_REG_LOWER_LIM,
@@ -568,7 +577,10 @@ sdtemp_refresh(struct sysmon_envsys *sme
 	uint16_t val;
 	int error;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error)
+		return;
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, );
 	iic_release_bus(sc->sc_tag, 0);
 
@@ -610,7 +622,10 @@ sdtemp_pmf_suspend(device_t dev, const p
 	int error;
 	uint16_t config;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error != 0)
+		return false;
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, );
 	if (error == 0) {
 		config |= SDTEMP_CONFIG_SHUTDOWN_MODE;
@@ -627,7 +642,10 @@ sdtemp_pmf_resume(device_t dev, const pm
 	int error;
 	uint16_t config;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error != 0)
+		return false;
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, );
 	if (error == 0) {
 		config &= ~SDTEMP_CONFIG_SHUTDOWN_MODE;



CVS commit: src/external/bsd/kyua-cli/tests/kyua-cli

2020-06-29 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jun 29 08:55:00 UTC 2020

Modified Files:
src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/cli: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/engine: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/engine/drivers: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/examples: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/integration/helpers: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/store: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/cmdline: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/config: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/format: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/fs: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/logging: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/process: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/signals: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/sqlite: Makefile
src/external/bsd/kyua-cli/tests/kyua-cli/utils/text: Makefile

Log Message:
kyua-cli: fix build of .cpp files

Fix assignment of SRCS for C++ sources that use .cpp instead of .cc.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/engine/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/engine/drivers/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/examples/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/integration/helpers/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/store/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/cmdline/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/config/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/format/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/fs/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/logging/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/process/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/signals/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/sqlite/Makefile
cvs rdiff -u -r1.1 -r1.2 \
src/external/bsd/kyua-cli/tests/kyua-cli/utils/text/Makefile

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

Modified files:

Index: src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile
diff -u src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile:1.1 src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile:1.2
--- src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile:1.1	Sat Feb 23 14:16:55 2013
+++ src/external/bsd/kyua-cli/tests/kyua-cli/bootstrap/Makefile	Mon Jun 29 08:54:58 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2013/02/23 14:16:55 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2020/06/29 08:54:58 lukem Exp $
 
 .include 
 
@@ -12,12 +12,14 @@ FILESDIR=		${TESTSDIR}
 FILESMODE=		${BINMODE}
 
 PROGS_CXX=		atf_helpers
+SRCS.atf_helpers=	atf_helpers.cpp
 BINDIR.atf_helpers=	${TESTSDIR}
 MAN.atf_helpers=	# none
 LDADD.atf_helpers=	-latf-c++ -latf-c
 DPADD.atf_helpers=	${LIBATF_CXX} ${LIBATF_C}
 
 PROGS_CXX+=		plain_helpers
+SRCS.plain_helpers=	plain_helpers.cpp
 BINDIR.plain_helpers=	${TESTSDIR}
 MAN.plain_helpers=	# none
 

Index: src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile
diff -u src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile:1.1 src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile:1.2
--- src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile:1.1	Sat Feb 23 14:16:55 2013
+++ src/external/bsd/kyua-cli/tests/kyua-cli/cli/Makefile	Mon Jun 29 08:54:58 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2013/02/23 14:16:55 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2020/06/29 08:54:58 lukem Exp $
 
 KYUA_LIBS=	cli engine store engine utils
 
@@ -8,7 +8,9 @@ TESTSDIR=	${TESTSBASE}/kyua-cli/cli
 
 .PATH:		${SRCDIR}/cli
 
-TESTS_CXX=	cmd_about_test \
+TESTS_CXX=
+.for test in	\
+		cmd_about_test \
 		cmd_config_test \
 		cmd_db_exec_test \
 		cmd_db_migrate_test \
@@ -21,5 +23,8 @@ TESTS_CXX=	cmd_about_test \
 		common_test \
 		config_test \
 		main_test
+TESTS_CXX+=	${test}
+SRCS.${test}=	${test}.cpp
+.endfor

CVS commit: src/external/gpl3/gcc/usr.bin

2020-06-29 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jun 29 08:34:17 UTC 2020

Modified Files:
src/external/gpl3/gcc/usr.bin/cc1: Makefile
src/external/gpl3/gcc/usr.bin/cc1obj: Makefile
src/external/gpl3/gcc/usr.bin/cc1plus: Makefile

Log Message:
Fix addition of C++ .cc source to SRCS

Fix assumption that all of the source files are .c, as some are .cc.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/external/gpl3/gcc/usr.bin/cc1/Makefile
cvs rdiff -u -r1.15 -r1.16 src/external/gpl3/gcc/usr.bin/cc1obj/Makefile
cvs rdiff -u -r1.12 -r1.13 src/external/gpl3/gcc/usr.bin/cc1plus/Makefile

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

Modified files:

Index: src/external/gpl3/gcc/usr.bin/cc1/Makefile
diff -u src/external/gpl3/gcc/usr.bin/cc1/Makefile:1.17 src/external/gpl3/gcc/usr.bin/cc1/Makefile:1.18
--- src/external/gpl3/gcc/usr.bin/cc1/Makefile:1.17	Tue Apr 28 05:45:15 2020
+++ src/external/gpl3/gcc/usr.bin/cc1/Makefile	Mon Jun 29 08:34:17 2020
@@ -1,7 +1,8 @@
-#	$NetBSD: Makefile,v 1.17 2020/04/28 05:45:15 mrg Exp $
+#	$NetBSD: Makefile,v 1.18 2020/06/29 08:34:17 lukem Exp $
 
 PROG=		cc1
-SRCS=		${G_C_OBJS:S,c-family/,,:S,c/,,:Nlibcpp.a:.o=.c} main.c ${PROG}-checksum.c
+SRCS=		${G_C_OBJS:S,c-family/,,:S,c/,,:S,known-headers.o,known-headers.cc,:S,c-spellcheck.o,c-spellcheck.cc,:Nlibcpp.a:.o=.c}
+SRCS+=		main.c ${PROG}-checksum.c
 CPPFLAGS+=	-DPREFIX=\"/usr\"
 
 .include "../Makefile.backend"

Index: src/external/gpl3/gcc/usr.bin/cc1obj/Makefile
diff -u src/external/gpl3/gcc/usr.bin/cc1obj/Makefile:1.15 src/external/gpl3/gcc/usr.bin/cc1obj/Makefile:1.16
--- src/external/gpl3/gcc/usr.bin/cc1obj/Makefile:1.15	Tue Apr 28 07:47:54 2020
+++ src/external/gpl3/gcc/usr.bin/cc1obj/Makefile	Mon Jun 29 08:34:17 2020
@@ -1,8 +1,9 @@
-#	$NetBSD: Makefile,v 1.15 2020/04/28 07:47:54 mrg Exp $
+#	$NetBSD: Makefile,v 1.16 2020/06/29 08:34:17 lukem Exp $
 
 MYOBJS=		${G_OBJC_OBJS} ${G_C_AND_OBJC_OBJS} 
 PROG=		cc1obj
-SRCS=		${MYOBJS:S,objc/,,:S,c-family/,,:S,c/,,:Nlibcpp.a:.o=.c} main.c ${PROG}-checksum.c
+SRCS=		${MYOBJS:S,objc/,,:S,c-family/,,:S,c/,,:S,known-headers.o,known-headers.cc,:S,c-spellcheck.o,c-spellcheck.cc,:Nlibcpp.a:.o=.c}
+SRCS+=		main.c ${PROG}-checksum.c
 
 CPPFLAGS+=	-I${DIST}/gcc/objc
 CPPFLAGS.prefix.c+=	-DPREFIX=\"/usr\"

Index: src/external/gpl3/gcc/usr.bin/cc1plus/Makefile
diff -u src/external/gpl3/gcc/usr.bin/cc1plus/Makefile:1.12 src/external/gpl3/gcc/usr.bin/cc1plus/Makefile:1.13
--- src/external/gpl3/gcc/usr.bin/cc1plus/Makefile:1.12	Tue Apr 28 07:47:54 2020
+++ src/external/gpl3/gcc/usr.bin/cc1plus/Makefile	Mon Jun 29 08:34:17 2020
@@ -1,7 +1,8 @@
-#	$NetBSD: Makefile,v 1.12 2020/04/28 07:47:54 mrg Exp $
+#	$NetBSD: Makefile,v 1.13 2020/06/29 08:34:17 lukem Exp $
 
 PROG=		cc1plus
-SRCS=		${G_CXX_OBJS:S,c-family/,,:S,cp/,,:Nlibcpp.a:.o=.c} main.c ${PROG}-checksum.c
+SRCS=		${G_CXX_OBJS:S,c-family/,,:S,cp/,,:S,constraint.o,constraint.cc,:S,logic.o,logic.cc,:S,known-headers.o,known-headers.cc,:S,c-spellcheck.o,c-spellcheck.cc,:Nlibcpp.a:.o=.c}
+SRCS+=		main.c ${PROG}-checksum.c
 
 # XXX
 NOMAN=	1



CVS commit: src/external/gpl3/gcc/usr.bin/lto-wrapper

2020-06-29 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jun 29 08:30:42 UTC 2020

Modified Files:
src/external/gpl3/gcc/usr.bin/lto-wrapper: Makefile

Log Message:
use ggc-none.c not ggc-none.o in SRCS


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile

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

Modified files:

Index: src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile
diff -u src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile:1.4 src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile:1.5
--- src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile:1.4	Fri Feb  1 10:34:19 2019
+++ src/external/gpl3/gcc/usr.bin/lto-wrapper/Makefile	Mon Jun 29 08:30:42 2020
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.4 2019/02/01 10:34:19 mrg Exp $
+#	$NetBSD: Makefile,v 1.5 2020/06/29 08:30:42 lukem Exp $
 
 NOMAN=1
 PROG=		lto-wrapper
 # XXX pullout from LTO_WRAPPER_OBJS
 SRCS=		lto-wrapper.c \
 		collect-utils.c \
-		ggc-none.o
+		ggc-none.c
 
 BINDIR=		/usr/libexec
 



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jun 29 06:51:32 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Remove evcnt(9) counter for tlbhit; there's no way to observe TLB hits
from kernel, and it just counted intersection b/w tlbmiss and tlbenter.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/powerpc/ibm4xx/pmap.c

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

Modified files:

Index: src/sys/arch/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.88 src/sys/arch/powerpc/ibm4xx/pmap.c:1.89
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.88	Fri Jun 19 07:31:59 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Mon Jun 29 06:51:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.88 2020/06/19 07:31:59 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.89 2020/06/29 06:51:32 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.88 2020/06/19 07:31:59 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.89 2020/06/29 06:51:32 rin Exp $");
 
 #include 
 #include 
@@ -123,14 +123,11 @@ static int pmap_bootstrap_done = 0;
 /* Event counters */
 struct evcnt tlbmiss_ev = EVCNT_INITIALIZER(EVCNT_TYPE_TRAP,
 	NULL, "cpu", "tlbmiss");
-struct evcnt tlbhit_ev = EVCNT_INITIALIZER(EVCNT_TYPE_TRAP,
-	NULL, "cpu", "tlbhit");
 struct evcnt tlbflush_ev = EVCNT_INITIALIZER(EVCNT_TYPE_TRAP,
 	NULL, "cpu", "tlbflush");
 struct evcnt tlbenter_ev = EVCNT_INITIALIZER(EVCNT_TYPE_TRAP,
 	NULL, "cpu", "tlbenter");
 EVCNT_ATTACH_STATIC(tlbmiss_ev);
-EVCNT_ATTACH_STATIC(tlbhit_ev);
 EVCNT_ATTACH_STATIC(tlbflush_ev);
 EVCNT_ATTACH_STATIC(tlbenter_ev);
 
@@ -1496,7 +1493,6 @@ pmap_tlbmiss(vaddr_t va, int ctx)
 		tte = TTE_PA(va) | TTE_ZONE(ZONE_PRIV) | TTE_SZ_16M | TTE_WR;
 #endif
 	}
-	tlbhit_ev.ev_count++;
 	ppc4xx_tlb_enter(ctx, va, tte);
 
 	return 0;



CVS commit: src/sys/dev/microcode/aic7xxx

2020-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jun 29 06:39:38 UTC 2020

Modified Files:
src/sys/dev/microcode/aic7xxx: Makefile

Log Message:
No longer depend on libl.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/microcode/aic7xxx/Makefile

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/microcode/aic7xxx/Makefile
diff -u src/sys/dev/microcode/aic7xxx/Makefile:1.8 src/sys/dev/microcode/aic7xxx/Makefile:1.9
--- src/sys/dev/microcode/aic7xxx/Makefile:1.8	Sat Jun 27 16:00:34 2020
+++ src/sys/dev/microcode/aic7xxx/Makefile	Mon Jun 29 06:39:38 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.8 2020/06/27 16:00:34 jdolecek Exp $
+#	$NetBSD: Makefile,v 1.9 2020/06/29 06:39:38 rin Exp $
 
 7XXX_SEQ=	aic7xxx.seq
 7XXX_SEQHDR=	aic7xxx_seq.h
@@ -17,7 +17,7 @@ SRCS=	aicasm.c aicasm_symbol.c aicasm_sc
 
 YHEADER=1
 
-DPADD+= ${LIBL} ${LIBY}
+DPADD+= ${LIBY}
 LDADD+= -ly
 
 NOSHARE=# defined



CVS commit: src/sys/dev/i2c

2020-06-29 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 29 06:01:30 UTC 2020

Modified Files:
src/sys/dev/i2c: sdtemp.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/i2c/sdtemp.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/i2c/sdtemp.c
diff -u src/sys/dev/i2c/sdtemp.c:1.36 src/sys/dev/i2c/sdtemp.c:1.37
--- src/sys/dev/i2c/sdtemp.c:1.36	Tue Oct  1 18:00:08 2019
+++ src/sys/dev/i2c/sdtemp.c	Mon Jun 29 06:01:30 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: sdtemp.c,v 1.36 2019/10/01 18:00:08 chs Exp $*/
+/*  $NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.36 2019/10/01 18:00:08 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.37 2020/06/29 06:01:30 msaitoh Exp $");
 
 #include 
 #include 
@@ -214,7 +214,10 @@ sdtemp_match(device_t parent, cfdata_t c
 	if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR)
 		return 0;
 
-	/* Verify that we can read the manufacturer ID, Device ID and the capability */
+	/*
+	 * Verify that we can read the manufacturer ID, Device ID and the
+	 * capability
+	 */
 	iic_acquire_bus(sc.sc_tag, 0);
 	error = sdtemp_read_16(, SDTEMP_REG_MFG_ID,  ) |
 		sdtemp_read_16(, SDTEMP_REG_DEV_REV, ) |
@@ -234,8 +237,8 @@ sdtemp_match(device_t parent, cfdata_t c
 	}
 
 	/*
-	 * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm
-	 * capability, too.
+	 * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the
+	 * alarm capability, too.
 	 */
 	if ((cap & SDTEMP_CAP_HAS_ALARM) == 0)
 		return 0;
@@ -593,7 +596,7 @@ sdtemp_refresh(struct sysmon_envsys *sme
 }
 
 /*
- * power management functions
+ * Power management functions
  *
  * We go into "shutdown" mode at suspend time, and return to normal
  * mode upon resume.  This reduces power consumption by disabling