Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2179392rwi; Tue, 1 Nov 2022 04:59:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5H//xqIhfMsGLIolPm3r3dEq6kJN3WVA6AHxnQfDWJNX52Tu13C0oTOxNEN8vHaeJkLB9D X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr18795433edi.121.1667303983891; Tue, 01 Nov 2022 04:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667303983; cv=none; d=google.com; s=arc-20160816; b=ZGI08IcVNNwc0vh7ZGBZCvSBMofEcMCnhnwq9mZJ36F2HArWME58dSnREB6ZnynfPa 7idI+uhNOOCIzChVXA6hmdsxLAuf9T1MS/OCcWaB7vOBIH/X95walgwuvWOxBeTZP8p3 1YF1/W+MXrng3I0z7FLtI3+HjI//+A8XUbLTPL0eFQkA1wTB4Mdz4fw3Bb0bQ1vbLVUp 18wVnOPcde8p0wAqF0Xnglek1a0akfrvbXlRj/o+7UBElGeVZ/I6j4JqPxDOrCZsxm/B njx0YyqrqxJm+WWznF+28h7h+PN/Sr65BcuZrCQhLokMwYCd/bpOI7ePs8JuEn98XD3S qLFw== 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=Jl3Ud48g0K6oFYW+9pbg1ZnB/kzklG+vusaHHkLyaGg=; b=gSaAZAM7yQ+YrhkK0MCSt7o85kHRuQDD/Xe64KgQeJOMG7AdBcwG/dkpz/RaGvaaEm r0Q3jMr93Soe4JIIa/aa4ipn9/LEQ0HfpksEHDn74LxHPHu6NcwidEMGs3uCvjth+HZ4 AeP+HF4lixe7hHZJdWRwdc+nsOqXqovYj5Fe7LuBXvllG/Oj2beJt4+xBZGoJEmBJFOj vz3C3k3OSHzjl1cWscm59daCcS7VBInvuyg0cUPP5Ov61cax4XH9q4FoquNuan8LhuBm tMZvwSTYWbkfwDImGxg9NmTklSC+2kxntqW4+eg+ChPK9yhJq3jYFB05vqmINdbwKWaB yKlw== 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 cw14-20020a170906478e00b007ade0bd0306si6059437ejc.227.2022.11.01.04.59.19; Tue, 01 Nov 2022 04:59:43 -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 S231434AbiKALrW (ORCPT + 97 others); Tue, 1 Nov 2022 07:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbiKALrE (ORCPT ); Tue, 1 Nov 2022 07:47:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 188F91A83A for ; Tue, 1 Nov 2022 04:39:19 -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 C3A21B81CE7 for ; Tue, 1 Nov 2022 11:39:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BFA9C433D7; Tue, 1 Nov 2022 11:39:15 +0000 (UTC) Date: Tue, 1 Nov 2022 11:39:11 +0000 From: Catalin Marinas To: "Jason A. Donenfeld" Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Will Deacon , Ard Biesheuvel , Jean-Philippe Brucker Subject: Re: [PATCH v3] random: remove early archrandom abstraction Message-ID: References: <20221030212123.1022049-1-Jason@zx2c4.com> <20221031102840.85621-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221031102840.85621-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 Mon, Oct 31, 2022 at 11:28:40AM +0100, Jason A. Donenfeld wrote: > Catalin - Though this touches arm64's archrandom.h, I intend to take > this through the random.git tree, if that's okay. I have other patches > that will build off of this one. -Jason I'm fine with the patch going through your tree but I have a comment below. > diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/archrandom.h > index 109e2a4454be..4b0f28730ab2 100644 > --- a/arch/arm64/include/asm/archrandom.h > +++ b/arch/arm64/include/asm/archrandom.h > @@ -58,6 +58,20 @@ static inline bool __arm64_rndrrs(unsigned long *v) > return ok; > } > > +static inline bool __early_cpu_has_rndr(void) > +{ > + /* 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; > +} > + > +static __always_inline bool __cpu_has_rng(void) > +{ > + if (!system_capabilities_finalized() && early_boot_irqs_disabled) > + return __early_cpu_has_rndr(); > + return cpus_have_const_cap(ARM64_HAS_RNG); > +} I'm not sure about using early_boot_irqs_disabled, it is described as a debug helper. It's also set to 'false' before system_capabilities_finalized() (once the full SMP is enabled). Would something like this work: if (system_capabilities_finalized()) return cpus_have_final_cap(ARM64_HAS_RNG); if (!preemptible()) return __early_cpu_has_rndr(); return false; We also have a this_cpu_has_cap() function, though it's likely more expensive than the hand-coded __early_cpu_has_rndr() (if we care about performance here). -- Catalin