1. 01 7月, 2021 1 次提交
    • V
      arch_topology: Avoid use-after-free for scale_freq_data · 83150f5d
      Viresh Kumar 提交于
      Currently topology_scale_freq_tick() (which gets called from
      scheduler_tick()) may end up using a pointer to "struct
      scale_freq_data", which was previously cleared by
      topology_clear_scale_freq_source(), as there is no protection in place
      here. The users of topology_clear_scale_freq_source() though needs a
      guarantee that the previously cleared scale_freq_data isn't used
      anymore, so they can free the related resources.
      
      Since topology_scale_freq_tick() is called from scheduler tick, we don't
      want to add locking in there. Use the RCU update mechanism instead
      (which is already used by the scheduler's utilization update path) to
      guarantee race free updates here.
      
      synchronize_rcu() makes sure that all RCU critical sections that started
      before it is called, will finish before it returns. And so the callers
      of topology_clear_scale_freq_source() don't need to worry about their
      callback getting called anymore.
      
      Cc: Paul E. McKenney <paulmck@kernel.org>
      Fixes: 01e055c1 ("arch_topology: Allow multiple entities to provide sched_freq_tick() callback")
      Tested-by: NVincent Guittot <vincent.guittot@linaro.org>
      Reviewed-by: NIonela Voinescu <ionela.voinescu@arm.com>
      Tested-by: NQian Cai <quic_qiancai@quicinc.com>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      83150f5d
  2. 12 3月, 2021 1 次提交
  3. 10 3月, 2021 2 次提交
  4. 08 10月, 2020 1 次提交
    • I
      cpufreq,arm,arm64: restructure definitions of arch_set_freq_scale() · a20b7053
      Ionela Voinescu 提交于
      Compared to other arch_* functions, arch_set_freq_scale() has an atypical
      weak definition that can be replaced by a strong architecture specific
      implementation.
      
      The more typical support for architectural functions involves defining
      an empty stub in a header file if the symbol is not already defined in
      architecture code. Some examples involve:
       - #define arch_scale_freq_capacity	topology_get_freq_scale
       - #define arch_scale_freq_invariant	topology_scale_freq_invariant
       - #define arch_scale_cpu_capacity	topology_get_cpu_scale
       - #define arch_update_cpu_topology	topology_update_cpu_topology
       - #define arch_scale_thermal_pressure	topology_get_thermal_pressure
       - #define arch_set_thermal_pressure	topology_set_thermal_pressure
      
      Bring arch_set_freq_scale() in line with these functions by renaming it to
      topology_set_freq_scale() in the arch topology driver, and by defining the
      arch_set_freq_scale symbol to point to the new function for arm and arm64.
      
      While there are other users of the arch_topology driver, this patch defines
      arch_set_freq_scale for arm and arm64 only, due to their existing
      definitions of arch_scale_freq_capacity. This is the getter function of the
      frequency invariance scale factor and without a getter function, the
      setter function - arch_set_freq_scale() has not purpose.
      Signed-off-by: NIonela Voinescu <ionela.voinescu@arm.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Acked-by: Sudeep Holla <sudeep.holla@arm.com> (BL_SWITCHER and topology parts)
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      a20b7053
  5. 02 10月, 2020 1 次提交
    • J
      drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions · aa838896
      Joe Perches 提交于
      Convert the various sprintf fmaily calls in sysfs device show functions
      to sysfs_emit and sysfs_emit_at for PAGE_SIZE buffer safety.
      
      Done with:
      
      $ spatch -sp-file sysfs_emit_dev.cocci --in-place --max-width=80 .
      
      And cocci script:
      
      $ cat sysfs_emit_dev.cocci
      @@
      identifier d_show;
      identifier dev, attr, buf;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	return
      -	sprintf(buf,
      +	sysfs_emit(buf,
      	...);
      	...>
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	return
      -	snprintf(buf, PAGE_SIZE,
      +	sysfs_emit(buf,
      	...);
      	...>
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	return
      -	scnprintf(buf, PAGE_SIZE,
      +	sysfs_emit(buf,
      	...);
      	...>
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      expression chr;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	return
      -	strcpy(buf, chr);
      +	sysfs_emit(buf, chr);
      	...>
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      identifier len;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	len =
      -	sprintf(buf,
      +	sysfs_emit(buf,
      	...);
      	...>
      	return len;
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      identifier len;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	len =
      -	snprintf(buf, PAGE_SIZE,
      +	sysfs_emit(buf,
      	...);
      	...>
      	return len;
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      identifier len;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      	len =
      -	scnprintf(buf, PAGE_SIZE,
      +	sysfs_emit(buf,
      	...);
      	...>
      	return len;
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      identifier len;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	<...
      -	len += scnprintf(buf + len, PAGE_SIZE - len,
      +	len += sysfs_emit_at(buf, len,
      	...);
      	...>
      	return len;
      }
      
      @@
      identifier d_show;
      identifier dev, attr, buf;
      expression chr;
      @@
      
      ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
      {
      	...
      -	strcpy(buf, chr);
      -	return strlen(buf);
      +	return sysfs_emit(buf, chr);
      }
      Signed-off-by: NJoe Perches <joe@perches.com>
      Link: https://lore.kernel.org/r/3d033c33056d88bbe34d4ddb62afd05ee166ab9a.1600285923.git.joe@perches.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa838896
  6. 19 9月, 2020 3 次提交
  7. 22 7月, 2020 1 次提交
    • V
      arch_topology, sched/core: Cleanup thermal pressure definition · 25980c7a
      Valentin Schneider 提交于
      The following commit:
      
        14533a16 ("thermal/cpu-cooling, sched/core: Move the arch_set_thermal_pressure() API to generic scheduler code")
      
      moved the definition of arch_set_thermal_pressure() to sched/core.c, but
      kept its declaration in linux/arch_topology.h. When building e.g. an x86
      kernel with CONFIG_SCHED_THERMAL_PRESSURE=y, cpufreq_cooling.c ends up
      getting the declaration of arch_set_thermal_pressure() from
      include/linux/arch_topology.h, which is somewhat awkward.
      
      On top of this, sched/core.c unconditionally defines
      o The thermal_pressure percpu variable
      o arch_set_thermal_pressure()
      
      while arch_scale_thermal_pressure() does nothing unless redefined by the
      architecture.
      
      arch_*() functions are meant to be defined by architectures, so revert the
      aforementioned commit and re-implement it in a way that keeps
      arch_set_thermal_pressure() architecture-definable, and doesn't define the
      thermal pressure percpu variable for kernels that don't need
      it (CONFIG_SCHED_THERMAL_PRESSURE=n).
      Signed-off-by: NValentin Schneider <valentin.schneider@arm.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/20200712165917.9168-2-valentin.schneider@arm.com
      25980c7a
  8. 18 3月, 2020 1 次提交
  9. 11 3月, 2020 2 次提交
  10. 07 3月, 2020 1 次提交
    • I
      arm64: use activity monitors for frequency invariance · cd0ed03a
      Ionela Voinescu 提交于
      The Frequency Invariance Engine (FIE) is providing a frequency
      scaling correction factor that helps achieve more accurate
      load-tracking.
      
      So far, for arm and arm64 platforms, this scale factor has been
      obtained based on the ratio between the current frequency and the
      maximum supported frequency recorded by the cpufreq policy. The
      setting of this scale factor is triggered from cpufreq drivers by
      calling arch_set_freq_scale. The current frequency used in computation
      is the frequency requested by a governor, but it may not be the
      frequency that was implemented by the platform.
      
      This correction factor can also be obtained using a core counter and a
      constant counter to get information on the performance (frequency based
      only) obtained in a period of time. This will more accurately reflect
      the actual current frequency of the CPU, compared with the alternative
      implementation that reflects the request of a performance level from
      the OS.
      
      Therefore, implement arch_scale_freq_tick to use activity monitors, if
      present, for the computation of the frequency scale factor.
      
      The use of AMU counters depends on:
       - CONFIG_ARM64_AMU_EXTN - depents on the AMU extension being present
       - CONFIG_CPU_FREQ - the current frequency obtained using counter
         information is divided by the maximum frequency obtained from the
         cpufreq policy.
      
      While it is possible to have a combination of CPUs in the system with
      and without support for activity monitors, the use of counters for
      frequency invariance is only enabled for a CPU if all related CPUs
      (CPUs in the same frequency domain) support and have enabled the core
      and constant activity monitor counters. In this way, there is a clear
      separation between the policies for which arch_set_freq_scale (cpufreq
      based FIE) is used, and the policies for which arch_scale_freq_tick
      (counter based FIE) is used to set the frequency scale factor. For
      this purpose, a late_initcall_sync is registered to trigger validation
      work for policies that will enable or disable the use of AMU counters
      for frequency invariance. If CONFIG_CPU_FREQ is not defined, the use
      of counters is enabled on all CPUs only if all possible CPUs correctly
      support the necessary counters.
      Signed-off-by: NIonela Voinescu <ionela.voinescu@arm.com>
      Reviewed-by: NLukasz Luba <lukasz.luba@arm.com>
      Acked-by: NSudeep Holla <sudeep.holla@arm.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NCatalin Marinas <catalin.marinas@arm.com>
      cd0ed03a
  11. 06 3月, 2020 2 次提交
  12. 17 1月, 2020 1 次提交
  13. 26 8月, 2019 1 次提交
  14. 23 7月, 2019 2 次提交
  15. 04 7月, 2019 1 次提交
  16. 25 6月, 2019 1 次提交
  17. 05 4月, 2019 1 次提交
    • L
      arch_topology: Make cpu_capacity sysfs node as read-only · 5d777b18
      Lingutla Chandrasekhar 提交于
      If user updates any cpu's cpu_capacity, then the new value is going to
      be applied to all its online sibling cpus. But this need not to be correct
      always, as sibling cpus (in ARM, same micro architecture cpus) would have
      different cpu_capacity with different performance characteristics.
      So, updating the user supplied cpu_capacity to all cpu siblings
      is not correct.
      
      And another problem is, current code assumes that 'all cpus in a cluster
      or with same package_id (core_siblings), would have same cpu_capacity'.
      But with commit '5bdd2b3f ("arm64: topology: add support to remove
      cpu topology sibling masks")', when a cpu hotplugged out, the cpu
      information gets cleared in its sibling cpus. So, user supplied
      cpu_capacity would be applied to only online sibling cpus at the time.
      After that, if any cpu hotplugged in, it would have different cpu_capacity
      than its siblings, which breaks the above assumption.
      
      So, instead of mucking around the core sibling mask for user supplied
      value, use device-tree to set cpu capacity. And make the cpu_capacity
      node as read-only to know the asymmetry between cpus in the system.
      While at it, remove cpu_scale_mutex usage, which used for sysfs write
      protection.
      Tested-by: NDietmar Eggemann <dietmar.eggemann@arm.com>
      Tested-by: NQuentin Perret <quentin.perret@arm.com>
      Reviewed-by: NQuentin Perret <quentin.perret@arm.com>
      Acked-by: NSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: NLingutla Chandrasekhar <clingutla@codeaurora.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5d777b18
  18. 10 9月, 2018 1 次提交
  19. 15 3月, 2018 1 次提交
    • G
      Revert "base: arch_topology: fix section mismatch build warnings" · 9de9a449
      Gaku Inami 提交于
      This reverts commit 452562ab ("base: arch_topology: fix section
      mismatch build warnings"). It causes the notifier call hangs in some
      use-cases.
      
      In some cases with using maxcpus, some of cpus are booted first and
      then the remaining cpus are booted. As an example, some users who want
      to realize fast boot up often use the following procedure.
      
        1) Define all CPUs on device tree (CA57x4 + CA53x4)
        2) Add "maxcpus=4" in bootargs
        3) Kernel boot up with CA57x4
        4) After kernel boot up, CA53x4 is booted from user
      
      When kernel init was finished, CPUFREQ_POLICY_NOTIFIER was not still
      unregisterd. This means that "__init init_cpu_capacity_callback()"
      will be called after kernel init sequence. To avoid this problem,
      it needs to remove __init{,data} annotations by reverting this commit.
      
      Also, this commit was needed to fix kernel compile issue below.
      However, this issue was also fixed by another patch: commit 82d8ba71
      ("arch_topology: Fix section miss match warning due to
      free_raw_capacity()") in v4.15 as well.
      Whereas commit 452562ab added all the missing __init annotations,
      commit 82d8ba71 removed it from free_raw_capacity().
      
      WARNING: vmlinux.o(.text+0x548f24): Section mismatch in reference
      from the function init_cpu_capacity_callback() to the variable
      .init.text:$x
      The function init_cpu_capacity_callback() references
      the variable __init $x.
      This is often because init_cpu_capacity_callback lacks a __init
      annotation or the annotation of $x is wrong.
      
      Fixes: 82d8ba71 ("arch_topology: Fix section miss match warning due to free_raw_capacity()")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGaku Inami <gaku.inami.xh@renesas.com>
      Reviewed-by: NDietmar Eggemann <dietmar.eggemann@arm.com>
      Tested-by: NDietmar Eggemann <dietmar.eggemann@arm.com>
      Acked-by: NSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9de9a449
  20. 08 12月, 2017 1 次提交
    • G
      drivers: core: arch_topology.c: move SPDX tag to top of the file · 6ee97d35
      Greg Kroah-Hartman 提交于
      arch_topology.c had a SPDX tag in it, so move it to the top of the file
      like the rest of the kernel files have it.
      
      Also remove the redundant license text as it is not needed if the SPDX
      tag is in the file, as the tag identifies the license in a specific and
      legally-defined manner.
      
      This is done on a quest to remove the 700+ different ways that files in
      the kernel describe the GPL license text.  And there's unneeded stuff
      like the address (sometimes incorrect) for the FSF which is never
      needed.
      
      No copyright headers or other non-license-description text was removed.
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6ee97d35
  21. 20 10月, 2017 1 次提交
  22. 03 10月, 2017 3 次提交
  23. 18 9月, 2017 1 次提交
    • S
      base: arch_topology: fix section mismatch build warnings · 452562ab
      Sudeep Holla 提交于
      Commit 2ef7a295 ("arm, arm64: factorize common cpu capacity default code")
      introduced init_cpu_capacity_callback and init_cpu_capacity_notifier
      which are referenced from initcall and are missing __init{,data}
      annotations resulting the below section mismatch build warnings.
      
      "WARNING: vmlinux.o(.text+0xbab790): Section mismatch in reference from
      the function init_cpu_capacity_callback() to the variable .init.text:$x
      The function init_cpu_capacity_callback() references the variable
      __init $x. This is often because init_cpu_capacity_callback lacks a
      __init annotation or the annotation of $x is wrong."
      
      This patch fixes the above build warnings by adding the required annotations.
      
      Fixes: 2ef7a295 ("arm, arm64: factorize common cpu capacity default code")
      Cc: Juri Lelli <juri.lelli@arm.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      452562ab
  24. 28 8月, 2017 1 次提交
  25. 17 7月, 2017 5 次提交
  26. 03 6月, 2017 3 次提交