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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44CDCC4332F for ; Thu, 14 Apr 2022 22:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344480AbiDNW2U (ORCPT ); Thu, 14 Apr 2022 18:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiDNW2T (ORCPT ); Thu, 14 Apr 2022 18:28:19 -0400 X-Greylist: delayed 2096 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 14 Apr 2022 15:25:52 PDT Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF970C1CB5; Thu, 14 Apr 2022 15:25:51 -0700 (PDT) Received: from [IPv6:::1] ([IPv6:2607:fb90:7391:dbf4:ac39:3cd7:6899:402e]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.15.2) with ESMTPSA id 23ELn22M2798814 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Thu, 14 Apr 2022 14:49:06 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 23ELn22M2798814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2022040301; t=1649972954; bh=jiFuth2NsJ6kFB5qJAnKixgQm17ojdbszGGbG4v/FeY=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=WlSCH46pkTTvkaONLTYtjSkmVwtV4qIeEdMmXnK56j8qtfwYS7JikfRA16t5MViVC EM1qWGvWzhlh2WlFCdtk8/UVeYPWJN9pelM2/l0cF13oibPwWutbgFsYCsjE65uNxL UzaMe4CX9mRVu4ZeBkEf3DAcp1R7Lu0Q4CjYfJaSmfE341ksWVeh/c/jWjfchMFBDB Kc/0+g7g2/qKBHAy4Z8aTTrUnbJmj1jVMpR2c1aRJI76xB5zAdlw1ESnuyChATNlb9 ESUZ4Kayt9mmYcOKPJjEWAfQnrQPber7lZBL2bGlkPEFzqEejAivyie3AdvPo+WqEc sBsC/PwpLjncQ== Date: Thu, 14 Apr 2022 14:49:01 -0700 From: "H. Peter Anvin" To: Rob Herring , "Jason A. Donenfeld" CC: "linux-kernel@vger.kernel.org" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Thomas Gleixner , Arnd Bergmann , "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 , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , linux-arm-kernel , linux-m68k , "open list:MIPS" , linux-riscv , sparclinux , linux-um@lists.infradead.org, X86 ML , linux-xtensa@linux-xtensa.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_v4_01/11=5D_timekeeping=3A_add_ra?= =?US-ASCII?Q?w_clock_fallback_for_random=5Fget=5Fentropy=28=29?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20220413115411.21489-1-Jason@zx2c4.com> <20220413115411.21489-2-Jason@zx2c4.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On April 14, 2022 1:41:38 PM PDT, Rob Herring wrote: >On Thu, Apr 14, 2022 at 12:38:49AM +0200, Jason A=2E Donenfeld wrote: >> Hi Rob, >>=20 >> On Wed, Apr 13, 2022 at 4:32 PM Rob Herring wrote: >> > 'does not have a usable get_cycles(), =2E=2E=2E' as clearly some arch= es have >> > get_cycles() and yet still need a fallback=2E >> > >> > Why not handle the 'if get_cycles() returns 0 do the fallback' within >> > a weak random_get_entropy() function? Then more arches don't need any >> > random_get_entropy() implementation=2E >>=20 >> No, this doesn't really work=2E Actually, most archs don't need a >> random_get_entropy() function, because it exists in asm-generic doing >> the thing we want=2E So that's taken care of=2E But weak functions as y= ou >> suggested would be quite suboptimal, because on, e=2Eg=2E x86, what we >> have now gets inlined into a single rdtsc instruction=2E Also, the >> relation between get_cycles() and random_get_entropy() doesn't always >> hold; some archs may not have a working get_cycles() function but do >> have a path for a random_get_entropy()=2E Etc, etc=2E So I'm pretty sur= e >> that this commit is really the most simple and optimal thing to do=2E I >> really don't want to go the weak functions route=2E > >Is random_get_entropy() a hot path? > > >It doesn't have to be a weak function, but look at it this way=2E We have= =20 >the following possibilities for what random_get_entropy() does: > >- get_cycles() >- get_cycles() but returns 0 sometimes >- returns 0 >- something else > >You're handling the 3rd case=2E > >For the 2nd case, that's riscv, arm, nios2, and x86=2E That's not a lot,= =20 >but is 2 or 3 of the most widely used architectures=2E Is it really too= =20 >much to ask to support the 2nd case in the generic code/header? > >Rob It goes into interrupts, which means it is latency critical=2E 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 C5B2EC433EF for ; Thu, 14 Apr 2022 21:50:52 +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:Message-ID:References: In-Reply-To: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=4WGz/4fxpn1NTP3//MGyPmplu8ZP5MRKCg1Mizb3vR0=; b=ExP/pw8h4OPNz9 dBCpzg1JVTBglGNzYxk+vpTgIgFMU9jcinP22gPnwBDqXXzZxKTsv7sCvi7zXVuNFfP/d4xny4JpQ VEZUM4PPjlqoBxMJxxNA5AfBilfT1xUQJFruqohj2ggHRMpaEO82ZP15RBMD1kxmEFVBrPq7P8XR8 6iBjZeDurmIzBfNMpa9clsiQBtaUDAFQsZ2IUHuxOxZQ2DYxWZiu8nCgfGcJIw4zEYeY8S1hrAVzP JpVkwAo3qo5t4SGFCE7InysUi55P5WS8m3d3LdOv5iSh0+2AOd0v0SvQ4XwQ8zBz+KrvMx510QeS0 +Gaeg3DuT0WrS+x0d8qA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nf7MN-007OoI-MO; Thu, 14 Apr 2022 21:50:39 +0000 Received: from terminus.zytor.com ([198.137.202.136] helo=mail.zytor.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nf7MK-007OnM-Li; Thu, 14 Apr 2022 21:50:38 +0000 Received: from [IPv6:::1] ([IPv6:2607:fb90:7391:dbf4:ac39:3cd7:6899:402e]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.15.2) with ESMTPSA id 23ELn22M2798814 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Thu, 14 Apr 2022 14:49:06 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 23ELn22M2798814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2022040301; t=1649972954; bh=jiFuth2NsJ6kFB5qJAnKixgQm17ojdbszGGbG4v/FeY=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=WlSCH46pkTTvkaONLTYtjSkmVwtV4qIeEdMmXnK56j8qtfwYS7JikfRA16t5MViVC EM1qWGvWzhlh2WlFCdtk8/UVeYPWJN9pelM2/l0cF13oibPwWutbgFsYCsjE65uNxL UzaMe4CX9mRVu4ZeBkEf3DAcp1R7Lu0Q4CjYfJaSmfE341ksWVeh/c/jWjfchMFBDB Kc/0+g7g2/qKBHAy4Z8aTTrUnbJmj1jVMpR2c1aRJI76xB5zAdlw1ESnuyChATNlb9 ESUZ4Kayt9mmYcOKPJjEWAfQnrQPber7lZBL2bGlkPEFzqEejAivyie3AdvPo+WqEc sBsC/PwpLjncQ== Date: Thu, 14 Apr 2022 14:49:01 -0700 From: "H. Peter Anvin" To: Rob Herring , "Jason A. Donenfeld" CC: "linux-kernel@vger.kernel.org" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Thomas Gleixner , Arnd Bergmann , "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 , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , linux-arm-kernel , linux-m68k , "open list:MIPS" , linux-riscv , sparclinux , linux-um@lists.infradead.org, X86 ML , linux-xtensa@linux-xtensa.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_v4_01/11=5D_timekeeping=3A_add_ra?= =?US-ASCII?Q?w_clock_fallback_for_random=5Fget=5Fentropy=28=29?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20220413115411.21489-1-Jason@zx2c4.com> <20220413115411.21489-2-Jason@zx2c4.com> Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220414_145036_817073_EC987ACD X-CRM114-Status: GOOD ( 18.13 ) 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 April 14, 2022 1:41:38 PM PDT, Rob Herring wrote: >On Thu, Apr 14, 2022 at 12:38:49AM +0200, Jason A. Donenfeld wrote: >> Hi Rob, >> >> On Wed, Apr 13, 2022 at 4:32 PM Rob Herring wrote: >> > 'does not have a usable get_cycles(), ...' as clearly some arches have >> > get_cycles() and yet still need a fallback. >> > >> > Why not handle the 'if get_cycles() returns 0 do the fallback' within >> > a weak random_get_entropy() function? Then more arches don't need any >> > random_get_entropy() implementation. >> >> No, this doesn't really work. Actually, most archs don't need a >> random_get_entropy() function, because it exists in asm-generic doing >> the thing we want. So that's taken care of. But weak functions as you >> suggested would be quite suboptimal, because on, e.g. x86, what we >> have now gets inlined into a single rdtsc instruction. Also, the >> relation between get_cycles() and random_get_entropy() doesn't always >> hold; some archs may not have a working get_cycles() function but do >> have a path for a random_get_entropy(). Etc, etc. So I'm pretty sure >> that this commit is really the most simple and optimal thing to do. I >> really don't want to go the weak functions route. > >Is random_get_entropy() a hot path? > > >It doesn't have to be a weak function, but look at it this way. We have >the following possibilities for what random_get_entropy() does: > >- get_cycles() >- get_cycles() but returns 0 sometimes >- returns 0 >- something else > >You're handling the 3rd case. > >For the 2nd case, that's riscv, arm, nios2, and x86. That's not a lot, >but is 2 or 3 of the most widely used architectures. Is it really too >much to ask to support the 2nd case in the generic code/header? > >Rob It goes into interrupts, which means it is latency critical. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 0CC92C433EF for ; Thu, 14 Apr 2022 21:51:46 +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:Message-ID:References: In-Reply-To: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=1IUB9Zck3EMUVThwtWHHSOiiWNkYAjles6w2DYaH/1o=; b=O8sWl13G+uM4eg MMF/pn9OYaKTrXOE1IvNMNIP8gp10gSwoSEkBgWJEX8WQLZG+4nJq6St33SIFCaVDV6Sdyu2IM1Oj VKYqmgmy+BHh2ZDQEgSGNCzhuSnH7hpkaOjanY3Tbv9tPf7tFhxo0lS4AOmogBPnlvmTx0zWdyNTk 8LVrdhFBtQ8/As7jsPeh9M5aqdBc+3fzS6G+nN1wlrEs20goY2+SiQ6sJQAO08bsoeEvQms2o4355 64GXpwQUpAVIlVqPaUJ1LFtvnO8W2K027ql7Yg4eDCkNetIpaLYDrNGlgN8nIss0UdAE8nKu/ZGnR BJntkfITWv1ZdKvvyehQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nf7MQ-007OpC-EX; Thu, 14 Apr 2022 21:50:42 +0000 Received: from terminus.zytor.com ([198.137.202.136] helo=mail.zytor.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nf7MK-007OnM-Li; Thu, 14 Apr 2022 21:50:38 +0000 Received: from [IPv6:::1] ([IPv6:2607:fb90:7391:dbf4:ac39:3cd7:6899:402e]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.15.2) with ESMTPSA id 23ELn22M2798814 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Thu, 14 Apr 2022 14:49:06 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 23ELn22M2798814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2022040301; t=1649972954; bh=jiFuth2NsJ6kFB5qJAnKixgQm17ojdbszGGbG4v/FeY=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=WlSCH46pkTTvkaONLTYtjSkmVwtV4qIeEdMmXnK56j8qtfwYS7JikfRA16t5MViVC EM1qWGvWzhlh2WlFCdtk8/UVeYPWJN9pelM2/l0cF13oibPwWutbgFsYCsjE65uNxL UzaMe4CX9mRVu4ZeBkEf3DAcp1R7Lu0Q4CjYfJaSmfE341ksWVeh/c/jWjfchMFBDB Kc/0+g7g2/qKBHAy4Z8aTTrUnbJmj1jVMpR2c1aRJI76xB5zAdlw1ESnuyChATNlb9 ESUZ4Kayt9mmYcOKPJjEWAfQnrQPber7lZBL2bGlkPEFzqEejAivyie3AdvPo+WqEc sBsC/PwpLjncQ== Date: Thu, 14 Apr 2022 14:49:01 -0700 From: "H. Peter Anvin" To: Rob Herring , "Jason A. Donenfeld" CC: "linux-kernel@vger.kernel.org" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Thomas Gleixner , Arnd Bergmann , "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 , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , linux-arm-kernel , linux-m68k , "open list:MIPS" , linux-riscv , sparclinux , linux-um@lists.infradead.org, X86 ML , linux-xtensa@linux-xtensa.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_v4_01/11=5D_timekeeping=3A_add_ra?= =?US-ASCII?Q?w_clock_fallback_for_random=5Fget=5Fentropy=28=29?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20220413115411.21489-1-Jason@zx2c4.com> <20220413115411.21489-2-Jason@zx2c4.com> Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220414_145036_817073_EC987ACD X-CRM114-Status: GOOD ( 18.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On April 14, 2022 1:41:38 PM PDT, Rob Herring wrote: >On Thu, Apr 14, 2022 at 12:38:49AM +0200, Jason A. Donenfeld wrote: >> Hi Rob, >> >> On Wed, Apr 13, 2022 at 4:32 PM Rob Herring wrote: >> > 'does not have a usable get_cycles(), ...' as clearly some arches have >> > get_cycles() and yet still need a fallback. >> > >> > Why not handle the 'if get_cycles() returns 0 do the fallback' within >> > a weak random_get_entropy() function? Then more arches don't need any >> > random_get_entropy() implementation. >> >> No, this doesn't really work. Actually, most archs don't need a >> random_get_entropy() function, because it exists in asm-generic doing >> the thing we want. So that's taken care of. But weak functions as you >> suggested would be quite suboptimal, because on, e.g. x86, what we >> have now gets inlined into a single rdtsc instruction. Also, the >> relation between get_cycles() and random_get_entropy() doesn't always >> hold; some archs may not have a working get_cycles() function but do >> have a path for a random_get_entropy(). Etc, etc. So I'm pretty sure >> that this commit is really the most simple and optimal thing to do. I >> really don't want to go the weak functions route. > >Is random_get_entropy() a hot path? > > >It doesn't have to be a weak function, but look at it this way. We have >the following possibilities for what random_get_entropy() does: > >- get_cycles() >- get_cycles() but returns 0 sometimes >- returns 0 >- something else > >You're handling the 3rd case. > >For the 2nd case, that's riscv, arm, nios2, and x86. That's not a lot, >but is 2 or 3 of the most widely used architectures. Is it really too >much to ask to support the 2nd case in the generic code/header? > >Rob It goes into interrupts, which means it is latency critical. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel