Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Take softnet_lock on pr_input properly if NET_MPSAFE
details: https://anonhg.NetBSD.org/src/rev/ffd67482f300
branches: trunk
changeset: 356450:ffd67482f300
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Sep 27 10:05:04 2017 +0000
description:
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).
diffstat:
sys/netinet/in_proto.c | 37 +++++++++++++++++++++++++++++++++++--
sys/netinet/ip_input.c | 6 ++----
sys/netinet6/in6_proto.c | 38 ++++++++++++++++++++++++++++++++++++--
sys/netinet6/ip6_input.c | 6 ++----
sys/netinet6/ip6protosw.h | 15 ++++++++++++++-
sys/sys/protosw.h | 18 +++++++++++++++++-
6 files changed, 106 insertions(+), 14 deletions(-)
diffs (248 lines):
diff -r b0e464661a17 -r ffd67482f300 sys/netinet/in_proto.c
--- a/sys/netinet/in_proto.c Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/netinet/in_proto.c Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
#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 @@
#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
diff -r b0e464661a17 -r ffd67482f300 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/netinet/ip_input.c Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
const int off = hlen, nh = ip->ip_p;
- SOFTNET_LOCK();
(*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
- SOFTNET_UNLOCK();
return;
out:
diff -r b0e464661a17 -r ffd67482f300 sys/netinet6/in6_proto.c
--- a/sys/netinet6/in6_proto.c Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/netinet6/in6_proto.c Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
#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 @@
#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
diff -r b0e464661a17 -r ffd67482f300 sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/netinet6/ip6_input.c Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
}
#endif /* IPSEC */
- SOFTNET_LOCK();
nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
- SOFTNET_UNLOCK();
}
return;
diff -r b0e464661a17 -r ffd67482f300 sys/netinet6/ip6protosw.h
--- a/sys/netinet6/ip6protosw.h Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/netinet6/ip6protosw.h Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
(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_ */
diff -r b0e464661a17 -r ffd67482f300 sys/sys/protosw.h
--- a/sys/sys/protosw.h Wed Sep 27 09:55:52 2017 +0000
+++ b/sys/sys/protosw.h Wed Sep 27 10:05:04 2017 +0000
@@ -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 @@
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_ */
Home |
Main Index |
Thread Index |
Old Index