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

2019-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Sep 20 05:35:27 UTC 2019

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

Log Message:
ref/mod bit should be set according to 'flags' argument, not 'prot'.  r1.44 was 
incomplete.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/aarch64/aarch64/pmap.c

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



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

2019-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Sep 20 05:35:27 UTC 2019

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

Log Message:
ref/mod bit should be set according to 'flags' argument, not 'prot'.  r1.44 was 
incomplete.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/aarch64/aarch64/pmap.c

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.45 src/sys/arch/aarch64/aarch64/pmap.c:1.46
--- src/sys/arch/aarch64/aarch64/pmap.c:1.45	Fri Sep 13 18:07:30 2019
+++ src/sys/arch/aarch64/aarch64/pmap.c	Fri Sep 20 05:35:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.45 2019/09/13 18:07:30 ryo Exp $	*/
+/*	$NetBSD: pmap.c,v 1.46 2019/09/20 05:35:27 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.45 2019/09/13 18:07:30 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.46 2019/09/20 05:35:27 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -1724,6 +1724,8 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	 */
 	if (prot & (VM_PROT_WRITE|VM_PROT_EXECUTE))
 		prot |= VM_PROT_READ;
+	if (flags & (VM_PROT_WRITE|VM_PROT_EXECUTE))
+		flags |= VM_PROT_READ;
 
 	mdattr = VM_PROT_READ | VM_PROT_WRITE;
 	if (need_update_pv) {
@@ -1750,7 +1752,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	if (pg != NULL) {
 		/* update referenced/modified flags */
 		VM_PAGE_TO_MD(pg)->mdpg_flags |=
-		(prot & (VM_PROT_READ | VM_PROT_WRITE));
+		(flags & (VM_PROT_READ | VM_PROT_WRITE));
 		mdattr &= VM_PAGE_TO_MD(pg)->mdpg_flags;
 	}
 



CVS commit: src/sys/dev/ic

2019-09-19 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri Sep 20 05:32:42 UTC 2019

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
Don't set Phase Tag bit of Completion Queue entry at nvme_poll_done().

A new completion queue entry check incorrectly determined that there was
a Completion Queue entry for a command that was not submitted.

Fix PR kern/54275, PR kern/54503, PR kern/54532.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.44 src/sys/dev/ic/nvme.c:1.45
--- src/sys/dev/ic/nvme.c:1.44	Fri Jun 28 15:08:47 2019
+++ src/sys/dev/ic/nvme.c	Fri Sep 20 05:32:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.44 2019/06/28 15:08:47 jmcneill Exp $	*/
+/*	$NetBSD: nvme.c,v 1.45 2019/09/20 05:32:42 nonaka Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44 2019/06/28 15:08:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.45 2019/09/20 05:32:42 nonaka Exp $");
 
 #include 
 #include 
@@ -1302,8 +1302,8 @@ nvme_poll_done(struct nvme_queue *q, str
 {
 	struct nvme_poll_state *state = ccb->ccb_cookie;
 
-	SET(cqe->flags, htole16(NVME_CQE_PHASE));
 	state->c = *cqe;
+	SET(state->c.flags, htole16(NVME_CQE_PHASE));
 
 	ccb->ccb_cookie = state->cookie;
 	state->done(q, ccb, >c);



CVS commit: src/sys/dev/ic

2019-09-19 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri Sep 20 05:32:42 UTC 2019

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
Don't set Phase Tag bit of Completion Queue entry at nvme_poll_done().

A new completion queue entry check incorrectly determined that there was
a Completion Queue entry for a command that was not submitted.

Fix PR kern/54275, PR kern/54503, PR kern/54532.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/ic/nvme.c

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



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 18:29:55 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use an explicit run-time assertion where compile-time doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.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/nist_hash_drbg/nist_hash_drbg.c
diff -u src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.3
--- src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2	Thu Sep 19 14:34:59 2019
+++ src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c	Thu Sep 19 18:29:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $	*/
+/*	$NetBSD: nist_hash_drbg.c,v 1.3 2019/09/19 18:29:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.3 2019/09/19 18:29:55 riastradh Exp $");
 #endif
 
 #include 
@@ -1009,10 +1009,6 @@ static const struct {
 #define	CHECK(i, name, actual, expected, n) do  \
 {	  \
 	CTASSERT(sizeof(actual) == (n));  \
-	CTASSERT(__builtin_constant_p(n) ? sizeof(actual) == (n) : 1);	  \
-	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(actual) >= (n));	  \
-	CTASSERT(__builtin_constant_p(n) ? sizeof(expected) == (n) : 1);  \
-	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(expected) >= (n));	  \
 	ok &= check(i, name, actual, expected, (n));			  \
 } while (0)
 
@@ -1091,7 +1087,9 @@ nist_hash_drbg_initialize(void)
 			kat[i].reseed ? 0 : kat[i].additional[0]->hv_len);
 			reseed_counter++;
 			CHECK(i, "V[1]", D->V, kat[i].V[1], SEEDLEN_BYTES);
-			CHECK(i, "rnd_val[0]", rnd_val, kat[i].rnd_val[0],
+			ASSERT(sizeof(kat[i].rnd_val[0]) - trunc <=
+			sizeof rnd_val);
+			check(i, "rnd_val[0]", rnd_val, kat[i].rnd_val[0],
 			sizeof(kat[i].rnd_val[0]) - trunc);
 			if (D->reseed_counter != reseed_counter) {
 DPRINTF("bad reseed counter: %u, expected %u",
@@ -1113,7 +,9 @@ nist_hash_drbg_initialize(void)
 			kat[i].reseed ? 0 : kat[i].additional[1]->hv_len);
 			reseed_counter++;
 			CHECK(i, "V[2]", D->V, kat[i].V[2], SEEDLEN_BYTES);
-			CHECK(i, "rnd_val[1]", rnd_val, kat[i].rnd_val[1],
+			ASSERT(sizeof(kat[i].rnd_val[1]) - trunc <=
+			sizeof rnd_val);
+			check(i, "rnd_val[1]", rnd_val, kat[i].rnd_val[1],
 			sizeof(kat[i].rnd_val[1]) - trunc);
 			if (D->reseed_counter != reseed_counter) {
 DPRINTF("bad reseed counter: %u, expected %u",



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 18:29:55 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use an explicit run-time assertion where compile-time doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c

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



Re: CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Kamil Rytarowski
On 19.09.2019 16:35, Taylor R Campbell wrote:
> Module Name:  src
> Committed By: riastradh
> Date: Thu Sep 19 14:35:00 UTC 2019
> 
> Modified Files:
>   src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c
> 
> Log Message:
> Use CTASSERT where possible, run-time assertion where not.
> 
> Should fix negative-length variable-length array found by kamil.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 

Unfortunately this still breaks with new __CTASSERT proposed in:

http://netbsd.org/~kamil/patch-00150-__CTASSERT1-bitfield.txt



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:41:28 UTC 2019

Modified Files:
src/sys/dev/mii: rlphy.c

Log Message:
- ICPLUS -> xxICPLUS
- Print model name if it's ICPLUS IP101 to avoid "Realtek internal PHY".


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/mii/rlphy.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/mii/rlphy.c
diff -u src/sys/dev/mii/rlphy.c:1.36 src/sys/dev/mii/rlphy.c:1.37
--- src/sys/dev/mii/rlphy.c:1.36	Mon Mar 25 09:20:46 2019
+++ src/sys/dev/mii/rlphy.c	Thu Sep 19 14:41:28 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rlphy.c,v 1.36 2019/03/25 09:20:46 msaitoh Exp $	*/
+/*	$NetBSD: rlphy.c,v 1.37 2019/09/19 14:41:28 msaitoh Exp $	*/
 /*	$OpenBSD: rlphy.c,v 1.20 2005/07/31 05:27:30 pvalchev Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rlphy.c,v 1.36 2019/03/25 09:20:46 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rlphy.c,v 1.37 2019/09/19 14:41:28 msaitoh Exp $");
 
 #include 
 #include 
@@ -78,7 +78,7 @@ const struct mii_phy_funcs rlphy_funcs =
 static const struct mii_phydesc rlphys[] = {
 	MII_PHY_DESC(yyREALTEK, RTL8201L),
 	MII_PHY_DESC(REALTEK, RTL8201E),
-	MII_PHY_DESC(ICPLUS, IP101),
+	MII_PHY_DESC(xxICPLUS, IP101),
 	MII_PHY_END,
 };
 
@@ -125,6 +125,9 @@ rlphyattach(device_t parent, device_t se
 		rsc->sc_rtl8201 = 1;
 		aprint_normal(": %s, rev. %d\n", MII_STR_REALTEK_RTL8201E,
 		MII_REV(ma->mii_id2));
+	} else if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxICPLUS_IP101) {
+		aprint_normal(": %s, rev. %d\n", MII_STR_xxICPLUS_IP101,
+		MII_REV(ma->mii_id2));
 	} else
 		aprint_normal(": Realtek internal PHY\n");
 



CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:41:28 UTC 2019

Modified Files:
src/sys/dev/mii: rlphy.c

Log Message:
- ICPLUS -> xxICPLUS
- Print model name if it's ICPLUS IP101 to avoid "Realtek internal PHY".


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/mii/rlphy.c

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



CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:39:08 UTC 2019

Modified Files:
src/sys/dev/mii: miidevs.h miidevs_data.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/sys/dev/mii/miidevs.h
cvs rdiff -u -r1.142 -r1.143 src/sys/dev/mii/miidevs_data.h

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



CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:39:08 UTC 2019

Modified Files:
src/sys/dev/mii: miidevs.h miidevs_data.h

Log Message:
Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/sys/dev/mii/miidevs.h
cvs rdiff -u -r1.142 -r1.143 src/sys/dev/mii/miidevs_data.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/mii/miidevs.h
diff -u src/sys/dev/mii/miidevs.h:1.154 src/sys/dev/mii/miidevs.h:1.155
--- src/sys/dev/mii/miidevs.h:1.154	Wed Sep  4 08:57:05 2019
+++ src/sys/dev/mii/miidevs.h	Thu Sep 19 14:39:08 2019
@@ -1,10 +1,10 @@
-/*	$NetBSD: miidevs.h,v 1.154 2019/09/04 08:57:05 msaitoh Exp $	*/
+/*	$NetBSD: miidevs.h,v 1.155 2019/09/19 14:39:08 msaitoh Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: miidevs,v 1.156 2019/09/04 08:56:45 msaitoh Exp
+ *	NetBSD: miidevs,v 1.157 2019/09/19 14:38:45 msaitoh Exp
  */
 
 /*-
@@ -85,7 +85,6 @@
 #define	MII_OUI_AMLOGIC	0x006051	/* Amlogic */
 #define	MII_OUI_DAVICOM	0x00606e	/* Davicom Semiconductor */
 #define	MII_OUI_SMSC	0x00800f	/* SMSC */
-#define	MII_OUI_ICPLUS	0x0090c3	/* IC Plus Corp. */
 #define	MII_OUI_SEEQ	0x00a07d	/* Seeq */
 #define	MII_OUI_ICS	0x00a0be	/* Integrated Circuit Systems */
 #define	MII_OUI_INTEL	0x00aa00	/* Intel */
@@ -116,6 +115,7 @@
 #define	MII_OUI_xxREALTEK	0x000732	/* Realtek */
 #define	MII_OUI_xxBROADCOM	0x000818	/* Broadcom Corporation */
 #define	MII_OUI_xxPMCSIERRA	0x0009c0	/* PMC-Sierra */
+#define	MII_OUI_xxICPLUS	0x0009c3	/* IC Plus Corp. */
 #define	MII_OUI_xxMARVELL	0x000ac2	/* Marvell Semiconductor */
 #define	MII_OUI_xxINTEL	0x001f00	/* Intel */
 #define	MII_OUI_xxBROADCOM_ALT1	0x0050ef	/* Broadcom Corporation */
@@ -344,14 +344,14 @@
 #define	MII_STR_xxDAVICOM_DM9601	"DM9601 internal 10/100 media interface"
 
 /* IC Plus Corp. PHYs */
-#define	MII_MODEL_ICPLUS_IP100	0x0004
-#define	MII_STR_ICPLUS_IP100	"IP100 10/100 PHY"
-#define	MII_MODEL_ICPLUS_IP101	0x0005
-#define	MII_STR_ICPLUS_IP101	"IP101 10/100 PHY"
-#define	MII_MODEL_ICPLUS_IP1000A	0x0008
-#define	MII_STR_ICPLUS_IP1000A	"IP1000A 10/100/1000 PHY"
-#define	MII_MODEL_ICPLUS_IP1001	0x0019
-#define	MII_STR_ICPLUS_IP1001	"IP1001 10/100/1000 PHY"
+#define	MII_MODEL_xxICPLUS_IP100	0x0004
+#define	MII_STR_xxICPLUS_IP100	"IP100 10/100 PHY"
+#define	MII_MODEL_xxICPLUS_IP101	0x0005
+#define	MII_STR_xxICPLUS_IP101	"IP101 10/100 PHY"
+#define	MII_MODEL_xxICPLUS_IP1000A	0x0008
+#define	MII_STR_xxICPLUS_IP1000A	"IP1000A 10/100/1000 PHY"
+#define	MII_MODEL_xxICPLUS_IP1001	0x0019
+#define	MII_STR_xxICPLUS_IP1001	"IP1001 10/100/1000 PHY"
 
 /* Integrated Circuit Systems PHYs */
 #define	MII_MODEL_ICS_1889	0x0001

Index: src/sys/dev/mii/miidevs_data.h
diff -u src/sys/dev/mii/miidevs_data.h:1.142 src/sys/dev/mii/miidevs_data.h:1.143
--- src/sys/dev/mii/miidevs_data.h:1.142	Wed Sep  4 08:57:05 2019
+++ src/sys/dev/mii/miidevs_data.h	Thu Sep 19 14:39:08 2019
@@ -1,10 +1,10 @@
-/*	$NetBSD: miidevs_data.h,v 1.142 2019/09/04 08:57:05 msaitoh Exp $	*/
+/*	$NetBSD: miidevs_data.h,v 1.143 2019/09/19 14:39:08 msaitoh Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: miidevs,v 1.156 2019/09/04 08:56:45 msaitoh Exp
+ *	NetBSD: miidevs,v 1.157 2019/09/19 14:38:45 msaitoh Exp
  */
 
 /*-
@@ -135,10 +135,10 @@ struct mii_knowndev mii_knowndevs[] = {
  { MII_OUI_xxDAVICOM, MII_MODEL_xxDAVICOM_DM9161A, MII_STR_xxDAVICOM_DM9161A },
  { MII_OUI_xxDAVICOM, MII_MODEL_xxDAVICOM_DM9161B, MII_STR_xxDAVICOM_DM9161B },
  { MII_OUI_xxDAVICOM, MII_MODEL_xxDAVICOM_DM9601, MII_STR_xxDAVICOM_DM9601 },
- { MII_OUI_ICPLUS, MII_MODEL_ICPLUS_IP100, MII_STR_ICPLUS_IP100 },
- { MII_OUI_ICPLUS, MII_MODEL_ICPLUS_IP101, MII_STR_ICPLUS_IP101 },
- { MII_OUI_ICPLUS, MII_MODEL_ICPLUS_IP1000A, MII_STR_ICPLUS_IP1000A },
- { MII_OUI_ICPLUS, MII_MODEL_ICPLUS_IP1001, MII_STR_ICPLUS_IP1001 },
+ { MII_OUI_xxICPLUS, MII_MODEL_xxICPLUS_IP100, MII_STR_xxICPLUS_IP100 },
+ { MII_OUI_xxICPLUS, MII_MODEL_xxICPLUS_IP101, MII_STR_xxICPLUS_IP101 },
+ { MII_OUI_xxICPLUS, MII_MODEL_xxICPLUS_IP1000A, MII_STR_xxICPLUS_IP1000A },
+ { MII_OUI_xxICPLUS, MII_MODEL_xxICPLUS_IP1001, MII_STR_xxICPLUS_IP1001 },
  { MII_OUI_ICS, MII_MODEL_ICS_1889, MII_STR_ICS_1889 },
  { MII_OUI_ICS, MII_MODEL_ICS_1890, MII_STR_ICS_1890 },
  { MII_OUI_ICS, MII_MODEL_ICS_1892, MII_STR_ICS_1892 },



CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:38:45 UTC 2019

Modified Files:
src/sys/dev/mii: miidevs

Log Message:
 Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3)


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/dev/mii/miidevs

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



CVS commit: src/sys/dev/mii

2019-09-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 14:38:45 UTC 2019

Modified Files:
src/sys/dev/mii: miidevs

Log Message:
 Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3)


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/dev/mii/miidevs

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/mii/miidevs
diff -u src/sys/dev/mii/miidevs:1.156 src/sys/dev/mii/miidevs:1.157
--- src/sys/dev/mii/miidevs:1.156	Wed Sep  4 08:56:45 2019
+++ src/sys/dev/mii/miidevs	Thu Sep 19 14:38:45 2019
@@ -1,4 +1,4 @@
-$NetBSD: miidevs,v 1.156 2019/09/04 08:56:45 msaitoh Exp $
+$NetBSD: miidevs,v 1.157 2019/09/19 14:38:45 msaitoh Exp $
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,6 @@ oui QUALSEMI			0x006051	Quality Semicond
 oui AMLOGIC			0x006051	Amlogic
 oui DAVICOM			0x00606e	Davicom Semiconductor
 oui SMSC			0x00800f	SMSC
-oui ICPLUS			0x0090c3	IC Plus Corp.
 oui SEEQ			0x00a07d	Seeq
 oui ICS0x00a0be	Integrated Circuit Systems
 oui INTEL			0x00aa00	Intel
@@ -109,6 +108,7 @@ oui xxQUALSEMI			0x00068a	Quality Semico
 oui xxREALTEK			0x000732	Realtek
 oui xxBROADCOM			0x000818	Broadcom Corporation
 oui xxPMCSIERRA			0x0009c0	PMC-Sierra
+oui xxICPLUS			0x0009c3	IC Plus Corp.
 oui xxMARVELL			0x000ac2	Marvell Semiconductor
 oui xxINTEL			0x001f00	Intel
 oui xxBROADCOM_ALT1		0x0050ef	Broadcom Corporation
@@ -244,10 +244,10 @@ model xxDAVICOM DM9161B		0x000b DM9161[B
 model xxDAVICOM DM9601		0x000c DM9601 internal 10/100 media interface
 
 /* IC Plus Corp. PHYs */
-model ICPLUS IP100		0x0004 IP100 10/100 PHY
-model ICPLUS IP101		0x0005 IP101 10/100 PHY
-model ICPLUS IP1000A		0x0008 IP1000A 10/100/1000 PHY
-model ICPLUS IP1001		0x0019 IP1001 10/100/1000 PHY
+model xxICPLUS IP100		0x0004 IP100 10/100 PHY
+model xxICPLUS IP101		0x0005 IP101 10/100 PHY
+model xxICPLUS IP1000A		0x0008 IP1000A 10/100/1000 PHY
+model xxICPLUS IP1001		0x0019 IP1001 10/100/1000 PHY
 
 /* Integrated Circuit Systems PHYs */
 model ICS 1889			0x0001 ICS1889 10/100 media interface



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 14:35:00 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use CTASSERT where possible, run-time assertion where not.

Should fix negative-length variable-length array found by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c

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



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 14:35:00 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use CTASSERT where possible, run-time assertion where not.

Should fix negative-length variable-length array found by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.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/nist_hash_drbg/nist_hash_drbg.c
diff -u src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.1 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2
--- src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.1	Mon Sep  2 20:09:29 2019
+++ src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c	Thu Sep 19 14:34:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $	*/
+/*	$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $");
 #endif
 
 #include 
@@ -1009,6 +1009,10 @@ static const struct {
 #define	CHECK(i, name, actual, expected, n) do  \
 {	  \
 	CTASSERT(sizeof(actual) == (n));  \
+	CTASSERT(__builtin_constant_p(n) ? sizeof(actual) == (n) : 1);	  \
+	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(actual) >= (n));	  \
+	CTASSERT(__builtin_constant_p(n) ? sizeof(expected) == (n) : 1);  \
+	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(expected) >= (n));	  \
 	ok &= check(i, name, actual, expected, (n));			  \
 } while (0)
 



CVS commit: src/tests/lib/libcurses

2019-09-19 Thread Brett Lymn
Module Name:src
Committed By:   blymn
Date:   Thu Sep 19 11:31:58 UTC 2019

Modified Files:
src/tests/lib/libcurses: testframe.txt
src/tests/lib/libcurses/check_files: mutt_test5.chk mutt_test6.chk
src/tests/lib/libcurses/director: returns.h testlang_conf.l
testlang_parse.y
src/tests/lib/libcurses/slave: commands.c slave.c
src/tests/lib/libcurses/tests: mutt_test

Log Message:
Rototill to add complex character support:

- Add cchar command to director test language to allow a complex character
  to be defined and passed to the slave.
- Removed the distinction between args and returns internally to prevent
  confusing the two which leads to errors and/or crashes.
- Converted mutt_test to use the new cchar definition and fixed the
  check files for the test.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libcurses/testframe.txt
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/check_files/mutt_test5.chk \
src/tests/lib/libcurses/check_files/mutt_test6.chk
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/director/returns.h
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libcurses/director/testlang_conf.l
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libcurses/director/testlang_parse.y
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libcurses/slave/commands.c
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libcurses/slave/slave.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/tests/mutt_test

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/libcurses/testframe.txt
diff -u src/tests/lib/libcurses/testframe.txt:1.3 src/tests/lib/libcurses/testframe.txt:1.4
--- src/tests/lib/libcurses/testframe.txt:1.3	Thu Nov 21 11:08:08 2013
+++ src/tests/lib/libcurses/testframe.txt	Thu Sep 19 11:31:57 2019
@@ -101,6 +101,27 @@ call, call2, call3, call4:
   that is the label STDSCR.  This parameter will be substituted by
   the value of stdscr when the function call is made.
 
+cchar:
+  Defines a variable as a complex character type (cchar_t).  The
+  syntax is:
+
+cchar var_name attributes elements
+
+  Where attributes is the attributes for the complex character, this
+  can be an integer, a variable or bitwise or'ed list (see below
+  for a description of the syntax). The elements is one or more wide
+  characters that make up the elements of the complex character.  A
+  single element of either a numeric, variable, byte or single
+  character string can simply be wrtten at the end of the line.
+  Multiple elements need to be space separated and enclosed in
+  square ([]) brackets, the types allowed are the same as for the
+  single element case.  In addition an element can be repeated by
+  following an element with a '*' then a number which will cause
+  the last element to be repeatedly added to the array the number
+  of times specified by number.  Once the complex character variable
+  has been defined it can be used in calls to curses routines
+  requiring a complex character type argument.
+
 check:
   Validate the value of a variable.  This allows a variable to be
   checked for an expected return after it has been assigned in a

Index: src/tests/lib/libcurses/check_files/mutt_test5.chk
diff -u src/tests/lib/libcurses/check_files/mutt_test5.chk:1.1 src/tests/lib/libcurses/check_files/mutt_test5.chk:1.2
--- src/tests/lib/libcurses/check_files/mutt_test5.chk:1.1	Sun May 26 09:54:33 2019
+++ src/tests/lib/libcurses/check_files/mutt_test5.chk	Thu Sep 19 11:31:57 2019
@@ -1,4 +1,4 @@
-cup13;1Xjsetaf7Xsetab0X
-boldsgr0opjsetaf7Xsetab0Xj
+cup13;1Xsetaf7Xsetab0X
+boldsgr0opsetaf7Xsetab0Xj
 boldsgr0opsetaf7Xsetab0Xj
 boldsgr0op
\ No newline at end of file
Index: src/tests/lib/libcurses/check_files/mutt_test6.chk
diff -u src/tests/lib/libcurses/check_files/mutt_test6.chk:1.1 src/tests/lib/libcurses/check_files/mutt_test6.chk:1.2
--- src/tests/lib/libcurses/check_files/mutt_test6.chk:1.1	Sun May 26 09:54:33 2019
+++ src/tests/lib/libcurses/check_files/mutt_test6.chk	Thu Sep 19 11:31:57 2019
@@ -1 +1 @@
-jcup15;11Xsetaf7Xsetab0XsmsoRRRcup24;1Xrmsoopsetaf7Xsetab0Xjopjcup15;15Xsetaf7Xsetab0XHHHopsetaf7Xsetab0Xjop
\ No newline 

CVS commit: src/tests/lib/libcurses

2019-09-19 Thread Brett Lymn
Module Name:src
Committed By:   blymn
Date:   Thu Sep 19 11:31:58 UTC 2019

Modified Files:
src/tests/lib/libcurses: testframe.txt
src/tests/lib/libcurses/check_files: mutt_test5.chk mutt_test6.chk
src/tests/lib/libcurses/director: returns.h testlang_conf.l
testlang_parse.y
src/tests/lib/libcurses/slave: commands.c slave.c
src/tests/lib/libcurses/tests: mutt_test

Log Message:
Rototill to add complex character support:

- Add cchar command to director test language to allow a complex character
  to be defined and passed to the slave.
- Removed the distinction between args and returns internally to prevent
  confusing the two which leads to errors and/or crashes.
- Converted mutt_test to use the new cchar definition and fixed the
  check files for the test.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libcurses/testframe.txt
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/check_files/mutt_test5.chk \
src/tests/lib/libcurses/check_files/mutt_test6.chk
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/director/returns.h
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libcurses/director/testlang_conf.l
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libcurses/director/testlang_parse.y
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libcurses/slave/commands.c
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libcurses/slave/slave.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/tests/mutt_test

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



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_l2tp.c

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



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_l2tp.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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.38 src/sys/net/if_l2tp.c:1.39
--- src/sys/net/if_l2tp.c:1.38	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 06:09:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -116,6 +116,7 @@ pserialize_t l2tp_psz __read_mostly;
 struct psref_class *lv_psref_class __read_mostly;
 
 static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+static void	l2tp_ifq_fini_pc(void *, void *, struct cpu_info *);
 
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
@@ -151,6 +152,20 @@ static void	l2tp_set_state(struct l2tp_s
 static int	l2tp_encap_attach(struct l2tp_variant *);
 static int	l2tp_encap_detach(struct l2tp_variant *);
 
+static inline struct ifqueue *
+l2tp_ifq_percpu_getref(percpu_t *pc)
+{
+
+	return *(struct ifqueue **)percpu_getref(pc);
+}
+
+static inline void
+l2tp_ifq_percpu_putref(percpu_t *pc)
+{
+
+	percpu_putref(pc);
+}
+
 #ifndef MAX_L2TP_NEST
 /*
  * This macro controls the upper limitation on nesting of l2tp tunnels.
@@ -252,7 +267,7 @@ l2tp_clone_create(struct if_clone *ifc, 
 
 	sc->l2tp_ro_percpu = if_tunnel_alloc_ro_percpu();
 
-	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue));
+	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue *));
 	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_init_pc, NULL);
 	sc->l2tp_si = softint_establish(si_flags, l2tpintr_softint, sc);
 
@@ -319,10 +334,18 @@ l2tpattach0(struct l2tp_softc *sc)
 void
 l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
 {
-	struct ifqueue *ifq = p;
+	struct ifqueue **ifqp = p;
 
-	memset(ifq, 0, sizeof(*ifq));
-	ifq->ifq_maxlen = IFQ_MAXLEN;
+	*ifqp = kmem_zalloc(sizeof(**ifqp), KM_SLEEP);
+	(*ifqp)->ifq_maxlen = IFQ_MAXLEN;
+}
+
+void
+l2tp_ifq_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue **ifqp = p;
+
+	kmem_free(*ifqp, sizeof(**ifqp));
 }
 
 static int
@@ -344,7 +367,8 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	mutex_exit(>l2tp_lock);
 
 	softint_disestablish(sc->l2tp_si);
-	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_fini_pc, NULL);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue *));
 
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
@@ -378,10 +402,10 @@ l2tp_tx_enqueue(struct l2tp_variant *var
 	ifp = >l2tp_ec.ec_if;
 
 	s = splsoftnet();
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	if (IF_QFULL(ifq)) {
 		ifp->if_oerrors++;
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		splx(s);
 		m_freem(m);
 		return ENOBUFS;
@@ -503,16 +527,16 @@ l2tpintr(struct l2tp_variant *var)
 
 	/* output processing */
 	if (var->lv_my_sess_id == 0 || var->lv_peer_sess_id == 0) {
-		ifq = percpu_getref(sc->l2tp_ifq_percpu);
+		ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 		IF_PURGE(ifq);
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		if (cpuid == 0)
 			IFQ_PURGE(>if_snd);
 		return;
 	}
 
 	/* Currently, l2tpintr() is always called in softint context. */
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	for (;;) {
 		IF_DEQUEUE(ifq, m);
 		if (m != NULL)
@@ -520,7 +544,7 @@ l2tpintr(struct l2tp_variant *var)
 		else
 			break;
 	

CVS commit: src/sys

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:07:25 UTC 2019

Modified Files:
src/sys/net: if.c if.h if_gif.c if_gif.h if_ipsec.c if_ipsec.h
if_l2tp.c if_l2tp.h
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
Avoid having a rtcache directly in a percpu storage for tunnel protocols.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.460 -r1.461 src/sys/net/if.c
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if.h
cvs rdiff -u -r1.148 -r1.149 src/sys/net/if_gif.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_gif.h
cvs rdiff -u -r1.23 -r1.24 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.37 -r1.38 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_l2tp.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.93 -r1.94 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netipsec/ipsecif.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/net/if.c
diff -u src/sys/net/if.c:1.460 src/sys/net/if.c:1.461
--- src/sys/net/if.c:1.460	Fri Sep 13 07:55:07 2019
+++ src/sys/net/if.c	Thu Sep 19 06:07:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.460 2019/09/13 07:55:07 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.461 2019/09/19 06:07:24 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.460 2019/09/13 07:55:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.461 2019/09/19 06:07:24 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2906,6 +2906,63 @@ if_tunnel_check_nesting(struct ifnet *if
 	return 0;
 }
 
+static void
+if_tunnel_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	tro->tr_ro = kmem_zalloc(sizeof(*tro->tr_ro), KM_SLEEP);
+	tro->tr_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
+}
+
+percpu_t *
+if_tunnel_alloc_ro_percpu(void)
+{
+	percpu_t *ro_percpu;
+
+	ro_percpu = percpu_alloc(sizeof(struct tunnel_ro));
+	percpu_foreach(ro_percpu, if_tunnel_ro_init_pc, NULL);
+
+	return ro_percpu;
+}
+
+static void
+if_tunnel_ro_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	rtcache_free(tro->tr_ro);
+	kmem_free(tro->tr_ro, sizeof(*tro->tr_ro));
+
+	mutex_obj_free(tro->tr_lock);
+}
+
+void
+if_tunnel_free_ro_percpu(percpu_t *ro_percpu)
+{
+
+	percpu_foreach(ro_percpu, if_tunnel_ro_fini_pc, NULL);
+	percpu_free(ro_percpu, sizeof(struct tunnel_ro));
+}
+
+
+static void
+if_tunnel_rtcache_free_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	mutex_enter(tro->tr_lock);
+	rtcache_free(tro->tr_ro);
+	mutex_exit(tro->tr_lock);
+}
+
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *ro_percpu)
+{
+
+	percpu_foreach(ro_percpu, if_tunnel_rtcache_free_pc, NULL);
+}
+
+
 /* common */
 int
 ifioctl_common(struct ifnet *ifp, u_long cmd, void *data)

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.276 src/sys/net/if.h:1.277
--- src/sys/net/if.h:1.276	Fri Sep 13 07:55:07 2019
+++ src/sys/net/if.h	Thu Sep 19 06:07:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.276 2019/09/13 07:55:07 msaitoh Exp $	*/
+/*	$NetBSD: if.h,v 1.277 2019/09/19 06:07:24 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1122,6 +1122,33 @@ void	if_acquire(struct ifnet *, struct p
 #define	if_release	if_put
 
 int if_tunnel_check_nesting(struct ifnet *, struct mbuf *, int);
+percpu_t *if_tunnel_alloc_ro_percpu(void);
+void if_tunnel_free_ro_percpu(percpu_t *);
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *);
+
+struct tunnel_ro {
+	struct route *tr_ro;
+	kmutex_t *tr_lock;
+};
+
+static inline void
+if_tunnel_get_ro(percpu_t *ro_percpu, struct route **ro, kmutex_t **lock)
+{
+	struct tunnel_ro *tro;
+
+	tro = percpu_getref(ro_percpu);
+	*ro = tro->tr_ro;
+	*lock = tro->tr_lock;
+	

CVS commit: src/sys

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:07:25 UTC 2019

Modified Files:
src/sys/net: if.c if.h if_gif.c if_gif.h if_ipsec.c if_ipsec.h
if_l2tp.c if_l2tp.h
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
Avoid having a rtcache directly in a percpu storage for tunnel protocols.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.460 -r1.461 src/sys/net/if.c
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if.h
cvs rdiff -u -r1.148 -r1.149 src/sys/net/if_gif.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_gif.h
cvs rdiff -u -r1.23 -r1.24 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.37 -r1.38 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_l2tp.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.93 -r1.94 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netipsec/ipsecif.c

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