Re: [PATCH] random: remove early archrandom abstraction

From: Jason A. Donenfeld
Date: Sun Oct 30 2022 - 17:08:34 EST


Hi Catalin,

> > +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.

This occurred to me too and I wasn't quite sure how the interaction
worked out. It sounds like system_capabilities_finalized() might still
be false when SMP brings up other cores? In that case, I guess we just
have to make sure the system is still booting / in single CPU mode,
before interrupts have been enabled. This should be straight forward to
do; I'll send a v2.

Jason