Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Use x86_read_psl/x86_disable_intr/x86_read_...



details:   https://anonhg.NetBSD.org/src/rev/31b056aa361a
branches:  trunk
changeset: 1011024:31b056aa361a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jun 15 01:23:44 2020 +0000

description:
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

diffstat:

 sys/arch/x86/x86/cpu_rng.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (37 lines):

diff -r d7e7440f2eb5 -r 31b056aa361a sys/arch/x86/x86/cpu_rng.c
--- a/sys/arch/x86/x86/cpu_rng.c        Mon Jun 15 00:46:00 2020 +0000
+++ b/sys/arch/x86/x86/cpu_rng.c        Mon Jun 15 01:23:44 2020 +0000
@@ -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 @@
 static size_t
 cpu_rng_via(uint64_t *out)
 {
+       u_long psl;
        uint32_t creg0, rndsts;
 
        /*
@@ -199,9 +200,9 @@
         * 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 @@
            : "=a" (rndsts), "+D" (out) : "d" (0) : "memory");
        /* Put CR0 back how it was */
        lcr0(creg0);
-       x86_enable_intr();
+       x86_write_psl(psl);
        kpreempt_enable();
 
        /*



Home | Main Index | Thread Index | Old Index