CVS commit: src/sys/uvm

2017-05-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu May 18 02:21:05 UTC 2017

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

Log Message:
more snprintb bits


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/uvm/uvm_map.h

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

Modified files:

Index: src/sys/uvm/uvm_map.h
diff -u src/sys/uvm/uvm_map.h:1.73 src/sys/uvm/uvm_map.h:1.74
--- src/sys/uvm/uvm_map.h:1.73	Wed May 25 13:43:58 2016
+++ src/sys/uvm/uvm_map.h	Wed May 17 22:21:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.h,v 1.73 2016/05/25 17:43:58 christos Exp $	*/
+/*	$NetBSD: uvm_map.h,v 1.74 2017/05/18 02:21:05 christos Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -238,6 +238,13 @@ struct vm_map {
 #define	VM_MAP_TOPDOWN		0x40		/* ro: arrange map top-down */
 #define	VM_MAP_WANTVA		0x100		/* rw: want va */
 
+#define VM_MAP_BITS	"\177\020\
+b\0PAGEABLE\0\
+b\2WIREFUTURE\0\
+b\5DYING\0\
+b\6TOPDOWN\0\
+b\10WANTVA\0"
+
 #ifdef _KERNEL
 struct uvm_map_args {
 	struct vm_map_entry *uma_prev;



CVS commit: src/sys/dev/pci

2017-05-17 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu May 18 01:32:46 UTC 2017

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

Log Message:
Fixed m is not freed if m_defrag() fails.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/if_rtwn.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/if_rtwn.c
diff -u src/sys/dev/pci/if_rtwn.c:1.11 src/sys/dev/pci/if_rtwn.c:1.12
--- src/sys/dev/pci/if_rtwn.c:1.11	Thu Feb  2 10:05:35 2017
+++ src/sys/dev/pci/if_rtwn.c	Thu May 18 01:32:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_rtwn.c,v 1.11 2017/02/02 10:05:35 nonaka Exp $	*/
+/*	$NetBSD: if_rtwn.c,v 1.12 2017/05/18 01:32:46 nonaka Exp $	*/
 /*	$OpenBSD: if_rtwn.c,v 1.5 2015/06/14 08:02:47 stsp Exp $	*/
 #define	IEEE80211_NO_HT
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_rtwn.c,v 1.11 2017/02/02 10:05:35 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_rtwn.c,v 1.12 2017/05/18 01:32:46 nonaka Exp $");
 
 #include 
 #include 
@@ -1957,10 +1957,13 @@ rtwn_tx(struct rtwn_softc *sc, struct mb
 	}
 	if (error != 0) {
 		/* Too many DMA segments, linearize mbuf. */
-		if ((m = m_defrag(m, M_DONTWAIT)) == NULL) {
+		struct mbuf *newm = m_defrag(m, M_DONTWAIT);
+		if (newm == NULL) {
 			aprint_error_dev(sc->sc_dev, "can't defrag mbuf\n");
+			m_freem(m);
 			return ENOBUFS;
 		}
+		m = newm;
 
 		error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m,
 		BUS_DMA_NOWAIT | BUS_DMA_WRITE);



CVS commit: src/sys/uvm

2017-05-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 17 22:43:12 UTC 2017

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

Log Message:
snprintb(3) for UVM_FLAGS.


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/uvm/uvm_extern.h

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

Modified files:

Index: src/sys/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.204 src/sys/uvm/uvm_extern.h:1.205
--- src/sys/uvm/uvm_extern.h:1.204	Sat May  6 17:34:52 2017
+++ src/sys/uvm/uvm_extern.h	Wed May 17 18:43:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.204 2017/05/06 21:34:52 joerg Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.205 2017/05/17 22:43:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -132,6 +132,48 @@
 #define UVM_FLAG_VAONLY  0x200 /* unmap: no pages are mapped */
 #define UVM_FLAG_COLORMATCH 0x400 /* match color given in off */
 
+#define UVM_FLAG_BITS "\177\020\
+F\0\3\
+:\0PROT=NONE\0\
+:\1PROT=R\0\
+:\2PROT=W\0\
+:\3PROT=RW\0\
+:\4PROT=X\0\
+:\5PROT=RX\0\
+:\6PROT=WX\0\
+:\7PROT=RWX\0\
+F\4\2\
+:\0INH=SHARE\0\
+:\1INH=COPY\0\
+:\2INH=NONE\0\
+:\3INH=DONATE\0\
+F\10\3\
+:\0MAXPROT=NONE\0\
+:\1MAXPROT=R\0\
+:\2MAXPROT=W\0\
+:\3MAXPROT=RW\0\
+:\4MAXPROT=X\0\
+:\5MAXPROT=RX\0\
+:\6MAXPROT=WX\0\
+:\7MAXPROT=RWX\0\
+F\14\3\
+:\0ADV=NORMAL\0\
+:\1ADV=RANDOM\0\
+:\2ADV=SEQUENTIAL\0\
+:\3ADV=WILLNEED\0\
+:\4ADV=DONTNEED\0\
+:\5ADV=NOREUSE\0\
+b\20FIXED\0\
+b\21OVERLAY\0\
+b\22NOMERGE\0\
+b\23COPYONW\0\
+b\24AMAPPAD\0\
+b\25TRYLOCK\0\
+b\26NOWAIT\0\
+b\27WAITVA\0\
+b\30VAONLY\0\
+b\31COLORMATCH\0"
+
 /* macros to extract info */
 #define UVM_PROTECTION(X)	((X) & UVM_PROT_MASK)
 #define UVM_INHERIT(X)		(((X) & UVM_INH_MASK) >> 4)



CVS commit: src/external/gpl3/gcc/dist/gcc

2017-05-17 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Wed May 17 22:06:10 UTC 2017

Modified Files:
src/external/gpl3/gcc/dist/gcc: auto-profile.c
graphite-isl-ast-to-gimple.c system.h

Log Message:
Fix building GCC 5 with clang 4.0
Obtained from FreeBSD ports r432958
https://svnweb.freebsd.org/ports?view=revision=432958
"doesn't compile with recent versions of libc++, because it attempts to 
redefine abort():
/usr/include/c++/v1/functional:1398:2: error: no member named 'fancy_abort' in 
namespace 'std::__1'; did you mean simply 'fancy_abort'?
_VSTD::abort();
^~~
/usr/include/c++/v1/__config:383:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE"


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/gpl3/gcc/dist/gcc/auto-profile.c \
src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc/dist/gcc/system.h

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

Modified files:

Index: src/external/gpl3/gcc/dist/gcc/auto-profile.c
diff -u src/external/gpl3/gcc/dist/gcc/auto-profile.c:1.1.1.1 src/external/gpl3/gcc/dist/gcc/auto-profile.c:1.2
--- src/external/gpl3/gcc/dist/gcc/auto-profile.c:1.1.1.1	Sun Jan 24 06:06:05 2016
+++ src/external/gpl3/gcc/dist/gcc/auto-profile.c	Wed May 17 22:06:10 2017
@@ -19,11 +19,11 @@ along with GCC; see the file COPYING3.  
 .  */
 
 #include "config.h"
-#include "system.h"
 
 #include 
 #include 
 #include 
+#include "system.h"
 
 #include "coretypes.h"
 #include "hash-set.h"
Index: src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c
diff -u src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c:1.1.1.1 src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c:1.2
--- src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c:1.1.1.1	Sun Jan 24 06:06:08 2016
+++ src/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c	Wed May 17 22:06:10 2017
@@ -38,6 +38,7 @@ extern "C" {
 #endif
 #endif
 
+#include 
 #include "system.h"
 #include "coretypes.h"
 #include "hash-set.h"
@@ -75,7 +76,6 @@ extern "C" {
 #include "tree-scalar-evolution.h"
 #include "gimple-ssa.h"
 #include "tree-into-ssa.h"
-#include 
 
 #ifdef HAVE_isl
 #include "graphite-poly.h"

Index: src/external/gpl3/gcc/dist/gcc/system.h
diff -u src/external/gpl3/gcc/dist/gcc/system.h:1.4 src/external/gpl3/gcc/dist/gcc/system.h:1.5
--- src/external/gpl3/gcc/dist/gcc/system.h:1.4	Sun Jan 24 09:43:31 2016
+++ src/external/gpl3/gcc/dist/gcc/system.h	Wed May 17 22:06:10 2017
@@ -224,6 +224,7 @@ extern int errno;
 #ifdef __cplusplus
 # include 
 # include 
+# include 
 # include 
 #endif
 #endif



CVS commit: src/sys/dev/pci

2017-05-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 17 20:13:02 UTC 2017

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

Log Message:
more precise m_freem() on error paths, and update m after the m_defrag() call


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/pci/if_vioif.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/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.36 src/sys/dev/pci/if_vioif.c:1.37
--- src/sys/dev/pci/if_vioif.c:1.36	Wed May 17 20:04:50 2017
+++ src/sys/dev/pci/if_vioif.c	Wed May 17 20:13:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.36 2017/05/17 20:04:50 jdolecek Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.37 2017/05/17 20:13:02 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.36 2017/05/17 20:04:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.37 2017/05/17 20:13:02 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -832,19 +832,19 @@ vioif_start(struct ifnet *ifp)
 			if (newm == NULL) {
 aprint_error_dev(sc->sc_dev,
 "m_defrag() failed\n");
-m_freem(m);
 goto skip;
 			}
 
+			m = newm;
 			r = bus_dmamap_load_mbuf(virtio_dmat(vsc),
 	 sc->sc_tx_dmamaps[slot],
-	 newm, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
+	 m, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
 			if (r != 0) {
 aprint_error_dev(sc->sc_dev,
 	   			"tx dmamap load failed, error code %d\n",
 r);
-m_freem(newm);
 skip:
+m_freem(m);
 virtio_enqueue_abort(vsc, vq, slot);
 continue;
 			}
@@ -860,6 +860,7 @@ skip:
 			bus_dmamap_unload(virtio_dmat(vsc),
 	  sc->sc_tx_dmamaps[slot]);
 			/* slot already freed by virtio_enqueue_reserve */
+			m_freem(m);
 			continue;
 		}
 



CVS commit: src/sys/dev/pci

2017-05-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 17 20:04:50 UTC 2017

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

Log Message:
simplify vioif_start() - remove the delivery attempts on failure and retries,
leave that for the dedicated thread

if dma map load fails, retry after m_defrag(), but continue processing
other queue items regardless

set interface queue length according to the length of virtio queue, so that
higher layer won't queue more than interface can manage to keep in flight

use the mutexes always, not just with NET_MPSAFE, so they continue
being exercised and hence working; they also enforce proper IPL level

inspired by discussion around PR kern/52211, thanks to Masanobu SAITOH
for the m_defrag() idea and code


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/pci/if_vioif.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/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.35 src/sys/dev/pci/if_vioif.c:1.36
--- src/sys/dev/pci/if_vioif.c:1.35	Wed May 17 18:21:40 2017
+++ src/sys/dev/pci/if_vioif.c	Wed May 17 20:04:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.35 2017/05/17 18:21:40 jdolecek Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.36 2017/05/17 20:04:50 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.35 2017/05/17 18:21:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.36 2017/05/17 20:04:50 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -226,8 +226,8 @@ struct vioif_softc {
 	}			sc_ctrl_inuse;
 	kcondvar_t		sc_ctrl_wait;
 	kmutex_t		sc_ctrl_wait_lock;
-	kmutex_t		*sc_tx_lock;
-	kmutex_t		*sc_rx_lock;
+	kmutex_t		sc_tx_lock;
+	kmutex_t		sc_rx_lock;
 	bool			sc_stopping;
 
 	bool			sc_has_ctrl;
@@ -235,12 +235,12 @@ struct vioif_softc {
 #define VIRTIO_NET_TX_MAXNSEGS		(16) /* XXX */
 #define VIRTIO_NET_CTRL_MAC_MAXENTRIES	(64) /* XXX */
 
-#define VIOIF_TX_LOCK(_sc)	if ((_sc)->sc_tx_lock) mutex_enter((_sc)->sc_tx_lock)
-#define VIOIF_TX_UNLOCK(_sc)	if ((_sc)->sc_tx_lock) mutex_exit((_sc)->sc_tx_lock)
-#define VIOIF_TX_LOCKED(_sc)	(!(_sc)->sc_tx_lock || mutex_owned((_sc)->sc_tx_lock))
-#define VIOIF_RX_LOCK(_sc)	if ((_sc)->sc_rx_lock) mutex_enter((_sc)->sc_rx_lock)
-#define VIOIF_RX_UNLOCK(_sc)	if ((_sc)->sc_rx_lock) mutex_exit((_sc)->sc_rx_lock)
-#define VIOIF_RX_LOCKED(_sc)	(!(_sc)->sc_rx_lock || mutex_owned((_sc)->sc_rx_lock))
+#define VIOIF_TX_LOCK(_sc)	mutex_enter(&(_sc)->sc_tx_lock)
+#define VIOIF_TX_UNLOCK(_sc)	mutex_exit(&(_sc)->sc_tx_lock)
+#define VIOIF_TX_LOCKED(_sc)	mutex_owned(&(_sc)->sc_tx_lock)
+#define VIOIF_RX_LOCK(_sc)	mutex_enter(&(_sc)->sc_rx_lock)
+#define VIOIF_RX_UNLOCK(_sc)	mutex_exit(&(_sc)->sc_rx_lock)
+#define VIOIF_RX_LOCKED(_sc)	mutex_owned(&(_sc)->sc_rx_lock)
 
 /* cfattach interface functions */
 static int	vioif_match(device_t, cfdata_t, void *);
@@ -439,7 +439,7 @@ vioif_alloc_mems(struct vioif_softc *sc)
 		C_L1(txhdr_dmamaps[i], tx_hdrs[i],
 		sizeof(struct virtio_net_hdr), 1,
 		WRITE, "tx header");
-		C(tx_dmamaps[i], NULL, ETHER_MAX_LEN, 16 /* XXX */, 0,
+		C(tx_dmamaps[i], NULL, ETHER_MAX_LEN, VIRTIO_NET_TX_MAXNSEGS, 0,
 		  "tx payload");
 	}
 
@@ -592,13 +592,8 @@ vioif_attach(device_t parent, device_t s
 
 	aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(sc->sc_mac));
 
-#ifdef VIOIF_MPSAFE
-	sc->sc_tx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
-	sc->sc_rx_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
-#else
-	sc->sc_tx_lock = NULL;
-	sc->sc_rx_lock = NULL;
-#endif
+	mutex_init(>sc_tx_lock, MUTEX_DEFAULT, IPL_NET);
+	mutex_init(>sc_rx_lock, MUTEX_DEFAULT, IPL_NET);
 	sc->sc_stopping = false;
 
 	/*
@@ -680,6 +675,8 @@ skip:
 	ifp->if_stop = vioif_stop;
 	ifp->if_capabilities = 0;
 	ifp->if_watchdog = vioif_watchdog;
+	IFQ_SET_MAXLEN(>if_snd, MAX(sc->sc_vq[VQ_TX].vq_num, IFQ_MAXLEN));
+	IFQ_SET_READY(>if_snd);
 
 	sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
 
@@ -690,10 +687,8 @@ skip:
 	return;
 
 err:
-	if (sc->sc_tx_lock)
-		mutex_obj_free(sc->sc_tx_lock);
-	if (sc->sc_rx_lock)
-		mutex_obj_free(sc->sc_rx_lock);
+	mutex_destroy(>sc_tx_lock);
+	mutex_destroy(>sc_rx_lock);
 
 	if (sc->sc_has_ctrl) {
 		cv_destroy(>sc_ctrl_wait);
@@ -799,7 +794,7 @@ vioif_start(struct ifnet *ifp)
 	struct virtio_softc *vsc = sc->sc_virtio;
 	struct virtqueue *vq = >sc_vq[VQ_TX];
 	struct mbuf *m;
-	int queued = 0, retry = 0;
+	int queued = 0;
 
 	VIOIF_TX_LOCK(sc);
 
@@ -814,41 +809,58 @@ vioif_start(struct ifnet *ifp)
 		int slot, r;
 
 		IFQ_DEQUEUE(>if_snd, m);
-
 		if (m == NULL)
 			break;
 
-retry:
 		r = virtio_enqueue_prep(vsc, vq, );
 		if (r == EAGAIN) {
 			ifp->if_flags |= IFF_OACTIVE;
-			vioif_tx_vq_done_locked(vq);
-			if (retry++ == 0)
-goto retry;
-			else
-break;
+			m_freem(m);
+			break;
 		}
 		if (r != 0)
 			

CVS commit: src/sys/net/npf

2017-05-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 17 18:56:12 UTC 2017

Modified Files:
src/sys/net/npf: npf_ctl.c

Log Message:
Allow npf to be used "normally" from a rump kernel, not just from the
test harness (problem reported by Frank Kardel)


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/net/npf/npf_ctl.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/npf/npf_ctl.c
diff -u src/sys/net/npf/npf_ctl.c:1.47 src/sys/net/npf/npf_ctl.c:1.48
--- src/sys/net/npf/npf_ctl.c:1.47	Sat Jan 28 19:15:54 2017
+++ src/sys/net/npf/npf_ctl.c	Wed May 17 14:56:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_ctl.c,v 1.47 2017/01/29 00:15:54 christos Exp $	*/
+/*	$NetBSD: npf_ctl.c,v 1.48 2017/05/17 18:56:12 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.47 2017/01/29 00:15:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.48 2017/05/17 18:56:12 christos Exp $");
 
 #include 
 #include 
@@ -491,6 +491,10 @@ npf_mk_connlist(npf_t *npf, prop_array_t
 	return error;
 }
 
+#if defined(_NPF_TESTING) || defined(_NPF_STANDALONE)
+int npfctl_testing;
+#endif
+
 /*
  * npfctl_load: store passed data i.e. update settings, create passed
  * tables, rules and atomically activate all them.
@@ -512,14 +516,17 @@ npfctl_load(npf_t *npf, u_long cmd, void
 	int error;
 
 	/* Retrieve the dictionary. */
-#if !defined(_NPF_TESTING) && !defined(_NPF_STANDALONE)
-	error = prop_dictionary_copyin_ioctl_size(pref, cmd, _dict,
-	4 * 1024 * 1024);
-	if (error)
-		return error;
-#else
-	npf_dict = (prop_dictionary_t)pref;
+#if defined(_NPF_TESTING) || defined(_NPF_STANDALONE)
+	if (npfctl_testing)
+		npf_dict = (prop_dictionary_t)pref;
+	else
 #endif
+	{
+		error = prop_dictionary_copyin_ioctl_size(pref, cmd, _dict,
+		4 * 1024 * 1024);
+		if (error)
+		return error;
+	}
 
 	/* Dictionary for error reporting and version check. */
 	errdict = prop_dictionary_create();



CVS commit: src/usr.sbin/npf/npftest

2017-05-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 17 18:55:13 UTC 2017

Modified Files:
src/usr.sbin/npf/npftest: npftest.c

Log Message:
set "testing mode" for ioctl I/O


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/npf/npftest/npftest.c

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

Modified files:

Index: src/usr.sbin/npf/npftest/npftest.c
diff -u src/usr.sbin/npf/npftest/npftest.c:1.20 src/usr.sbin/npf/npftest/npftest.c:1.21
--- src/usr.sbin/npf/npftest/npftest.c:1.20	Mon Dec 26 18:05:05 2016
+++ src/usr.sbin/npf/npftest/npftest.c	Wed May 17 14:55:13 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: npftest.c,v 1.20 2016/12/26 23:05:05 christos Exp $	*/
+/*	$NetBSD: npftest.c,v 1.21 2017/05/17 18:55:13 christos Exp $	*/
 
 /*
  * NPF testing framework.
@@ -195,6 +195,8 @@ npf_kern_fini(void)
 #endif
 }
 
+extern int rumpns_npfctl_testing;
+
 int
 main(int argc, char **argv)
 {
@@ -276,6 +278,7 @@ main(int argc, char **argv)
 	/*
 	 * Initialise the NPF kernel component.
 	 */
+	rumpns_npfctl_testing = 1;
 	npf_kern_init();
 	rumpns_npf_test_init(inet_pton, inet_ntop, random);
 



CVS commit: src/sys/dev/pci

2017-05-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed May 17 18:21:40 UTC 2017

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

Log Message:
do not set IFF_OACTIVE if dma map load or the virtio reserve fails;
this causes interface to ignore any further TX requests if this happens
when there are no other TX requests in progress

fixes kern/52211 by Juergen Hannken-Illjes


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/pci/if_vioif.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/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.34 src/sys/dev/pci/if_vioif.c:1.35
--- src/sys/dev/pci/if_vioif.c:1.34	Tue Mar 28 04:10:33 2017
+++ src/sys/dev/pci/if_vioif.c	Wed May 17 18:21:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.34 2017/03/28 04:10:33 ozaki-r Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.35 2017/05/17 18:21:40 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.34 2017/03/28 04:10:33 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.35 2017/05/17 18:21:40 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -844,7 +844,6 @@ retry:
 		if (r != 0) {
 			bus_dmamap_unload(virtio_dmat(vsc),
 	  sc->sc_tx_dmamaps[slot]);
-			ifp->if_flags |= IFF_OACTIVE;
 			vioif_tx_vq_done_locked(vq);
 			if (retry++ == 0)
 goto retry;
@@ -868,10 +867,8 @@ retry:
 		bpf_mtap(ifp, m);
 	}
 
-	if (m != NULL) {
-		ifp->if_flags |= IFF_OACTIVE;
+	if (m != NULL)
 		m_freem(m);
-	}
 
 	if (queued > 0) {
 		virtio_enqueue_commit(vsc, vq, -1, true);



CVS commit: src/sys/dev/usb

2017-05-17 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed May 17 14:15:29 UTC 2017

Modified Files:
src/sys/dev/usb: uts.c

Log Message:
fix tpyo


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/usb/uts.c

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

Modified files:

Index: src/sys/dev/usb/uts.c
diff -u src/sys/dev/usb/uts.c:1.6 src/sys/dev/usb/uts.c:1.7
--- src/sys/dev/usb/uts.c:1.6	Thu Apr  6 20:06:44 2017
+++ src/sys/dev/usb/uts.c	Wed May 17 14:15:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uts.c,v 1.6 2017/04/06 20:06:44 macallan Exp $	*/
+/*	$NetBSD: uts.c,v 1.7 2017/05/17 14:15:29 macallan Exp $	*/
 
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uts.c,v 1.6 2017/04/06 20:06:44 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uts.c,v 1.7 2017/05/17 14:15:29 macallan Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -212,7 +212,7 @@ uts_attach(device_t parent, device_t sel
 			 * valid data
 			 */
 			aprint_debug_dev(sc->sc_hdev.sc_dev,
-			"ELAN touchscreen found, workinmg around bug.\n");
+			"ELAN touchscreen found, working around bug.\n");
 		} else {
 			aprint_error_dev(sc->sc_hdev.sc_dev,
 			"touchscreen has no range report\n");



CVS commit: src/sys/kern

2017-05-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 17 12:46:14 UTC 2017

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

Log Message:
Suspend file system while revoking a vnode.  This way no operations run
on the mounted file system during revoke and all operations see
the state before or after the revoke.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/kern/vfs_vnode.c

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

Modified files:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.87 src/sys/kern/vfs_vnode.c:1.88
--- src/sys/kern/vfs_vnode.c:1.87	Mon Apr 17 08:32:01 2017
+++ src/sys/kern/vfs_vnode.c	Wed May 17 12:46:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.87 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.88 2017/05/17 12:46:14 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.87 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.88 2017/05/17 12:46:14 hannken Exp $");
 
 #include 
 #include 
@@ -950,31 +950,48 @@ vrecycle(vnode_t *vp)
 void
 vrevoke(vnode_t *vp)
 {
+	int error;
+	struct mount *mp;
 	vnode_t *vq;
 	enum vtype type;
 	dev_t dev;
 
 	KASSERT(vp->v_usecount > 0);
 
+	mp = vp->v_mount;
+	error = vfs_suspend(mp, 0);
+	KASSERT(error == 0 || error == EOPNOTSUPP);
+	if (error)
+		mp = NULL;
+
 	mutex_enter(vp->v_interlock);
 	VSTATE_WAIT_STABLE(vp);
 	if (VSTATE_GET(vp) == VS_RECLAIMED) {
 		mutex_exit(vp->v_interlock);
-		return;
 	} else if (vp->v_type != VBLK && vp->v_type != VCHR) {
 		atomic_inc_uint(>v_usecount);
 		mutex_exit(vp->v_interlock);
 		vgone(vp);
-		return;
 	} else {
 		dev = vp->v_rdev;
 		type = vp->v_type;
 		mutex_exit(vp->v_interlock);
-	}
 
-	while (spec_node_lookup_by_dev(type, dev, ) == 0) {
-		vgone(vq);
+		while (spec_node_lookup_by_dev(type, dev, ) == 0) {
+			if (mp != vq->v_mount) {
+if (mp)
+	vfs_resume(mp);
+mp = vp->v_mount;
+error = vfs_suspend(mp, 0);
+KASSERT(error == 0 || error == EOPNOTSUPP);
+if (error)
+	mp = NULL;
+			}
+			vgone(vq);
+		}
 	}
+	if (mp)
+		vfs_resume(mp);
 }
 
 /*



CVS commit: src/sys/kern

2017-05-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed May 17 12:45:03 UTC 2017

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

Log Message:
Suspend file system while unmounting.  This way no operations run
on the mounted file system during unmount and all operations see
the state before or after the (possibly failed) unmount.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/kern/vfs_mount.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.61 src/sys/kern/vfs_mount.c:1.62
--- src/sys/kern/vfs_mount.c:1.61	Sun May  7 08:26:58 2017
+++ src/sys/kern/vfs_mount.c	Wed May 17 12:45:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.61 2017/05/07 08:26:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.62 2017/05/17 12:45:03 hannken Exp $");
 
 #include 
 #include 
@@ -599,7 +599,7 @@ vflush(struct mount *mp, vnode_t *skipvp
 		 * First, flush out any vnode references from the
 		 * deferred vrele list.
 		 */
-		vfs_drainvnodes();
+		vrele_flush(mp);
 
 		vfs_vnode_iterator_init(mp, );
 
@@ -875,6 +875,12 @@ dounmount(struct mount *mp, int flags, s
 	 */
 	mutex_enter(_mutex);
 
+	error = vfs_suspend(mp, 0);
+	if (error) {
+		mutex_exit(_mutex);
+		return error;
+	}
+
 	/*
 	 * Abort unmount attempt when the filesystem is in use
 	 */
@@ -882,6 +888,7 @@ dounmount(struct mount *mp, int flags, s
 	if (mp->mnt_busynest != 0) {
 		mutex_exit(>mnt_unmounting);
 		mutex_exit(_mutex);
+		vfs_resume(mp);
 		return EBUSY;
 	}
 
@@ -933,6 +940,7 @@ dounmount(struct mount *mp, int flags, s
 			vfs_syncer_add_to_worklist(mp);
 		mp->mnt_flag |= async;
 		mutex_exit(>mnt_updating);
+		vfs_resume(mp);
 		if (used_syncer)
 			mutex_exit(_mutex);
 		if (used_extattr) {
@@ -955,6 +963,7 @@ dounmount(struct mount *mp, int flags, s
 	 */
 	mp->mnt_iflag |= IMNT_GONE;
 	mutex_exit(>mnt_unmounting);
+	vfs_resume(mp);
 
 	if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) {
 		vn_lock(coveredvp, LK_EXCLUSIVE | LK_RETRY);



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 12:11:41 UTC 2017

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

Log Message:
decrease the priority of batch crp even if there are more than one batch crp.


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

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.70 src/sys/opencrypto/crypto.c:1.71
--- src/sys/opencrypto/crypto.c:1.70	Wed May 17 11:04:38 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 12:11:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.70 2017/05/17 11:04:38 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.71 2017/05/17 12:11:41 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.70 2017/05/17 11:04:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.71 2017/05/17 12:11:41 knakahara Exp $");
 
 #include 
 #include 
@@ -1272,24 +1272,30 @@ cryptointr(void)
 			if (cap->cc_qblocked != 0)
 continue;
 
-			if (submit != NULL) {
-/*
- * We stop on finding another op,
- * regardless whether its for the same
- * driver or not.  We could keep
- * searching the queue but it might be
- * better to just use a per-driver
- * queue instead.
- */
-if (CRYPTO_SESID2HID(submit->crp_sid) == hid)
-	hint = CRYPTO_HINT_MORE;
-break;
-			} else {
-submit = crp;
-if ((submit->crp_flags & CRYPTO_F_BATCH) == 0)
-	break;
-/* keep scanning for more are q'd */
+			/*
+			 * skip batch crp until the end of crp_q
+			 */
+			if ((crp->crp_flags & CRYPTO_F_BATCH) != 0) {
+if (submit == NULL) {
+	submit = crp;
+} else {
+	if (CRYPTO_SESID2HID(submit->crp_sid)
+	== hid)
+		hint = CRYPTO_HINT_MORE;
+}
+
+continue;
 			}
+
+			/*
+			 * found first crp which is neither blocked nor batch.
+			 */
+			submit = crp;
+			/*
+			 * batch crp can be processed much later, so clear hint.
+			 */
+			hint = 0;
+			break;
 		}
 		if (submit != NULL) {
 			TAILQ_REMOVE(_q, submit, crp_next);



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 11:04:38 UTC 2017

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

Log Message:
refactor cryptointr(), no functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.69 src/sys/opencrypto/crypto.c:1.70
--- src/sys/opencrypto/crypto.c:1.69	Wed May 17 11:03:42 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 11:04:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.69 2017/05/17 11:03:42 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.70 2017/05/17 11:04:38 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.69 2017/05/17 11:03:42 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.70 2017/05/17 11:04:38 knakahara Exp $");
 
 #include 
 #include 
@@ -1265,26 +1265,30 @@ cryptointr(void)
 submit = crp;
 break;
 			}
-			if (!cap->cc_qblocked) {
-if (submit != NULL) {
-	/*
-	 * We stop on finding another op,
-	 * regardless whether its for the same
-	 * driver or not.  We could keep
-	 * searching the queue but it might be
-	 * better to just use a per-driver
-	 * queue instead.
-	 */
-	if (CRYPTO_SESID2HID(submit->crp_sid)
-	== hid)
-		hint = CRYPTO_HINT_MORE;
+
+			/*
+			 * skip blocked crp regardless of CRYPTO_F_BATCH
+			 */
+			if (cap->cc_qblocked != 0)
+continue;
+
+			if (submit != NULL) {
+/*
+ * We stop on finding another op,
+ * regardless whether its for the same
+ * driver or not.  We could keep
+ * searching the queue but it might be
+ * better to just use a per-driver
+ * queue instead.
+ */
+if (CRYPTO_SESID2HID(submit->crp_sid) == hid)
+	hint = CRYPTO_HINT_MORE;
+break;
+			} else {
+submit = crp;
+if ((submit->crp_flags & CRYPTO_F_BATCH) == 0)
 	break;
-} else {
-	submit = crp;
-	if ((submit->crp_flags & CRYPTO_F_BATCH) == 0)
-		break;
-	/* keep scanning for more are q'd */
-}
+/* keep scanning for more are q'd */
 			}
 		}
 		if (submit != NULL) {



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 11:03:42 UTC 2017

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

Log Message:
fix cryptointr() can process unexpected request.

If migrate crp is linked after batch crp, "submit" is already set to
the batch crp. So, cryptointr() can process the batch crp instead of
the target migrate crp.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.68 src/sys/opencrypto/crypto.c:1.69
--- src/sys/opencrypto/crypto.c:1.68	Wed May 17 07:12:50 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 11:03:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.68 2017/05/17 07:12:50 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.69 2017/05/17 11:03:42 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.68 2017/05/17 07:12:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.69 2017/05/17 11:03:42 knakahara Exp $");
 
 #include 
 #include 
@@ -1262,8 +1262,7 @@ cryptointr(void)
 			cap = crypto_checkdriver(hid);
 			if (cap == NULL || cap->cc_process == NULL) {
 /* Op needs to be migrated, process it. */
-if (submit == NULL)
-	submit = crp;
+submit = crp;
 break;
 			}
 			if (!cap->cc_qblocked) {



CVS commit: src/share/man/man4

2017-05-17 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed May 17 09:03:12 UTC 2017

Modified Files:
src/share/man/man4: vioscsi.4

Log Message:
Sort SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/man/man4/vioscsi.4

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

Modified files:

Index: src/share/man/man4/vioscsi.4
diff -u src/share/man/man4/vioscsi.4:1.1 src/share/man/man4/vioscsi.4:1.2
--- src/share/man/man4/vioscsi.4:1.1	Tue May 16 23:21:53 2017
+++ src/share/man/man4/vioscsi.4	Wed May 17 09:03:12 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: vioscsi.4,v 1.1 2017/05/16 23:21:53 jdolecek Exp $
+.\" $NetBSD: vioscsi.4,v 1.2 2017/05/17 09:03:12 wiz Exp $
 .\"
 .\" Copyright (c) 2017 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -39,9 +39,9 @@ driver provides support for
 .Xr virtio 4
 SCSI adapters.
 .Sh SEE ALSO
-.Xr virtio 4 ,
 .Xr scsi 4 ,
-.Xr sd 4
+.Xr sd 4 ,
+.Xr virtio 4
 .Sh HISTORY
 The
 .Nm



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 07:12:50 UTC 2017

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

Log Message:
refactor crypto_kdispatch() in a similar way as crypto_dispatch().


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.67 src/sys/opencrypto/crypto.c:1.68
--- src/sys/opencrypto/crypto.c:1.67	Wed May 17 06:53:02 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 07:12:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.68 2017/05/17 07:12:50 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.68 2017/05/17 07:12:50 knakahara Exp $");
 
 #include 
 #include 
@@ -853,36 +853,49 @@ crypto_kdispatch(struct cryptkop *krp)
 	cryptostats.cs_kops++;
 
 	cap = crypto_checkdriver(krp->krp_hid);
-	if (cap && !cap->cc_kqblocked) {
+	/*
+	 * TODO:
+	 * If we can ensure the driver has been valid until the driver is
+	 * done crypto_unregister(), this migrate operation is not required.
+	 */
+	if (cap == NULL) {
+		TAILQ_INSERT_TAIL(_kq, krp, krp_next);
 		mutex_spin_exit(_q_mtx);
-		result = crypto_kinvoke(krp, 0);
-		if (result == ERESTART) {
-			/*
-			 * The driver ran out of resources, mark the
-			 * driver ``blocked'' for cryptop's and put
-			 * the op on the queue.
-			 */
-			mutex_spin_enter(_q_mtx);
-			crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
-			TAILQ_INSERT_HEAD(_kq, krp, krp_next);
-			cryptostats.cs_kblocks++;
-			mutex_spin_exit(_q_mtx);
 
-			/*
-			 * The krp is enqueued to crp_kq, that is,
-			 * no error occurs. So, this function should
-			 * not return error.
-			 */
-			result = 0;
-		}
-	} else {
+		return 0;
+	}
+
+	if (cap->cc_kqblocked != 0) {
 		/*
 		 * The driver is blocked, just queue the op until
 		 * it unblocks and the swi thread gets kicked.
 		 */
 		TAILQ_INSERT_TAIL(_kq, krp, krp_next);
-		result = 0;
 		mutex_spin_exit(_q_mtx);
+
+		return 0;
+	}
+
+	mutex_spin_exit(_q_mtx);
+	result = crypto_kinvoke(krp, 0);
+	if (result == ERESTART) {
+		/*
+		 * The driver ran out of resources, mark the
+		 * driver ``blocked'' for cryptop's and put
+		 * the op on the queue.
+		 */
+		mutex_spin_enter(_q_mtx);
+		crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
+		TAILQ_INSERT_HEAD(_kq, krp, krp_next);
+		cryptostats.cs_kblocks++;
+		mutex_spin_exit(_q_mtx);
+
+		/*
+		 * The krp is enqueued to crp_kq, that is,
+		 * no error occurs. So, this function should
+		 * not return error.
+		 */
+		result = 0;
 	}
 
 	return result;



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 06:53:02 UTC 2017

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

Log Message:
refactor crypto_dispatch (3/3): do "blocked" operation previously


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.66 src/sys/opencrypto/crypto.c:1.67
--- src/sys/opencrypto/crypto.c:1.66	Wed May 17 06:52:08 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 06:53:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.66 2017/05/17 06:52:08 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.66 2017/05/17 06:52:08 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.67 2017/05/17 06:53:02 knakahara Exp $");
 
 #include 
 #include 
@@ -792,44 +792,48 @@ crypto_dispatch(struct cryptop *crp)
 	}
 
 	/*
+	 * TODO:
+	 * cap->cc_qblocked should be protected by a spin lock other than
+	 * crypto_q_mtx.
+	 */
+	if (cap->cc_qblocked != 0) {
+		/*
+		 * The driver is blocked, just queue the op until
+		 * it unblocks and the swi thread gets kicked.
+		 */
+		TAILQ_INSERT_TAIL(_q, crp, crp_next);
+		mutex_spin_exit(_q_mtx);
+
+		return 0;
+	}
+
+	/*
 	 * Caller marked the request to be processed
 	 * immediately; dispatch it directly to the
 	 * driver unless the driver is currently blocked.
 	 */
-	if (!cap->cc_qblocked) {
+	mutex_spin_exit(_q_mtx);
+	result = crypto_invoke(crp, 0);
+	if (result == ERESTART) {
+		/*
+		 * The driver ran out of resources, mark the
+		 * driver ``blocked'' for cryptop's and put
+		 * the op on the queue.
+		 */
+		mutex_spin_enter(_q_mtx);
+		crypto_drivers[hid].cc_qblocked = 1;
+		TAILQ_INSERT_HEAD(_q, crp, crp_next);
+		cryptostats.cs_blocks++;
 		mutex_spin_exit(_q_mtx);
-		result = crypto_invoke(crp, 0);
-		if (result == ERESTART) {
-			/*
-			 * The driver ran out of resources, mark the
-			 * driver ``blocked'' for cryptop's and put
-			 * the op on the queue.
-			 */
-			mutex_spin_enter(_q_mtx);
-			crypto_drivers[hid].cc_qblocked = 1;
-			TAILQ_INSERT_HEAD(_q, crp, crp_next);
-			cryptostats.cs_blocks++;
-			mutex_spin_exit(_q_mtx);
 
-			/*
-			 * The crp is enqueued to crp_q, that is,
-			 * no error occurs. So, this function should
-			 * not return error.
-			 */
-			result = 0;
-		}
-		goto out_released;
-	} else {
 		/*
-		 * The driver is blocked, just queue the op until
-		 * it unblocks and the swi thread gets kicked.
+		 * The crp is enqueued to crp_q, that is,
+		 * no error occurs. So, this function should
+		 * not return error.
 		 */
-		TAILQ_INSERT_TAIL(_q, crp, crp_next);
 		result = 0;
 	}
 
-	mutex_spin_exit(_q_mtx);
-out_released:
 	return result;
 }
 



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 06:52:08 UTC 2017

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

Log Message:
refactor crypto_dispatch (2/3): divide migrate operation


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.65 src/sys/opencrypto/crypto.c:1.66
--- src/sys/opencrypto/crypto.c:1.65	Wed May 17 06:50:12 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 06:52:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.65 2017/05/17 06:50:12 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.66 2017/05/17 06:52:08 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.65 2017/05/17 06:50:12 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.66 2017/05/17 06:52:08 knakahara Exp $");
 
 #include 
 #include 
@@ -774,13 +774,29 @@ crypto_dispatch(struct cryptop *crp)
 
 	mutex_spin_enter(_q_mtx);
 
+	cap = crypto_checkdriver(hid);
+	/*
+	 * TODO:
+	 * If we can ensure the driver has been valid until the driver is
+	 * done crypto_unregister(), this migrate operation is not required.
+	 */
+	if (cap == NULL) {
+		/*
+		 * The driver must be detached, so this request will migrate
+		 * to other drivers in cryptointr() later.
+		 */
+		TAILQ_INSERT_TAIL(_q, crp, crp_next);
+		mutex_spin_exit(_q_mtx);
+
+		return 0;
+	}
+
 	/*
 	 * Caller marked the request to be processed
 	 * immediately; dispatch it directly to the
 	 * driver unless the driver is currently blocked.
 	 */
-	cap = crypto_checkdriver(hid);
-	if (cap && !cap->cc_qblocked) {
+	if (!cap->cc_qblocked) {
 		mutex_spin_exit(_q_mtx);
 		result = crypto_invoke(crp, 0);
 		if (result == ERESTART) {



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 06:50:12 UTC 2017

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

Log Message:
refactor crypto_dispatch (1/3): divide batch operation

Processing batch operation at first, crypto_q_mtx's lock region is reduced
because crp does not require crypto_q_mtx.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/opencrypto/crypto.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.64 src/sys/opencrypto/crypto.c:1.65
--- src/sys/opencrypto/crypto.c:1.64	Wed May 17 06:33:04 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 06:50:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.64 2017/05/17 06:33:04 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.65 2017/05/17 06:50:12 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.64 2017/05/17 06:33:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.65 2017/05/17 06:50:12 knakahara Exp $");
 
 #include 
 #include 
@@ -740,12 +740,12 @@ crypto_dispatch(struct cryptop *crp)
 {
 	u_int32_t hid;
 	int result;
+	struct cryptocap *cap;
 
 	KASSERT(crp != NULL);
 
 	hid = CRYPTO_SESID2HID(crp->crp_sid);
 
-	mutex_spin_enter(_q_mtx);
 	DPRINTF("crp %p, alg %d\n", crp, crp->crp_desc->crd_alg);
 
 	cryptostats.cs_ops++;
@@ -754,46 +754,8 @@ crypto_dispatch(struct cryptop *crp)
 	if (crypto_timing)
 		nanouptime(>crp_tstamp);
 #endif
-	if ((crp->crp_flags & CRYPTO_F_BATCH) == 0) {
-		struct cryptocap *cap;
-		/*
-		 * Caller marked the request to be processed
-		 * immediately; dispatch it directly to the
-		 * driver unless the driver is currently blocked.
-		 */
-		cap = crypto_checkdriver(hid);
-		if (cap && !cap->cc_qblocked) {
-			mutex_spin_exit(_q_mtx);
-			result = crypto_invoke(crp, 0);
-			if (result == ERESTART) {
-/*
- * The driver ran out of resources, mark the
- * driver ``blocked'' for cryptop's and put
- * the op on the queue.
- */
-mutex_spin_enter(_q_mtx);
-crypto_drivers[hid].cc_qblocked = 1;
-TAILQ_INSERT_HEAD(_q, crp, crp_next);
-cryptostats.cs_blocks++;
-mutex_spin_exit(_q_mtx);
 
-/*
- * The crp is enqueued to crp_q, that is,
- * no error occurs. So, this function should
- * not return error.
- */
-result = 0;
-			}
-			goto out_released;
-		} else {
-			/*
-			 * The driver is blocked, just queue the op until
-			 * it unblocks and the swi thread gets kicked.
-			 */
-			TAILQ_INSERT_TAIL(_q, crp, crp_next);
-			result = 0;
-		}
-	} else {
+	if ((crp->crp_flags & CRYPTO_F_BATCH) != 0) {
 		int wasempty = TAILQ_EMPTY(_q);
 		/*
 		 * Caller marked the request as ``ok to delay'';
@@ -801,14 +763,52 @@ crypto_dispatch(struct cryptop *crp)
 		 * when the operation is low priority and/or suitable
 		 * for batching.
 		 */
+		mutex_spin_enter(_q_mtx);
 		TAILQ_INSERT_TAIL(_q, crp, crp_next);
 		mutex_spin_exit(_q_mtx);
-		if (wasempty) {
+		if (wasempty)
 			setsoftcrypto(softintr_cookie);
+
+		return 0;
+	}
+
+	mutex_spin_enter(_q_mtx);
+
+	/*
+	 * Caller marked the request to be processed
+	 * immediately; dispatch it directly to the
+	 * driver unless the driver is currently blocked.
+	 */
+	cap = crypto_checkdriver(hid);
+	if (cap && !cap->cc_qblocked) {
+		mutex_spin_exit(_q_mtx);
+		result = crypto_invoke(crp, 0);
+		if (result == ERESTART) {
+			/*
+			 * The driver ran out of resources, mark the
+			 * driver ``blocked'' for cryptop's and put
+			 * the op on the queue.
+			 */
+			mutex_spin_enter(_q_mtx);
+			crypto_drivers[hid].cc_qblocked = 1;
+			TAILQ_INSERT_HEAD(_q, crp, crp_next);
+			cryptostats.cs_blocks++;
+			mutex_spin_exit(_q_mtx);
+
+			/*
+			 * The crp is enqueued to crp_q, that is,
+			 * no error occurs. So, this function should
+			 * not return error.
+			 */
 			result = 0;
-			goto out_released;
 		}
-
+		goto out_released;
+	} else {
+		/*
+		 * The driver is blocked, just queue the op until
+		 * it unblocks and the swi thread gets kicked.
+		 */
+		TAILQ_INSERT_TAIL(_q, crp, crp_next);
 		result = 0;
 	}
 



CVS commit: src/sys/opencrypto

2017-05-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed May 17 06:33:04 UTC 2017

Modified Files:
src/sys/opencrypto: crypto.c cryptodev.c cryptodev.h cryptosoft.c
deflate.c ocryptodev.c

Log Message:
opencrypto: cleanup debug messages.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/opencrypto/crypto.c
cvs rdiff -u -r1.89 -r1.90 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.31 -r1.32 src/sys/opencrypto/cryptodev.h
cvs rdiff -u -r1.49 -r1.50 src/sys/opencrypto/cryptosoft.c
cvs rdiff -u -r1.22 -r1.23 src/sys/opencrypto/deflate.c
cvs rdiff -u -r1.6 -r1.7 src/sys/opencrypto/ocryptodev.c

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

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.63 src/sys/opencrypto/crypto.c:1.64
--- src/sys/opencrypto/crypto.c:1.63	Wed May 10 09:45:51 2017
+++ src/sys/opencrypto/crypto.c	Wed May 17 06:33:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.63 2017/05/10 09:45:51 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.64 2017/05/17 06:33:04 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.63 2017/05/10 09:45:51 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.64 2017/05/17 06:33:04 knakahara Exp $");
 
 #include 
 #include 
@@ -363,7 +363,7 @@ crypto_newsession(u_int64_t *sid, struct
 		/* See if all the algorithms are supported. */
 		for (cr = cri; cr; cr = cr->cri_next)
 			if (crypto_drivers[hid].cc_alg[cr->cri_alg] == 0) {
-DPRINTF(("crypto_newsession: alg %d not supported\n", cr->cri_alg));
+DPRINTF("alg %d not supported\n", cr->cri_alg);
 break;
 			}
 
@@ -387,8 +387,8 @@ crypto_newsession(u_int64_t *sid, struct
 (*sid) |= (lid & 0x);
 crypto_drivers[hid].cc_sessions++;
 			} else {
-DPRINTF(("%s: crypto_drivers[%d].cc_newsession() failed. error=%d\n",
-	__func__, hid, err));
+DPRINTF("crypto_drivers[%d].cc_newsession() failed. error=%d\n",
+	hid, err);
 			}
 			goto done;
 			/*break;*/
@@ -746,8 +746,7 @@ crypto_dispatch(struct cryptop *crp)
 	hid = CRYPTO_SESID2HID(crp->crp_sid);
 
 	mutex_spin_enter(_q_mtx);
-	DPRINTF(("crypto_dispatch: crp %p, alg %d\n",
-		crp, crp->crp_desc->crd_alg));
+	DPRINTF("crp %p, alg %d\n", crp, crp->crp_desc->crd_alg);
 
 	cryptostats.cs_ops++;
 
@@ -980,7 +979,7 @@ crypto_invoke(struct cryptop *crp, int h
 		/*
 		 * Invoke the driver to process the request.
 		 */
-		DPRINTF(("calling process for %p\n", crp));
+		DPRINTF("calling process for %p\n", crp);
 		return (*process)(arg, crp, hint);
 	} else {
 		struct cryptodesc *crd;
@@ -1015,8 +1014,7 @@ crypto_freereq(struct cryptop *crp)
 
 	if (crp == NULL)
 		return;
-	DPRINTF(("crypto_freereq[%u]: crp %p\n",
-		CRYPTO_SESID2LID(crp->crp_sid), crp));
+	DPRINTF("lid[%u]: crp %p\n", CRYPTO_SESID2LID(crp->crp_sid), crp);
 
 	/* sanity check */
 	if (crp->crp_flags & CRYPTO_F_ONRETQ) {
@@ -1076,8 +1074,7 @@ crypto_done(struct cryptop *crp)
 	if (crypto_timing)
 		crypto_tstat(_done, >crp_tstamp);
 #endif
-	DPRINTF(("crypto_done[%u]: crp %p\n",
-		CRYPTO_SESID2LID(crp->crp_sid), crp));
+	DPRINTF("lid[%u]: crp %p\n", CRYPTO_SESID2LID(crp->crp_sid), crp);
 
 	/*
 	 * Normal case; queue the callback for the thread.
@@ -1123,20 +1120,20 @@ crypto_done(struct cryptop *crp)
 			 * the same context, we can skip enqueueing crp_ret_q
 			 * and cv_signal(_cv).
 			 */
-			DPRINTF(("crypto_done[%u]: crp %p CRYPTO_F_USER\n",
-CRYPTO_SESID2LID(crp->crp_sid), crp));
+			DPRINTF("lid[%u]: crp %p CRYPTO_F_USER\n",
+CRYPTO_SESID2LID(crp->crp_sid), crp);
 		} else
 #endif
 		{
 			wasempty = TAILQ_EMPTY(_ret_q);
-			DPRINTF(("crypto_done[%u]: queueing %p\n",
-CRYPTO_SESID2LID(crp->crp_sid), crp));
+			DPRINTF("lid[%u]: queueing %p\n",
+CRYPTO_SESID2LID(crp->crp_sid), crp);
 			crp->crp_flags |= CRYPTO_F_ONRETQ;
 			TAILQ_INSERT_TAIL(_ret_q, crp, crp_next);
 			if (wasempty) {
-DPRINTF(("crypto_done[%u]: waking cryptoret, "
+DPRINTF("lid[%u]: waking cryptoret, "
 	"crp %p hit empty queue\n.",
-	CRYPTO_SESID2LID(crp->crp_sid), crp));
+	CRYPTO_SESID2LID(crp->crp_sid), crp);
 cv_signal(_cv);
 			}
 		}

Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.89 src/sys/opencrypto/cryptodev.c:1.90
--- src/sys/opencrypto/cryptodev.c:1.89	Mon Apr 24 03:29:37 2017
+++ src/sys/opencrypto/cryptodev.c	Wed May 17 06:33:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.89 2017/04/24 03:29:37 knakahara Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.90 2017/05/17 06:33:04 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $	*/
 /*	$OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $	*/
 
@@ -64,7 +64,7 @@

CVS commit: src/tests/net

2017-05-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed May 17 06:30:16 UTC 2017

Modified Files:
src/tests/net: net_common.sh
src/tests/net/ipsec: t_ipsec_misc.sh

Log Message:
Add test cases of TCP communications with IPsec enabled

The test cases transfer data over TCP by using nc with IPsec just enabled
(no SA/SP is configured) and confirm the commit "Fix diagnostic assertion
failure in ipsec_init_policy" really fixes the issue.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/net/net_common.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/net/ipsec/t_ipsec_misc.sh

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

Modified files:

Index: src/tests/net/net_common.sh
diff -u src/tests/net/net_common.sh:1.15 src/tests/net/net_common.sh:1.16
--- src/tests/net/net_common.sh:1.15	Fri Apr 14 02:56:48 2017
+++ src/tests/net/net_common.sh	Wed May 17 06:30:15 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: net_common.sh,v 1.15 2017/04/14 02:56:48 ozaki-r Exp $
+#	$NetBSD: net_common.sh,v 1.16 2017/05/17 06:30:15 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -140,13 +140,20 @@ start_nc_server()
 	local sock=$1
 	local port=$2
 	local outfile=$3
+	local proto=${4:-ipv4}
 	local backup=$RUMP_SERVER
-	local pid=
+	local pid= opts=
 
 	export RUMP_SERVER=$sock
 
+	if [ $proto = ipv4 ]; then
+		opts="-l -4"
+	else
+		opts="-l -6"
+	fi
+
 	env LD_PRELOAD=/usr/lib/librumphijack.so \
-	nc -l $port > $outfile &
+	nc $opts $port > $outfile &
 	pid=$!
 	echo $pid > $NC_PID
 

Index: src/tests/net/ipsec/t_ipsec_misc.sh
diff -u src/tests/net/ipsec/t_ipsec_misc.sh:1.1 src/tests/net/ipsec/t_ipsec_misc.sh:1.2
--- src/tests/net/ipsec/t_ipsec_misc.sh:1.1	Mon May 15 09:58:22 2017
+++ src/tests/net/ipsec/t_ipsec_misc.sh	Wed May 17 06:30:15 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_misc.sh,v 1.1 2017/05/15 09:58:22 ozaki-r Exp $
+#	$NetBSD: t_ipsec_misc.sh,v 1.2 2017/05/17 06:30:15 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -298,6 +298,117 @@ add_test_lifetime()
 	atf_add_test_case ${name}
 }
 
+prepare_file()
+{
+	local file=$1
+	local data="0123456789"
+
+	touch $file
+	for i in `seq 1 512`
+	do
+		echo $data >> $file
+	done
+}
+
+test_tcp()
+{
+	local proto=$1
+	local ip_local=$2
+	local ip_peer=$3
+	local port=1234
+	local file_send=./file.send
+	local file_recv=./file.recv
+	local opts=
+
+	if [ $proto = ipv4 ]; then
+		opts="-N -w 3 -4"
+	else
+		opts="-N -w 3 -6"
+	fi
+
+	# Start nc server
+	start_nc_server $SOCK_PEER $port $file_recv $proto
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	# Send a file to the server
+	prepare_file $file_send
+	atf_check -s exit:0 $HIJACKING nc $opts $ip_peer $port < $file_send
+
+	# Check if the file is transferred correctly
+	atf_check -s exit:0 diff -q $file_send $file_recv
+
+	stop_nc_server
+	rm -f $file_send $file_recv
+}
+
+test_tcp_ipv4()
+{
+	local ip_local=10.0.0.1
+	local ip_peer=10.0.0.2
+
+	rump_server_crypto_start $SOCK_LOCAL netipsec
+	rump_server_crypto_start $SOCK_PEER netipsec
+	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
+	rump_server_add_iface $SOCK_PEER shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip_local/24
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	export RUMP_SERVER=$SOCK_PEER
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip_peer/24
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	test_tcp ipv4 $ip_local $ip_peer
+}
+
+test_tcp_ipv6()
+{
+	local ip_local=fd00::1
+	local ip_peer=fd00::2
+
+	rump_server_crypto_start $SOCK_LOCAL netinet6 netipsec
+	rump_server_crypto_start $SOCK_PEER netinet6 netipsec
+	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
+	rump_server_add_iface $SOCK_PEER shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_local
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	export RUMP_SERVER=$SOCK_PEER
+	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_peer
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	test_tcp ipv6 $ip_local $ip_peer
+}
+
+add_test_tcp()
+{
+	local ipproto=$1
+	local name= desc=
+
+	name="ipsec_tcp_${ipproto}"
+	desc="Tests of TCP with IPsec enabled ($ipproto)"
+
+	atf_test_case ${name} cleanup
+	eval "\
+	${name}_head() {		\
+	atf_set \"descr\" \"$desc\";\
+	atf_set \"require.progs\" \"rump_server\" \"setkey\";	\
+	};\
+	${name}_body() {		\
+	test_tcp_${ipproto};	\
+	rump_server_destroy_ifaces;\
+	};\
+	${name}_cleanup() {		\
+	$DEBUG && dump;		\
+	cleanup;		\
+	}\
+	"
+	atf_add_test_case ${name}
+}
+
 atf_init_test_cases()
 {
 	local algo=
@@ -310,4 +421,7 @@ atf_init_test_cases()
 		add_test_lifetime ipv4 ah $algo
 		add_test_lifetime ipv6 ah $algo
 	done
+
+	add_test_tcp ipv4
+	add_test_tcp ipv6
 }