From nobody Fri May 8 07:36:46 2026 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 BE385C433EF for ; Sun, 8 May 2022 00:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344179AbiEHAYf (ORCPT ); Sat, 7 May 2022 20:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbiEHAY0 (ORCPT ); Sat, 7 May 2022 20:24:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC2B510CA for ; Sat, 7 May 2022 17:20:35 -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 A7B79B80CB3 for ; Sun, 8 May 2022 00:20:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F13BBC385A5; Sun, 8 May 2022 00:20:31 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="RWoY6whx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1651969230; 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: in-reply-to:in-reply-to:references:references; bh=n1Nbn66kBHdnSXivPE3WcHST5AT2Su5zyz1tMG3BgD8=; b=RWoY6whxz3Mxuv2vtz54IsZ8emVat0BL7au5BTpo1/rEHe+VF8AiPi4T77LRanY3LBE57W OI+N3oWjFZg6eCBIvAM6ANDqpSXnB9EVr5Yy9f/NvW0t22lUe/dJIhOk3EKHCnqilEglD8 uv3MZS2MAaN8JFUvcwSY1OIWmY50BjA= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8acbde0f (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 8 May 2022 00:20:30 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" , Andrew Morton , Stafford Horne Subject: [PATCH v2] init: call time_init() before rand_initialize() Date: Sun, 8 May 2022 02:20:18 +0200 Message-Id: <20220508002018.117030-1-Jason@zx2c4.com> In-Reply-To: References: 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" Currently time_init() is called after rand_initialize(), but rand_initialize() makes use of the timer on various platforms, and sometimes this timer needs to be initialized by time_init() first. In order for random_get_entropy() to not return zero during early boot when it's potentially used as an entropy source, reverse the order of these two calls. The block doing random initialization was right before time_init() before, so changing the order shouldn't have any complicated effects. Cc: Andrew Morton Cc: Stafford Horne Signed-off-by: Jason A. Donenfeld --- Changes v1->v2: - Clarified commit message; code remains the same. This lives in random.git and will be in linux-next for testing. init/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/main.c b/init/main.c index 98182c3c2c4b..e37ec99cf56d 100644 --- a/init/main.c +++ b/init/main.c @@ -1035,6 +1035,7 @@ asmlinkage __visible void __init __no_sanitize_addres= s start_kernel(void) softirq_init(); timekeeping_init(); kfence_init(); + time_init(); =20 /* * For best initial stack canary entropy, prepare it after: @@ -1049,7 +1050,6 @@ asmlinkage __visible void __init __no_sanitize_addres= s start_kernel(void) add_device_randomness(command_line, strlen(command_line)); boot_init_stack_canary(); =20 - time_init(); perf_event_init(); profile_init(); call_function_init(); --=20 2.35.1