On Tue, Jun 06, 2017 at 05:15:40PM +0200, Martin Pieuchot wrote:
> TCP/UDP are almost ready to run without KERNEL_LOCK() because accesses
> to their sockets are serialized via the NET_LOCK(). On the other hand
> pfkey and routing sockets accesses still rely on the KERNEL_LOCK().
>
> Since we're going to work at the socket layer, first to remove the
> KERNEL_LOCK() from routing/pfkey sockets then to split the NET_LOCK(),
> we need some tooling to move faster and avoid mistakes.
>
> Currently all operations on socket buffers are protected by these
> locks. I'd like to assert that, at least for all functions used in
> TCP/UDP layers.
>
> The idea is to later change the lock asserted in soassertlocked().
>
> Comments, ok?
Good idea, mostly OK.
> @@ -1058,7 +1058,9 @@ sorflush(struct socket *so)
> }
> if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
> (*pr->pr_domain->dom_dispose)(asb.sb_mb);
> - sbrelease(&asb);
> + *sb = asb;
> + sbrelease(so, sb);
> + memset(sb, 0, sizeof (*sb));
> }
A few lines above we have
/* XXX - the memset stomps all over so_rcv */
if (asb.sb_flags & SB_KNOTE) {
sb->sb_sel.si_note = asb.sb_sel.si_note;
sb->sb_flags = SB_KNOTE;
}
I think this has to be redone after your memset() as the socket is
still used after a soshutdown().
> @@ -1270,7 +1272,7 @@ somove(struct socket *so, int wait)
> maxreached = 1;
> }
> }
> - space = sbspace(&sosp->so_snd);
> + space = sbspace(so, &sosp->so_snd);
> if (so->so_oobmark && so->so_oobmark < len &&
> so->so_oobmark < space + 1024)
> space += 1024;
This must be sosp.
+ space = sbspace(sosp, &sosp->so_snd);
> -sbappendstream(struct sockbuf *sb, struct mbuf *m)
> +sbappendstream(struct socket *so, struct sockbuf *sb, struct mbuf *m)
> -sbappendaddr(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0,
> +sbappendaddr(struct socket *so, struct sockbuf *sb, struct sockaddr *asa,
> -sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control)
> +sbappendcontrol(struct socket *so, struct sockbuf *sb, struct mbuf *m0,
Should we also change sbappendrecord() and sbappend() ?
> /* can we write something to so? */
> #define sowriteable(so) \
> - ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
> + ((sbspace(so, &(so)->so_snd) >= (so)->so_snd.sb_lowat && \
> (((so)->so_state & SS_ISCONNECTED) || \
> ((so)->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || \
> ((so)->so_state & SS_CANTSENDMORE) || (so)->so_error)
You need () around marco arguments.
+ ((sbspace((so), &(so)->so_snd) >= (so)->so_snd.sb_lowat && \
bluhm