Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jan 2010 10:52:27 +0100
From:      Attilio Rao <attilio@freebsd.org>
To:        Jeff Roberson <jroberson@jroberson.net>
Cc:        freebsd-current@freebsd.org, Kohji Okuno <okuno.kohji@jp.panasonic.com>
Subject:   Re: Bug about sched_4bsd?
Message-ID:  <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com>
In-Reply-To: <alpine.BSF.2.00.1001181544130.1027@desktop>
References:  <3bbf2fe11001171858o4568fe38l9b2db54ec9856b50@mail.gmail.com> <20100118.155352.59640143160034670.okuno.kohji@jp.panasonic.com> <3bbf2fe11001172306m69ff6544i3aaf05e2540136e1@mail.gmail.com> <20100119.103858.29593248145858473.okuno.kohji@jp.panasonic.com> <alpine.BSF.2.00.1001181544130.1027@desktop>

next in thread | previous in thread | raw e-mail | index | archive | help
2010/1/19 Jeff Roberson <jroberson@jroberson.net>:
> On Tue, 19 Jan 2010, Kohji Okuno wrote:
>
>> Hello, Attilio,
>>
>> I think setpriority() can set priority to sleeping threads.
>> Is it really safe?
>
> I agree, in this code path maybe_resched is not properly locking curthrea=
d.
> =C2=A0curthread will be sched_lock and the sleeping thread will be a slee=
pq lock.
> =C2=A0I believe that since &sched_lock is ordered after container locks i=
t would
> be sufficient to compare the two td_lock pointers and acquire sched_lock =
if
> they are not equal. =C2=A0Someone should look at other maybe_resched call=
ers or
> add an assert that curthread->td_lock is always &sched_lock in this
> function.

I'm not sure I understand you well here, but I generally don't agree,
if we speak about the current code plus the patch I posted.
Without the patch, there is a general problem of maybe_preempt()
because sched_switch() will handle TDF_NEEDRESCHED just in racy ways
(not ensuring atomicity of td_lock operations for sleeping threads).
That's, however, still not specific to maybe_preempt() only. However:
* If you make a problem about the callers of maybe_resched() I agree.
The callers should assert for sched_lock to be in place. But that is
not a general problem of maybe_resched(), it is on the callers
ballpark
* If you make a problem about the locking itself, the patch IMHO
should fix it or there is still something I can't see.

Thanks,
Attilio


--=20
Peace can only be achieved by understanding - A. Einstein



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3bbf2fe11001190152k15c24f70k876762817bf522c1>