From patchwork Sat Oct 22 07:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1109399wrr; Sat, 22 Oct 2022 01:48:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4KmB13V77soRJ0qgIBCvlV1R6RiuK4RXnQ88mqROmjaOGkG6y8YM2nSNofk7s6sTi13xQ+ X-Received: by 2002:a17:907:7f07:b0:779:7f94:d259 with SMTP id qf7-20020a1709077f0700b007797f94d259mr18976307ejc.525.1666428500350; Sat, 22 Oct 2022 01:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428500; cv=none; d=google.com; s=arc-20160816; b=1BVjCtesQv75WoctITE+U6mpGS3hsoxmcZYwcJvvXh31RpYIo/phnE827rD/BRI0m/ KG77JAub+k0L/IZy7+K92E4fP+/y8oH+ytPFJ+4rXq8zRF/uzSnXaFdewCgkDd5STPRK Fa35l33Hsw7gQXr/O1aWIRMtp1vaYZXIAYfkPac2oakgsK1PHoUCYf+gnvT6NMqfRAwk rm0+silnFHZ9g+io+etqGHseo6lMjU842m5Y2XWIxZTH3a9tnm+jPRewpA4kCT9Lf+0u Gk8GCY1dagrumu8D21hYj+bAaVMtLJt3K+SiQFuhoDUf0QfFLhXE6wsw7qgj1/xlO3FT czvw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RguZUmlNTMoTKqHGi+v4jkh3k1eLc80dmEzMJqjo6Kc=; b=Q7E0Vxwldf5auG89aT0g9kW2m2YhE1o55ogfTjYpRSCwsCtCeVH5c4jUTFj78k5V6T qgiXaBnfZUxxxuY+gfFXpLZm8Er/FDMCe7q4Vnc6E5DYSs1/Nz5phdDXE/805K3WEr2X qwfoU3C5nlbTnjfv4k4xNvTaJRHcuufYMuUJP316HgQDXv6dXbSRE2p6vDiw5B3WGZbn 7XlQGQhzXpX+SDncku3UfACwssw+n0g6qfYMQkllambcLyj9doHVfHfcoH8apLH0J8rG R/YGKekzSHtDLr6cnMVvxTxNkHXPmjVAV9ivfakEi5p3jNlKaU63J3UoADmeV+SbrBRa 1itQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PdEzsNcL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a056402038700b004592ebc28a9si18923639edv.59.2022.10.22.01.47.56; Sat, 22 Oct 2022 01:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=PdEzsNcL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234630AbiJVIr0 (ORCPT + 99 others); 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 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376931268520301?= X-GMAIL-MSGID: =?utf-8?q?1747376931268520301?= 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 passively 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 *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(); @@ -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 = random_get_entropy();