Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys make encap_lock_{enter,exit} interruptable.
details: https://anonhg.NetBSD.org/src/rev/fc9e99859da6
branches: trunk
changeset: 346265:fc9e99859da6
user: knakahara <knakahara%NetBSD.org@localhost>
date: Mon Jul 04 04:35:09 2016 +0000
description:
make encap_lock_{enter,exit} interruptable.
diffstat:
sys/net/if.c | 12 ++++++++-
sys/net/if_gif.c | 17 ++++++++++---
sys/net/if_stf.c | 12 +++++++--
sys/netinet/ip_encap.c | 57 ++++++++++++++++++++++++++++++++++------------
sys/netinet/ip_encap.h | 6 +++-
sys/netinet/ip_mroute.c | 8 ++++--
sys/netipsec/xform_ipip.c | 9 ++++--
7 files changed, 89 insertions(+), 32 deletions(-)
diffs (truncated from 325 to 300 lines):
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/net/if.c
--- a/sys/net/if.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/net/if.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.351 2016/07/04 01:36:06 ozaki-r Exp $ */
+/* $NetBSD: if.c,v 1.352 2016/07/04 04:35:09 knakahara Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,10 +90,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.351 2016/07/04 01:36:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.352 2016/07/04 04:35:09 knakahara Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
+#include "opt_ipsec.h"
#include "opt_atalk.h"
#include "opt_natm.h"
@@ -137,6 +138,9 @@
#include <net/pfil.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
+#ifndef IPSEC
+#include <netinet/ip_encap.h>
+#endif
#ifdef INET6
#include <netinet6/in6_var.h>
@@ -258,6 +262,10 @@
sysctl_net_pktq_setup(NULL, PF_INET6);
#endif
+#ifndef IPSEC
+ encapinit();
+#endif
+
if_listener = kauth_listen_scope(KAUTH_SCOPE_NETWORK,
if_listener_cb, NULL);
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/net/if_gif.c
--- a/sys/net/if_gif.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/net/if_gif.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.c,v 1.116 2016/07/04 04:22:47 knakahara Exp $ */
+/* $NetBSD: if_gif.c,v 1.117 2016/07/04 04:35:09 knakahara Exp $ */
/* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.116 2016/07/04 04:22:47 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.117 2016/07/04 04:35:09 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -829,7 +829,11 @@
int error;
s = splsoftnet();
- encap_lock_enter();
+ error = encap_lock_enter();
+ if (error) {
+ splx(s);
+ return error;
+ }
LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
if (sc2 == sc)
@@ -916,9 +920,14 @@
{
struct gif_softc *sc = ifp->if_softc;
int s;
+ int error;
s = splsoftnet();
- encap_lock_enter();
+ error = encap_lock_enter();
+ if (error) {
+ splx(s);
+ return;
+ }
gif_encap_pause(sc);
if (sc->gif_psrc) {
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/net/if_stf.c
--- a/sys/net/if_stf.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/net/if_stf.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_stf.c,v 1.92 2016/07/04 04:17:25 knakahara Exp $ */
+/* $NetBSD: if_stf.c,v 1.93 2016/07/04 04:35:09 knakahara Exp $ */
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
/*
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.92 2016/07/04 04:17:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.93 2016/07/04 04:35:09 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -190,11 +190,17 @@
stf_clone_create(struct if_clone *ifc, int unit)
{
struct stf_softc *sc;
+ int error;
sc = malloc(sizeof(struct stf_softc), M_DEVBUF, M_WAIT|M_ZERO);
if_initname(&sc->sc_if, ifc->ifc_name, unit);
- encap_lock_enter();
+ error = encap_lock_enter();
+ if (error) {
+ free(sc, M_DEVBUF);
+ return error;
+ }
+
if (LIST_FIRST(&stf_softc_list) != NULL) {
/* Only one stf interface is allowed. */
encap_lock_exit();
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/netinet/ip_encap.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_encap.c,v 1.58 2016/07/04 04:32:55 knakahara Exp $ */
+/* $NetBSD: ip_encap.c,v 1.59 2016/07/04 04:35:09 knakahara Exp $ */
/* $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $ */
/*
@@ -68,7 +68,7 @@
#define USE_RADIX
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.58 2016/07/04 04:32:55 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.59 2016/07/04 04:35:09 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@@ -85,6 +85,7 @@
#include <sys/kmem.h>
#include <sys/once.h>
#include <sys/mutex.h>
+#include <sys/condvar.h>
#include <sys/psref.h>
#include <sys/pslist.h>
@@ -145,6 +146,12 @@
};
#define encap_table encaptab.list
+static struct {
+ kmutex_t lock;
+ kcondvar_t cv;
+ struct lwp *busy;
+} encap_whole __cacheline_aligned;
+
#ifdef USE_RADIX
struct radix_node_head *encap_head[2]; /* 0 for AF_INET, 1 for AF_INET6 */
static bool encap_head_updating = false;
@@ -154,6 +161,18 @@
static int encap_init_once(void);
+/*
+ * must be done before other encap interfaces initialization.
+ */
+void
+encapinit(void)
+{
+
+ mutex_init(&encap_whole.lock, MUTEX_DEFAULT, IPL_NONE);
+ cv_init(&encap_whole.cv, "ip_encap cv");
+ encap_whole.busy = NULL;
+}
+
void
encap_init(void)
{
@@ -1081,32 +1100,40 @@
return p;
}
-void
+int
encap_lock_enter(void)
{
+ int error;
- /* XXX future work
- * change interruptable lock.
- */
- KERNEL_LOCK(1, NULL);
+ mutex_enter(&encap_whole.lock);
+ while (encap_whole.busy != NULL) {
+ error = cv_wait_sig(&encap_whole.cv, &encap_whole.lock);
+ if (error) {
+ mutex_exit(&encap_whole.lock);
+ return error;
+ }
+ }
+ KASSERT(encap_whole.busy == NULL);
+ encap_whole.busy = curlwp;
+ mutex_exit(&encap_whole.lock);
+
+ return 0;
}
void
encap_lock_exit(void)
{
- /* XXX future work
- * change interruptable lock
- */
- KERNEL_UNLOCK_ONE(NULL);
+ mutex_enter(&encap_whole.lock);
+ KASSERT(encap_whole.busy == curlwp);
+ encap_whole.busy = NULL;
+ cv_broadcast(&encap_whole.cv);
+ mutex_exit(&encap_whole.lock);
}
bool
encap_lock_held(void)
{
- /* XXX future work
- * should change interruptable lock.
- */
- return KERNEL_LOCKED_P();
+ return (encap_whole.busy == curlwp);
}
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/netinet/ip_encap.h
--- a/sys/netinet/ip_encap.h Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/netinet/ip_encap.h Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_encap.h,v 1.21 2016/07/04 04:29:11 knakahara Exp $ */
+/* $NetBSD: ip_encap.h,v 1.22 2016/07/04 04:35:09 knakahara Exp $ */
/* $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $ */
/*
@@ -97,6 +97,8 @@
struct sockaddr_in6 yours;
};
+void encapinit(void);
+
void encap_init(void);
void encap4_input(struct mbuf *, ...);
int encap6_input(struct mbuf **, int *, int);
@@ -110,7 +112,7 @@
int encap_detach(const struct encaptab *);
void *encap_getarg(struct mbuf *);
-void encap_lock_enter(void);
+int encap_lock_enter(void);
void encap_lock_exit(void);
bool encap_lock_held(void);
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/netinet/ip_mroute.c
--- a/sys/netinet/ip_mroute.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/netinet/ip_mroute.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_mroute.c,v 1.142 2016/07/04 04:17:25 knakahara Exp $ */
+/* $NetBSD: ip_mroute.c,v 1.143 2016/07/04 04:35:09 knakahara Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.142 2016/07/04 04:17:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.143 2016/07/04 04:35:09 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -832,7 +832,9 @@
* this requires both radix tree lookup and then a
* function to check, and this is not supported yet.
*/
- encap_lock_enter();
+ error = encap_lock_enter();
+ if (error)
+ return error;
vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
vif_encapcheck, &vif_encapsw, vifp);
encap_lock_exit();
diff -r 7c46a1b4dc55 -r fc9e99859da6 sys/netipsec/xform_ipip.c
--- a/sys/netipsec/xform_ipip.c Mon Jul 04 04:32:55 2016 +0000
+++ b/sys/netipsec/xform_ipip.c Mon Jul 04 04:35:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xform_ipip.c,v 1.40 2016/07/04 04:17:25 knakahara Exp $ */
Home |
Main Index |
Thread Index |
Old Index