msm: vidc: Initialize kernel space stack variables

This change initializes kernel space stack variables
that are passed between kernel space and user space
using ioctls.
Non initialization of these variables may lead to
leakage of memory values from the kernel stack to
user space.

Change-Id: Icb195470545ee48b55671ac09798610178e833e1
CRs-fixed: 556771,563420
Signed-off-by: Deepak Verma <dverma@codeaurora.org>
Add PR_{GET,SET}_NO_NEW_PRIVS to prevent execve from granting privs

With this set, a lot of dangerous operations (chroot, unshare, etc)
become a lot less dangerous because there is no possibility of
subverting privileged binaries.

Includes additional work to fix apparmor.

Patch taken from kernel.org, authored by
Andy Lutomirski <luto@amacapital.net>
John Johansen <john.johansen@canonical.com>

Change-Id: Ic34200e2d1a690a81c0e88a59926f81c805ee713
msm: idle-v7: Power collapse Krait with caches enabled

The SCTLR[C/I] bits do not need to be cleared when entering
power collapse on Krait CPUs.

Change-Id: Ic33b227fe55a87e10aab46e6a30f44cc400ccfbb
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
staging: android: lowmemorykiller: Add config option to support oom_adj values

The conversion to use oom_score_adj instead of the deprecated oom_adj
values breaks existing user-space code. Add a config option to convert
oom_adj values written to oom_score_adj values if they appear to be
valid oom_adj values.

Change-Id: I68308125059b802ee2991feefb07e9703bc48549
Signed-off-by: Arve Hjønnevåg <arve@android.com>
defconfig: Enable lowmemorykiller autodetect option

Recent ABI changes have made the lowmemorykiller less effective.
Enable ANDROID_LOW_MEMORY_KILLER_AUTODETECT_OOM_ADJ_VALUE to
detect when the old ABI is being used and convert it to the new
ABI.

Change-Id: If47113e5fc7706bcd6bb144c591e9935b0c5115a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
lib: genalloc: Change chunk allocation to vmalloc

Change the chunk allocation from kmalloc to vmalloc for
allocations greater than a page. This allows large
chunks to be allocated from physically non-contiguous
memory and increases the chance of the allocation
succeeding.

CRs-fixed: 387655
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 0614b96dc8e4c8a0dd0db41aec5a79daa3bdf091)

Conflicts:

	lib/genalloc.c

Change-Id: Ic0dedbad9d277d0842591b1f075ce3b80c8c05de
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
ARM: Fix deadlock scenario with smp_send_stop()

If one process calls sys_reboot and that process then stops other
CPUs while those CPUs are within a spin_lock() region we can
potentially encounter a deadlock scenario like below.

CPU 0                   CPU 1
-----                   -----
                        spin_lock(my_lock)
smp_send_stop()
 send_IPI               handle_IPI()
                         disable_preemption/irqs
                          while(1);
 <PREEMPT>
spin_lock(my_lock) <--- Waits forever

We shouldn't attempt to run any other tasks after we send a stop
IPI to a CPU so disable preemption so that this task runs to
completion.

Change-Id: I528af0b4448433bd9d6ca12d6a0e2c422a55d4be
CRs-Fixed: 396169
Reported-by: Sundarajan Srinivasan <sundaraj@codeaurora.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Revert "mmc: Make sure host is disabled on suspend"

Change-Id: Ia17ab7eeee77673b1d069add7cc98fa1d37f9990
mmc: Make sure host is disabled on suspend

Change-Id: Ie0bf2004e173cef8dad66722a152658d7727ab65
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
msm: idle-v7.S: Warmboot support for NR_CPUS >= 2

The change supports save/restore of processor state during warmboot when
the number of cores is greater than 2. The current version supports two
cores only.

Change-Id: Icd23f10cde00a5dbe0abc1a76f1555f8834053a3
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: idle-v7: Remove redundant cache clean

Cleaning the register save area is not necessary if we are
already cleaning the entire cache. Eliminate the redundant
cleaning operation to reduce power collapse latency.

Change-Id: I3651083f147874fd6003cfe12b07861689ca77cc
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
msm: idle-v7 : Restore context for NR_CPUS >= 2 when PC fails

When there is a pending interrupt and the core executes WFI
instruction, the SPM would not trigger its state machine and would
bail out. The instructions after the WFI instruction will be executed.
The context calculation need to take care of getting the right context
to restore.

Change-Id: Icda4abe68503250f27b8c9b89891318beab86a7b
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
msm: pm: save registers to noncached area before pc

The power collapse path is simplified if a noncached area is
used for the purpose of saving register state prior to power
collapsing. This is especially beneficial in the case of targets
with an outer cache, where the process of cleaning the register
state would require complex operations.

Change-Id: I9edac28e4091548e2843fc87c89e3451df2b6ae9
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
thermal: Don't limit CPU frequency after msm_thermal is disabled

There may be an outstanding task to check for threshold crossing
when msm_thermal is disabled and CPU is restored to maximum
frequency. This task can get scheduled after the maximum frequency
is restored, and result in another mitigation that pins CPU
frequencies to 918mHz. This happens in the case that the final
temperature was still above the max temperature threshold.
This patch ensures any outstanding tasks are cancelled and flushed
before finally restoring the CPU frequencies.

CRs-fixed: 351614
Change-Id: Ifce00b379989b78856803ac09c7403207f5c998b
Signed-off-by: Eugene Seah <eseah@codeaurora.org>
msm: thermal: Simplify kernel thermal safeguard mechanism

Using CPUFreq policy objects and setting the max frequency limit by
overriding the policy->max node, leads to race/overwrite conditions with
an user trying to use the scaling_max_frequency node.

The thermal limits are directly communicated to the 'msm' cpufreq driver
and use the cpufreq_update_policy() to ensure that the frequency is
limited as per the thermal safeguard requirements.

CRs-fixed: 370343
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
(cherry picked from commit 9181436c8d688480ded367557b4b9b012b1881b2)

Change-Id: I5c4ceaac00c6dcd91eb207c555519f9c5fd08d9b
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
msm: cpufreq: fix a race between hotplug and cpufreq

When msm_cpufreq_target() is called without holding the policy
semaphore, there is a rare chance that the cpu gets hotplugged in
the acpuclk_set_rate. The probability of this issue increases
when cross-calling is used or using interactive governor which
tries to set all cpu frequencies from a single thread.

Add a hotplug notifier and set the device_suspended flag holding
the suspend mutex, when cpu is going down. This mutex is always
held when frequency changes are done.

Change-Id: Ide3aa6927ad60d2512d63761c51bb15117461250
Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>
msm: cpufreq: Add API to allow limiting of min and max cpu frequencies

CPUFreq provides scaling sysfs nodes to set min and max frequencies, but
there are times when the operating range has to be controlled
irrespective of the scaling limits, to ensure the thermal stability of
the device.

The API allows kernel thermal safeguards to pitch in and limit the
frequencies.

Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
(cherry picked from commit 696a561c5bbc4733476db16be6f05fd92dee9a71)

Change-Id: I7faa1205948b81a23d24a3b29bdedc98a07a5861
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
msm: cpuidle: Update C state time stats in the cpu idle device.

msm_pm_idle_enter function returns time spent by cpu in particular
C state. Update the cpu idle device last residency with the return
value which is required for cpuidle stats.

CRs-fixed: 391456
Change-Id: If9f1b59e05c233e53ba37ae0fe9399f12275f3d8
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
arm: show present cpu instead of online cpu in /proc/cpuinfo

Some userspace applications use /proc/cpuinfo to determine how many CPUs
the system has. CPU hotplug can offline a CPU at runtime and causing the
offline CPU not present in /proc/cpuinfo if we only show online cpu in
/proc/cpuinfo.

CRs-Fixed: 354430
Signed-off-by: Jin Hong <jinh@codeaurora.org>
(cherry picked from commit 1e28794d0ff00fc6567d68b5b4e863b0745cfe20)

Change-Id: I3b38472b690bb3dba67ada74f60cce79ed0b2a7d
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: gpio-v2: Fix lockdep warning

In similar fashion as b5eee2f (ARM: mxc: Add missing lockdep
annotation, 2011-04-04) add a lock class so that lockdep knows
the gpio irqs are always locked correctly with respect to the
descriptor lock class.

=============================================
[ INFO: possible recursive locking detected ]
3.0.21-g51ce160-00020-g8eb5789-dirty #2894
---------------------------------------------
swapper/1 is trying to acquire lock:
 (&irq_desc_lock_class){-.....}, at: [<c01ceaf0>] __irq_get_desc_lock+0x74/0x8c

but task is already holding lock:
 (&irq_desc_lock_class){-.....}, at: [<c01ceaf0>] __irq_get_desc_lock+0x74/0x8c

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

       CPU0
       ----
  lock(&irq_desc_lock_class);
  lock(&irq_desc_lock_class);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

3 locks held by swapper/1:
 #0:  (&__lockdep_no_validate__){+.+.+.}, at: device_attach+0x18/0xa4
 #1:  (&__lockdep_no_validate__){+.+.+.}, at: device_attach+0x18/0xa4
 #2:  (&irq_desc_lock_class){-.....}, at: __irq_get_desc_lock+0x74/0x8c

Change-Id: Icc0058370de4db17ae4fadb66f5fe970c37ecc6c
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>