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

2018-01-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan  2 18:54:26 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Stop sharing the double-fault stack. It is embedded in .data, and we won't
want that in the future. This has always been wrong anyway, even if it is
unlikely that two CPUs will double fault at the same time.


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 src/sys/arch/amd64/amd64/machdep.c

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

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.280 src/sys/arch/amd64/amd64/machdep.c:1.281
--- src/sys/arch/amd64/amd64/machdep.c:1.280	Sun Dec 31 08:29:38 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Jan  2 18:54:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.280 2017/12/31 08:29:38 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.281 2018/01/02 18:54:26 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.280 2017/12/31 08:29:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.281 2018/01/02 18:54:26 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -290,8 +290,6 @@ struct pool x86_dbregspl;
 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
 int mem_cluster_cnt;
 
-char x86_64_doubleflt_stack[4096];
-
 int cpu_dump(void);
 int cpu_dumpsize(void);
 u_long cpu_dump_mempagecnt(void);
@@ -511,11 +509,13 @@ cpu_init_tss(struct cpu_info *ci)
 	/* tss->tss_ist[0] is filled by cpu_intr_init */
 
 	/* double fault */
-	tss->tss_ist[1] = (uint64_t)x86_64_doubleflt_stack + PAGE_SIZE - 16;
+	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
+	tss->tss_ist[1] = p + PAGE_SIZE - 16;
 
 	/* NMI */
 	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
 	tss->tss_ist[2] = p + PAGE_SIZE - 16;
+
 	ci->ci_tss_sel = tss_alloc(tss);
 }
 



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

2018-01-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jan  2 18:41:14 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S

Log Message:
Use decimal numbering - hex is just misleading -, use ZTRAP_NJ for NMIs,
and declare intrspurious independently.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/amd64/amd64/amd64_trap.S

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

Modified files:

Index: src/sys/arch/amd64/amd64/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.13 src/sys/arch/amd64/amd64/amd64_trap.S:1.14
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.13	Sun Nov 26 14:54:43 2017
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Tue Jan  2 18:41:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.13 2017/11/26 14:54:43 maxv Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.14 2018/01/02 18:41:14 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.13 2017/11/26 14:54:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.14 2018/01/02 18:41:14 maxv Exp $");
 #endif
 
 /*
@@ -118,8 +118,7 @@ IDTVEC(trap02)
 #if defined(XEN)
 	ZTRAP(T_NMI)
 #else
-	pushq	$0
-	pushq	$T_NMI
+	ZTRAP_NJ(T_NMI)
 	subq	$TF_REGSIZE,%rsp
 	INTR_SAVE_GPRS
 	cld
@@ -230,9 +229,9 @@ IDTVEC(trap09)
 	ZTRAP(T_FPOPFLT)
 IDTVEC_END(trap09)
 
-IDTVEC(trap0a)
+IDTVEC(trap10)
 	TRAP(T_TSSFLT)
-IDTVEC_END(trap0a)
+IDTVEC_END(trap10)
 
 #ifdef XEN
 /*
@@ -243,37 +242,35 @@ IDTVEC_END(trap0a)
 #define check_swapgs alltraps
 #endif
 
-IDTVEC(trap0b)		/* #NP() Segment not present */
+IDTVEC(trap11)		/* #NP() Segment not present */
 	TRAP_NJ(T_SEGNPFLT)
 	jmp	check_swapgs
-IDTVEC_END(trap0b)
+IDTVEC_END(trap11)
 
-IDTVEC(trap0c)		/* #SS() Stack exception */
+IDTVEC(trap12)		/* #SS() Stack exception */
 	TRAP_NJ(T_STKFLT)
 	jmp	check_swapgs
-IDTVEC_END(trap0c)
+IDTVEC_END(trap12)
 
-IDTVEC(trap0d)		/* #GP() General protection */
+IDTVEC(trap13)		/* #GP() General protection */
 	TRAP_NJ(T_PROTFLT)
 	jmp	check_swapgs
-IDTVEC_END(trap0d)
+IDTVEC_END(trap13)
 
-IDTVEC(trap0e)
+IDTVEC(trap14)
 	TRAP(T_PAGEFLT)
-IDTVEC_END(trap0e)
+IDTVEC_END(trap14)
 
-IDTVEC(intrspurious)
-IDTVEC(trap0f)
+IDTVEC(trap15)
 	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
 	movl	CPUVAR(ILEVEL),%ebx
 #endif
 	jmp	.Lalltraps_checkusr
-IDTVEC_END(trap0f)
-IDTVEC_END(intrspurious)
+IDTVEC_END(trap15)
 
-IDTVEC(trap10)
+IDTVEC(trap16)
 	ZTRAP_NJ(T_ARITHTRAP)
 .Ldo_fputrap:
 	INTRENTRY
@@ -283,47 +280,47 @@ IDTVEC(trap10)
 	movq	%rsp,%rdi
 	call	_C_LABEL(fputrap)
 	jmp	.Lalltraps_checkusr
-IDTVEC_END(trap10)
+IDTVEC_END(trap16)
 
-IDTVEC(trap11)
+IDTVEC(trap17)
 	TRAP(T_ALIGNFLT)
-IDTVEC_END(trap11)
+IDTVEC_END(trap17)
 
-IDTVEC(trap12)
+IDTVEC(trap18)
 	ZTRAP(T_MCA)
-IDTVEC_END(trap12)
+IDTVEC_END(trap18)
 
-IDTVEC(trap13)
+IDTVEC(trap19)
 	ZTRAP_NJ(T_XMM)
 	jmp	.Ldo_fputrap
-IDTVEC_END(trap13)
+IDTVEC_END(trap19)
 
-IDTVEC(trap14)
-IDTVEC(trap15)
-IDTVEC(trap16)
-IDTVEC(trap17)
-IDTVEC(trap18)
-IDTVEC(trap19)
-IDTVEC(trap1a)
-IDTVEC(trap1b)
-IDTVEC(trap1c)
-IDTVEC(trap1d)
-IDTVEC(trap1e)
-IDTVEC(trap1f)
+IDTVEC(trap20)
+IDTVEC(trap21)
+IDTVEC(trap22)
+IDTVEC(trap23)
+IDTVEC(trap24)
+IDTVEC(trap25)
+IDTVEC(trap26)
+IDTVEC(trap27)
+IDTVEC(trap28)
+IDTVEC(trap29)
+IDTVEC(trap30)
+IDTVEC(trap31)
 	/* 20 - 31 reserved for future exp */
 	ZTRAP(T_RESERVED)
-IDTVEC_END(trap1f)
-IDTVEC_END(trap1e)
-IDTVEC_END(trap1d)
-IDTVEC_END(trap1c)
-IDTVEC_END(trap1b)
-IDTVEC_END(trap1a)
-IDTVEC_END(trap19)
-IDTVEC_END(trap18)
-IDTVEC_END(trap17)
-IDTVEC_END(trap16)
-IDTVEC_END(trap15)
-IDTVEC_END(trap14)
+IDTVEC_END(trap20)
+IDTVEC_END(trap21)
+IDTVEC_END(trap22)
+IDTVEC_END(trap23)
+IDTVEC_END(trap24)
+IDTVEC_END(trap25)
+IDTVEC_END(trap26)
+IDTVEC_END(trap27)
+IDTVEC_END(trap28)
+IDTVEC_END(trap29)
+IDTVEC_END(trap30)
+IDTVEC_END(trap31)
 
 IDTVEC(exceptions)
 	.quad	_C_LABEL(Xtrap00), _C_LABEL(Xtrap01)
@@ -331,19 +328,28 @@ IDTVEC(exceptions)
 	.quad	_C_LABEL(Xtrap04), _C_LABEL(Xtrap05)
 	.quad	_C_LABEL(Xtrap06), _C_LABEL(Xtrap07)
 	.quad	_C_LABEL(Xtrap08), _C_LABEL(Xtrap09)
-	.quad	_C_LABEL(Xtrap0a), _C_LABEL(Xtrap0b)
-	.quad	_C_LABEL(Xtrap0c), _C_LABEL(Xtrap0d)
-	.quad	_C_LABEL(Xtrap0e), _C_LABEL(Xtrap0f)
 	.quad	_C_LABEL(Xtrap10), _C_LABEL(Xtrap11)
 	.quad	_C_LABEL(Xtrap12), _C_LABEL(Xtrap13)
 	.quad	_C_LABEL(Xtrap14), _C_LABEL(Xtrap15)
 	.quad	_C_LABEL(Xtrap16), _C_LABEL(Xtrap17)
 	.quad	_C_LABEL(Xtrap18), _C_LABEL(Xtrap19)
-	.quad	_C_LABEL(Xtrap1a), _C_LABEL(Xtrap1b)
-	.quad	_C_LABEL(Xtrap1c), _C_LABEL(Xtrap1d)
-	.quad	_C_LABEL(Xtrap1e), _C_LABEL(Xtrap1f)
+	.quad	_C_LABEL(Xtrap20), _C_LABEL(Xtrap21)
+	.quad	_C_LABEL(Xtrap22), _C_LABEL(Xtrap23)
+	.quad	_C_LABEL(Xtrap24), _C_LABEL(Xtrap25)
+	.quad	_C_LABEL(Xtrap26), _C_LABEL(Xtrap27)
+	.quad	_C_LABEL(Xtrap28), _C_LABEL(Xtrap29)
+	.quad	_C_LABEL(Xtrap30), _C_LABEL(Xtrap31)
 IDTVEC_END(exceptions)
 

CVS commit: [netbsd-8] src/doc

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 11:21:28 UTC 2018

Modified Files:
src/doc [netbsd-8]: CHANGES-8.0

Log Message:
tickets 456 457 458 460 461 462 463


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.97 -r1.1.2.98 src/doc/CHANGES-8.0

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

Modified files:

Index: src/doc/CHANGES-8.0
diff -u src/doc/CHANGES-8.0:1.1.2.97 src/doc/CHANGES-8.0:1.1.2.98
--- src/doc/CHANGES-8.0:1.1.2.97	Mon Jan  1 19:11:07 2018
+++ src/doc/CHANGES-8.0	Tue Jan  2 11:21:28 2018
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-8.0,v 1.1.2.97 2018/01/01 19:11:07 snj Exp $
+# $NetBSD: CHANGES-8.0,v 1.1.2.98 2018/01/02 11:21:28 snj Exp $
 
 A complete list of changes from the initial NetBSD 8.0 branch on 2017-06-04
 until the 8.0 release:
@@ -8685,3 +8685,111 @@ sys/arch/x86/x86/vm_machdep.c			1.30
 	Xen: Prevent userland from having access to the CPU ports.
 	[maxv, ticket #477]
 
+sys/arch/arm/sunxi/sunxi_emac.c			1.9
+sys/dev/ic/dwc_gmac.c1.43-1.44
+sys/dev/pci/if_iwm.c1.75
+sys/dev/pci/if_wm.c1.543
+sys/dev/pci/ixgbe/ixgbe.c			1.112
+sys/dev/pci/ixgbe/ixv.c1.74
+sys/kern/sys_socket.c1.75
+sys/net/agr/if_agr.c1.43
+sys/net/bpf.c	1.219
+sys/net/if.c	1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416
+sys/net/if.h	1.242-1.247, 1.250, 1.252-1.257
+sys/net/if_bridge.c1.140 via patch, 1.142-1.146
+sys/net/if_etherip.c1.40
+sys/net/if_ethersubr.c1.243, 1.246
+sys/net/if_faith.c1.57
+sys/net/if_gif.c1.132
+sys/net/if_l2tp.c1.15, 1.17
+sys/net/if_loop.c1.98-1.101
+sys/net/if_media.c1.35
+sys/net/if_pppoe.c1.131-1.132
+sys/net/if_spppsubr.c1.176-1.177
+sys/net/if_tun.c1.142
+sys/net/if_vlan.c1.107, 1.109, 1.114-1.121
+sys/net/npf/npf_ifaddr.c			1.3
+sys/net/npf/npf_os.c1.8-1.9
+sys/net/rtsock.c1.230
+sys/netcan/if_canloop.c1.3-1.5
+sys/netinet/if_arp.c1.255
+sys/netinet/igmp.c1.65
+sys/netinet/in.c1.210-1.211
+sys/netinet/in_pcb.c1.180
+sys/netinet/ip_carp.c1.92, 1.94
+sys/netinet/ip_flow.c1.81
+sys/netinet/ip_input.c1.362
+sys/netinet/ip_mroute.c1.147
+sys/netinet/ip_output.c1.283, 1.285, 1.287
+sys/netinet6/frag6.c1.61
+sys/netinet6/in6.c1.251, 1.255
+sys/netinet6/in6_pcb.c1.162
+sys/netinet6/ip6_flow.c1.35
+sys/netinet6/ip6_input.c			1.183
+sys/netinet6/ip6_output.c			1.196
+sys/netinet6/mld6.c1.90
+sys/netinet6/nd6.c1.239-1.240
+sys/netinet6/nd6_nbr.c1.139
+sys/netinet6/nd6_rtr.c1.136
+sys/netipsec/ipsec_output.c			1.65
+sys/rump/net/lib/libnetinet/netinet_component.c	1.9-1.10
+
+	- Protect ifnet#if_flags with IFNET_LOCK surely
+	- Protect ifnet#if_link_queue
+	- Unify IFEF_*_MPSAFE flags into IFEF_MPSAFE
+	- Don't hold KERNEL_LOCK on if_ioctl if IFEF_MPSAFE
+	- Enable IFEF_MPSAFE only if NET_MPSAFE
+	[ozaki-r, ticket #456]
+
+sys/net/rtsock.c1.233-1.234, 1.236
+
+	- Protect ifp returned from route_output_get_ifa surely
+	- Fix a bug that tries to psref_acquire ifa with a psref used before
+	- Fix compile error (may be used uninitialized)
+	[ozaki-r, ticket #457]
+
+sys/kern/subr_psref.c1.8-1.9
+sys/sys/psref.h	1.3
+
+	- Fix psref(9) part of PR kern/52515.
+	- Improve debugging functions.
+	[ozaki-r, ticket #458]
+
+sys/opencrypto/crypto.c1.101
+
+	fix opencrypto(9) part of PR kern/52515
+	percpu data use pointers to TAILQ instead of TAILQ itself.
+	[knakahara, ticket #460]
+
+sys/netinet/in_l2tp.c1.9
+sys/netinet6/in6_l2tp.c1.12
+
+	fix mbuf leaks.
+	[knakahara, ticket #461]
+
+sys/net/if_gif.c1.133, 1.134, 1.137
+sys/net/if_gif.h1.28-1.29
+sys/netinet/in_gif.c1.90-1.91
+sys/netinet/in_gif.h1.18
+sys/netinet6/in6_gif.c1.88-1.89
+sys/netinet6/in6_gif.h1.17
+
+	- preserve gif(4) configs by psref(9) like vlan(4) and l2tp(4).
+	- update gif(4) locking notes.
+	- IFF_RUNNING checking in Rx and Tx processing is unnecessary now.
+	- remove duplicated null ckeck
+	[knakahara, ticket #462]
+
+sys/netinet/in.c1.212
+sys/netinet/ip_output.c1.288
+sys/netinet6/in6.c1.256
+sys/netinet6/in6_pcb.c1.163
+sys/sys/lwp.h	1.176
+
+	- Add missing curlwp_bindx
+	- Check LP_BOUND is surely set in curlwp_bindx
+	  This may find an extra call of curlwp_bindx.
+	- Fix usage of curlwp_bind in ip_output
+	- Fix wrong usage of psref_held
+	[ozaki-r, ticket #463]
+



CVS commit: [netbsd-8] src/sys

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:56:58 UTC 2018

Modified Files:
src/sys/netinet [netbsd-8]: in.c ip_output.c
src/sys/netinet6 [netbsd-8]: in6.c in6_pcb.c
src/sys/sys [netbsd-8]: lwp.h

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #463):
sys/netinet/in.c: revision 1.212
sys/netinet/ip_output.c: revision 1.288
sys/netinet6/in6.c: revision 1.256
sys/netinet6/in6_pcb.c: revision 1.163
sys/sys/lwp.h: revision 1.176
Add missing curlwp_bindx
--
Add missing curlwp_bindx
--
Check LP_BOUND is surely set in curlwp_bindx
This may find an extra call of curlwp_bindx.
--
Fix usage of curlwp_bind in ip_output
curlwp_bindx must be called in LIFO order, i.e., we can't call curlwp_bind
and curlwp_bindx like this:
  bound1 = curlwp_bind();
  bound2 = curlwp_bind();
  curlwp_bindx(bound1);
  curlwp_bindx(bound2);
ip_outout did so if NET_MPSAFE. Fix it.
--
Fix wrong usage of psref_held
We can't use it for checking if a caller does NOT hold a given target.
If you want to do it you should have psref_not_held or something.


To generate a diff of this commit:
cvs rdiff -u -r1.203.2.4 -r1.203.2.5 src/sys/netinet/in.c
cvs rdiff -u -r1.279.2.3 -r1.279.2.4 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.245.2.4 -r1.245.2.5 src/sys/netinet6/in6.c
cvs rdiff -u -r1.161.4.1 -r1.161.4.2 src/sys/netinet6/in6_pcb.c
cvs rdiff -u -r1.174 -r1.174.4.1 src/sys/sys/lwp.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/netinet/in.c
diff -u src/sys/netinet/in.c:1.203.2.4 src/sys/netinet/in.c:1.203.2.5
--- src/sys/netinet/in.c:1.203.2.4	Tue Jan  2 10:20:34 2018
+++ src/sys/netinet/in.c	Tue Jan  2 10:56:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.203.2.4 2018/01/02 10:20:34 snj Exp $	*/
+/*	$NetBSD: in.c,v 1.203.2.5 2018/01/02 10:56:58 snj Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.4 2018/01/02 10:20:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.5 2018/01/02 10:56:58 snj Exp $");
 
 #include "arp.h"
 
@@ -845,7 +845,7 @@ in_purgeaddr(struct ifaddr *ifa)
 	struct in_ifaddr *ia = (void *) ifa;
 	struct ifnet *ifp = ifa->ifa_ifp;
 
-	KASSERT(!ifa_held(ifa));
+	/* KASSERT(!ifa_held(ifa)); XXX need ifa_not_held (psref_not_held) */
 
 	ifa->ifa_flags |= IFA_DESTROYING;
 	in_scrubaddr(ia);

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.279.2.3 src/sys/netinet/ip_output.c:1.279.2.4
--- src/sys/netinet/ip_output.c:1.279.2.3	Tue Jan  2 10:20:34 2018
+++ src/sys/netinet/ip_output.c	Tue Jan  2 10:56:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.279.2.3 2018/01/02 10:20:34 snj Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.279.2.4 2018/01/02 10:56:58 snj Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.279.2.3 2018/01/02 10:20:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.279.2.4 2018/01/02 10:56:58 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -303,6 +303,10 @@ ip_output(struct mbuf *m0, struct mbuf *
 	!in_hosteq(dst->sin_addr, ip->ip_dst)))
 		rtcache_free(ro);
 
+	/* XXX must be before rtcache operations */
+	bound = curlwp_bind();
+	bind_need_restore = true;
+
 	if ((rt = rtcache_validate(ro)) == NULL &&
 	(rt = rtcache_update(ro, 1)) == NULL) {
 		dst = 
@@ -311,8 +315,6 @@ ip_output(struct mbuf *m0, struct mbuf *
 			goto bad;
 	}
 
-	bound = curlwp_bind();
-	bind_need_restore = true;
 	/*
 	 * If routing to interface only, short circuit routing lookup.
 	 */

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.245.2.4 src/sys/netinet6/in6.c:1.245.2.5
--- src/sys/netinet6/in6.c:1.245.2.4	Tue Jan  2 10:20:34 2018
+++ src/sys/netinet6/in6.c	Tue Jan  2 10:56:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.245.2.4 2018/01/02 10:20:34 snj Exp $	*/
+/*	$NetBSD: in6.c,v 1.245.2.5 2018/01/02 10:56:58 snj Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.4 2018/01/02 10:20:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.5 2018/01/02 10:56:58 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1384,7 +1384,7 @@ in6_purgeaddr(struct ifaddr *ifa)
 	struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa;
 	struct in6_multi_mship *imm;
 
-	KASSERT(!ifa_held(ifa));
+	/* KASSERT(!ifa_held(ifa)); XXX need ifa_not_held (psref_not_held) */
 	KASSERT(IFNET_LOCKED(ifp));
 
 	ifa->ifa_flags |= IFA_DESTROYING;

Index: src/sys/netinet6/in6_pcb.c
diff -u src/sys/netinet6/in6_pcb.c:1.161.4.1 src/sys/netinet6/in6_pcb.c:1.161.4.2
--- src/sys/netinet6/in6_pcb.c:1.161.4.1	Tue Jan  2 10:20:34 2018
+++ src/sys/netinet6/in6_pcb.c	Tue Jan  2 

CVS commit: [netbsd-8] src/sys

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:48:51 UTC 2018

Modified Files:
src/sys/net [netbsd-8]: if_gif.c if_gif.h
src/sys/netinet [netbsd-8]: in_gif.c in_gif.h
src/sys/netinet6 [netbsd-8]: in6_gif.c in6_gif.h

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #462):
sys/net/if_gif.c: revision 1.133, 1.134, 1.137
sys/net/if_gif.h: revision 1.28-1.29
sys/netinet/in_gif.c: revision 1.90-1.91
sys/netinet/in_gif.h: revision 1.18
sys/netinet6/in6_gif.c: revision 1.88-1.89
sys/netinet6/in6_gif.h: revision 1.17
preserve gif(4) configs by psref(9) like vlan(4) and l2tp(4).
After Tx side does not use softint, gif(4) can use psref(9) for config
preservation like vlan(4) and l2tp(4).
update locking notes later.
--
update gif(4) locking notes.
--
IFF_RUNNING checking in Rx and Tx processing is unnecessary now.
Because the configs of gif (members of gif_var) are protected by psref(9).
--
remove duplicated null ckeck


To generate a diff of this commit:
cvs rdiff -u -r1.126.2.6 -r1.126.2.7 src/sys/net/if_gif.c
cvs rdiff -u -r1.25.8.1 -r1.25.8.2 src/sys/net/if_gif.h
cvs rdiff -u -r1.87.8.2 -r1.87.8.3 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16.10.1 -r1.16.10.2 src/sys/netinet/in_gif.h
cvs rdiff -u -r1.85.6.2 -r1.85.6.3 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.15.10.1 -r1.15.10.2 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.126.2.6 src/sys/net/if_gif.c:1.126.2.7
--- src/sys/net/if_gif.c:1.126.2.6	Tue Jan  2 10:20:33 2018
+++ src/sys/net/if_gif.c	Tue Jan  2 10:48:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.126.2.6 2018/01/02 10:20:33 snj Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.126.2.7 2018/01/02 10:48:51 snj 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.126.2.6 2018/01/02 10:20:33 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.7 2018/01/02 10:48:51 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -57,6 +57,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -102,6 +105,9 @@ static struct {
 	kmutex_t lock;
 } gif_softcs __cacheline_aligned;
 
+pserialize_t gif_psz __read_mostly;
+struct psref_class *gv_psref_class __read_mostly;
+
 static void	gif_ro_init_pc(void *, void *, struct cpu_info *);
 static void	gif_ro_fini_pc(void *, void *, struct cpu_info *);
 
@@ -110,6 +116,7 @@ static int	gif_output(struct ifnet *, st
 			   const struct sockaddr *, const struct rtentry *);
 static void	gif_start(struct ifnet *);
 static int	gif_transmit(struct ifnet *, struct mbuf *);
+static int	gif_transmit_direct(struct gif_variant *, struct mbuf *);
 static int	gif_ioctl(struct ifnet *, u_long, void *);
 static int	gif_set_tunnel(struct ifnet *, struct sockaddr *,
 			   struct sockaddr *);
@@ -119,9 +126,10 @@ static int	gif_clone_create(struct if_cl
 static int	gif_clone_destroy(struct ifnet *);
 static int	gif_check_nesting(struct ifnet *, struct mbuf *);
 
-static int	gif_encap_attach(struct gif_softc *);
-static int	gif_encap_detach(struct gif_softc *);
-static void	gif_encap_pause(struct gif_softc *);
+static int	gif_encap_attach(struct gif_variant *);
+static int	gif_encap_detach(struct gif_variant *);
+
+static void	gif_update_variant(struct gif_softc *, struct gif_variant *);
 
 static struct if_clone gif_cloner =
 IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy);
@@ -216,6 +224,9 @@ gifinit(void)
 	LIST_INIT(_softcs.list);
 	if_clone_attach(_cloner);
 
+	gif_psz = pserialize_create();
+	gv_psref_class = psref_class_create("gifvar", IPL_SOFTNET);
+
 	gif_sysctl_setup();
 }
 
@@ -231,6 +242,9 @@ gifdetach(void)
 	}
 
 	if (error == 0) {
+		psref_class_destroy(gv_psref_class);
+		pserialize_destroy(gif_psz);
+
 		if_clone_detach(_cloner);
 		sysctl_teardown(_sysctl);
 	}
@@ -242,6 +256,7 @@ static int
 gif_clone_create(struct if_clone *ifc, int unit)
 {
 	struct gif_softc *sc;
+	struct gif_variant *var;
 	int rv;
 
 	sc = kmem_zalloc(sizeof(struct gif_softc), KM_SLEEP);
@@ -254,6 +269,12 @@ gif_clone_create(struct if_clone *ifc, i
 		return rv;
 	}
 
+	var = kmem_zalloc(sizeof(*var), KM_SLEEP);
+	var->gv_softc = sc;
+	psref_target_init(>gv_psref, gv_psref_class);
+
+	sc->gif_var = var;
+	mutex_init(>gif_lock, MUTEX_DEFAULT, IPL_NONE);
 	sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
 	percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
 
@@ -268,8 +289,6 @@ gifattach0(struct gif_softc *sc)
 {
 	int rv;
 
-	sc->encap_cookie4 = sc->encap_cookie6 = NULL;
-
 	sc->gif_if.if_addrlen = 0;
 	sc->gif_if.if_mtu= GIF_MTU;
 	sc->gif_if.if_flags  = IFF_POINTOPOINT | IFF_MULTICAST;
@@ 

CVS commit: [netbsd-8] src/sys

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:39:57 UTC 2018

Modified Files:
src/sys/netinet [netbsd-8]: in_l2tp.c
src/sys/netinet6 [netbsd-8]: in6_l2tp.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #461):
sys/netinet/in_l2tp.c: revision 1.9
sys/netinet6/in6_l2tp.c: revision 1.12
fix mbuf leaks. pointed out and suggested by kre@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2.8.2 -r1.2.8.3 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.5.8.2 -r1.5.8.3 src/sys/netinet6/in6_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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.2.8.2 src/sys/netinet/in_l2tp.c:1.2.8.3
--- src/sys/netinet/in_l2tp.c:1.2.8.2	Sun Dec 10 09:41:31 2017
+++ src/sys/netinet/in_l2tp.c	Tue Jan  2 10:39:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.2.8.2 2017/12/10 09:41:31 snj Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.2.8.3 2018/01/02 10:39:57 snj Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.2.8.2 2017/12/10 09:41:31 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.2.8.3 2018/01/02 10:39:57 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -368,13 +368,11 @@ in_l2tp_match(struct mbuf *m, int off, i
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/*
+	 * 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);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.5.8.2 src/sys/netinet6/in6_l2tp.c:1.5.8.3
--- src/sys/netinet6/in6_l2tp.c:1.5.8.2	Sun Dec 10 09:41:32 2017
+++ src/sys/netinet6/in6_l2tp.c	Tue Jan  2 10:39:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.5.8.2 2017/12/10 09:41:32 snj Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.5.8.3 2018/01/02 10:39:57 snj Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.5.8.2 2017/12/10 09:41:32 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.5.8.3 2018/01/02 10:39:57 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -360,13 +360,11 @@ in6_l2tp_match(struct mbuf *m, int off, 
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/*
+	 * 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);



CVS commit: [netbsd-8] src/sys/opencrypto

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:38:36 UTC 2018

Modified Files:
src/sys/opencrypto [netbsd-8]: crypto.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #460):
sys/opencrypto/crypto.c: revision 1.101
fix opencrypto(9) part of PR kern/52515
percpu data use pointers to TAILQ instead of TAILQ itself.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.3 -r1.78.2.4 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.78.2.3 src/sys/opencrypto/crypto.c:1.78.2.4
--- src/sys/opencrypto/crypto.c:1.78.2.3	Sat Aug  5 03:59:21 2017
+++ src/sys/opencrypto/crypto.c	Tue Jan  2 10:38:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.78.2.3 2017/08/05 03:59:21 snj Exp $ */
+/*	$NetBSD: crypto.c,v 1.78.2.4 2018/01/02 10:38:36 snj 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.78.2.3 2017/08/05 03:59:21 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.78.2.4 2018/01/02 10:38:36 snj Exp $");
 
 #include 
 #include 
@@ -105,8 +105,8 @@ static	void *crypto_ret_si;
 TAILQ_HEAD(crypto_crp_q, cryptop);
 TAILQ_HEAD(crypto_crp_kq, cryptkop);
 struct crypto_crp_qs {
-	struct crypto_crp_q crp_q;
-	struct crypto_crp_kq crp_kq;
+	struct crypto_crp_q *crp_q;
+	struct crypto_crp_kq *crp_kq;
 };
 static percpu_t *crypto_crp_qs_percpu;
 
@@ -136,7 +136,7 @@ crypto_crp_q_is_busy_pc(void *p, void *a
 	struct crypto_crp_qs *qs_pc = p;
 	bool *isempty = arg;
 
-	if (!TAILQ_EMPTY(_pc->crp_q) || !TAILQ_EMPTY(_pc->crp_kq))
+	if (!TAILQ_EMPTY(qs_pc->crp_q) || !TAILQ_EMPTY(qs_pc->crp_kq))
 		*isempty = true;
 }
 
@@ -145,8 +145,11 @@ crypto_crp_qs_init_pc(void *p, void *arg
 {
 	struct crypto_crp_qs *qs = p;
 
-	TAILQ_INIT(>crp_q);
-	TAILQ_INIT(>crp_kq);
+	qs->crp_q = kmem_alloc(sizeof(struct crypto_crp_q), KM_SLEEP);
+	qs->crp_kq = kmem_alloc(sizeof(struct crypto_crp_kq), KM_SLEEP);
+
+	TAILQ_INIT(qs->crp_q);
+	TAILQ_INIT(qs->crp_kq);
 }
 
 /*
@@ -1310,7 +1313,7 @@ crypto_dispatch(struct cryptop *crp)
 		 * don't care list order in batch job.
 		 */
 		crp_qs = crypto_get_crp_qs();
-		crp_q = _qs->crp_q;
+		crp_q = crp_qs->crp_q;
 		wasempty  = TAILQ_EMPTY(crp_q);
 		TAILQ_INSERT_TAIL(crp_q, crp, crp_next);
 		crypto_put_crp_qs();
@@ -1325,7 +1328,7 @@ crypto_dispatch(struct cryptop *crp)
 	}
 
 	crp_qs = crypto_get_crp_qs();
-	crp_q = _qs->crp_q;
+	crp_q = crp_qs->crp_q;
 	cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(crp->crp_sid));
 	/*
 	 * TODO:
@@ -1402,7 +1405,7 @@ crypto_kdispatch(struct cryptkop *krp)
 	cryptostats.cs_kops++;
 
 	crp_qs = crypto_get_crp_qs();
-	crp_kq = _qs->crp_kq;
+	crp_kq = crp_qs->crp_kq;
 	cap = crypto_checkdriver_lock(krp->krp_hid);
 	/*
 	 * TODO:
@@ -1908,8 +1911,8 @@ cryptointr(void *arg __unused)
 
 	cryptostats.cs_intrs++;
 	crp_qs = crypto_get_crp_qs();
-	crp_q = _qs->crp_q;
-	crp_kq = _qs->crp_kq;
+	crp_q = crp_qs->crp_q;
+	crp_kq = crp_qs->crp_kq;
 	do {
 		/*
 		 * Find the first element in the queue that can be



CVS commit: [netbsd-8] src/sys

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:36:13 UTC 2018

Modified Files:
src/sys/kern [netbsd-8]: subr_psref.c
src/sys/sys [netbsd-8]: psref.h

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #458):
sys/sys/psref.h: 1.3
sys/kern/subr_psref.c: 1.8-1.9
Fix psref(9) part of PR kern/52515. It is complete to fix the PR now.
implementated by ozaki-r@n.o, reviewed by riastradh@n.o, thanks.
--
Improve debugging functions
- Make psref_check_duplication check just if a given psref is on the list
  - It checked both psref and target
  - Suggested by riastradh@ some time ago
- Add psref_check_existence that checks a releasing psref is surely on the list


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.2.1 src/sys/kern/subr_psref.c
cvs rdiff -u -r1.2 -r1.2.8.1 src/sys/sys/psref.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/kern/subr_psref.c
diff -u src/sys/kern/subr_psref.c:1.7 src/sys/kern/subr_psref.c:1.7.2.1
--- src/sys/kern/subr_psref.c:1.7	Thu Jun  1 02:45:13 2017
+++ src/sys/kern/subr_psref.c	Tue Jan  2 10:36:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_psref.c,v 1.7 2017/06/01 02:45:13 chs Exp $	*/
+/*	$NetBSD: subr_psref.c,v 1.7.2.1 2018/01/02 10:36:12 snj Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.7 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.7.2.1 2018/01/02 10:36:12 snj Exp $");
 
 #include 
 #include 
@@ -78,7 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_psref.c
 #include 
 #include 
 
-LIST_HEAD(psref_head, psref);
+SLIST_HEAD(psref_head, psref);
 
 static bool	_psref_held(const struct psref_target *, struct psref_class *,
 		bool);
@@ -135,7 +135,7 @@ psref_cpu_drained_p(void *p, void *cooki
 	const struct psref_cpu *pcpu = p;
 	bool *retp = cookie;
 
-	if (!LIST_EMPTY(>pcpu_head))
+	if (!SLIST_EMPTY(>pcpu_head))
 		*retp = false;
 }
 
@@ -187,22 +187,40 @@ psref_target_init(struct psref_target *t
 }
 
 #ifdef DEBUG
+static bool
+psref_exist(struct psref_cpu *pcpu, struct psref *psref)
+{
+	struct psref *_psref;
+
+	SLIST_FOREACH(_psref, >pcpu_head, psref_entry) {
+		if (_psref == psref)
+			return true;
+	}
+	return false;
+}
+
 static void
 psref_check_duplication(struct psref_cpu *pcpu, struct psref *psref,
 const struct psref_target *target)
 {
 	bool found = false;
-	struct psref *_psref;
 
-	LIST_FOREACH(_psref, >pcpu_head, psref_entry) {
-		if (_psref == psref &&
-		_psref->psref_target == target) {
-			found = true;
-			break;
-		}
-	}
+	found = psref_exist(pcpu, psref);
 	if (found) {
-		panic("trying to acquire a target twice with the same psref: "
+		panic("The psref is already in the list (acquiring twice?): "
+		"psref=%p target=%p", psref, target);
+	}
+}
+
+static void
+psref_check_existence(struct psref_cpu *pcpu, struct psref *psref,
+const struct psref_target *target)
+{
+	bool found = false;
+
+	found = psref_exist(pcpu, psref);
+	if (!found) {
+		panic("The psref isn't in the list (releasing unused psref?): "
 		"psref=%p target=%p", psref, target);
 	}
 }
@@ -250,7 +268,7 @@ psref_acquire(struct psref *psref, const
 #endif
 
 	/* Record our reference.  */
-	LIST_INSERT_HEAD(>pcpu_head, psref, psref_entry);
+	SLIST_INSERT_HEAD(>pcpu_head, psref, psref_entry);
 	psref->psref_target = target;
 	psref->psref_lwp = curlwp;
 	psref->psref_cpu = curcpu();
@@ -273,6 +291,7 @@ void
 psref_release(struct psref *psref, const struct psref_target *target,
 struct psref_class *class)
 {
+	struct psref_cpu *pcpu;
 	int s;
 
 	KASSERTMSG((kpreempt_disabled() || cpu_softintr_p() ||
@@ -302,7 +321,13 @@ psref_release(struct psref *psref, const
 	 * (as does blocking interrupts).
 	 */
 	s = splraiseipl(class->prc_iplcookie);
-	LIST_REMOVE(psref, psref_entry);
+	pcpu = percpu_getref(class->prc_percpu);
+#ifdef DEBUG
+	/* Sanity-check if the target is surely acquired before.  */
+	psref_check_existence(pcpu, psref, target);
+#endif
+	SLIST_REMOVE(>pcpu_head, psref, psref, psref_entry);
+	percpu_putref(class->prc_percpu);
 	splx(s);
 
 	/* If someone is waiting for users to drain, notify 'em.  */
@@ -353,7 +378,7 @@ psref_copy(struct psref *pto, const stru
 	pcpu = percpu_getref(class->prc_percpu);
 
 	/* Record the new reference.  */
-	LIST_INSERT_HEAD(>pcpu_head, pto, psref_entry);
+	SLIST_INSERT_HEAD(>pcpu_head, pto, psref_entry);
 	pto->psref_target = pfrom->psref_target;
 	pto->psref_lwp = curlwp;
 	pto->psref_cpu = curcpu();
@@ -474,7 +499,7 @@ _psref_held(const struct psref_target *t
 	pcpu = percpu_getref(class->prc_percpu);
 
 	/* Search through all the references on this CPU.  */
-	LIST_FOREACH(psref, >pcpu_head, psref_entry) {
+	SLIST_FOREACH(psref, >pcpu_head, psref_entry) {
 		/* Sanity-check the reference's CPU.  */
 		

CVS commit: [netbsd-8] src/sys/net

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:30:10 UTC 2018

Modified Files:
src/sys/net [netbsd-8]: rtsock.c

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #457):
sys/net/rtsock.c: revision 1.233-1.234, 1.236
Protect ifp returned from route_output_get_ifa surely
An ifp returned from route_output_get_ifa was supposed to be protected
by a returned ifa; if the ifa belongs to ifp, holding the ifa prevents
the ifp from being freed. However route_output_get_ifa can return an ifp
to which a returned ifa doesn't belong. So we need to take a reference
to a returning ifp separately.
--
Fix a bug that tries to psref_acquire ifa with a psref used before
This fixes ATF tests that started to fail by a recent change to psref.
--
Fix compile error (may be used uninitialized)
Hmm, __noinline had hidden this error.


To generate a diff of this commit:
cvs rdiff -u -r1.213.2.4 -r1.213.2.5 src/sys/net/rtsock.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/rtsock.c
diff -u src/sys/net/rtsock.c:1.213.2.4 src/sys/net/rtsock.c:1.213.2.5
--- src/sys/net/rtsock.c:1.213.2.4	Tue Jan  2 10:20:33 2018
+++ src/sys/net/rtsock.c	Tue Jan  2 10:30:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -608,7 +608,7 @@ route_output_report(struct rtentry *rt, 
 
 static struct ifaddr *
 route_output_get_ifa(const struct rt_addrinfo info, const struct rtentry *rt,
-struct ifnet **ifp, struct psref *psref)
+struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
 {
 	struct ifaddr *ifa = NULL;
 
@@ -618,9 +618,11 @@ route_output_get_ifa(const struct rt_add
 		if (ifa == NULL)
 			goto next;
 		*ifp = ifa->ifa_ifp;
+		if_acquire(*ifp, psref_ifp);
 		if (info.rti_info[RTAX_IFA] == NULL &&
 		info.rti_info[RTAX_GATEWAY] == NULL)
 			goto next;
+		ifa_release(ifa, psref);
 		if (info.rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */
 			ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_GATEWAY],
@@ -648,8 +650,14 @@ next:
 		info.rti_info[RTAX_GATEWAY], psref);
 	}
 out:
-	if (ifa != NULL && *ifp == NULL)
+	if (ifa != NULL && *ifp == NULL) {
 		*ifp = ifa->ifa_ifp;
+		if_acquire(*ifp, psref_ifp);
+	}
+	if (ifa == NULL && *ifp != NULL) {
+		if_put(*ifp, psref_ifp);
+		*ifp = NULL;
+	}
 	return ifa;
 }
 
@@ -658,9 +666,9 @@ route_output_change(struct rtentry *rt, 
 struct rt_xmsghdr *rtm)
 {
 	int error = 0;
-	struct ifnet *ifp = NULL, *new_ifp;
+	struct ifnet *ifp = NULL, *new_ifp = NULL;
 	struct ifaddr *ifa = NULL, *new_ifa;
-	struct psref psref_ifa, psref_new_ifa, psref_ifp;
+	struct psref psref_ifa, psref_new_ifa, psref_ifp, psref_new_ifp;
 	bool newgw, ifp_changed = false;
 
 	/*
@@ -674,6 +682,7 @@ route_output_change(struct rtentry *rt, 
 	if (newgw || info->rti_info[RTAX_IFP] != NULL ||
 	info->rti_info[RTAX_IFA] != NULL) {
 		ifp = rt_getifp(info, _ifp);
+		/* info refers ifp so we need to keep a reference */
 		ifa = rt_getifa(info, _ifa);
 		if (ifa == NULL) {
 			error = ENETUNREACH;
@@ -698,7 +707,8 @@ route_output_change(struct rtentry *rt, 
 	 * flags may also be different; ifp may be specified
 	 * by ll sockaddr when protocol address is ambiguous
 	 */
-	new_ifa = route_output_get_ifa(*info, rt, _ifp, _new_ifa);
+	new_ifa = route_output_get_ifa(*info, rt, _ifp, _new_ifp,
+	_new_ifa);
 	if (new_ifa != NULL) {
 		ifa_release(ifa, _ifa);
 		ifa = new_ifa;
@@ -736,6 +746,7 @@ route_output_change(struct rtentry *rt, 
 	(void)ifp_changed; /* XXX gcc */
 #endif
 out:
+	if_put(new_ifp, _new_ifp);
 	if_put(ifp, _ifp);
 
 	return error;



CVS commit: [netbsd-8] src/sys

2018-01-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jan  2 10:20:34 UTC 2018

Modified Files:
src/sys/arch/arm/sunxi [netbsd-8]: sunxi_emac.c
src/sys/dev/ic [netbsd-8]: dwc_gmac.c
src/sys/dev/pci [netbsd-8]: if_iwm.c if_wm.c
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixv.c
src/sys/kern [netbsd-8]: sys_socket.c
src/sys/net [netbsd-8]: bpf.c if.c if.h if_bridge.c if_etherip.c
if_ethersubr.c if_faith.c if_gif.c if_l2tp.c if_loop.c if_media.c
if_pppoe.c if_spppsubr.c if_tun.c if_vlan.c rtsock.c
src/sys/net/agr [netbsd-8]: if_agr.c
src/sys/net/npf [netbsd-8]: npf_ifaddr.c npf_os.c
src/sys/netcan [netbsd-8]: if_canloop.c
src/sys/netinet [netbsd-8]: if_arp.c igmp.c in.c in_pcb.c ip_carp.c
ip_flow.c ip_input.c ip_mroute.c ip_output.c
src/sys/netinet6 [netbsd-8]: frag6.c in6.c in6_pcb.c ip6_flow.c
ip6_input.c ip6_output.c mld6.c nd6.c nd6_nbr.c nd6_rtr.c
src/sys/netipsec [netbsd-8]: ipsec_output.c
src/sys/rump/net/lib/libnetinet [netbsd-8]: netinet_component.c

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #456):
sys/arch/arm/sunxi/sunxi_emac.c: 1.9
sys/dev/ic/dwc_gmac.c: 1.43-1.44
sys/dev/pci/if_iwm.c: 1.75
sys/dev/pci/if_wm.c: 1.543
sys/dev/pci/ixgbe/ixgbe.c: 1.112
sys/dev/pci/ixgbe/ixv.c: 1.74
sys/kern/sys_socket.c: 1.75
sys/net/agr/if_agr.c: 1.43
sys/net/bpf.c: 1.219
sys/net/if.c: 1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416
sys/net/if.h: 1.242-1.247, 1.250, 1.252-1.257
sys/net/if_bridge.c: 1.140 via patch, 1.142-1.146
sys/net/if_etherip.c: 1.40
sys/net/if_ethersubr.c: 1.243, 1.246
sys/net/if_faith.c: 1.57
sys/net/if_gif.c: 1.132
sys/net/if_l2tp.c: 1.15, 1.17
sys/net/if_loop.c: 1.98-1.101
sys/net/if_media.c: 1.35
sys/net/if_pppoe.c: 1.131-1.132
sys/net/if_spppsubr.c: 1.176-1.177
sys/net/if_tun.c: 1.142
sys/net/if_vlan.c: 1.107, 1.109, 1.114-1.121
sys/net/npf/npf_ifaddr.c: 1.3
sys/net/npf/npf_os.c: 1.8-1.9
sys/net/rtsock.c: 1.230
sys/netcan/if_canloop.c: 1.3-1.5
sys/netinet/if_arp.c: 1.255
sys/netinet/igmp.c: 1.65
sys/netinet/in.c: 1.210-1.211
sys/netinet/in_pcb.c: 1.180
sys/netinet/ip_carp.c: 1.92, 1.94
sys/netinet/ip_flow.c: 1.81
sys/netinet/ip_input.c: 1.362
sys/netinet/ip_mroute.c: 1.147
sys/netinet/ip_output.c: 1.283, 1.285, 1.287
sys/netinet6/frag6.c: 1.61
sys/netinet6/in6.c: 1.251, 1.255
sys/netinet6/in6_pcb.c: 1.162
sys/netinet6/ip6_flow.c: 1.35
sys/netinet6/ip6_input.c: 1.183
sys/netinet6/ip6_output.c: 1.196
sys/netinet6/mld6.c: 1.90
sys/netinet6/nd6.c: 1.239-1.240
sys/netinet6/nd6_nbr.c: 1.139
sys/netinet6/nd6_rtr.c: 1.136
sys/netipsec/ipsec_output.c: 1.65
sys/rump/net/lib/libnetinet/netinet_component.c: 1.9-1.10
kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
Unify IFEF_*_MPSAFE into IFEF_MPSAFE
There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.
Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).
Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.
Proposed on tech-kern@ and tech-net@
Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.
No functional change
Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE
If IFEF_MPSAFE is set, hold the lock and otherwise don't hold.
This change requires additions of KERNEL_LOCK to subsequence functions from
if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe
components.
Proposed on tech-kern@ and tech-net@
Ensure to hold if_ioctl_lock when calling if_flags_set
Fix locking against myself on ifpromisc
vlan_unconfig_locked could be called with holding if_ioctl_lock.
Ensure to not turn on IFF_RUNNING of an interface until its initialization 
completes
And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful