Received: by 2002:a05:6504:5087:b0:1e5:d399:13c4 with SMTP id i7csp1971308ltq; Fri, 30 Sep 2022 16:16:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6w5B7TY/G8jJ18sXPSQA2V97ZVxBSH18TVplcgeVXEEb18HqJVE1yMLhnoE8XHTexPnopb X-Received: by 2002:a05:6402:520c:b0:451:4213:49db with SMTP id s12-20020a056402520c00b00451421349dbmr9620015edd.130.1664579817086; Fri, 30 Sep 2022 16:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664579817; cv=none; d=google.com; s=arc-20160816; b=qkPgQaOyh9bu/kuJNanbTchAxg/Uyv3JaX+zeblaWCRDRFDRqW3vckEGVhYiDQkqHO JQc05FnYj5w9Mt0leIp87N4646VNYm/WZTchTB43/Y3tK8YLVsBp/Pdsn1kP41AGsV/9 kYhGVtHN5yFOCnYNc6GFVbiXjiPt4vw49wPTqKPv6iFe2RHw6ZhztS9MtcXNSlPbyxi1 quLmGmoIeVFJyX05SWqSEnuGp7884xNH/yaGLHU/4eCDZ8CTxCeuh9RT+qTbGI84apOe IV7WR0MrKxrClW0irePrWykJ2Rvrsh+15loTnAU8aTufNQIub8V3Cvd/5RnIe44TmLqv ENlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tNSsweT9TTVejKwOARbU5QKMnoD9GUfRqiMtcILsJxo=; b=otQvijVvCc3OJgj+QSZxehMOSSVKiEDWiGaLwR3sde7Xa+83IDWURgYQXTp01fXA8D /7oatg3+AqbuivGl7TukTM4mITjjRzr1pFpjJ0lubGm1BOX4UGPwP5l14czNu2SGnEJ3 y6Rd8Pp5YnkEB9XAfa7NPijhv4GVhPQ/uqSqdyX0QhOu/dagF/lgHseFLBS+mIasUwm4 ROk7PlL5Orx/rPxEEvWuW4Ne8Wu9Sj2M9XyGE8gn9bHyhpiLndaHmhw9lR5plWXBz1CL LSQ13h8vTOiqMKE3oV08PDWqgAG2LNTM7b8Lwd9WUdZ9+PozLyCfr6wSOuMe7CbnOiMo 4BZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=lfnFBZfy; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd4-20020a1709076e0400b00782f6b6f10asi2691206ejc.726.2022.09.30.16.16.02; Fri, 30 Sep 2022 16:16:57 -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; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=lfnFBZfy; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231939AbiI3XPy (ORCPT + 99 others); Fri, 30 Sep 2022 19:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231473AbiI3XPw (ORCPT ); Fri, 30 Sep 2022 19:15:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43C45CEEB2; Fri, 30 Sep 2022 16:15:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id ED162B82986; Fri, 30 Sep 2022 23:15:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9D20C433D6; Fri, 30 Sep 2022 23:15:42 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="lfnFBZfy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664579740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=tNSsweT9TTVejKwOARbU5QKMnoD9GUfRqiMtcILsJxo=; b=lfnFBZfytp82YCa4ht9ykeqc+yqNznvUWpO5CqL/0yr81o7fBldgTBvBuK0pJ7VeDv5Bhr I1CXTGthH5oXLSvIArTN4NOdy4dqoH6BiC5yvuUE7kyhSo1VUM6Nf6FRTzkFsjxyjcyfNh SzGaugAUL0nHwggvMYkSBCifY/5VajM= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d1e3b0ec (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Sep 2022 23:15:40 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: "Jason A. Donenfeld" , Dominik Brodowski , Sebastian Andrzej Siewior , Sultan Alsawaf Subject: [PATCH 1/2] random: schedule jitter credit for next jiffy, not in two jiffies Date: Sat, 1 Oct 2022 01:10:49 +0200 Message-Id: <20220930231050.749824-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 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 passively wait for it") Cc: Dominik Brodowski Cc: Sebastian Andrzej Siewior Cc: Sultan Alsawaf Signed-off-by: Jason A. Donenfeld --- 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 64ee16ffb8b7..fdf15f5c87dd 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1205,7 +1205,7 @@ static void __cold entropy_timer(struct timer_list *timer) */ static void __cold try_to_generate_entropy(void) { - enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 30 }; + enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 15 }; struct entropy_timer_state stack; unsigned int i, num_different = 0; unsigned long last = random_get_entropy(); @@ -1224,7 +1224,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 = random_get_entropy(); -- 2.37.3