Fix race when initializing TSC.
authorbluhm <bluhm@openbsd.org>
Wed, 22 Nov 2023 18:50:10 +0000 (18:50 +0000)
committerbluhm <bluhm@openbsd.org>
Wed, 22 Nov 2023 18:50:10 +0000 (18:50 +0000)
During boot TSC initialization could fail with panic: tsc_test_sync_ap:
cpu2: tsc_ap_name is not NULL: cpu1.
The root cause is a race between the moment the application processor
sets CPUF_IDENTIFIED in cpu_hatch() and the moment the boot processor
checks CPUF_IDENTIFIED in cpu_start_secondary() before the TSC sync
test.
The fix is to set CPUF_IDENTIFIED before clearing CPUF_IDENTIFY in
cpu_hatch().

from hshoexer@ cheloha@; OK deraadt@ mlarkin@

sys/arch/amd64/amd64/cpu.c

index bee2ff1..db06cd7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cpu.c,v 1.176 2023/10/24 13:20:09 claudio Exp $       */
+/*     $OpenBSD: cpu.c,v 1.177 2023/11/22 18:50:10 bluhm Exp $ */
 /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
 
 /*-
@@ -1023,10 +1023,11 @@ cpu_hatch(void *v)
 
                identifycpu(ci);
 
-               /* Signal we're done */
-               atomic_clearbits_int(&ci->ci_flags, CPUF_IDENTIFY);
                /* Prevent identifycpu() from running again */
                atomic_setbits_int(&ci->ci_flags, CPUF_IDENTIFIED);
+
+               /* Signal we're done */
+               atomic_clearbits_int(&ci->ci_flags, CPUF_IDENTIFY);
        }
 
        /* These have to run after identifycpu() */