public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: 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,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	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 28/38] mips: Select ARCH_HAS_RANDOM_ENTROPY
Date: Fri, 10 Apr 2026 14:20:45 +0200	[thread overview]
Message-ID: <20260410120319.462206386@kernel.org> (raw)
In-Reply-To: 20260410120044.031381086@kernel.org

The only remaining usage of get_cycles() is to provide random_get_entropy().

Switch mips over to the new scheme of selecting ARCH_HAS_RANDOM_ENTROPY
and providing random_get_entropy() in asm/random.h.

As a consequence this unearthed a nasty include dependency hell because
arbitrary code relies on a magic include of asm/timex.h. Including the
headers in asm/random.h turned out to be impossible as well.

The only solution for now is to uninline random_get_entropy().  Fix up all
other dependencies on the content of asm/timex.h in those files which
really depend on it.

Remove asm/timex.h as it has no functionality anymore.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
---
 arch/mips/Kconfig              |    1 
 arch/mips/generic/init.c       |    1 
 arch/mips/include/asm/random.h |    7 +++
 arch/mips/include/asm/timex.h  |   92 -----------------------------------------
 arch/mips/kernel/pm-cps.c      |    1 
 arch/mips/kernel/proc.c        |    1 
 arch/mips/kernel/relocate.c    |    1 
 arch/mips/kernel/time.c        |   53 +++++++++++++++++++++++
 arch/mips/lib/dump_tlb.c       |    1 
 arch/mips/mm/cache.c           |    1 
 10 files changed, 66 insertions(+), 93 deletions(-)

--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -19,6 +19,7 @@ config MIPS
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAS_UBSAN
 	select ARCH_HAS_GCOV_PROFILE_ALL
+	select ARCH_HAS_RANDOM_ENTROPY
 	select ARCH_KEEP_MEMBLOCK
 	select ARCH_USE_BUILTIN_BSWAP
 	select ARCH_USE_CMPXCHG_LOCKREF if 64BIT
--- a/arch/mips/generic/init.c
+++ b/arch/mips/generic/init.c
@@ -12,6 +12,7 @@
 #include <linux/of_fdt.h>
 
 #include <asm/bootinfo.h>
+#include <asm/cpu-type.h>
 #include <asm/fw/fw.h>
 #include <asm/irq_cpu.h>
 #include <asm/machine.h>
--- /dev/null
+++ b/arch/mips/include/asm/random.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-v2.0-only */
+#ifndef _ASM_RANDOM_H
+#define _ASM_RANDOM_H
+
+unsigned long random_get_entropy(void);
+
+#endif /*  _ASM_RANDOM_H */
--- a/arch/mips/include/asm/timex.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 1998, 1999, 2003 by Ralf Baechle
- * Copyright (C) 2014 by Maciej W. Rozycki
- */
-#ifndef _ASM_TIMEX_H
-#define _ASM_TIMEX_H
-
-#ifdef __KERNEL__
-
-#include <linux/compiler.h>
-
-#include <asm/cpu.h>
-#include <asm/cpu-features.h>
-#include <asm/mipsregs.h>
-#include <asm/cpu-type.h>
-
-/*
- * Standard way to access the cycle counter.
- * Currently only used on SMP for scheduling.
- *
- * Only the low 32 bits are available as a continuously counting entity.
- * But this only means we'll force a reschedule every 8 seconds or so,
- * which isn't an evil thing.
- *
- * We know that all SMP capable CPUs have cycle counters.
- */
-
-/*
- * On R4000/R4400 an erratum exists such that if the cycle counter is
- * read in the exact moment that it is matching the compare register,
- * no interrupt will be generated.
- *
- * There is a suggested workaround and also the erratum can't strike if
- * the compare interrupt isn't being used as the clock source device.
- * However for now the implementation of this function doesn't get these
- * fine details right.
- */
-static inline int can_use_mips_counter(unsigned int prid)
-{
-	int comp = (prid & PRID_COMP_MASK) != PRID_COMP_LEGACY;
-
-	if (__builtin_constant_p(cpu_has_counter) && !cpu_has_counter)
-		return 0;
-	else if (__builtin_constant_p(cpu_has_mips_r) && cpu_has_mips_r)
-		return 1;
-	else if (likely(!__builtin_constant_p(cpu_has_mips_r) && comp))
-		return 1;
-	/* Make sure we don't peek at cpu_data[0].options in the fast path! */
-	if (!__builtin_constant_p(cpu_has_counter))
-		asm volatile("" : "=m" (cpu_data[0].options));
-	if (likely(cpu_has_counter &&
-		   prid > (PRID_IMP_R4000 | PRID_REV_ENCODE_44(15, 15))))
-		return 1;
-	else
-		return 0;
-}
-
-static inline cycles_t get_cycles(void)
-{
-	if (can_use_mips_counter(read_c0_prid()))
-		return read_c0_count();
-	else
-		return 0;	/* no usable counter */
-}
-#define get_cycles get_cycles
-
-/*
- * Like get_cycles - but where c0_count is not available we desperately
- * use c0_random in an attempt to get at least a little bit of entropy.
- */
-static inline unsigned long random_get_entropy(void)
-{
-	unsigned int c0_random;
-
-	if (can_use_mips_counter(read_c0_prid()))
-		return read_c0_count();
-
-	if (cpu_has_3kex)
-		c0_random = (read_c0_random() >> 8) & 0x3f;
-	else
-		c0_random = read_c0_random() & 0x3f;
-	return (random_get_entropy_fallback() << 6) | (0x3f - c0_random);
-}
-#define random_get_entropy random_get_entropy
-
-#endif /* __KERNEL__ */
-
-#endif /*  _ASM_TIMEX_H */
--- a/arch/mips/kernel/pm-cps.c
+++ b/arch/mips/kernel/pm-cps.c
@@ -13,6 +13,7 @@
 #include <asm/asm-offsets.h>
 #include <asm/cacheflush.h>
 #include <asm/cacheops.h>
+#include <asm/cpu-type.h>
 #include <asm/idle.h>
 #include <asm/mips-cps.h>
 #include <asm/mipsmtregs.h>
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -11,6 +11,7 @@
 #include <asm/bootinfo.h>
 #include <asm/cpu.h>
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/idle.h>
 #include <asm/mipsregs.h>
 #include <asm/processor.h>
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/relocate.c
@@ -13,7 +13,6 @@
 #include <asm/fw/fw.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
-#include <asm/timex.h>
 #include <linux/elf.h>
 #include <linux/kernel.h>
 #include <linux/libfdt.h>
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -2,6 +2,7 @@
 /*
  * Copyright 2001 MontaVista Software Inc.
  * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ * Copyright (C) 1998, 1999, 2003 by Ralf Baechle
  * Copyright (c) 2003, 2004  Maciej W. Rozycki
  *
  * Common time service routines for MIPS machines.
@@ -21,9 +22,12 @@
 #include <linux/cpufreq.h>
 #include <linux/delay.h>
 
+#include <asm/cpu.h>
 #include <asm/cpu-features.h>
 #include <asm/cpu-type.h>
 #include <asm/div64.h>
+#include <asm/mipsregs.h>
+#include <asm/random.h>
 #include <asm/time.h>
 
 #ifdef CONFIG_CPU_FREQ
@@ -150,6 +154,55 @@ static __init int cpu_has_mfc0_count_bug
 	return 0;
 }
 
+
+/*
+ * On R4000/R4400 an erratum exists such that if the cycle counter is
+ * read in the exact moment that it is matching the compare register,
+ * no interrupt will be generated.
+ *
+ * There is a suggested workaround and also the erratum can't strike if
+ * the compare interrupt isn't being used as the clock source device.
+ * However for now the implementation of this function doesn't get these
+ * fine details right.
+ */
+static inline int can_use_mips_counter(unsigned int prid)
+{
+	int comp = (prid & PRID_COMP_MASK) != PRID_COMP_LEGACY;
+
+	if (__builtin_constant_p(cpu_has_counter) && !cpu_has_counter)
+		return 0;
+	else if (__builtin_constant_p(cpu_has_mips_r) && cpu_has_mips_r)
+		return 1;
+	else if (likely(!__builtin_constant_p(cpu_has_mips_r) && comp))
+		return 1;
+	/* Make sure we don't peek at cpu_data[0].options in the fast path! */
+	if (!__builtin_constant_p(cpu_has_counter))
+		asm volatile("" : "=m" (cpu_data[0].options));
+	if (likely(cpu_has_counter &&
+		   prid > (PRID_IMP_R4000 | PRID_REV_ENCODE_44(15, 15))))
+		return 1;
+	else
+		return 0;
+}
+
+/*
+ * Like get_cycles - but where c0_count is not available we desperately
+ * use c0_random in an attempt to get at least a little bit of entropy.
+ */
+unsigned long random_get_entropy(void)
+{
+	unsigned int c0_random;
+
+	if (can_use_mips_counter(read_c0_prid()))
+		return read_c0_count();
+
+	if (cpu_has_3kex)
+		c0_random = (read_c0_random() >> 8) & 0x3f;
+	else
+		c0_random = read_c0_random() & 0x3f;
+	return (random_get_entropy_fallback() << 6) | (0x3f - c0_random);
+}
+
 void __init time_init(void)
 {
 	plat_time_init();
--- a/arch/mips/lib/dump_tlb.c
+++ b/arch/mips/lib/dump_tlb.c
@@ -8,6 +8,7 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 
+#include <asm/cpu-type.h>
 #include <asm/hazards.h>
 #include <asm/mipsregs.h>
 #include <asm/mmu_context.h>
--- a/arch/mips/mm/cache.c
+++ b/arch/mips/mm/cache.c
@@ -22,6 +22,7 @@
 #include <asm/processor.h>
 #include <asm/cpu.h>
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/setup.h>
 #include <asm/pgtable.h>
 


  parent reply	other threads:[~2026-04-10 12:20 UTC|newest]

Thread overview: 43+ 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 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-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-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-10 12:19 ` [patch 11/38] misc: sgi-gru: Remove get_cycles() [ab]use 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-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-10 12:19 ` [patch 18/38] lib/tests: Replace get_cycles() " Thomas Gleixner
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 ` [patch 22/38] random: Provide CONFIG_ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
2026-04-10 12:20 ` [patch 23/38] alpha: Select ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
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-10 12:20 ` Thomas Gleixner [this message]
2026-04-10 12:20 ` [patch 29/38] nios2: " Thomas Gleixner
2026-04-10 12:20 ` [patch 30/38] openrisc: " Thomas Gleixner
2026-04-10 12:21 ` [patch 31/38] parisc: " Thomas Gleixner
2026-04-10 12:21 ` [patch 32/38] powerpc/spufs: Use mftb() directly Thomas Gleixner
2026-04-10 12:21 ` [patch 33/38] powerpc: Select ARCH_HAS_RANDOM_ENTROPY Thomas Gleixner
2026-04-10 12:21 ` [patch 34/38] riscv: " Thomas Gleixner
2026-04-10 12:21 ` [patch 35/38] s390: " 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

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.462206386@kernel.org \
    --to=tglx@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=baolu.lu@linux.intel.com \
    --cc=bernie@plugable.com \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=davem@davemloft.net \
    --cc=deller@gmx.de \
    --cc=dinguyen@kernel.org \
    --cc=dvyukov@google.com \
    --cc=dwmw2@infradead.org \
    --cc=elver@google.com \
    --cc=geert@linux-m68k.org \
    --cc=hca@linux.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=iommu@lists.linux.dev \
    --cc=jonas@southpole.se \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-openrisc@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=m.grzeschik@pengutronix.de \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=pjw@kernel.org \
    --cc=richard.henderson@linaro.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=t.sailer@alumni.ethz.ch \
    --cc=tytso@mit.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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