From: Sepherosa Ziehau Date: Wed, 14 Aug 2019 02:40:22 +0000 (+0800) Subject: net/raw: Assert all APIs are called from netisr0. X-Git-Tag: v5.8.0rc1~1158 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/aef87d48249d62118067dc0ab9d17f3a4c6ecc51 net/raw: Assert all APIs are called from netisr0. Remove the raw pcb list lock, since thread serialization is used. --- diff --git a/sys/net/raw_cb.c b/sys/net/raw_cb.c index e31f2d2343..d36c9b0d01 100644 --- a/sys/net/raw_cb.c +++ b/sys/net/raw_cb.c @@ -38,10 +38,13 @@ #include #include +#include /* * Routines to manage the raw protocol control blocks. * + * All of them must run in netisr0. + * * TODO: * hash lookups by protocol family/protocol + address family * take care of unique address problems per AF? @@ -66,6 +69,8 @@ raw_attach(struct socket *so, int proto, struct rlimit *rl) struct rawcb *rp = sotorawcb(so); int error; + ASSERT_NETISR0; + /* * It is assumed that raw_attach is called * after space has been allocated for the @@ -80,9 +85,7 @@ raw_attach(struct socket *so, int proto, struct rlimit *rl) rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family; rp->rcb_proto.sp_protocol = proto; - lockmgr(&raw_lock, LK_EXCLUSIVE); LIST_INSERT_HEAD(&rawcb_list, rp, list); - lockmgr(&raw_lock, LK_RELEASE); return (0); } @@ -96,9 +99,9 @@ raw_detach(struct rawcb *rp) { struct socket *so = rp->rcb_socket; - lockmgr(&raw_lock, LK_EXCLUSIVE); + ASSERT_NETISR0; + LIST_REMOVE(rp, list); - lockmgr(&raw_lock, LK_RELEASE); so->so_pcb = NULL; sofree(so); /* remove pcb ref */ @@ -111,6 +114,8 @@ raw_detach(struct rawcb *rp) void raw_disconnect(struct rawcb *rp) { + ASSERT_NETISR0; + if (rp->rcb_socket->so_state & SS_NOFDREF) raw_detach(rp); } @@ -124,6 +129,8 @@ raw_bind(struct socket *so, struct mbuf *nam) struct sockaddr *addr = mtod(nam, struct sockaddr *); struct rawcb *rp; + ASSERT_NETISR0; + if (ifnet == NULL) return (EADDRNOTAVAIL); rp = sotorawcb(so); diff --git a/sys/net/raw_cb.h b/sys/net/raw_cb.h index 9def816deb..c575a383b0 100644 --- a/sys/net/raw_cb.h +++ b/sys/net/raw_cb.h @@ -69,7 +69,6 @@ struct rawcb { #ifdef _KERNEL extern LIST_HEAD(rawcb_list_head, rawcb) rawcb_list; -extern struct lock raw_lock; union netmsg; diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index 5acb9c715c..b837ef2943 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -43,8 +43,12 @@ #include #include +#include -struct lock raw_lock = LOCK_INITIALIZER("rawlk", 0, 0); +/* + * Except from the raw_init(), rest of interfaces must be called + * from netisr0. + */ /* * Initialize raw connection block q. @@ -76,7 +80,8 @@ raw_input(struct mbuf *m0, const struct sockproto *proto, struct mbuf *m = m0; struct socket *last; - lockmgr(&raw_lock, LK_SHARED); + ASSERT_NETISR0; + last = NULL; LIST_FOREACH(rp, &rawcb_list, list) { @@ -128,7 +133,6 @@ raw_input(struct mbuf *m0, const struct sockproto *proto, } else { m_freem(m); } - lockmgr(&raw_lock, LK_RELEASE); } /* @@ -139,6 +143,8 @@ raw_ctlinput(netmsg_t msg) { int error = 0; + ASSERT_NETISR0; + if (msg->ctlinput.nm_cmd < 0 || msg->ctlinput.nm_cmd > PRC_NCMDS) { ; /* no-op */ } @@ -155,6 +161,8 @@ raw_uabort(netmsg_t msg) struct rawcb *rp = sotorawcb(msg->base.nm_so); int error; + ASSERT_NETISR0; + if (rp) { raw_disconnect(rp); soisdisconnected(msg->base.nm_so); @@ -176,6 +184,8 @@ raw_uattach(netmsg_t msg) struct rawcb *rp; int error; + ASSERT_NETISR0; + rp = sotorawcb(so); if (rp) { error = priv_check_cred(ai->p_ucred, PRIV_ROOT, NULL_CRED_OKAY); @@ -190,12 +200,14 @@ raw_uattach(netmsg_t msg) static void raw_ubind(netmsg_t msg) { + ASSERT_NETISR0; lwkt_replymsg(&msg->lmsg, EINVAL); } static void raw_uconnect(netmsg_t msg) { + ASSERT_NETISR0; lwkt_replymsg(&msg->lmsg, EINVAL); } @@ -208,6 +220,8 @@ raw_udetach(netmsg_t msg) struct rawcb *rp = sotorawcb(msg->base.nm_so); int error; + ASSERT_NETISR0; + if (rp) { raw_detach(rp); error = 0; @@ -224,6 +238,8 @@ raw_udisconnect(netmsg_t msg) struct rawcb *rp; int error; + ASSERT_NETISR0; + rp = sotorawcb(so); if (rp == NULL) { error = EINVAL; @@ -247,6 +263,8 @@ raw_upeeraddr(netmsg_t msg) struct rawcb *rp = sotorawcb(msg->base.nm_so); int error; + ASSERT_NETISR0; + if (rp == NULL) { error = EINVAL; } else if (rp->rcb_faddr == NULL) { @@ -272,6 +290,8 @@ raw_usend(netmsg_t msg) int flags = msg->send.nm_flags; int error; + ASSERT_NETISR0; + if (rp == NULL) { error = EINVAL; goto release; @@ -315,6 +335,8 @@ raw_ushutdown(netmsg_t msg) struct rawcb *rp = sotorawcb(msg->base.nm_so); int error; + ASSERT_NETISR0; + if (rp) { socantsendmore(msg->base.nm_so); error = 0; @@ -330,6 +352,8 @@ raw_usockaddr(netmsg_t msg) struct rawcb *rp = sotorawcb(msg->base.nm_so); int error; + ASSERT_NETISR0; + if (rp == NULL) { error = EINVAL; } else if (rp->rcb_laddr == NULL) {