Date: Wed, 26 Feb 2014 14:53:36 -0800 From: John-Mark Gurney <jmg@funkthat.com> To: "Son, Sonny" <Sonny.Son@netapp.com> Cc: "freebsd-net \(freebsd-net@freebsd.org\)" <freebsd-net@freebsd.org> Subject: Re: socket lock Message-ID: <20140226225336.GG92037@funkthat.com> In-Reply-To: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C3A7@SACEXCMBX03-PRD.hq.netapp.com> References: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C3A7@SACEXCMBX03-PRD.hq.netapp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Son, Sonny wrote this message on Wed, Feb 26, 2014 at 22:47 +0000: > Can somebody explain me how socket data structure-i.e. 'struct socket'-is protected in FreeBSD? It seems that socket is accessed and modified without lock in some places. As an instance, the following code reads and/or modifies various socket fields including so_error without socket lock held: Have you seen this in sys/socketvar.h? /*- * Locking key to struct socket: * (a) constant after allocation, no locking required. * (b) locked by SOCK_LOCK(so). * (c) locked by SOCKBUF_LOCK(&so->so_rcv). * (d) locked by SOCKBUF_LOCK(&so->so_snd). * (e) locked by ACCEPT_LOCK(). * (f) not locked since integer reads/writes are atomic. * (g) used only as a sleep/wakeup address, no value. * (h) locked by global mutex so_global_mtx. */ > int > sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, > struct mbuf *top, struct mbuf *control, int flags, struct thread *td) > { [...] > if (so->so_error) { > error = so->so_error; > so->so_error = 0; <=========== we do have socket's send buffer lock but not socket lock (, which is socket recv buffer lock) > SOCKBUF_UNLOCK(&so->so_snd); > goto out; > } So, so_error is: u_short so_error; /* (f) error affecting connection */ and f is: * (f) not locked since integer reads/writes are atomic. Though, I'm not so sure u_short counts as an integer.. it maybe should be something like u_register_t, but not sure about this... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140226225336.GG92037>