msm: ipc: Possible memory corruption due to Sign Conversion

msm_ipc_router_skb_to_buf() takes an unsigned argument and assigns the
same to a signed local variable. This might cause issues when the value
of the argument is too high.

Change the datatype of the local variable to unsigned.

CRs-Fixed: 550606
Change-Id: I257a095681dd82fba05367fd6faf25820e95c719
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Set unsupported protocol operations to default operations

Some of the socket system calls do not check the validity of the
operations supported by the protocol. This in turn leads to NULL
pointer dereference.

Set the operations that are not supported by IPC Router to default
operations.

CRs-Fixed: 573295
Change-Id: Iba94b1403fa84dbe712255cc10677e9ef0848100
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm_ipc_router: Allow processes in the oncrpc group to use it freely

Instead of adding rild to the current catch-all net-raw group,
treat the oncrpc group as another catch-all.
msm: kgsl: Enable the shader corruption workaround for all A3XX targets

The power-on shader corruption workaround is required for all A3XX
targets.

CRs-fixed: 556872
Change-Id: Ic0dedbad5ef5a1bfec7cba148a652e1766517e57
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Change an overflow check to be "smart" compiler proof

In its infinite wisdom, GCC will optimize out this overflow check:

   if ((gpuaddr + size) < gpuaddr)

Which might totally make sense for the compiler but it doesn't do us
a bit of good. Replace the existing overflow check with something
that GCC can't ignore.

CRs-fixed: 544025
Change-Id: Ic0dedbad921545a01d5fe80a20c3f2f4f86ef641
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Return NULL when done parsing the profiler assignments string

The assignment string parser has a corner condition wherein the user
can craft a malicious string that contains a \0 and force a buffer
overrun.  Avoid this by always returning NULL when the parser encounters
a \0.

CRs-fixed: 547601
Change-Id: Ic0dedbad946e597a5a245df41239b89f114ba9ee
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Fix overflow check in mmap_range_valid

A eager compiler might optimize out the overflow check in
mmap_range_valid.  Add a check against ULONG_MAX to ensure
that the check is performed.

CRs-fixed: 546373
Change-Id: Ic0dedbad478cc3bd65a00a7b31d2039095c005d6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Switch to default pagetables in case of NULL context

Switch to default pagetables when context is NULL. This prevents
instances of page faults when switching to default pagetable when
GPU is busy.

CRs-fixed: 550082
Change-Id: I74bab681b823bf50e58b50b6cb819fbf93163bf7
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Handle failure of find_process_private()

Handle the case of NULL return from find_process_private() upon
its failure by failing from get_process_private().

Change-Id: Id42ae795d140bd67d8a36496f840387858e5f779
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Enable GPU hang interrupt

Enable and use GPU hang interrupt to detect GPU hangs.
If the GPU hang is not detected using the interrupt we
still have the hang timer to detect GPU hangs. When
hang is detected using GPU hang interrupt fault tolerance
is triggered. Fault tolerance time is less than 50ms with
GPU hang interrupt.

Conflicts:

	drivers/gpu/msm/adreno.h
	drivers/gpu/msm/adreno_a2xx.c
	drivers/gpu/msm/adreno_a3xx.c
	drivers/gpu/msm/adreno_ringbuffer.c

CRs-Fixed: 512795
Change-Id: I9327803f178ae1b5e8248fe3450499b7bba2a68d
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Set FSR to 0 on IOMMU pagefault

On IOMMU pagefault the FSR is not cleared until the IOMMU
is reset and re-attached to the GPU device. Until FSR clears
the system will keep generating fault interrupts. Clear the
FSR when iommu is stopped in kgsl driver to prevent system
from generating additional fault interrupts for the same
fault until the IOMMU is re-attached

Change-Id: Ia56bbd1245a84a001ec8464f73cfedf2a2d312c2
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: GPU pagefault policy change to not stall on pagefault

GPU pagefault policy is changed to not stall on pagefault, most
of the time GPU pagefault is harmless and stalling for every
pagefault is not required on a commercial device. Sysfs option
to stall on pagefault exists for developers to debug pagefault.

Change-Id: Iecdcc2d57f09a56a2d4830943616702426d3d83e
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Don't spam the kernel log if qcom,step-pwrlevel isn't found

qcom,step-pwrlevel is a specific parameter that only applies to
certain targets.  Don't spam the world if it isn't specified.

CRs-fixed: 556418
Change-Id: Ic0dedbad65dbdcf9bc227fef4a796e22131ba68f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Try to run soft reset on all targets that support it

Run soft reset on all targets that define a soft_reset function hook.
If the target defines jump table offsets then we can run through a
faster reset sequence, otherwise default to the slower full reset
path.  In any event, both these options are much faster than the
hard reset path that toggles the regulators.

CRs-Fixed: 519855
Change-Id: I0ff1ea61dbe46afe08e04b2292949cf631514d99
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Verify the user address before reading a perfcounter group

In adreno_perfcounter_read_group some user input verification is
occuring on a user pointer before copy_from_user is called
resulting in a possible segmentation fault if called with improper
input data.

CRs-fixed: 553314
Change-Id: Ic0dedbad4c5e4b2610368d51ff591d1f716712f4
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Restructure performance counters

Restructure the performance counter mechanism by combining the two
structures declared for it. The 2 structures can only refer to a
single counter hence it is easier to manage by having them
under a single structure.

Change-Id: I19d13cf5aa619b85a332b383b464c2af65ad38c9
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Save/restore performance counters across GPU power collapse

Physical performance counters are reset on GPU power collapse.
Save the values of the performance counters when the GPU goes to
power collapse and restore them on restart.

Change-Id: I63bec7b20e7fe516bbac4901cac0af3a1c1f4959
Signed-off-by: Harshdeep Dhatt <hdhatt@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Get reference to process private when attaching mem entry

When a memory entry is attached with to a process private list then
increment the refcount of the process private structure so that the
structure is valid as long as the entry is around. The context
structure is also handled in similar manner. Also, the refcount to
the entry needs to be decremented when the handle that created the
entry goes away and not when the process private structure is
destroyed.

Conflicts:
        drivers/gpu/msm/kgsl.c

Change-Id: I225698ad4081947a93eb553104e5259bbf31f293
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Shrenuj Bansal <shrenujb@codeaurora.org>
msm: kgsl: Don't resume MMU before detaching domain

In cases of page fault, resuming the MMU before detaching
the domain locks up the MMU and causes erroneous behavior.
To avoid this, only resume the MMU after detaching the domain.
Additionally, do not attempt soft reset in cases of page faults.

CRs-fixed: 550840
Change-Id: I0c8ea79d802d8b8d29e03af6f3153ee6c3401400
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Add TSE performance counter to software hang detection

Our current hang detection logic covers rendering pass by checking for
shader performance counters but it does not cover the case where there
is long binning or resolve pass. For long binning pass shader is inactive
making our current hang detection logic faulty. Checking for TSE number of
input primitives covers binning and resolve passes and makes our hang
detection logic robust.

CRs-fixed: 521284
Change-Id: Ifdec4b53685903456feb367f64380119b1485408
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>