Re: [PATCH] random: remove early archrandom abstraction

From: Catalin Marinas
Date: Sun Oct 30 2022 - 13:30:21 EST


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