From 9fa027f16fcb815ac6d45f93c5c75deb8f911231 Mon Sep 17 00:00:00 2001 From: bluhm Date: Wed, 22 Nov 2023 18:50:10 +0000 Subject: [PATCH] Fix race when initializing TSC. 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index bee2ff12b6d..db06cd7d527 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -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() */ -- 2.20.1