lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zio1gGgpl0FJ4qPg@yujie-X299>
Date: Thu, 25 Apr 2024 18:50:40 +0800
From: Yujie Liu <yujie.liu@...el.com>
To: Vincent Guittot <vincent.guittot@...aro.org>
CC: kernel test robot <lkp@...el.com>, <oe-kbuild-all@...ts.linux.dev>,
	<linux-kernel@...r.kernel.org>, <x86@...nel.org>, Ingo Molnar
	<mingo@...nel.org>, Qais Yousef <qyousef@...alina.io>, Lukasz Luba
	<lukasz.luba@....com>
Subject: Re: [tip:sched/core 26/27] drivers/base/arch_topology.c:204:17:
 sparse: sparse: incorrect type in initializer (different address spaces)

Hi Vincent,

On Thu, Apr 25, 2024 at 08:36:31AM +0200, Vincent Guittot wrote:
> Hi,
> 
> On Thu, 25 Apr 2024 at 01:22, kernel test robot <lkp@...el.com> wrote:
> >
> > Hi Vincent,
> >
> > FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.
> >
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
> > head:   97450eb909658573dcacc1063b06d3d08642c0c1
> > commit: d4dbc991714eefcbd8d54a3204bd77a0a52bd32d [26/27] sched/cpufreq: Rename arch_update_thermal_pressure() => arch_update_hw_pressure()
> 
> I'm going to look at this more deeply but this patch only rename
> "thermal_pressure" by "hw_pressure" so unless I miss a renaming, this
> should not trigger anything new.

Before renaming, there is a global "thermal_pressure", and a local
"th_pressure" inside topology_update_thermal_pressure function. They
live together peacefully since they have different names.

DEFINE_PER_CPU(unsigned long, thermal_pressure);
                              ^____

void topology_update_thermal_pressure(const struct cpumask *cpus,
                                      unsigned long capped_freq)
{
        unsigned long max_capacity, capacity, th_pressure;
                                              ^____
..
        for_each_cpu(cpu, cpus)
                WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
                                   ^____                   ^____
}

After renaming, the global and local variables are both given the same
name "hw_pressure", so the local one shadows the global one, causing
this sparse warning.

DEFINE_PER_CPU(unsigned long, hw_pressure);
                              ^___

void topology_update_hw_pressure(const struct cpumask *cpus,
                                      unsigned long capped_freq)
{
        unsigned long max_capacity, capacity, hw_pressure;
                                              ^___
..
        for_each_cpu(cpu, cpus)
                WRITE_ONCE(per_cpu(hw_pressure, cpu), hw_pressure);
                                   ^____              ^____
}


We can give them different names as before to fix this warning:

---------------------------------------------------------------

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 0248912ff6875..c66d070207a0e 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -179,7 +179,7 @@ DEFINE_PER_CPU(unsigned long, hw_pressure);
 void topology_update_hw_pressure(const struct cpumask *cpus,
                                      unsigned long capped_freq)
 {
-       unsigned long max_capacity, capacity, hw_pressure;
+       unsigned long max_capacity, capacity, pressure;
        u32 max_freq;
        int cpu;

@@ -196,12 +196,12 @@ void topology_update_hw_pressure(const struct cpumask *cpus,
        else
                capacity = mult_frac(max_capacity, capped_freq, max_freq);

-       hw_pressure = max_capacity - capacity;
+       pressure = max_capacity - capacity;

-       trace_hw_pressure_update(cpu, hw_pressure);
+       trace_hw_pressure_update(cpu, pressure);

        for_each_cpu(cpu, cpus)
-               WRITE_ONCE(per_cpu(hw_pressure, cpu), hw_pressure);
+               WRITE_ONCE(per_cpu(hw_pressure, cpu), pressure);
 }
 EXPORT_SYMBOL_GPL(topology_update_hw_pressure);

--

Thanks,
Yujie

> > config: arm64-randconfig-r132-20240425 (https://download.01.org/0day-ci/archive/20240425/202404250740.VhQQoD7N-lkp@intel.com/config)
> > compiler: aarch64-linux-gcc (GCC) 13.2.0
> > reproduce: (https://download.01.org/0day-ci/archive/20240425/202404250740.VhQQoD7N-lkp@intel.com/reproduce)
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@...el.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202404250740.VhQQoD7N-lkp@intel.com/
> >
> > sparse warnings: (new ones prefixed by >>)
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> > >> drivers/base/arch_topology.c:204:17: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void const [noderef] __percpu *__vpp_verify @@     got unsigned long * @@
> >    drivers/base/arch_topology.c:204:17: sparse:     expected void const [noderef] __percpu *__vpp_verify
> >    drivers/base/arch_topology.c:204:17: sparse:     got unsigned long *
> >
> > vim +204 drivers/base/arch_topology.c
> >
> >    164
> >    165  /**
> >    166   * topology_update_hw_pressure() - Update HW pressure for CPUs
> >    167   * @cpus        : The related CPUs for which capacity has been reduced
> >    168   * @capped_freq : The maximum allowed frequency that CPUs can run at
> >    169   *
> >    170   * Update the value of HW pressure for all @cpus in the mask. The
> >    171   * cpumask should include all (online+offline) affected CPUs, to avoid
> >    172   * operating on stale data when hot-plug is used for some CPUs. The
> >    173   * @capped_freq reflects the currently allowed max CPUs frequency due to
> >    174   * HW capping. It might be also a boost frequency value, which is bigger
> >    175   * than the internal 'capacity_freq_ref' max frequency. In such case the
> >    176   * pressure value should simply be removed, since this is an indication that
> >    177   * there is no HW throttling. The @capped_freq must be provided in kHz.
> >    178   */
> >    179  void topology_update_hw_pressure(const struct cpumask *cpus,
> >    180                                        unsigned long capped_freq)
> >    181  {
> >    182          unsigned long max_capacity, capacity, hw_pressure;
> >    183          u32 max_freq;
> >    184          int cpu;
> >    185
> >    186          cpu = cpumask_first(cpus);
> >    187          max_capacity = arch_scale_cpu_capacity(cpu);
> >    188          max_freq = arch_scale_freq_ref(cpu);
> >    189
> >    190          /*
> >    191           * Handle properly the boost frequencies, which should simply clean
> >    192           * the HW pressure value.
> >    193           */
> >    194          if (max_freq <= capped_freq)
> >    195                  capacity = max_capacity;
> >    196          else
> >    197                  capacity = mult_frac(max_capacity, capped_freq, max_freq);
> >    198
> >    199          hw_pressure = max_capacity - capacity;
> >    200
> >    201          trace_hw_pressure_update(cpu, hw_pressure);
> >    202
> >    203          for_each_cpu(cpu, cpus)
> >  > 204                  WRITE_ONCE(per_cpu(hw_pressure, cpu), hw_pressure);
> >    205  }
> >    206  EXPORT_SYMBOL_GPL(topology_update_hw_pressure);
> >    207
> >
> > --
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ