Module Name: src
Committed By: riastradh
Date: Mon Jun 15 01:23:44 UTC 2020
Modified Files:
src/sys/arch/x86/x86: cpu_rng.c
Log Message:
Use x86_read_psl/x86_disable_intr/x86_read_psl to defer interrupts.
Using x86_disable_intr/x86_enable_intr causes a bit of a snag when we
try it early at boot before we're ready to handle interrupts, because
it has the effect of enabling interrupts!
Fixes instant reset at boot on VIA CPUs. The instant reset on boot
is new since the entropy rework, which initialized the x86 CPU RNG
earlier than before, but in principle this could also cause other
problems while not early at boot too.
XXX pullup
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/x86/cpu_rng.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/x86/cpu_rng.c
diff -u src/sys/arch/x86/x86/cpu_rng.c:1.15 src/sys/arch/x86/x86/cpu_rng.c:1.16
--- src/sys/arch/x86/x86/cpu_rng.c:1.15 Fri Jun 5 21:48:03 2020
+++ src/sys/arch/x86/x86/cpu_rng.c Mon Jun 15 01:23:44 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_rng.c,v 1.15 2020/06/05 21:48:03 kamil Exp $ */
+/* $NetBSD: cpu_rng.c,v 1.16 2020/06/15 01:23:44 riastradh Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -186,6 +186,7 @@ cpu_rng_rdseed_rdrand(uint64_t *out)
static size_t
cpu_rng_via(uint64_t *out)
{
+ u_long psl;
uint32_t creg0, rndsts;
/*
@@ -199,9 +200,9 @@ cpu_rng_via(uint64_t *out)
* even if such a fault is generated.
*
* XXX can this really happen if we don't use "rep xstorrng"?
- *
*/
kpreempt_disable();
+ psl = x86_read_psl();
x86_disable_intr();
creg0 = rcr0();
lcr0(creg0 & ~(CR0_EM|CR0_TS)); /* Permit access to SIMD/FPU path */
@@ -215,7 +216,7 @@ cpu_rng_via(uint64_t *out)
: "=a" (rndsts), "+D" (out) : "d" (0) : "memory");
/* Put CR0 back how it was */
lcr0(creg0);
- x86_enable_intr();
+ x86_write_psl(psl);
kpreempt_enable();
/*