cpufreq: Retain only online cpus in managed_policy->cpus
cpufreq's handling of cpu online event can incorrectly initialize
managed_policy->cpus to include offline cpus. This causes cpufreq
governors to include offline cpus in their idle time computation, which
causes frequency to shoot up beyond normal levels (on systems where 2 or
more cpus need to be synchronized wrt frequency change).

This frequency shootup was not seen prior to commit 21111be8 which
changed idle time accounting for offline cpus. Prior to commit 21111be8,
idle time statistics for offline cpus would include their offline time
as well. Post commit 21111be8, offline time is not included in a cpu's
idle time statistics.

As a result, ondemand (or other cpufreq) governors would see unchanged
idle time for offline cpus, causing them to interpret those (offline)
cpus as 100% busy, which is wrong.

This patch fixes the issue by modifying cpufreq's hotplug handling to
retain only online cpus in managed_policy->cpus field. cpufreq governors
would then skip such offline cpus from idle time calculations.

Change-Id: Id2eba8c0ec3367609369b2e42a4e1386ff2e7ab5
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
cpufreq: Fix sysfs deadlock with concurrent hotplug/frequency switch
Running one program that continuously hotplugs and replugs a cpu
concurrently with another program that continuously writes to the
scaling_set_speed node eventually deadlocks with:

=============================================
[ INFO: possible recursive locking detected ]
3.4.0 #37 Tainted: G        W
---------------------------------------------
filemonkey/122 is trying to acquire lock:
 (s_active#13){++++.+}, at: [<c01a3d28>] sysfs_remove_dir+0x9c/0xb4

but task is already holding lock:
 (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(s_active#13);
  lock(s_active#13);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by filemonkey/122:
 #0:  (&buffer->mutex){+.+.+.}, at: [<c01a2230>] sysfs_write_file+0x28/0x140
 #1:  (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

stack backtrace:
[<c0014fcc>] (unwind_backtrace+0x0/0x120) from [<c00ca600>] (validate_chain+0x6f8/0x1054)
[<c00ca600>] (validate_chain+0x6f8/0x1054) from [<c00cb778>] (__lock_acquire+0x81c/0x8d8)
[<c00cb778>] (__lock_acquire+0x81c/0x8d8) from [<c00cb9c0>] (lock_acquire+0x18c/0x1e8)
[<c00cb9c0>] (lock_acquire+0x18c/0x1e8) from [<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180)
[<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180) from [<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4)
[<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4) from [<c02d0e5c>] (kobject_del+0x10/0x38)
[<c02d0e5c>] (kobject_del+0x10/0x38) from [<c02d0f74>] (kobject_release+0xf0/0x194)
[<c02d0f74>] (kobject_release+0xf0/0x194) from [<c0565a98>] (cpufreq_cpu_put+0xc/0x24)
[<c0565a98>] (cpufreq_cpu_put+0xc/0x24) from [<c05683f0>] (store+0x6c/0x74)
[<c05683f0>] (store+0x6c/0x74) from [<c01a2314>] (sysfs_write_file+0x10c/0x140)
[<c01a2314>] (sysfs_write_file+0x10c/0x140) from [<c014af44>] (vfs_write+0xb0/0x128)
[<c014af44>] (vfs_write+0xb0/0x128) from [<c014b06c>] (sys_write+0x3c/0x68)
[<c014b06c>] (sys_write+0x3c/0x68) from [<c000e0e0>] (ret_fast_syscall+0x0/0x3c)

This is because store() in cpufreq.c indirectly grabs a kobject
with kobject_get() and is the last one to call kobject_put()
indirectly via cpufreq_cpu_put().

Fix this deadlock by introducing two new functions,
cpufreq_cpu_get_sysfs() and cpufreq_cpu_put_sysfs() which do the
same thing as cpufreq_cpu_{get,put}() but don't grab the kobject.

CRs-fixed: 366560
Change-Id: I23ea50a01793b2b2af0972cde52dba7396925fe3
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
msm_mpdecision: further simplifications

- redo and simplify enable/disable. move sysfs enabled parameter to
  /sys/module/msm_mpdecision/parameters/enabled consistent
  with other modules. simplify related sysfs functions
- use nr_cpu_ids instead of CONFIG_NR_CPUS. remove redundant if checks
  of nr_cpu_ids from msm_mpdec_work_thread
- redo pause check in msm_mpdec_work_thread
- remove suspend var from msm_mpdec_cpudata, also remove suspend check
  from msm_mpdec_work_thread
- redo and simplify suspend and resume functions
- remove redundant clk_get_rate function, directly call acpuclk_get_rate
- merge mp_decision function with msm_mpdec_work_thread and simplify
  the work thread
- remove startdelay sysfs parameter. there is no point of having it since
  it resets at every boot and used only once after boot
- properly use startdelay only once in the init function instead of an
  if statement repeatedly executed in the work function
- remove redundant exit function
msm_rq_stats: backport from CAF msm-3.4 kernel
also rename get_rq_info as get_rq_avg used in msm_mpdecision
Linux 3.0.86

Ben Hutchings <ben@decadent.org.uk>
SCSI: sd: Fix parsing of 'temporary ' cache mode prefix

J. Bruce Fields <bfields@redhat.com>
nfsd4: fix decoding of compounds across page boundaries

Greg Kroah-Hartman <gregkh@linuxfoundation.org>
MAINTAINERS: add stable_kernel_rules.txt to stable maintainer information

Kees Cook <keescook@chromium.org>
crypto: sanitize argument for format string

Kees Cook <keescook@chromium.org>
block: do not pass disk names as format strings

Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
hpfs: better test for errors

Jonathan Salwan <jonathan.salwan@gmail.com>
drivers/cdrom/cdrom.c: use kzalloc() for failing hardware

Tyler Hicks <tyhicks@canonical.com>
libceph: Fix NULL pointer dereference in auth client code
space patrol
block: row: change hrtimer_cancel to hrtimer_try_to_cancel
Calling hrtimer_cancel with interrupts disabled can result in a livelock.
When flushing plug list in the block layer interrupts are disabled and an
hrtimer is used when adding requests from that plug list to the scheduler.
In this code flow, if the hrtimer (which is used for idling) is set, it's
being canceled by calling hrtimer_cancel. hrtimer_cancel will perform
the following in an endless loop:
1. try cancel the timer
2. if fails - rest_cpu
the cancellation can fail if the timer function already started. Since
interrupts are disabled it can never complete.
This patch reduced the number of times the hrtimer lock is taken while
interrupts are disabled by calling hrtimer_try_co_cancel. the later will
try to cancel the timer just once and return with an error code if fails.

CRs-fixed: 499887
Change-Id: I25f79c357426d72ad67c261ce7cb503ae97dc7b9
Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org>
msm_mpdecision: simplify stats

- remove times_cpus_unlugged since it is correlated to times_cpus_hotplugged
- remove time_cpus_on. this better be obtained from cpuidle stats
- use for_each_online_cpu to simplify the code
- several format changes
cpufreq: interactive: resched timer if max freq raised

When the policy max freq is raised, and before the timer is
rescheduled in idle callback, the cpu freq may stuck at a
lower freq.

The target_freq shall be updated too, else on a high load
situation, the new_freq is always equal to target_freq and
which will cause freq stuck at a lower freq too.

Reschedule the timer on gov limits callback.

Change-Id: I6c187001ab43e859731429b64f75a74eebc37a24
Signed-off-by: Lianwei Wang <a22439@motorola.com>
workqueue: backport from Linux 3.6.11

to get the following patches by Tejun Heo that improves the latency of cpu
hotplug events.
workqueue: simplify CPU hotplug code
workqueue: remove CPU offline trustee
workqueue: don't butcher idle workers on an offline CPU
workqueue: reimplement CPU online rebinding to handle idle workers
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/Hotplug#Workqueue

Thanks to johnnyslt for fixes in msm_watchdog.c and restart.c
msm_thermal: code clean up
no functional changes. replace sysfs store functions with a single macro
and minor formatting
msm_mpdecision: directly access rq_stats and eliminate msm_rq_stats
The original purpose of msm_rq_stats is enabling userspace access to
rq_stats and comes with the overhead of additional spin/mutex
locks and sysfs facilities,  mainly used by userspace mpdecision.
However, kernel-based mpdecision still depends on this code to obtain
cpu load averages while using a tiny fraction of the code. This commit
completely eliminates msm_rq_stats code and adds a very simple
rq_stats direct-access capability in msm_mpdecision.
workqueue: update documentation
Linux 3.0.87

Bartlomiej Zolnierkiewicz <b.zolnierkie [at] samsung>
drivers/dma/pl330.c: fix locking in pl330_free_chan_resources()

Jed Davis <jld [at] mozilla>
ARM: 7765/1: perf: Record the user-mode PC in the call chain.

Jan Kara <jack [at] suse>
ext4: fix overflow when counting used blocks on 32-bit architectures

Jan Kara <jack [at] suse>
ext4: fix data offset overflow in ext4_xattr_fiemap() on 32-bit archs

Bart Van Assche <bart.vanassche [at] gmail>
timer: Fix jiffies wrap behavior of round_jiffies_common()

Shane Huang <shane.huang [at] amd>
ahci: remove pmp link online check in FBS EH

Shane Huang <shane.huang [at] amd>
ahci: Add AMD CZ SATA device ID

Junxiao Bi <junxiao.bi [at] oracle>
ocfs2: xattr: fix inlined xattr reflink

Lan Tianyu <tianyu.lan [at] intel>
ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan

Axel Lin <axel.lin [at] ingics>
drivers/rtc/rtc-rv3029c2.c: fix disabling AIE irq

Ben Hutchings <ben [at] decadent>
genirq: Fix can_request_irq() for IRQs without an action

Laszlo Ersek <lersek [at] redhat>
xen/time: remove blocked time accounting from xen "clockchip"

Joachim Eastwood <manabian [at] gmail>
pcmcia: at91_cf: fix gpio_get_value in at91_cf_get_status

Mathias Nyman <mathias.nyman [at] linux>
xhci: check for failed dma pool allocation

UCHINO Satoshi <satoshi.uchino [at] toshiba>
usb: gadget: f_mass_storage: add missing memory barrier for thread_wakeup_needed

Dan Williams <dcbw [at] redhat>
USB: option,qcserial: move Novatel Gobi1K IDs to qcserial

Al Viro <viro [at] ZenIV>
ext3,ext4: don't mess with dir_file->f_pos in htree_dirblock_to_tree()

Theodore Ts'o <tytso [at] mit>
jbd2: fix theoretical race in jbd2__journal_restart
msm_mpdecision: simplify for dual-core cpus with preprocessor directives
Some of the loops and function calls are not necessary for dual core
cpus, such as MSM8660 in EVO 3D, since there is only one core to hotplug.
Use preprocessor conditionals to eliminate the unnecessary overhead.