Re: [ammarfaizi2-block:akpm/mm/mm-nonmm-unstable 50/50] kernel/smpboot.c:435:6: warning: variable 'oldstate' is used uninitialized whenever 'if' condition is true

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 25, 2022 at 6:30 AM kernel test robot <lkp@xxxxxxxxx> wrote:
>
> Hi Uros,
>
> FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.

No, the warning is correct, and although my compiler didn't emit the
warning, the variable is indeed uninitialized.

The patched kernel worked for me and I was not careful enough to find
all incoming edges to the label.

Attached is an incremental patch I am testing, will send it later
today as a proper patch.

Uros.

> tree:   https://github.com/ammarfaizi2/linux-block akpm/mm/mm-nonmm-unstable
> head:   2d1e07c7534c14e56ac3818fa24e7c1643a9b1dc
> commit: 2d1e07c7534c14e56ac3818fa24e7c1643a9b1dc [50/50] smpboot: use atomic_try_cmpxchg in cpu_wait_death and cpu_report_death
> config: x86_64-randconfig-a003 (https://download.01.org/0day-ci/archive/20220825/202208251224.teVMa7Yy-lkp@xxxxxxxxx/config)
> compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/ammarfaizi2/linux-block/commit/2d1e07c7534c14e56ac3818fa24e7c1643a9b1dc
>         git remote add ammarfaizi2-block https://github.com/ammarfaizi2/linux-block
>         git fetch --no-tags ammarfaizi2-block akpm/mm/mm-nonmm-unstable
>         git checkout 2d1e07c7534c14e56ac3818fa24e7c1643a9b1dc
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
>
> All warnings (new ones prefixed by >>):
>
> >> kernel/smpboot.c:435:6: warning: variable 'oldstate' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (atomic_read(&per_cpu(cpu_hotplug_state, cpu)) == CPU_DEAD)
>                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    kernel/smpboot.c:449:6: note: uninitialized use occurs here
>            if (oldstate == CPU_DEAD) {
>                ^~~~~~~~
>    kernel/smpboot.c:435:2: note: remove the 'if' if its condition is always false
>            if (atomic_read(&per_cpu(cpu_hotplug_state, cpu)) == CPU_DEAD)
>            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    kernel/smpboot.c:428:14: note: initialize the variable 'oldstate' to silence this warning
>            int oldstate;
>                        ^
>                         = 0
>    1 warning generated.
>
>
> vim +435 kernel/smpboot.c
>
> 8038dad7e88858 Paul E. McKenney 2015-02-25  421
> 8038dad7e88858 Paul E. McKenney 2015-02-25  422  /*
> 8038dad7e88858 Paul E. McKenney 2015-02-25  423   * Wait for the specified CPU to exit the idle loop and die.
> 8038dad7e88858 Paul E. McKenney 2015-02-25  424   */
> 8038dad7e88858 Paul E. McKenney 2015-02-25  425  bool cpu_wait_death(unsigned int cpu, int seconds)
> 8038dad7e88858 Paul E. McKenney 2015-02-25  426  {
> 8038dad7e88858 Paul E. McKenney 2015-02-25  427         int jf_left = seconds * HZ;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  428         int oldstate;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  429         bool ret = true;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  430         int sleep_jf = 1;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  431
> 8038dad7e88858 Paul E. McKenney 2015-02-25  432         might_sleep();
> 8038dad7e88858 Paul E. McKenney 2015-02-25  433
> 8038dad7e88858 Paul E. McKenney 2015-02-25  434         /* The outgoing CPU will normally get done quite quickly. */
> 8038dad7e88858 Paul E. McKenney 2015-02-25 @435         if (atomic_read(&per_cpu(cpu_hotplug_state, cpu)) == CPU_DEAD)
> 8038dad7e88858 Paul E. McKenney 2015-02-25  436                 goto update_state;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  437         udelay(5);
> 8038dad7e88858 Paul E. McKenney 2015-02-25  438
> 8038dad7e88858 Paul E. McKenney 2015-02-25  439         /* But if the outgoing CPU dawdles, wait increasingly long times. */
> 8038dad7e88858 Paul E. McKenney 2015-02-25  440         while (atomic_read(&per_cpu(cpu_hotplug_state, cpu)) != CPU_DEAD) {
> 8038dad7e88858 Paul E. McKenney 2015-02-25  441                 schedule_timeout_uninterruptible(sleep_jf);
> 8038dad7e88858 Paul E. McKenney 2015-02-25  442                 jf_left -= sleep_jf;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  443                 if (jf_left <= 0)
> 8038dad7e88858 Paul E. McKenney 2015-02-25  444                         break;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  445                 sleep_jf = DIV_ROUND_UP(sleep_jf * 11, 10);
> 8038dad7e88858 Paul E. McKenney 2015-02-25  446         }
> 8038dad7e88858 Paul E. McKenney 2015-02-25  447         oldstate = atomic_read(&per_cpu(cpu_hotplug_state, cpu));
> 2d1e07c7534c14 Uros Bizjak      2022-08-23  448  update_state:
> 8038dad7e88858 Paul E. McKenney 2015-02-25  449         if (oldstate == CPU_DEAD) {
> 8038dad7e88858 Paul E. McKenney 2015-02-25  450                 /* Outgoing CPU died normally, update state. */
> 8038dad7e88858 Paul E. McKenney 2015-02-25  451                 smp_mb(); /* atomic_read() before update. */
> 8038dad7e88858 Paul E. McKenney 2015-02-25  452                 atomic_set(&per_cpu(cpu_hotplug_state, cpu), CPU_POST_DEAD);
> 8038dad7e88858 Paul E. McKenney 2015-02-25  453         } else {
> 8038dad7e88858 Paul E. McKenney 2015-02-25  454                 /* Outgoing CPU still hasn't died, set state accordingly. */
> 2d1e07c7534c14 Uros Bizjak      2022-08-23  455                 if (!atomic_try_cmpxchg(&per_cpu(cpu_hotplug_state, cpu),
> 2d1e07c7534c14 Uros Bizjak      2022-08-23  456                                         &oldstate, CPU_BROKEN))
> 8038dad7e88858 Paul E. McKenney 2015-02-25  457                         goto update_state;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  458                 ret = false;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  459         }
> 8038dad7e88858 Paul E. McKenney 2015-02-25  460         return ret;
> 8038dad7e88858 Paul E. McKenney 2015-02-25  461  }
> 8038dad7e88858 Paul E. McKenney 2015-02-25  462
>
> :::::: The code at line 435 was first introduced by commit
> :::::: 8038dad7e888581266c76df15d70ca457a3c5910 smpboot: Add common code for notification from dying CPU
>
> :::::: TO: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
> :::::: CC: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
>
> --
> 0-DAY CI Kernel Test Service
> https://01.org/lkp
From 29c419f9c27677a4842fe2aef36dcf44b4321dfe Mon Sep 17 00:00:00 2001
From: Uros Bizjak <ubizjak@xxxxxxxxx>
Date: Thu, 25 Aug 2022 08:09:44 +0200
Subject: [PATCH] smpboot: Fix cpu_wait_death for early cpu death

Fix uninitialized variable in case cpu dies early.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
---
 kernel/smpboot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/smpboot.c b/kernel/smpboot.c
index f3cf1a9a8b44..2c7396da470c 100644
--- a/kernel/smpboot.c
+++ b/kernel/smpboot.c
@@ -433,7 +433,7 @@ bool cpu_wait_death(unsigned int cpu, int seconds)
 
 	/* The outgoing CPU will normally get done quite quickly. */
 	if (atomic_read(&per_cpu(cpu_hotplug_state, cpu)) == CPU_DEAD)
-		goto update_state;
+		goto update_state_early;
 	udelay(5);
 
 	/* But if the outgoing CPU dawdles, wait increasingly long times. */
@@ -444,6 +444,7 @@ bool cpu_wait_death(unsigned int cpu, int seconds)
 			break;
 		sleep_jf = DIV_ROUND_UP(sleep_jf * 11, 10);
 	}
+update_state_early:
 	oldstate = atomic_read(&per_cpu(cpu_hotplug_state, cpu));
 update_state:
 	if (oldstate == CPU_DEAD) {
-- 
2.31.1


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux