From patchwork Fri Apr 8 18:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807071 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 8A804C433F5 for ; Fri, 8 Apr 2022 18:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7Eigxrh7hi4ZyG9rjc7sHXuzwL5ywih/EJEKafbs1y4=; b=I1ZF4vjYZcYAzI lEhcwAQLRFbYGtbO7wI+YIQiQvl9P30wl5vDbY8z/49ztGd/QX9wO/qgDxw8KBJwLMo2pVHXtxutC zwJ5B0wfoR1GHPQoXhPcB5L0y9GLr/6Q0Ynn/E7NGswCX3y2njPXQI1J0K6zsH7MSE8ITpma4AXuy ClZXSI86csOI75ApDSuVXlpOvjdQx/gsg+d+lEQyW2qeYZ3VV8pw3GPB5/bNz2tk1nEgCJiWuLict L76Auckj48Yp8dRQTq6bY/5+CJkORatv/3Yb3dVt0Bdhjc9Kp8Jxz0hhAPt3ds6mkxwZIPRx7mn7o 6crROEdGceLzcBeEj/gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctFq-000rec-CF; Fri, 08 Apr 2022 18:22:42 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctFV-000rWZ-U5; Fri, 08 Apr 2022 18:22:23 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8F473B82A89; Fri, 8 Apr 2022 18:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96822C385BB; Fri, 8 Apr 2022 18:22:15 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="jcpLG88Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bKnGziADgzlHYNafG897CPxh8A5i6JayWbcFusMVF+o=; b=jcpLG88YHHP6AloS0heU9nwr6NJdw/JKwkHxnAETctCFQ01GcKhEazXCv1l8LYoXkmFxRD ftX1/Z6lNxkT70S7kwuImsr0xpjUDcs5HuIyBEDxSRaDq4wzLA6+sbCA5e6UpziDcyropk fx7n4JcOruZvQmUQLel+8lYi/eG+/LU= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e268004a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:14 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 01/10] random: use sched_clock() for random_get_entropy() if no get_cycles() Date: Fri, 8 Apr 2022 20:21:36 +0200 Message-Id: <20220408182145.142506-2-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112222_302195_818F4610 X-CRM114-Status: GOOD ( 16.59 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. Cc: Thomas Gleixner Cc: Arnd Bergmann Cc: Theodore Ts'o Signed-off-by: Jason A. Donenfeld --- include/linux/timex.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/timex.h b/include/linux/timex.h index 5745c90c8800..bd78f784762e 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -61,6 +61,7 @@ #include #include #include +#include #include @@ -74,8 +75,13 @@ * * By default we use get_cycles() for this purpose, but individual * architectures may override this in their asm/timex.h header file. + * If a given arch does not have get_cycles(), then we fallback to + * using sched_clock(). */ +#ifdef get_cycles #define random_get_entropy() ((unsigned long)get_cycles()) +#else +#define random_get_entropy() ((unsigned long)sched_clock()) #endif /* From patchwork Fri Apr 8 18:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807072 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 69DE9C433F5 for ; Fri, 8 Apr 2022 18:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FfZsEtHxm4r/Svft4HhRnVeEQTB2YeJNyE/GHl1RIvs=; b=M6/CRz3Kn1Y0e5 8wtwL9onSDK29tdzeFJ9oYMFDykDgILeS1lYtlnutiz6dBkky1R0QkK0iedFjJtzBhNGj+G6Gwnbc kZYBMW54yjW7enY+N2I2W1eyw/wyK3ETukCZUmAnTg/31d1xHOAY4LLO9dkP64OqMKEJ7TKXDhByD KnYCtfXeCB8ZaI/qCbrcoDZ22PrMp/slJ4mGuE/8fNkroQXWBxSpgZnH0JRLcZYf1EKR6+z9z+cnt RzpxFKZpfvCLKf+HAjKSgFoSD7ryy7SiI9vXcofixOasxhZhh4E+BUhoVr5WCqMBcTgW6ozY/Dk+y kMByFW+jJQB8PSp2ku2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGF-000ryY-Vg; Fri, 08 Apr 2022 18:23:08 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctFe-000rZ6-Db; Fri, 08 Apr 2022 18:22:31 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DBA7D6220C; Fri, 8 Apr 2022 18:22:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2CBFC385A3; Fri, 8 Apr 2022 18:22:25 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="mm79Jlmn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Azmq3qhRrdkmHljnnsXC3++LJCKNZe+lfezvnYnc39M=; b=mm79Jlmn+haFAeapmSSeR84SfB+kF20VVnX1H8gOS6Bf8q6dkzg7hgzuYdV6/IoFvyGhc+ ItuQlkzFGEsb+99E3m/AyLbHKsPXgOchjLh7R8DmhjfZMauNBrFmCRpgGwBkz8XmOxov5y BXW3244pE066ktXzUnEWutqdW49uT2A= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c95c2b8f (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:23 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 02/10] m68k: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:37 +0200 Message-Id: <20220408182145.142506-3-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112230_570612_A9339E1B X-CRM114-Status: GOOD ( 16.89 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. Cc: Arnd Bergmann Cc: Geert Uytterhoeven Signed-off-by: Jason A. Donenfeld --- arch/m68k/include/asm/timex.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/m68k/include/asm/timex.h b/arch/m68k/include/asm/timex.h index 6a21d9358280..2cd0942097f8 100644 --- a/arch/m68k/include/asm/timex.h +++ b/arch/m68k/include/asm/timex.h @@ -7,6 +7,8 @@ #ifndef _ASMm68K_TIMEX_H #define _ASMm68K_TIMEX_H +#include + #ifdef CONFIG_COLDFIRE /* * CLOCK_TICK_RATE should give the underlying frequency of the tick timer @@ -35,7 +37,7 @@ static inline unsigned long random_get_entropy(void) { if (mach_random_get_entropy) return mach_random_get_entropy(); - return 0; + return sched_clock(); } #define random_get_entropy random_get_entropy From patchwork Fri Apr 8 18:21:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807073 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 F26E7C433F5 for ; Fri, 8 Apr 2022 18:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6HW6EU8qOqa9IkyRXZlqen2isAh8Br/jYhIoCe9rTiw=; b=Is4Ly/eL7uJjAH lUFjctLYdYAI8e0Eaak5sWCUFJqD7dY6NZPjlJNw0IeB/i4Ezo373un3XKAEQxf9PnCELI7HkMYYZ rAYCXXlx95CZbgJjwykkM8QDy3sO9zhaGtzuOaTGOJHx16y4VziWuLHn2rGg045hSIJm+AVAz6zs2 HcgsaKZYjjw7RREJB0XxCppnggJiKO2ofQRylXs3lIYrZvyb9ZNH9RWWYBLpD8sp5hk9Ccq4Vgb2r mxBe4BPpvouQOVvqyj2jU3B1iogX7jvhth5eqrA825QrMa5DqnFW640yL84XacVUbzvv30jrSfSbZ TwthnkjTBhOjO5e4KgUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGm-000sOJ-4H; Fri, 08 Apr 2022 18:23:40 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctFm-000rcN-96; Fri, 08 Apr 2022 18:22:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DBA6C62211; Fri, 8 Apr 2022 18:22:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97ECEC385A3; Fri, 8 Apr 2022 18:22:33 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="djbMPAQR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jAgaDVvKz2mrahZxhZJxvyI0QeySOXC+VCOwMUwenjM=; b=djbMPAQR4aqJUQDv+3pg3YapaJCJtrqHTv182qnVHzhzX38f/Gy5cwbRLXMn1fX0kpVI9h EMnqZPYoR76vXVWG+QR8GFe8DR0F8gnqmvU01F8MCU5X46mkfIP/s+eXJyzk4PzQijiyvd zxhAQBPpNZOLAiRbTPg/OR/eSF3huiY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 9ab255ec (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:32 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 03/10] riscv: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:38 +0200 Message-Id: <20220408182145.142506-4-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112238_436636_B4BA59AD X-CRM114-Status: GOOD ( 16.58 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. Cc: Arnd Bergmann Cc: Paul Walmsley Cc: Palmer Dabbelt Signed-off-by: Jason A. Donenfeld --- arch/riscv/include/asm/timex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/timex.h b/arch/riscv/include/asm/timex.h index 507cae273bc6..5b802755ca3a 100644 --- a/arch/riscv/include/asm/timex.h +++ b/arch/riscv/include/asm/timex.h @@ -7,6 +7,7 @@ #define _ASM_RISCV_TIMEX_H #include +#include typedef unsigned long cycles_t; @@ -41,7 +42,7 @@ static inline u32 get_cycles_hi(void) static inline unsigned long random_get_entropy(void) { if (unlikely(clint_time_val == NULL)) - return 0; + return sched_clock(); return get_cycles(); } #define random_get_entropy() random_get_entropy() From patchwork Fri Apr 8 18:21:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807074 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 C421DC433F5 for ; Fri, 8 Apr 2022 18:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n6guyNb+jFKsgP2745iQDZjbeiB6S9A42LVrQGY0dvA=; b=BOkptGSB57DPkv DDPoME4wh1HzucEqdPdGlZuXuxQZB03u5czUz0eUnBVB9fkrnm+UvXFEuSCDuaq22G0pJWEsLpXp0 R9smfw8Kw7CniVPmaGcSKErqaO6dOI7tz8y3plgVpSYpLdWnMThi4wfBJGhUS6QykCua5nwoIvkcT Rh5cJnnLiB3NFxzfURRrwqWedB+ihyFCv+o2MxXCuhKV05F1aJNngao//+BgaEzrmi6XsZM27zrxD DpmP5cwXt2JlgKwEi5TjKWZXmchBkRTjmNQ01Ua7uljBQ3sz3n8Bim8T3vzY0WLpZMWrpjHCa5ax2 qOO8I9ERLaA0/uNmdnMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctHB-000shk-7R; Fri, 08 Apr 2022 18:24:05 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctFu-000rhs-W0; Fri, 08 Apr 2022 18:22:48 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 82A3F621F0; Fri, 8 Apr 2022 18:22:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AFAEC385A1; Fri, 8 Apr 2022 18:22:42 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="GAIaUJEC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DbIus65zpzI+xHKEAM5+xHyu+CtmATmWW3aZiXwzgc4=; b=GAIaUJEC1HUSfuNdrnqAWUTn3284cm/0xfh3fiKI5ZuipFFMuZvPn8LjBm4e+qk0cDLs3N 9VBsCM134dJPVZQe2Z1dOghNMM/0hI7v2FG5TdMR6v08EqeWuaCzCNYpKR7kcHopDDiZi5 UhU8/gd1mZNEseTUYlFrm8hfIl5ta+Q= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 94b0c155 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:41 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 04/10] mips: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:39 +0200 Message-Id: <20220408182145.142506-5-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112247_146496_BF5FEE51 X-CRM114-Status: GOOD ( 16.55 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. Cc: Arnd Bergmann Cc: Thomas Bogendoerfer Signed-off-by: Jason A. Donenfeld --- arch/mips/include/asm/timex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/mips/include/asm/timex.h b/arch/mips/include/asm/timex.h index b05bb70a2e46..1de8ded08bb7 100644 --- a/arch/mips/include/asm/timex.h +++ b/arch/mips/include/asm/timex.h @@ -12,6 +12,7 @@ #ifdef __KERNEL__ #include +#include #include #include @@ -94,7 +95,7 @@ static inline unsigned long random_get_entropy(void) else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A)) return read_c0_random(); else - return 0; /* no usable register */ + return sched_clock(); /* no usable register */ } #define random_get_entropy random_get_entropy From patchwork Fri Apr 8 18:21:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807075 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 44FF3C433F5 for ; Fri, 8 Apr 2022 18:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VjH1TvRBx9R72K3r4g5r5cOQ1110fU2Hq3C0Az0kYRs=; b=U5cKJvhca2Py4u X11qz62s+mlwqUt+0eH8DTWAU2o/g8Tdb/Od9UHLveMtk+J9rrDnKYjphF7I784Z2mkySe+34ng7t P63Qa4mRvVl92xmEw0NnGMMRK5L4qGgSuJbeuGclQneu4rGd/i5J+TtZULGILK5tNthgaGiAkQ6wB sjPq2dba5MQ+dt0Mhll51XwvWVQ5Pg9OAJlRY5w2ljqqtPBCTRW8eAMXU+6pSmae6VMfaw96utIeS RPKUcMhpM8iV7OCvQTUAH3y2LLaz1bD1KN9ZBnwF+GifTJdyZVhXN4JaQlMyt1rLXl2/zyL2GUz0u Nnui1obbW29iFNXN0sCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctHe-000t6x-Jm; Fri, 08 Apr 2022 18:24:34 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctG6-000rqT-0t; Fri, 08 Apr 2022 18:22:59 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 99B97B82CDC; Fri, 8 Apr 2022 18:22:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3572C385A1; Fri, 8 Apr 2022 18:22:51 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="G6BU8Ywm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jfm/+0nZe/a0gZ1BVOi1xoOTd0LXu2XtqvwNu5ICWks=; b=G6BU8YwmryDS1gmWE+VsSKq/CaivlVVRO+4FBmjCGpVgAiTEzz4rBGY2zrzrcC6JvcSxxJ QBlo+NeO6cN98+dyhw52GgoZFCETJXKA3Zs612fg5YoJ6Q03UdzN8+K83P/PaMf7MKK1nJ Bi7Y4m7JizYUQvonoKB619aaE5aOiKI= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c108eea7 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:50 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 05/10] arm: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:40 +0200 Message-Id: <20220408182145.142506-6-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112258_368993_9CA85B9F X-CRM114-Status: GOOD ( 14.62 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. Cc: Arnd Bergmann Cc: Russell King Signed-off-by: Jason A. Donenfeld --- arch/arm/include/asm/timex.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/include/asm/timex.h b/arch/arm/include/asm/timex.h index 7c3b3671d6c2..1c51580ee55d 100644 --- a/arch/arm/include/asm/timex.h +++ b/arch/arm/include/asm/timex.h @@ -9,7 +9,18 @@ #ifndef _ASMARM_TIMEX_H #define _ASMARM_TIMEX_H +#include + typedef unsigned long cycles_t; #define get_cycles() ({ cycles_t c; read_current_timer(&c) ? 0 : c; }) +static inline unsigned long random_get_entropy(void) +{ + unsigned long ret = get_cycles(); + if (ret) + return ret; + return sched_clock(); +} +#define random_get_entropy random_get_entropy + #endif From patchwork Fri Apr 8 18:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807076 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 560A1C433EF for ; Fri, 8 Apr 2022 18:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XOdfMSrzG8KyJf7XiZOlZH3OUy6mK5PymJfXxqD+gr4=; b=D4glc3ZFSwxV3R f8/TA1O23sY036o38nMdSsBBvPTW2E6nrFdtLQQuiV50r8xUiycFS5RCVfCwzOQdHI64qkFf7DYes wujE/2ppaZssFn5MvLLANNxe33MoZodL9+uDodwylsrcc7c06piEHG57TZs2l1V0z6OJ6E9km+DVN PrK6euBWm6hp1JMSyxMs02LTmWcfIAEWr9IgNWSp7ecrYgveh8nXVRIXqWyzP9ujF5eZCmYrOdN65 6p0tphQzpztmDeixr1NrzKURFucG48sIWsdD8v7QnCfTNP0NsKdR4yhPur1aJfids8Tkl46CCbrdK GLs+PSWrOHhfWNc/Nuiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctIA-000tUE-KR; Fri, 08 Apr 2022 18:25:06 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGE-000rwP-2M; Fri, 08 Apr 2022 18:23:08 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 875A8B82CD7; Fri, 8 Apr 2022 18:23:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99E13C385A3; Fri, 8 Apr 2022 18:22:59 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="CLPULdzg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442178; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QhQ1HwDDQ0VBViTeG0LB+139Jo2Xk5438IuvpR3RiNg=; b=CLPULdzgGXJrwK4uCCHM7+j7CQPO/TnUdFHV8jGVPXt2oRPuFGfQuIGVwrwhQmuAXIEyIK +pMFaA2OsSQLAz2u75tmYrg486K8df6y/V/MHRdhzu90z8Dl9A4EKbCnoFVpvWCWqoNp4p IgJX3Y50X9yQA9wOGJqYKrd+/9+6GG8= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 2adbe4d1 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:22:58 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 06/10] x86: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:41 +0200 Message-Id: <20220408182145.142506-7-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112306_446753_08FE1C99 X-CRM114-Status: GOOD ( 15.98 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. If CONFIG_X86_TSC=n, then it's possible that we're running on a 486 with no RDTSC, so we only need the fallback code for that case. Cc: Arnd Bergmann Cc: x86@kernel.org Signed-off-by: Jason A. Donenfeld --- arch/x86/include/asm/tsc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index 01a300a9700b..b0c0b2b9e0f7 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -5,6 +5,7 @@ #ifndef _ASM_X86_TSC_H #define _ASM_X86_TSC_H +#include #include #include @@ -28,6 +29,16 @@ static inline cycles_t get_cycles(void) return rdtsc(); } +static inline unsigned long random_get_entropy(void) +{ +#ifndef CONFIG_X86_TSC + if (!boot_cpu_has(X86_FEATURE_TSC)) + return sched_clock(); +#endif + return rdtsc(); +} +#define random_get_entropy random_get_entropy + extern struct system_counterval_t convert_art_to_tsc(u64 art); extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns); From patchwork Fri Apr 8 18:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807077 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 EA5C3C433EF for ; Fri, 8 Apr 2022 18:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Er9bUc9FG6m4IvYa0g88k/YaMBi95Ui9zvmS0REVlPc=; b=lJf1L9CaK2i+zn cq4JDJ3mFhJwb+IA1hBtkp4Ad5TOUFKFKmShAIgSG3Hjx6tfAUooUJK6LmYYdeLqj0gyqpbCjEoE1 Mk+bYVQUuwfhxzrY6xZD8T+1TNR9u2ZHhFnUxKmwcOw7ekp5wJM3tgS6LrgU/OgPWu48/oQCKtCLb +qS2558kSa4uYmE72TEd3aWuIVjFNbuluG1Yc/6n2sNX7ZW2TBt3IT7RdB9qCfGT17mEd235Ti2NR K2E66++DTLIQ1ZjYJAohnNXL82U3ker/F5p9CWcQTumoWltlWondb+XKtLme1OhBqbZSFgE07BUPb nL0ciR62Xwdu0fX+ZnsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctIo-000tuk-H6; Fri, 08 Apr 2022 18:25:46 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGL-000s1v-T8; Fri, 08 Apr 2022 18:23:15 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8413EB82CDE; Fri, 8 Apr 2022 18:23:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96180C385A3; Fri, 8 Apr 2022 18:23:07 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="bHvsH7he" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=78dSRR6cg4Cb6xE6wzqZl0y3T/C5RqbL9OTQfhaSus0=; b=bHvsH7heTJ22wd9kOVkjQRjB8qxqDYb0Neo0BG7ETnElqZmWD+KvzZiWfTFZwr1zQmUbC5 XXdPLoX/hfqwadSYoHEgXfmb2MBW+rOO7AO7VyqUuq9QbfjjauYGlTUsreemS7BXRmsC9S aoLAL9JjFgYgrOUBP32exCl+fVMfezY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 2a1ba7e8 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:23:06 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 07/10] arm64: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:42 +0200 Message-Id: <20220408182145.142506-8-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112314_271522_5493F781 X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. If CONFIG_ARM_ARCH_TIMER=n, then get_cycles() will return 0, so we only need the fallback code for that case. Cc: Arnd Bergmann Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Jason A. Donenfeld --- arch/arm64/include/asm/timex.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/include/asm/timex.h b/arch/arm64/include/asm/timex.h index cf59ce91b22d..bfebd2e1ce45 100644 --- a/arch/arm64/include/asm/timex.h +++ b/arch/arm64/include/asm/timex.h @@ -13,6 +13,15 @@ */ #define get_cycles() arch_timer_read_counter() +#ifndef CONFIG_ARM_ARCH_TIMER +/* + * The default implementation of random_get_entropy() calls get_cycles(), + * which will return 0 if CONFIG_ARM_ARCH_TIMER=n, so we fall back to + * sched_clock() here. Not a great situation, but better than nothing. + */ +#define random_get_entropy() ((unsigned long)sched_clock()) +#endif + #include #endif From patchwork Fri Apr 8 18:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807078 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 7C35EC433F5 for ; Fri, 8 Apr 2022 18:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sZqQzazqjvRq2ytHm0o6yk1URoah6T7DVVAleQCBR7k=; b=yW1XlKr0TdsmF3 4Fp2/1uN4NfQDYgJeCA03fK1scgXm5JMeivFhDhV2TWIk8IjBg+a4jrCuecHFpwdrbt/VadaHH6qE kZ4fvfe/tCBUryMaJpAHacU5+G8hJ67bDbm5l7FFy3KySqHFWXZlIBfxv1uCoc5BLz2rl/+sB5WRS J0WCzlYW77Ss/XofYbKxMFOVvEIc+7gf+c/qyA7/Up6+lfNAsxGC/9D6CvojLUFuonaMx1Gy0t7gc 2cRpEhME6WHoIIMkoWzvSEV8dEiU6Mx1n30IrcNjrxkXDn35PJFAHWeXtGQxCbXas0myJa5qDZLzL eQlFpLospD2DCkZM0VJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctJN-000uIA-7J; Fri, 08 Apr 2022 18:26:21 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGR-000s8G-KB; Fri, 08 Apr 2022 18:23:22 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D445862214; Fri, 8 Apr 2022 18:23:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FB3BC385A3; Fri, 8 Apr 2022 18:23:14 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="aQX3TeNo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/gSxv4fNuqOrrrmMH7+ftUspm7t2MfvPel8L6C8Lv04=; b=aQX3TeNoQ+QPwL8ndARaAfDg11wsJ/YFju+XvbVGJVNyL0LmZc+hDJK7/o16t+IHMdwpvI xtvhii8Iw7wWFLushibaSZy3vV9y/yroybqjTxkHmVSfenFP7sC/ErHxl7tvuHgtuCA48c Qkej7EwLwnOiXDFxDvxO5DE8fShgI0g= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e0f02080 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:23:13 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 08/10] um: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:43 +0200 Message-Id: <20220408182145.142506-9-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112319_801746_A589B54D X-CRM114-Status: GOOD ( 15.74 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. This is accomplished by just including the asm-generic code like on other architectures, which means we can get rid of the empty stub function here. Cc: Arnd Bergmann Cc: Richard Weinberger Cc: Anton Ivanov Cc: Johannes Berg Signed-off-by: Jason A. Donenfeld --- arch/um/include/asm/timex.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/um/include/asm/timex.h b/arch/um/include/asm/timex.h index e392a9a5bc9b..9f27176adb26 100644 --- a/arch/um/include/asm/timex.h +++ b/arch/um/include/asm/timex.h @@ -2,13 +2,8 @@ #ifndef __UM_TIMEX_H #define __UM_TIMEX_H -typedef unsigned long cycles_t; - -static inline cycles_t get_cycles (void) -{ - return 0; -} - #define CLOCK_TICK_RATE (HZ) +#include + #endif From patchwork Fri Apr 8 18:21:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807079 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 C6BEFC433EF for ; Fri, 8 Apr 2022 18:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8vPxic7OpI3NTb5fbWs3EZZco10Cml+06begefkFoQ4=; b=P4HUznISOrQgdd TqiYJtlsSmg37uKazgM1akz3YRmhabqV7eU9ugKd8c+twmnrjdYjJSwxDHOji1KMdfe9hrPwm3esN AE4nBsOLcPx1YHo9/xWhmzIOK6pdHI3/i0OqWhZ/C+O0MSQnkfX/iSy9UCbOlR7GPlbVFKSnZgAo0 FgKQzcXHpk3vIZ0MMRKg3aAzp7p5esg6CgMvxlE3rQioop7nNEDJAcNaF8fWBVmmK3N2l1CtxUa3p GTbYTLAqzsL1cuQBovGEc51CR8D9Fyo8/xXEF+xU8mgxYm+qXH/By6XEnbQYs3idvqMx6uRXxzuVF calHTi9ddXEU5McLoZ0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctK0-000ud3-3F; Fri, 08 Apr 2022 18:27:00 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGa-000sFW-SL; Fri, 08 Apr 2022 18:23:30 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6ACBB621FA; Fri, 8 Apr 2022 18:23:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93E11C385A5; Fri, 8 Apr 2022 18:23:24 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="jQIWOLhO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yN+amZ/gYA3bch1ZPQw4W7sQ+gf5w/y9JgysyWp/RDk=; b=jQIWOLhOUxBvoZusFmG6avdoNOZumfkFzlX9JI+3sz/6LcZi6fiHz50PhiH1f/pdI/MtFy m9sMAaUA8mqTbw1Qy+VONizn1MdUAgqLlxFGn0j+LDdVGvybZYqkC9KIQHfkrtMbsi6/b8 O6Q/CydOHJ0sqZXSrnNhN0PBk1v565E= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 28c99cda (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:23:22 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 09/10] sparc: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:44 +0200 Message-Id: <20220408182145.142506-10-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112329_065095_E9C26E5A X-CRM114-Status: GOOD ( 16.17 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. This is accomplished by just including the asm-generic code like on other architectures, which means we can get rid of the empty stub function here. Cc: Arnd Bergmann Cc: David S. Miller Signed-off-by: Jason A. Donenfeld --- arch/sparc/include/asm/timex_32.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/sparc/include/asm/timex_32.h b/arch/sparc/include/asm/timex_32.h index 542915b46209..f86326a6f89e 100644 --- a/arch/sparc/include/asm/timex_32.h +++ b/arch/sparc/include/asm/timex_32.h @@ -9,8 +9,6 @@ #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */ -/* XXX Maybe do something better at some point... -DaveM */ -typedef unsigned long cycles_t; -#define get_cycles() (0) +#include #endif From patchwork Fri Apr 8 18:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12807080 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 B6C2FC433EF for ; Fri, 8 Apr 2022 18:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NUdLgKLh1t0pFCXY40PUmCwTpUzg07k7+0RhMOhv2X8=; b=l/F6XuQMQNcvms bsIseuts1W1eZdrLna5XSgZapSHO32MFBhsUk8bVrGiBxLmFf7yRyP5d97qvA12awDWY3h5l1qiew 6EcK7a/1SUfASAnBfxNIpwoHGWT6HdKooF9p09YGBxp27JSrRUcoIWF7fkBn1vNTJ/Y5+AqgZeVAJ B7HpGOENIfDOJTI+JyGyIXu4JUYTXJLwzGNo0/1k4JHgUAWN0XOz/PIDWvswZk613WvAQ48zPkSBT yBaEVv01gxmLXcIM3SVdyesVV1PVDW4p2xA0HPB3kyn379DMg9SGgA1FT7MB3rDnpVW39JNvvgeG2 vl87B7QY2IVbkor6AaZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctKj-000v2W-2J; Fri, 08 Apr 2022 18:27:45 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nctGk-000sMY-PF; Fri, 08 Apr 2022 18:23:40 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6620AB80683; Fri, 8 Apr 2022 18:23:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8946FC385A5; Fri, 8 Apr 2022 18:23:32 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="X5Gkobvj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649442212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X+SOXCxlTVp5T6r4OXCDhv2RSY3Z97e2yzOuZYoobyg=; b=X5Gkobvj4quH9iXj/OmVaky1rOe+XlIiOQkQwsW/YXlqbHU2kvCpAxr3F4BlAiUBJjacz4 4hLrdMULeI/cM/0ZYjOyJ5ULjjQszeCJT4hYpzk92ZapKgN5ISsrXbdV5iB2kpZxcK0qe6 yMVMQkcZxubXBYCwgD1TiGQ4JjUNu+I= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id a12bc66c (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 8 Apr 2022 18:23:31 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de Cc: "Jason A. Donenfeld" , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH RFC v1 10/10] xtensa: use sched_clock() for random_get_entropy() instead of zero Date: Fri, 8 Apr 2022 20:21:45 +0200 Message-Id: <20220408182145.142506-11-Jason@zx2c4.com> In-Reply-To: <20220408182145.142506-1-Jason@zx2c4.com> References: <20220408182145.142506-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_112339_121504_AC4FBCF7 X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In the event that random_get_entropy() can't access a cycle counter or similar, falling back to returning 0 is really not the best we can do. Instead, at least calling sched_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though sched_clock() 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. This is accomplished by just including the asm-generic code like on other architectures, which means we can get rid of the empty stub function here. Cc: Arnd Bergmann Cc: Max Filippov Signed-off-by: Jason A. Donenfeld --- arch/xtensa/include/asm/timex.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/xtensa/include/asm/timex.h b/arch/xtensa/include/asm/timex.h index 233ec75e60c6..3f2462f2d027 100644 --- a/arch/xtensa/include/asm/timex.h +++ b/arch/xtensa/include/asm/timex.h @@ -29,10 +29,6 @@ extern unsigned long ccount_freq; -typedef unsigned long long cycles_t; - -#define get_cycles() (0) - void local_timer_setup(unsigned cpu); /* @@ -59,4 +55,6 @@ static inline void set_linux_timer (unsigned long ccompare) xtensa_set_sr(ccompare, SREG_CCOMPARE + LINUX_TIMER); } +#include + #endif /* _XTENSA_TIMEX_H */