From patchwork Mon Sep 21 07:58:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 11788659 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4909C1668 for ; Mon, 21 Sep 2020 07:59:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C34E20EDD for ; Mon, 21 Sep 2020 07:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726501AbgIUH7W (ORCPT ); Mon, 21 Sep 2020 03:59:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:56802 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbgIUH7T (ORCPT ); Mon, 21 Sep 2020 03:59:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1DDF8B503; Mon, 21 Sep 2020 07:59:53 +0000 (UTC) From: Nicolai Stange To: "Theodore Y. Ts'o" Cc: linux-crypto@vger.kernel.org, LKML , Arnd Bergmann , Greg Kroah-Hartman , "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Peter Matthias , Marcelo Henrique Cerri , Roman Drahtmueller , Neil Horman , Randy Dunlap , Julia Lawall , Dan Carpenter , Andy Lavr , Eric Biggers , "Jason A. Donenfeld" , =?utf-8?q?Stephan_M=C3=BCller?= , Torsten Duwe , Petr Tesarik , Nicolai Stange Subject: [RFC PATCH 07/41] random: let pool_entropy_delta() take nbits in units of 2^-ENTROPY_SHIFT Date: Mon, 21 Sep 2020 09:58:23 +0200 Message-Id: <20200921075857.4424-8-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921075857.4424-1-nstange@suse.de> References: <20200921075857.4424-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Currently pool_entropy_delta() expects its nbits argument to be given in units of integral bits. Using fractional bits for processing intermediate entropy counts consistently throughout the code will facilitate upcoming changes to the entropy accounting logic in add_interrupt_randomness(). Replace pool_entropy_delta()'s nbits argument with nfrac, which used to be a local variable and is expected to be given in units of 2^-ENTROPY_SHIFT. Adapt the single caller, credit_entropy_bits(), accordingly. Signed-off-by: Nicolai Stange --- drivers/char/random.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 15dd22d74029..08caa7a691a5 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -655,21 +655,20 @@ static void process_random_ready_list(void) /* * Based on the pool's current entropy fill level, specified as - * base_entropy_count, and the number of new entropy bits to add, - * return the amount of new entropy to credit. If the 'fast' - * parameter is set to true, the calculation will be guaranteed to - * terminate quickly, but this comes at the expense of capping - * nbits to one half of the pool size. + * base_entropy_count, and the number of new entropy bits in units of + * 2^-ENTROPY_SHIFT to add, return the amount of new entropy to + * credit. If the 'fast' parameter is set to true, the calculation + * will be guaranteed to terminate quickly, but this comes at the + * expense of capping nbits to one half of the pool size. */ static unsigned int pool_entropy_delta(struct entropy_store *r, int base_entropy_count, - int nbits, bool fast) + int nfrac, bool fast) { const int pool_size = r->poolinfo->poolfracbits; int entropy_count = base_entropy_count; - int nfrac = nbits << ENTROPY_SHIFT; - if (!nbits) + if (!nfrac) return 0; /* @@ -729,7 +728,9 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) retry: orig = READ_ONCE(r->entropy_count); - entropy_count = orig + pool_entropy_delta(r, orig, nbits, false); + entropy_count = orig + pool_entropy_delta(r, orig, + nbits << ENTROPY_SHIFT, + false); if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) goto retry;