All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qais Yousef <qyousef@layalina.io>
To: Dan Carpenter <error27@gmail.com>
Cc: oe-kbuild@lists.linux.dev, Qais Yousef <qais.yousef@arm.com>,
	lkp@intel.com, oe-kbuild-all@lists.linux.dev,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [tip:sched/core 3/19] kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_min'.
Date: Sun, 20 Nov 2022 20:45:36 +0000	[thread overview]
Message-ID: <20221120204536.ei2st4yv76lboe6x@airbuntu> (raw)
In-Reply-To: <Y3H7AcgnGMq5p+nn@kadam>

On 11/14/22 11:23, Dan Carpenter wrote:
> On Sat, Nov 12, 2022 at 05:47:05PM +0000, Qais Yousef wrote:
> > On 11/12/22 13:16, Dan Carpenter wrote:
> > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
> > > head:   52b33d87b9197c51e8ffdc61873739d90dd0a16f
> > > commit: 244226035a1f9b2b6c326e55ae5188fab4f428cb [3/19] sched/uclamp: Fix fits_capacity() check in feec()
> > > config: riscv-randconfig-m031-20221111
> > > compiler: riscv64-linux-gcc (GCC) 12.1.0
> > > 
> > > If you fix the issue, kindly add following tag where applicable
> > > | Reported-by: kernel test robot <lkp@intel.com>
> > > | Reported-by: Dan Carpenter <error27@gmail.com>
> > > 
> > > smatch warnings:
> > > kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_min'.
> > > kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_max'.
> > > 
> > > vim +/util_min +7263 kernel/sched/fair.c
> > 
> > [...]
> > 
> > > util_min/max not initialized if uclamp_is_used() is false.  (I thought
> > > I had reported this earlier but I don't see it on vger).
> > 
> > Thanks Dan!
> > 
> > It's harmless since util_min/max are ignored in util_fits_cpu() too;
> > uclamp_is_used() is checked there as well.
> > 
> > I couldn't reproduce, I need to get GCC 12.1.0, but the below ought to cure it.
> > Let me test it a bit more and send a patch.
> 
> In that case it's fine.  This is inlined.  I guess, generally, we are
> going to only consider passing uninitialized variables to functions as
> bugs when the functions are not inlined.  I believe that one of the
> KMsan things will trigger a warning at runtime for this as well but it's
> the same situation, where it's considered a false positive because it's
> inlined.  (Technically it's undefined behavior either way according to
> the C standard, but the standard is sometimes useless).
> 
> It's not a GCC warning, it's from Smatch.
> 
> GCC uninitialized warnings were disabled by defualt because they have
> too many false positives.  Use "make W=2" to enable them.  GCC will
> complain.

Thanks Dan. I could reproduce it a while ago and I have the full patch below
- but I couldn't run it on real hardware just to do some sanity check and it
seems I'll have to wait for a while longer.

Putting it down here in case Peter fancies picking it up. I'll be posting it
along with other fixes in this area as soon as I get chance to run them
somewhere.


Cheers

--
Qais Yousef


--->8----

commit 8539b7d7b9e3c3bb6d817cbbd5be002f80f6eb31
Author: Qais Yousef <qyousef@layalina.io>
Date:   Sat Nov 19 23:12:34 2022 +0000

    sched/uclamp: Fix a uninitialized variable warnings
    
    Addresses the following warnings:
    
    > config: riscv-randconfig-m031-20221111
    > compiler: riscv64-linux-gcc (GCC) 12.1.0
    >
    > smatch warnings:
    > kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_min'.
    > kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_max'.
    
    Reported-by: kernel test robot <lkp@intel.com>
    Reported-by: Dan Carpenter <error27@gmail.com>
    Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io>

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4cc56c91e06e..89dadaafc1ec 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7217,10 +7217,10 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
 	eenv_task_busy_time(&eenv, p, prev_cpu);
 
 	for (; pd; pd = pd->next) {
+		unsigned long util_min = p_util_min, util_max = p_util_max;
 		unsigned long cpu_cap, cpu_thermal_cap, util;
 		unsigned long cur_delta, max_spare_cap = 0;
 		unsigned long rq_util_min, rq_util_max;
-		unsigned long util_min, util_max;
 		unsigned long prev_spare_cap = 0;
 		int max_spare_cap_cpu = -1;
 		unsigned long base_energy;
@@ -7258,10 +7258,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
 			 * aligned with sched_cpu_util().
 			 */
 			if (uclamp_is_used()) {
-				if (uclamp_rq_is_idle(cpu_rq(cpu))) {
-					util_min = p_util_min;
-					util_max = p_util_max;
-				} else {
+				if (!uclamp_rq_is_idle(cpu_rq(cpu))) {
 					/*
 					 * Open code uclamp_rq_util_with() except for
 					 * the clamp() part. Ie: apply max aggregation

      reply	other threads:[~2022-11-20 20:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12  9:33 [tip:sched/core 3/19] kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_min' kernel test robot
2022-11-12 10:16 ` Dan Carpenter
2022-11-12 17:47 ` Qais Yousef
2022-11-14  8:23   ` Dan Carpenter
2022-11-20 20:45     ` Qais Yousef [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=20221120204536.ei2st4yv76lboe6x@airbuntu \
    --to=qyousef@layalina.io \
    --cc=error27@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=qais.yousef@arm.com \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.