qseecom: Check if ce clock is enabled before sending cmd to TZ

Make change to check if ce clock is enabled before sending command
to TZ, then to prevent data aborting if clock is not enabled for
TZ crypto operation.

CRs-Fixed: 726840
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
Signed-off-by: William Clark <wclark@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
qseecom: Enable/disable clock for client if bus scaling is not enabled

To avoid the service failure on a target where bus scaling flag is not
enabled in target device tree file by mistake, make a change to enable/
disable crypto clocks when the client calls to scale up bus bandwidth
and send command even if bus scaling feature is not enabled.

Signed-off-by: Zhen Kong <zkong@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
mmc: core: Fix unclocked access in get_xfer_remain/stop_request

The unclocked access could happen in the following scenario -

1. mmcqd thread is waiting for previously submitted io to be done
2. before this io is done, it is woken up due to is_urgent event
3. mmcqd thread is running and is processing the is_urgent event
4. Just about the same time the previously submitted io is done and
it sets is_done_rcv flag, tries to wake up mmcqd thread and release
host clock so as to gate the clocks.

If step 3 and 4 happen at the same time, then clocks will be gated off
before is_urgent is completely handled. Hence, make sure to hold the
clock before invoking get_xfer_remain and stop_request host->op.

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ARM: validate address before dumping it in OOPS message

As a part of kernel OOPS message, kernel treats every register
as memory pointer and dumps the memory area from an offset of
0x80. Add check to see if its a valid virtual address before
dumping it.

Such addresses may be part of CMA regions and they may
be protected at times. Therefore, while dumping such addresses
violations can potentially occur.

Additionally validate the pfn first as it may belong to a
carveout region which has no associated page object.

Add check to see if they belong to CMA region and don't dump
such addresses altogether to be safe.

CRs-Fixed: 696028,737215
Signed-off-by: Vignesh Radhakrishnan <vigneshr@codeaurora.org>
Signed-off-by: Shiraz Hashim <shashim@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
kprobe: delay blacklist symbol lookup

The symbol lookup can take a long time and kprobes
is iniitilized very early in boot, So delay symbol
lookup until the blacklist is first used.

Signed-off-by: Rahul Sharma <sharah@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
block: Switch from BFQ-v7r5 for 3.4.0 to BFQ-v7r6 for 3.4.0

. IMPROVEMENT: Introduced a new mechanism that helps get the job done
  more quickly for services and applications that create or reactivate
  many parallel I/O-bound processes. Examples are systemd at boot, or
  commands such as git grep.
. CODE IMPROVEMENTS: Small code cleanups and improvements.

Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
OOM, PM: OOM killed task shouldn't escape PM suspend

PM freezer relies on having all tasks frozen by the time devices are
getting frozen so that no task will touch them while they are getting
frozen. But OOM killer is allowed to kill an already frozen task in
order to handle OOM situtation. In order to protect from late wake ups
OOM killer is disabled after all tasks are frozen. This, however, still
keeps a window open when a killed task didn't manage to die by the time
freeze_processes finishes.

Reduce the race window by checking all tasks after OOM killer has been
disabled. This is still not race free completely unfortunately because
oom_killer_disable cannot stop an already ongoing OOM killer so a task
might still wake up from the fridge and get killed without
freeze_processes noticing. Full synchronization of OOM and freezer is,
however, too heavy weight for this highly unlikely case.

Introduce and check oom_kills counter which gets incremented early when
the allocator enters __alloc_pages_may_oom path and only check all the
tasks if the counter changes during the freezing attempt. The counter
is updated so early to reduce the race window since allocator checked
oom_killer_disabled which is set by PM-freezing code. A false positive
will push the PM-freezer into a slow path but that is not a big deal.

Changes since v1
- push the re-check loop out of freeze_processes into
  check_frozen_processes and invert the condition to make the code more
  readable as per Rafael

Fixes: f660daac474c6f (oom: thaw threads if oom killed thread is frozen before deferring)
Cc: 3.2+ <stable@vger.kernel.org> # 3.2+
Signed-off-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Revert "lzo: properly check for overruns"

This reverts commit ("lzo: properly check for overruns").

As analysed by Willem Pinckaers, this fix is still incomplete on
certain rare corner cases, and it is easier to restart from the
original code.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
lzo: check for length overrun in variable length encoding.

This fix ensures that we never meet an integer overflow while adding
255 while parsing a variable length encoding. It works differently from
commit 206a81c ("lzo: properly check for overruns") because instead of
ensuring that we don't overrun the input, which is tricky to guarantee
due to many assumptions in the code, it simply checks that the cumulated
number of 255 read cannot overflow by bounding this number.

The MAX_255_COUNT is the maximum number of times we can add 255 to a base
count without overflowing an integer. The multiply will overflow when
multiplying 255 by more than MAXINT/255. The sum will overflow earlier
depending on the base count. Since the base count is taken from a u8
and a few bits, it is safe to assume that it will always be lower than
or equal to 2*255, thus we can always prevent any overflow by accepting
two less 255 steps.

This patch also reduces the CPU overhead and actually increases performance
by 1.1% compared to the initial code, while the previous fix costs 3.1%
(measured on x86_64).

The fix needs to be backported to all currently supported stable kernels.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Documentation: lzo: document part of the encoding

Add a complete description of the LZO format as processed by the
decompressor. I have not found a public specification of this format
hence this analysis, which will be used to better understand the code.

Cc: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cpufreq / stats: fix race between stats allocation and first usage

This patch forces complete struct cpufreq_stats allocation for all cpus before
registering CPUFREQ_TRANSITION_NOTIFIER notifier, otherwise in some conditions
cpufreq_stat_notifier_trans() can be called in the middle of stats allocation,
in this case cpufreq_stats_table already exists, but stat->freq_table is NULL.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cpufreq / stats: Get rid of CPUFREQ_STATDEVICE_ATTR

Macro "CPUFREQ_STATDEVICE_ATTR" is defined local to cpufreq_stats.c file and is
almost a copy of the generic version present in cpufreq.h file. Lets use the
generic version instead.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm8974: Add ultra-low-latency audio instance

 * Replace deprecated LPA output with new ULL feature.

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: remove internal details from header

Some internal details no longer need to be shared between modules, so
they can be moved to the main implementation file to avoid unnecessary
coupling in the future.

Change-Id: Ie8774f0c95f5ec6a56a95c57fea79032194eb05e
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: add client version support

If clients use custom serialization functions, then they may need to
define a version for deserialization support for log extraction.

Add client version support.

Change-Id: Id135f06d4142de39275b5d0caab88708d5496b5e
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: add locking hierarchy

Add locking hierarchy to allow identification of deadlocks by code
inspection.

Change-Id: I41cd479d72be7b2c729fbf09b5b89180c0a11191
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: enhance log-extraction support

One of the main goals of the IPC Logging is to allow extracting logs
from memory dumps.  The current implementation has the following
limitations:

  1) if logs are being dumped through debugfs at the time of the crash,
     it is not possible to extract logs that were already dumped

  2) it is not always possible to tell the difference between empty,
     partially full, and full log pages resulting in extraction
     complications

  3) if the system memory is not cleared between reboots, then the same
     log ID and log page may be extracted leading to duplicate log
     pages

Add additional debugfs read index, timestamps for log pages, and change
the read/write indices to easily differentiate between empty, partially
full, and full log pages.

CRs-Fixed: 670345
Change-Id: I695f6e0605f3755b868ede59851f5ca919f8fb0d
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: reset completion instead of reinitializing

init_completion() is being used to reinitialize the read completion
which will cause problems if complete_all() is ever used.

Use INIT_COMPLETION instead of init_completion() to reinitialize
the completion.

Change-Id: I33a78559d9debb6c90a039bd9f22f391c6c15f27
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: fix non-destructive read logic

When dumping logs through debugfs, a non-destructive read is performed
and after all data has been printed, the call waits on a completion for
new log data.  When that event is completed, the entire contents of the
logs are incorrectly printed.

Fix the read logic to correctly update the non-destructive read pointer
such that only the new data is printed to the logs.

CRs-Fixed: 681317
Change-Id: Ia12787b576b18b9f5174cefe91eb283979c286f7
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ipc_logging: Validate the next page pointer

Validate the pointer returned from get_next_page function.

Change-Id: I32d7c0771d116186fffb206335993f6114e303f8
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>