summaryrefslogtreecommitdiff
path: root/sys/arch/arm64
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-05 23:16:25 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2020-06-05 23:16:25 +0000
commita90f318b6153d167e0650e862255c8119c8702f2 (patch)
treef68618e2ff6fde6968e04f557782b7e52813c737 /sys/arch/arm64
parentbb47463e44ba95db5a0ce64649ba085ef8c18638 (diff)
Implement cpu_rnd_messybits() as a read of the virtual counter xored
with a bit-reversed copy of itself. There is progressively less entropy in the higher bits of a counter than in the lower bits, so bit-reverse one half in order to extract maximal entropy. style fixes and ok kettenis@
Diffstat (limited to 'sys/arch/arm64')
-rw-r--r--sys/arch/arm64/arm64/machdep.c11
-rw-r--r--sys/arch/arm64/include/cpu.h13
2 files changed, 12 insertions, 12 deletions
diff --git a/sys/arch/arm64/arm64/machdep.c b/sys/arch/arm64/arm64/machdep.c
index 4e292479233..db37ab929f3 100644
--- a/sys/arch/arm64/arm64/machdep.c
+++ b/sys/arch/arm64/arm64/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.52 2020/05/31 06:23:57 dlg Exp $ */
+/* $OpenBSD: machdep.c,v 1.53 2020/06/05 23:16:24 naddy Exp $ */
/*
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
*
@@ -1247,12 +1247,3 @@ dumpregs(struct trapframe *frame)
printf("pc: 0x%016lx\n", frame->tf_elr);
printf("spsr: 0x%016lx\n", frame->tf_spsr);
}
-
-unsigned int
-cpu_rnd_messybits(void)
-{
- struct timespec ts;
-
- nanotime(&ts);
- return (ts.tv_nsec ^ (ts.tv_sec << 20));
-}
diff --git a/sys/arch/arm64/include/cpu.h b/sys/arch/arm64/include/cpu.h
index 099567d225c..a4d18502997 100644
--- a/sys/arch/arm64/include/cpu.h
+++ b/sys/arch/arm64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.17 2020/05/31 06:23:57 dlg Exp $ */
+/* $OpenBSD: cpu.h,v 1.18 2020/06/05 23:16:24 naddy Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
*
@@ -183,7 +183,16 @@ void cpu_boot_secondary_processors(void);
#define curpcb curcpu()->ci_curpcb
-unsigned int cpu_rnd_messybits(void);
+static inline unsigned int
+cpu_rnd_messybits(void)
+{
+ uint64_t val, rval;
+
+ __asm volatile("mrs %0, CNTVCT_EL0; rbit %1, %0;"
+ : "=r" (val), "=r" (rval));
+
+ return (val ^ rval);
+}
/*
* Scheduling glue