From: Thomas Gleixner <tglx@kernel•org>
To: LKML <linux-kernel@vger•kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4•com>,
Arnd Bergmann <arnd@arndb•de>,
x86@kernel•org, Lu Baolu <baolu.lu@linux•intel.com>,
iommu@lists•linux.dev,
Michael Grzeschik <m.grzeschik@pengutronix•de>,
netdev@vger•kernel.org, linux-wireless@vger•kernel.org,
Herbert Xu <herbert@gondor•apana.org.au>,
linux-crypto@vger•kernel.org, Vlastimil Babka <vbabka@kernel•org>,
linux-mm@kvack•org, David Woodhouse <dwmw2@infradead•org>,
Bernie Thompson <bernie@plugable•com>,
linux-fbdev@vger•kernel.org, "Theodore Tso" <tytso@mit•edu>,
linux-ext4@vger•kernel.org,
Andrew Morton <akpm@linux-foundation•org>,
Uladzislau Rezki <urezki@gmail•com>,
Marco Elver <elver@google•com>,
Dmitry Vyukov <dvyukov@google•com>,
kasan-dev@googlegroups•com,
Andrey Ryabinin <ryabinin.a.a@gmail•com>,
Thomas Sailer <t.sailer@alumni•ethz.ch>,
linux-hams@vger•kernel.org,
Richard Henderson <richard.henderson@linaro•org>,
linux-alpha@vger•kernel.org, Russell King <linux@armlinux•org.uk>,
linux-arm-kernel@lists•infradead.org,
Catalin Marinas <catalin.marinas@arm•com>,
Huacai Chen <chenhuacai@kernel•org>,
loongarch@lists•linux.dev,
Geert Uytterhoeven <geert@linux-m68k•org>,
linux-m68k@lists•linux-m68k.org,
Dinh Nguyen <dinguyen@kernel•org>,
Jonas Bonn <jonas@southpole•se>,
linux-openrisc@vger•kernel.org, Helge Deller <deller@gmx•de>,
linux-parisc@vger•kernel.org,
Michael Ellerman <mpe@ellerman•id.au>,
linuxppc-dev@lists•ozlabs.org, Paul Walmsley <pjw@kernel•org>,
linux-riscv@lists•infradead.org,
Heiko Carstens <hca@linux•ibm.com>,
linux-s390@vger•kernel.org,
"David S. Miller" <davem@davemloft•net>,
sparclinux@vger•kernel.org
Subject: [patch 22/38] random: Provide CONFIG_ARCH_HAS_RANDOM_ENTROPY
Date: Fri, 10 Apr 2026 14:20:16 +0200 [thread overview]
Message-ID: <20260410120319.064561422@kernel.org> (raw)
In-Reply-To: 20260410120044.031381086@kernel.org
Chasing down to what random_get_entropy() resolves is a 'spot the mouse'
game through a maze of #ifdeffery. Also the placement in timex.h is
non-obvious and has just been chosen because it provides conveniant access
to the underlying get_cycles() #ifdeffery.
Provide a config switch which is selectable by the architecture and a
temporary #ifdef guard in timex.h. Architectures which select the config
switch must provide asm/random.h with the architecture specific
implementation.
Update all usage sites to include linux/random.h so that the gradual
conversion does not cause build regressions.
This is part of a larger effort to remove get_cycles() usage from
non-architecture code.
Signed-off-by: Thomas Gleixner <tglx@kernel•org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4•com>
---
arch/Kconfig | 3 +++
arch/loongarch/kernel/relocate.c | 1 +
arch/mips/kernel/relocate.c | 1 +
crypto/jitterentropy-kcapi.c | 1 +
include/linux/random.h | 15 +++++++++++++++
include/linux/timex.h | 2 ++
kernel/kcsan/core.c | 1 +
7 files changed, 24 insertions(+)
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -370,6 +370,9 @@ config ARCH_HAS_CPU_FINALIZE_INIT
config ARCH_HAS_DELAY_TIMER
bool
+config ARCH_HAS_RANDOM_ENTROPY
+ bool
+
# The architecture has a per-task state that includes the mm's PASID
config ARCH_HAS_CPU_PASID
bool
--- a/arch/loongarch/kernel/relocate.c
+++ b/arch/loongarch/kernel/relocate.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/panic_notifier.h>
+#include <linux/random.h>
#include <linux/start_kernel.h>
#include <asm/bootinfo.h>
#include <asm/early_ioremap.h>
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/relocate.c
@@ -19,6 +19,7 @@
#include <linux/libfdt.h>
#include <linux/of_fdt.h>
#include <linux/panic_notifier.h>
+#include <linux/random.h>
#include <linux/sched/task.h>
#include <linux/start_kernel.h>
#include <linux/string.h>
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -42,6 +42,7 @@
#include <linux/fips.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/random.h>
#include <linux/slab.h>
#include <linux/time.h>
#include <crypto/internal/rng.h>
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -139,4 +139,19 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops;
#endif
+unsigned long random_get_entropy_fallback(void);
+
+/*
+ * random_get_entropy() is used by the /dev/random driver in order to extract
+ * entropy via the relative unpredictability of when an interrupt takes places
+ * versus a high speed, fine-grained timing source or cycle counter. Since it
+ * will be occurred on every single interrupt, it must have a very low
+ * cost/overhead.
+ *
+ * If an architecture does not provide it, then use random_get_entropy_fallback().
+ */
+#ifdef CONFIG_ARCH_HAS_RANDOM_ENTROPY
+#include <asm/random.h>
+#endif
+
#endif /* _LINUX_RANDOM_H */
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -66,6 +66,7 @@ unsigned long random_get_entropy_fallbac
#include <asm/timex.h>
+#ifndef CONFIG_ARCH_HAS_RANDOM_ENTROPY
#ifndef random_get_entropy
/*
* The random_get_entropy() function is used by the /dev/random driver
@@ -85,6 +86,7 @@ unsigned long random_get_entropy_fallbac
#define random_get_entropy() random_get_entropy_fallback()
#endif
#endif
+#endif
/*
* SHIFT_PLL is used as a dampening factor to define how much we
--- a/kernel/kcsan/core.c
+++ b/kernel/kcsan/core.c
@@ -18,6 +18,7 @@
#include <linux/moduleparam.h>
#include <linux/percpu.h>
#include <linux/preempt.h>
+#include <linux/random.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/uaccess.h>
next prev parent reply other threads:[~2026-04-10 12:20 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 12:18 [patch 00/38] treewide: Cleanup LATCH, CLOCK_TICK_RATE and get_cycles() [ab]use Thomas Gleixner
2026-04-10 12:18 ` [patch 01/38] percpu: Sanitize __percpu_qual include hell Thomas Gleixner
2026-04-10 12:18 ` [patch 02/38] x86: Cleanup include recursion hell Thomas Gleixner
2026-04-10 20:55 ` [patch V1.1 " Thomas Gleixner
2026-04-10 12:18 ` [patch 03/38] x86/apm: Remove last LATCH usage Thomas Gleixner
2026-04-10 12:18 ` [patch 04/38] x86: Use PIT_TICK_RATE instead of CLOCK_TICK_RATE Thomas Gleixner
2026-04-10 12:18 ` [patch 05/38] treewide: Remove CLOCK_TICK_RATE Thomas Gleixner
2026-04-15 6:40 ` Christophe Leroy (CS GROUP)
2026-04-16 11:22 ` Geert Uytterhoeven
2026-04-10 12:18 ` [patch 06/38] calibrate: Rework delay timer calibration Thomas Gleixner
2026-04-10 12:19 ` [patch 07/38] treewide: Consolidate cycles_t Thomas Gleixner
2026-04-13 9:15 ` Ojaswin Mujoo
2026-04-15 6:43 ` Christophe Leroy (CS GROUP)
2026-04-16 19:32 ` Thomas Gleixner
2026-04-16 11:22 ` Geert Uytterhoeven
2026-04-10 12:19 ` [patch 08/38] x86/tsc: Use rdtsc() instead of get_cycles() Thomas Gleixner
2026-04-10 12:19 ` [patch 09/38] iommu/vt-d: Use sched_clock() " Thomas Gleixner
2026-04-10 13:45 ` Baolu Lu
2026-04-10 15:14 ` Thomas Gleixner
2026-04-10 12:19 ` [patch 10/38] arcnet: Remove function timing code Thomas Gleixner
2026-04-13 15:29 ` David Woodhouse
2026-04-10 12:19 ` [patch 11/38] misc: sgi-gru: Remove get_cycles() [ab]use Thomas Gleixner
2026-04-10 20:56 ` [patch V1.1 " Thomas Gleixner
2026-04-10 12:19 ` [patch 12/38] wifi: wil6210: Replace get_cyles() usage Thomas Gleixner
2026-04-10 12:19 ` [patch 13/38] crypto: tcrypt: Replace get_cycles() with ktime_get() Thomas Gleixner
2026-04-10 12:19 ` [patch 14/38] slub: Use prandom instead of get_cycles() Thomas Gleixner
2026-04-10 12:19 ` [patch 15/38] ptp: ptp_vmclock: Replace get_cycles() usage Thomas Gleixner
2026-04-13 15:33 ` David Woodhouse
2026-04-13 19:30 ` Arnd Bergmann
2026-04-10 12:19 ` [patch 16/38] fbdev: udlfb: Replace get_cycles() with ktime_get() Thomas Gleixner
2026-04-10 12:19 ` [patch 17/38] ext4: Replace get_cycles() usage " Thomas Gleixner
2026-04-13 14:46 ` Arnd Bergmann
2026-04-10 12:19 ` [patch 18/38] lib/tests: Replace get_cycles() " Thomas Gleixner
2026-04-16 10:24 ` Geert Uytterhoeven
2026-04-10 12:20 ` [patch 19/38] kcsan: Replace get_cycles() usage Thomas Gleixner
2026-04-10 13:39 ` Marco Elver
2026-04-10 12:20 ` [patch 20/38] kasan: sw_tags: Replace get_cycles() by random_get_entropy() Thomas Gleixner
2026-04-10 12:20 ` [patch 21/38] hamradio: baycom_epp: Remove BAYCOM_DEBUG Thomas Gleixner
2026-04-10 12:20 ` Thomas Gleixner [this message]
2026-04-10 12:20 ` [patch 23/38] alpha: Select ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
2026-04-12 13:22 ` Magnus Lindholm
2026-04-10 12:20 ` [patch 24/38] ARM: " Thomas Gleixner
2026-04-10 12:20 ` [patch 25/38] arm64: " Thomas Gleixner
2026-04-10 12:20 ` [patch 26/38] loongarch: " Thomas Gleixner
2026-04-10 12:20 ` [patch 27/38] m68k: " Thomas Gleixner
2026-04-10 15:31 ` Daniel Palmer
2026-04-16 11:22 ` Geert Uytterhoeven
2026-04-10 12:20 ` [patch 28/38] mips: " Thomas Gleixner
2026-04-13 5:47 ` Maciej W. Rozycki
2026-04-10 12:20 ` [patch 29/38] nios2: " Thomas Gleixner
2026-04-10 12:20 ` [patch 30/38] openrisc: " Thomas Gleixner
2026-04-12 8:56 ` Stafford Horne
2026-04-10 12:21 ` [patch 31/38] parisc: " Thomas Gleixner
2026-04-14 12:41 ` Helge Deller
2026-04-10 12:21 ` [patch 32/38] powerpc/spufs: Use mftb() directly Thomas Gleixner
2026-04-13 14:43 ` Arnd Bergmann
2026-04-15 6:38 ` Christophe Leroy (CS GROUP)
2026-04-21 6:48 ` Mukesh Kumar Chaurasiya
2026-04-10 12:21 ` [patch 33/38] powerpc: Select ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
2026-04-15 6:47 ` Christophe Leroy (CS GROUP)
2026-04-21 11:22 ` Mukesh Kumar Chaurasiya
2026-04-10 12:21 ` [patch 34/38] riscv: " Thomas Gleixner
2026-04-10 12:21 ` [patch 35/38] s390: " Thomas Gleixner
2026-04-16 13:42 ` Heiko Carstens
2026-04-16 19:29 ` Thomas Gleixner
2026-04-10 12:21 ` [patch 36/38] sparc: Select ARCH_HAS_RANDOM_ENTROPY for SPARC64 Thomas Gleixner
2026-04-10 12:21 ` [patch 37/38] x86: Select ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
2026-04-10 12:21 ` [patch 38/38] treewide: Remove asm/timex.h includes from generic code Thomas Gleixner
2026-04-13 14:45 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260410120319.064561422@kernel.org \
--to=tglx@kernel$(echo .)org \
--cc=Jason@zx2c4$(echo .)com \
--cc=akpm@linux-foundation$(echo .)org \
--cc=arnd@arndb$(echo .)de \
--cc=baolu.lu@linux$(echo .)intel.com \
--cc=bernie@plugable$(echo .)com \
--cc=catalin.marinas@arm$(echo .)com \
--cc=chenhuacai@kernel$(echo .)org \
--cc=davem@davemloft$(echo .)net \
--cc=deller@gmx$(echo .)de \
--cc=dinguyen@kernel$(echo .)org \
--cc=dvyukov@google$(echo .)com \
--cc=dwmw2@infradead$(echo .)org \
--cc=elver@google$(echo .)com \
--cc=geert@linux-m68k$(echo .)org \
--cc=hca@linux$(echo .)ibm.com \
--cc=herbert@gondor$(echo .)apana.org.au \
--cc=iommu@lists$(echo .)linux.dev \
--cc=jonas@southpole$(echo .)se \
--cc=kasan-dev@googlegroups$(echo .)com \
--cc=linux-alpha@vger$(echo .)kernel.org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-crypto@vger$(echo .)kernel.org \
--cc=linux-ext4@vger$(echo .)kernel.org \
--cc=linux-fbdev@vger$(echo .)kernel.org \
--cc=linux-hams@vger$(echo .)kernel.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-m68k@lists$(echo .)linux-m68k.org \
--cc=linux-mm@kvack$(echo .)org \
--cc=linux-openrisc@vger$(echo .)kernel.org \
--cc=linux-parisc@vger$(echo .)kernel.org \
--cc=linux-riscv@lists$(echo .)infradead.org \
--cc=linux-s390@vger$(echo .)kernel.org \
--cc=linux-wireless@vger$(echo .)kernel.org \
--cc=linux@armlinux$(echo .)org.uk \
--cc=linuxppc-dev@lists$(echo .)ozlabs.org \
--cc=loongarch@lists$(echo .)linux.dev \
--cc=m.grzeschik@pengutronix$(echo .)de \
--cc=mpe@ellerman$(echo .)id.au \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pjw@kernel$(echo .)org \
--cc=richard.henderson@linaro$(echo .)org \
--cc=ryabinin.a.a@gmail$(echo .)com \
--cc=sparclinux@vger$(echo .)kernel.org \
--cc=t.sailer@alumni$(echo .)ethz.ch \
--cc=tytso@mit$(echo .)edu \
--cc=urezki@gmail$(echo .)com \
--cc=vbabka@kernel$(echo .)org \
--cc=x86@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox