From owner-freebsd-net@FreeBSD.ORG Wed Jan 9 21:13:10 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4F61A882 for ; Wed, 9 Jan 2013 21:13:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 2EA70E4E for ; Wed, 9 Jan 2013 21:13:10 +0000 (UTC) Received: from pakbsde14.localnet (unknown [38.105.238.108]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 4FC78B91E; Wed, 9 Jan 2013 16:13:09 -0500 (EST) From: John Baldwin To: freebsd-net@freebsd.org Subject: Re: bpf hold buffer in-use flag Date: Wed, 9 Jan 2013 15:35:04 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p22; KDE/4.5.5; amd64; ; ) References: <9C928117-2230-4F01-9B95-B6D945AF4416@gmail.com> In-Reply-To: <9C928117-2230-4F01-9B95-B6D945AF4416@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201301091535.04904.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 09 Jan 2013 16:13:09 -0500 (EST) Cc: Guy Helmer X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 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, 09 Jan 2013 21:13:10 -0000 On Tuesday, November 13, 2012 4:40:57 pm Guy Helmer wrote: > To try to completely resolve the race in bpfread(), I have put together these changes to add a flag to indicate when the hold buffer cannot be modified because it is in use. Since it's my first time using mtx_sleep() and wakeup(), I wanted to run these past the list to see if I can get any feedback on the approach. > > > Index: bpf.c > =================================================================== > --- bpf.c (revision 242997) > +++ bpf.c (working copy) > @@ -819,6 +819,7 @@ bpfopen(struct cdev *dev, int flags, int fmt, stru > * particular buffer method. > */ > bpf_buffer_init(d); > + d->bd_hbuf_in_use = 0; > d->bd_bufmode = BPF_BUFMODE_BUFFER; > d->bd_sig = SIGIO; > d->bd_direction = BPF_D_INOUT; > @@ -872,6 +873,9 @@ bpfread(struct cdev *dev, struct uio *uio, int iof > callout_stop(&d->bd_callout); > timed_out = (d->bd_state == BPF_TIMED_OUT); > d->bd_state = BPF_IDLE; > + while (d->bd_hbuf_in_use) > + mtx_sleep(&d->bd_hbuf_in_use, &d->bd_lock, > + PRINET|PCATCH, "bd_hbuf", 0); You need to check the return value here, otherwise the PCATCH is useless (you will just go back to sleep instead of failing with an error if this is interrupted by a signal). -- John Baldwin