linux-stable/kernel/time
Jason A. Donenfeld 2142a4d898 timekeeping: Add raw clock fallback for random_get_entropy()
commit 1366992e16 upstream.

The addition of random_get_entropy_fallback() provides access to
whichever time source has the highest frequency, which is useful for
gathering entropy on platforms without available cycle counters. It's
not necessarily as good as being able to quickly access a cycle counter
that the CPU has, but it's still something, even when it falls back to
being jiffies-based.

In the event that a given arch does not define get_cycles(), falling
back to the get_cycles() default implementation that returns 0 is really
not the best we can do. Instead, at least calling
random_get_entropy_fallback() would be preferable, because that always
needs to return _something_, even falling back to jiffies eventually.
It's not as though random_get_entropy_fallback() is super high precision
or guaranteed to be entropic, but basically anything that's not zero all
the time is better than returning zero all the time.

Finally, since random_get_entropy_fallback() is used during extremely
early boot when randomizing freelists in mm_init(), it can be called
before timekeeping has been initialized. In that case there really is
nothing we can do; jiffies hasn't even started ticking yet. So just give
up and return 0.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-06-25 11:46:38 +02:00
..
alarmtimer.c kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data() 2021-03-24 11:05:05 +01:00
clockevents.c
clocksource.c clocksource: Prevent double add_timer_on() for watchdog_timer 2020-02-14 16:32:20 -05:00
hrtimer.c kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data() 2021-03-24 11:05:05 +01:00
itimer.c time: Prevent undefined behaviour in timespec64_to_ns() 2020-11-18 18:27:52 +01:00
jiffies.c
Kconfig
Makefile
ntp.c ntp: Limit TAI-UTC offset 2019-07-31 07:28:27 +02:00
ntp_internal.h
posix-clock.c ptp: fix the race between the release of ptp_clock and cdev 2020-01-04 14:00:12 +01:00
posix-cpu-timers.c kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data() 2021-03-24 11:05:05 +01:00
posix-stubs.c
posix-timers.c posix-timers: Preserve return value in clock_adjtime32() 2021-05-22 10:57:22 +02:00
posix-timers.h posix-timers: Make forward callback return s64 2018-10-03 17:00:50 -07:00
sched_clock.c
test_udelay.c
tick-broadcast-hrtimer.c tick: broadcast-hrtimer: Fix a race in bc_set_next 2019-10-11 18:18:46 +02:00
tick-broadcast.c
tick-common.c
tick-internal.h
tick-oneshot.c
tick-sched.c tick/sched: Annotate lockless access to last_jiffies_update 2020-01-23 08:20:35 +01:00
tick-sched.h
time.c time: Make sure jiffies_to_msecs() preserves non-zero time periods 2018-07-03 11:24:56 +02:00
timeconst.bc
timeconv.c
timecounter.c
timekeeping.c timekeeping: Add raw clock fallback for random_get_entropy() 2022-06-25 11:46:38 +02:00
timekeeping.h
timekeeping_debug.c
timekeeping_internal.h
timer.c random32: make prandom_u32() output unpredictable 2020-11-18 18:28:00 +01:00
timer_list.c timer_list: Guard procfs specific code 2019-07-31 07:28:28 +02:00