Re: [PATCH] random: remove early archrandom abstraction

From
Catalin Marinas <catalin.marinas@arm.com>
Date
2022-10-30 17:30:21
Also in
lkml
Reply to
Jason A. Donenfeld, 2022-10-28
On Sat, Oct 29, 2022 at 01:40:25AM +0200, Jason A. Donenfeld wrote:
quoted hunk ↗ jump to hunk
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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thread (13 messages) 13 messages, 3 authors, last reply 2022-11-01
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help