public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Peilin He <peilinhe2020@163.com>
Cc: bsegall@google.com, dietmar.eggemann@arm.com, fan.yu9@zte.com.cn,
	he.peilin@zte.com.cn, jiang.kun2@zte.com.cn,
	juri.lelli@redhat.com, linux-kernel@vger.kernel.org,
	liu.chun2@zte.com.cn, mgorman@suse.de, mingo@redhat.com,
	rostedt@goodmis.org, tu.qiang35@zte.com.cn,
	vincent.guittot@linaro.org, xu.xin16@zte.com.cn,
	yang.yang29@zte.com.cn, zhang.yunkai@zte.com.cn
Subject: Re: Re: [PATCH linux-next v2] sched/core: Add WARN() to check overflow in migrate_disable()
Date: Fri, 5 Jul 2024 09:56:09 +0200	[thread overview]
Message-ID: <20240705075609.GY11386@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240705054132.108523-1-peilinhe2020@163.com>

On Fri, Jul 05, 2024 at 05:41:32AM +0000, Peilin He wrote:
> > How about we do something like this?
> >
> > ---
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 7a5ea8fc8abb..06a559532ed6 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -2237,6 +2237,12 @@ void migrate_disable(void)
> >  
> >      if (p->migration_disabled) {
> >          p->migration_disabled++;
> > +#ifdef CONFIG_DEBUG_PREEMPT
> > +        /*
> > +         * Warn about overflow half-way through the range.
> > +         */
> > +        WARN_ON_ONCE((s16)p->migration_disabled < 0);
> > +#endif
> >          return;
> >      }
> 
> Agreed, converting p->migration_disabled to a signed number 
> will detect overflow occurrences earlier than our current method.
> 
> > @@ -2254,14 +2260,20 @@ void migrate_enable(void)
> >          .flags     = SCA_MIGRATE_ENABLE,
> >      };
> >  
> > +#ifdef CONFIG_DEBUG_PREEMPT
> > +    /*
> > +     * Check both overflow from migrate_disable() and superfluous
> > +     * migrate_enable().
> > +     */
> > +    if (WARN_ON_ONCE((s16)p->migration_disabled <= 0))
> > +        return;
> > +#endif
> > +
> >      if (p->migration_disabled > 1) {
> >          p->migration_disabled--;
> >          return;
> >      }
> >  
> > -    if (WARN_ON_ONCE(!p->migration_disabled))
> > -        return;
> > -
> >      /*
> >       * Ensure stop_task runs either before or after this, and that
> >       * __set_cpus_allowed_ptr(SCA_MIGRATE_ENABLE) doesn't schedule().
> 
> Agreed, similarly checking for overflow in p->migration_disabled 
> within migrate_enable is fine, but placing WARN_ON_ONCE inside 
> the CONFIG_DEBUG_PREEMPT macro may cause return logic deviations. 
> It is recommended to support WARN_ON_ONCE as a standard feature.

It is debug stuff, it should only be needed for debug builds. Same as
the preemption things, they also only check for overflow on debug
builds.

      reply	other threads:[~2024-07-05  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03 12:53 [PATCH linux-next v2] sched/core: Add WARN() to check overflow in migrate_disable() xu.xin16
2024-07-04 13:47 ` Peter Zijlstra
2024-07-05  5:41   ` Peilin He
2024-07-05  7:56     ` Peter Zijlstra [this message]

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=20240705075609.GY11386@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=fan.yu9@zte.com.cn \
    --cc=he.peilin@zte.com.cn \
    --cc=jiang.kun2@zte.com.cn \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liu.chun2@zte.com.cn \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peilinhe2020@163.com \
    --cc=rostedt@goodmis.org \
    --cc=tu.qiang35@zte.com.cn \
    --cc=vincent.guittot@linaro.org \
    --cc=xu.xin16@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    --cc=zhang.yunkai@zte.com.cn \
    /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