On Tue, Sep 20, 2016 at 04:17:37PM +0200, Mike Belopuhov wrote:
> On 20 September 2016 at 15:55, Alexander Bluhm <[email protected]>
> wrote:
> > On Tue, Sep 20, 2016 at 08:21:55AM -0400, David Hill wrote:
> >> With bluhm's r1.160 uipc_socket.c.
> >
> > With splsoftnet() in soshutdown() I can fix this one.
> >
> > splassert: sowwakeup: want 5 have 0
> > Starting stack trace...
> > splassert_check() at splassert_check+0x78
> > sowwakeup() at sowwakeup+0x27
> > uipc_usrreq() at uipc_usrreq+0xfd
> > sys_shutdown() at sys_shutdown+0x67
> > syscall() at syscall+0x27b
> > --- syscall (number 134) ---
> > end of kernel
> > end trace frame: 0xe8f2cba5e80, count: 252
> > 0xe8f305dc16a:
> > End of stack trace.
> >
> > ok?
> >
>
> OK mikeb
>
> Can we assert that *_usrreq is always called under splsoftnet?
> I recall fixing some of them for raw sockets and some such and
> was wondering if the spl has to be raised before we end up there.
>
Just playing around with splsoftassert's and had to add the following
splsoftnet's to get my machine to be quiet.
Index: kern/sys_socket.c
===================================================================
RCS file: /cvs/src/sys/kern/sys_socket.c,v
retrieving revision 1.22
diff -u -p -r1.22 sys_socket.c
--- kern/sys_socket.c 6 Oct 2016 17:02:10 -0000 1.22
+++ kern/sys_socket.c 18 Oct 2016 20:15:47 -0000
@@ -167,6 +167,7 @@ int
soo_stat(struct file *fp, struct stat *ub, struct proc *p)
{
struct socket *so = fp->f_data;
+ int s;
memset(ub, 0, sizeof (*ub));
ub->st_mode = S_IFSOCK;
@@ -177,8 +178,10 @@ soo_stat(struct file *fp, struct stat *u
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
ub->st_uid = so->so_euid;
ub->st_gid = so->so_egid;
+ s = splsoftnet();
(void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
(struct mbuf *)ub, NULL, NULL, p));
+ splx(s);
return (0);
}
Index: kern/uipc_syscalls.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.135
diff -u -p -r1.135 uipc_syscalls.c
--- kern/uipc_syscalls.c 8 Oct 2016 02:16:43 -0000 1.135
+++ kern/uipc_syscalls.c 18 Oct 2016 20:15:47 -0000
@@ -1049,7 +1049,7 @@ sys_getsockname(struct proc *p, void *v,
struct socket *so;
struct mbuf *m = NULL;
socklen_t len;
- int error;
+ int error, s;
if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
@@ -1061,7 +1061,9 @@ sys_getsockname(struct proc *p, void *v,
if (error)
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
+ s = splsoftnet();
error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0, p);
+ splx(s);
if (error)
goto bad;
error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen));
@@ -1087,7 +1089,7 @@ sys_getpeername(struct proc *p, void *v,
struct socket *so;
struct mbuf *m = NULL;
socklen_t len;
- int error;
+ int error, s;
if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
@@ -1103,7 +1105,9 @@ sys_getpeername(struct proc *p, void *v,
if (error)
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
+ s = splsoftnet();
error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0, p);
+ splx(s);
if (error)
goto bad;
error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen));
Index: net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.455
diff -u -p -r1.455 if.c
--- net/if.c 16 Oct 2016 21:45:17 -0000 1.455
+++ net/if.c 18 Oct 2016 20:15:47 -0000
@@ -2072,9 +2072,11 @@ ifioctl(struct socket *so, u_long cmd, c
default:
if (so->so_proto == 0)
return (EOPNOTSUPP);
+ s = splsoftnet();
error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
(struct mbuf *) cmd, (struct mbuf *) data,
(struct mbuf *) ifp, p));
+ splx(s);
break;
}
Index: net/pfkey.c
===================================================================
RCS file: /cvs/src/sys/net/pfkey.c,v
retrieving revision 1.31
diff -u -p -r1.31 pfkey.c
--- net/pfkey.c 5 Sep 2016 15:12:30 -0000 1.31
+++ net/pfkey.c 18 Oct 2016 20:15:47 -0000
@@ -242,6 +242,8 @@ pfkey_usrreq(struct socket *socket, int
{
int rval;
+ splsoftassert(IPL_SOFTNET);
+
if ((socket->so_proto->pr_protocol > PFKEY_PROTOCOL_MAX) ||
(socket->so_proto->pr_protocol < 0) ||
!pfkey_versions[socket->so_proto->pr_protocol])
Index: net/raw_usrreq.c
===================================================================
RCS file: /cvs/src/sys/net/raw_usrreq.c,v
retrieving revision 1.25
diff -u -p -r1.25 raw_usrreq.c
--- net/raw_usrreq.c 8 Oct 2016 03:32:25 -0000 1.25
+++ net/raw_usrreq.c 18 Oct 2016 20:15:47 -0000
@@ -139,6 +139,8 @@ raw_usrreq(struct socket *so, int req, s
int error = 0;
int len, s;
+ splsoftassert(IPL_SOFTNET);
+
if (req == PRU_CONTROL)
return (EOPNOTSUPP);
if (control && control->m_len) {
Index: net/rtsock.c
===================================================================
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.208
diff -u -p -r1.208 rtsock.c
--- net/rtsock.c 18 Oct 2016 11:05:45 -0000 1.208
+++ net/rtsock.c 18 Oct 2016 20:15:47 -0000
@@ -152,6 +152,8 @@ route_usrreq(struct socket *so, int req,
int s, af;
int error = 0;
+ splsoftassert(IPL_SOFTNET);
+
s = splsoftnet();
rp = sotorawcb(so);
Index: netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.135
diff -u -p -r1.135 tcp_usrreq.c
--- netinet/tcp_usrreq.c 24 Sep 2016 14:51:37 -0000 1.135
+++ netinet/tcp_usrreq.c 18 Oct 2016 20:15:47 -0000
@@ -134,6 +134,8 @@ tcp_usrreq(struct socket *so, int req, s
int error = 0;
short ostate;
+ splsoftassert(IPL_SOFTNET);
+
if (req == PRU_CONTROL) {
#ifdef INET6
if (sotopf(so) == PF_INET6)
Index: netinet/udp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.219
diff -u -p -r1.219 udp_usrreq.c
--- netinet/udp_usrreq.c 3 Sep 2016 13:46:57 -0000 1.219
+++ netinet/udp_usrreq.c 18 Oct 2016 20:15:47 -0000
@@ -1112,6 +1112,8 @@ udp_usrreq(struct socket *so, int req, s
int error = 0;
int s;
+ splsoftassert(IPL_SOFTNET);
+
if (req == PRU_CONTROL) {
#ifdef INET6
if (sotopf(so) == PF_INET6)
Index: netinet6/raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.96
diff -u -p -r1.96 raw_ip6.c
--- netinet6/raw_ip6.c 19 Sep 2016 18:09:09 -0000 1.96
+++ netinet6/raw_ip6.c 18 Oct 2016 20:15:48 -0000
@@ -571,6 +571,8 @@ rip6_usrreq(struct socket *so, int req,
int s;
int priv;
+ splsoftassert(IPL_SOFTNET);
+
priv = 0;
if ((so->so_state & SS_PRIV) != 0)
priv++;