1. 08 5月, 2015 5 次提交
  2. 03 4月, 2015 1 次提交
    • V
      cpufreq: Schedule work for the first-online CPU on resume · c75de0ac
      Viresh Kumar 提交于
      All CPUs leaving the first-online CPU are hotplugged out on suspend and
      and cpufreq core stops managing them.
      
      On resume, we need to call cpufreq_update_policy() for this CPU's policy
      to make sure its frequency is in sync with cpufreq's cached value, as it
      might have got updated by hardware during suspend/resume.
      
      The policies are always added to the top of the policy-list. So, in
      normal circumstances, CPU 0's policy will be the last one in the list.
      And so the code checks for the last policy.
      
      But there are cases where it will fail. Consider quad-core system, with
      policy-per core. If CPU0 is hotplugged out and added back again, the
      last policy will be on CPU1 :(
      
      To fix this in a proper way, always look for the policy of the first
      online CPU. That way we will be sure that we are calling
      cpufreq_update_policy() for the only CPU that wasn't hotplugged out.
      
      Cc: 3.15+ <stable@vger.kernel.org> # 3.15+
      Fixes: 2f0aea93 ("cpufreq: suspend governors on system suspend/hibernate")
      Reported-by: NSaravana Kannan <skannan@codeaurora.org>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      Acked-by: NSaravana Kannan <skannan@codeaurora.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      c75de0ac
  3. 04 2月, 2015 3 次提交
  4. 03 2月, 2015 1 次提交
    • V
      cpufreq: Set cpufreq_cpu_data to NULL before putting kobject · 6ffae8c0
      Viresh Kumar 提交于
      In __cpufreq_remove_dev_finish(), per-cpu 'cpufreq_cpu_data' needs
      to be cleared before calling kobject_put(&policy->kobj) and under
      cpufreq_driver_lock. Otherwise, if someone else calls cpufreq_cpu_get()
      in parallel with it, they can obtain a non-NULL policy from that after
      kobject_put(&policy->kobj) was executed.
      
      Consider this case:
      
      Thread A				Thread B
      cpufreq_cpu_get()
        acquire cpufreq_driver_lock
        read-per-cpu cpufreq_cpu_data
      					kobject_put(&policy->kobj);
        kobject_get(&policy->kobj);
      					...
      					per_cpu(&cpufreq_cpu_data, cpu) = NULL
      
      And this will result in a warning like this one:
      
       ------------[ cut here ]------------
       WARNING: CPU: 0 PID: 4 at include/linux/kref.h:47
       kobject_get+0x41/0x50()
       Modules linked in: acpi_cpufreq(+) nfsd auth_rpcgss nfs_acl
       lockd grace sunrpc xfs libcrc32c sd_mod ixgbe igb mdio ahci hwmon
       ...
       Call Trace:
        [<ffffffff81661b14>] dump_stack+0x46/0x58
        [<ffffffff81072b61>] warn_slowpath_common+0x81/0xa0
        [<ffffffff81072c7a>] warn_slowpath_null+0x1a/0x20
        [<ffffffff812e16d1>] kobject_get+0x41/0x50
        [<ffffffff815262a5>] cpufreq_cpu_get+0x75/0xc0
        [<ffffffff81527c3e>] cpufreq_update_policy+0x2e/0x1f0
        [<ffffffff810b8cb2>] ? up+0x32/0x50
        [<ffffffff81381aa9>] ? acpi_ns_get_node+0xcb/0xf2
        [<ffffffff81381efd>] ? acpi_evaluate_object+0x22c/0x252
        [<ffffffff813824f6>] ? acpi_get_handle+0x95/0xc0
        [<ffffffff81360967>] ? acpi_has_method+0x25/0x40
        [<ffffffff81391e08>] acpi_processor_ppc_has_changed+0x77/0x82
        [<ffffffff81089566>] ? move_linked_works+0x66/0x90
        [<ffffffff8138e8ed>] acpi_processor_notify+0x58/0xe7
        [<ffffffff8137410c>] acpi_ev_notify_dispatch+0x44/0x5c
        [<ffffffff8135f293>] acpi_os_execute_deferred+0x15/0x22
        [<ffffffff8108c910>] process_one_work+0x160/0x410
        [<ffffffff8108d05b>] worker_thread+0x11b/0x520
        [<ffffffff8108cf40>] ? rescuer_thread+0x380/0x380
        [<ffffffff81092421>] kthread+0xe1/0x100
        [<ffffffff81092340>] ? kthread_create_on_node+0x1b0/0x1b0
        [<ffffffff81669ebc>] ret_from_fork+0x7c/0xb0
        [<ffffffff81092340>] ? kthread_create_on_node+0x1b0/0x1b0
       ---[ end trace 89e66eb9795efdf7 ]---
      
      The actual code flow is as follows:
      
       Thread A: Workqueue: kacpi_notify
      
       acpi_processor_notify()
         acpi_processor_ppc_has_changed()
               cpufreq_update_policy()
                 cpufreq_cpu_get()
                   kobject_get()
      
       Thread B: xenbus_thread()
      
       xenbus_thread()
         msg->u.watch.handle->callback()
           handle_vcpu_hotplug_event()
             vcpu_hotplug()
               cpu_down()
                 __cpu_notify(CPU_POST_DEAD..)
                   cpufreq_cpu_callback()
                     __cpufreq_remove_dev_finish()
                       cpufreq_policy_put_kobj()
                         kobject_put()
      
      cpufreq_cpu_get() gets the policy from per-cpu variable cpufreq_cpu_data
      under cpufreq_driver_lock, and once it gets a valid policy it expects it
      to not be freed until cpufreq_cpu_put() is called.
      
      But the race happens when another thread puts the kobject first and updates
      cpufreq_cpu_data before or later. And so the first thread gets a valid policy
      structure and before it does kobject_get() on it, the second one has already
      done kobject_put().
      
      Fix this by setting cpufreq_cpu_data to NULL before putting the kobject and that
      too under locks.
      Reported-by: NEthan Zhao <ethan.zhao@oracle.com>
      Reported-by: NSantosh Shilimkar <santosh.shilimkar@oracle.com>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      Cc: 3.12+ <stable@vger.kernel.org> # 3.12+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      6ffae8c0
  5. 24 1月, 2015 18 次提交
  6. 20 12月, 2014 1 次提交
    • E
      cpufreq: fix a NULL pointer dereference in __cpufreq_governor() · cb57720b
      Ethan Zhao 提交于
      If ACPI _PPC changed notification happens before governor was initiated
      while kernel is booting, a NULL pointer dereference will be triggered:
      
      BUG: unable to handle kernel NULL pointer dereference at 0000000000000030
       IP: [<ffffffff81470453>] __cpufreq_governor+0x23/0x1e0
       PGD 0
       Oops: 0000 [#1] SMP
       ... ...
       RIP: 0010:[<ffffffff81470453>]  [<ffffffff81470453>]
       __cpufreq_governor+0x23/0x1e0
       RSP: 0018:ffff881fcfbcfbb8  EFLAGS: 00010286
       RAX: 0000000000000000 RBX: ffff881fd11b3980 RCX: ffff88407fc20000
       RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff881fd11b3980
       RBP: ffff881fcfbcfbd8 R08: 0000000000000000 R09: 000000000000000f
       R10: ffffffff818068d0 R11: 0000000000000043 R12: 0000000000000004
       R13: 0000000000000000 R14: ffffffff8196cae0 R15: 0000000000000000
       FS:  0000000000000000(0000) GS:ffff881fffc00000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 0000000000000030 CR3: 00000000018ae000 CR4: 00000000000407f0
       DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
       Process kworker/0:3 (pid: 750, threadinfo ffff881fcfbce000, task
       ffff881fcf556400)
       Stack:
        ffff881fffc17d00 ffff881fcfbcfc18 ffff881fd11b3980 0000000000000000
        ffff881fcfbcfc08 ffffffff81470d08 ffff881fd11b3980 0000000000000007
        ffff881fcfbcfc18 ffff881fffc17d00 ffff881fcfbcfd28 ffffffff81472e9a
       Call Trace:
        [<ffffffff81470d08>] __cpufreq_set_policy+0x1b8/0x2e0
        [<ffffffff81472e9a>] cpufreq_update_policy+0xca/0x150
        [<ffffffff81472f20>] ? cpufreq_update_policy+0x150/0x150
        [<ffffffff81324a96>] acpi_processor_ppc_has_changed+0x71/0x7b
        [<ffffffff81320bcd>] acpi_processor_notify+0x55/0x115
        [<ffffffff812f9c29>] acpi_device_notify+0x19/0x1b
        [<ffffffff813084ca>] acpi_ev_notify_dispatch+0x41/0x5f
        [<ffffffff812f64a4>] acpi_os_execute_deferred+0x27/0x34
      
      The root cause is a race conditon -- cpufreq core and acpi-cpufreq driver
      were initiated, but cpufreq_governor wasn't and _PPC changed notification
      happened, __cpufreq_governor() was called within acpi_os_execute_deferred
      kernel thread context.
      
      To fix this panic issue, add pointer checking code in __cpufreq_governor()
      before pointer policy->governor is to be dereferenced.
      Signed-off-by: NEthan Zhao <ethan.zhao@oracle.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      cb57720b
  7. 30 11月, 2014 1 次提交
  8. 26 11月, 2014 1 次提交
    • T
      cpufreq: Ref the policy object sooner · 6d4e81ed
      Tomeu Vizoso 提交于
      Do it before it's assigned to cpufreq_cpu_data, otherwise when a driver
      tries to get the cpu frequency during initialization the policy kobj is
      referenced and we get this warning:
      
      ------------[ cut here ]------------
      WARNING: CPU: 1 PID: 64 at include/linux/kref.h:47 kobject_get+0x64/0x70()
      Modules linked in:
      CPU: 1 PID: 64 Comm: irq/77-tegra-ac Not tainted 3.18.0-rc4-next-20141114ccu-00050-g3eff942 #326
      [<c0016fac>] (unwind_backtrace) from [<c001272c>] (show_stack+0x10/0x14)
      [<c001272c>] (show_stack) from [<c06085d8>] (dump_stack+0x98/0xd8)
      [<c06085d8>] (dump_stack) from [<c002892c>] (warn_slowpath_common+0x84/0xb4)
      [<c002892c>] (warn_slowpath_common) from [<c00289f8>] (warn_slowpath_null+0x1c/0x24)
      [<c00289f8>] (warn_slowpath_null) from [<c0220290>] (kobject_get+0x64/0x70)
      [<c0220290>] (kobject_get) from [<c03e944c>] (cpufreq_cpu_get+0x88/0xc8)
      [<c03e944c>] (cpufreq_cpu_get) from [<c03e9500>] (cpufreq_get+0xc/0x64)
      [<c03e9500>] (cpufreq_get) from [<c0285288>] (actmon_thread_isr+0x134/0x198)
      [<c0285288>] (actmon_thread_isr) from [<c0069008>] (irq_thread_fn+0x1c/0x40)
      [<c0069008>] (irq_thread_fn) from [<c0069324>] (irq_thread+0x134/0x174)
      [<c0069324>] (irq_thread) from [<c0040290>] (kthread+0xdc/0xf4)
      [<c0040290>] (kthread) from [<c000f4b8>] (ret_from_fork+0x14/0x3c)
      ---[ end trace b7bd64a81b340c59 ]---
      Signed-off-by: NTomeu Vizoso <tomeu.vizoso@collabora.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      6d4e81ed
  9. 12 11月, 2014 1 次提交
    • V
      cpufreq: respect the min/max settings from user space · 619c144c
      Vince Hsu 提交于
      When the user space tries to set scaling_(max|min)_freq through
      sysfs, the cpufreq_set_policy() asks other driver's opinions
      for the max/min frequencies. Some device drivers, like Tegra
      CPU EDP which is not upstreamed yet though, may constrain the
      CPU maximum frequency dynamically because of board design.
      So if the user space access happens and some driver is capping
      the cpu frequency at the same time, the user_policy->(max|min)
      is overridden by the capped value, and that's not expected by
      the user space. And if the user space is not invoked again,
      the CPU will always be capped by the user_policy->(max|min)
      even no drivers limit the CPU frequency any more.
      
      This patch preserves the user specified min/max settings, so that
      every time the cpufreq policy is updated, the new max/min can
      be re-evaluated correctly based on the user's expection and
      the present device drivers' status.
      Signed-off-by: NVince Hsu <vinceh@nvidia.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      619c144c
  10. 08 11月, 2014 1 次提交
    • G
      cpufreq: Avoid crash in resume on SMP without OPP · 09712f55
      Geert Uytterhoeven 提交于
      When resuming from s2ram on an SMP system without cpufreq operating
      points (e.g. there's no "operating-points" property for the CPU node in
      DT, or the platform doesn't use DT yet), the kernel crashes when
      bringing CPU 1 online:
      
          Enabling non-boot CPUs ...
          CPU1: Booted secondary processor
          Unable to handle kernel NULL pointer dereference at virtual address 0000003c
          pgd = ee5e6b00
          [0000003c] *pgd=6e579003, *pmd=6e588003, *pte=00000000
          Internal error: Oops: a07 [#1] SMP ARM
          Modules linked in:
          CPU: 0 PID: 1246 Comm: s2ram Tainted: G        W      3.18.0-rc3-koelsch-01614-g0377af242bb175c8-dirty #589
          task: eeec5240 ti: ee704000 task.ti: ee704000
          PC is at __cpufreq_add_dev.isra.24+0x24c/0x77c
          LR is at __cpufreq_add_dev.isra.24+0x244/0x77c
          pc : [<c0298efc>]    lr : [<c0298ef4>]    psr: 60000153
          sp : ee705d48  ip : ee705d48  fp : ee705d84
          r10: c04e0450  r9 : 00000000  r8 : 00000001
          r7 : c05426a8  r6 : 00000001  r5 : 00000001  r4 : 00000000
          r3 : 00000000  r2 : 00000000  r1 : 20000153  r0 : c0542734
      
      Verify that policy is not NULL before dereferencing it to fix this.
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Fixes: 8414809c (cpufreq: Preserve policy structure across suspend/resume)
      Cc: 3.12+ <stable@vger.kernel.org> # 3.12+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      09712f55
  11. 24 10月, 2014 1 次提交
  12. 21 10月, 2014 1 次提交
  13. 01 10月, 2014 1 次提交
  14. 29 9月, 2014 2 次提交
    • R
      cpufreq: Replace strnicmp with strncasecmp · 7c4f4539
      Rasmus Villemoes 提交于
      The kernel used to contain two functions for length-delimited,
      case-insensitive string comparison, strnicmp with correct semantics
      and a slightly buggy strncasecmp. The latter is the POSIX name, so
      strnicmp was renamed to strncasecmp, and strnicmp made into a wrapper
      for the new strncasecmp to avoid breaking existing users.
      
      To allow the compat wrapper strnicmp to be removed at some point in
      the future, and to avoid the extra indirection cost, do
      s/strnicmp/strncasecmp/g.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      7c4f4539
    • P
      cpufreq: Allow stop CPU callback to be used by all cpufreq drivers · 789ca243
      Preeti U Murthy 提交于
      Commit 367dc4aa ("cpufreq: Add stop CPU callback to
      cpufreq_driver interface") introduced the stop CPU callback for
      intel_pstate drivers. During the CPU_DOWN_PREPARE stage, this
      callback is invoked so that drivers can take some action on the
      pstate of the cpu before it is taken offline. This callback was
      assumed to be useful only for those drivers which have implemented
      the set_policy CPU callback because they have no other way to take
      action about the cpufreq of a CPU which is being hotplugged out
      except in the exit callback which is called very late in the offline
      process.
      
      The drivers which implement the target/target_index callbacks were
      expected to take care of requirements like the ones that commit
      367dc4aa addresses in the GOV_STOP notification event. But there
      are disadvantages to restricting the usage of stop CPU callback
      to cpufreq drivers that implement the set_policy callbacks and who
      want to take explicit action on the setting the cpufreq during a
      hotplug operation.
      
      1.GOV_STOP gets called for every CPU offline and drivers would usually
      want to take action when the last cpu in the policy->cpus mask
      is taken offline. As long as there is more than one cpu in the
      policy->cpus mask, cpufreq core itself makes sure that the freq
      for the other cpus in this mask is set according to the maximum load.
      This is sensible and drivers which implement the target_index callback
      would mostly not want to modify that. However the cpufreq core leaves a
      loose end when the cpu in the policy->cpus mask is the last one to go offline;
      it does nothing explicit to the frequency of the core. Drivers may need
      a way to take some action here and stop CPU callback mechanism is the
      best way to do it today.
      
      2. We cannot implement driver specific actions in the GOV_STOP mechanism.
      So we will need another driver callback which is invoked from here which is
      unnecessary.
      
      Therefore this patch extends the usage of stop CPU callback to be used
      by all cpufreq drivers as long as they have this callback implemented
      and irrespective of whether they are set_policy/target_index drivers.
      The assumption is if the drivers find the GOV_STOP path to be a suitable
      way of implementing what they want to do with the freq of the cpu
      going offine,they will not implement the stop CPU callback at all.
      Signed-off-by: NPreeti U Murthy <preeti@linux.vnet.ibm.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      789ca243
  15. 22 9月, 2014 2 次提交
    • P
      cpufreq: release policy->rwsem on error · 7106e02b
      Prarit Bhargava 提交于
      While debugging a cpufreq-related hardware failure on a system I saw the
      following lockdep warning:
      
       =========================
       [ BUG: held lock freed! ] 3.17.0-rc4+ #1 Tainted: G            E
       -------------------------
       insmod/2247 is freeing memory ffff88006e1b1400-ffff88006e1b17ff, with a lock still held there!
        (&policy->rwsem){+.+...}, at: [<ffffffff8156d37d>] __cpufreq_add_dev.isra.21+0x47d/0xb80
       3 locks held by insmod/2247:
        #0:  (subsys mutex#5){+.+.+.}, at: [<ffffffff81485579>] subsys_interface_register+0x69/0x120
        #1:  (cpufreq_rwsem){.+.+.+}, at: [<ffffffff8156cf73>] __cpufreq_add_dev.isra.21+0x73/0xb80
        #2:  (&policy->rwsem){+.+...}, at: [<ffffffff8156d37d>] __cpufreq_add_dev.isra.21+0x47d/0xb80
      
       stack backtrace:
       CPU: 0 PID: 2247 Comm: insmod Tainted: G            E  3.17.0-rc4+ #1
       Hardware name: HP ProLiant MicroServer Gen8, BIOS J06 08/24/2013
        0000000000000000 000000008f3063c4 ffff88006f87bb30 ffffffff8171b358
        ffff88006bcf3750 ffff88006f87bb68 ffffffff810e09e1 ffff88006e1b1400
        ffffea0001b86c00 ffffffff8156d327 ffff880073003500 0000000000000246
       Call Trace:
        [<ffffffff8171b358>] dump_stack+0x4d/0x66
        [<ffffffff810e09e1>] debug_check_no_locks_freed+0x171/0x180
        [<ffffffff8156d327>] ? __cpufreq_add_dev.isra.21+0x427/0xb80
        [<ffffffff8121412b>] kfree+0xab/0x2b0
        [<ffffffff8156d327>] __cpufreq_add_dev.isra.21+0x427/0xb80
        [<ffffffff81724cf7>] ? _raw_spin_unlock+0x27/0x40
        [<ffffffffa003517f>] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq]
        [<ffffffff8156da8e>] cpufreq_add_dev+0xe/0x10
        [<ffffffff814855d1>] subsys_interface_register+0xc1/0x120
        [<ffffffff8156bcf2>] cpufreq_register_driver+0x112/0x340
        [<ffffffff8121415a>] ? kfree+0xda/0x2b0
        [<ffffffffa003517f>] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq]
        [<ffffffffa003562e>] pcc_cpufreq_init+0x4af/0xe81 [pcc_cpufreq]
        [<ffffffffa003517f>] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq]
        [<ffffffff81002144>] do_one_initcall+0xd4/0x210
        [<ffffffff811f7472>] ? __vunmap+0xd2/0x120
        [<ffffffff81127155>] load_module+0x1315/0x1b70
        [<ffffffff811222a0>] ? store_uevent+0x70/0x70
        [<ffffffff811229d9>] ? copy_module_from_fd.isra.44+0x129/0x180
        [<ffffffff81127b86>] SyS_finit_module+0xa6/0xd0
        [<ffffffff81725b69>] system_call_fastpath+0x16/0x1b
       cpufreq: __cpufreq_add_dev: ->get() failed
      insmod: ERROR: could not insert module pcc-cpufreq.ko: No such device
      
      The warning occurs in the __cpufreq_add_dev() code which does
      
              down_write(&policy->rwsem);
      	...
              if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
                      policy->cur = cpufreq_driver->get(policy->cpu);
                      if (!policy->cur) {
                              pr_err("%s: ->get() failed\n", __func__);
                              goto err_get_freq;
                      }
      
      If cpufreq_driver->get(policy->cpu) returns an error we execute the
      code at err_get_freq, which does not up the policy->rwsem.  This causes
      the lockdep warning.
      
      Trivial patch to up the policy->rwsem in the error path.
      
      After the patch has been applied, and an error occurs in the
      cpufreq_driver->get(policy->cpu) call we will now see
      
      cpufreq: __cpufreq_add_dev: ->get() failed
      cpufreq: __cpufreq_add_dev: ->get() failed
      modprobe: ERROR: could not insert 'pcc_cpufreq': No such device
      
      Fixes: 4e97b631 (cpufreq: Initialize governor for a new policy under policy->rwsem)
      Signed-off-by: NPrarit Bhargava <prarit@redhat.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Cc: 3.14+ <stable@vger.kernel.org> # 3.14+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      7106e02b
    • L
      cpufreq: fix cpufreq suspend/resume for intel_pstate · 8e30444e
      Lan Tianyu 提交于
      Cpufreq core introduces cpufreq_suspended flag to let cpufreq sysfs nodes
      across S2RAM/S2DISK. But the flag is only set in the cpufreq_suspend()
      for cpufreq drivers which have target or target_index callback. This
      skips intel_pstate driver. This patch is to set the flag before checking
      target or target_index callback.
      
      Fixes: 2f0aea93 (cpufreq: suspend governors on system suspend/hibernate)
      Signed-off-by: NLan Tianyu <tianyu.lan@intel.com>
      Cc: 3.15+ <stable@vger.kernel.org> # 3.15+
      [rjw: Subject]
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      8e30444e