mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Axtens <dja@axtens.net>
To: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
	Ben Segall <bsegall@google.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] sched/fair: WARN and refuse to set buddy when !se->on_rq
Date: Tue, 09 May 2017 11:47:17 +1000	[thread overview]
Message-ID: <87k25qreca.fsf@possimpible.ozlabs.ibm.com> (raw)
In-Reply-To: <CALYGNiMSo0UjgaQjw8sMkNdWxsB9v=A53Fo_+7pTX-En1pFQ=g@mail.gmail.com>

Konstantin Khlebnikov <koct9i@gmail.com> writes:

> On Mon, May 8, 2017 at 10:22 PM, Daniel Axtens <dja@axtens.net> wrote:
>> If we set a next or last buddy for a se that is not on_rq, we will
>> end up taking a NULL pointer dereference in wakeup_preempt_entity
>> via pick_next_task_fair.
>>
>> Detect when we would be about to do that, throw a warning and
>> then refuse to actually set it.
>>
>> This has been suggested at least twice[0][1]: just do it.
>>
>> [0] https://marc.info/?l=linux-kernel&m=146651668921468&w=2
>> [1] https://lkml.org/lkml/2016/6/16/663
>>
>> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
>> Cc: Ben Segall <bsegall@google.com>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Signed-off-by: Daniel Axtens <dja@axtens.net>
>>
>> ---
>>
>> I recently had to debug a problem with these (we hadn't backported
>> Konstantin's patches in this area) and this would have saved a lot
>> of time/pain.
>
> Yep, this is worth debug. But I think it should be under compile-time
> config option.
> Something like CONFIG_DEBUG_VM which enables VM_BUG_ON and VM_WARN_ON.

OK, will respin.

Regards,
Daniel

>
>> ---
>>  kernel/sched/fair.c | 10 ++++++++--
>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index d71109321841..9b988815b4ad 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -6168,8 +6168,11 @@ static void set_last_buddy(struct sched_entity *se)
>>         if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
>>                 return;
>>
>> -       for_each_sched_entity(se)
>> +       for_each_sched_entity(se) {
>> +               if (WARN_ON_ONCE(!se->on_rq))
>> +                       return;
>>                 cfs_rq_of(se)->last = se;
>> +       }
>>  }
>>
>>  static void set_next_buddy(struct sched_entity *se)
>> @@ -6177,8 +6180,11 @@ static void set_next_buddy(struct sched_entity *se)
>>         if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
>>                 return;
>>
>> -       for_each_sched_entity(se)
>> +       for_each_sched_entity(se) {
>> +               if (WARN_ON_ONCE(!se->on_rq))
>> +                       return;
>>                 cfs_rq_of(se)->next = se;
>> +       }
>>  }
>>
>>  static void set_skip_buddy(struct sched_entity *se)
>> --
>> 2.11.0
>>

  reply	other threads:[~2017-05-09  1:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08 19:22 Daniel Axtens
2017-05-08 19:32 ` Konstantin Khlebnikov
2017-05-09  1:47   ` Daniel Axtens [this message]
2017-05-09  6:45   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k25qreca.fsf@possimpible.ozlabs.ibm.com \
    --to=dja@axtens.net \
    --cc=bsegall@google.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=koct9i@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®