Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp487957iob; Wed, 4 May 2022 00:53:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYdNMSLiKOz22WwI655RMTkhwvfKfaABXpzxNQsbV3+oeNgykLY1aCwYmA4eYJlJkBnWP9 X-Received: by 2002:a17:907:7293:b0:6f4:b0b4:c807 with SMTP id dt19-20020a170907729300b006f4b0b4c807mr3139509ejc.180.1651650818182; Wed, 04 May 2022 00:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651650818; cv=none; d=google.com; s=arc-20160816; b=qWk35F/X9+OM2ED2M/MYzst2paIy7bWJNvuW1WnMpfp8kCSqC3QdExdKs3DO6VXKsY LdPn7ekF9tiGxgc5cfY7tk2+D99UDDb4wYoSSzeUnhj5hogDqE7uAyIIjlgqKeY/VdeJ 75Okv+DCvy1aCIPSYfXuk7jDW24mFbltc9Y25qD5udggT3BVavjlKx3HQ4QJswdUHTKm at+KUtgZE6siWH18nTmJECEn2qiCUZODjKswn44uJSTGq8tohKTWzXdmBWDzEP9Fwp7l B7MqldIBl8mC6GM/a46dk3jkn7qEjl3X73HLRzQJ0SfvINtfoGXC6MhjvBDMpRO7wQVS 0Rdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=HtSYmWn93qh5godJScoA6wPffHTcWLxkyf1LFplyBoc=; b=xNNOqCSvB83sD6k2gb9uWGLqLIRRrBOFlUjepV6BFSvRdhOJS5o4B5Lj3AEn6qhlzY kfLj/OH8EOowCPFOq7Z5NOSU5f/cCKoE3TAgIISmWqdQopkSfI7kPnonzE9bO97tjgdG 3Xm3r1HmbBAwFTQC4zdNKttIqOJ4zuijtmLzvJFI/7demjH43TF7xT7MGkEwTAVsBNJP Cx/pAbWB11qTjOC19uKGjBz0avo/xLG3wj1ZfqY+MmVi00+rrwm6/L3rZPJ7GCdiCu1t LySpH5gY+xBdnlZtzsDmMa9fIIZhB09Y8wgf2M/8CedWqRi7ppl9w+pwh8xl9kd766qA +1iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vp13-20020a17090712cd00b006e89e2b6fffsi4046151ejb.479.2022.05.04.00.53.06; Wed, 04 May 2022 00:53:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344989AbiEDGiV (ORCPT + 99 others); Wed, 4 May 2022 02:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240410AbiEDGiU (ORCPT ); Wed, 4 May 2022 02:38:20 -0400 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB89726D5; Tue, 3 May 2022 23:34:45 -0700 (PDT) X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from owl.dominikbrodowski.net (owl.brodo.linta [10.2.0.111]) by isilmar-4.linta.de (Postfix) with ESMTPSA id 3988B2013EB; Wed, 4 May 2022 06:34:43 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id 70D46806B0; Wed, 4 May 2022 07:36:53 +0200 (CEST) Date: Wed, 4 May 2022 07:36:53 +0200 From: Dominik Brodowski To: "Jason A. Donenfeld" Cc: Linux Crypto Mailing List , LKML Subject: Re: [PATCH] random: mix hwgenerator randomness before sleeping Message-ID: References: <20220503195141.683217-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Jason, Am Wed, May 04, 2022 at 02:45:46AM +0200 schrieb Jason A. Donenfeld: > On Tue, May 3, 2022 at 9:56 PM Dominik Brodowski > wrote: > > > > Am Tue, May 03, 2022 at 09:51:41PM +0200 schrieb Jason A. Donenfeld: > > > The add_hwgenerator_randomness() function is called in a loop from a > > > kthread by the hwgenerator core. It's supposed to sleep when there's > > > nothing to do, and wake up periodically for more entropy. Right now it > > > receives entropy, sleeps, and then mixes it in. This commit reverses the > > > order, so that it always mixes in entropy sooner and sleeps after. This > > > way the entropy is more fresh. > > > > ... however, the hwgenerator may take quite some time to accumulate entropy > > after wakeup. So now we might have a delay between a wakeup ("we need more > > entropy!") and that entropy becoming available. Beforehand, the thread only > > went to sleep when there is no current need for "fresh" entropy. > > Huh, interesting consideration. I didn't think about that. You wrote, > "hwgenerator may take quite some time to accumulate entropy" -- any > idea how long in the worst case? A second? A minute? For TPM or virtio-rng, this shouldn't take long. But, for example, the Kconfig entry for HW_RANDOM_TIMERIOMEM states that This driver provides kernel-side support for a generic Random Number Generator used by reading a 'dumb' iomem address that is to be read no faster than, for example, once a second; the default FPGA bitstream on the TS-7800 has such functionality. Then, optee-rng.c contains a value "data_rate" in random bytes per second, and may sleep for a considerable time: msleep((1000 * (max - read)) / pvt_data->data_rate); Thanks, Dominik