From patchwork Sun Apr 10 21:49: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: 12808307 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 230C8C433F5 for ; Sun, 10 Apr 2022 21:50:47 +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=ht7ls/ZSvkjpBPCNnzgLbJs258YUILZxzQKwlkpARE0=; b=Y6jOsXJ5uMoCxI z0FHAGjzxszKkulEbiH3GatqBWPmhltMITanxAvjGh90NoYxZt0Ur/weUBLwchOlOTySFXn2eFuEk xmvEFXav7kJU7RzpyYG2XW/kRvWeGB8eTBCt2LbWJKst8ri0bvbG779obtDXazAT8ixzz5Wcc9pi9 bScLvl7uts+8aN7yxxo8jN7z3nL1sRakJVCXQsuO6AeO5i+lY2NcYD+ydIkozjdHPyje2hFsAphLE lgT5sWRZeK99jUM3ClFk6VK1meilF5680WnArLvlvOQA3mlfDMyKC2PHsk/2P1pdColRy579kI95R FXyMoFr1SzlLvbzNYl5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfS4-005aYg-4Y; Sun, 10 Apr 2022 21:50:32 +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 1ndfRt-005aUS-6Q; Sun, 10 Apr 2022 21:50: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 11B7560C88; Sun, 10 Apr 2022 21:50:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31778C385AD; Sun, 10 Apr 2022 21:50:16 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="N/kh/3mi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627415; 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=eCzcuPEAsFfV3KQBApenUVcgAqREPhA7I39P+jrbFEE=; b=N/kh/3milYkWfElQYLj5pol3Zh+yt3dFFaR1x4WN1G+GoRTaYgzUaCgs450uGUV/NmfpD7 fkbxjgPP/06fQeOc7+8NwwwXXk5PmfxvA+cloaTCbOIZrghQ2mom6zXVxWpLwE7PtdE9mv znqG4O0+VAQldUpD/4+kP4jcicb1oPk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e822035e (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:15 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 01/11] timekeeping: add accessor for raw clock Date: Sun, 10 Apr 2022 23:49:41 +0200 Message-Id: <20220410214951.55294-2-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145021_363178_32BA3D5B X-CRM114-Status: GOOD ( 15.56 ) 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 This provides access to whichever time source has the highest frequency, which is useful for gathering entropy on platforms without available cycle counters. It's not necessarily as good as being able to quickly access a cycle counter that the CPU has, but it's still something, even when it falls back to being jiffies-based. It's defined in linux/timex.h rather than linux/timekeeping.h, because the latter cannot be included easily from asm/ headers, and generally shouldn't be used outside of this rather narrow purpose. It's a ktime function, but it's not the usual ktime API. Suggested-by: Thomas Gleixner Cc: Arnd Bergmann Cc: Theodore Ts'o Signed-off-by: Jason A. Donenfeld --- include/linux/timex.h | 2 ++ kernel/time/timekeeping.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/linux/timex.h b/include/linux/timex.h index 5745c90c8800..56502b338287 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -62,6 +62,8 @@ #include #include +extern u64 ktime_read_raw_clock(void); + #include #ifndef random_get_entropy diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dcdcb85121e4..0d04d2e8b94b 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -939,6 +939,14 @@ ktime_t ktime_get_raw(void) } EXPORT_SYMBOL_GPL(ktime_get_raw); +/** + * ktime_read_raw_clock - Returns the raw clock source value + */ +u64 ktime_read_raw_clock(void) +{ + return tk_clock_read(&tk_core.timekeeper.tkr_mono); +} + /** * ktime_get_ts64 - get the monotonic clock in timespec64 format * @ts: pointer to timespec variable From patchwork Sun Apr 10 21:49: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: 12808309 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 7E8BBC433F5 for ; Sun, 10 Apr 2022 21:51: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=82lh7LSb+/Jl+dZXhw9lMa1wRLflqcpD6SgLAzhV0Yo=; b=q51WZ+dQWXkX7l o1L2Dwphl9PR1mi1WQvqpHJu+QqNDt5aLTnT5jIR1HnyLRIYnHwDMonx4GqJcbALnlQyzRoSAQMtu T4AESjV+JP0FcWjOV/WPcGtPCnUxgx80UHIEkM1ROi+z88NB0GoFCoH3AjKSTv+bOvEnlIyO58/GQ 5/GmLDH79i3ZxDj7CNn4E9EWNlK/33uX48LEZ+sKqaCo6UAaNCDb+D/+1t2mr2ciQHZXEG5qUKaO7 cWpjZfQLH/FW0lu5qYNtVpZlVZFK1vLgQALK6jmjdKKD4kVnVKa4BqUTgliH21SL0I8u8M7UT3VeI aV2TRtk5KgC9a8GjtPYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfSU-005ans-OW; Sun, 10 Apr 2022 21:50:58 +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 1ndfRx-005aWU-Vr; Sun, 10 Apr 2022 21:50:27 +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 94ED160C49; Sun, 10 Apr 2022 21:50:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2B4C385A1; Sun, 10 Apr 2022 21:50:21 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="mljTD4lD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627421; 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=JyQJDqG7G7qoM6gKahWfWcpxoWg/Hr8hXOQQlij0UbM=; b=mljTD4lDHrPCpdKRHHsPWTFR14XiiWdhvN87TPRANPmZWfc+MO66VyuX/rXcSG22A4eyEP dnVOLtFaU6Sq0fucK3TI1wZEKw8xT1SKDR6YeAoPoyixF1BUW3rFAxNA+gC8iEtzcWxwSM 5HC0l2Iwg27gXOb6sTJlPKYcF+fyEVo= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 2f5fc337 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:20 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 02/11] timekeeping: use ktime_read_raw_clock() for random_get_entropy() if no get_cycles() Date: Sun, 10 Apr 2022 23:49:42 +0200 Message-Id: <20220410214951.55294-3-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145026_137591_A742B898 X-CRM114-Status: GOOD ( 15.22 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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 56502b338287..4050f68c34cb 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -76,8 +76,14 @@ extern u64 ktime_read_raw_clock(void); * * 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)ktime_read_raw_clock()) +#endif #endif /* From patchwork Sun Apr 10 21:49: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: 12808310 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 B6147C433F5 for ; Sun, 10 Apr 2022 21:51: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: 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=2xxb+7qejani7Mi2V8QkEgSRNsxb5pvqK0p5cwdjcco=; b=jB/db9Iy2pzbwO 1K8WpffC8/sm9DoPm8YNUt/3CdRUnk8lZtl5NxOG2+1+kFLxQqz4E1JyWUXQccFa9D6TIz7hRbZO5 JhKFOJKEnh+hlCj0I0brU2o2pHEShxiSwKPI05w7KZB0t40kZ2FoVY364bDVkmvch0V8dlJWJ3ZJc ehfLbkEWffP2AZB7vlkCkH5Glp/rs95pjICbdx9DsAHGYyXDNtLO62+JFVL/eX894ly1v/H3AEd0H GtdqvhXkpQMkzNaNUJmGG+oR3AMJtZIp/9yxU3i8h9g+If10zBpxo3kb1oeU/3cjo5CUQ15huSDsQ ec35Z3nN2rI1C0y903tQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfT1-005bA7-Lu; Sun, 10 Apr 2022 21:51:31 +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 1ndfS5-005aYi-2S; Sun, 10 Apr 2022 21:50:34 +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 A57D3B80CD2; Sun, 10 Apr 2022 21:50:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 475E3C385A4; Sun, 10 Apr 2022 21:50:27 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="F711I4MV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627426; 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=lzoxsJsBsi/VeA4T3KBOBfZZh94BpAt9k+SLscl3Id0=; b=F711I4MVzDb5425/gxQhBAIdgL7zWPn1f0VOu4iDdVTWS9xd83zi9lln+p5radGdxzVMSr vWuROQMwu/GkZg/TFmnbZnHSkgB0Adb9qte1ITjaYJjzV6rS9cntsmY+bcuWLVDpezIxYs jXkpmQZb4uaGdkVoJRSfzdhZXuHchU8= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id aba84008 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:26 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 03/11] m68k: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:43 +0200 Message-Id: <20220410214951.55294-4-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145033_459631_E3CABE36 X-CRM114-Status: GOOD ( 16.78 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Geert Uytterhoeven Signed-off-by: Jason A. Donenfeld --- arch/m68k/include/asm/timex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/m68k/include/asm/timex.h b/arch/m68k/include/asm/timex.h index 6a21d9358280..5351b10e1b18 100644 --- a/arch/m68k/include/asm/timex.h +++ b/arch/m68k/include/asm/timex.h @@ -35,7 +35,7 @@ static inline unsigned long random_get_entropy(void) { if (mach_random_get_entropy) return mach_random_get_entropy(); - return 0; + return ktime_read_raw_clock(); } #define random_get_entropy random_get_entropy From patchwork Sun Apr 10 21:49: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: 12808311 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 9D55CC433FE for ; Sun, 10 Apr 2022 21:52: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=JasyJQM0h8tQHE8Dpio/s0zPq8Ogb7CbwRNGkuJATms=; b=LQvvIiPVQzjTm5 jbGpg6pGRSizmS+kwb1BlDPN0sZ521VWTJ/6aANY9Ifb4YfuBpVQMQt5UEI5luVqidPrRVamAbLl3 PTo7zjXRQcxDjvzl4kLhGTxI3/2LMBHPt1EyI8mw2E6MYPt3pQmnegaqjITZc1lpVeWTuVIhWhfEQ 6FGs4o964hTeCATWKy0twIUZOS/jPj7RooDnnWPPNoB7JPF5K/t46X3bWVTv6WV0eFi+rR5yYSX5D zwIqEQ09H4lCf6lY1k2hjIgtbq+q7MZ4snBfy/G7KCgxI0KS5HrjIF0cCNX8SguXUiRLbvRmbVsqe TGvTXoFKRGw14fOjushA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfTS-005bVY-7x; Sun, 10 Apr 2022 21:51:58 +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 1ndfSA-005aat-Qn; Sun, 10 Apr 2022 21:50: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 6534DB80ECC; Sun, 10 Apr 2022 21:50:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7ACCC385A4; Sun, 10 Apr 2022 21:50:32 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="S3d7wENi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627431; 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=ZT7A550eKHvOIQqOwZYiKReOcnqasZBfHDcS1LUIZrE=; b=S3d7wENiCKMNM6111ZHRtIkrh53yfcj1ZUbdrqkIB83Vw6NMGZrjAOVRDU3FQf5ApnQVw3 51v7rAatX/tVw9Wg0sQ6Xp2F2wRnrEqjRoE4Lvh38tb1RlFGb2YSUOBE1misGoswqxFVtv fEB4OR0u/B9fNSNEFSHuj55k0l8VdUI= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b58be70e (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:31 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 04/11] riscv: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:44 +0200 Message-Id: <20220410214951.55294-5-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145039_449980_89901A06 X-CRM114-Status: GOOD ( 16.93 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Paul Walmsley Cc: Palmer Dabbelt Signed-off-by: Jason A. Donenfeld --- arch/riscv/include/asm/timex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/timex.h b/arch/riscv/include/asm/timex.h index 507cae273bc6..b320afede88a 100644 --- a/arch/riscv/include/asm/timex.h +++ b/arch/riscv/include/asm/timex.h @@ -41,7 +41,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 ktime_read_raw_clock(); return get_cycles(); } #define random_get_entropy() random_get_entropy() From patchwork Sun Apr 10 21:49: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: 12808312 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 0E39CC433EF for ; Sun, 10 Apr 2022 21:52:32 +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=W5ZWyNimzLPuias1yS5QpBot278IKpe58Pul+08Hp2g=; b=Fbd4zsrtC2fvNN dmxWhS4/JByjcqR24pW41OEa0iwE6NIVFKMKxogAKHL3rT2ZUNqO10404kpgee8Ut+5yTGnyUt5fj m2jemXn3F+VOxyPHXHUNJMz3rahiK6UbsaL+fTcEHZlXfWZihenHKr7aSXVN9s6svWY68oN/nTMNJ 1VSRGxBV4CdAP6SbVR76XtBF9aHkhdrQfLv6Z0TkLTHLwF4h2hGQuTbNpqC3hr9a6dxKUO8WKFUF1 mttIw4SeHSzSJGWiKspMtfj/3AeIg9r6mB8BCRNWKetOHCSgN+zsvI5TmpDXTdbERc6CmY4zv8ySa sdppr2befVxy+uuP7Jaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfTr-005bmV-4i; Sun, 10 Apr 2022 21:52:23 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfSH-005ack-0n; Sun, 10 Apr 2022 21:50:47 +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 sin.source.kernel.org (Postfix) with ESMTPS id 1A763CE1157; Sun, 10 Apr 2022 21:50:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4752FC385A4; Sun, 10 Apr 2022 21:50:38 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="EoEiRPi7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627437; 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=sejvMdltPCXTzEKFmNj/gkozCnvR+ZhNjcilYgDYs/4=; b=EoEiRPi7bM3YMtpflGeHRv7J7AFQ0XVuLlQurjsdYVJcVAxP5wqdVA0wUOlrZ4G2fY4uTU /x0DKnZUf5qImTM6Dm9c1oqi9HGF9/ZbLtd7Tnmf6WKT9TjzeLvt1qNqXN9PoULJRa5XOv CMo7MBwGXlZwAxg2G2ZghuGe8iN2KtQ= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 440d167a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:37 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 05/11] mips: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:45 +0200 Message-Id: <20220410214951.55294-6-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145045_471257_62CABFF8 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 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Thomas Bogendoerfer Signed-off-by: Jason A. Donenfeld --- arch/mips/include/asm/timex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/include/asm/timex.h b/arch/mips/include/asm/timex.h index b05bb70a2e46..fa6a5ca20b46 100644 --- a/arch/mips/include/asm/timex.h +++ b/arch/mips/include/asm/timex.h @@ -94,7 +94,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 ktime_read_raw_clock(); /* no usable register */ } #define random_get_entropy random_get_entropy From patchwork Sun Apr 10 21:49:46 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: 12808313 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 601DFC433F5 for ; Sun, 10 Apr 2022 21:53:24 +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=M3UhzMBb0soJ8hnZ5tPUZYKeFfU2kE1akd6z9xoLPSE=; b=RKhle6Vqombrp3 hrl6G1AWR9/qR3sSROb/oDNNf44ZbiuVQS4yso0/5GSlykUjzpkqqmQD3K3f63pMS87u9RTge3XXX 3WSdUHDARVDczSF5WmEnOQk2lb2vc5AFKnqlyzSEm9PhcVxUM3m6f51rsxRfX0GtshGrdaq6INGaI 79PHJx/7bzu/Y/gF+BEgGdjlAkeUSD2gkp/RR4tHbDAIN5UFnIVzpK9+TOYDrNHlUaLX1ijQ/4KVH YEFICxHGtgl6M8xD0yzfjHZVcq8hOvwlX7dt1KoTGOP6FBmbNHN3PFDJ3hxnX5t3xATxKo/Z7IR0z NSj/HkFEZJBLaMj7rkUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfUe-005cLC-4O; Sun, 10 Apr 2022 21:53:12 +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 1ndfSK-005afJ-03; Sun, 10 Apr 2022 21:50:50 +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 8B05860BC7; Sun, 10 Apr 2022 21:50:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD8D0C385A4; Sun, 10 Apr 2022 21:50:43 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="lHshAUTM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627442; 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=cSGyYL7537w/eSUXQ4B3L4Q4DOgYt+/N/yWCJBkFGzI=; b=lHshAUTMZ57bymsNdlDY1dc2P6vXuSlkoc7NREKzgSwwgH0UX/EEEkU5/UYmNKN4UujiFM OtoGK7PJ+EiBKaSI8WyBGrVYpsqHvSaIFoKwsfVEsjO9yzOUnSCtwopUrRM85n2ieX6e9I GITq5zsP8ZXPNmFI9fkc6zWS3xhal1k= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3c5a2d8c (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:42 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 06/11] arm: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:46 +0200 Message-Id: <20220410214951.55294-7-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145048_157594_38396F3A X-CRM114-Status: GOOD ( 13.65 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Russell King Signed-off-by: Jason A. Donenfeld --- arch/arm/include/asm/timex.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/include/asm/timex.h b/arch/arm/include/asm/timex.h index 7c3b3671d6c2..d0b32ce87254 100644 --- a/arch/arm/include/asm/timex.h +++ b/arch/arm/include/asm/timex.h @@ -11,5 +11,6 @@ typedef unsigned long cycles_t; #define get_cycles() ({ cycles_t c; read_current_timer(&c) ? 0 : c; }) +#define random_get_entropy() ((unsigned long)(get_cycles() ?: ktime_read_raw_clock())) #endif From patchwork Sun Apr 10 21:49:47 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: 12808320 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 75FD5C433FE for ; Sun, 10 Apr 2022 21:53:57 +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=vjE5AfYBNPFmyyz3sXVds0GVCwF9C6uvPTyGiwW0/a4=; b=4zcoU5AEjyiB8p E9YaQzNyHBqhgYgrXhSKoDV9cHrKXo58IyQ0NhUKw5iy011A18eiLOADb8JcuPMesN3QdZjunIs6/ MK0+SC7vA/jv2Sgg/jfANq4Oz+ZatCBOx+JIluY7j0yZEIG6glOWOhfh7e57Ltmakze0TUmla6HdW k5YWXYYimNP/qea6AxWAxZ8PhC9N55UjgM7yZhyAyrxPFiiKrkKGcG7QL5XNRBEVGanY01BeJmZ8f ERz8qgZBGVcuQNO5f94lHAKb0pk8s7CZRSwiSmw6v4tX1jNx5RgwB2q4NJprnwbXmlDnizMUS6a7y WQnywGa7740emf9rlHIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfVE-005cgN-0r; Sun, 10 Apr 2022 21:53:48 +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 1ndfSR-005akv-Qq; Sun, 10 Apr 2022 21:50:57 +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 72C38B80ECE; Sun, 10 Apr 2022 21:50:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA62C385A5; Sun, 10 Apr 2022 21:50:49 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="eYFoGmmo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627448; 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=XGGw/2OLV9XBv7hCdHmioHEJlceq6MZoyaNom0couuU=; b=eYFoGmmo8Dt/9ijlnNQRwao6VRVAUmVZ8OjQCi65Uj2pkdtlxXF4NqJPRINb2QSw1Es4LG exj/uAqtkrm562joHuvbgsNSoj++sHxYW8y36ud/bfe1FofaUFalJPd7C8U1Gkx0LzomSD VKsm/ImybmHqWCeMOLGftiBgl+U7nsk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 074745f1 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:48 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 07/11] nios2: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:47 +0200 Message-Id: <20220410214951.55294-8-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145056_168486_6F78D8A5 X-CRM114-Status: GOOD ( 13.68 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Dinh Nguyen Signed-off-by: Jason A. Donenfeld --- arch/nios2/include/asm/timex.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/nios2/include/asm/timex.h b/arch/nios2/include/asm/timex.h index a769f871b28d..3c74d3e337a0 100644 --- a/arch/nios2/include/asm/timex.h +++ b/arch/nios2/include/asm/timex.h @@ -9,4 +9,6 @@ typedef unsigned long cycles_t; extern cycles_t get_cycles(void); +#define random_get_entropy() ((unsigned long)(get_cycles() ?: ktime_read_raw_clock())) + #endif From patchwork Sun Apr 10 21:49:48 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: 12808321 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 0D007C433EF for ; Sun, 10 Apr 2022 21:54:51 +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=d6OXoFvXLy4OqmWsa0CaKZCvYCqSRaamRJ45mpsmygk=; b=fdB2PSvdSLdQJ6 U/Warh7UdF8CyefDr/TvnHU5ms/dlSHdguvRlVlvw7cv4/BzpifNX44p5BmygxBvnWtz/V6Czkedd wzCN+jaLGUmhU3Wl2xJYwR8xGoTdGI2N5fqEWfJusSbA9H+0jyDOfMqM13Jwx3DG6CksvKBCl/yLQ eMWnTCaMTcm6pzIP1L3NnoOuMFyd9bDnWCXxOUV8IpRaObp/waHC2HdHvBNg10pEU1P+Ve/xgY9pC 0ZaJLe+NuFgCQtweNr6Jj7Q16GS7FUF0flv8dc5b3xemM3VsmfnPtP7HdqMFrqkDYKH7iqCUg1zFW M5fTbyrTZZYd3xQ/i2/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfW4-005dA4-8P; Sun, 10 Apr 2022 21:54:40 +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 1ndfSW-005aoM-2G; Sun, 10 Apr 2022 21:51:01 +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 AADE3B80ED0; Sun, 10 Apr 2022 21:50:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B421C385A4; Sun, 10 Apr 2022 21:50:55 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="lRyRLonZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627453; 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=SSX7U4wa9cltqh9+okLsswtZRwrikCLPITiZ2u/h7CU=; b=lRyRLonZk8b09UJFho2SIWp9Foyd0FzLMoCHzOADidJrAIZdMFIPPeEFanRwibw6Ql3t40 21CxmRLKakuXCoVIZKi+bjqXQe+fCxt/Rd/Vj5+cHAmGQmTOUMye32xDhpjpyKUhIvn4k3 mfko2Iy/6OA/jrZGVwCPi1qdQqZHC0k= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e85d0e85 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:53 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 08/11] x86: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:48 +0200 Message-Id: <20220410214951.55294-9-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145100_447989_1D40DD6C X-CRM114-Status: GOOD ( 15.15 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Thomas Gleixner Cc: Arnd Bergmann Cc: x86@kernel.org Signed-off-by: Jason A. Donenfeld --- arch/x86/include/asm/tsc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index 01a300a9700b..dad3027bf6a2 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -28,6 +28,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 ktime_read_raw_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 Sun Apr 10 21:49:49 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: 12808322 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 D4B5AC433F5 for ; Sun, 10 Apr 2022 21:55: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=ta+9zvM/B4rVbykLk22RFe3ZBxtNZ+omDGtblUsgYt4=; b=q0xpTgYJZaOAEg IE9tYw4dNuITDcqQm+P70I/JewbjAqkQAb5v+014DgJ8NXjALXkVkUKupOM3rnIpIc/zJsXoizXOz 7rADF3lnH0jQnz/raBY2E7yQpQpzC0Lp9z0NJhp1ygVGPTsXrjgcWjhTQh4W1Q5+pj6CLe3/Mzk+n otVR2FS6/sdSXGkwVdGC1dgkhIfsPitSXU4a873IyPiL2+IWd6fzGOJGM6l2a6gsVbuPw1UI92/12 7orBqZPAl2WtJ7IfDHgscFT0gWsHf3J7Nqee6ZsY8uglWQipksBWwjv2LIE8Y6y7ma1OVfrxU+Lqi wr2l9D0ZaCwDiY0muJUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfWj-005dWZ-CQ; Sun, 10 Apr 2022 21:55:21 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfSd-005asb-Ty; Sun, 10 Apr 2022 21:51:09 +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 sin.source.kernel.org (Postfix) with ESMTPS id 382C3CE1157; Sun, 10 Apr 2022 21:51:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FECAC385A5; Sun, 10 Apr 2022 21:51:00 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Df8ZdRHB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627459; 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=v0GuQCNGwq3fJUQ7IzqmuEoFgX5zC7G7ODjmQAKE6bw=; b=Df8ZdRHBX2SvbUp8tw7wPXpPXDlU6kDTCmgYGh41kIe3ddHm2qqZ8mqMClMRW10+/kz+yS qS0hW7UHDa2CXwgazmm3LHTSLWGxFjdBnwNGAQrJxvZyp2ZtjtH27tB3vmNiu0HI07+LaL gOF3/i/LKf0evowuQUKO1D4BSxkJvIQ= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id a59763bf (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:50:59 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 09/11] um: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:49 +0200 Message-Id: <20220410214951.55294-10-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145108_344718_297BF527 X-CRM114-Status: GOOD ( 15.22 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Thomas Gleixner 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 Sun Apr 10 21:49:50 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: 12808323 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 88229C433EF for ; Sun, 10 Apr 2022 21:56: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=kwX4W5j/3Ihejltili1SQWgyF+gdjd0p9qLaEwptCvw=; b=garXBWqqPd4nB5 8SjriDddo4MDmm0ZM/UgJh93dh/iWc46KF5nlRm+SDohRiVjHzF12nKxv9caMSCG+esme6jQRHq5R 7OTNGPD26wKOSBhek3DS6bom9jM7JuLRL7kbt2xjBm3Bx5mIQnlRdRx4ghOBMWHH0khoXZGZeffRd SdTD8qQEoMakBCIaLxhqd7OQMsAfvpHjaB5Lc0Qv7YsTVRZxSe7BvjQExI28HdpSHUfiySEowAfmm 7UPl0HBiD/3cm/ta2p5DziG7HYg1SwbZEekJH7hMkOG/2LvBMCy4Zju+M4A0TrRNQvfRMvKT29D5R gEMcdRYBQYOwZtZitt7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfXR-005duG-F0; Sun, 10 Apr 2022 21:56:05 +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 1ndfSf-005avf-Vg; Sun, 10 Apr 2022 21:51:11 +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 79DD260C8B; Sun, 10 Apr 2022 21:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F5A8C385A4; Sun, 10 Apr 2022 21:51:05 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="oK1G66UK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627464; 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=C1ufLrONysCe3yEQR0EDgg6+4J7GIerx7v+cUIeDJoo=; b=oK1G66UKLQjisT2dZxHPb7eiQBb5LINqc5DrHQew1fp5uC96tVgAxXsU3uDN5LoBwvFOTm S28h0ZByMgUKvgHs+QYLek1FYfCRt1ZeOmNdOM5rt3/n+i5UDEqjb9HogOfuXe8TY+jcXJ SdLf2gX1e9o1Q+cykNqxXlo/2kXiymU= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 02e0bab8 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:51:04 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 10/11] sparc: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:50 +0200 Message-Id: <20220410214951.55294-11-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145110_141355_DE8A6F29 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Thomas Gleixner 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 Sun Apr 10 21:49:51 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: 12808324 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 F12B1C433EF for ; Sun, 10 Apr 2022 21:56:54 +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=66ZqQUHjfhVDRiiIlvKu6anBEmeB69KGw6SS2V7p344=; b=EU7/QCHlOReQhS E1NN9QNJlEiyPlas6TiqbvBQQ2PSVXh7xDGbUowVP/VB/Cx5cwtc0j3F+mCag8YC6AwYFe2b6Ae0O hhZ/oVpurd9yrn8vFoeNcj1UQvgBgkjxClzvmnCD8IeiMZ0oKikzy9dtH2HMLmO8UaHXodWKbRIUJ hH60bAbMLgspA5/XQyukeGi3KyyBVjog14k4bJUiSFn4Hop2anlZHZ4sUSH4UPNI1H0BohvezLCmu ZlhfI6MdF47K4gFRy8jxgCL8iGUGcK/tlGLULIF5+2RaMpgSWuIJNdE3bSJJlFtEpJZRrCd+V44Xp GwJLtf4NxtpvmG7tKtyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndfY6-005eFA-9G; Sun, 10 Apr 2022 21:56:46 +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 1ndfSk-005azE-UF; Sun, 10 Apr 2022 21:51:16 +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 58F4A60B7F; Sun, 10 Apr 2022 21:51:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1256C385A4; Sun, 10 Apr 2022 21:51:10 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="HSRuLPF+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649627469; 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=9Cu7QXRsL/z13xQn/GFGGfZ5O+ssd8ncuQpowmlC+V8=; b=HSRuLPF+VEh5X+14lNQIOIFMHoOjiZe3dSYDy4a6n3H8a3H9VkjOITzBcZyRFj//HRr2Mm t6DBVplsZGwsPuaoIOTCX9UmrGJTeMZzXbEOLZSVNNhNta5KvvLPw2gQ+dNWWnwBbEQ+wc 6Tt5kGdkQwkh5Zu4gPG1UBVc3RaNcBk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8bb042a8 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 10 Apr 2022 21:51:09 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , 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 v2 11/11] xtensa: use ktime_read_raw_clock() for random_get_entropy() instead of zero Date: Sun, 10 Apr 2022 23:49:51 +0200 Message-Id: <20220410214951.55294-12-Jason@zx2c4.com> In-Reply-To: <20220410214951.55294-1-Jason@zx2c4.com> References: <20220410214951.55294-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_145115_116297_64F3AE3E X-CRM114-Status: GOOD ( 16.65 ) 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 ktime_read_raw_clock() would be preferable, because that always needs to return _something_, even falling back to jiffies eventually. It's not as though ktime_read_raw_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: Thomas Gleixner 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 */