Module Name:    src
Committed By:   ozaki-r
Date:           Wed Sep 27 10:05:05 UTC 2017

Modified Files:
        src/sys/netinet: in_proto.c ip_input.c
        src/sys/netinet6: in6_proto.c ip6_input.c ip6protosw.h
        src/sys/sys: protosw.h

Log Message:
Take softnet_lock on pr_input properly if NET_MPSAFE

Currently softnet_lock is taken unnecessarily in some cases, e.g.,
icmp_input and encap4_input from ip_input, or not taken even if needed,
e.g., udp_input and tcp_input from ipsec4_common_input_cb. Fix them.

NFC if NET_MPSAFE is disabled (default).


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/netinet/in_proto.c
cvs rdiff -u -r1.360 -r1.361 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.118 -r1.119 src/sys/netinet6/in6_proto.c
cvs rdiff -u -r1.181 -r1.182 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.25 -r1.26 src/sys/netinet6/ip6protosw.h
cvs rdiff -u -r1.66 -r1.67 src/sys/sys/protosw.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_proto.c
diff -u src/sys/netinet/in_proto.c:1.124 src/sys/netinet/in_proto.c:1.125
--- src/sys/netinet/in_proto.c:1.124	Thu Sep 21 07:15:34 2017
+++ src/sys/netinet/in_proto.c	Wed Sep 27 10:05:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_proto.c,v 1.124 2017/09/21 07:15:34 ozaki-r Exp $	*/
+/*	$NetBSD: in_proto.c,v 1.125 2017/09/27 10:05:04 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.124 2017/09/21 07:15:34 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.125 2017/09/27 10:05:04 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v
 #include "opt_dccp.h"
 #include "opt_sctp.h"
 #include "opt_compat_netbsd.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -185,6 +186,38 @@ PR_WRAP_CTLOUTPUT(sctp_ctloutput)
 #define sctp_ctloutput	sctp_ctloutput_wrapper
 #endif
 
+#ifdef NET_MPSAFE
+PR_WRAP_INPUT(udp_input)
+PR_WRAP_INPUT(tcp_input)
+#ifdef DCCP
+PR_WRAP_INPUT(dccp_input)
+#endif
+#ifdef SCTP
+PR_WRAP_INPUT(sctp_input)
+#endif
+PR_WRAP_INPUT(rip_input)
+#if NETHERIP > 0
+PR_WRAP_INPUT(ip_etherip_input)
+#endif
+#if NPFSYNC > 0
+PR_WRAP_INPUT(pfsync_input)
+#endif
+PR_WRAP_INPUT(igmp_input)
+#ifdef PIM
+PR_WRAP_INPUT(pim_input)
+#endif
+
+#define	udp_input		udp_input_wrapper
+#define	tcp_input		tcp_input_wrapper
+#define	dccp_input		dccp_input_wrapper
+#define	sctp_input		sctp_input_wrapper
+#define	rip_input		rip_input_wrapper
+#define	ip_etherip_input	ip_etherip_input_wrapper
+#define	pfsync_input		pfsync_input_wrapper
+#define	igmp_input		igmp_input_wrapper
+#define	pim_input		pim_input_wrapper
+#endif
+
 #if defined(IPSEC)
 
 #ifdef IPSEC_RUMPKERNEL

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.360 src/sys/netinet/ip_input.c:1.361
--- src/sys/netinet/ip_input.c:1.360	Thu Jul 27 06:59:28 2017
+++ src/sys/netinet/ip_input.c	Wed Sep 27 10:05:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.360 2017/07/27 06:59:28 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 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.360 2017/07/27 06:59:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -826,9 +826,7 @@ ours:
 
 	const int off = hlen, nh = ip->ip_p;
 
-	SOFTNET_LOCK();
 	(*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
-	SOFTNET_UNLOCK();
 	return;
 
 out:

Index: src/sys/netinet6/in6_proto.c
diff -u src/sys/netinet6/in6_proto.c:1.118 src/sys/netinet6/in6_proto.c:1.119
--- src/sys/netinet6/in6_proto.c:1.118	Thu Sep 21 07:15:35 2017
+++ src/sys/netinet6/in6_proto.c	Wed Sep 27 10:05:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_proto.c,v 1.118 2017/09/21 07:15:35 ozaki-r Exp $	*/
+/*	$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $	*/
 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.118 2017/09/21 07:15:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -70,6 +70,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_proto.c,
 #include "opt_ipsec.h"
 #include "opt_dccp.h"
 #include "opt_sctp.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -184,6 +185,39 @@ PR_WRAP_CTLOUTPUT(sctp_ctloutput)
 #define sctp_ctloutput	sctp_ctloutput_wrapper
 #endif
 
+#ifdef NET_MPSAFE
+PR_WRAP_INPUT6(udp6_input)
+PR_WRAP_INPUT6(tcp6_input)
+#ifdef DCCP
+PR_WRAP_INPUT6(dccp6_input)
+#endif
+#ifdef SCTP
+PR_WRAP_INPUT6(sctp6_input)
+#endif
+PR_WRAP_INPUT6(rip6_input)
+PR_WRAP_INPUT6(dest6_input)
+PR_WRAP_INPUT6(route6_input)
+PR_WRAP_INPUT6(frag6_input)
+#if NETHERIP > 0
+PR_WRAP_INPUT6(ip6_etherip_input)
+#endif
+#if NPFSYNC > 0
+PR_WRAP_INPUT6(pfsync_input)
+#endif
+PR_WRAP_INPUT6(pim6_input)
+
+#define	udp6_input		udp6_input_wrapper
+#define	tcp6_input		tcp6_input_wrapper
+#define	dccp6_input		dccp6_input_wrapper
+#define	sctp6_input		sctp6_input_wrapper
+#define	rip6_input		rip6_input_wrapper
+#define	dest6_input		dest6_input_wrapper
+#define	route6_input		route6_input_wrapper
+#define	frag6_input		frag6_input_wrapper
+#define	ip6_etherip_input	ip6_etherip_input_wrapper
+#define	pim6_input		pim6_input_wrapper
+#endif
+
 #if defined(IPSEC)
 
 #ifdef IPSEC_RUMPKERNEL

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.181 src/sys/netinet6/ip6_input.c:1.182
--- src/sys/netinet6/ip6_input.c:1.181	Thu Jul 27 06:59:28 2017
+++ src/sys/netinet6/ip6_input.c	Wed Sep 27 10:05:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.181 2017/07/27 06:59:28 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.181 2017/07/27 06:59:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -797,9 +797,7 @@ ip6_input(struct mbuf *m, struct ifnet *
 		}
 #endif /* IPSEC */
 
-		SOFTNET_LOCK();
 		nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
-		SOFTNET_UNLOCK();
 	}
 	return;
 

Index: src/sys/netinet6/ip6protosw.h
diff -u src/sys/netinet6/ip6protosw.h:1.25 src/sys/netinet6/ip6protosw.h:1.26
--- src/sys/netinet6/ip6protosw.h:1.25	Thu Jan 21 15:41:30 2016
+++ src/sys/netinet6/ip6protosw.h	Wed Sep 27 10:05:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6protosw.h,v 1.25 2016/01/21 15:41:30 riastradh Exp $	*/
+/*	$NetBSD: ip6protosw.h,v 1.26 2017/09/27 10:05:05 ozaki-r Exp $	*/
 /*	$KAME: ip6protosw.h,v 1.22 2001/02/08 18:02:08 itojun Exp $	*/
 
 /*
@@ -140,6 +140,19 @@ struct ip6protosw {
 			(void);
 };
 
+#ifdef _KERNEL
+#define	PR_WRAP_INPUT6(name)				\
+static int						\
+name##_wrapper(struct mbuf **mp, int *offp, int proto)	\
+{							\
+	int rv;						\
+	mutex_enter(softnet_lock);			\
+	rv = name(mp, offp, proto);			\
+	mutex_exit(softnet_lock);			\
+	return rv;					\
+}
+#endif
+
 extern const struct ip6protosw inet6sw[];
 
 #endif /* !_NETINET6_IP6PROTOSW_H_ */

Index: src/sys/sys/protosw.h
diff -u src/sys/sys/protosw.h:1.66 src/sys/sys/protosw.h:1.67
--- src/sys/sys/protosw.h:1.66	Wed Jan 20 21:43:59 2016
+++ src/sys/sys/protosw.h	Wed Sep 27 10:05:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: protosw.h,v 1.66 2016/01/20 21:43:59 riastradh Exp $	*/
+/*	$NetBSD: protosw.h,v 1.67 2017/09/27 10:05:05 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1993
@@ -494,6 +494,22 @@ name##_wrapper(int a, const struct socka
 	return rv;					\
 }
 
+#define	PR_WRAP_INPUT(name)				\
+static void						\
+name##_wrapper(struct mbuf *m, ...)			\
+{							\
+	va_list args;					\
+	int off, nxt;					\
+	/* XXX just passing args doesn't work on rump kernels */\
+	va_start(args, m);				\
+	off = va_arg(args, int);			\
+	nxt = va_arg(args, int);			\
+	va_end(args);					\
+	mutex_enter(softnet_lock);			\
+	name(m, off, nxt);				\
+	mutex_exit(softnet_lock);			\
+}
+
 #endif /* _KERNEL */
 
 #endif /* !_SYS_PROTOSW_H_ */

Reply via email to