Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp235693iob; Mon, 2 May 2022 18:04:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8kItoJoEntINCbyDZeLjYXozbKwJNuC19A0k0oVhC0nr4U8NKakXC5ZDsiF9/pFDMeJ9r X-Received: by 2002:a17:902:6bc9:b0:158:f2e1:8c69 with SMTP id m9-20020a1709026bc900b00158f2e18c69mr14314456plt.69.1651539867062; Mon, 02 May 2022 18:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651539867; cv=none; d=google.com; s=arc-20160816; b=moZl/FbC2kYSSJ9WHM+t8g3mZoJf3w6APzNw7k8uKw5a183BuC6ztlaGxM6TV2P8an a9+5SOSCchaqI2+Oqm+vQsdcu7powEWn89I3EYFJAJp0GM/qNU3nyYsyqC6iXocJr8RF w70fOQjTvt+IO1G88Mxjk4RQhc1YWJeYLV12ImHeCj4aSoX0N0MWISGO5T3vPs79he/S Xgy5jhyd9kqHNIsDeaGIuA1/wzFxjdsI5O7/3Wz1LFNAyBfG950L7FMjJIV8edPnS+bS 8FI5R1xO9cn7chF3WqHoYcUgDfzV6vvZhJbPdwY1SS49OVvxKoBUXA5d7YxNcMhR2qp7 KSQQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fgcN0qR53PxDNDyRz8mDwIaBEjIsjkyTe89/FfZgIDM=; b=rnqm3Mc9St+u8KXeNCUq2vtZrOzJ/6HgTVEjnN5SkIOEbz1i29GI+hrnyStmwcQVE9 0fwSoVpQ5UkM2+pKpe5Un6ca+//huaLCEtILW8cRnVUm6F+5eg1EebrLGFd9sSdGFmuk D2hk13Uvmu346FWNuiOIdOsLc+h54FaV1BpU0eE5f3MbiSWeL1VsZRGZxFn3NH9VK4XS dhJvGrrVXeNH3dCy0YN0V1iIwLHtGg78z0TJGeteU4PmBpmtkir5V+JSTrKuzL108Nm/ /jdgi9/sNkiiaECV8nUy66Bv40BqdaymOAxU0ZWCxNHMp0pevNBXUkNJBAlORIGB2qSa 5s6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b="eshy/VUi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g4-20020a636b04000000b003c26d66859bsi1087266pgc.417.2022.05.02.18.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 18:04:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b="eshy/VUi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AED5B37BEE; Mon, 2 May 2022 17:48:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbiD3M2D (ORCPT + 99 others); Sat, 30 Apr 2022 08:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232836AbiD3M2C (ORCPT ); Sat, 30 Apr 2022 08:28:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79A0139; Sat, 30 Apr 2022 05:24:39 -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 4367560AE5; Sat, 30 Apr 2022 12:24:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23826C385A7; Sat, 30 Apr 2022 12:24:38 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="eshy/VUi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1651321475; 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=fgcN0qR53PxDNDyRz8mDwIaBEjIsjkyTe89/FfZgIDM=; b=eshy/VUiIAgCcfeuV75Wr/Er5w1aUXt6kzCJoYjL15KSNHeEk5Jh2kfFZE04m/Q87EiXym PF2/F+ko2ujnFvZfStEdi9cFC/HZqkpv+lmKPIP8OWcglsvBB5pRZAhWxmxKRJcfHYA6V9 N9vHELmyGyG+03V5TZgeyG3/1+c+VV8= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id f9b1305e (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 30 Apr 2022 12:24:35 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, openrisc@lists.librecores.org, shorne@gmail.com Cc: "Jason A. Donenfeld" Subject: [PATCH v8 06/19] openrisc: start CPU timer early in boot Date: Sat, 30 Apr 2022 14:24:33 +0200 Message-Id: <20220430122433.2719029-1-Jason@zx2c4.com> In-Reply-To: <20220430122355.2718797-1-Jason@zx2c4.com> References: <20220430122355.2718797-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 In order to measure the boot process, the timer should be switched on as early in boot as possible. This is necessary so that by the time the setup code reaches random_init(), get_cycles() (by way of random_get_entropy()) returns non-zero, indicating that it is actually capable of counting. So this commit enables the timer immediately upon booting up. As well, the commit define the get_cycles macro, like the previous patches in this series, so that generic code is aware that it's implemented by the platform, as is done on other archs. Cc: Thomas Gleixner Cc: Arnd Bergmann Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Signed-off-by: Jason A. Donenfeld --- Changes v7->v8: - Rather than doing get_cycles()+1 to handle the early boot case, actually start the timer early in boot. This has the huge advantage of properly measuring the boot sequence timing, which could be a valuable source of entropy. arch/openrisc/include/asm/timex.h | 1 + arch/openrisc/kernel/setup.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/arch/openrisc/include/asm/timex.h b/arch/openrisc/include/asm/timex.h index d52b4e536e3f..5487fa93dd9b 100644 --- a/arch/openrisc/include/asm/timex.h +++ b/arch/openrisc/include/asm/timex.h @@ -23,6 +23,7 @@ static inline cycles_t get_cycles(void) { return mfspr(SPR_TTCR); } +#define get_cycles get_cycles /* This isn't really used any more */ #define CLOCK_TICK_RATE 1000 diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index 0cd04d936a7a..1cb7c1770a17 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -220,6 +220,13 @@ void __init setup_cpuinfo(void) void __init or1k_early_setup(void *fdt) { + /* Start the TTCR as early as possible, so that the RNG can make use of + * measurements of boot time from the earliest opportunity. Especially + * important is that the TTCR does not return zero by the time we reach + * rand_initialize(). + */ + mtspr(SPR_TTMR, SPR_TTMR_CR); + if (fdt) pr_info("FDT at %p\n", fdt); else { -- 2.35.1