On Mon, Jul 03, 2017 at 02:41:15PM +0200, Martin Pieuchot wrote:
> I'd like to assert the socket lock is held when `so_qlen' is modified
> or when it is accessed as part of a sequence that needs atomicity.
>
> ok?
OK bluhm@
>
> Index: kern/uipc_socket2.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_socket2.c,v
> retrieving revision 1.80
> diff -u -p -r1.80 uipc_socket2.c
> --- kern/uipc_socket2.c 27 Jun 2017 12:02:43 -0000 1.80
> +++ kern/uipc_socket2.c 3 Jul 2017 12:34:18 -0000
> @@ -208,6 +208,7 @@ sonewconn(struct socket *head, int conns
> void
> soqinsque(struct socket *head, struct socket *so, int q)
> {
> + soassertlocked(head);
>
> #ifdef DIAGNOSTIC
> if (so->so_onq != NULL)
> @@ -228,9 +229,10 @@ soqinsque(struct socket *head, struct so
> int
> soqremque(struct socket *so, int q)
> {
> - struct socket *head;
> + struct socket *head = so->so_head;
> +
> + soassertlocked(head);
>
> - head = so->so_head;
> if (q == 0) {
> if (so->so_onq != &head->so_q0)
> return (0);
> Index: sys/socketvar.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/socketvar.h,v
> retrieving revision 1.70
> diff -u -p -r1.70 socketvar.h
> --- sys/socketvar.h 26 Jun 2017 09:32:32 -0000 1.70
> +++ sys/socketvar.h 3 Jul 2017 12:34:18 -0000
> @@ -199,11 +199,15 @@ sbspace(struct socket *so, struct sockbu
> ((so)->so_state & SS_ISSENDING)
>
> /* can we read something from so? */
> -#define soreadable(so) \
> - (!isspliced(so) && \
> - ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
> - ((so)->so_state & SS_CANTRCVMORE) || \
> - (so)->so_qlen || (so)->so_error))
> +static inline int
> +soreadable(struct socket *so)
> +{
> + soassertlocked(so);
> + if (isspliced(so))
> + return 0;
> + return (so->so_state & SS_CANTRCVMORE) || so->so_qlen || so->so_error ||
> + so->so_rcv.sb_cc >= so->so_rcv.sb_lowat;
> +}
>
> /* can we write something to so? */
> #define sowriteable(so) \