Date: Thu, 23 May 2013 17:28:05 -0400 From: John Baldwin <jhb@freebsd.org> To: Guy Helmer <guy.helmer@gmail.com> Cc: freebsd-net@freebsd.org Subject: Re: bpf hold buffer in-use flag Message-ID: <201305231728.05253.jhb@freebsd.org> In-Reply-To: <4EA47178-7CE2-40CE-A767-2689FAF7BEBD@gmail.com> References: <9C928117-2230-4F01-9B95-B6D945AF4416@gmail.com> <201301091535.04904.jhb@freebsd.org> <4EA47178-7CE2-40CE-A767-2689FAF7BEBD@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, May 23, 2013 5:05:39 pm Guy Helmer wrote:
>
> On Jan 9, 2013, at 2:35 PM, John Baldwin <jhb@freebsd.org> wrote:
>
> > 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).
>
> Thanks for the feedback (sorry it's taken so long to get to it). Would this
> change correctly handle interruptions?
Yes.
> Index: bpf.c
> ===================================================================
> --- bpf.c (revision 250941)
> +++ bpf.c (working copy)
> @@ -856,9 +856,14 @@
> 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,
> + while (d->bd_hbuf_in_use) {
> + error = mtx_sleep(&d->bd_hbuf_in_use, &d->bd_lock,
> PRINET|PCATCH, "bd_hbuf", 0);
> + if (error == EINTR || error == ERESTART) {
> + BPFD_UNLOCK(d);
> + return (error);
> + }
> + }
Maybe simplify the check to just 'if (error != 0)'?
--
John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201305231728.05253.jhb>
