sched: fix race between try_to_wake_up() and move_task()

Until a task's state has been seen as interruptible/uninterruptible
and it is no longer on_cpu, it is possible that the task may move
to another CPU (load balancing may cause this). Here is an example
where the race condition results in incorrect operation:

- cpu 0 calls put_prev_task on task A, task A's state is TASK_RUNNING
- cpu 0 runs task B, which attempts to wake up A
- cpu 0 begins try_to_wake_up(), recording src_cpu for task A as cpu 0
- cpu 1 then pulls task A (perhaps due to idle balance)
- cpu 1 runs task A, which then sleeps, becoming INTERRUPTIBLE
- cpu 0 continues in try_to_wake_up(), thinking task A's previous
  cpu is 0, where it is actually 1
- if select_task_rq returns cpu 0, task A will be woken up on cpu 0
  without properly updating its cpu to 0 in set_task_cpu()

CRs-Fixed: 665958
Change-Id: Icee004cb320bd8edfc772d9f74e670a9d4978a99
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
crypto: msm: Add support for FIPS complience

FIPS140-2 certification asks to do a Power on Known Answer tests on each
algorithm which is getting certified. This patch implements the self tests
and hardcoded test vectors.  Also, we need to verify the integrity of
kernel as soon as it boots up. This patch also adds an ioctl for
integrity test along with ioctl to query FIPS status (pass / fail) from
user land.
also, The piece of code is added for FIPS compliance DRBG under
drivers/char/hw_random
This change is already merged to KK mainline.

Change-Id: I7f3355602d5c2dfaefce0c0e4f9225fde0c5f485
Signed-off-by: Dinesh K Garg <dineshg@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
crypto: msm: Compilation flag in  Kconfig For FIPS

Added a FIPS_ENABLE flag under drivers/crypto/Kconfig
which will be enabled/disabled according to defconfig
file selection of CONFIG_FIPS_ENABLE
This change is already merged to KK mainline.

Change-Id: I8d2c1278598e255027e4427483ed9d4e684b2839
Signed-off-by: Dinesh K Garg <dineshg@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
net: socket: Added notifier chains for socket administrative functions

Allows other areas in the kernel to register notifier callbacks which
get invoked whenever something performs an administrative action on a
socket. This patch adds hooks in socket(), bind(), listen(), accept(),
shutdown().

CRs-Fixed:  626021
Change-Id: I4ae99cb2206d7c4eddba69757335c18d10143045
Signed-off-by: Harout Hedeshian <harouth@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
net: sockev: Initial Commit

Added module which subscribes to socket notifier events. Notifier events
are then converted to a multicast netlink message for user space
applications to consume.

CRs-Fixed:  626021
Change-Id: Id5c6808d972b69f5f065d7fba9094e75c6ad0b2c
Signed-off-by: Harout Hedeshian <harouth@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Config GPIOs by name rather then by index

Currently GPIOs are identified (MISO/MOSI/CLK or CS0..3)
by their index in the device-tree entry's array.
Further, chipselect GPIOs must be declared in order.
This allows to set a value for GPIO number three only
if the values for GPIOs one and two are also set.
This patch allows the driver to identify GPIOs by a
unique name, thus allows to specify any arbitrary
chipselect GPIO and reduces chances of simple
user configuration error.

Change-Id: I7cf1fb4329155bd5fc635257fc58d1dfa7312462
Signed-off-by: Gilad Avidov <gavidov@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: correct the chip select gpios valid field entry

During probe Chip select gpio's valid field is set to non-zero.
This is causing gpio free to get called for not-used gpios
during runtime suspend.

CRs-Fixed: 525743
Change-Id: Ib0de417d640f30908ad11650b584833dac286646
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Remove check for unaligned  length during input_irq

QUP_IRQ complete is triggered before dmov_rx callback.
Which will initiate SPI to start next transfer, due to
this earlier DMOV_CMD is blocked and results in kernel panic.

Current Implementation  make sure that transfer complete waits
For DMOV callback only in case of aligned lengths ,This patch
ensures transfer trigger only after DMOV RX call back for
unaligned length also.

CRs-Fixed: 583126
Change-Id: I306a705d0eaf0eac33b2dbf335992254351cce20
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Add support for multiple BAM descriptors

Currently SPI driver is queuing a single BAM descriptor
at a time. The BAM engine supports queuing of multiple
transfer descriptors.

Add support to spi driver to queue multiple descriptors.

CRs-Fixed: 546346
Change-Id: Iaee9b3b362832262b75e46e19ad18552d037620b
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Add core message queue feature

Add support to use new message queue feature provided
by SPI core framework. It is having benefits of saving
code space and getting the benefits of improvements
implemented in the core. User can set the priority
of message queue at compile time.

CRs-Fixed: 458268
Change-Id: I3f3a70b20ed6f2c8ceb9c27d616c5ba19acb422c
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Fix bug in multi-xfer bam mode transaction

Spi doesn't handle multiple xfer per message scenario
(eg:Rd->Wr or Wr->Rd) correctly and spi request
stuck indefinetly in while loop when total byte count
is not 0.

increment both(rx,tx) references so next bam
transaction will be queued correctly. Flush the
bam pipes after each transactions.

CRs-Fixed: 637693
Change-Id: I455df38be2f9687b1eb2a704466f6974dfb83a22
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
spi_qsd: Initialize wait queue

Due to missing initialization of wait queue
issues reported on customer builds. This patch
adds the missing wait queue initialization code.

Change-Id: I2150d94bfec74b26842aac4fbd0e2e44af3b9943
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
USB: ccid_bridge: Add support for USB smart card class

This module implements a bridge driver which allows user space
to communicate with USB smart card devices.  This module provides
/dev/ccid_bridge device file which allows read/write/ioctl methods.
The ioctls facilitate control and interrupt transfers.  The bulk
transfers are implemented via read and write.  The interrupt
endpoint is optional and not all devices may support it.

Change-Id: I67ac7c7d15fb65c8f6a2cc9f9c81343da074aab7
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
USB: ccid_bridge: Don't kill URB in release after device is disconnected

The URBs are killed in disconnect method. If the device is disconnected
before the /dev/ccid_bridge is closed, no need to kill the URBs again.
As the URB reference count is dropped in disconnect, accessing it in
release is causing the kernel panic.

CRs-Fixed: 653776
Change-Id: I7fae9ac2568cce59ea39bdd73c955d388d3f26bd
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
USB: ccid_bridge: Provide bulk message write/read stats via debugfs

The bulk message timeouts are observed occasionally during mass storage
transfers. This debug facility helps in identifying such timeout issues.

The sample output of the stats debugfs file.

ccid_bridge: connected
ccid_bridge: opened
total writes: 444
total reads: 444
write/read timeout val: 1000
write_timeout: 0
read_timeout: 0
write_max_time (msec): 130
read_max_time: (msec): 857

CRs-Fixed: 659909
Change-Id: I9787288c10d23b176c9316feed82d41bd2adae65
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
[PATCH] Staging: android: binder: More offset validation.

Make sure offsets don't point to overlapping flat_binder_object
structs.

Change-Id: I425ab0c46fbe2b00ed679c5becf9e8140395eb40
Signed-off-by: Arve HjÃ¸nnevÃ¥g <arve@android.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
[PATCH] netlink: add signed types

Signed types might be needed in NL communication from time to time
(I need s32 in team driver), so add them.

Change-Id: Icc6c8286a1d55313fcc7993d8b02267fe1ef2bdc
CRs-Fixed: 677858
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
cpufreq: interactive: Choose highest frequency below or at target

This generally saves us one freq level.

Signed-off-by: Dan Trifan <jimsth@gmail.com>
cpufreq: Always allow update of user policy

In the cases where the system boots up in a constraint with policy min and
max lower than cpuinfo min/max, and user tries to set a higher user
policy min, the value would be overridden during the verifying the
limits.

Once user initiates the sysfs write the previous user policy is
maintained in policy min and max thus changing the limits for verification
of the current policy. Once the verification is completed restore the
current user policy min/max with the updated values if any. This would take
care of cases uwhere user policy min/max input is higher/lesser than the
current min and max.

Change-Id: I5ad92ba05162cb5c32c3ba3fdae21d2e505493d3
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: pm: Increase cpu collapse timeout

20ms is still not enough, try 30ms.

<4>[  670.307705] ------------[ cut here ]------------
<4>[  670.308133] WARNING: at arch/arm/mach-msm/msm-pm.c:792 msm_pm_wait_cpu_shutdown+0x9c/0xb0()
<4>[  670.308351] CPU2 didn't collapse in 2 ms
<4>[  670.308839] [<c010dfb8>] (unwind_backtrace+0x0/0x144) from [<c0a26304>] (dump_stack+0x20/0x24)
<4>[  670.310590] [<c0a26304>] (dump_stack+0x20/0x24) from [<c019b610>] (warn_slowpath_common+0x58/0x70)
<4>[  670.311848] [<c019b610>] (warn_slowpath_common+0x58/0x70) from [<c019b6a4>] (warn_slowpath_fmt+0x40/0x48)
<4>[  670.313030] [<c019b6a4>] (warn_slowpath_fmt+0x40/0x48) from [<c0179500>] (msm_pm_wait_cpu_shutdown+0x9c/0xb0)
<4>[  670.313580] [<c0179500>] (msm_pm_wait_cpu_shutdown+0x9c/0xb0) from [<c01260bc>] (platform_cpu_kill+0x38/0x48)
<4>[  670.320147] [<c01260bc>] (platform_cpu_kill+0x38/0x48) from [<c010c5a8>] (__cpu_die+0x4c/0x98)
<4>[  670.320767] [<c010c5a8>] (__cpu_die+0x4c/0x98) from [<c09fb544>] (_cpu_down+0xf8/0x2e0)
<4>[  670.321029] [<c09fb544>] (_cpu_down+0xf8/0x2e0) from [<c09fb7d0>] (cpu_down+0x34/0x50)
<4>[  670.321452] [<c09fb7d0>] (cpu_down+0x34/0x50) from [<c01943c4>] (cpu_down_work+0x120/0x154)
<4>[  670.321924] [<c01943c4>] (cpu_down_work+0x120/0x154) from [<c01b59a4>] (process_one_work+0x178/0x4f4)
<4>[  670.322385] [<c01b59a4>] (process_one_work+0x178/0x4f4) from [<c01b60a0>] (worker_thread+0x174/0x448)
<4>[  670.322795] [<c01b60a0>] (worker_thread+0x174/0x448) from [<c01bc454>] (kthread+0xb4/0xc0)
<4>[  670.323049] [<c01bc454>] (kthread+0xb4/0xc0) from [<c0108060>] (kernel_thread_exit+0x0/0x8)
<4>[  670.323699] ---[ end trace 26c4346f4c26704b ]---

Signed-off-by: Dan Trifan <jimsth@gmail.com>