From owner-freebsd-net@FreeBSD.ORG Wed Feb 26 23:53:04 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C5B88EB8 for ; Wed, 26 Feb 2014 23:53:04 +0000 (UTC) Received: from mx2.netapp.com (mx2.netapp.com [216.240.18.37]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8BACE1AE8 for ; Wed, 26 Feb 2014 23:53:04 +0000 (UTC) X-IronPort-AV: E=Sophos;i="4.97,551,1389772800"; d="scan'208";a="73327679" Received: from vmwexceht01-prd.hq.netapp.com ([10.106.76.239]) by mx2-out.netapp.com with ESMTP; 26 Feb 2014 15:52:49 -0800 Received: from SACEXCMBX03-PRD.hq.netapp.com ([169.254.5.58]) by vmwexceht01-prd.hq.netapp.com ([10.106.76.239]) with mapi id 14.03.0123.003; Wed, 26 Feb 2014 15:52:50 -0800 From: "Son, Sonny" To: John-Mark Gurney Subject: RE: socket lock Thread-Topic: socket lock Thread-Index: Ac8zQCCXLObL7+kFTXuTI0rB9CfzMwASIJkAABCsxeA= Date: Wed, 26 Feb 2014 23:52:48 +0000 Message-ID: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C43F@SACEXCMBX03-PRD.hq.netapp.com> References: <3967D1AB1B4E6F4CA4E2329EEB83ED3E30D8C3A7@SACEXCMBX03-PRD.hq.netapp.com> <20140226225336.GG92037@funkthat.com> In-Reply-To: <20140226225336.GG92037@funkthat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.106.53.53] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "freebsd-net \(freebsd-net@freebsd.org\)" X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Feb 2014 23:53:04 -0000 Thanks John-Mark. That explains. I will do more research and bug you guys a= gain if I need help. Regards... -----Original Message----- From: John-Mark Gurney [mailto:jmg@funkthat.com]=20 Sent: Wednesday, February 26, 2014 2:54 PM To: Son, Sonny Cc: freebsd-net (freebsd-net@freebsd.org) Subject: Re: socket lock 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 withou= t lock in some places. As an instance, the following code reads and/or modi= fies 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=20 > *td) { [...] > if (so->so_error) { > error =3D so->so_error; > so->so_error =3D 0; <=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D we do have socket's send buffer lock but not socket lock (, which is so= cket 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 s= omething like u_register_t, but not sure about this... --=20 John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."