Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Oct 2014 12:39:39 -0700
From:      Adrian Chadd <adrian@freebsd.org>
To:        =?UTF-8?Q?Edward_Tomasz_Napiera=C5=82a?= <trasz@freebsd.org>
Cc:        "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, Mateusz Guzik <mjg@freebsd.org>, John Baldwin <jhb@freebsd.org>
Subject:   Re: svn commit: r273549 - head/sys/kern
Message-ID:  <CAJ-Vmo=teX0ggxDkjErA%2B_TwddedOsyeYXmkXv5pgB44d7ikBA@mail.gmail.com>
In-Reply-To: <20E7F407-9DC5-4A59-BC1C-7B868C31EF52@FreeBSD.org>
References:  <201410231535.s9NFZlbn002656@svn.freebsd.org> <201410231438.09220.jhb@freebsd.org> <20E7F407-9DC5-4A59-BC1C-7B868C31EF52@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Please back this out; it looks like the lock is protecting sf_si.


-adrian

On 23 October 2014 11:45, Edward Tomasz Napiera=C5=82a <trasz@freebsd.org> =
wrote:
> Dnia 23 pa=C5=BA 2014 o godz. 20:38 John Baldwin <jhb@freebsd.org> napisa=
=C5=82(a):
>
>>> On Thursday, October 23, 2014 11:35:47 am Mateusz Guzik wrote:
>>> Author: mjg
>>> Date: Thu Oct 23 15:35:47 2014
>>> New Revision: 273549
>>> URL: https://svnweb.freebsd.org/changeset/base/273549
>>>
>>> Log:
>>>  Avoid taking the lock in selfdfree when not needed.
>>>
>>> Modified:
>>>  head/sys/kern/sys_generic.c
>>>
>>> Modified: head/sys/kern/sys_generic.c
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
>>> --- head/sys/kern/sys_generic.c    Thu Oct 23 15:16:40 2014    (r273548=
)
>>> +++ head/sys/kern/sys_generic.c    Thu Oct 23 15:35:47 2014    (r273549=
)
>>> @@ -1600,10 +1600,11 @@ static void
>>> selfdfree(struct seltd *stp, struct selfd *sfp)
>>> {
>>>    STAILQ_REMOVE(&stp->st_selq, sfp, selfd, sf_link);
>>> -    mtx_lock(sfp->sf_mtx);
>>> -    if (sfp->sf_si)
>>> +    if (sfp->sf_si !=3D NULL) {
>>> +        mtx_lock(sfp->sf_mtx);
>>>        TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads);
>>> -    mtx_unlock(sfp->sf_mtx);
>>> +        mtx_unlock(sfp->sf_mtx);
>>> +    }
>>>    uma_zfree(selfd_zone, sfp);
>>
>> How do you ensure that the value you read for sf_si here is up to date? =
 In
>> particular, if a thread is selecting on multiple fds and one awakens it,
>> another fd can invoke selwakeup() while the thread is in seltdclear().
>> In that case, you might see a stale value of sf_si and not realize it is
>> cleared by the selwakeup() after you get the lock and you will invoke
>> TAILQ_REMOVE an extra time.
>
> FWIW, I've just hit a panic in selfdfree().
>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmo=teX0ggxDkjErA%2B_TwddedOsyeYXmkXv5pgB44d7ikBA>