msm: mdss: share fb memory ion fd to userspace

Add new operation request to share ion fd to userspace
for mapping to the frame buffer memory.

Change-Id: I404c73c19e3fffec593ffd32c34e7b1a74a500d8
Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>
vsprintf: ignore %n again

This ignores %n in printf again, as was originally documented.
Implementing %n poses a greater security risk than utility, so it should
stay ignored.  To help anyone attempting to use %n, a warning will be
emitted if it is encountered.

Based on an earlier patch by Joe Perches.

Because %n was designed to write to pointers on the stack, it has been
frequently used as an attack vector when bugs are found that leak
user-controlled strings into functions that ultimately process format
strings.  While this class of bug can still be turned into an
information leak, removing %n eliminates the common method of elevating
such a bug into an arbitrary kernel memory writing primitive,
significantly reducing the danger of this class of bug.

For seq_file users that need to know the length of a written string for
padding, please see seq_setwidth() and seq_pad() instead.

Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 9196436ab2f713b823a2ba2024cb69f40b2f54a5
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
CRs-fixed: 665291
Change-Id: Id191acaf66e3c395df92b0a77331269b525e3cad
Signed-off-by: David Brown <davidb@codeaurora.org>
seq_file: introduce seq_setwidth() and seq_pad()

There are several users who want to know bytes written by seq_*() for
alignment purpose.  Currently they are using %n format for knowing it
because seq_*() returns 0 on success.

This patch introduces seq_setwidth() and seq_pad() for allowing them to
align without using %n format.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 839cc2a94cc3665bafe32203c2f095f4dd470a80)
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
CRs-fixed: 665291
Change-Id: I727d9af5ed320d717295c9d0f82c88623fb181c1
Signed-off-by: David Brown <davidb@codeaurora.org>
seq_file: remove "%n" usage from seq_file users

All seq_printf() users are using "%n" for calculating padding size,
convert them to use seq_setwidth() / seq_pad() pair.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 652586df95e5d76b37d07a11839126dcfede1621
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
[rsiddoji@codeaurora.org: Resolve merge conflicts with ipv4/6 ping
 changes in upstream]
 CRs-fixed: 665291
 Change-Id: Ia0416c9dbe3d80ff35f24f9c93c3543d1200a327
 Signed-off-by: Ravi Kumar <rsiddoji@codeaurora.org>
net: guard tcp_set_keepalive() to tcp sockets

Its possible to use RAW sockets to get a crash in
tcp_set_keepalive() / sk_reset_timer()

Fix is to make sure socket is a SOCK_STREAM one.

Change-Id: Ieeb498a3e623cfcb54e1c865a3c0229e4acf1e87
Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
ASoC: dapm: Fix _PRE and _POST events for DAPM performance improvements

ver since the DAPM performance improvements we've been marking all widgets
as not dirty after each DAPM run. Since _PRE and _POST events aren't part
of the DAPM graph this has rendered them non-functional, they will never be
marked dirty again and thus will never be run again.

Fix this by skipping them when marking widgets as not dirty.

Change-Id: I5aa40ea131921c3f1d309a6567ddff4fce6ab220
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Cc: stable@vger.kernel.org
ASoC: msm: qdsp6v2: requeue read buffers in mmap device switch

When device switch happens, ASM might return a 0 length
buffer. For MMAP style capture cases, buffers need to be
re-queued at the event handler for this case, otherwise
ASM will have no buffers to read data into after the
device is over successful.

CRs-fixed: 700614
Change-Id: I2b8930a3058bbe3979405d5de04d3371291db42d
Signed-off-by: Banajit Goswami <bgoswami@codeaurora.org>
ASoC: msm: audio-effects: improve logging

Make logs more meaningful by logging values where ever
applicable.

Change-Id: I0fd0e62e543480762096d64c7ee7c92eb1204126
Signed-off-by: Dhananjay Kumar <dhakumar@codeaurora.org>
ASoC: msm: qdsp6v2: Fix bit alignment in snd_codec params

Pointer member variables in snd_codec params break bit alignment and
causes data corruption. By changing these pointers to fixed size
array variables, the bit alignment is rectified. The size has been
set to max possible size. Also, remove params which are not required
anymore.

Change-Id: Ib87bbeb07b0df1ce8a81166b319976fe54c0f013
Signed-off-by: Amit Shekhar <ashekhar@codeaurora.org>
ASoC: msm: qdsp6v2: Add the matrix mixer call during ASM loopback

Add support for matrix mixer command. The render window start and
end are set up before RUN CMD for ASM loopback is issued. This
will ensure that audio data is not dropped and audio quality
is good.

CRs-fixed: 667925
Change-Id: I406d86e9805d9f57613c0349f11cfc729ef7a24c
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
ASoC: msm: qdsp6v2: Cleanup of audio drivers

Using the format strings will remove need for typecasting.
This change cleans up audio msm drivers to use the kernel
defined data types and format specifiers for printk.

Change-Id: Ie1b3d5c8dcf868aa1cc7407d3e679976dffafc76
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>
ASoC: msm: qdsp6v2: Cleanup of compress offload drivers

Clean up the format specifiers for compress offload drivers
and add compat ioctl support

Change-Id: I0829830336ec62c66658d6a5199d73b61249f791
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>
ASoC: qdsp6v2: update perf mode flag for LL capture cases

Read perf mode flag from platform data and update to the
audio client structure, so that the right settings can be
applied to ADM for Low-latency capture use-case.
Also, update the correct bit value for ASM perf mode flag
sent to DSP.

Change-Id: If1f8b9e657a409fd9d2af19ff004a797fd987788
Signed-off-by: Banajit Goswami <bgoswami@codeaurora.org>
ASoC: msm: q6dspv2: add pause/resume support for audio record

Add support for pause/resume functionality for audio capture
path. When application calls stop()for for pausing, suspend
the ASM stream, so that hardware resources can be released.
Again when resuming capture streams with prepare()->start(),
ASM open and the routing call should not be called again.

CRs-fixed: 692084
Change-Id: I59e014696ab0a8c473b87361ac9b739adf538d32
Signed-off-by: Banajit Goswami <bgoswami@codeaurora.org>
ASoC: wcd9320: Fix micbias setting for MAD

For Microphone Activity Detection (MAD) to work properly, it is required
to update the micbias setting correctly to indicate the micbias is
external or internal. Correct the MAD micbias settings to account for
type of micbias (internal or external).

CRs-fixed: 684818
Change-Id: If209f9e4ad971a25fd28848ba7ba297c4f3dbf06
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
ASoC: msm: qdsp6v2: Change client names for ion alloc

ASM and AFE are using the same client name when requesting
ion alloc. This is making it harder to debug which client
requested the memory.  Changing the client names to more
descriptive names.

CRs-fixed: 714707
Change-Id: Id774ce06ff5300da1de5b653812a02a22a47147c
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
ASoC: msm: qdsp6v2: update int to size_t

Int aren't same size as size_t in 64bit kernel. This actually cause part of
the stack to be overwritten

Change-Id: I0ebff1fb9030fdb93a6889ee02329599ae2800fb
Signed-off-by: Fred Oh <fred@codeaurora.org>
msm: kgsl: Fix gpu idle check

Fix the mask being used to check whether gpu has a pending
irq or not and check whether gpu status is idle before checking
for a pending irq. If pending irq is checked before the gpu
status then there is a possibility of the irq being set after
it has been checked but before the gpu status is checked which
will result in the logic detecting that gpu is idle with a
pending irq.

Change-Id: I5f97b6f3f4c6b58c95e91604ae87330d06685962
CRs-Fixed: 647176
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: Change check for gpu idle

Check whether gpu is idle by checking if any of its bits in
RBBM_STATUS is set except for AHB and HI bits.

Change-Id: I3dac8131a637c046d4c5cfde5935483cefaf8b53
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: Clean-up unneeded power code

No platforms with direct ebi1 connections exist, nor
is idling before changing the frequency needed.

Change-Id: I80911c81ef7303e229494ce6ba3df57ee25b24a5
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Set the GX rail voltage before enabling it

Make sure the rail turns on with a consistent voltage.  Also
this sequence moves an RPM call from after the rail is on to
before it is powered up which saves a bit of power.

Change-Id: Ided5f9777879fa48fd594c84b31cec9cdf513098
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Add traces for the constraints API

This interface helps with debugging when an application
requests for a pwrlevel constraint to be set/unset. It
also traces when the constraints actually come into affect
and when they could be revoked.

Change-Id: I638cee89253a4c2383cf082193d735fd1e279ca0
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_pwrctrl.h

msm: kgsl: fix MIN power constraints in non-trivial cases

Switching from a MAX to a MIN power constraint in the same
context is broken.  So is switching from a MAX context constraint
to a MIN constraint on a different context.  Clarify constraint
ownership, update the timestamps accordingly, and reset constraints
when changed by the context.

Change-Id: Id27dbc20e2aac994101817af3857451c1703219e
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Remove the busy waiting loop from idle_check

Previously there were issues with extra long GPU sequences
running during the idle_check NAP attempt thwarting the
transition to NAP.  With the dispatcher architecture this
is much less likely to occur.  In addition the dispatcher
increases chances of a very short pause between a command
coming in and being submitted increasing the occurence of
"micro-NAPs" being caught by this loop.  These extremely
short NAP periods are actually a power loss on the CX rail.
Given that hw clock gating will take care of any long GPU
command tails remove the busy wait loop for power savings.

Change-Id: I4efc6215689c42ab03d4e478ad97839208d04004
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

gpu: msm: Add missing trace include

Change-Id: Iefaa252a8cef43e5037f4bf3232560a44b11cb3f

msm: kgsl: Wait for dispatcher on adreno idle

When waiting for the adreno device to become idle wait for
the dispatcher to complete processing commands that are
already submitted to the ringbuffer and prevent dispatcher
from submitting more commands while a thread is waiting for
dispatcher to become idle. This is required to support mutiple
ringbuffers where it is not sufficient to just wait for current
ringbuffer to become idle. All ringbuffers need to be idle and
to do that dispatcher needs to run without submitting more
commands but retiring commands that have been submitted.

Change-Id: Idd36a8da3c230981476348682cd22aed6dab113c
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_dispatch.c

msm: kgsl: Add CFF capture for IBs

If CFF is enabled, when an IB is submitted to hardware
parse it to find all objects in it and dump them.

Change-Id: I2caecb6a9c912a59be4c0d2acdd3949c96196653
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: Use the correct method for exporting trace event functions

Use EXPORT_TRACEPOINT_SYMBOL instead of my lazy "trace" wrappers for
trace_kgsl_regwrite and trace_kgsl_issueibcmds thus saving lots of
code and a shred or two of dignity along the way.

Change-Id: Ic0dedbad4f54a7522edd2f9c3d017ba1e9dba505
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_ringbuffer.c
	drivers/gpu/msm/kgsl.h

msm: kgsl: Idle the dispatcher before writing perfcounter select

The GPU must be idle before writing to the perfcounter select
registers to avoid an AHB timeout. Idle the GPU before writing
to the register.

Change-Id: Ic0dedbadf8ad3f10f78ddf68520afe6cf98880e4
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno.c

msm: kgsl: Avoid race conditions with GPU halt variable

1. Take the device mutex before we check for GPU halt.
It's quite possible that after checking gpu halt this
thread might be preempted by kernel, other thread can
update the gpu halt. This will lead to a situation
where other thread has requested to stop sending cmds
and this thread might be sending cmds to ringbuffer.

2. Handle multiple threads changing the halt variable.
It's possible that one thread has set the halt value
and other thread clears that value.

3. init_completion() cannot be used to reinitialize
completion when reusing completion object,
INIT_COMPLETION macro should be used instead.

CRs-Fixed: 667179
Change-Id: Ie41c69be35bfd3ca14f3ce782ab45efb70aaf46a
Signed-off-by: Prakash Kamliya <pkamliya@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_dispatch.c

msm: kgsl: Avoid another race condition with GPU halt

A race condition may occur while clearing GPU halt
from _adreno_start() in one thread and at the same
time decrementing it inside adreno_put_gpu_halt()
from adreno_dispatcher_idle_unsafe() in the other
thread. This can cause BUG_ON as "halt" value would
become negative.

Clearing GPU halt inside _adreno_start() should not
be required explicitly for below reasons:
1. "halt" is member of static global variable, so it
would be initialized to zero at the beginning.
2. Commands submission to GPU from the thread executing
_adreno_start() should be blocked until "halt" is reset
back to zero from adreno_dispatcher_idle_unsafe().

CRs-Fixed: 678633
Change-Id: I06bbf4ad751a72b2e943365c1ac1952f67ac299c
Signed-off-by: Prabhat Awasthi <pawasthi@codeaurora.org>
msm: kgsl: Keep the GPU from going into a slumber after a touch event

If the GPU is on the tail end of the nap period when a new touch event
occurs the system could go into slumber before the first render which
increases the startup latency. If a touch event occurs while in nap
just kick the idle timer back out to the interval timeout - this should
keep the system from transitioning to the lower power state only to
come right back up.

Change-Id: Ic0dedbad07cac877d0a71c69516b7c01841be1bd
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
sched: Remove get_online_cpus() usage

Remove get_online_cpus() usage from the scheduler; there's 4 sites that
use it:

 - sched_init_smp(); where its completely superfluous since we're in
   'early' boot and there simply cannot be any hotplugging.

 - sched_getaffinity(); we already take a raw spinlock to protect the
   task cpus_allowed mask, this disables preemption and therefore
   also stabilizes cpu_online_mask as that's modified using
   stop_machine. However switch to active mask for symmetry with
   sched_setaffinity()/set_cpus_allowed_ptr(). We guarantee active
   mask stability by inserting sync_rcu/sched() into _cpu_down.

 - sched_setaffinity(); we don't appear to need get_online_cpus()
   either, there's two sites where hotplug appears relevant:
    * cpuset_cpus_allowed(); for the !cpuset case we use possible_mask,
      for the cpuset case we hold task_lock, which is a spinlock and
      thus for mainline disables preemption (might cause pain on RT).
    * set_cpus_allowed_ptr(); Holds all scheduler locks and thus has
      preemption properly disabled; also it already deals with hotplug
      races explicitly where it releases them.

 - migrate_swap(); we can make stop_two_cpus() do the heavy lifting for
   us with a little trickery. By adding a sync_sched/rcu() after the
   CPU_DOWN_PREPARE notifier we can provide preempt/rcu guarantees for
   cpu_active_mask. Use these to validate that both our cpus are active
   when queueing the stop work before we queue the stop_machine works
   for take_cpu_down().

CRs-fixed: 647141
Change-Id: Id41e66659574f716de0e7c29f477e56a86db9404
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Link:
http://lkml.kernel.org/r/20131011123820.GV3081@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Git-commit: 6acce3ef84520537f8a09a12c9ddbe814a584dd2
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
[kaushalk@codeaurora.org: get_online_cpus has only 3 sites of usage in
 kernel/sched/core.c of msm-3.10 so migrate_swap changes are not
 applicable here. stop_two_cpus related change is not applicable to
 msm-3.10, so skip it.]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>

Conflicts:
        kernel/sched/core.c

sched: Remove extra put_online_cpus() inside sched_setaffinity()

Commit 6acce3ef8:

        sched: Remove get_online_cpus() usage

has left one extra put_online_cpus() inside sched_setaffinity(),
remove it to fix the WARN:

   ------------[ cut here ]------------
   WARNING: CPU: 0 PID: 3166 at kernel/cpu.c:84
put_online_cpus+0x43/0x70()
   ...
   [<ffffffff810c3fef>] put_online_cpus+0x43/0x70 [
   [<ffffffff810efd59>] sched_setaffinity+0x7d/0x1f9 [
   ...

CRs-fixed: 647141
Change-Id: I33f799f30a963db3e9459832832e9c786931c8c2
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/526DD0EE.1090309@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Git-commit: ac9ff7997b6f2b31949dcd2495ac671fd9ddc990
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>

sched: Fix endless sync_sched/rcu() loop inside _cpu_down()

Commit 6acce3ef8:

        sched: Remove get_online_cpus() usage

tries to do sync_sched/rcu() inside _cpu_down() but triggers:

        INFO: task swapper/0:1 blocked for more than 120 seconds.
        ...
        [<ffffffff811263dc>] synchronize_rcu+0x2c/0x30
        [<ffffffff81d1bd82>] _cpu_down+0x2b2/0x340
        ...

It was caused by that in the rcu boost case we rely on smpboot thread to
finish the rcu callback, which has already been parked before sync in
here
and leads to the endless sync_sched/rcu().

This patch exchanges the sequence of smpboot_park_threads() and
sync_sched/rcu() to fix the bug.

CRs-fixed: 647141
Change-Id: Ia8b325d7c3c778f428d9fb51271977c849df32ad
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5282EDC0.6060003@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Git-commit: 106dd5afde3cd10db7e1370b6ddc77f0b2496a75
Git-repo:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>

sched: Remove synchronize rcu/sched calls from _cpu_down

There is no need for sync_sched() in _cpu_down as stop_machine()
provides that barrier implicitly. Removing it also helps improve
hot-unplug latency.
The sync_sched/rcu were earlier removed for the same reason by the
commit 9ee349ad6d326df3633d43f54202427295999c47, but recently got
added as part of commit c4575f83b9fe87bb57b737bc8a667f746a20320a.

CRs-Fixed: 667325
Change-Id: I97763004454d082d3cc2d9d9dbef7da923608600
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>