Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6031712iog; Thu, 23 Jun 2022 09:56:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t6XR6mrCcbCjXMosQS+O/7sFLhfLAlcBlVFVmLEa6nrQlGdJ+JCZEKaL25VVo9fIxVGF/j X-Received: by 2002:a17:906:7953:b0:722:e8e3:ef67 with SMTP id l19-20020a170906795300b00722e8e3ef67mr9032715ejo.199.1656003417847; Thu, 23 Jun 2022 09:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003417; cv=none; d=google.com; s=arc-20160816; b=gVLuiSg5u8EQqdLBZBb9Be5wNQvs0viyaUNLuX6byVZ/EO6eJEOhuI+J8PhGW6qHvE WO9N7gSQV+TlacW9dRLf5AcjF+yosmmvk9UvhEmZFSrXD/QhUNOoRQLJfJxiyYulf6tY AZDne6xBbBBjrOv3iGYOI/mgzh71YxIDZ4yg3asG0wcbG1VH9DPk3jA0Eo6mt+PGsFjx S9Wvsl4MGC32A4u/ALd7gxNaH5oh7NBF4laIm7qWmfcnfMa+OsNCWkt+i93/Z95J5CTC AvcScPwU/PMMTIg8qwXgangH4fYXDJlh1qQo9mz4F96+cKxT/LDCGfGtc2InsIJkIDKM NaNw== 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=Am3ZDwTbyuBr0XQJp0xk/w7aNeGgMAjFRqm4olLJaCU=; b=zqybWT4hqFeITyskBxwetz6J5y7r/aT06c5uffd2YBzeRAo67le6D/SMujqQD6irq7 /RHSN88DJoHr4I3Ukg4T+qnD22uWn36hZ5X/tZVxY2lLhCTPPoSkkqt3r9MGDbsgZO5F TLRea3QfMR6hvkELagTI1ris+b4WOn/MQK2SoDvjeEJgrhnnXtSibFPJTtlMFnnmBKGS kCGvlXEXsGH4MKp3QKXrg/5nAhT9lGsB/KFV54yV0dc+V3OVh9WQ1LmByjFVO33FEkXB 4efyIxmF1m7ACwyTzFSDTLeitqR6t/pDb6SuCXxl6kXkxO2qN0VDVJFSiEsLnbRObyOF qknA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=14nNOGIA; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa33-20020a1709076d2100b00711d9021212si25406584ejc.566.2022.06.23.09.56.22; Thu, 23 Jun 2022 09:56:57 -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=14nNOGIA; 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 S232388AbiFWQyq (ORCPT + 99 others); Thu, 23 Jun 2022 12:54:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233883AbiFWQvs (ORCPT ); Thu, 23 Jun 2022 12:51:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C654F13F3D; Thu, 23 Jun 2022 09:50:38 -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 5B1E161FBF; Thu, 23 Jun 2022 16:50:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40491C3411B; Thu, 23 Jun 2022 16:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003037; bh=gPjIJx2UsgYG+ZjDGkqJcx9hLZiYTeR+h9JF0JxYGTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=14nNOGIA/XwPUGhdtopauLB/aop7XWaXLJcHqC2oQTwTrb2e7BxEq4rRtsuwXz4s1 1wICYUUvEpGMqoj29JzDoxdG0+1urF7Gqaf+3LlWU6i5ssSAKbpzaaz9J2G//S7fyV PEBYLb9MFqH3ClWahQ0v75brqXu9mWV9nczjBFz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , "Jason A. Donenfeld" Subject: [PATCH 4.9 109/264] random: only call crng_finalize_init() for primary_crng Date: Thu, 23 Jun 2022 18:41:42 +0200 Message-Id: <20220623164347.152724953@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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,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-kernel@vger.kernel.org From: Dominik Brodowski commit 9d5505f1eebeca778074a0260ed077fd85f8792c upstream. crng_finalize_init() returns instantly if it is called for another pool than primary_crng. The test whether crng_finalize_init() is still required can be moved to the relevant caller in crng_reseed(), and crng_need_final_init can be reset to false if crng_finalize_init() is called with workqueues ready. Then, no previous callsite will call crng_finalize_init() unless it is needed, and we can get rid of the superfluous function parameter. Signed-off-by: Dominik Brodowski Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -800,10 +800,8 @@ static void __init crng_initialize_prima primary_crng.init_time = jiffies - CRNG_RESEED_INTERVAL - 1; } -static void crng_finalize_init(struct crng_state *crng) +static void crng_finalize_init(void) { - if (crng != &primary_crng || crng_init >= 2) - return; if (!system_wq) { /* We can't call numa_crng_init until we have workqueues, * so mark this for processing later. */ @@ -814,6 +812,7 @@ static void crng_finalize_init(struct cr invalidate_batched_entropy(); numa_crng_init(); crng_init = 2; + crng_need_final_init = false; process_random_ready_list(); wake_up_interruptible(&crng_init_wait); kill_fasync(&fasync, SIGIO, POLL_IN); @@ -1031,7 +1030,8 @@ static void crng_reseed(struct crng_stat memzero_explicit(&buf, sizeof(buf)); WRITE_ONCE(crng->init_time, jiffies); spin_unlock_irqrestore(&crng->lock, flags); - crng_finalize_init(crng); + if (crng == &primary_crng && crng_init < 2) + crng_finalize_init(); } static void _extract_crng(struct crng_state *crng, u8 out[CHACHA20_BLOCK_SIZE]) @@ -1748,7 +1748,7 @@ int __init rand_initialize(void) { init_std_data(); if (crng_need_final_init) - crng_finalize_init(&primary_crng); + crng_finalize_init(); crng_initialize_primary(); crng_global_init_time = jiffies; if (ratelimit_disable) {