Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp2079238rwj; Sun, 30 Oct 2022 10:53:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Jh6RxRKVpoo9gF01vXkaOMJKV8BgJh46Z8bQzoyUhaGhajUO/sMJqrdzBiSSx2EFoSOpn X-Received: by 2002:a63:f07:0:b0:440:5c6e:5833 with SMTP id e7-20020a630f07000000b004405c6e5833mr9218496pgl.375.1667152408610; Sun, 30 Oct 2022 10:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667152408; cv=none; d=google.com; s=arc-20160816; b=skY+mIt8pzEmUblO5CY9qg9zZw6bDL+pTP7eukQfl7MPsYJz3bhwmHFF39GvxnlB3m YJWqFHGa7o/1CNP4KlLk/SKg5tTU7X+jnHCSsUwoyEg5P5fn9Tn9dGV13LR1nUQJv+rY b9B8u4fRovtUBvv9nKDdQhWwbgUmRluya1m+IIFtewv7lDEYn6fGioM1uOHoURua/Zhy PSe56BDHqRRH1yUNJD7uo/WAR/7BTIUqhzP/6gepkPin9nQsD5GFSak2xpTz8ifN7tTt F+w+BBCEFhtD3yqCW10DRAm/Y3Xh9oqIaH5AtL3ztZ801yXkCqSlzgCfbOm62SmxndeE +YWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=c+c/EeHMUsxb9DZBX2Xtok92Dbpxdudyvjl2DUYYudk=; b=g7U0C3bkBoreWz7FmyhbOAlvGd+0Zg2XaXLxxDpFu+KCka/uMJW9q9FLvMAUcgSOfG 8lyp7CKrs7QG8LmjLG49gK4xkzcQiNtGYrK59hKU/XmMZzLwvvpzV87ASRQkuC/Wwd9n QKAVBMPTObUeeSMiJE+rx8u6zcMrxFKedRkhLOL7ntTV9V3yXVbamy4VT5nWKD+0p1Ip BfWI4kgmUmJNLJyzrRXI6ThaKXjSSqnLOqAIdyy69y1ZEUZ+E5GwqTF4rzurPtDy48L4 6fH1mQ1ClPie2I9o6WT5KXBk4qOE6O78BwKy31A0UWGRAffLik25Jc3jB8/lQWBpGJ+Y Yjbw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a17090a4a8e00b0021071bf8d26si5138210pjh.29.2022.10.30.10.52.46; Sun, 30 Oct 2022 10:53:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbiJ3RaT (ORCPT + 99 others); Sun, 30 Oct 2022 13:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbiJ3RaR (ORCPT ); Sun, 30 Oct 2022 13:30:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77853A44C for ; Sun, 30 Oct 2022 10:30:16 -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 2ABE4B80EBC for ; Sun, 30 Oct 2022 17:30:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 902F3C433C1; Sun, 30 Oct 2022 17:30:12 +0000 (UTC) Date: Sun, 30 Oct 2022 17:30:09 +0000 From: Catalin Marinas To: "Jason A. Donenfeld" Cc: will@kernel.org, jean-philippe@linaro.org, ardb@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] random: remove early archrandom abstraction Message-ID: References: <20221028234025.82222-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221028234025.82222-1-Jason@zx2c4.com> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 On Sat, Oct 29, 2022 at 01:40:25AM +0200, Jason A. Donenfeld wrote: > diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/archrandom.h > index 109e2a4454be..8a059a9033af 100644 > --- a/arch/arm64/include/asm/archrandom.h > +++ b/arch/arm64/include/asm/archrandom.h > @@ -58,6 +58,16 @@ static inline bool __arm64_rndrrs(unsigned long *v) > return ok; > } > > +static __always_inline bool __cpu_has_rng(void) > +{ > + if (!system_capabilities_finalized()) { > + /* Open code as we run prior to the first call to cpufeature. */ > + unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1); > + return (ftr >> ID_AA64ISAR0_EL1_RNDR_SHIFT) & 0xf; > + } > + return cpus_have_const_cap(ARM64_HAS_RNG); > +} We need to be careful with this check as it is only valid on the CPU it was called on. Is the result used only on this CPU and with the preemption disabled? We have big.LITTLE systems where CPUs may differ and the ARM64_HAS_RNG feature may not be enabled once all the CPUs have been initialised (capabilities finalised). We could make this capability an ARM64_CPUCAP_BOOT_CPU_FEATURE, though I'd have to check whether any systems in the wild have such mixed CPUs. -- Catalin