cpufreq: force cpuN policy to match cpu0 when changing freq or gov

(cherry picked from commit 3a6afd3e14e441950ffe80699688db53e374905d)

(cherry picked from commit 9930e35537757264488c4fb6d617a6811da47e3c)

(cherry picked from commit be00c970b46254333a382bbbdabbb2b6040ebf56)

(cherry picked from commit 341777c7de3b0afb7e2906c5556d8bc903aa70aa)
fs: sync: Asynchronous Fsync from HTC

    * taken from Faux's S5 repo and modified/fixed-up
      for Linux 3.10 and shamu

(cherry picked from commit 8c1fdece03510efc8129e1289141c1b6f3ed2c20)

(cherry picked from commit 5483f6ae676b452f60fd346577cba5143b2f4716)

(cherry picked from commit c981ff38ea970c280188a1a9fd0b6d0a25f9535a)

(cherry picked from commit b8d2eb72b136af1dfb4c1a4cca807d895c7341a5)
cpufreq: force cpuN policy to match cpu0 when setting min freq

* I omitted this on purpose before on N3 but no need to do that
for shamu

(cherry picked from commit 0b9948790567748d7dd34a74ff593277d4fc13c2)

(cherry picked from commit 071c295230659f093096b5be633d108a10f0e4f2)

(cherry picked from commit 31deba13ab3386d57823060fc715941dac7f73d7)

(cherry picked from commit 4060af1fb5e7167f88b30b2a2a720cad9be9dd92)
cpufreq: Return directly in __cpufreq_get if policy is NULL

__cpufreq_get() checks whether policy->cur matches frequency returned
by cpufreq device driver and acts accordingly. However, policy could
be NULL if the CPU is being hotplugged. Current implementation crashes
when trying to dereference the NULL policy.

Return the frequency provided by cpufreq device driver directly if
policy is not available.

Change-Id: I1f2ba4028c259392bf730db37dbec2d8c5ae3fa4
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>

(cherry picked from commit 4f32e7eaf49b07f184348c297b8eebe969181131)

(cherry picked from commit 3f663571c2ab873452db10288e075dcdf3c9ca24)

(cherry picked from commit 6417c65cc195ecbc4bc98a853e77b886063c73fd)

(cherry picked from commit 369b28f8ff5ce82ffebee6f6a49d0127a5737ffb)
cpufreq: Protect against hotplug in cpufreq_register_driver()

cpufreq_register_driver() could race with CPU hotplug during
bootup. Since hotplug notification is not registered when
subsys_interface_register() is being executed, it's possible
cpufreq's view of online CPUs becomes stale before it registers
for hotplug notification.

Register for hotplug notification first and protect
subsys_interface_register() against hotplug using
get/put_online_cpus().

Change-Id: I26b2908f1d167c2becc4e8664c357bb7c6162406
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>

(cherry picked from commit ff98b9d2abcb47cbb6dfddb16ac9aa01992df17a)

(cherry picked from commit e9f320a4a4aa78139748749fb2ec72c2bac495f2)

(cherry picked from commit 590a3c1608c26e5e6274fc33f455f1fd8293b03b)

(cherry picked from commit 45cd77b26e849aefc7a4b67f7684d7aaa8173bd5)
f2fs: updated to "call flush_dcache_page when the page was updated"

(cherry picked from commit d1b794edaf6bbadbe8ac85692f4d84fd4b665588)

(cherry picked from commit 9d70412f8903ac0c3f5b2b566b1736aa04f967a5)

(cherry picked from commit 8b340489edf7be1bf03264c4d5cecd481004ae26)

(cherry picked from commit 7ce4473cf4b625039306cf2d8f8f8a3202144941)
random: entropy tweaks are all the rage nowadays

use non-blocking pool for all

http://lwn.net/Articles/489734/

Conflicts:

	drivers/char/random.c

Conflicts:
	drivers/char/random.c

(cherry picked from commit d0e606f8d5409d975941ce45636af5d071a442d6)

(cherry picked from commit 26eab4e4c9c70b8d13a63a3033f3a4a03a59c16c)

(cherry picked from commit 7d5198cb7ca7b42691d6090b49fbfa386001771d)

(cherry picked from commit d1222cf7e135ad254633226a49e2527300d52f04)
random: prevent add_input from doing anything

(cherry picked from commit dde6d47374f7d61d396b6adba1e13d131723dae9)

(cherry picked from commit 7fa54be6838959137f3b57f85a96f57c833fbc0e)

(cherry picked from commit eb427c13c0fd13f17c73fcef1b71bb29f36aa564)

(cherry picked from commit 23a7bcf636cd2a605b9571c0876c80f0174d5528)
random: remove warning

(cherry picked from commit b714a57f97cdc27e6aabafcd5a9af9550bfcaadd)

(cherry picked from commit 87faf55cc8653e4807e2bf5af603c9d003fc5b85)

(cherry picked from commit d8b37764c81b64c263ded2ef801ddd4fc5ab905b)

(cherry picked from commit 8879d44efeac7755b14ec1d0e26b22cd7abcdb18)
qcom-cpufreq: ignore rounded calculation for underclock min frequency

    * hack: do this better later

(cherry picked from commit eb6849aaddbc5549906b6acadffe28a7ca766d6f)

(cherry picked from commit 5a7dfc0c5a574e809d96f340bc1f460a978e4396)

(cherry picked from commit 35f3fadf4e8ecf9bb76c458cc9d508031b340d03)

(cherry picked from commit 2132b5e25e0a5a311d5d3d36f8abd7ac6fb89895)
msm: mdss: properly handle panel on and off

There is some condition that panel off will be called multiple times.
In this case, it was blindly free the gpios that were already released.
This is adding the check to handle this condition.

Change-Id: I0140872be1255fe00ed5abd164a246fa57b2a245
Signed-off-by: Xiaoming Zhou <zhoux@codeaurora.org>

(cherry picked from commit 985f9002d4c618891aaa1faa09cc4965532f9fd4)

(cherry picked from commit dcbfb2d4c3f03602368ceb940841d4002b9bae22)

(cherry picked from commit a18a178cad05d7c25f9382a2797f7f95a085df7d)

(cherry picked from commit b408af45adc59ab08af662941a0554a302e454c4)
char: frandom: initial commit v1.1

    Based on my dd test:
      hw_random (msm_rng): 0.56 MB/s
      linux random/urandom: 4.4 MB/s
      frandom/erandom: 90 MB/s

(cherry picked from commit bed32bc30aadd0610b9fce02e7b9fc74a8543d92)

(cherry picked from commit 1d5cc7bfac1782a8a7d7a9b051da0378902819dd)

(cherry picked from commit 73de452f84ac30f9b9f4643594a7eb246cd63bb8)

(cherry picked from commit 9dafbf759fee1c24c413ada426a4764bee656231)
random32: add periodic reseeding

The current Tausworthe PRNG is never reseeded with truly random data after
the first attempt in late_initcall. As this PRNG is used for some critical
random data as e.g. UDP port randomization we should try better and reseed
the PRNG once in a while with truly random data from get_random_bytes().

When we reseed with prandom_seed we now make also sure to throw the first
output away. This suffices the reseeding procedure.

The delay calculation is based on a proposal from Eric Dumazet.

Joint work with Daniel Borkmann.

Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit dcb36cbb58cd90c3af374f5b89b7c514407b510b)

(cherry picked from commit 36ce90e0ebba6539b970ea85215dd9d4782ee349)

(cherry picked from commit cab4b84d9ae96ea355b5df9e72ed474a5b9b6d21)
random32: add prandom_reseed_late() and call when nonblocking pool becomes initialized

The Tausworthe PRNG is initialized at late_initcall time. At that time the
entropy pool serving get_random_bytes is not filled sufficiently. This
patch adds an additional reseeding step as soon as the nonblocking pool
gets marked as initialized.

On some machines it might be possible that late_initcall gets called after
the pool has been initialized. In this situation we won't reseed again.

(A call to prandom_seed_late blocks later invocations of early reseed
attempts.)

Joint work with Daniel Borkmann.

Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit 98724f2994193aa4d03f9c50da8b365beb4c050b)

(cherry picked from commit fef0b95e9a95edf3f20f8e78151df38e754027d8)

(cherry picked from commit 52b098fecdb71c60f4a0ec217eac9bf806d80e66)

(cherry picked from commit 02a4b923f829d1b8da42545a101978a6ed201d0f)
random32: move rnd_state to linux/random.h

struct rnd_state got mistakenly pulled into uapi header. It is not
used anywhere and does also not belong there!

Commit 5960164fde ("lib/random32: export pseudo-random number
generator for modules"), the last commit on rnd_state before it
got moved to uapi, says:

  This patch moves the definition of struct rnd_state and the inline
  __seed() function to linux/random.h.  It renames the static __random32()
  function to prandom32() and exports it for use in modules.

Hence, the structure was moved from lib/random32.c to linux/random.h
so that it can be used within modules (FCoE-related code in this
case), but not from user space. However, it seems to have been
mistakenly moved to uapi header through the uapi script. Since no-one
should make use of it from the linux headers, move the structure back
to the kernel for internal use, so that it can be modified on demand.

Joint work with Hannes Frederic Sowa.

Cc: Joe Eykholt <jeykholt@cisco.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit 7c74769c35269c306365cb7ff13bd360d09abfa5)

(cherry picked from commit 36bd442380c6f4ef69972873f40b9cb3de1efb2b)

(cherry picked from commit 220964e7da5e7b232044c0dd1bc94ccdfdd6b76c)

(cherry picked from commit 7c8fed76176bbe5a24f806b749c1b418135d04d3)
random32: upgrade taus88 generator to taus113 from errata paper

Since we use prandom*() functions quite often in networking code
i.e. in UDP port selection, netfilter code, etc, upgrade the PRNG
from Pierre L'Ecuyer's original paper "Maximally Equidistributed
Combined Tausworthe Generators", Mathematics of Computation, 65,
213 (1996), 203--213 to the version published in his errata paper [1].

The Tausworthe generator is a maximally-equidistributed generator,
that is fast and has good statistical properties [1].

The version presented there upgrades the 3 state LFSR to a 4 state
LFSR with increased periodicity from about 2^88 to 2^113. The
algorithm is presented in [1] by the very same author who also
designed the original algorithm in [2].

Also, by increasing the state, we make it a bit harder for attackers
to "guess" the PRNGs internal state. See also discussion in [3].

Now, as we use this sort of weak initialization discussed in [3]
only between core_initcall() until late_initcall() time [*] for
prandom32*() users, namely in prandom_init(), it is less relevant
from late_initcall() onwards as we overwrite seeds through
prandom_reseed() anyways with a seed source of higher entropy, that
is, get_random_bytes(). In other words, a exhaustive keysearch of
96 bit would be needed. Now, with the help of this patch, this
state-search increases further to 128 bit. Initialization needs
to make sure that s1 > 1, s2 > 7, s3 > 15, s4 > 127.

taus88 and taus113 algorithm is also part of GSL. I added a test
case in the next patch to verify internal behaviour of this patch
with GSL and ran tests with the dieharder 3.31.1 RNG test suite:

$ dieharder -g 052 -a -m 10 -s 1 -S 4137730333 #taus88
$ dieharder -g 054 -a -m 10 -s 1 -S 4137730333 #taus113

With this seed configuration, in order to compare both, we get
the following differences:

algorithm                 taus88           taus113
rands/second [**]         1.61e+08         1.37e+08
sts_serial(4, 1st run)    WEAK             PASSED
sts_serial(9, 2nd run)    WEAK             PASSED
rgb_lagged_sum(31)        WEAK             PASSED

We took out diehard_sums test as according to the authors it is
considered broken and unusable [4]. Despite that and the slight
decrease in performance (which is acceptable), taus113 here passes
all 113 tests (only rgb_minimum_distance_5 in WEAK, the rest PASSED).
In general, taus/taus113 is considered "very good" by the authors
of dieharder [5].

The papers [1][2] states a single warm-up step is sufficient by
running quicktaus once on each state to ensure proper initialization
of ~s_{0}:

Our selection of (s) according to Table 1 of [1] row 1 holds the
condition L - k <= r - s, that is,

  (32 32 32 32) - (31 29 28 25) <= (25 27 15 22) - (18 2 7 13)

with r = k - q and q = (6 2 13 3) as also stated by the paper.
So according to [2] we are safe with one round of quicktaus for
initialization. However we decided to include the warm-up phase
of the PRNG as done in GSL in every case as a safety net. We also
use the warm up phase to make the output of the RNG easier to
verify by the GSL output.

In prandom_init(), we also mix random_get_entropy() into it, just
like drivers/char/random.c does it, jiffies ^ random_get_entropy().
random-get_entropy() is get_cycles(). xor is entropy preserving so
it is fine if it is not implemented by some architectures.

Note, this PRNG is *not* used for cryptography in the kernel, but
rather as a fast PRNG for various randomizations i.e. in the
networking code, or elsewhere for debugging purposes, for example.

[*]: In order to generate some "sort of pseduo-randomness", since
get_random_bytes() is not yet available for us, we use jiffies and
initialize states s1 - s3 with a simple linear congruential generator
(LCG), that is x <- x * 69069; and derive s2, s3, from the 32bit
initialization from s1. So the above quote from [3] accounts only
for the time from core to late initcall, not afterwards.
[**] Single threaded run on MacBook Air w/ Intel Core i5-3317U

 [1] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps
 [2] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
 [3] http://thread.gmane.org/gmane.comp.encryption.general/12103/
 [4] http://code.google.com/p/dieharder/source/browse/trunk/libdieharder/diehard_sums.c?spec=svn490&r=490#20
 [5] http://www.phy.duke.edu/~rgb/General/dieharder.php

Joint work with Hannes Frederic Sowa.

Cc: Florian Weimer <fweimer@redhat.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit 8ae038377eb4334715bf61dd0ef4dc8d147c1501)

(cherry picked from commit a14a9b0e1442c92fe1431853654fc4e366575d22)

(cherry picked from commit 93e82f2ead685d2700a3990ab25b622b4add20ed)
random32: add test cases for taus113 implementation

We generated a battery of 100 test cases from GSL taus113 implemention
and compare the results from a particular seed and a particular
iteration with our implementation in the kernel. We have verified on
32 and 64 bit machines that our taus113 kernel implementation gives
same results as GSL taus113 implementation:

  [    0.147370] prandom: seed boundary self test passed
  [    0.148078] prandom: 100 self tests passed

This is a Kconfig option that is disabled on default, just like the
crc32 init selftests in order to not unnecessary slow down boot process.
We also refactored out prandom_seed_very_weak() as it's now used in
multiple places in order to reduce redundant code.

GSL code we used for generating test cases:

  int i, j;
  srand(time(NULL));
  for (i = 0; i < 100; ++i) {
    int iteration = 500 + (rand() % 500);
    gsl_rng_default_seed = rand() + 1;
    gsl_rng *r = gsl_rng_alloc(gsl_rng_taus113);
    printf("\t{ %lu, ", gsl_rng_default_seed);
    for (j = 0; j < iteration - 1; ++j)
      gsl_rng_get(r);
    printf("%u, %lu },\n", iteration, gsl_rng_get(r));
    gsl_rng_free(r);
  }

Joint work with Hannes Frederic Sowa.

Cc: Florian Weimer <fweimer@redhat.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit 747de3c223fe1b1f00522ae5a0d6f02d62217738)

(cherry picked from commit 9f5b6fbd90863feb83b119811d7538b923e2c467)

(cherry picked from commit a62bb3b67de944c19c2129ecac44f08941dba8d9)

(cherry picked from commit 513b746cd08cb1c132a954a39f85dcf3fdda0eff)
random32: add __init prefix to prandom_start_seed_timer

We only call that in functions annotated with __init, so add __init
prefix in prandom_start_seed_timer() as well, so that the kernel can
make use of this hint and we can possibly free up resources after it's
usage. And since it's an internal function rename it to
__prandom_start_seed_timer().

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit d112feae4c1cbacbb8f5ec1bb253016f2a7cd15e)

(cherry picked from commit 63051db584c40e5379cc91ee86cd78acda306f30)

(cherry picked from commit 3ef53fd773a3f9a006dc27aa501720899dfa248e)

(cherry picked from commit 7a3d8b9de245468ecb4a425e0bc19f7e4bbe73a9)
random32: use msecs_to_jiffies for reseed timer

Use msecs_to_jiffies, for these calculations as different HZ
considerations are taken into account for conversion of the timer
shot, and also it makes the code more readable.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit 96db74247f3f1fd3b19d8a908ec8dc6c03a85c1d)

(cherry picked from commit f8a41a7e7a953bd56a1e7afc3cd8cfb0d045fcc2)

(cherry picked from commit 647d4feb4513a9752df0bfabbdb58a0323e741bc)

(cherry picked from commit 73779ffe6a67eda793acd5ad187debb12080d06a)
random32: avoid attempt to late reseed if in the middle of seeding

Commit 4af712e8df ("random32: add prandom_reseed_late() and call when
nonblocking pool becomes initialized") has added a late reseed stage
that happens as soon as the nonblocking pool is marked as initialized.

This fails in the case that the nonblocking pool gets initialized
during __prandom_reseed()'s call to get_random_bytes(). In that case
we'd double back into __prandom_reseed() in an attempt to do a late
reseed - deadlocking on 'lock' early on in the boot process.

Instead, just avoid even waiting to do a reseed if a reseed is already
occuring.

Fixes: 4af712e8df99 ("random32: add prandom_reseed_late() and call when nonblocking pool becomes initialized")
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

(cherry picked from commit ae9a52f62ac0683d098dd57f53dc304da7c6cdbb)

(cherry picked from commit 75330dfe1846ce2aae09069f3d7f3e86b316b2dd)

(cherry picked from commit 1ca00f039a01ff224076e7d4623e0b7e3d646724)

(cherry picked from commit 4ad0e5f6d812a3924e14c1e53c76aa22c9054b27)