Tue Jan 24 07:09:25 2017 UTC ()
Tweak softnet_lock and NET_MPSAFE

- Don't hold softnet_lock in some functions if NET_MPSAFE
- Add softnet_lock to sysctl_net_inet_icmp_redirtimeout
- Add softnet_lock to expire_upcalls of ip_mroute.c
- Restore softnet_lock for in{,6}_pcbpurgeif{,0} if NET_MPSAFE
- Mark some softnet_lock for future work


(ozaki-r)
diff -r1.239 -r1.240 src/sys/netinet/if_arp.c
diff -r1.63 -r1.64 src/sys/netinet/igmp.c
diff -r1.154 -r1.155 src/sys/netinet/ip_icmp.c
diff -r1.347 -r1.348 src/sys/netinet/ip_input.c
diff -r1.145 -r1.146 src/sys/netinet/ip_mroute.c
diff -r1.161 -r1.162 src/sys/netinet/raw_ip.c
diff -r1.213 -r1.214 src/sys/netinet/tcp_usrreq.c
diff -r1.229 -r1.230 src/sys/netinet/udp_usrreq.c
diff -r1.10 -r1.11 src/sys/netinet6/dccp6_usrreq.c
diff -r1.59 -r1.60 src/sys/netinet6/frag6.c
diff -r1.109 -r1.110 src/sys/netinet6/in6_ifattach.c
diff -r1.115 -r1.116 src/sys/netinet6/ip6_mroute.c
diff -r1.79 -r1.80 src/sys/netinet6/mld6.c
diff -r1.154 -r1.155 src/sys/netinet6/raw_ip6.c
diff -r1.126 -r1.127 src/sys/netinet6/udp6_usrreq.c

cvs diff -r1.239 -r1.240 src/sys/netinet/if_arp.c (expand / switch to context diff)
--- src/sys/netinet/if_arp.c 2017/01/21 11:07:46 1.239
+++ src/sys/netinet/if_arp.c 2017/01/24 07:09:24 1.240
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.239 2017/01/21 11:07:46 maxv Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.240 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.239 2017/01/21 11:07:46 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.240 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1676,8 +1676,10 @@
 	struct dadq *dp;
 	char ipbuf[INET_ADDRSTRLEN];
 
+#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
+#endif
 	mutex_enter(&arp_dad_lock);
 
 	/* Sanity check */
@@ -1767,8 +1769,10 @@
 
 done:
 	mutex_exit(&arp_dad_lock);
+#ifndef NET_MPSAFE
 	KERNEL_UNLOCK_ONE(NULL);
 	mutex_exit(softnet_lock);
+#endif
 }
 
 static void

cvs diff -r1.63 -r1.64 src/sys/netinet/igmp.c (expand / switch to context diff)
--- src/sys/netinet/igmp.c 2017/01/11 13:08:29 1.63
+++ src/sys/netinet/igmp.c 2017/01/24 07:09:24 1.64
@@ -1,4 +1,4 @@
-/*	$NetBSD: igmp.c,v 1.63 2017/01/11 13:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,10 +40,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.63 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -541,8 +542,10 @@
 		return;
 	}
 
+#ifndef NET_MPSAFE
 	/* XXX: Needed for ip_output(). */
 	mutex_enter(softnet_lock);
+#endif
 
 	in_multi_lock(RW_WRITER);
 	igmp_timers_on = false;
@@ -566,7 +569,9 @@
 		inm = in_next_multi(&step);
 	}
 	in_multi_unlock();
+#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
+#endif
 }
 
 void
@@ -649,7 +654,9 @@
 	 * Note: IP_IGMP_MCAST indicates that in_multilock is held.
 	 * The caller must still acquire softnet_lock for ip_output().
 	 */
+#ifndef NET_MPSAFE
 	KASSERT(mutex_owned(softnet_lock));
+#endif
 	ip_output(m, NULL, NULL, IP_IGMP_MCAST, &imo, NULL);
 	IGMP_STATINC(IGMP_STAT_SND_REPORTS);
 }

cvs diff -r1.154 -r1.155 src/sys/netinet/ip_icmp.c (expand / switch to context diff)
--- src/sys/netinet/ip_icmp.c 2016/12/12 03:55:57 1.154
+++ src/sys/netinet/ip_icmp.c 2017/01/24 07:09:24 1.155
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_icmp.c,v 1.154 2016/12/12 03:55:57 ozaki-r Exp $	*/
+/*	$NetBSD: ip_icmp.c,v 1.155 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -94,7 +94,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.154 2016/12/12 03:55:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.155 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -105,6 +105,7 @@
 #include <sys/mbuf.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
+#include <sys/socketvar.h> /* For softnet_lock */
 #include <sys/kmem.h>
 #include <sys/time.h>
 #include <sys/kernel.h>
@@ -1012,6 +1013,9 @@
 		return (EINVAL);
 	icmp_redirtimeout = tmp;
 
+	/* XXX NOMPSAFE still need softnet_lock */
+	mutex_enter(softnet_lock);
+
 	/*
 	 * was it a *defined* side-effect that anyone even *reading*
 	 * this value causes these things to happen?
@@ -1028,6 +1032,8 @@
 		icmp_redirect_timeout_q =
 		    rt_timer_queue_create(icmp_redirtimeout);
 	}
+
+	mutex_exit(softnet_lock);
 
 	return (0);
 }

cvs diff -r1.347 -r1.348 src/sys/netinet/ip_input.c (expand / switch to context diff)
--- src/sys/netinet/ip_input.c 2016/12/12 03:55:57 1.347
+++ src/sys/netinet/ip_input.c 2017/01/24 07:09:24 1.348
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.347 2016/12/12 03:55:57 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.348 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.347 2016/12/12 03:55:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.348 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -866,13 +866,17 @@
 ip_slowtimo(void)
 {
 
+#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
+#endif
 
 	ip_reass_slowtimo();
 
+#ifndef NET_MPSAFE
 	KERNEL_UNLOCK_ONE(NULL);
 	mutex_exit(softnet_lock);
+#endif
 }
 
 /*
@@ -1603,6 +1607,7 @@
 	if (tmp < 0)
 		return (EINVAL);
 
+	/* XXX NOMPSAFE still need softnet_lock */
 	mutex_enter(softnet_lock);
 
 	ip_mtudisc_timeout = tmp;

cvs diff -r1.145 -r1.146 src/sys/netinet/ip_mroute.c (expand / switch to context diff)
--- src/sys/netinet/ip_mroute.c 2017/01/11 13:08:29 1.145
+++ src/sys/netinet/ip_mroute.c 2017/01/24 07:09:24 1.146
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.145 2017/01/11 13:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.146 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.145 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.146 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1561,9 +1561,10 @@
 expire_upcalls(void *v)
 {
 	int i;
-	int s;
 
-	s = splsoftnet();
+	/* XXX NOMPSAFE still need softnet_lock */
+	mutex_enter(softnet_lock);
+	KERNEL_LOCK(1, NULL);
 
 	for (i = 0; i < MFCTBLSIZ; i++) {
 		struct mfc *rt, *nrt;
@@ -1599,9 +1600,11 @@
 		}
 	}
 
-	splx(s);
 	callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
 	    expire_upcalls, NULL);
+
+	KERNEL_UNLOCK_ONE(NULL);
+	mutex_exit(softnet_lock);
 }
 
 /*

cvs diff -r1.161 -r1.162 src/sys/netinet/raw_ip.c (expand / switch to context diff)
--- src/sys/netinet/raw_ip.c 2016/09/29 12:19:47 1.161
+++ src/sys/netinet/raw_ip.c 2017/01/24 07:09:24 1.162
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip.c,v 1.161 2016/09/29 12:19:47 roy Exp $	*/
+/*	$NetBSD: raw_ip.c,v 1.162 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,13 +65,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.161 2016/09/29 12:19:47 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.162 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
 #include "opt_compat_netbsd.h"
 #include "opt_ipsec.h"
 #include "opt_mrouting.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -806,7 +807,13 @@
 	s = splsoftnet();
 	mutex_enter(softnet_lock);
 	in_pcbpurgeif0(&rawcbtable, ifp);
+#ifdef NET_MPSAFE
+	mutex_exit(softnet_lock);
+#endif
 	in_purgeif(ifp);
+#ifdef NET_MPSAFE
+	mutex_enter(softnet_lock);
+#endif
 	in_pcbpurgeif(&rawcbtable, ifp);
 	mutex_exit(softnet_lock);
 	splx(s);

cvs diff -r1.213 -r1.214 src/sys/netinet/tcp_usrreq.c (expand / switch to context diff)
--- src/sys/netinet/tcp_usrreq.c 2016/11/18 06:50:04 1.213
+++ src/sys/netinet/tcp_usrreq.c 2017/01/24 07:09:24 1.214
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.213 2016/11/18 06:50:04 knakahara Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.214 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.213 2016/11/18 06:50:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.214 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1210,21 +1210,31 @@
 
 	s = splsoftnet();
 
-#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
-#endif
 	switch (so->so_proto->pr_domain->dom_family) {
 #ifdef INET
 	case PF_INET:
 		in_pcbpurgeif0(&tcbtable, ifp);
+#ifdef NET_MPSAFE
+		mutex_exit(softnet_lock);
+#endif
 		in_purgeif(ifp);
+#ifdef NET_MPSAFE
+		mutex_enter(softnet_lock);
+#endif
 		in_pcbpurgeif(&tcbtable, ifp);
 		break;
 #endif
 #ifdef INET6
 	case PF_INET6:
 		in6_pcbpurgeif0(&tcbtable, ifp);
+#ifdef NET_MPSAFE
+		mutex_exit(softnet_lock);
+#endif
 		in6_purgeif(ifp);
+#ifdef NET_MPSAFE
+		mutex_enter(softnet_lock);
+#endif
 		in6_pcbpurgeif(&tcbtable, ifp);
 		break;
 #endif
@@ -1232,9 +1242,7 @@
 		error = EAFNOSUPPORT;
 		break;
 	}
-#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
-#endif
 	splx(s);
 
 	return error;

cvs diff -r1.229 -r1.230 src/sys/netinet/udp_usrreq.c (expand / switch to context diff)
--- src/sys/netinet/udp_usrreq.c 2016/11/18 06:50:04 1.229
+++ src/sys/netinet/udp_usrreq.c 2017/01/24 07:09:24 1.230
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.229 2016/11/18 06:50:04 knakahara Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.230 2017/01/24 07:09:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.229 2016/11/18 06:50:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.230 2017/01/24 07:09:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1140,15 +1140,17 @@
 	int s;
 
 	s = splsoftnet();
-#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
-#endif
 	in_pcbpurgeif0(&udbtable, ifp);
+#ifdef NET_MPSAFE
+	mutex_exit(softnet_lock);
+#endif
 	in_purgeif(ifp);
+#ifdef NET_MPSAFE
+	mutex_enter(softnet_lock);
+#endif
 	in_pcbpurgeif(&udbtable, ifp);
-#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
-#endif
 	splx(s);
 
 	return 0;

cvs diff -r1.10 -r1.11 src/sys/netinet6/dccp6_usrreq.c (expand / switch to context diff)
--- src/sys/netinet6/dccp6_usrreq.c 2016/12/13 08:29:03 1.10
+++ src/sys/netinet6/dccp6_usrreq.c 2017/01/24 07:09:25 1.11
@@ -1,5 +1,5 @@
 /*	$KAME: dccp6_usrreq.c,v 1.13 2005/07/27 08:42:56 nishida Exp $	*/
-/*	$NetBSD: dccp6_usrreq.c,v 1.10 2016/12/13 08:29:03 ozaki-r Exp $ */
+/*	$NetBSD: dccp6_usrreq.c,v 1.11 2017/01/24 07:09:25 ozaki-r Exp $ */
 
 /*
  * Copyright (C) 2003 WIDE Project.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.10 2016/12/13 08:29:03 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.11 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -318,15 +318,17 @@
 	int s;
 
 	s = splsoftnet();
-#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
-#endif
 	in6_pcbpurgeif0(&dccpbtable, ifp);
+#ifdef NET_MPSAFE
+	mutex_exit(softnet_lock);
+#endif
 	in6_purgeif(ifp);
+#ifdef NET_MPSAFE
+	mutex_enter(softnet_lock);
+#endif
 	in6_pcbpurgeif(&dccpbtable, ifp);
-#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
-#endif
 	splx(s);
 
 	return 0;

cvs diff -r1.59 -r1.60 src/sys/netinet6/frag6.c (expand / switch to context diff)
--- src/sys/netinet6/frag6.c 2017/01/11 13:08:29 1.59
+++ src/sys/netinet6/frag6.c 2017/01/24 07:09:25 1.60
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.59 2017/01/11 13:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,8 +31,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.59 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $");
 
+#ifdef _KERNEL_OPT
+#include "opt_net_mpsafe.h"
+#endif
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/mbuf.h>
@@ -592,16 +596,21 @@
 void
 frag6_fasttimo(void)
 {
+
+#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
+#endif
 
 	if (frag6_drainwanted) {
 		frag6_drain();
 		frag6_drainwanted = 0;
 	}
 
+#ifndef NET_MPSAFE
 	KERNEL_UNLOCK_ONE(NULL);
 	mutex_exit(softnet_lock);
+#endif
 }
 
 /*
@@ -614,8 +623,10 @@
 {
 	struct ip6q *q6;
 
+#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
+#endif
 
 	mutex_enter(&frag6_lock);
 	q6 = ip6q.ip6q_next;
@@ -642,8 +653,10 @@
 	}
 	mutex_exit(&frag6_lock);
 
+#ifndef NET_MPSAFE
 	KERNEL_UNLOCK_ONE(NULL);
 	mutex_exit(softnet_lock);
+#endif
 
 #if 0
 	/*

cvs diff -r1.109 -r1.110 src/sys/netinet6/in6_ifattach.c (expand / switch to context diff)
--- src/sys/netinet6/in6_ifattach.c 2017/01/04 19:37:14 1.109
+++ src/sys/netinet6/in6_ifattach.c 2017/01/24 07:09:25 1.110
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_ifattach.c,v 1.109 2017/01/04 19:37:14 christos Exp $	*/
+/*	$NetBSD: in6_ifattach.c,v 1.110 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.109 2017/01/04 19:37:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.110 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -860,6 +860,7 @@
 	struct ifnet *ifp;
 	int s;
 
+	/* XXX NOMPSAFE still need softnet_lock */
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
 

cvs diff -r1.115 -r1.116 src/sys/netinet6/ip6_mroute.c (expand / switch to context diff)
--- src/sys/netinet6/ip6_mroute.c 2017/01/16 15:44:47 1.115
+++ src/sys/netinet6/ip6_mroute.c 2017/01/24 07:09:25 1.116
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.115 2017/01/16 15:44:47 christos Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.116 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.115 2017/01/16 15:44:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.116 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1310,6 +1310,7 @@
 	struct mf6c *mfc, **nptr;
 	int i;
 
+	/* XXX NOMPSAFE still need softnet_lock */
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
 

cvs diff -r1.79 -r1.80 src/sys/netinet6/mld6.c (expand / switch to context diff)
--- src/sys/netinet6/mld6.c 2017/01/16 15:44:47 1.79
+++ src/sys/netinet6/mld6.c 2017/01/24 07:09:25 1.80
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.79 2017/01/16 15:44:47 christos Exp $	*/
+/*	$NetBSD: mld6.c,v 1.80 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.79 2017/01/16 15:44:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.80 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -229,6 +229,7 @@
 {
 	struct in6_multi *in6m = arg;
 
+	/* XXX NOMPSAFE still need softnet_lock */
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
 
@@ -792,11 +793,10 @@
 
 		/* Tell mld_timeo we're halting the timer */
 		in6m->in6m_timer = IN6M_TIMER_UNDEF;
-#ifdef NET_MPSAFE
-		callout_halt(&in6m->in6m_timer_ch, NULL);
-#else
-		callout_halt(&in6m->in6m_timer_ch, softnet_lock);
-#endif
+		if (mutex_owned(softnet_lock))
+			callout_halt(&in6m->in6m_timer_ch, softnet_lock);
+		else
+			callout_halt(&in6m->in6m_timer_ch, NULL);
 		callout_destroy(&in6m->in6m_timer_ch);
 
 		free(in6m, M_IPMADDR);

cvs diff -r1.154 -r1.155 src/sys/netinet6/raw_ip6.c (expand / switch to context diff)
--- src/sys/netinet6/raw_ip6.c 2016/12/13 08:29:03 1.154
+++ src/sys/netinet6/raw_ip6.c 2017/01/24 07:09:25 1.155
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip6.c,v 1.154 2016/12/13 08:29:03 ozaki-r Exp $	*/
+/*	$NetBSD: raw_ip6.c,v 1.155 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.154 2016/12/13 08:29:03 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.155 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -935,15 +935,17 @@
 rip6_purgeif(struct socket *so, struct ifnet *ifp)
 {
 
-#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
-#endif
 	in6_pcbpurgeif0(&raw6cbtable, ifp);
+#ifdef NET_MPSAFE
+	mutex_exit(softnet_lock);
+#endif
 	in6_purgeif(ifp);
+#ifdef NET_MPSAFE
+	mutex_enter(softnet_lock);
+#endif
 	in6_pcbpurgeif(&raw6cbtable, ifp);
-#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
-#endif
 
 	return 0;
 }

cvs diff -r1.126 -r1.127 src/sys/netinet6/udp6_usrreq.c (expand / switch to context diff)
--- src/sys/netinet6/udp6_usrreq.c 2016/11/18 06:50:04 1.126
+++ src/sys/netinet6/udp6_usrreq.c 2017/01/24 07:09:25 1.127
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp6_usrreq.c,v 1.126 2016/11/18 06:50:04 knakahara Exp $	*/
+/*	$NetBSD: udp6_usrreq.c,v 1.127 2017/01/24 07:09:25 ozaki-r Exp $	*/
 /*	$KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.126 2016/11/18 06:50:04 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.127 2017/01/24 07:09:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -912,15 +912,17 @@
 udp6_purgeif(struct socket *so, struct ifnet *ifp)
 {
 
-#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
-#endif
 	in6_pcbpurgeif0(&udbtable, ifp);
+#ifdef NET_MPSAFE
+	mutex_exit(softnet_lock);
+#endif
 	in6_purgeif(ifp);
+#ifdef NET_MPSAFE
+	mutex_enter(softnet_lock);
+#endif
 	in6_pcbpurgeif(&udbtable, ifp);
-#ifndef NET_MPSAFE
 	mutex_exit(softnet_lock);
-#endif
 
 	return 0;
 }