Re: CVS commit: src/sys/arch/x86/x86

2020-04-02 Thread Kengo NAKAHARA

Hi,

Hmm, but TSC drift is still observed on recent (high clock) CPUs.
I will have researched and fix later.

On 2020/04/03 12:05, Kengo NAKAHARA wrote:

Module Name:src
Committed By:   knakahara
Date:   Fri Apr  3 03:05:39 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
Fix TSC drift is observed almost every time wrongly.

Ths "TSC drift" in tsc_tc_init() means the cpu_cc_skew delta between
first measurement (in cpu_start_secondary) and second measurement
(in cpu_boot_secondary), that is, the TSC drift is expected to be
almost zero.  However, the second measument in current implementation
is added extra cpu_cc_skew accidentally, so current delta value means
almost cpu_cc_skew wrongly.

tsc_sync_bp and tsc_sync_ap should use rdtsc() to get raw values.

Advised by nonaka@n.o, thanks.


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

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



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

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

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.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/rss_config.c
diff -u src/sys/net/rss_config.c:1.1 src/sys/net/rss_config.c:1.2
--- src/sys/net/rss_config.c:1.1	Fri Feb 16 04:48:32 2018
+++ src/sys/net/rss_config.c	Wed Nov 20 08:17:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $  */
+/*	$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $  */
 
 /*
  * Copyright (c) 2018 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $");
 
 #include 
 #include 
@@ -62,6 +62,7 @@ static uint8_t rss_symmetric_key[RSS_KEY
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 };
 #endif
 



CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

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

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


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

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



CVS commit: src/sys/netipsec

2019-11-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 14 03:17:08 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Reduce load for IKE negotiations when the system has many IPv6 addresses.

e.g. the system has many vlan(4), gif(4) or ipsecif(4) with link local address.


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netipsec/key.c

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



CVS commit: src/sys/netipsec

2019-11-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 14 03:17:08 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Reduce load for IKE negotiations when the system has many IPv6 addresses.

e.g. the system has many vlan(4), gif(4) or ipsecif(4) with link local address.


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netipsec/key.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/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.268 src/sys/netipsec/key.c:1.269
--- src/sys/netipsec/key.c:1.268	Tue Nov 12 05:13:29 2019
+++ src/sys/netipsec/key.c	Thu Nov 14 03:17:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.269 2019/11/14 03:17:08 knakahara Exp $	*/
 /*	$FreeBSD: key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.269 2019/11/14 03:17:08 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -4502,30 +4502,34 @@ key_ismyaddr6(const struct sockaddr_in6 
 	bound = curlwp_bind();
 	s = pserialize_read_enter();
 	IN6_ADDRLIST_READER_FOREACH(ia) {
-		bool ingroup;
-
 		if (key_sockaddr_match((const struct sockaddr *),
 		(const struct sockaddr *)>ia_addr, 0)) {
 			pserialize_read_exit(s);
 			goto ours;
 		}
-		ia6_acquire(ia, );
-		pserialize_read_exit(s);
 
-		/*
-		 * XXX Multicast
-		 * XXX why do we care about multlicast here while we don't care
-		 * about IPv4 multicast??
-		 * XXX scope
-		 */
-		ingroup = in6_multi_group(>sin6_addr, ia->ia_ifp);
-		if (ingroup) {
+		if (IN6_IS_ADDR_MULTICAST(>sin6_addr)) {
+			bool ingroup;
+
+			ia6_acquire(ia, );
+			pserialize_read_exit(s);
+
+			/*
+			 * XXX Multicast
+			 * XXX why do we care about multlicast here while we don't care
+			 * about IPv4 multicast??
+			 * XXX scope
+			 */
+			ingroup = in6_multi_group(>sin6_addr, ia->ia_ifp);
+			if (ingroup) {
+ia6_release(ia, );
+goto ours;
+			}
+
+			s = pserialize_read_enter();
 			ia6_release(ia, );
-			goto ours;
 		}
 
-		s = pserialize_read_enter();
-		ia6_release(ia, );
 	}
 	pserialize_read_exit(s);
 



CVS commit: src/sys/netipsec

2019-11-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Nov 12 05:13:29 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Fix SA can be expaired wrongly when there are many SPs.

When key_timehandler_spd() spent over one second, the "now" argument of
key_timehandler_sad() could be older than sav->created. That caused SA
was expired immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netipsec/key.c

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



CVS commit: src/sys/netipsec

2019-11-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Nov 12 05:13:29 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Fix SA can be expaired wrongly when there are many SPs.

When key_timehandler_spd() spent over one second, the "now" argument of
key_timehandler_sad() could be older than sav->created. That caused SA
was expired immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netipsec/key.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/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.267 src/sys/netipsec/key.c:1.268
--- src/sys/netipsec/key.c:1.267	Wed Sep 25 09:53:38 2019
+++ src/sys/netipsec/key.c	Tue Nov 12 05:13:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.267 2019/09/25 09:53:38 ozaki-r Exp $	*/
+/*	$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $	*/
 /*	$FreeBSD: key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.267 2019/09/25 09:53:38 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -4883,14 +4883,20 @@ key_bb_match_withmask(const void *a1, co
 }
 
 static void
-key_timehandler_spd(time_t now)
+key_timehandler_spd(void)
 {
 	u_int dir;
 	struct secpolicy *sp;
+	volatile time_t now;
 
 	for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
 	retry:
 		mutex_enter(_spd.lock);
+		/*
+		 * To avoid for sp->created to overtake "now" because of
+		 * wating mutex, set time_uptime here.
+		 */
+		now = time_uptime;
 		SPLIST_WRITER_FOREACH(sp, dir) {
 			KASSERTMSG(sp->state != IPSEC_SPSTATE_DEAD,
 			"sp->state=%u", sp->state);
@@ -4925,10 +4931,11 @@ key_timehandler_spd(time_t now)
 }
 
 static void
-key_timehandler_sad(time_t now)
+key_timehandler_sad(void)
 {
 	struct secashead *sah;
 	int s;
+	volatile time_t now;
 
 restart:
 	mutex_enter(_sad.lock);
@@ -4954,6 +4961,10 @@ restart:
 		/* if LARVAL entry doesn't become MATURE, delete it. */
 		mutex_enter(_sad.lock);
 	restart_sav_LARVAL:
+		/*
+		 * Same as key_timehandler_spd(), set time_uptime here.
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_LARVAL) {
 			if (now - sav->created > key_larval_lifetime) {
 key_sa_chgstate(sav, SADB_SASTATE_DEAD);
@@ -4968,6 +4979,10 @@ restart:
 		 */
 	restart_sav_MATURE:
 		mutex_enter(_sad.lock);
+		/*
+		 * ditto
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_MATURE) {
 			/* we don't need to check. */
 			if (sav->lft_s == NULL)
@@ -5032,6 +5047,10 @@ restart:
 		/* check DYING entry to change status to DEAD. */
 		mutex_enter(_sad.lock);
 	restart_sav_DYING:
+		/*
+		 * ditto
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_DYING) {
 			/* we don't need to check. */
 			if (sav->lft_h == NULL)
@@ -5098,13 +5117,18 @@ restart:
 }
 
 static void
-key_timehandler_acq(time_t now)
+key_timehandler_acq(void)
 {
 #ifndef IPSEC_NONBLOCK_ACQUIRE
 	struct secacq *acq, *nextacq;
+	volatile time_t now;
 
 restart:
 	mutex_enter(_misc.lock);
+	/*
+	 * Same as key_timehandler_spd(), set time_uptime here.
+	 */
+	now = time_uptime;
 	LIST_FOREACH_SAFE(acq, _misc.acqlist, chain, nextacq) {
 		if (now - acq->created > key_blockacq_lifetime) {
 			LIST_REMOVE(acq, chain);
@@ -5118,10 +5142,11 @@ key_timehandler_acq(time_t now)
 }
 
 static void
-key_timehandler_spacq(time_t now)
+key_timehandler_spacq(void)
 {
 #ifdef notyet
 	struct secspacq *acq, *nextacq;
+	time_t now = time_uptime;
 
 	LIST_FOREACH_SAFE(acq, _misc.spacqlist, chain, nextacq) {
 		if (now - acq->created > key_blockacq_lifetime) {
@@ -5143,15 +5168,14 @@ static unsigned int key_timehandler_work
 static void
 key_timehandler_work(struct work *wk, void *arg)
 {
-	time_t now = time_uptime;
 
 	/* We can allow enqueuing another work at this point */
 	atomic_swap_uint(_timehandler_work_enqueued, 0);
 
-	key_timehandler_spd(now);
-	key_timehandler_sad(now);
-	key_timehandler_acq(now);
-	key_timehandler_spacq(now);
+	key_timehandler_spd();
+	key_timehandler_sad();
+	key_timehandler_acq();
+	key_timehandler_spacq();
 
 	key_acquire_sendup_pending_mbuf();
 



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:28:14 UTC 2019

Modified Files:
src/sys/net: if_ipsec.c if_ipsec.h
src/sys/netinet6: in6.h
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
Make global and per-interface ipsecif(4) pmtu tunable like gif(4).

And make hop limit tunable same as gif(4).

See http://mail-index.netbsd.org/source-changes/2019/10/30/msg110426.html


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/in6.h
cvs rdiff -u -r1.17 -r1.18 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netipsec/ipsecif.h

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



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:28:14 UTC 2019

Modified Files:
src/sys/net: if_ipsec.c if_ipsec.h
src/sys/netinet6: in6.h
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
Make global and per-interface ipsecif(4) pmtu tunable like gif(4).

And make hop limit tunable same as gif(4).

See http://mail-index.netbsd.org/source-changes/2019/10/30/msg110426.html


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/in6.h
cvs rdiff -u -r1.17 -r1.18 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netipsec/ipsecif.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.24 src/sys/net/if_ipsec.c:1.25
--- src/sys/net/if_ipsec.c:1.24	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_ipsec.c	Fri Nov  1 04:28:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.24 2019/09/19 06:07:24 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.24 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -48,6 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -147,6 +148,138 @@ struct if_clone ipsec_cloner =
 IF_CLONE_INITIALIZER("ipsec", if_ipsec_clone_create, if_ipsec_clone_destroy);
 static int max_ipsec_nesting = MAX_IPSEC_NEST;
 
+static struct sysctllog *if_ipsec_sysctl;
+
+#ifdef INET6
+static int
+sysctl_if_ipsec_pmtu_global(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+
+	pmtu = ip6_ipsec_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case IPSEC_PMTU_MINMTU:
+	case IPSEC_PMTU_OUTERMTU:
+		ip6_ipsec_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+sysctl_if_ipsec_pmtu_perif(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+	struct ipsec_softc *sc = (struct ipsec_softc *)node.sysctl_data;
+
+	pmtu = sc->ipsec_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case IPSEC_PMTU_SYSDEFAULT:
+	case IPSEC_PMTU_MINMTU:
+	case IPSEC_PMTU_OUTERMTU:
+		sc->ipsec_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+#endif
+
+static void
+if_ipsec_sysctl_setup(void)
+{
+	if_ipsec_sysctl = NULL;
+
+#ifdef INET6
+	/*
+	 * Previously create "net.inet6.ip6" entry to avoid sysctl_createv error.
+	 */
+	sysctl_createv(NULL, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "inet6",
+		   SYSCTL_DESCR("PF_INET6 related settings"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, PF_INET6, CTL_EOL);
+	sysctl_createv(NULL, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "ip6",
+		   SYSCTL_DESCR("IPv6 related settings"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
+
+	sysctl_createv(_ipsec_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "ipsecifhlim",
+		   SYSCTL_DESCR("Default hop limit for a ipsec tunnel datagram"),
+		   NULL, 0, _ipsec_hlim, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_IPSEC_HLIM, CTL_EOL);
+
+	sysctl_createv(_ipsec_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "ipsecifpmtu",
+		   SYSCTL_DESCR("Default Path MTU setting for ipsec tunnels"),
+		   sysctl_if_ipsec_pmtu_global, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_IPSEC_PMTU, CTL_EOL);
+#endif
+}
+
+static void
+if_ipsec_perif_sysctl_setup(struct sysctllog **clog, struct ipsec_softc *sc)
+{
+#ifdef INET6
+	const struct sysctlnode *cnode, *rnode;
+	struct ifnet *ifp = >ipsec_if;
+	const char *ifname = ifp->if_xname;
+	int rv;
+
+	/*
+	 * Already created in sysctl_sndq_setup().
+	 */
+	sysctl_createv(clog, 0, NULL, ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "interfaces",
+		   SYSCTL_DESCR("Per-interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, , ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, ifname,
+		   SYSCTL_DESCR("Interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_CREATE, CTL_EOL);
+
+	rv = sysctl_createv(clog, 0, , ,
+			CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+			CTLTYPE_INT, "pmtu",
+			SYSCTL_DESCR("Path MTU setting for this ipsec 

CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:23:21 UTC 2019

Modified Files:
src/sys/netinet6: ip6_forward.c ip6_output.c
src/sys/netipsec: ipsec.h ipsec6.h ipsec_output.c xform.h xform_ah.c
xform_esp.c xform_ipcomp.c xform_ipip.c xform_tcp.c

Log Message:
Fix ipsecif(4) IPV6_MINMTU does not work correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.220 -r1.221 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.88 -r1.89 src/sys/netipsec/ipsec.h
cvs rdiff -u -r1.29 -r1.30 src/sys/netipsec/ipsec6.h
cvs rdiff -u -r1.83 -r1.84 src/sys/netipsec/ipsec_output.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/xform.h
cvs rdiff -u -r1.108 -r1.109 src/sys/netipsec/xform_ah.c
cvs rdiff -u -r1.98 -r1.99 src/sys/netipsec/xform_esp.c
cvs rdiff -u -r1.68 -r1.69 src/sys/netipsec/xform_ipcomp.c
cvs rdiff -u -r1.76 -r1.77 src/sys/netipsec/xform_ipip.c
cvs rdiff -u -r1.23 -r1.24 src/sys/netipsec/xform_tcp.c

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



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:23:21 UTC 2019

Modified Files:
src/sys/netinet6: ip6_forward.c ip6_output.c
src/sys/netipsec: ipsec.h ipsec6.h ipsec_output.c xform.h xform_ah.c
xform_esp.c xform_ipcomp.c xform_ipip.c xform_tcp.c

Log Message:
Fix ipsecif(4) IPV6_MINMTU does not work correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.220 -r1.221 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.88 -r1.89 src/sys/netipsec/ipsec.h
cvs rdiff -u -r1.29 -r1.30 src/sys/netipsec/ipsec6.h
cvs rdiff -u -r1.83 -r1.84 src/sys/netipsec/ipsec_output.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/xform.h
cvs rdiff -u -r1.108 -r1.109 src/sys/netipsec/xform_ah.c
cvs rdiff -u -r1.98 -r1.99 src/sys/netipsec/xform_esp.c
cvs rdiff -u -r1.68 -r1.69 src/sys/netipsec/xform_ipcomp.c
cvs rdiff -u -r1.76 -r1.77 src/sys/netipsec/xform_ipip.c
cvs rdiff -u -r1.23 -r1.24 src/sys/netipsec/xform_tcp.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/netinet6/ip6_forward.c
diff -u src/sys/netinet6/ip6_forward.c:1.97 src/sys/netinet6/ip6_forward.c:1.98
--- src/sys/netinet6/ip6_forward.c:1.97	Thu Sep 19 04:08:29 2019
+++ src/sys/netinet6/ip6_forward.c	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_forward.c,v 1.97 2019/09/19 04:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_forward.c,v 1.98 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.97 2019/09/19 04:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.98 2019/11/01 04:23:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -261,7 +261,7 @@ ip6_forward(struct mbuf *m, int srcrt)
 	 */
 	if (needipsec) {
 		int s = splsoftnet();
-		error = ipsec6_process_packet(m, sp->req);
+		error = ipsec6_process_packet(m, sp->req, 0);
 		splx(s);
 		/* m is freed */
 		if (mcopy)

Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.220 src/sys/netinet6/ip6_output.c:1.221
--- src/sys/netinet6/ip6_output.c:1.220	Wed May 15 02:59:18 2019
+++ src/sys/netinet6/ip6_output.c	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.220 2019/05/15 02:59:18 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.220 2019/05/15 02:59:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -477,7 +477,7 @@ ip6_output(
 #ifdef IPSEC
 	if (needipsec) {
 		int s = splsoftnet();
-		error = ipsec6_process_packet(m, sp->req);
+		error = ipsec6_process_packet(m, sp->req, flags);
 		splx(s);
 
 		/*

Index: src/sys/netipsec/ipsec.h
diff -u src/sys/netipsec/ipsec.h:1.88 src/sys/netipsec/ipsec.h:1.89
--- src/sys/netipsec/ipsec.h:1.88	Wed Jun 12 22:23:50 2019
+++ src/sys/netipsec/ipsec.h	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.h,v 1.88 2019/06/12 22:23:50 christos Exp $	*/
+/*	$NetBSD: ipsec.h,v 1.89 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$FreeBSD: ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
 
@@ -318,7 +318,7 @@ void ipsec4_common_input(struct mbuf *m,
 int ipsec4_common_input_cb(struct mbuf *, struct secasvar *, int, int);
 int ipsec4_process_packet(struct mbuf *, const struct ipsecrequest *, u_long *);
 int ipsec_process_done(struct mbuf *, const struct ipsecrequest *,
-struct secasvar *);
+struct secasvar *, int);
 
 struct mbuf *m_clone(struct mbuf *);
 struct mbuf *m_makespace(struct mbuf *, int, int, int *);

Index: src/sys/netipsec/ipsec6.h
diff -u src/sys/netipsec/ipsec6.h:1.29 src/sys/netipsec/ipsec6.h:1.30
--- src/sys/netipsec/ipsec6.h:1.29	Mon May 14 17:34:26 2018
+++ src/sys/netipsec/ipsec6.h	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec6.h,v 1.29 2018/05/14 17:34:26 maxv Exp $	*/
+/*	$NetBSD: ipsec6.h,v 1.30 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$FreeBSD: ipsec6.h,v 1.1.4.1 2003/01/24 05:11:35 sam Exp $	*/
 /*	$KAME: ipsec.h,v 1.44 2001/03/23 08:08:47 itojun Exp $	*/
 
@@ -59,7 +59,7 @@ void *ah6_ctlinput(int, const struct soc
 struct m_tag;
 int ipsec6_common_input(struct mbuf **, int *, int);
 int ipsec6_common_input_cb(struct mbuf *, struct secasvar *, int, int);
-int ipsec6_process_packet(struct mbuf *, const struct ipsecrequest *);
+int ipsec6_process_packet(struct mbuf *, const struct ipsecrequest *, int);
 #endif /*_KERNEL*/
 
 #endif /* !_NETIPSEC_IPSEC6_H_ */

Index: src/sys/netipsec/ipsec_output.c
diff -u 

CVS commit: src/sys

2019-10-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 30 03:45:59 UTC 2019

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet6: in6.h in6_gif.c in6_gif.h

Log Message:
Add sysctl nodes to control fragmentation with IPv[46] over IPv6 gif(4).

New sysctl node "net.inet6.ip6.gifpmtu" means
- 0 (default)
  Fragment by IPV6_MMTU. All packets reach the destination certainly,
  however the long packet performance is poor.
  This is same behavior as before.
- 1
  Fragment by outer interface's MTU. The long packet performance would
  be good, however the packets may be dropped in some network paths
  whose path MTU less than the interface's MTU.
- others
  undefined yet

New sysctl node "net.interfaces.gif*.pmtu" means
- -1 (default)
  Use system default value (net.inet6.ip6.gifpmtu).
- 0
  Fragment by IPV6_MMTU for this gif(4) tunnel.
- 1
  Fragment by outer interface's MTU for this gif(4) tunnel.
- others
  undefined yet

See RFC4459 for more information and other solutions.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/net/if_gif.c
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_gif.h
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet6/in6.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_gif.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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.149 src/sys/net/if_gif.c:1.150
--- src/sys/net/if_gif.c:1.149	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_gif.c	Wed Oct 30 03:45:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.149 2019/09/19 06:07:24 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.150 2019/10/30 03:45:59 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.149 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.150 2019/10/30 03:45:59 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -142,6 +142,58 @@ static int max_gif_nesting = MAX_GIF_NES
 
 static struct sysctllog *gif_sysctl;
 
+#ifdef INET6
+static int
+sysctl_gif_pmtu_global(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+
+	pmtu = ip6_gif_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case GIF_PMTU_MINMTU:
+	case GIF_PMTU_OUTERMTU:
+		ip6_gif_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+sysctl_gif_pmtu_perif(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+	struct gif_softc *sc = (struct gif_softc *)node.sysctl_data;
+
+	pmtu = sc->gif_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case GIF_PMTU_SYSDEFAULT:
+	case GIF_PMTU_MINMTU:
+	case GIF_PMTU_OUTERMTU:
+		sc->gif_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+#endif
+
 static void
 gif_sysctl_setup(void)
 {
@@ -196,6 +248,52 @@ gif_sysctl_setup(void)
 		   NULL, 0, _gif_hlim, 0,
 		   CTL_NET, PF_INET6, IPPROTO_IPV6,
 		   IPV6CTL_GIF_HLIM, CTL_EOL);
+
+	sysctl_createv(_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "gifpmtu",
+		   SYSCTL_DESCR("Default Path MTU setting for gif tunnels"),
+		   sysctl_gif_pmtu_global, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_GIF_PMTU, CTL_EOL);
+#endif
+}
+
+static void
+gif_perif_sysctl_setup(struct sysctllog **clog, struct gif_softc *sc)
+{
+#ifdef INET6
+	const struct sysctlnode *cnode, *rnode;
+	struct ifnet *ifp = >gif_if;
+	const char *ifname = ifp->if_xname;
+	int rv;
+
+	/*
+	 * Already created in sysctl_sndq_setup().
+	 */
+	sysctl_createv(clog, 0, NULL, ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "interfaces",
+		   SYSCTL_DESCR("Per-interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, , ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, ifname,
+		   SYSCTL_DESCR("Interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_CREATE, CTL_EOL);
+
+	rv = sysctl_createv(clog, 0, , ,
+			CTLFLAG_PERMANENT,
+			CTLTYPE_INT, "pmtu",
+			SYSCTL_DESCR("Path MTU setting for this gif tunnel"),
+			sysctl_gif_pmtu_perif, 0, (void *)sc, 0,
+			CTL_CREATE, CTL_EOL);
+	if (rv != 0)
+		log(LOG_WARNING, "%s: could not attach sysctl node pmtu\n", ifname);
+
+	sc->gif_pmtu = GIF_PMTU_SYSDEFAULT;
 #endif
 }
 
@@ -248,6 +346,7 @@ gif_clone_create(struct if_clone *ifc, i
 {
 	struct gif_softc *sc;
 	struct gif_variant *var;
+	struct ifnet *ifp;
 	int rv;
 
 	sc = kmem_zalloc(sizeof(struct 

CVS commit: src/sys

2019-10-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 30 03:45:59 UTC 2019

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet6: in6.h in6_gif.c in6_gif.h

Log Message:
Add sysctl nodes to control fragmentation with IPv[46] over IPv6 gif(4).

New sysctl node "net.inet6.ip6.gifpmtu" means
- 0 (default)
  Fragment by IPV6_MMTU. All packets reach the destination certainly,
  however the long packet performance is poor.
  This is same behavior as before.
- 1
  Fragment by outer interface's MTU. The long packet performance would
  be good, however the packets may be dropped in some network paths
  whose path MTU less than the interface's MTU.
- others
  undefined yet

New sysctl node "net.interfaces.gif*.pmtu" means
- -1 (default)
  Use system default value (net.inet6.ip6.gifpmtu).
- 0
  Fragment by IPV6_MMTU for this gif(4) tunnel.
- 1
  Fragment by outer interface's MTU for this gif(4) tunnel.
- others
  undefined yet

See RFC4459 for more information and other solutions.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/net/if_gif.c
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_gif.h
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet6/in6.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_gif.h

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-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:53:34 UTC 2019

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

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/net/if_gre.c
cvs rdiff -u -r1.39 -r1.40 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.113 -r1.114 src/sys/net/if_tap.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_gre.c
diff -u src/sys/net/if_gre.c:1.175 src/sys/net/if_gre.c:1.176
--- src/sys/net/if_gre.c:1.175	Fri Apr 26 11:51:56 2019
+++ src/sys/net/if_gre.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $ */
+/*	$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -964,8 +964,11 @@ gre_output(struct ifnet *ifp, struct mbu
 	if ((error = gre_bufq_enqueue(>sc_snd, m)) != 0) {
 		sc->sc_oflow_ev.ev_count++;
 		m_freem(m);
-	} else
+	} else {
+		kpreempt_disable();
 		softint_schedule(sc->sc_si);
+		kpreempt_enable();
+	}
 
 end:
 	if (error)

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.39 src/sys/net/if_l2tp.c:1.40
--- src/sys/net/if_l2tp.c:1.39	Thu Sep 19 06:09:52 2019
+++ src/sys/net/if_l2tp.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -673,7 +673,9 @@ l2tp_start(struct ifnet *ifp)
 	if (var->lv_psrc == NULL || var->lv_pdst == NULL)
 		return;
 
+	kpreempt_disable();
 	softint_schedule(sc->l2tp_si);
+	kpreempt_enable();
 	l2tp_putref_variant(var, );
 }
 

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.113 src/sys/net/if_tap.c:1.114
--- src/sys/net/if_tap.c:1.113	Wed May 29 10:07:30 2019
+++ src/sys/net/if_tap.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -533,8 +533,11 @@ tap_start(struct ifnet *ifp)
 		ifp->if_flags |= IFF_OACTIVE;
 		cv_broadcast(>sc_cv);
 		selnotify(>sc_rsel, 0, 1);
-		if (sc->sc_flags & TAP_ASYNCIO)
+		if (sc->sc_flags & TAP_ASYNCIO) {
+			kpreempt_disable();
 			softint_schedule(sc->sc_sih);
+			kpreempt_enable();
+		}
 	}
 done:
 	mutex_exit(>sc_lock);
@@ -643,8 +646,11 @@ tap_stop(struct ifnet *ifp, int disable)
 	ifp->if_flags &= ~IFF_RUNNING;
 	cv_broadcast(>sc_cv);
 	selnotify(>sc_rsel, 0, 1);
-	if (sc->sc_flags & TAP_ASYNCIO)
+	if (sc->sc_flags & TAP_ASYNCIO) {
+		kpreempt_disable();
 		softint_schedule(sc->sc_sih);
+		kpreempt_enable();
+	}
 	mutex_exit(>sc_lock);
 }
 



CVS commit: src/sys/dev/pci/ixgbe

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:36:00 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/pci/ixgbe/ix_txrx.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/pci/ixgbe

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:36:00 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/pci/ixgbe/ix_txrx.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/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.55 src/sys/dev/pci/ixgbe/ix_txrx.c:1.56
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.55	Wed Sep  4 07:29:34 2019
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Wed Oct 16 06:36:00 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.55 2019/09/04 07:29:34 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.56 2019/10/16 06:36:00 knakahara Exp $ */
 
 /**
 
@@ -266,8 +266,11 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 >wq_cookie, curcpu());
 			} else
 percpu_putref(adapter->txr_wq_enqueued);
-		} else
+		} else {
+			kpreempt_disable();
 			softint_schedule(txr->txr_si);
+			kpreempt_enable();
+		}
 	}
 
 	return (0);



CVS commit: src/sys/arch/x86/pci

2019-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 10 08:55:08 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix kassert failure in vmxnet3_transmit(). Pointed out by ryo@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 10 08:55:08 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix kassert failure in vmxnet3_transmit(). Pointed out by ryo@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.50 src/sys/arch/x86/pci/if_vmx.c:1.51
--- src/sys/arch/x86/pci/if_vmx.c:1.50	Mon Sep 30 07:13:54 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Thu Oct 10 08:55:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.51 2019/10/10 08:55:08 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.51 2019/10/10 08:55:08 knakahara Exp $");
 
 #include 
 #include 
@@ -3276,7 +3276,9 @@ vmxnet3_transmit(struct ifnet *ifp, stru
 		vmxnet3_transmit_locked(ifp, txq);
 		VMXNET3_TXQ_UNLOCK(txq);
 	} else {
+		kpreempt_disable();
 		softint_schedule(txq->vxtxq_si);
+		kpreempt_enable();
 	}
 
 	return 0;



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

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

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.224 src/sys/net/route.c:1.225
--- src/sys/net/route.c:1.224	Mon Sep 30 10:22:14 2019
+++ src/sys/net/route.c	Thu Oct  3 03:10:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,11 +1400,8 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL) {
-			ifa_release(ifa, psref);
-			ifa = NULL;
-			goto next;
-		}
+		info->rti_info[RTAX_GATEWAY] == NULL)
+			goto out;
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

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

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.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-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

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

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.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-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

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

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.223 src/sys/net/route.c:1.224
--- src/sys/net/route.c:1.223	Wed Sep 25 09:53:37 2019
+++ src/sys/net/route.c	Mon Sep 30 10:22:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,8 +1400,11 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL)
+		info->rti_info[RTAX_GATEWAY] == NULL) {
+			ifa_release(ifa, psref);
+			ifa = NULL;
 			goto next;
+		}
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/arch/x86/pci

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 07:13:54 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix typo in vmxnet3_legacy_intr().

That causes sysctl hw.vmx*.{rx,tx} effect inversely when vmx(4) uses
INTx or MSI.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.49 src/sys/arch/x86/pci/if_vmx.c:1.50
--- src/sys/arch/x86/pci/if_vmx.c:1.49	Fri Aug 30 05:03:32 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Sep 30 07:13:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $");
 
 #include 
 #include 
@@ -2513,11 +2513,11 @@ vmxnet3_legacy_intr(void *xsc)
 		vmxnet3_evintr(sc);
 
 	VMXNET3_RXQ_LOCK(rxq);
-	rxmore = vmxnet3_rxq_eof(rxq, txlimit);
+	rxmore = vmxnet3_rxq_eof(rxq, rxlimit);
 	VMXNET3_RXQ_UNLOCK(rxq);
 
 	VMXNET3_TXQ_LOCK(txq);
-	txmore = vmxnet3_txq_eof(txq, rxlimit);
+	txmore = vmxnet3_txq_eof(txq, txlimit);
 	VMXNET3_TXQ_UNLOCK(txq);
 
 	if (txmore || rxmore) {



CVS commit: src/sys/arch/x86/pci

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 07:13:54 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix typo in vmxnet3_legacy_intr().

That causes sysctl hw.vmx*.{rx,tx} effect inversely when vmx(4) uses
INTx or MSI.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/x86/pci/if_vmx.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.



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.



CVS commit: src/sys/net

2019-09-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

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

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_l2tp.h

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-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

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

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_l2tp.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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.36 src/sys/net/if_l2tp.c:1.37
--- src/sys/net/if_l2tp.c:1.36	Mon Aug 19 03:24:05 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 04:59:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -118,15 +118,20 @@ struct psref_class *lv_psref_class __rea
 static void	l2tp_ro_init_pc(void *, void *, struct cpu_info *);
 static void	l2tp_ro_fini_pc(void *, void *, struct cpu_info *);
 
+static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
 
 struct if_clone l2tp_cloner =
 IF_CLONE_INITIALIZER("l2tp", l2tp_clone_create, l2tp_clone_destroy);
 
+static int	l2tp_tx_enqueue(struct l2tp_variant *, struct mbuf *);
 static int	l2tp_output(struct ifnet *, struct mbuf *,
 		const struct sockaddr *, const struct rtentry *);
+static void	l2tp_sendit(struct l2tp_variant *, struct mbuf *);
 static void	l2tpintr(struct l2tp_variant *);
+static void	l2tpintr_softint(void *);
 
 static void	l2tp_hash_init(void);
 static int	l2tp_hash_fini(void);
@@ -225,7 +230,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	struct l2tp_softc *sc;
 	struct l2tp_variant *var;
 	int rv;
-
+	u_int si_flags = SOFTINT_NET;
+#ifdef NET_MPSAFE
+	si_flags |= SOFTINT_MPSAFE;
+#endif
 	sc = kmem_zalloc(sizeof(struct l2tp_softc), KM_SLEEP);
 	if_initname(>l2tp_ec.ec_if, ifc->ifc_name, unit);
 	rv = l2tpattach0(sc);
@@ -248,6 +256,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
 	percpu_foreach(sc->l2tp_ro_percpu, l2tp_ro_init_pc, NULL);
 
+	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);
+
 	mutex_enter(_softcs.lock);
 	LIST_INSERT_HEAD(_softcs.list, sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -326,6 +338,15 @@ l2tp_ro_fini_pc(void *p, void *arg __unu
 	mutex_obj_free(lro->lr_lock);
 }
 
+void
+l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue *ifq = p;
+
+	memset(ifq, 0, sizeof(*ifq));
+	ifq->ifq_maxlen = IFQ_MAXLEN;
+}
+
 static int
 l2tp_clone_destroy(struct ifnet *ifp)
 {
@@ -336,13 +357,17 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	l2tp_clear_session(sc);
 	l2tp_delete_tunnel(>l2tp_ec.ec_if);
 	/*
-	 * To avoid for l2tp_transmit() to access sc->l2tp_var after free it.
+	 * To avoid for l2tp_transmit() and l2tpintr_softint() to access
+	 * sc->l2tp_var after free it.
 	 */
 	mutex_enter(>l2tp_lock);
 	var = sc->l2tp_var;
 	l2tp_variant_update(sc, NULL);
 	mutex_exit(>l2tp_lock);
 
+	softint_disestablish(sc->l2tp_si);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -363,6 +388,37 @@ l2tp_clone_destroy(struct ifnet *ifp)
 }
 
 static int
+l2tp_tx_enqueue(struct l2tp_variant *var, struct mbuf *m)
+{
+	struct l2tp_softc *sc;
+	struct ifnet *ifp;
+	struct ifqueue *ifq;
+	int s;
+
+	KASSERT(psref_held(>lv_psref, lv_psref_class));
+
+	sc = var->lv_softc;
+	ifp = >l2tp_ec.ec_if;
+
+	s = splsoftnet();
+	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	if (IF_QFULL(ifq)) {
+		ifp->if_oerrors++;
+		percpu_putref(sc->l2tp_ifq_percpu);
+		splx(s);
+		m_freem(m);
+		return ENOBUFS;
+	}
+
+	IF_ENQUEUE(ifq, m);
+	percpu_putref(sc->l2tp_ifq_percpu);
+	softint_schedule(sc->l2tp_si);
+	/* counter is incremented in l2tpintr() */
+	splx(s);
+	return 0;
+}
+
+static int
 l2tp_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 const struct rtentry *rt)
 {
@@ -404,17 +460,7 @@ l2tp_output(struct ifnet *ifp, struct mb
 	}
 	*mtod(m, int *) = dst->sa_family;
 
-	IFQ_ENQUEUE(>if_snd, m, error);
-	if (error)
-		goto end;
-
-	/*
-	 * direct call to avoid infinite 

CVS commit: src/sys/arch/x86/pci

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 30 05:03:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmxnet3_softc.vmx_stats should not count globally. pointed out by hikaru@n.o

divide vmxnet3_softc.vmx_stats to each vmxnet3_txqueue and vmxnet3_rxqueue,
furthermore make them evcnt.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.48 src/sys/arch/x86/pci/if_vmx.c:1.49
--- src/sys/arch/x86/pci/if_vmx.c:1.48	Mon Aug 19 05:25:38 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Aug 30 05:03:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $");
 
 #include 
 #include 
@@ -207,6 +207,8 @@ struct vmxnet3_txqueue {
 	struct evcnt vxtxq_pcqdrop;
 	struct evcnt vxtxq_transmitdef;
 	struct evcnt vxtxq_watchdogto;
+	struct evcnt vxtxq_defragged;
+	struct evcnt vxtxq_defrag_failed;
 };
 
 struct vmxnet3_rxq_stats {
@@ -230,6 +232,8 @@ struct vmxnet3_rxqueue {
 	struct evcnt vxrxq_intr;
 	struct evcnt vxrxq_defer;
 	struct evcnt vxrxq_deferreq;
+	struct evcnt vxrxq_mgetcl_failed;
+	struct evcnt vxrxq_mbuf_load_failed;
 };
 
 struct vmxnet3_queue {
@@ -244,13 +248,6 @@ struct vmxnet3_queue {
 	struct work vxq_wq_cookie;
 };
 
-struct vmxnet3_statistics {
-	uint32_t vmst_defragged;
-	uint32_t vmst_defrag_failed;
-	uint32_t vmst_mgetcl_failed;
-	uint32_t vmst_mbuf_load_failed;
-};
-
 struct vmxnet3_softc {
 	device_t vmx_dev;
 	struct ethercom vmx_ethercom;
@@ -281,7 +278,6 @@ struct vmxnet3_softc {
 	int vmx_nrxdescs;
 	int vmx_max_rxsegs;
 
-	struct vmxnet3_statistics vmx_stats;
 	struct evcnt vmx_event_intr;
 	struct evcnt vmx_event_link;
 	struct evcnt vmx_event_txqerror;
@@ -395,7 +391,8 @@ int vmxnet3_setup_interface(struct vmxne
 
 void vmxnet3_evintr(struct vmxnet3_softc *);
 bool vmxnet3_txq_eof(struct vmxnet3_txqueue *, u_int);
-int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxring *);
+int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxqueue *,
+struct vmxnet3_rxring *);
 void vmxnet3_rxq_eof_discard(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxring *, int);
 void vmxnet3_rxq_discard_chain(struct vmxnet3_rxqueue *);
@@ -1971,6 +1968,10 @@ vmxnet3_setup_stats(struct vmxnet3_softc
 		NULL, txq->vxtxq_name, "Deferred transmit");
 		evcnt_attach_dynamic(>vxtxq_watchdogto, EVCNT_TYPE_MISC,
 		NULL, txq->vxtxq_name, "Watchdog timeount");
+		evcnt_attach_dynamic(>vxtxq_defragged, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "m_defrag sucessed");
+		evcnt_attach_dynamic(>vxtxq_defrag_failed, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "m_defrag failed");
 	}
 
 	for (i = 0; i < sc->vmx_nrxqueues; i++) {
@@ -1982,6 +1983,10 @@ vmxnet3_setup_stats(struct vmxnet3_softc
 		NULL, rxq->vxrxq_name, "Handled queue in softint/workqueue");
 		evcnt_attach_dynamic(>vxrxq_deferreq, EVCNT_TYPE_MISC,
 		NULL, rxq->vxrxq_name, "Requested in softint/workqueue");
+		evcnt_attach_dynamic(>vxrxq_mgetcl_failed, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "MCLGET failed");
+		evcnt_attach_dynamic(>vxrxq_mbuf_load_failed, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "bus_dmamap_load_mbuf failed");
 	}
 
 	evcnt_attach_dynamic(>vmx_event_intr, EVCNT_TYPE_INTR,
@@ -2017,6 +2022,8 @@ vmxnet3_teardown_stats(struct vmxnet3_so
 		evcnt_detach(>vxtxq_pcqdrop);
 		evcnt_detach(>vxtxq_transmitdef);
 		evcnt_detach(>vxtxq_watchdogto);
+		evcnt_detach(>vxtxq_defragged);
+		evcnt_detach(>vxtxq_defrag_failed);
 	}
 
 	for (i = 0; i < sc->vmx_nrxqueues; i++) {
@@ -2025,6 +2032,8 @@ vmxnet3_teardown_stats(struct vmxnet3_so
 		evcnt_detach(>vxrxq_intr);
 		evcnt_detach(>vxrxq_defer);
 		evcnt_detach(>vxrxq_deferreq);
+		evcnt_detach(>vxrxq_mgetcl_failed);
+		evcnt_detach(>vxrxq_mbuf_load_failed);
 	}
 
 	evcnt_detach(>vmx_event_intr);
@@ -2154,7 +2163,8 @@ vmxnet3_txq_eof(struct vmxnet3_txqueue *
 }
 
 int
-vmxnet3_newbuf(struct vmxnet3_softc *sc, struct vmxnet3_rxring *rxr)
+vmxnet3_newbuf(struct vmxnet3_softc *sc, struct vmxnet3_rxqueue *rxq,
+struct vmxnet3_rxring *rxr)
 {
 	struct mbuf *m;
 	struct vmxnet3_rxdesc *rxd;
@@ -2180,7 +2190,7 @@ vmxnet3_newbuf(struct vmxnet3_softc *sc,
 
 	MCLGET(m, M_DONTWAIT);
 	if ((m->m_flags & M_EXT) == 0) {
-		sc->vmx_stats.vmst_mgetcl_failed++;
+		rxq->vxrxq_mgetcl_failed.ev_count++;
 		m_freem(m);
 		return (ENOBUFS);
 	}
@@ -2191,7 +2201,7 @@ vmxnet3_newbuf(struct vmxnet3_softc *sc,
 	

CVS commit: src/sys/arch/x86/pci

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 30 05:03:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmxnet3_softc.vmx_stats should not count globally. pointed out by hikaru@n.o

divide vmxnet3_softc.vmx_stats to each vmxnet3_txqueue and vmxnet3_rxqueue,
furthermore make them evcnt.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/pci/if_vmx.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/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:45:22 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix panic when ncpu == 1 && sysctl -w hw.ixg0.txrx_workqueue=1. Reported by 
nonaka@n.o.

ok by msaitoh@n.o and nonaka@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/pci/ixgbe/ixgbe.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/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.205 src/sys/dev/pci/ixgbe/ixgbe.c:1.206
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.205	Thu Aug 29 09:35:18 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Aug 29 09:45:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.205 2019/08/29 09:35:18 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.206 2019/08/29 09:45:22 knakahara Exp $ */
 
 /**
 
@@ -6467,7 +6467,9 @@ ixgbe_allocate_legacy(struct adapter *ad
 	int		counts[PCI_INTR_TYPE_SIZE];
 	pci_intr_type_t intr_type, max_type;
 	char		intrbuf[PCI_INTRSTR_LEN];
+	char		wqname[MAXCOMLEN];
 	const char	*intrstr = NULL;
+	int defertx_error = 0, error;
 
 	/* We allocate a single interrupt resource */
 	max_type = PCI_INTR_TYPE_MSI;
@@ -6529,15 +6531,27 @@ alloc_retry:
 	 * Try allocating a fast interrupt and the associated deferred
 	 * processing contexts.
 	 */
-	if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX))
+	if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)) {
 		txr->txr_si =
 		softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
 			ixgbe_deferred_mq_start, txr);
+
+		snprintf(wqname, sizeof(wqname), "%sdeferTx", device_xname(dev));
+		defertx_error = workqueue_create(>txr_wq, wqname,
+		ixgbe_deferred_mq_start_work, adapter, IXGBE_WORKQUEUE_PRI,
+		IPL_NET, IXGBE_WORKQUEUE_FLAGS);
+		adapter->txr_wq_enqueued = percpu_alloc(sizeof(u_int));
+	}
 	que->que_si = softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
 	ixgbe_handle_que, que);
+	snprintf(wqname, sizeof(wqname), "%sTxRx", device_xname(dev));
+	error = workqueue_create(>que_wq, wqname,
+	ixgbe_handle_que_work, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
+	IXGBE_WORKQUEUE_FLAGS);
 
 	if ((!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)
-		&& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
+		&& ((txr->txr_si == NULL) || defertx_error != 0))
+	|| (que->que_si == NULL) || error != 0) {
 		aprint_error_dev(dev,
 		"could not establish software interrupts\n");
 



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:45:22 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix panic when ncpu == 1 && sysctl -w hw.ixg0.txrx_workqueue=1. Reported by 
nonaka@n.o.

ok by msaitoh@n.o and nonaka@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/pci/ixgbe/ixgbe.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/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:35:18 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
fix typo in error handling of ixgbe_allocate_legacy().

ok by msaitoh@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/dev/pci/ixgbe/ixgbe.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/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.204 src/sys/dev/pci/ixgbe/ixgbe.c:1.205
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.204	Wed Aug 28 08:54:21 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Aug 29 09:35:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.204 2019/08/28 08:54:21 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.205 2019/08/29 09:35:18 knakahara Exp $ */
 
 /**
 
@@ -6537,7 +6537,7 @@ alloc_retry:
 	ixgbe_handle_que, que);
 
 	if ((!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)
-		& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
+		&& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
 		aprint_error_dev(dev,
 		"could not establish software interrupts\n");
 



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:35:18 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
fix typo in error handling of ixgbe_allocate_legacy().

ok by msaitoh@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/dev/pci/ixgbe/ixgbe.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/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA

Hi,

On 2019/08/19 14:25, Kengo NAKAHARA wrote:

Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.c

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


I have finished my task for vmx(4), so I think if_vmx.c can be moved
to sys/dev/pci/ directory as pointed out by mrg@n.o.

However, it would require some htole* codes to become MI correctly.
cf. 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/vmxnet3/vmxnet3_drv.c?h=v5.3-rc5=115924b6bdc7cc6bf7da5b933b09281e1f4e17a9


It would be required to test on big endian architectures before moving
to sys/dev/pci directory.


Thanks,

--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.47 src/sys/arch/x86/pci/if_vmx.c:1.48
--- src/sys/arch/x86/pci/if_vmx.c:1.47	Mon Aug 19 05:23:50 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Aug 19 05:25:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $");
 
 #include 
 #include 
@@ -200,6 +200,13 @@ struct vmxnet3_txqueue {
 	char vxtxq_name[16];
 
 	void *vxtxq_si;
+
+	struct evcnt vxtxq_intr;
+	struct evcnt vxtxq_defer;
+	struct evcnt vxtxq_deferreq;
+	struct evcnt vxtxq_pcqdrop;
+	struct evcnt vxtxq_transmitdef;
+	struct evcnt vxtxq_watchdogto;
 };
 
 struct vmxnet3_rxq_stats {
@@ -219,6 +226,10 @@ struct vmxnet3_rxqueue {
 	struct vmxnet3_rxq_stats vxrxq_stats;
 	struct vmxnet3_rxq_shared *vxrxq_rs;
 	char vxrxq_name[16];
+
+	struct evcnt vxrxq_intr;
+	struct evcnt vxrxq_defer;
+	struct evcnt vxrxq_deferreq;
 };
 
 struct vmxnet3_queue {
@@ -271,6 +282,12 @@ struct vmxnet3_softc {
 	int vmx_max_rxsegs;
 
 	struct vmxnet3_statistics vmx_stats;
+	struct evcnt vmx_event_intr;
+	struct evcnt vmx_event_link;
+	struct evcnt vmx_event_txqerror;
+	struct evcnt vmx_event_rxqerror;
+	struct evcnt vmx_event_dic;
+	struct evcnt vmx_event_debug;
 
 	int vmx_intr_type;
 	int vmx_intr_mask_mode;
@@ -349,6 +366,9 @@ void vmxnet3_set_interrupt_idx(struct vm
 int vmxnet3_setup_interrupts(struct vmxnet3_softc *);
 int vmxnet3_setup_sysctl(struct vmxnet3_softc *);
 
+int vmxnet3_setup_stats(struct vmxnet3_softc *);
+void vmxnet3_teardown_stats(struct vmxnet3_softc *);
+
 int vmxnet3_init_rxq(struct vmxnet3_softc *, int);
 int vmxnet3_init_txq(struct vmxnet3_softc *, int);
 int vmxnet3_alloc_rxtx_queues(struct vmxnet3_softc *);
@@ -631,6 +651,10 @@ vmxnet3_attach(device_t parent, device_t
 	if (error)
 		return;
 
+	error = vmxnet3_setup_stats(sc);
+	if (error)
+		return;
+
 	sc->vmx_flags |= VMXNET3_FLAG_ATTACHED;
 }
 
@@ -655,6 +679,7 @@ vmxnet3_detach(device_t self, int flags)
 		if_detach(ifp);
 	}
 
+	vmxnet3_teardown_stats(sc);
 	sysctl_teardown(>vmx_sysctllog);
 
 	vmxnet3_free_interrupts(sc);
@@ -1923,6 +1948,93 @@ out:
 	return error;
 }
 
+int
+vmxnet3_setup_stats(struct vmxnet3_softc *sc)
+{
+	struct vmxnet3_queue *vmxq;
+	struct vmxnet3_txqueue *txq;
+	struct vmxnet3_rxqueue *rxq;
+	int i;
+
+	for (i = 0; i < sc->vmx_ntxqueues; i++) {
+		vmxq = >vmx_queue[i];
+		txq = >vxq_txqueue;
+		evcnt_attach_dynamic(>vxtxq_intr, EVCNT_TYPE_INTR,
+		NULL, txq->vxtxq_name, "Interrupt on queue");
+		evcnt_attach_dynamic(>vxtxq_defer, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Handled queue in softint/workqueue");
+		evcnt_attach_dynamic(>vxtxq_deferreq, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Requested in softint/workqueue");
+		evcnt_attach_dynamic(>vxtxq_pcqdrop, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Dropped in pcq");
+		evcnt_attach_dynamic(>vxtxq_transmitdef, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Deferred transmit");
+		evcnt_attach_dynamic(>vxtxq_watchdogto, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Watchdog timeount");
+	}
+
+	for (i = 0; i < sc->vmx_nrxqueues; i++) {
+		vmxq = >vmx_queue[i];
+		rxq = >vxq_rxqueue;
+		evcnt_attach_dynamic(>vxrxq_intr, EVCNT_TYPE_INTR,
+		NULL, rxq->vxrxq_name, "Interrupt on queue");
+		evcnt_attach_dynamic(>vxrxq_defer, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "Handled queue in softint/workqueue");
+		evcnt_attach_dynamic(>vxrxq_deferreq, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "Requested in softint/workqueue");
+	}
+
+	evcnt_attach_dynamic(>vmx_event_intr, EVCNT_TYPE_INTR,
+	NULL, device_xname(sc->vmx_dev), "Interrupt for other events");
+	evcnt_attach_dynamic(>vmx_event_link, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Link status event");
+	evcnt_attach_dynamic(>vmx_event_txqerror, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Tx queue error event");
+	evcnt_attach_dynamic(>vmx_event_rxqerror, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Rx queue error event");
+	evcnt_attach_dynamic(>vmx_event_dic, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Device impl change event");
+	

CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:23:50 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
fix panic when vmx(4) is detached.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.46 src/sys/arch/x86/pci/if_vmx.c:1.47
--- src/sys/arch/x86/pci/if_vmx.c:1.46	Thu Aug  1 09:37:34 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Aug 19 05:23:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.46 2019/08/01 09:37:34 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.46 2019/08/01 09:37:34 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $");
 
 #include 
 #include 
@@ -859,11 +859,13 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	int i;
 
 	workqueue_destroy(sc->vmx_queue_wq);
-	for (i = 0; i < sc->vmx_nintrs; i++) {
+	for (i = 0; i < sc->vmx_ntxqueues; i++) {
 		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
 
 		softint_disestablish(vmxq->vxq_si);
 		vmxq->vxq_si = NULL;
+	}
+	for (i = 0; i < sc->vmx_nintrs; i++) {
 		pci_intr_disestablish(pc, sc->vmx_ihs[i]);
 	}
 	pci_intr_release(pc, sc->vmx_intrs, sc->vmx_nintrs);



CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:23:50 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
fix panic when vmx(4) is detached.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/pci/if_vmx.c

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



CVS commit: src/sys/netipsec

2019-08-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Aug  7 10:10:00 UTC 2019

Modified Files:
src/sys/netipsec: ipsec.c

Log Message:
ipsec_getpolicybysock() should also call key_havesp() like 
ipsec_getpolicybyaddr().

That can reduce KEYDEBUG messages.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/netipsec/ipsec.c

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



CVS commit: src/sys/netipsec

2019-08-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Aug  7 10:10:00 UTC 2019

Modified Files:
src/sys/netipsec: ipsec.c

Log Message:
ipsec_getpolicybysock() should also call key_havesp() like 
ipsec_getpolicybyaddr().

That can reduce KEYDEBUG messages.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/netipsec/ipsec.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/netipsec/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.169 src/sys/netipsec/ipsec.c:1.170
--- src/sys/netipsec/ipsec.c:1.169	Tue Jul  9 16:56:24 2019
+++ src/sys/netipsec/ipsec.c	Wed Aug  7 10:10:00 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.169 2019/07/09 16:56:24 maxv Exp $ */
+/* $NetBSD: ipsec.c,v 1.170 2019/08/07 10:10:00 knakahara Exp $ */
 /* $FreeBSD: ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $ */
 /* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.169 2019/07/09 16:56:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.170 2019/08/07 10:10:00 knakahara Exp $");
 
 /*
  * IPsec controller part.
@@ -466,7 +466,10 @@ ipsec_getpolicybysock(struct mbuf *m, u_
 
 		case IPSEC_POLICY_ENTRUST:
 			/* look for a policy in SPD */
-			sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+			if (key_havesp(dir))
+sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+			else
+sp = NULL;
 			if (sp == NULL)		/* no SP found */
 sp = KEY_GET_DEFAULT_SP(af);
 			break;
@@ -478,7 +481,10 @@ ipsec_getpolicybysock(struct mbuf *m, u_
 			return NULL;
 		}
 	} else {/* unpriv, SPD has policy */
-		sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+		if (key_havesp(dir))
+			sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+		else
+			sp = NULL;
 		if (sp == NULL) {		/* no SP found */
 			switch (currsp->policy) {
 			case IPSEC_POLICY_BYPASS:



CVS commit: src/sys/arch/x86/pci

2019-07-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 30 11:16:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can select workqueue for packet processing like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 30 11:16:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can select workqueue for packet processing like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.44 src/sys/arch/x86/pci/if_vmx.c:1.45
--- src/sys/arch/x86/pci/if_vmx.c:1.44	Mon Jul 29 10:28:57 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 30 11:16:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45 2019/07/30 11:16:15 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45 2019/07/30 11:16:15 knakahara Exp $");
 
 #include 
 #include 
@@ -30,6 +30,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -96,6 +97,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #define VMXNET3_RX_PROCESS_LIMIT 256
 #define VMXNET3_TX_PROCESS_LIMIT 256
 
+#define VMXNET3_WORKQUEUE_PRI PRI_SOFTNET
+
 /*
  * IP protocols that we can perform Tx checksum offloading of.
  */
@@ -225,6 +228,8 @@ struct vmxnet3_queue {
 	struct vmxnet3_rxqueue vxq_rxqueue;
 
 	void *vxq_si;
+	bool vxq_workqueue;
+	struct work vxq_wq_cookie;
 };
 
 struct vmxnet3_statistics {
@@ -291,8 +296,10 @@ struct vmxnet3_softc {
 	u_int vmx_tx_intr_process_limit;
 	u_int vmx_rx_process_limit;
 	u_int vmx_tx_process_limit;
-
 	struct sysctllog *vmx_sysctllog;
+
+	bool vmx_txrx_workqueue;
+	struct workqueue *vmx_queue_wq;
 };
 
 #define VMXNET3_STAT
@@ -378,6 +385,7 @@ bool vmxnet3_rxq_eof(struct vmxnet3_rxqu
 int vmxnet3_legacy_intr(void *);
 int vmxnet3_txrxq_intr(void *);
 void vmxnet3_handle_queue(void *);
+void vmxnet3_handle_queue_work(struct work *, void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -849,6 +857,7 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	pci_chipset_tag_t pc = sc->vmx_pc;
 	int i;
 
+	workqueue_destroy(sc->vmx_queue_wq);
 	for (i = 0; i < sc->vmx_nintrs; i++) {
 		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
 
@@ -866,7 +875,7 @@ vmxnet3_setup_msix_interrupts(struct vmx
 	struct vmxnet3_queue *vmxq;
 	pci_intr_handle_t *intr;
 	void **ihs;
-	int intr_idx, i, use_queues;
+	int intr_idx, i, use_queues, error;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
 	char xnamebuf[32];
@@ -904,6 +913,15 @@ vmxnet3_setup_msix_interrupts(struct vmx
 
 		vmxq->vxq_intr_idx = intr_idx;
 	}
+	snprintf(xnamebuf, MAXCOMLEN, "%s_tx_rx", device_xname(sc->vmx_dev));
+	error = workqueue_create(>vmx_queue_wq, xnamebuf,
+	vmxnet3_handle_queue_work, sc, VMXNET3_WORKQUEUE_PRI, IPL_NET,
+	WQ_PERCPU | WQ_MPSAFE);
+	if (error) {
+		aprint_error_dev(sc->vmx_dev, "workqueue_create failed\n");
+		return (-1);
+	}
+	sc->vmx_txrx_workqueue = false;
 
 	intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
@@ -1839,6 +1857,12 @@ vmxnet3_setup_sysctl(struct vmxnet3_soft
 	NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
 	if (error)
 		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_BOOL, "txrx_workqueue",
+	SYSCTL_DESCR("Use workqueue for packet processing"),
+	NULL, 0, >vmx_txrx_workqueue, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
 
 	error = sysctl_createv(log, 0, , ,
 	0, CTLTYPE_NODE, "rx",
@@ -2305,6 +2329,18 @@ nextp:
 	return more;
 }
 
+static inline void
+vmxnet3_sched_handle_queue(struct vmxnet3_softc *sc, struct vmxnet3_queue *vmxq)
+{
+
+	if (vmxq->vxq_workqueue) {
+		workqueue_enqueue(sc->vmx_queue_wq, >vxq_wq_cookie,
+		curcpu());
+	} else {
+		softint_schedule(vmxq->vxq_si);
+	}
+}
+
 int
 vmxnet3_legacy_intr(void *xsc)
 {
@@ -2339,7 +2375,7 @@ vmxnet3_legacy_intr(void *xsc)
 	VMXNET3_TXQ_UNLOCK(txq);
 
 	if (txmore || rxmore) {
-		softint_schedule(sc->vmx_queue[0].vxq_si);
+		vmxnet3_sched_handle_queue(sc, >vmx_queue[0]);
 	} else {
 		if_schedule_deferred_start(>vmx_ethercom.ec_if);
 		vmxnet3_enable_all_intrs(sc);
@@ -2363,6 +2399,7 @@ vmxnet3_txrxq_intr(void *xvmxq)
 	sc = txq->vxtxq_sc;
 	txlimit = sc->vmx_tx_intr_process_limit;
 	rxlimit = sc->vmx_rx_intr_process_limit;
+	vmxq->vxq_workqueue = sc->vmx_txrx_workqueue;
 
 	if (sc->vmx_intr_mask_mode == VMXNET3_IMM_ACTIVE)
 		vmxnet3_disable_intr(sc, vmxq->vxq_intr_idx);
@@ -2376,7 +2413,7 @@ vmxnet3_txrxq_intr(void *xvmxq)
 	VMXNET3_RXQ_UNLOCK(rxq);
 
 	if (txmore || rxmore) {
-		softint_schedule(vmxq->vxq_si);
+		vmxnet3_sched_handle_queue(sc, vmxq);
 	} else {
 		/* for ALTQ */
 		if (vmxq->vxq_id 

CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:28:58 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
make vmx(4)'s *_process_limit tunable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:28:58 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
make vmx(4)'s *_process_limit tunable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.43 src/sys/arch/x86/pci/if_vmx.c:1.44
--- src/sys/arch/x86/pci/if_vmx.c:1.43	Mon Jul 29 10:24:18 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 10:28:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $");
 
 #include 
 #include 
@@ -291,6 +291,8 @@ struct vmxnet3_softc {
 	u_int vmx_tx_intr_process_limit;
 	u_int vmx_rx_process_limit;
 	u_int vmx_tx_process_limit;
+
+	struct sysctllog *vmx_sysctllog;
 };
 
 #define VMXNET3_STAT
@@ -337,6 +339,7 @@ int vmxnet3_setup_msi_interrupt(struct v
 int vmxnet3_setup_legacy_interrupt(struct vmxnet3_softc *);
 void vmxnet3_set_interrupt_idx(struct vmxnet3_softc *);
 int vmxnet3_setup_interrupts(struct vmxnet3_softc *);
+int vmxnet3_setup_sysctl(struct vmxnet3_softc *);
 
 int vmxnet3_init_rxq(struct vmxnet3_softc *, int);
 int vmxnet3_init_txq(struct vmxnet3_softc *, int);
@@ -615,6 +618,10 @@ vmxnet3_attach(device_t parent, device_t
 	if (error)
 		return;
 
+	error = vmxnet3_setup_sysctl(sc);
+	if (error)
+		return;
+
 	sc->vmx_flags |= VMXNET3_FLAG_ATTACHED;
 }
 
@@ -639,6 +646,8 @@ vmxnet3_detach(device_t self, int flags)
 		if_detach(ifp);
 	}
 
+	sysctl_teardown(>vmx_sysctllog);
+
 	vmxnet3_free_interrupts(sc);
 
 	vmxnet3_free_data(sc);
@@ -1813,6 +1822,69 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	return (0);
 }
 
+int
+vmxnet3_setup_sysctl(struct vmxnet3_softc *sc)
+{
+	const char *devname;
+	struct sysctllog **log;
+	const struct sysctlnode *rnode, *rxnode, *txnode;
+	int error;
+
+	log = >vmx_sysctllog;
+	devname = device_xname(sc->vmx_dev);
+
+	error = sysctl_createv(log, 0, NULL, ,
+	0, CTLTYPE_NODE, devname,
+	SYSCTL_DESCR("vmxnet3 information and settings"),
+	NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+
+	error = sysctl_createv(log, 0, , ,
+	0, CTLTYPE_NODE, "rx",
+	SYSCTL_DESCR("vmxnet3 information and settings for Rx"),
+	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
+	SYSCTL_DESCR("max number of Rx packets to process for interrupt processing"),
+	NULL, 0, >vmx_rx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
+	SYSCTL_DESCR("max number of Rx packets to process for deferred processing"),
+	NULL, 0, >vmx_rx_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+
+	error = sysctl_createv(log, 0, , ,
+	0, CTLTYPE_NODE, "tx",
+	SYSCTL_DESCR("vmxnet3 information and settings for Tx"),
+	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
+	SYSCTL_DESCR("max number of Tx packets to process for interrupt processing"),
+	NULL, 0, >vmx_tx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
+	SYSCTL_DESCR("max number of Tx packets to process for deferred processing"),
+	NULL, 0, >vmx_tx_process_limit, 0, CTL_CREATE, CTL_EOL);
+
+out:
+	if (error) {
+		aprint_error_dev(sc->vmx_dev,
+		"unable to create sysctl node\n");
+		sysctl_teardown(log);
+	}
+	return error;
+}
+
 void
 vmxnet3_evintr(struct vmxnet3_softc *sc)
 {



CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:24:18 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) uses deferred interrupt handlering like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.42 src/sys/arch/x86/pci/if_vmx.c:1.43
--- src/sys/arch/x86/pci/if_vmx.c:1.42	Mon Jul 29 09:45:16 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 10:24:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $");
 
 #include 
 #include 
@@ -83,6 +83,20 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #define VMXNET3_WATCHDOG_TIMEOUT	5
 
 /*
+ * Default value for vmx_intr_{rx,tx}_process_limit which is used for
+ * max number of packets to process for interrupt handler
+ */
+#define VMXNET3_RX_INTR_PROCESS_LIMIT 0U
+#define VMXNET3_TX_INTR_PROCESS_LIMIT 256
+
+/*
+ * Default value for vmx_{rx,tx}_process_limit which is used for
+ * max number of packets to process for deferred processing
+ */
+#define VMXNET3_RX_PROCESS_LIMIT 256
+#define VMXNET3_TX_PROCESS_LIMIT 256
+
+/*
  * IP protocols that we can perform Tx checksum offloading of.
  */
 #define VMXNET3_CSUM_OFFLOAD \
@@ -209,6 +223,8 @@ struct vmxnet3_queue {
 
 	struct vmxnet3_txqueue vxq_txqueue;
 	struct vmxnet3_rxqueue vxq_rxqueue;
+
+	void *vxq_si;
 };
 
 struct vmxnet3_statistics {
@@ -270,6 +286,11 @@ struct vmxnet3_softc {
 	int vmx_max_ntxqueues;
 	int vmx_max_nrxqueues;
 	uint8_t vmx_lladdr[ETHER_ADDR_LEN];
+
+	u_int vmx_rx_intr_process_limit;
+	u_int vmx_tx_intr_process_limit;
+	u_int vmx_rx_process_limit;
+	u_int vmx_tx_process_limit;
 };
 
 #define VMXNET3_STAT
@@ -342,7 +363,7 @@ void vmxnet3_free_data(struct vmxnet3_so
 int vmxnet3_setup_interface(struct vmxnet3_softc *);
 
 void vmxnet3_evintr(struct vmxnet3_softc *);
-void vmxnet3_txq_eof(struct vmxnet3_txqueue *);
+bool vmxnet3_txq_eof(struct vmxnet3_txqueue *, u_int);
 int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxring *);
 void vmxnet3_rxq_eof_discard(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxring *, int);
@@ -350,9 +371,10 @@ void vmxnet3_rxq_discard_chain(struct vm
 void vmxnet3_rx_csum(struct vmxnet3_rxcompdesc *, struct mbuf *);
 void vmxnet3_rxq_input(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxcompdesc *, struct mbuf *);
-void vmxnet3_rxq_eof(struct vmxnet3_rxqueue *);
+bool vmxnet3_rxq_eof(struct vmxnet3_rxqueue *, u_int);
 int vmxnet3_legacy_intr(void *);
 int vmxnet3_txrxq_intr(void *);
+void vmxnet3_handle_queue(void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -819,6 +841,10 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	int i;
 
 	for (i = 0; i < sc->vmx_nintrs; i++) {
+		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
+
+		softint_disestablish(vmxq->vxq_si);
+		vmxq->vxq_si = NULL;
 		pci_intr_disestablish(pc, sc->vmx_ihs[i]);
 	}
 	pci_intr_release(pc, sc->vmx_intrs, sc->vmx_nintrs);
@@ -859,6 +885,14 @@ vmxnet3_setup_msix_interrupts(struct vmx
 		}
 		aprint_normal_dev(sc->vmx_dev, "txrx interrupting at %s\n", intrstr);
 
+		vmxq->vxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+		vmxnet3_handle_queue, vmxq);
+		if (vmxq->vxq_si == NULL) {
+			aprint_error_dev(sc->vmx_dev,
+			"softint_establish for vxq_si failed\n");
+			return (-1);
+		}
+
 		vmxq->vxq_intr_idx = intr_idx;
 	}
 
@@ -886,6 +920,7 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
 	pci_intr_handle_t *intr;
 	void **ihs;
+	struct vmxnet3_queue *vmxq;
 	int i;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
@@ -893,6 +928,7 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 
 	intr = >vmx_intrs[0];
 	ihs = sc->vmx_ihs;
+	vmxq = >vmx_queue[0];
 
 	intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
@@ -907,6 +943,14 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 	}
 	aprint_normal_dev(sc->vmx_dev, "interrupting at %s\n", intrstr);
 
+	vmxq->vxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+	vmxnet3_handle_queue, vmxq);
+	if (vmxq->vxq_si == NULL) {
+		aprint_error_dev(sc->vmx_dev,
+		"softint_establish for vxq_si failed\n");
+		return (-1);
+	}
+
 	for (i = 0; i < MIN(sc->vmx_nrxqueues, sc->vmx_nrxqueues); i++)
 		sc->vmx_queue[i].vxq_intr_idx = 0;
 	sc->vmx_event_intr_idx = 0;
@@ -920,6 +964,7 @@ vmxnet3_setup_legacy_interrupt(struct vm
 	pci_chipset_tag_t pc = 

CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:24:18 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) uses deferred interrupt handlering like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 09:45:16 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix missing NULL check after softint_establish().


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 09:45:16 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix missing NULL check after softint_establish().


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.41 src/sys/arch/x86/pci/if_vmx.c:1.42
--- src/sys/arch/x86/pci/if_vmx.c:1.41	Mon Jul 29 02:20:59 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 09:45:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $");
 
 #include 
 #include 
@@ -1046,6 +1046,12 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 
 	txq->vxtxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 	vmxnet3_deferred_transmit, txq);
+	if (txq->vxtxq_si == NULL) {
+		mutex_obj_free(txq->vxtxq_mtx);
+		aprint_error_dev(sc->vmx_dev,
+		"softint_establish for vxtxq_si failed\n");
+		return ENOMEM;
+	}
 
 	txr->vxtxr_ndesc = sc->vmx_ntxdescs;
 	txr->vxtxr_txbuf = kmem_zalloc(txr->vxtxr_ndesc *



CVS commit: src/sys/arch/x86/pci

2019-07-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 02:20:59 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Join Tx interrupt handler and Rx interrupt handler of vmx(4).

That can reduce interrupt resources.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.40 src/sys/arch/x86/pci/if_vmx.c:1.41
--- src/sys/arch/x86/pci/if_vmx.c:1.40	Wed Jul 24 10:17:52 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 02:20:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.40 2019/07/24 10:17:52 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.40 2019/07/24 10:17:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $");
 
 #include 
 #include 
@@ -173,8 +173,6 @@ struct vmxnet3_txq_stats {
 struct vmxnet3_txqueue {
 	kmutex_t *vxtxq_mtx;
 	struct vmxnet3_softc *vxtxq_sc;
-	int vxtxq_id;
-	int vxtxq_intr_idx;
 	int vxtxq_watchdog;
 	pcq_t *vxtxq_interq;
 	struct vmxnet3_txring vxtxq_cmd_ring;
@@ -196,8 +194,6 @@ struct vmxnet3_rxq_stats {
 struct vmxnet3_rxqueue {
 	kmutex_t *vxrxq_mtx;
 	struct vmxnet3_softc *vxrxq_sc;
-	int vxrxq_id;
-	int vxrxq_intr_idx;
 	struct mbuf *vxrxq_mhead;
 	struct mbuf *vxrxq_mtail;
 	struct vmxnet3_rxring vxrxq_cmd_ring[VMXNET3_RXRINGS_PERQ];
@@ -207,6 +203,14 @@ struct vmxnet3_rxqueue {
 	char vxrxq_name[16];
 };
 
+struct vmxnet3_queue {
+	int vxq_id;
+	int vxq_intr_idx;
+
+	struct vmxnet3_txqueue vxq_txqueue;
+	struct vmxnet3_rxqueue vxq_rxqueue;
+};
+
 struct vmxnet3_statistics {
 	uint32_t vmst_defragged;
 	uint32_t vmst_defrag_failed;
@@ -224,8 +228,7 @@ struct vmxnet3_softc {
 #define VMXNET3_FLAG_RSS	(1 << 1)
 #define VMXNET3_FLAG_ATTACHED	(1 << 2)
 
-	struct vmxnet3_txqueue *vmx_txq;
-	struct vmxnet3_rxqueue *vmx_rxq;
+	struct vmxnet3_queue *vmx_queue;
 
 	struct pci_attach_args *vmx_pa;
 	pci_chipset_tag_t vmx_pc;
@@ -349,8 +352,7 @@ void vmxnet3_rxq_input(struct vmxnet3_rx
 struct vmxnet3_rxcompdesc *, struct mbuf *);
 void vmxnet3_rxq_eof(struct vmxnet3_rxqueue *);
 int vmxnet3_legacy_intr(void *);
-int vmxnet3_txq_intr(void *);
-int vmxnet3_rxq_intr(void *);
+int vmxnet3_txrxq_intr(void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -534,6 +536,7 @@ vmxnet3_attach(device_t parent, device_t
 	struct pci_attach_args *pa = aux;
 	pcireg_t preg;
 	int error;
+	int candidate;
 
 	sc->vmx_dev = self;
 	sc->vmx_pa = pa;
@@ -552,10 +555,10 @@ vmxnet3_attach(device_t parent, device_t
 	sc->vmx_mtx = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
 	callout_init(>vmx_tick, CALLOUT_MPSAFE);
 
-	sc->vmx_max_ntxqueues =
-	vmxnet3_calc_queue_size(MIN(VMXNET3_MAX_TX_QUEUES, ncpu));
-	sc->vmx_max_nrxqueues =
-	vmxnet3_calc_queue_size(MIN(VMXNET3_MAX_RX_QUEUES, ncpu));
+	candidate = MIN(MIN(VMXNET3_MAX_TX_QUEUES, VMXNET3_MAX_RX_QUEUES),
+	ncpu);
+	sc->vmx_max_ntxqueues = sc->vmx_max_nrxqueues =
+	vmxnet3_calc_queue_size(candidate);
 	sc->vmx_ntxdescs = 512;
 	sc->vmx_nrxdescs = 256;
 	sc->vmx_max_rxsegs = VMXNET3_MAX_RX_SEGS;
@@ -723,7 +726,7 @@ vmxnet3_alloc_msix_interrupts(struct vmx
 		return (1);
 
 	/* Allocate an additional vector for the events interrupt. */
-	required = sc->vmx_max_nrxqueues + sc->vmx_max_ntxqueues + 1;
+	required = MIN(sc->vmx_max_ntxqueues, sc->vmx_max_nrxqueues) + 1;
 
 	if (pci_msix_count(pa->pa_pc, pa->pa_tag) < required)
 		return (1);
@@ -825,11 +828,10 @@ int
 vmxnet3_setup_msix_interrupts(struct vmxnet3_softc *sc)
 {
 	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
-	struct vmxnet3_txqueue *txq;
-	struct vmxnet3_rxqueue *rxq;
+	struct vmxnet3_queue *vmxq;
 	pci_intr_handle_t *intr;
 	void **ihs;
-	int intr_idx, i;
+	int intr_idx, i, use_queues;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
 	char xnamebuf[32];
@@ -838,44 +840,26 @@ vmxnet3_setup_msix_interrupts(struct vmx
 	intr_idx = 0;
 	ihs = sc->vmx_ihs;
 
-	for (i = 0; i < sc->vmx_ntxqueues; i++, intr++, ihs++, intr_idx++) {
-		snprintf(xnamebuf, 32, "%s: tx %d", device_xname(sc->vmx_dev), i);
+	/* See vmxnet3_alloc_msix_interrupts() */
+	use_queues = MIN(sc->vmx_max_ntxqueues, sc->vmx_max_nrxqueues);
+	for (i = 0; i < use_queues; i++, intr++, ihs++, intr_idx++) {
+		snprintf(xnamebuf, 32, "%s: txrx %d", device_xname(sc->vmx_dev), i);
 
-		txq = >vmx_txq[i];
+		vmxq = >vmx_queue[i];
 
 		intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
 		pci_intr_setattr(pc, intr, PCI_INTR_MPSAFE, true);
 		*ihs = pci_intr_establish_xname(pc, *intr, IPL_NET,
-		vmxnet3_txq_intr, txq, 

CVS commit: src/sys/arch/x86/pci

2019-07-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 02:20:59 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Join Tx interrupt handler and Rx interrupt handler of vmx(4).

That can reduce interrupt resources.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/pci/if_vmx.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-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

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

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.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-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

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

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.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.456 src/sys/net/if.c:1.457
--- src/sys/net/if.c:1.456	Thu Jul  4 02:44:25 2019
+++ src/sys/net/if.c	Thu Jul 25 07:45:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 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.456 2019/07/04 02:44:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1043,9 +1043,9 @@ static inline bool
 if_snd_is_used(struct ifnet *ifp)
 {
 
-	return ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit ||
-	ifp->if_transmit == if_transmit ||
-	ALTQ_IS_ENABLED(>if_snd);
+	return ALTQ_IS_ENABLED(>if_snd) ||
+		ifp->if_transmit == if_transmit ||
+		ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit;
 }
 
 /*



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:17:52 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (2/2).

Fix Tx interrupt handler. I tested on ESXi 5.5.

TODO: add statistics counters


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:15:23 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
refactor: unify vmxnet3_start_locked and vmxnet_transmit_locked


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:15:23 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
refactor: unify vmxnet3_start_locked and vmxnet_transmit_locked


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.38 src/sys/arch/x86/pci/if_vmx.c:1.39
--- src/sys/arch/x86/pci/if_vmx.c:1.38	Wed Jul 24 10:13:14 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Wed Jul 24 10:15:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $");
 
 #include 
 #include 
@@ -2756,17 +2756,17 @@ vmxnet3_txq_encap(struct vmxnet3_txqueue
 	return (0);
 }
 
-void
-vmxnet3_start_locked(struct ifnet *ifp)
+#define VMXNET3_TX_START 1
+#define VMXNET3_TX_TRANSMIT 2
+static inline void
+vmxnet3_tx_common_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq, int txtype)
 {
 	struct vmxnet3_softc *sc;
-	struct vmxnet3_txqueue *txq;
 	struct vmxnet3_txring *txr;
 	struct mbuf *m_head;
 	int tx;
 
 	sc = ifp->if_softc;
-	txq = >vmx_txq[0];
 	txr = >vxtxq_cmd_ring;
 	tx = 0;
 
@@ -2777,14 +2777,20 @@ vmxnet3_start_locked(struct ifnet *ifp)
 		return;
 
 	for (;;) {
-		IFQ_POLL(>if_snd, m_head);
+		if (txtype == VMXNET3_TX_START)
+			IFQ_POLL(>if_snd, m_head);
+		else
+			m_head = pcq_peek(txq->vxtxq_interq);
 		if (m_head == NULL)
 			break;
 
 		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
 			break;
 
-		IFQ_DEQUEUE(>if_snd, m_head);
+		if (txtype == VMXNET3_TX_START)
+			IFQ_DEQUEUE(>if_snd, m_head);
+		else
+			m_head = pcq_get(txq->vxtxq_interq);
 		if (m_head == NULL)
 			break;
 
@@ -2802,6 +2808,18 @@ vmxnet3_start_locked(struct ifnet *ifp)
 		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
 }
 
+void
+vmxnet3_start_locked(struct ifnet *ifp)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txqueue *txq;
+
+	sc = ifp->if_softc;
+	txq = >vmx_txq[0];
+
+	vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_START);
+}
+
 
 void
 vmxnet3_start(struct ifnet *ifp)
@@ -2842,45 +2860,8 @@ vmxnet3_select_txqueue(struct ifnet *ifp
 void
 vmxnet3_transmit_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq)
 {
-	struct vmxnet3_softc *sc;
-	struct vmxnet3_txring *txr;
-	struct mbuf *m_head;
-	int tx;
-
-	sc = ifp->if_softc;
-	txr = >vxtxq_cmd_ring;
-	tx = 0;
-
-	VMXNET3_TXQ_LOCK_ASSERT(txq);
-
-	if ((ifp->if_flags & IFF_RUNNING) == 0 ||
-	sc->vmx_link_active == 0)
-		return;
-
-	for (;;) {
-		m_head = pcq_peek(txq->vxtxq_interq);
-		if (m_head == NULL)
-			break;
 
-		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
-			break;
-
-		m_head = pcq_get(txq->vxtxq_interq);
-		if (m_head == NULL)
-			break;
-
-		if (vmxnet3_txq_encap(txq, _head) != 0) {
-			if (m_head != NULL)
-m_freem(m_head);
-			break;
-		}
-
-		tx++;
-		bpf_mtap(ifp, m_head, BPF_D_OUT);
-	}
-
-	if (tx > 0)
-		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
+	vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_TRANSMIT);
 }
 
 int



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:13:14 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (1/2)

Implemented Tx processing only. Fix Tx interrupt handler later.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:13:14 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (1/2)

Implemented Tx processing only. Fix Tx interrupt handler later.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.37 src/sys/arch/x86/pci/if_vmx.c:1.38
--- src/sys/arch/x86/pci/if_vmx.c:1.37	Tue Jul 23 04:50:05 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Wed Jul 24 10:13:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $");
 
 #include 
 #include 
@@ -29,6 +29,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -174,6 +175,7 @@ struct vmxnet3_txqueue {
 	int vxtxq_id;
 	int vxtxq_intr_idx;
 	int vxtxq_watchdog;
+	pcq_t *vxtxq_interq;
 	struct vmxnet3_txring vxtxq_cmd_ring;
 	struct vmxnet3_comp_ring vxtxq_comp_ring;
 	struct vmxnet3_txq_stats vxtxq_stats;
@@ -371,6 +373,8 @@ void vmxnet3_txq_unload_mbuf(struct vmxn
 int vmxnet3_txq_encap(struct vmxnet3_txqueue *, struct mbuf **);
 void vmxnet3_start_locked(struct ifnet *);
 void vmxnet3_start(struct ifnet *);
+void vmxnet3_transmit_locked(struct ifnet *, struct vmxnet3_txqueue *);
+int vmxnet3_transmit(struct ifnet *, struct mbuf *);
 
 void vmxnet3_set_rxfilter(struct vmxnet3_softc *);
 int vmxnet3_ioctl(struct ifnet *, u_long, void *);
@@ -1061,6 +1065,8 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 
 	txq->vxtxq_comp_ring.vxcr_ndesc = sc->vmx_ntxdescs;
 
+	txq->vxtxq_interq = pcq_create(sc->vmx_ntxdescs, KM_SLEEP);
+
 	return (0);
 }
 
@@ -1134,12 +1140,17 @@ void
 vmxnet3_destroy_txq(struct vmxnet3_txqueue *txq)
 {
 	struct vmxnet3_txring *txr;
+	struct mbuf *m;
 
 	txr = >vxtxq_cmd_ring;
 
 	txq->vxtxq_sc = NULL;
 	txq->vxtxq_id = -1;
 
+	while ((m = pcq_get(txq->vxtxq_interq)) != NULL)
+		m_freem(m);
+	pcq_destroy(txq->vxtxq_interq);
+
 	if (txr->vxtxr_txbuf != NULL) {
 		kmem_free(txr->vxtxr_txbuf,
 		txr->vxtxr_ndesc * sizeof(struct vmxnet3_txbuf));
@@ -1704,6 +1715,7 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = vmxnet3_ioctl;
 	ifp->if_start = vmxnet3_start;
+	ifp->if_transmit = vmxnet3_transmit;
 	ifp->if_watchdog = NULL;
 	ifp->if_init = vmxnet3_init;
 	ifp->if_stop = vmxnet3_stop;
@@ -2805,6 +2817,95 @@ vmxnet3_start(struct ifnet *ifp)
 	VMXNET3_TXQ_UNLOCK(txq);
 }
 
+static int
+vmxnet3_select_txqueue(struct ifnet *ifp, struct mbuf *m __unused)
+{
+	struct vmxnet3_softc *sc;
+	u_int cpuid;
+
+	sc = ifp->if_softc;
+	cpuid = cpu_index(curcpu());
+	/*
+	 * Furure work
+	 * We should select txqueue to even up the load even if ncpu is
+	 * different from sc->vmx_ntxqueues. Currently, the load is not
+	 * even, that is, when ncpu is six and ntxqueues is four, the load
+	 * of vmx_txq[0] and vmx_txq[1] is higher than vmx_txq[2] and
+	 * vmx_txq[3] because CPU#4 always uses vmx_txq[0] and CPU#5 always
+	 * uses vmx_txq[1].
+	 * Furthermore, we should not use random value to select txqueue to
+	 * avoid reordering. We should use flow information of mbuf.
+	 */
+	return cpuid % sc->vmx_ntxqueues;
+}
+
+void
+vmxnet3_transmit_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txring *txr;
+	struct mbuf *m_head;
+	int tx;
+
+	sc = ifp->if_softc;
+	txr = >vxtxq_cmd_ring;
+	tx = 0;
+
+	VMXNET3_TXQ_LOCK_ASSERT(txq);
+
+	if ((ifp->if_flags & IFF_RUNNING) == 0 ||
+	sc->vmx_link_active == 0)
+		return;
+
+	for (;;) {
+		m_head = pcq_peek(txq->vxtxq_interq);
+		if (m_head == NULL)
+			break;
+
+		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
+			break;
+
+		m_head = pcq_get(txq->vxtxq_interq);
+		if (m_head == NULL)
+			break;
+
+		if (vmxnet3_txq_encap(txq, _head) != 0) {
+			if (m_head != NULL)
+m_freem(m_head);
+			break;
+		}
+
+		tx++;
+		bpf_mtap(ifp, m_head, BPF_D_OUT);
+	}
+
+	if (tx > 0)
+		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
+}
+
+int
+vmxnet3_transmit(struct ifnet *ifp, struct mbuf *m)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txqueue *txq;
+	int qid;
+
+	qid = vmxnet3_select_txqueue(ifp, m);
+	sc = ifp->if_softc;
+	txq = >vmx_txq[qid];
+
+	if (__predict_false(!pcq_put(txq->vxtxq_interq, m))) {
+		m_freem(m);
+		return ENOBUFS;
+	}
+
+	VMXNET3_TXQ_LOCK(txq);
+	vmxnet3_transmit_locked(ifp, txq);
+	VMXNET3_TXQ_UNLOCK(txq);
+
+	

CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 23 04:50:05 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be detached now.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 23 04:50:05 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be detached now.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.36 src/sys/arch/x86/pci/if_vmx.c:1.37
--- src/sys/arch/x86/pci/if_vmx.c:1.36	Mon Jul 22 06:52:06 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 23 04:50:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $");
 
 #include 
 #include 
@@ -223,6 +223,7 @@ struct vmxnet3_softc {
 	struct vmxnet3_rxqueue *vmx_rxq;
 
 	struct pci_attach_args *vmx_pa;
+	pci_chipset_tag_t vmx_pc;
 
 	bus_space_tag_t vmx_iot0;
 	bus_space_tag_t vmx_iot1;
@@ -528,6 +529,7 @@ vmxnet3_attach(device_t parent, device_t
 
 	sc->vmx_dev = self;
 	sc->vmx_pa = pa;
+	sc->vmx_pc = pa->pa_pc;
 	if (pci_dma64_available(pa))
 		sc->vmx_dmat = pa->pa_dmat64;
 	else
@@ -802,7 +804,7 @@ vmxnet3_alloc_interrupts(struct vmxnet3_
 void
 vmxnet3_free_interrupts(struct vmxnet3_softc *sc)
 {
-	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
+	pci_chipset_tag_t pc = sc->vmx_pc;
 	int i;
 
 	for (i = 0; i < sc->vmx_nintrs; i++) {



CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 22 06:52:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
remove unnecessary NULL check after kmem_zalloc(KM_SLEEP)


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.35 src/sys/arch/x86/pci/if_vmx.c:1.36
--- src/sys/arch/x86/pci/if_vmx.c:1.35	Fri Jul 19 08:49:44 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 22 06:52:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $");
 
 #include 
 #include 
@@ -1030,8 +1030,6 @@ vmxnet3_init_rxq(struct vmxnet3_softc *s
 		rxr->vxrxr_ndesc = sc->vmx_nrxdescs;
 		rxr->vxrxr_rxbuf = kmem_zalloc(rxr->vxrxr_ndesc *
 		sizeof(struct vmxnet3_rxbuf), KM_SLEEP);
-		if (rxr->vxrxr_rxbuf == NULL)
-			return (ENOMEM);
 
 		rxq->vxrxq_comp_ring.vxcr_ndesc += sc->vmx_nrxdescs;
 	}
@@ -1058,8 +1056,6 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 	txr->vxtxr_ndesc = sc->vmx_ntxdescs;
 	txr->vxtxr_txbuf = kmem_zalloc(txr->vxtxr_ndesc *
 	sizeof(struct vmxnet3_txbuf), KM_SLEEP);
-	if (txr->vxtxr_txbuf == NULL)
-		return (ENOMEM);
 
 	txq->vxtxq_comp_ring.vxcr_ndesc = sc->vmx_ntxdescs;
 
@@ -1093,8 +1089,6 @@ vmxnet3_alloc_rxtx_queues(struct vmxnet3
 	sizeof(struct vmxnet3_rxqueue) * sc->vmx_max_nrxqueues, KM_SLEEP);
 	sc->vmx_txq = kmem_zalloc(
 	sizeof(struct vmxnet3_txqueue) * sc->vmx_max_ntxqueues, KM_SLEEP);
-	if (sc->vmx_rxq == NULL || sc->vmx_txq == NULL)
-		return (ENOMEM);
 
 	for (i = 0; i < sc->vmx_max_nrxqueues; i++) {
 		error = vmxnet3_init_rxq(sc, i);



CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 22 06:52:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
remove unnecessary NULL check after kmem_zalloc(KM_SLEEP)


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:49:44 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be set IFEF_MPSAFE now.

I tested bidirectional forwarding with some ioctls.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.34 src/sys/arch/x86/pci/if_vmx.c:1.35
--- src/sys/arch/x86/pci/if_vmx.c:1.34	Fri Jul 19 08:46:32 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Jul 19 08:49:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $");
 
 #include 
 #include 
@@ -1705,6 +1705,7 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	strlcpy(ifp->if_xname, device_xname(sc->vmx_dev), IFNAMSIZ);
 	ifp->if_softc = sc;
 	ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX;
+	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = vmxnet3_ioctl;
 	ifp->if_start = vmxnet3_start;
 	ifp->if_watchdog = NULL;



CVS commit: src/sys/arch/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:49:44 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be set IFEF_MPSAFE now.

I tested bidirectional forwarding with some ioctls.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:46:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Store IFF_ALLMULTI in ec->ec_flags instead of ifp->if_flags.

See such as if_wm.c:1.636.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.33 src/sys/arch/x86/pci/if_vmx.c:1.34
--- src/sys/arch/x86/pci/if_vmx.c:1.33	Fri Jul 19 08:31:41 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Jul 19 08:46:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.33 2019/07/19 08:31:41 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.33 2019/07/19 08:31:41 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $");
 
 #include 
 #include 
@@ -2820,7 +2820,9 @@ vmxnet3_set_rxfilter(struct vmxnet3_soft
 	uint8_t *p;
 
 	ds->mcast_tablelen = 0;
-	CLR(ifp->if_flags, IFF_ALLMULTI);
+	ETHER_LOCK(ec);
+	CLR(ec->ec_flags, ETHER_F_ALLMULTI);
+	ETHER_UNLOCK(ec);
 
 	/*
 	 * Always accept broadcast frames.
@@ -2864,7 +2866,9 @@ vmxnet3_set_rxfilter(struct vmxnet3_soft
 	goto setit;
 
 allmulti:
-	SET(ifp->if_flags, IFF_ALLMULTI);
+	ETHER_LOCK(ec);
+	SET(ec->ec_flags, ETHER_F_ALLMULTI);
+	ETHER_UNLOCK(ec);
 	SET(mode, (VMXNET3_RXMODE_ALLMULTI | VMXNET3_RXMODE_MCAST));
 	if (ifp->if_flags & IFF_PROMISC)
 		SET(mode, VMXNET3_RXMODE_PROMISC);



CVS commit: src/sys/arch/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:46:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Store IFF_ALLMULTI in ec->ec_flags instead of ifp->if_flags.

See such as if_wm.c:1.636.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:31:41 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) enable jumbo frame.

I tested 1600 mtu to/from Linux vmxnet3.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.32 src/sys/arch/x86/pci/if_vmx.c:1.33
--- src/sys/arch/x86/pci/if_vmx.c:1.32	Tue Jul 16 10:12:10 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Jul 19 08:31:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.32 2019/07/16 10:12:10 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.33 2019/07/19 08:31:41 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.32 2019/07/16 10:12:10 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.33 2019/07/19 08:31:41 knakahara Exp $");
 
 #include 
 #include 
@@ -1721,7 +1721,7 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	sc->vmx_ethercom.ec_if.if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
 
 	sc->vmx_ethercom.ec_capabilities |=
-	ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING;
+	ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING | ETHERCAP_JUMBO_MTU;
 	sc->vmx_ethercom.ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
 
 	IFQ_SET_MAXLEN(>if_snd, sc->vmx_ntxdescs);



CVS commit: src/sys/arch/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:31:41 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) enable jumbo frame.

I tested 1600 mtu to/from Linux vmxnet3.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 16 10:12:10 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix vmx(4) MTU setting.

Advised by hikaru@n.o and msaitoh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-07-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 16 10:12:10 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix vmx(4) MTU setting.

Advised by hikaru@n.o and msaitoh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.31 src/sys/arch/x86/pci/if_vmx.c:1.32
--- src/sys/arch/x86/pci/if_vmx.c:1.31	Tue Jul 16 10:01:23 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 16 10:12:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.31 2019/07/16 10:01:23 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.32 2019/07/16 10:12:10 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.31 2019/07/16 10:01:23 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.32 2019/07/16 10:12:10 knakahara Exp $");
 
 #include 
 #include 
@@ -372,7 +372,6 @@ void vmxnet3_start_locked(struct ifnet *
 void vmxnet3_start(struct ifnet *);
 
 void vmxnet3_set_rxfilter(struct vmxnet3_softc *);
-int vmxnet3_change_mtu(struct vmxnet3_softc *, int);
 int vmxnet3_ioctl(struct ifnet *, u_long, void *);
 int vmxnet3_ifflags_cb(struct ethercom *);
 
@@ -2877,18 +2876,6 @@ setit:
 }
 
 int
-vmxnet3_change_mtu(struct vmxnet3_softc *sc, int mtu)
-{
-
-	if (mtu < VMXNET3_MIN_MTU || mtu > VMXNET3_MAX_MTU)
-		return EINVAL;
-
-	vmxnet3_init_locked(sc);
-
-	return 0;
-}
-
-int
 vmxnet3_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct vmxnet3_softc *sc = ifp->if_softc;
@@ -2896,13 +2883,20 @@ vmxnet3_ioctl(struct ifnet *ifp, u_long 
 	int s, error = 0;
 
 	switch (cmd) {
-	case SIOCSIFMTU:
-		if (ifp->if_mtu != ifr->ifr_mtu) {
-			VMXNET3_CORE_LOCK(sc);
-			error = vmxnet3_change_mtu(sc, ifr->ifr_mtu);
-			VMXNET3_CORE_UNLOCK(sc);
+	case SIOCSIFMTU: {
+		int nmtu = ifr->ifr_mtu;
+
+		if (nmtu < VMXNET3_MIN_MTU || nmtu > VMXNET3_MAX_MTU) {
+			error = EINVAL;
+			break;
+		}
+		if (ifp->if_mtu != nmtu) {
+			error = ether_ioctl(ifp, cmd, data);
+			if (error == ENETRESET)
+error = vmxnet3_init(ifp);
 		}
 		break;
+	}
 	case SIOCGIFDATA:
 	case SIOCZIFDATA:
 		ifp->if_ipackets = 0;



CVS commit: src/sys/arch/x86/pci

2019-07-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 16 10:01:24 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Eliminate IFF_RUNNING checking code from vmxnet3_init_locked().

Advised by hikaru@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/pci/if_vmx.c

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

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.30 src/sys/arch/x86/pci/if_vmx.c:1.31
--- src/sys/arch/x86/pci/if_vmx.c:1.30	Tue Jul  9 08:46:58 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 16 10:01:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.30 2019/07/09 08:46:58 msaitoh Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.31 2019/07/16 10:01:23 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.30 2019/07/09 08:46:58 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.31 2019/07/16 10:01:23 knakahara Exp $");
 
 #include 
 #include 
@@ -1752,14 +1752,12 @@ void
 vmxnet3_evintr(struct vmxnet3_softc *sc)
 {
 	device_t dev;
-	struct ifnet *ifp;
 	struct vmxnet3_txq_shared *ts;
 	struct vmxnet3_rxq_shared *rs;
 	uint32_t event;
 	int reset;
 
 	dev = sc->vmx_dev;
-	ifp = >vmx_ethercom.ec_if;
 	reset = 0;
 
 	VMXNET3_CORE_LOCK(sc);
@@ -1791,10 +1789,8 @@ vmxnet3_evintr(struct vmxnet3_softc *sc)
 	if (event & VMXNET3_EVENT_DEBUG)
 		device_printf(dev, "debug event\n");
 
-	if (reset != 0) {
-		ifp->if_flags &= ~IFF_RUNNING;
+	if (reset != 0)
 		vmxnet3_init_locked(sc);
-	}
 
 	VMXNET3_CORE_UNLOCK(sc);
 }
@@ -2504,9 +2500,6 @@ vmxnet3_init_locked(struct vmxnet3_softc
 	struct ifnet *ifp = >vmx_ethercom.ec_if;
 	int error;
 
-	if (ifp->if_flags & IFF_RUNNING)
-		return 0;
-
 	vmxnet3_stop_locked(sc);
 
 	error = vmxnet3_reinit(sc);
@@ -2886,15 +2879,11 @@ setit:
 int
 vmxnet3_change_mtu(struct vmxnet3_softc *sc, int mtu)
 {
-	struct ifnet *ifp = >vmx_ethercom.ec_if;
 
 	if (mtu < VMXNET3_MIN_MTU || mtu > VMXNET3_MAX_MTU)
 		return EINVAL;
 
-	if (ifp->if_flags & IFF_RUNNING) {
-		ifp->if_flags &= ~IFF_RUNNING;
-		vmxnet3_init_locked(sc);
-	}
+	vmxnet3_init_locked(sc);
 
 	return 0;
 }
@@ -3012,11 +3001,9 @@ void
 vmxnet3_tick(void *xsc)
 {
 	struct vmxnet3_softc *sc;
-	struct ifnet *ifp;
 	int i, timedout;
 
 	sc = xsc;
-	ifp = >vmx_ethercom.ec_if;
 	timedout = 0;
 
 	VMXNET3_CORE_LOCK(sc);
@@ -3026,10 +3013,9 @@ vmxnet3_tick(void *xsc)
 	for (i = 0; i < sc->vmx_ntxqueues; i++)
 		timedout |= vmxnet3_watchdog(>vmx_txq[i]);
 
-	if (timedout != 0) {
-		ifp->if_flags &= ~IFF_RUNNING;
+	if (timedout != 0)
 		vmxnet3_init_locked(sc);
-	} else
+	else
 		callout_reset(>vmx_tick, hz, vmxnet3_tick, sc);
 
 	VMXNET3_CORE_UNLOCK(sc);



CVS commit: src/sys/arch/x86/pci

2019-07-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 16 10:01:24 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Eliminate IFF_RUNNING checking code from vmxnet3_init_locked().

Advised by hikaru@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/pci/if_vmx.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/x86/pci

2019-06-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun 26 10:20:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: msipic.c

Log Message:
Fix updating "Multiple Message Enable" field for MSI multiple vectors. Pointed 
out by jmcneill@n.o, thanks.

I tested ahcisata for MSI single vector regression.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/pci/msipic.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/x86/pci

2019-06-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun 26 10:20:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: msipic.c

Log Message:
Fix updating "Multiple Message Enable" field for MSI multiple vectors. Pointed 
out by jmcneill@n.o, thanks.

I tested ahcisata for MSI single vector regression.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/pci/msipic.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/pci/msipic.c
diff -u src/sys/arch/x86/pci/msipic.c:1.16 src/sys/arch/x86/pci/msipic.c:1.17
--- src/sys/arch/x86/pci/msipic.c:1.16	Tue Jun 18 10:06:49 2019
+++ src/sys/arch/x86/pci/msipic.c	Wed Jun 26 10:20:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msipic.c,v 1.16 2019/06/18 10:06:49 msaitoh Exp $	*/
+/*	$NetBSD: msipic.c,v 1.17 2019/06/26 10:20:06 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.16 2019/06/18 10:06:49 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.17 2019/06/26 10:20:06 knakahara Exp $");
 
 #include "opt_intrdebug.h"
 
@@ -37,6 +37,7 @@ __KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -754,6 +755,25 @@ msipic_set_msi_vectors(struct pic *msi_p
 
 	KASSERT(msipic_is_msi_pic(msi_pic));
 
+	if (msi_pic->pic_type == PIC_MSI) {
+		pci_chipset_tag_t pc;
+		struct pci_attach_args *pa;
+		pcitag_t tag;
+		int off, err __diagused;
+		pcireg_t ctl;
+
+		pc = NULL;
+		pa = _pic->pic_msipic->mp_pa;
+		tag = pa->pa_tag;
+		err = pci_get_capability(pc, tag, PCI_CAP_MSI, , NULL);
+		KASSERT(err != 0);
+
+		ctl = pci_conf_read(pc, tag, off + PCI_MSI_CTL);
+		ctl &= ~PCI_MSI_CTL_MME_MASK;
+		ctl |= __SHIFTIN(ilog2(count), PCI_MSI_CTL_MME_MASK);
+		pci_conf_write(pc, tag, off + PCI_MSI_CTL, ctl);
+	}
+
 	msi_pic->pic_msipic->mp_veccnt = count;
 	return 0;
 }



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

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 04:31:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Add TODO comments to support MSI multiple vectors on x86 systems.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/intr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.144 src/sys/arch/x86/x86/intr.c:1.145
--- src/sys/arch/x86/x86/intr.c:1.144	Fri Feb 15 08:54:01 2019
+++ src/sys/arch/x86/x86/intr.c	Wed Jun  5 04:31:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.144 2019/02/15 08:54:01 nonaka Exp $	*/
+/*	$NetBSD: intr.c,v 1.145 2019/06/05 04:31:37 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.144 2019/02/15 08:54:01 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.145 2019/06/05 04:31:37 knakahara Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -661,6 +661,19 @@ intr_allocate_slot(struct pic *pic, int 
 	if (pic == _pic) {
 		idtvec = ICU_OFFSET + pin;
 	} else {
+		/*
+		 * TODO to support MSI (not MSI-X) multiple vectors
+		 *
+		 * PCI Local Bus Specification Revision 3.0 says the devices
+		 * which use MSI multiple vectors increment the low order bits
+		 * of MSI message data.
+		 * On the other hand, Intel SDM "10.11.2 Message Data Register
+		 * Format" says the 7:0 bits of MSI message data mean Interrupt
+		 * Descriptor Table(IDT) vector.
+		 * As the result of these two documents, the IDT vectors which
+		 * are used by a device using MSI multiple vectors must be
+		 * continuous.
+		 */
 		idtvec = idt_vec_alloc(APIC_LEVEL(level), IDT_INTR_HIGH);
 	}
 	if (idtvec == 0) {



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

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 04:31:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Add TODO comments to support MSI multiple vectors on x86 systems.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/intr.c

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



CVS commit: src/sys/netinet

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 01:31:05 UTC 2019

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
The packets which will be esp-fragmented should not be applied pfil. Pointed 
out by ohishi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/sys/netinet/ip_output.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/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.313 src/sys/netinet/ip_output.c:1.314
--- src/sys/netinet/ip_output.c:1.313	Wed Jun  5 01:27:20 2019
+++ src/sys/netinet/ip_output.c	Wed Jun  5 01:31:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.313 2019/06/05 01:27:20 knakahara Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.314 2019/06/05 01:31:04 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.313 2019/06/05 01:27:20 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.314 2019/06/05 01:31:04 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -616,15 +616,18 @@ sendit:
 		if (error || ipsec_done)
 			goto done;
 	}
-#endif
 
-	/*
-	 * Run through list of hooks for output packets.
-	 */
-	error = pfil_run_hooks(inet_pfil_hook, , ifp, PFIL_OUT);
-	if (error || m == NULL) {
-		IP_STATINC(IP_STAT_PFILDROP_OUT);
-		goto done;
+	if (!ipsec_used || !natt_frag)
+#endif
+	{
+		/*
+		 * Run through list of hooks for output packets.
+		 */
+		error = pfil_run_hooks(inet_pfil_hook, , ifp, PFIL_OUT);
+		if (error || m == NULL) {
+			IP_STATINC(IP_STAT_PFILDROP_OUT);
+			goto done;
+		}
 	}
 
 	ip = mtod(m, struct ip *);



CVS commit: src/sys/netinet

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 01:31:05 UTC 2019

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
The packets which will be esp-fragmented should not be applied pfil. Pointed 
out by ohishi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/sys/netinet/ip_output.c

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



CVS commit: src/sys/netinet

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 01:27:20 UTC 2019

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
Fix rtcache cannot be released once an esp-fragmented packet is sent. Pointed 
out by ohishi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.312 -r1.313 src/sys/netinet/ip_output.c

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



CVS commit: src/sys/netinet

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 01:27:20 UTC 2019

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
Fix rtcache cannot be released once an esp-fragmented packet is sent. Pointed 
out by ohishi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.312 -r1.313 src/sys/netinet/ip_output.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/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.312 src/sys/netinet/ip_output.c:1.313
--- src/sys/netinet/ip_output.c:1.312	Wed May 15 02:59:18 2019
+++ src/sys/netinet/ip_output.c	Wed Jun  5 01:27:20 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.312 2019/05/15 02:59:18 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.313 2019/06/05 01:27:20 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.312 2019/05/15 02:59:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.313 2019/06/05 01:27:20 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -777,7 +777,7 @@ sendit:
 		 * processing can occur.
 		 */
 		if (natt_frag) {
-			error = ip_output(m, opt, ro,
+			error = ip_output(m, opt, NULL,
 			flags | IP_RAWOUTPUT | IP_NOIPNEWID,
 			imo, inp);
 		} else {



CVS commit: src/sys/netipsec

2019-05-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri May 17 05:27:24 UTC 2019

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
Don't clear calculated Tx tos value for IPv[46] over IPv6.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.15 src/sys/netipsec/ipsecif.c:1.16
--- src/sys/netipsec/ipsecif.c:1.15	Fri Apr 12 07:12:12 2019
+++ src/sys/netipsec/ipsecif.c	Fri May 17 05:27:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.15 2019/04/12 07:12:12 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.16 2019/05/17 05:27:24 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.15 2019/04/12 07:12:12 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.16 2019/05/17 05:27:24 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -583,13 +583,13 @@ ipsecif6_output(struct ipsec_variant *va
 		return ENETUNREACH;
 	}
 #ifndef IPSEC_TX_TOS_CLEAR
+	if (!ip6_ipsec_copy_tos)
+		otos = 0;
+
 	if (ifp->if_flags & IFF_ECN)
 		ip_ecn_ingress(ECN_ALLOWED, , );
 	else
 		ip_ecn_ingress(ECN_NOCARE, , );
-
-	if (!ip6_ipsec_copy_tos)
-		otos = 0;
 #else
 	if (ip6_ipsec_copy_tos)
 		otos = itos;



CVS commit: src/sys/netipsec

2019-05-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri May 17 05:27:24 UTC 2019

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
Don't clear calculated Tx tos value for IPv[46] over IPv6.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/netipsec/ipsecif.c

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



CVS commit: src/sys/netinet

2019-05-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 15 03:33:41 UTC 2019

Modified Files:
src/sys/netinet: ip_encap.c

Log Message:
Fix build failure when INET6 is disabled. Pointed out by ozaki-r@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/netinet/ip_encap.c

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



CVS commit: src/sys/netinet

2019-05-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 15 03:33:41 UTC 2019

Modified Files:
src/sys/netinet: ip_encap.c

Log Message:
Fix build failure when INET6 is disabled. Pointed out by ozaki-r@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/netinet/ip_encap.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/netinet/ip_encap.c
diff -u src/sys/netinet/ip_encap.c:1.70 src/sys/netinet/ip_encap.c:1.71
--- src/sys/netinet/ip_encap.c:1.70	Fri Sep 14 05:09:51 2018
+++ src/sys/netinet/ip_encap.c	Wed May 15 03:33:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.70 2018/09/14 05:09:51 maxv Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.71 2019/05/15 03:33:41 knakahara Exp $	*/
 /*	$KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $	*/
 
 /*
@@ -68,7 +68,7 @@
 #define USE_RADIX
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.70 2018/09/14 05:09:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.71 2019/05/15 03:33:41 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -79,6 +79,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v
 #include 
 #include 
 #include 
+#include  /* for softnet_lock */
 #include 
 #include 
 #include 



Re: CVS commit: src/sys/dev/pci

2018-06-08 Thread Kengo NAKAHARA
Hi,

Sorry, I checked it fixed panic only. iwm.c:r1.81 and r1.82 fix this problem
at my environment.

Could you try latest kernel with these commits?


Thanks,

On 2018/06/09 3:14, Ryo ONODERA wrote:
> Hi,
> 
> This change causes the following error and I cannot use iwm(4) device
> anymore.
> Could you take a look at my problem?
> 
> $ ifconfig iwm0
> ifconfig: SIOCGIFFLAGS iwm0: Device not configured
> 
> dmesg is here:
> (snip)
> iwm0 at pci2 dev 0 function 0: vendor 8086 product 24fd (rev. 0x78)
> iwm0: interrupting at msi2 vec 0
> (snip)
> iwm0: hw rev 0x230, fw ver 22.361476.0, address 74:e5:f9:69:6c:bb
> iwm0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 
> 36Mbps 48Mbps 54Mbps
> 
> 
> From: "Kengo NAKAHARA" , Date: Tue, 5 Jun 2018 12:17:18 
> +
> 
>> Module Name: src
>> Committed By:knakahara
>> Date:Tue Jun  5 12:17:18 UTC 2018
>>
>> Modified Files:
>>  src/sys/dev/pci: if_iwm.c
>>
>> Log Message:
>> Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.
>>
>> XXX pullup-8
>>
>>
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.78 -r1.79 src/sys/dev/pci/if_iwm.c
>>
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
>>
> 
> --
> Ryo ONODERA // r...@tetera.org
> PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3
> 

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA 


Re: CVS commit: src/share/man/man4

2018-02-07 Thread Kengo NAKAHARA
Hi,

On 2018/02/07 19:12, m...@netbsd.org wrote:
> Hi!
> 
> Please give credit in the future.
> 
> It can be very important for a new contributor, I used to show my
> friends, "look, I made this change, and it says I did it!" and it was
> very cool.
> 
> Even though they were small contributions, they were my biggest
> contributions.
> 
> (For example:
> Mention jumbo frame support.
> From David H. Gutteridge in PR misc/52890)

Sorry, I update the commit message. And I will be careful in future.


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys

2018-01-08 Thread Kengo NAKAHARA
Hi,

On 2018/01/09 8:27, Christos Zoulas wrote:
> In article <20180108232325.522d0f...@cvs.netbsd.org>,
> Kengo NAKAHARA <source-changes-d@NetBSD.org> wrote:
>>  size_t hash;
>>
>> +printf(" %s: enter\n", __func__);
>> +
>>  ip6 = mtod(m, const struct ip6_hdr *);
>>
>>  KERNEL_LOCK_UNLESS_NET_MPSAFE();
>> @@ -571,8 +573,12 @@ ip6flow_create(struct route *ro, struct 
>>   *
>>   * Don't create a flow for ICMPv6 messages.
>>   */
>> -if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP)
>> +if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP) {
>> +printf(" %s: icmp skip\n", __func__);
>>  goto out;
>> +}
>> +
>> +printf(" %s: ip6->ip6_nxt=%d\n", __func__, ip6->ip6_nxt);
>>
>>  /*
>>   * See if an existing flow exists.  If so:
>>
> 
> These look like an accident.

Yes. Sorry, I revert the wrong modifications and re-commit the fix.


Thanks,

-- 
//////
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys

2017-12-17 Thread Kengo NAKAHARA
Hi,

On 2017/12/17 2:17, Robert Elz wrote:
> Date:Fri, 15 Dec 2017 21:24:20 +0700
> From:Robert Elz <k...@munnari.oz.au>
> Message-ID:  <11642.1513347...@andromeda.noi.kre.to>
> 
>   | Unfortunately, because of the way it gets called, this might not be an
>   | easy change to make.
> 
> It wouldn't be, but it also turns out to be (I think) unnecessary.
> 
> The m_pullup() (or equiv) isn't needed at all, as you determined initially,
> m_copydata() handles fetching data from multiple mbufs (or an external
> cluster if needed).
> 
> The problem with your first fix was that you were checking whether the
> current mbuf contained the session-ID which it might not, it could be
> later - but we really do not need to care (and if it isn't there we
> do not need to fix it).
> 
> What I'd suggest doing (and the same for the inet6 case) is to make the
> function be ...
> 
> [aside don't cut& paste from this e-mail, it will have had most tabs
> turned into spaces...]
> 
> static int
> in_l2tp_match(struct mbuf *m, int off, int proto, void *arg)
> {
> struct l2tp_variant *var = arg;
> uint32_t sess_id;
> 
> KASSERT(proto == IPPROTO_L2TP);
> 
>   /*
>* If the packet contains no session ID it cannot match
>*/
> if (m_length(m) < off + sizeof(uint32_t))
>   return 0;
>  
> /* get L2TP session ID */
> m_copydata(m, off, sizeof(uint32_t), (void *)_id);
> NTOHL(sess_id);
> if (sess_id == 0) {
> /*
>  * L2TPv3 control packet received.
>  * userland daemon(l2tpd?) should process.
>  */
> return 32 * 2;
> } else if (sess_id == var->lv_my_sess_id)
> return 32 * 2;
> else
> return 0;
> }

You are right. I fix it by your patch at in_l2tp.c:r1.9 and in6_l2tp.c:r1.12.


Thanks,

-- 
//////
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/arch/x86/x86

2017-08-07 Thread Kengo NAKAHARA
Hi maxv@n.o,

On 2017/08/08 2:12, Maxime Villard wrote:
> Le 07/08/2017 à 10:38, Kengo NAKAHARA a écrit :
>> "intrctl affinity" in NetBSD-current causes panic. Here is the backtrace
>> 
>> panic: kernel diagnostic assertion "mutex_owned(_lock) || !mp_online" 
>> failed: file 
>> "/disk4/home/k-nakahara/repos/netbsd-src/sys/arch/x86/x86/idt.c", line 122
>> fatal breakpoint trap in supervisor mode
>> trap type 1 code 0 rip 0x802249e5 cs 0x8 rflags 0x246 cr2 
>> 0x72ca08412d98 ilevel 0 rsp 0xe4010e898dc0
>> curlwp 0xe4010e88a0c0 pid 0.22 lowest kstack 0xe4010e8952c0
>> Stopped in pid 0.22 (system) at netbsd:breakpoint+0x5:  leave
>> db{1}> bt
>> breakpoint() at netbsd:breakpoint+0x5
>> vpanic() at netbsd:vpanic+0x140
>> ch_voltag_convert_in() at netbsd:ch_voltag_convert_in
>> idt_vec_set() at netbsd:idt_vec_set+0x82
>> intr_activate_xcall() at netbsd:intr_activate_xcall+0x8a
>> xc_thread() at netbsd:xc_thread+0xd4
>> 
>>
>> ozaki-r@n.o bisects and finds the following commit causes this panic.
>>
>> On 2017/08/01 3:54, Maxime Villard wrote:
>>> Module Name:src
>>> Committed By:   maxv
>>> Date:   Mon Jul 31 18:54:40 UTC 2017
>>>
>>> Modified Files:
>>> src/sys/arch/x86/x86: intr.c
>>>
>>> Log Message:
>>> Use idt_vec_set instead.
>>>
>>>
>>> To generate a diff of this commit:
>>> cvs rdiff -u -r1.101 -r1.102 src/sys/arch/x86/x86/intr.c
>>>
>>> Please note that diffs are not public domain; they are subject to the
>>> copyright notices on the relevant files.
>>
>> I think setgate() must be called with kpreempt_disable() and
>> x86_disable_intr(). However, I don't know why setgate() must be called
>> with mutex_onwed(_lock). Could you tell me why mutex_onwed(_lock)
>> is required?
> 
> setgate already disables preemption on amd64, but not on i386. I guess
> this needs to be investigated.

I see. Hmm, I also research about it when I can.


> Otherwise it's fixed, thanks

I test latest kernel(including idt.c:r1.5), and I confirm the bug is
fixed. Thank you.


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/arch/x86/x86

2017-08-07 Thread Kengo NAKAHARA
Hi maxv@n.o,

"intrctl affinity" in NetBSD-current causes panic. Here is the backtrace

panic: kernel diagnostic assertion "mutex_owned(_lock) || !mp_online" 
failed: file "/disk4/home/k-nakahara/repos/netbsd-src/sys/arch/x86/x86/idt.c", 
line 122
fatal breakpoint trap in supervisor mode
trap type 1 code 0 rip 0x802249e5 cs 0x8 rflags 0x246 cr2 
0x72ca08412d98 ilevel 0 rsp 0xe4010e898dc0
curlwp 0xe4010e88a0c0 pid 0.22 lowest kstack 0xe4010e8952c0
Stopped in pid 0.22 (system) at netbsd:breakpoint+0x5:  leave
db{1}> bt
breakpoint() at netbsd:breakpoint+0x5
vpanic() at netbsd:vpanic+0x140
ch_voltag_convert_in() at netbsd:ch_voltag_convert_in
idt_vec_set() at netbsd:idt_vec_set+0x82
intr_activate_xcall() at netbsd:intr_activate_xcall+0x8a
xc_thread() at netbsd:xc_thread+0xd4


ozaki-r@n.o bisects and finds the following commit causes this panic.

On 2017/08/01 3:54, Maxime Villard wrote:
> Module Name:  src
> Committed By: maxv
> Date: Mon Jul 31 18:54:40 UTC 2017
> 
> Modified Files:
>   src/sys/arch/x86/x86: intr.c
> 
> Log Message:
> Use idt_vec_set instead.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.101 -r1.102 src/sys/arch/x86/x86/intr.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.

I think setgate() must be called with kpreempt_disable() and
x86_disable_intr(). However, I don't know why setgate() must be called
with mutex_onwed(_lock). Could you tell me why mutex_onwed(_lock)
is required?

BTW, do you have any idea to fix this panic?


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/dev/scsipi

2017-06-18 Thread Kengo NAKAHARA
Hi,

Today, I found my environment panic while rebooting. As bisecting, it
seems the cause is below commit.

On 2017/06/18 7:35, Michael van Elst wrote:
> Module Name:  src
> Committed By: mlelstv
> Date: Sat Jun 17 22:35:50 UTC 2017
> 
> Modified Files:
>   src/sys/dev/scsipi: atapiconf.c cd.c scsi_base.c scsiconf.c
>   scsipi_base.c sd.c ss.c st.c
> 
> Log Message:
> The atapibus detach path did hold the channel mutex while calling into 
> autoconf,
> which would trigger a panic when unplugging a USB ATAPI CDROM.
> 
> Align detach code for scsibus and atapibus to fix this.
> 
> Also avoid races when detaching devices by replacing callout_stop with
> callout_halt.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.90 -r1.91 src/sys/dev/scsipi/atapiconf.c
> cvs rdiff -u -r1.340 -r1.341 src/sys/dev/scsipi/cd.c
> cvs rdiff -u -r1.91 -r1.92 src/sys/dev/scsipi/scsi_base.c
> cvs rdiff -u -r1.279 -r1.280 src/sys/dev/scsipi/scsiconf.c
> cvs rdiff -u -r1.175 -r1.176 src/sys/dev/scsipi/scsipi_base.c
> cvs rdiff -u -r1.324 -r1.325 src/sys/dev/scsipi/sd.c
> cvs rdiff -u -r1.88 -r1.89 src/sys/dev/scsipi/ss.c
> cvs rdiff -u -r1.230 -r1.231 src/sys/dev/scsipi/st.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.

The panic message is here.

// snip
Jun 19 22:48:28 syncing disks... done
config_detach: detached device scsibus0 has children sd0
Skipping crash dump on recursive panic
panic: config_detach
fatal breakpoint trap in supervisor mode
trap type 1 code 0 rip 0x802249f5 cs 0x8 rflags 0x246 cr2 
0x70c8884aa38f ilevel 0 rsp 0xe4011099cc80
curlwp 0xe4027de12140 pid 632.1 lowest kstack 0xe401109992c0
Stopped in pid 632.1 (reboot) atnetbsd:breakpoint+0x5:  leave
db{2}> bt
breakpoint() at netbsd:breakpoint+0x5
vpanic() at netbsd:vpanic+0x140
snprintf() at netbsd:snprintf
config_detach() at netbsd:config_detach+0x218
config_detach_all() at netbsd:config_detach_all+0x97
cpu_reboot() at netbsd:cpu_reboot+0x173
sys_reboot() at netbsd:sys_reboot+0x75
syscall() at netbsd:syscall+0x1d8
--- syscall (number 208) ---
70c88843e5ba:

The addr2line of config_detach()+0x218 is here.
https://nxr.netbsd.org/xref/src/sys/kern/subr_autoconf.c#1728

My environment is amd64 which use sd0(USB Flash) as root filesystem.

Could someone have any solution?


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys

2016-09-12 Thread Kengo NAKAHARA
Hi,

On 2016/09/12 17:28, Roy Marples wrote:
> On 09/09/2016 20:08, Martin Husemann wrote:
>> On Thu, Sep 08, 2016 at 02:19:15PM +0900, Kengo NAKAHARA wrote:
>>>
>>> On 2016/09/08 0:41, Roy Marples wrote:
>>>> Module Name:   src
>>>> Committed By:  roy
>>>> Date:  Wed Sep  7 15:41:44 UTC 2016
>>>>
>>>> Modified Files:
>>>>src/sys/netinet: ip_input.c
>>>>src/sys/netinet6: ip6_input.c
>>>>
>>>> Log Message:
>>>> Disallow input to detached addresses because they are not yet valid.
>>>>
>>>>
>>>> To generate a diff of this commit:
>>>> cvs rdiff -u -r1.340 -r1.341 src/sys/netinet/ip_input.c
>>>> cvs rdiff -u -r1.167 -r1.168 src/sys/netinet6/ip6_input.c
>>>>
>>>> Please note that diffs are not public domain; they are subject to the
>>>> copyright notices on the relevant files.
>>>
>>> ATF net/if_pppoe/t_pppoe:pap fails after this commit. I revert this
>>> commit locally, and then the ATF become successful.
>>
>> I see the failure too, but manually configuring two rump servers in a very
>> similar setup than the test still works for me - something must be wrong
>> in the test, but I don't see it right now.
> 
> martin@ did more testing and discovered that the PPP connection works
> fine, so something is wrong in the test.
> 
> I believe that the function wait_for_session_established needs an
> additional pause to wait for the detached flag to clear.
> If the interface is marked IFF_UP at this point, it should be possible
> to add ifconfig -w 5 -W -5 and the test should then succeed. I'm getting
> symbol errors still trying to run this test so cannot fix it myself
> right now.

I add ifconfig -w 15 -W 15 in wait_for_session_established(), however
net/if_pppoe/t_pppoe:pap still fails.

Hmm, does my below modification match your pointing out, doesn't it?

--- net/if_pppoe/t_pppoe.orig   2016-09-12 18:16:26.610435947 +0900
+++ net/if_pppoe/t_pppoe2016-09-12 18:30:14.756955057 +0900
@@ -99,6 +99,8 @@
sleep 1
done
 
+   env RUMP_SERVER=$CLIENT rump.ifconfig -w 15 -W 15
+
if [ $dontfail != "dontfail" ]; then
    atf_fail "Couldn't connect to the server for $n seconds."
fi


 
Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys

2016-09-07 Thread Kengo NAKAHARA
Hi roy@n.o,

On 2016/09/08 0:41, Roy Marples wrote:
> Module Name:  src
> Committed By: roy
> Date: Wed Sep  7 15:41:44 UTC 2016
> 
> Modified Files:
>   src/sys/netinet: ip_input.c
>   src/sys/netinet6: ip6_input.c
> 
> Log Message:
> Disallow input to detached addresses because they are not yet valid.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.340 -r1.341 src/sys/netinet/ip_input.c
> cvs rdiff -u -r1.167 -r1.168 src/sys/netinet6/ip6_input.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.

ATF net/if_pppoe/t_pppoe:pap fails after this commit. I revert this
commit locally, and then the ATF become successful.

Could you check your ATF results?


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/arch/x86/x86

2016-07-11 Thread Kengo NAKAHARA
Hi,

On 2016/07/12 0:21, David Holland wrote:
> On Mon, Jul 11, 2016 at 09:42:20AM +0000, Kengo NAKAHARA wrote:
>  > Log Message:
>  > strncpy should use destination buf length instead of source buf length.
>  > 
>  > pointed out by nonaka@n.o.
> 
> this should almost certainly be strlcpy, not strncpy.

Thank you for your point out. I fix it.


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/share/man/man9

2016-07-06 Thread Kengo NAKAHARA
Hi,

On 2016/07/06 18:20, Abhinav Upadhyay wrote:
> Module Name:  src
> Committed By: abhinav
> Date: Wed Jul  6 09:20:42 UTC 2016
> 
> Modified Files:
>   src/share/man/man9: interrupt_distribute.9
> 
> Log Message:
> Add missing .Nd
> 
> ok wiz@, knakaraha@
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.1 -r1.2 src/share/man/man9/interrupt_distribute.9

Thank you for your fixes.


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/net

2016-06-27 Thread Kengo NAKAHARA
Hi,

On 2016/06/27 18:55, Roy Marples wrote:
> On 27/06/2016 09:58, Kengo NAKAHARA wrote:
>> Module Name: src
>> Committed By:knakahara
>> Date:Mon Jun 27 08:58:50 UTC 2016
>>
>> Modified Files:
>>  src/sys/net: if.c if.h
>>
>> Log Message:
>> reduce link state changing softint if it is not required
>>
>> ok by ozaki-r@n.o
> 
> There is a spelling mistake, an n is missing.
> 
> if_is_link_state_chageable(ifp)
> 
> should be
> 
> if_is_link_state_changeable(ifp)

Thank you for your point out. I fix it if.c:r1.347 and if.h:r1.217.


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/net

2016-01-13 Thread Kengo NAKAHARA
Hi,

On 2016/01/13 7:10, David Laight wrote:
> On Fri, Dec 11, 2015 at 11:37:29AM +0900, Kengo NAKAHARA wrote:
>> # Sorry, I forgot to subscribe source-changes-d ml, I reply as
>> # a new mail.
>>
>> Hi,
>>
>>> In article <20151210081103.E0FBBFB83%cvs.NetBSD.org@localhost>,
>>> Kengo NAKAHARA <source-changes-d%NetBSD.org@localhost> wrote:
>>>> -=-=-=-=-=-
>>>>
>>>> Module Name:   src
>>>> Committed By:  knakahara
>>>> Date:  Thu Dec 10 08:11:03 UTC 2015
>>>>
>>>> Modified Files:
>>>>src/sys/net: if_gif.c
>>>>
>>>> Log Message:
>>>> kmem_zalloc(, KM_SLEEP) must not return NULL.
>>>
>>> I would like to solicit opinions about this change and form a general
>>> policy.
>>>
>>> 1. I would like to reduce the use of KASSERT in the kernel, specially
>>> in situations like thee above where the test can be centralized (inside
>>> kmem_alloc) and avoided without being fatal.
>>
>> OK, this kmem_zalloc() is not fatal. I should avoid KASSERT here.
> 
> There is no real point using KASSERT() when the immediate
> dereference of NULL will have the same effect and is about as
> easy to debug.
> 
> Whether kmem_alloc(KM_SLEEP) can return NULL is another matter.
> Seems wrong to me - maybe even for impossible allications.
> ISTR a problem waiting for KVA and phys-mem being 'difficult'.
> I know that the Linux equivalent will return NULL, not sure when.
> It would be useful to define that allocation for non-huge
> (maybe even several MB) amounts will always sleep.
> 
>   David

Have you read this thread?
http://mail-index.netbsd.org/tech-kern/2015/12/11/msg019762.html

I think Mr. Chuck Silvers points out a similar issue.
http://mail-index.netbsd.org/tech-kern/2015/12/11/msg019772.html


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
Core Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


Re: CVS commit: src/sys/net

2015-12-10 Thread Kengo NAKAHARA
# Sorry, I forgot to subscribe source-changes-d ml, I reply as
# a new mail.

Hi,

> In article <20151210081103.E0FBBFB83%cvs.NetBSD.org@localhost>,
> Kengo NAKAHARA <source-changes-d%NetBSD.org@localhost> wrote:
>>-=-=-=-=-=-
>>
>>Module Name:  src
>>Committed By: knakahara
>>Date: Thu Dec 10 08:11:03 UTC 2015
>>
>>Modified Files:
>>  src/sys/net: if_gif.c
>>
>>Log Message:
>>kmem_zalloc(, KM_SLEEP) must not return NULL.
> 
> I would like to solicit opinions about this change and form a general
> policy.
> 
> 1. I would like to reduce the use of KASSERT in the kernel, specially
> in situations like thee above where the test can be centralized (inside
> kmem_alloc) and avoided without being fatal.

OK, this kmem_zalloc() is not fatal. I should avoid KASSERT here.


> 2. Static analyzer models understand allocators, but they are not
> smart enough to determine under which situations they can fail. I
> believe even kmem_alloc with KM_SLEEP can fail when the size is
> large enough.

I have a question. The man of kmem(9) says:

 kmflags  Either of the following:

  KM_SLEEPIf the allocation cannot be satisfied immediately,
  sleep until enough memory is available.

Is this manual incorrect?
I'm confused... Could you tell me easily comprehensible manual?


> So I propose to always check the return value of allocators with
> an 'if' and not a KASSERT.

There are some codes like "foo = kmem_alloc(size, KM_SLEEP); KASSERT(foo != 
NULL)".
Should the codes be unified to use not KASSERT' but if'?


Thanks,

-- 
//
Internet Initiative Japan Inc.

Device Engineering Section,
Core Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA <k-nakah...@iij.ad.jp>


  1   2   >