Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6093218iog; Thu, 23 Jun 2022 11:10:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uK6arKSJOR2blUJx2pGU1LfqNBRdHqd0T/PmHVHZCsQZDazOGLBR2JEE7lUUuSlbqNVBqR X-Received: by 2002:a17:906:9b93:b0:722:f3e8:3f5e with SMTP id dd19-20020a1709069b9300b00722f3e83f5emr8606440ejc.65.1656007801694; Thu, 23 Jun 2022 11:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656007801; cv=none; d=google.com; s=arc-20160816; b=ZIFLsKw0FP29EkpeIuDBoO9spQL08jZIrHpCivQyvXjAJfvF5bBwhMm2Lx/h07bos9 HPcpRLWanKe0WpF+A+F10zilNQqC8ChsHaxELyXEb+hqaR140ny0iBGq1pDH8Eo1zO1s VeiFpAXZ/FuF6vDYsZzX/pYU4fYd/LqlE30z0F501nkCIncFWpXyz+VxG+i1604/lvrF /yGYEJtexQu2jsL7FRJy0AP2VIAKtLyXFVG7/P4s/EG94yuV41yrZe+jp3QSBnldTLOJ Y16pAv/q1iAax4eTXdEi443kLuGNqjIW1SEh1/1EPgKtUn4yeP0DWuO4sDFHAOZfXK2s jqew== 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=vFiqEered5rgkp36icskpXnTfftuyZ0aNJASZrGLLPw=; b=THnpJsJjF04sPC/wvSSWDH0tPa+F3QCvgz1AwbY1gfqj0bP+HqALpodfZJZlIu1A6s ajGR8JHRw/fMkjxf1sDtBbci9nj6RYUDPXrX9l48XALuJ64bfNDdzY//LiYKHDRZ0N/W qJ1U5QAFu4NzTNwNknMOBhPTOcOaFX28V+nL8sjrO0wOE/18s0hAVu8aGTtYeQBHi4gU /xFN3ee1YqKH1R6mj40IlonZM/IhxzEfpRen7Zy1L34hKcZVOuwgQhS260WzJv+ZPXLt a1rJG5MzyVnFbRNgS5idXcMoyGqkitZwvcYc0LslX5Xm6wmPM2hQBHHi6VvK8AZuRV0w zVLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hSaca/tQ"; 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 s7-20020a056402520700b004357397219csi327054edd.139.2022.06.23.11.09.32; Thu, 23 Jun 2022 11:10:01 -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="hSaca/tQ"; 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 S236140AbiFWSHI (ORCPT + 99 others); Thu, 23 Jun 2022 14:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbiFWSGL (ORCPT ); Thu, 23 Jun 2022 14:06:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4814D4F1EF; Thu, 23 Jun 2022 10:18:33 -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 0465CB824B8; Thu, 23 Jun 2022 17:18:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A1FCC3411B; Thu, 23 Jun 2022 17:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004710; bh=tdJgFI6BSEbMlog94O8U41zIwpESdHgVPKAWwGejSCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hSaca/tQ/pWz8DWrGp867YeoaI9so7S6jSgG6W94xP7/LHCg4GR9+lirvUKMmWveR qfIMEHP3af18bA+LbkDoNJ2EO8OlqUyNeOOiSrx1FOi/nnM2ASjDXFPHTmk7eB3TsY ZL2P1NqmnK5Uef3iaBLl0P8S2hZ/ekQDsdSjgWA0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Dominik Brodowski , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 4.19 084/234] random: inline leaves of rand_initialize() Date: Thu, 23 Jun 2022 18:42:31 +0200 Message-Id: <20220623164345.435299731@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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: "Jason A. Donenfeld" commit 8566417221fcec51346ec164e920dacb979c6b5f upstream. This is a preparatory commit for the following one. We simply inline the various functions that rand_initialize() calls that have no other callers. The compiler was doing this anyway before. Doing this will allow us to reorganize this after. We can then move the trust_cpu and parse_trust_cpu definitions a bit closer to where they're actually used, which makes the code easier to read. Cc: Theodore Ts'o Reviewed-by: Dominik Brodowski Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 90 ++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 57 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -476,42 +476,6 @@ static DECLARE_WAIT_QUEUE_HEAD(crng_init static void invalidate_batched_entropy(void); -static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); -static int __init parse_trust_cpu(char *arg) -{ - return kstrtobool(arg, &trust_cpu); -} -early_param("random.trust_cpu", parse_trust_cpu); - -static bool __init crng_init_try_arch_early(void) -{ - int i; - bool arch_init = true; - unsigned long rv; - - for (i = 4; i < 16; i++) { - if (!arch_get_random_seed_long_early(&rv) && - !arch_get_random_long_early(&rv)) { - rv = random_get_entropy(); - arch_init = false; - } - primary_crng.state[i] ^= rv; - } - - return arch_init; -} - -static void __init crng_initialize(void) -{ - extract_entropy(&primary_crng.state[4], sizeof(u32) * 12); - if (crng_init_try_arch_early() && trust_cpu && crng_init < 2) { - invalidate_batched_entropy(); - crng_init = 2; - pr_notice("crng init done (trusting CPU's manufacturer)\n"); - } - primary_crng.init_time = jiffies - CRNG_RESEED_INTERVAL - 1; -} - /* * crng_fast_load() can be called by code in the interrupt service * path. So we can't afford to dilly-dally. Returns the number of @@ -1220,17 +1184,28 @@ int __must_check get_random_bytes_arch(v } EXPORT_SYMBOL(get_random_bytes_arch); +static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); +static int __init parse_trust_cpu(char *arg) +{ + return kstrtobool(arg, &trust_cpu); +} +early_param("random.trust_cpu", parse_trust_cpu); + /* - * init_std_data - initialize pool with system data - * - * This function clears the pool's entropy count and mixes some system - * data into the pool to prepare it for use. The pool is not cleared - * as that can only decrease the entropy in the pool. + * Note that setup_arch() may call add_device_randomness() + * long before we get here. This allows seeding of the pools + * with some platform dependent data very early in the boot + * process. But it limits our options here. We must use + * statically allocated structures that already have all + * initializations complete at compile time. We should also + * take care not to overwrite the precious per platform data + * we were given. */ -static void __init init_std_data(void) +int __init rand_initialize(void) { int i; ktime_t now = ktime_get_real(); + bool arch_init = true; unsigned long rv; mix_pool_bytes(&now, sizeof(now)); @@ -1241,22 +1216,23 @@ static void __init init_std_data(void) mix_pool_bytes(&rv, sizeof(rv)); } mix_pool_bytes(utsname(), sizeof(*(utsname()))); -} -/* - * Note that setup_arch() may call add_device_randomness() - * long before we get here. This allows seeding of the pools - * with some platform dependent data very early in the boot - * process. But it limits our options here. We must use - * statically allocated structures that already have all - * initializations complete at compile time. We should also - * take care not to overwrite the precious per platform data - * we were given. - */ -int __init rand_initialize(void) -{ - init_std_data(); - crng_initialize(); + extract_entropy(&primary_crng.state[4], sizeof(u32) * 12); + for (i = 4; i < 16; i++) { + if (!arch_get_random_seed_long_early(&rv) && + !arch_get_random_long_early(&rv)) { + rv = random_get_entropy(); + arch_init = false; + } + primary_crng.state[i] ^= rv; + } + if (arch_init && trust_cpu && crng_init < 2) { + invalidate_batched_entropy(); + crng_init = 2; + pr_notice("crng init done (trusting CPU's manufacturer)\n"); + } + primary_crng.init_time = jiffies - CRNG_RESEED_INTERVAL - 1; + if (ratelimit_disable) { urandom_warning.interval = 0; unseeded_warning.interval = 0;