android_kernel_google_msm/drivers
Jason A. Donenfeld f44d2c1f42 random: always use batched entropy for get_random_u{32,64}
commit 69efea712f5b0489e67d07565aad5c94e09a3e52 upstream.

It turns out that RDRAND is pretty slow. Comparing these two
constructions:

  for (i = 0; i < CHACHA_BLOCK_SIZE; i += sizeof(ret))
    arch_get_random_long(&ret);

and

  long buf[CHACHA_BLOCK_SIZE / sizeof(long)];
  extract_crng((u8 *)buf);

it amortizes out to 352 cycles per long for the top one and 107 cycles
per long for the bottom one, on Coffee Lake Refresh, Intel Core i9-9880H.

And importantly, the top one has the drawback of not benefiting from the
real rng, whereas the bottom one has all the nice benefits of using our
own chacha rng. As get_random_u{32,64} gets used in more places (perhaps
beyond what it was originally intended for when it was introduced as
get_random_{int,long} back in the md5 monstrosity era), it seems like it
might be a good thing to strengthen its posture a tiny bit. Doing this
should only be stronger and not any weaker because that pool is already
initialized with a bunch of rdrand data (when available). This way, we
get the benefits of the hardware rng as well as our own rng.

Another benefit of this is that we no longer hit pitfalls of the recent
stream of AMD bugs in RDRAND. One often used code pattern for various
things is:

  do {
  	val = get_random_u32();
  } while (hash_table_contains_key(val));

That recent AMD bug rendered that pattern useless, whereas we're really
very certain that chacha20 output will give pretty distributed numbers,
no matter what.

So, this simplification seems better both from a security perspective
and from a performance perspective.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20200221201037.30231-1-Jason@zx2c4.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: I868e7472df493f410744dd8ed210dd1c4ca5e55d
2023-03-24 20:53:06 +01:00
..
accessibility
acpi ACPI: Use correct IRQ when uninstalling ACPI interrupt handler 2016-10-26 23:15:26 +08:00
amba
ata sata_sil: disable trim 2016-10-26 23:15:34 +08:00
atm
auxdisplay auxdisplay: ks0108: fix refcount 2016-04-27 18:55:15 +08:00
base mm: export NR_SHMEM via sysinfo(2) / si_meminfo() interfaces 2020-12-01 19:08:36 +01:00
bcma
block UPSTREAM: block: disable entropy contributions for nonrot devices 2018-01-01 22:06:21 +03:00
bluetooth Bluetooth: ath3k: Add support of AR3012 0cf3:817b device 2016-10-26 23:15:25 +08:00
cdrom
char random: always use batched entropy for get_random_u{32,64} 2023-03-24 20:53:06 +01:00
clk Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
clocksource sched_clock: Squashed revert of the latest updates 2018-02-20 21:56:17 +03:00
connector
coresight
cpufreq Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
cpuidle
crypto Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
dca
devfreq
dio
dma dmaengine: mv_xor: bug fix for racing condition in descriptors cleanup 2015-10-22 09:20:04 +08:00
edac EDAC, ppc4xx: Access mci->csrows array elements properly 2016-03-21 09:17:52 +08:00
eisa
firewire firewire: ohci: fix JMicron JMB38x IT context discovery 2016-10-26 23:15:27 +08:00
firmware
gpio Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
gpu ion: cma: Update print_debug function 2018-08-27 14:52:43 +00:00
hid Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
hsi
hv Drivers: hv: vmbus: Don't wait after requesting offers 2015-09-18 09:20:26 +08:00
hwmon Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
hwspinlock
i2c Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
ide UPSTREAM: block: disable entropy contributions for nonrot devices 2018-01-01 22:06:21 +03:00
idle
ieee802154
infiniband Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
input enable/disable the lid sensor 2019-03-19 08:57:18 +01:00
iommu iommu: msm: Handle unmapping of PTE properly 2018-08-27 14:52:32 +00:00
isdn ser_gigaset: use container_of() instead of detour 2016-10-26 23:15:46 +08:00
leds Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
lguest lguest: fix out-by-one error in address checking. 2015-09-18 09:20:43 +08:00
macintosh windfarm: decrement client count when unregistering 2016-04-27 18:55:15 +08:00
mca
md dm-crypt: run in a WQ_HIGHPRI workqueue 2018-01-13 17:13:45 +03:00
media gpu: ion: Add support for sharing buffers with dma buf kernel handles 2018-08-27 14:52:38 +00:00
memstick memstick: mspro_block: add missing curly braces 2015-09-18 09:20:31 +08:00
message
mfd Sound Control: (Optional) work around for WCD93xx audio issues 2019-03-16 12:46:51 +01:00
misc Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
mmc mmc: move to a SCHED_FIFO thread 2018-01-13 17:13:45 +03:00
mtd UPSTREAM: block: disable entropy contributions for nonrot devices 2018-01-01 22:06:21 +03:00
net net: Replace u64_stats_fetch_begin_bh to u64_stats_fetch_begin_irq 2020-11-30 19:26:49 +03:00
nfc Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
nubus
of Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
oprofile Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
parisc parisc iommu: fix panic due to trying to allocate too large region 2016-10-26 23:15:37 +08:00
parport
pci Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
pcmcia Disable write buffering on Toshiba ToPIC95 2015-10-22 09:20:04 +08:00
pinctrl
platform msm: sps: Fix race condition in SPS debugfs APIs 2018-02-16 20:15:07 -07:00
pnp
power otg+charge: detect charging while OTG enabled 2018-04-04 10:19:45 +02:00
pps
ps3
ptp
rapidio
regulator Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
remoteproc Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
rpmsg
rtc Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
s390 s390/3215: fix tty output containing tabs 2015-04-14 17:34:03 +08:00
sbus bbc-i2c: Fix BBC I2C envctrl on SunBlade 2000 2014-08-14 08:42:37 +08:00
scsi ANDROID: scsi: Add segment checking in sg_read 2018-01-13 17:13:38 +03:00
sfi
sh
slimbus
sn
spi Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
spmi
ssb
staging flo/deb: Update Android binder 2021-11-26 22:02:17 +01:00
switch
target Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
tc
thermal Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
tty Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
uio Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
usb Merge branch 'lineage-18.1' into followmsi-11 2020-12-19 13:42:14 +01:00
uwb uwb: init beacon cache entry before registering uwb device 2014-12-01 18:02:28 +08:00
vhost vhost: actually track log eventfd file 2016-03-21 09:17:49 +08:00
video msm: vidc: prevent vcd_stop to wait for long 2018-08-27 14:52:38 +00:00
virt
virtio Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
vlynq
w1
watchdog watchdog: omap: assert the counter being stopped before reprogramming 2015-10-22 09:20:06 +08:00
xen Merge remote-tracking branch 'stable/linux-3.4.y' into lineage-15.1 2017-12-27 17:13:15 +03:00
zorro
Kconfig msm: gud: Remove gud driver 2018-01-13 17:13:39 +03:00
Makefile msm: gud: Remove gud driver 2018-01-13 17:13:39 +03:00