From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ACE66F4484C for ; Fri, 10 Apr 2026 12:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=U8y46tGevNTaaJuQgRNS3grY9omWgCX/AAW8OBbapGE=; b=a7zjy9NtJI3fcO +r+GH1ime68ZPodW4W7EIeHekKld77QT4SPSySVHqC4gZ+/rtDqevZvOZCBWNI7sGE6hFFLjqDQE2 FlHS6XM1cvdrgOMJFjoWQHCxdA8ZlYogBJa/FYdqrpLMgGyzxp8HVCelsUq2P8hCMGxV4VLZBgaRV 3S/WXrRU/pBy+1nLz/O7aRKBWyoQ1HJa/7MHiBjZYoU18T2/ngegx7ske6kVzrTjfQmObblrfG9wT 3SzQKq/YNAFRXkV9iVEAjAbFMuTjQTAeODtIEnS6voPPWrXoe+a9Er+XhJG8Nd6QtsLxh48O+Q1XH LYoSUZmgMFJCYt/q270w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wBArd-0000000CD6R-3WJ0; Fri, 10 Apr 2026 12:21:33 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wBArP-0000000CCfy-1XEQ; Fri, 10 Apr 2026 12:21:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id A5F7D6111B; Fri, 10 Apr 2026 12:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57879C2BCB3; Fri, 10 Apr 2026 12:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775823677; bh=8aVhqN+bsjtC+8iOVhItTcCo4nE5t4ex+cjOCvHOROg=; h=Date:From:To:Cc:Subject:References:From; b=OA4RjUakSKbHP7uZl9Rn6aI/7Qts08y1gdCxG4212yNJdVKaYLulTRlHhQ1giBOu6 tARhrIBIltPo7n2ZqupgbCjM222ynMbD+JMBXCcsIED9ns8vEth54JFbieyU26o9rm KoQTgfYyoH0jSRf5j3OQodGQDBBjhAykp4Hy5bQdfGP0P88P76fnb883frBXWWU03q P/YOEYqjXf/L4ccO74xjFbM3qOQBRFdrvTUVXM6TfNVPJX1ACluXAp6rS0x+D02XQB ZfqSCQC8dN3KdQ34VmPvfFKRcfafCQ6soBJ+KtAS56vLrMJXpWDVh/K6XVrYMUGmaP YaxQP6ppalRew== Date: Fri, 10 Apr 2026 14:21:14 +0200 Message-ID: <20260410120319.853669871@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: Paul Walmsley , linux-riscv@lists.infradead.org, Arnd Bergmann , x86@kernel.org, Lu Baolu , iommu@lists.linux.dev, Michael Grzeschik , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Herbert Xu , linux-crypto@vger.kernel.org, Vlastimil Babka , linux-mm@kvack.org, David Woodhouse , Bernie Thompson , linux-fbdev@vger.kernel.org, "Theodore Tso" , linux-ext4@vger.kernel.org, Andrew Morton , Uladzislau Rezki , Marco Elver , Dmitry Vyukov , kasan-dev@googlegroups.com, Andrey Ryabinin , Thomas Sailer , linux-hams@vger.kernel.org, "Jason A. Donenfeld" , Richard Henderson , linux-alpha@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Huacai Chen , loongarch@lists.linux.dev, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, Dinh Nguyen , Jonas Bonn , linux-openrisc@vger.kernel.org, Helge Deller , linux-parisc@vger.kernel.org, Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Heiko Carstens , linux-s390@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Subject: [patch 34/38] riscv: Select ARCH_HAS_RANDOM_ENTROPY References: <20260410120044.031381086@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The only remaining non-architecture usage of get_cycles() is to provide random_get_entropy(). Switch riscv over to the new scheme of selecting ARCH_HAS_RANDOM_ENTROPY and providing random_get_entropy() in asm/random.h. Add 'asm/timex.h' includes to the relevant files, so the global include can be removed once all architectures are converted over. Signed-off-by: Thomas Gleixner Cc: Paul Walmsley Cc: linux-riscv@lists.infradead.org --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/random.h | 25 +++++++++++++++++++++++++ arch/riscv/include/asm/timex.h | 13 ------------- arch/riscv/kernel/unaligned_access_speed.c | 1 + arch/riscv/kvm/vcpu_timer.c | 1 + arch/riscv/lib/delay.c | 1 + 6 files changed, 29 insertions(+), 13 deletions(-) --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -47,6 +47,7 @@ config RISCV select ARCH_HAS_PREPARE_SYNC_CORE_CMD select ARCH_HAS_PTDUMP if MMU select ARCH_HAS_PTE_SPECIAL + select ARCH_HAS_RANDOM_ENTROPY select ARCH_HAS_SET_DIRECT_MAP if MMU select ARCH_HAS_SET_MEMORY if MMU select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL --- /dev/null +++ b/arch/riscv/include/asm/random.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_RANDOM_H +#define _ASM_RISCV_RANDOM_H + +#include + +#ifdef CONFIG_RISCV_M_MODE +/* + * Much like MIPS, we may not have a viable counter to use at an early point + * in the boot process. Unfortunately we don't have a fallback, so instead + * invoke the fallback function. + */ +static inline unsigned long random_get_entropy(void) +{ + if (unlikely(clint_time_val == NULL)) + return random_get_entropy_fallback(); + return get_cycles(); +} +#else /* !CONFIG_RISCV_M_MODE */ +static inline unsigned long random_get_entropy(void) +{ + return get_cycles(); +} +#endif /* CONFIG_RISCV_M_MODE */ +#endif /* _ASM_RISCV_RANDOM_H */ --- a/arch/riscv/include/asm/timex.h +++ b/arch/riscv/include/asm/timex.h @@ -31,19 +31,6 @@ static inline u32 get_cycles_hi(void) #define get_cycles_hi get_cycles_hi #endif /* CONFIG_64BIT */ -/* - * Much like MIPS, we may not have a viable counter to use at an early point - * in the boot process. Unfortunately we don't have a fallback, so instead - * we just return 0. - */ -static inline unsigned long random_get_entropy(void) -{ - if (unlikely(clint_time_val == NULL)) - return random_get_entropy_fallback(); - return get_cycles(); -} -#define random_get_entropy() random_get_entropy() - #else /* CONFIG_RISCV_M_MODE */ static inline cycles_t get_cycles(void) --- a/arch/riscv/kernel/unaligned_access_speed.c +++ b/arch/riscv/kernel/unaligned_access_speed.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "copy-unaligned.h" --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -14,6 +14,7 @@ #include #include #include +#include static u64 kvm_riscv_current_cycles(struct kvm_guest_timer *gt) { --- a/arch/riscv/lib/delay.c +++ b/arch/riscv/lib/delay.c @@ -10,6 +10,7 @@ #include #include +#include /* * This is copies from arch/arm/include/asm/delay.h