From nobody Fri Dec 19 19:06:33 2025 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 39D9CC04A95 for ; Sat, 22 Oct 2022 08:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234399AbiJVIr0 (ORCPT ); Sat, 22 Oct 2022 04:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235177AbiJVIot (ORCPT ); Sat, 22 Oct 2022 04:44:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 696A12CB8D0; Sat, 22 Oct 2022 01:08:44 -0700 (PDT) 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 0E85160B9C; Sat, 22 Oct 2022 07:58:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2193CC433D6; Sat, 22 Oct 2022 07:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425533; bh=XyPVQJbFTLvipGXK1VZ5NAIpvAx/eXTeDvTak5V8T+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PdEzsNcLljOQGtWkv+98ElY2+y8Oqai9rmVIPXlXAjG3XxbZQA8Zcuzpj9yRArh9l o1lK+QuNnUr3ReH4ksGGFD+OZ7SHDVKxxvKZPggKsVw4Xvs9KvU8guXxe2RyTVMHfG bH7KRePhQjhyFsXGNpmpPqNwNQxdgBGHrwzWCrsE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , Sebastian Andrzej Siewior , Sultan Alsawaf , "Jason A. Donenfeld" , Sasha Levin Subject: [PATCH 5.19 533/717] random: schedule jitter credit for next jiffy, not in two jiffies Date: Sat, 22 Oct 2022 09:26:52 +0200 Message-Id: <20221022072521.900794646@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jason A. Donenfeld [ Upstream commit 122733471384be8c23f019fbbd46bdf7be561dcd ] Counterintuitively, mod_timer(..., jiffies + 1) will cause the timer to fire not in the next jiffy, but in two jiffies. The way to cause the timer to fire in the next jiffy is with mod_timer(..., jiffies). Doing so then lets us bump the upper bound back up again. Fixes: 50ee7529ec45 ("random: try to actively add entropy rather than passi= vely wait for it") Fixes: 829d680e82a9 ("random: cap jitter samples per bit to factor of HZ") Cc: Dominik Brodowski Cc: Sebastian Andrzej Siewior Cc: Sultan Alsawaf Signed-off-by: Jason A. Donenfeld Signed-off-by: Sasha Levin --- drivers/char/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 8dfb28d5ae3f..5defbc479a5c 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1178,7 +1178,7 @@ static void __cold entropy_timer(struct timer_list *t= imer) */ static void __cold try_to_generate_entropy(void) { - enum { NUM_TRIAL_SAMPLES =3D 8192, MAX_SAMPLES_PER_BIT =3D HZ / 30 }; + enum { NUM_TRIAL_SAMPLES =3D 8192, MAX_SAMPLES_PER_BIT =3D HZ / 15 }; struct entropy_timer_state stack; unsigned int i, num_different =3D 0; unsigned long last =3D random_get_entropy(); @@ -1197,7 +1197,7 @@ static void __cold try_to_generate_entropy(void) timer_setup_on_stack(&stack.timer, entropy_timer, 0); while (!crng_ready() && !signal_pending(current)) { if (!timer_pending(&stack.timer)) - mod_timer(&stack.timer, jiffies + 1); + mod_timer(&stack.timer, jiffies); mix_pool_bytes(&stack.entropy, sizeof(stack.entropy)); schedule(); stack.entropy =3D random_get_entropy(); --=20 2.35.1