[PATCH v3] random: remove early archrandom abstraction
Catalin Marinas
catalin.marinas at arm.com
Tue Nov 1 04:39:11 PDT 2022
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
More information about the linux-arm-kernel
mailing list