Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net sppp_lock is changed from mutex to rwlock now. Contr...
details: https://anonhg.NetBSD.org/src/rev/9b4725ec9592
branches: trunk
changeset: 356782:9b4725ec9592
user: knakahara <knakahara%NetBSD.org@localhost>
date: Thu Oct 12 09:49:43 2017 +0000
description:
sppp_lock is changed from mutex to rwlock now. Contributed by s-yamaguchi@IIJ.
Add locking notes later.
diffstat:
sys/net/if_pppoe.c | 16 +-
sys/net/if_spppsubr.c | 827 ++++++++++++++++++++++++++++---------------------
sys/net/if_spppvar.h | 7 +-
3 files changed, 476 insertions(+), 374 deletions(-)
diffs (truncated from 2618 to 300 lines):
diff -r 4786c3c123aa -r 9b4725ec9592 sys/net/if_pppoe.c
--- a/sys/net/if_pppoe.c Thu Oct 12 09:48:53 2017 +0000
+++ b/sys/net/if_pppoe.c Thu Oct 12 09:49:43 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $ */
/*-
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "pppoe.h"
@@ -813,9 +813,7 @@
sc->sc_state = PPPOE_STATE_SESSION;
PPPOE_UNLOCK(sc);
- sppp_lock_enter(&sc->sc_sppp);
sc->sc_sppp.pp_up(&sc->sc_sppp);
- sppp_lock_exit(&sc->sc_sppp);
break;
}
#else
@@ -899,9 +897,7 @@
sc->sc_state = PPPOE_STATE_SESSION;
PPPOE_UNLOCK(sc);
- sppp_lock_enter(&sc->sc_sppp);
sc->sc_sppp.pp_up(&sc->sc_sppp); /* notify upper layers */
- sppp_lock_exit(&sc->sc_sppp);
break;
case PPPOE_CODE_PADT: {
struct ifnet *rcvif;
@@ -1495,9 +1491,7 @@
PPPOE_UNLOCK(sc);
/* notify upper layer */
- sppp_lock_enter(&sc->sc_sppp);
sc->sc_sppp.pp_down(&sc->sc_sppp);
- sppp_lock_exit(&sc->sc_sppp);
PPPOE_LOCK(sc, RW_WRITER);
@@ -1518,9 +1512,7 @@
PPPOE_UNLOCK(sc);
/* notify upper layer */
- sppp_lock_enter(&sc->sc_sppp);
sc->sc_sppp.pp_down(&sc->sc_sppp);
- sppp_lock_exit(&sc->sc_sppp);
PPPOE_LOCK(sc, RW_WRITER);
@@ -1849,13 +1841,11 @@
PPPOE_UNLOCK(sc);
continue;
}
- sppp_lock_enter(&sc->sc_sppp);
if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
printf("%s: ethernet interface detached, going down\n",
sc->sc_sppp.pp_if.if_xname);
}
- sppp_lock_exit(&sc->sc_sppp);
sc->sc_eth_if = NULL;
pppoe_clear_softc(sc, "ethernet interface detached");
PPPOE_UNLOCK(sc);
@@ -1881,9 +1871,7 @@
PPPOE_UNLOCK(sc);
/* signal upper layer */
- sppp_lock_enter(&sc->sc_sppp);
sc->sc_sppp.pp_down(&sc->sc_sppp);
- sppp_lock_exit(&sc->sc_sppp);
PPPOE_LOCK(sc, RW_WRITER);
diff -r 4786c3c123aa -r 9b4725ec9592 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c Thu Oct 12 09:48:53 2017 +0000
+++ b/sys/net/if_spppsubr.c Thu Oct 12 09:49:43 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $ */
+/* $NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -254,6 +254,15 @@
#define SPPPQ_UNLOCK() if (spppq_lock) \
mutex_exit(spppq_lock);
+#define SPPP_LOCK(_sp, _op) rw_enter(&(_sp)->pp_lock, (_op))
+#define SPPP_UNLOCK(_sp) rw_exit(&(_sp)->pp_lock)
+#define SPPP_WLOCKED(_sp) rw_write_held(&(_sp)->pp_lock)
+#define SPPP_UPGRADE(_sp) do{ \
+ SPPP_UNLOCK(_sp); \
+ SPPP_LOCK(_sp, RW_WRITER); \
+}while (0)
+#define SPPP_DOWNGRADE(_sp) rw_downgrade(&(_sp)->pp_lock)
+
#ifdef INET
#ifndef SPPPSUBR_MPSAFE
/*
@@ -403,6 +412,16 @@
static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src);
#endif
+static void sppp_notify_up(struct sppp *);
+static void sppp_notify_down(struct sppp *);
+static void sppp_notify_tls_wlocked(struct sppp *);
+static void sppp_notify_tlf_wlocked(struct sppp *);
+static void sppp_notify_con_wlocked(struct sppp *);
+static void sppp_notify_con(struct sppp *);
+
+static void sppp_notify_chg_wlocked(struct sppp *);
+
+
/* our control protocol descriptors */
static const struct cp lcp = {
PPP_LCP, IDX_LCP, CP_LCP, "lcp",
@@ -469,7 +488,7 @@
{
STDDCL;
- KASSERT(sppp_locked(sp));
+ KASSERT(SPPP_WLOCKED(sp));
if (sp->pp_phase == phase)
return;
@@ -506,9 +525,7 @@
int debug = ifp->if_flags & IFF_DEBUG;
int isr = 0;
- KASSERT(!sppp_locked(sp));
-
- sppp_lock_enter(sp);
+ SPPP_LOCK(sp, RW_READER);
if (ifp->if_flags & IFF_UP) {
/* Count received bytes, add hardware framing */
@@ -527,7 +544,7 @@
++ifp->if_ierrors;
++ifp->if_iqdrops;
m_freem(m);
- sppp_lock_exit(sp);
+ SPPP_UNLOCK(sp);
return;
}
@@ -572,7 +589,7 @@
++ifp->if_noproto;
goto invalid;
case CISCO_KEEPALIVE:
- sppp_lock_exit(sp);
+ SPPP_UNLOCK(sp);
sppp_cisco_input((struct sppp *) ifp, m);
m_freem(m);
return;
@@ -605,9 +622,12 @@
default:
if (sp->state[IDX_LCP] == STATE_OPENED) {
uint16_t prot = htons(protocol);
+
+ SPPP_UPGRADE(sp);
sppp_cp_send(sp, PPP_LCP, PROTO_REJ,
++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,
&prot);
+ SPPP_DOWNGRADE(sp);
}
if (debug)
log(LOG_DEBUG,
@@ -616,33 +636,30 @@
++ifp->if_noproto;
goto drop;
case PPP_LCP:
- sppp_lock_exit(sp);
+ SPPP_UNLOCK(sp);
sppp_cp_input(&lcp, sp, m);
m_freem(m);
return;
case PPP_PAP:
+ SPPP_UNLOCK(sp);
if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) {
- sppp_lock_exit(sp);
sppp_pap_input(sp, m);
- } else
- sppp_lock_exit(sp);
+ }
m_freem(m);
return;
case PPP_CHAP:
+ SPPP_UNLOCK(sp);
if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) {
- sppp_lock_exit(sp);
sppp_chap_input(sp, m);
- } else
- sppp_lock_exit(sp);
+ }
m_freem(m);
return;
#ifdef INET
case PPP_IPCP:
+ SPPP_UNLOCK(sp);
if (sp->pp_phase == SPPP_PHASE_NETWORK) {
- sppp_lock_exit(sp);
sppp_cp_input(&ipcp, sp, m);
- } else
- sppp_lock_exit(sp);
+ }
m_freem(m);
return;
case PPP_IP:
@@ -654,11 +671,10 @@
#endif
#ifdef INET6
case PPP_IPV6CP:
+ SPPP_UNLOCK(sp);
if (sp->pp_phase == SPPP_PHASE_NETWORK) {
- sppp_lock_exit(sp);
sppp_cp_input(&ipv6cp, sp, m);
- } else
- sppp_lock_exit(sp);
+ }
m_freem(m);
return;
@@ -676,16 +692,17 @@
goto drop;
}
- sppp_lock_exit(sp);
/* Check queue. */
if (__predict_true(pktq)) {
if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
- sppp_lock_enter(sp);
goto drop;
}
+ SPPP_UNLOCK(sp);
return;
}
+ SPPP_UNLOCK(sp);
+
IFQ_LOCK(inq);
if (IF_QFULL(inq)) {
/* Queue overflow. */
@@ -694,7 +711,8 @@
if (debug)
log(LOG_DEBUG, "%s: protocol queue overflow\n",
ifp->if_xname);
- sppp_lock_enter(sp);
+
+ SPPP_LOCK(sp, RW_READER);
goto drop;
}
IF_ENQUEUE(inq, m);
@@ -719,15 +737,17 @@
size_t pktlen;
s = splnet();
-
- sppp_lock_enter(sp);
+ SPPP_LOCK(sp, RW_READER);
+
sp->pp_last_activity = time_uptime;
if ((ifp->if_flags & IFF_UP) == 0 ||
(ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == 0) {
- sppp_lock_exit(sp);
+ SPPP_UNLOCK(sp);
+ splx(s);
+
m_freem(m);
- splx(s);
+
return (ENETDOWN);
}
@@ -737,9 +757,16 @@
* to start LCP for it.
*/
ifp->if_flags |= IFF_RUNNING;
+
+ SPPP_UNLOCK(sp);
splx(s);
+
+ SPPP_LOCK(sp, RW_WRITER);
Home |
Main Index |
Thread Index |
Old Index