From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16B56C433F5 for ; Thu, 21 Apr 2022 21:06: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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=waziPdM4pV2RWHm5mkd4H8dns0Tcu//N/GN2kNYc7W8=; b=3GfRHpG2QghziU HYrJZfmiRWd/6ypNYOp/SXUvz2Fc37QhjWGfIg9g7xXYgkos2neZUpsiWY9uRiD7Yz0ajXCsJ+/nN LycfjLyHKlukZtf7XiVMTdfdz6IMgL9YCZIVz7PoxV3A1/nFIOg/LqaM+QdOzWhJ61z0lpNCgrDsE RR5MAoeFL1+QdBhhqe9dbGqHGEfW5TMpxZxwJd/8BttgGH0c0HKJ64e1HbdK5k0Qzp21F5X6PSBGL lhu7VOmfwYAGsD3S9kdN7eDpAY3iy3MO3/qYgO5npNXXmBj0K5F24pq2ureuVJ7w+mFhwW0uH6cEP 6mNGL/EGJjaiek5RzpbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhe0d-00EzDI-Og; Thu, 21 Apr 2022 21:06:39 +0000 Received: from elvis.franken.de ([193.175.24.41]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhe0Z-00EzAt-EV; Thu, 21 Apr 2022 21:06:37 +0000 Received: from uucp (helo=alpha) by elvis.franken.de with local-bsmtp (Exim 3.36 #1) id 1nhe01-0007Hb-00; Thu, 21 Apr 2022 23:06:01 +0200 Received: by alpha.franken.de (Postfix, from userid 1000) id 79792C01A0; Thu, 21 Apr 2022 23:05:25 +0200 (CEST) Date: Thu, 21 Apr 2022 23:05:25 +0200 From: Thomas Bogendoerfer To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, arnd@arndb.de, Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , 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 , 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, "Maciej W . Rozycki" Subject: Re: [PATCH v5 04/11] mips: use fallback for random_get_entropy() instead of just c0 random Message-ID: <20220421210525.GA16228@alpha.franken.de> References: <20220419111650.1582274-1-Jason@zx2c4.com> <20220419111650.1582274-5-Jason@zx2c4.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220419111650.1582274-5-Jason@zx2c4.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220421_140635_870587_3FD925EE X-CRM114-Status: GOOD ( 30.11 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Tue, Apr 19, 2022 at 01:16:43PM +0200, Jason A. Donenfeld wrote: > For situations in which we don't have a c0 counter register available, > we've been falling back to reading the c0 "random" register, which is > usually bounded by the amount of TLB entries and changes every other > cycle or so. This means it wraps extremely often. We can do better by > combining this fast-changing counter with a potentially slower-changing > counter from random_get_entropy_fallback() in the more significant bits. > This commit combines the two, taking into account that the changing bits > are in a different bit position depending on the CPU model. In addition, > we previously were falling back to 0 for ancient CPUs that Linux does > not support anyway; remove that dead path entirely. > > Cc: Thomas Gleixner > Cc: Arnd Bergmann > Cc: Thomas Bogendoerfer > Cc: Maciej W. Rozycki > Signed-off-by: Jason A. Donenfeld > --- > ThomasB - I dropped your Ack from v4, because this is pretty different > from v4 now. > > Maciej - you mentioned you had a test rig. Think you could provide a > "Tested-by" if this approach works? > > arch/mips/include/asm/timex.h | 16 +++++++--------- > 1 file changed, 7 insertions(+), 9 deletions(-) > > diff --git a/arch/mips/include/asm/timex.h b/arch/mips/include/asm/timex.h > index b05bb70a2e46..e3f5460a923b 100644 > --- a/arch/mips/include/asm/timex.h > +++ b/arch/mips/include/asm/timex.h > @@ -80,21 +80,19 @@ static inline cycles_t get_cycles(void) > /* > * Like get_cycles - but where c0_count is not available we desperately > * use c0_random in an attempt to get at least a little bit of entropy. > - * > - * R6000 and R6000A neither have a count register nor a random register. > - * That leaves no entropy source in the CPU itself. > */ > static inline unsigned long random_get_entropy(void) > { > - unsigned int prid = read_c0_prid(); > - unsigned int imp = prid & PRID_IMP_MASK; > + unsigned int c0_random; > > - if (can_use_mips_counter(prid)) > + if (can_use_mips_counter(read_c0_prid())) > return read_c0_count(); > - else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A)) > - return read_c0_random(); > + > + if (cpu_has_3kex) > + c0_random = (read_c0_random() >> 8) & 0x3f; > else > - return 0; /* no usable register */ > + c0_random = read_c0_random() & 0x3f; > + return (random_get_entropy_fallback() << 6) | (0x3f - c0_random); > } > #define random_get_entropy random_get_entropy > > -- > 2.35.1 Acked-by: Thomas Bogendoerfer -- Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ] _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv