Re: NULL pointer dereference in pick_next_task_fair

Peter Zijlstra
2019-11-06T13:08:53Z

On Wed, Nov 06, 2019 at 01:05:25PM +0100, Peter Zijlstra wrote:
> On Mon, Oct 28, 2019 at 05:46:03PM +0000, Quentin Perret wrote:
> >
> > After digging a bit, the offending commit seems to be:
> >
> > 67692435c411 ("sched: Rework pick_next_task() slow-path")
> >
> > By 'offending' I mean that reverting it makes the issue go away. The
> > issue comes from the fact that pick_next_entity() returns a NULL se in
> > the 'simple' path of pick_next_task_fair(), which causes obvious
> > problems in the subsequent call to set_next_entity().
> >
> > I'll dig more, but if anybody understands the issue in the meatime feel
> > free to send me a patch to try out :)
>
> So for all those who didn't follow along on IRC, the below seems to cure
> things.
>
> The only thing I'm now considering is if we shouldn't be setting
> ->on_cpu=2 _before_ calling put_prev_task(). I'll go audit the RT/DL
> cases.

So I think it all works, but that's more by accident than anything else.
I'll move the ->on_cpu=2 assignment earlier. That clearly avoids calling
put_prev_task() while we're in put_prev_task().