From owner-freebsd-smp Wed May 8 4:59:15 2002 Delivered-To: freebsd-smp@freebsd.org Received: from rina.r.dl.itc.u-tokyo.ac.jp (rina.r.dl.itc.u-tokyo.ac.jp [133.11.199.247]) by hub.freebsd.org (Postfix) with ESMTP id D07B637B401; Wed, 8 May 2002 04:59:08 -0700 (PDT) Received: from rina.r.dl.itc.u-tokyo.ac.jp (localhost [127.0.0.1]) by rina.r.dl.itc.u-tokyo.ac.jp (8.12.3+3.5Wbeta/3.7W-rina.r-Nankai-Koya) with ESMTP id g48Bx63i045654 ; Wed, 8 May 2002 20:59:06 +0900 (JST) Message-Id: <200205081159.g48Bx63i045654@rina.r.dl.itc.u-tokyo.ac.jp> Date: Wed, 08 May 2002 20:59:06 +0900 From: Seigo Tanimura To: current@FreeBSD.org, smp@FreeBSD.org Cc: Seigo Tanimura Subject: The updated socket patch and axing sotryfree() (Re: Locking down a socket, milestone 1) In-Reply-To: <200204241110.g3OB8u8t006194@bunko> References: <200204241110.g3OB8u8t006194@bunko> User-Agent: Wanderlust/2.8.1 (Something) SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (=?ISO-8859-1?Q?Unebigory=F2mae?=) APEL/10.3 MULE XEmacs/21.1 (patch 14) (Cuyahoga Valley) (i386--freebsd) Organization: Digital Library Research Division, Information Techinology Centre, The University of Tokyo MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Wed, 24 Apr 2002 20:08:56 +0900, Seigo Tanimura said: tanimura> I am now working on locking down a socket. (I have heard that Jeffrey tanimura> Hsu is also doing that, but I have never seen his patch. Has anyone tanimura> seen that?) My first milestone patch is now available at: I updated the patch slightly, found at http://people.FreeBSD.org/~tanimura/patches/socket_milestone1b.diff.gz tanimura> The works I have done so far are: tanimura> - Determine the lock required to protect each of the members in struct tanimura> socket. tanimura> - Add mutexes to each of the sockbufs in a socket as BSD/OS does. tanimura> - Lock down so_count, so_options, so_linger and so_state. tanimura> - Add a global mutex socq_lock to protect the connection queues of a tanimura> listening socket. Lock socq_lock to lock two sockets at once, tanimura> followed by enqueuing or dequeuing a socket, or moving a socket across tanimura> queues. socq_lock is not an sx lock because we usually have to lock tanimura> two sockets to modify them. This is reverted. I cleaned up soisconnected() to avoid locking two sockets at once. *_locked() functions and macros no longer exist. The following functions and macros require a socket lock: o soref(), sorele(), sotryfree() o so[rw]wakeup() I would like to commit this patch in one or two weeks to start working on a possible race between a user process and a netisr kthread, prevented by only the Giant lock at the moment. When a user process calls sofree() for a listening socket, it attempts to free the sockets in the connection queues by soabort(). If the connection of an aborting socket gets dropped by a remote host (eg by TCP RST), a netisr kthread also attempts to free the socket. Since the reference count of a socket in a connection queue is zero, this would resust in doubly freeing a socket. To solve that problem, I would like to axe sotryfree(). The PCB of a socket and a connection queue should hold a reference to the socket. This should make the reference count of an alive socket always be >= 1, and ensure that there is only one referer to a socket to be freed. Comments? -- Seigo Tanimura To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message