From nobody Mon Jan 5 23:16:54 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dlVYf2rrVz6MSbP for ; Mon, 05 Jan 2026 23:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dlVYf269Dz3qld for ; Mon, 05 Jan 2026 23:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767655014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fYx4UC1i+c5Eqwma0vzfDidiQFB8t2ihOfFNNtrfsQI=; b=ZxeOeAnnK2Tn96NU8cmbPMhq5ZbkwsW9O8S0jfgbUpHXlq7qeR8hOzCqOHBveu8XnvNgNY hh0/9eR2OPfIHw3SM0LV/42BrYcESMvFBMO0ECXIRlxwcEb900DOKqfU3jxKiafldnqtfw JRKYqCtbRoQIzpaTb5X1D/x2FZCLauxRs3sp1UnEZW5JU90TfrXNZGij6ckpxI+nACpcQa F2vm8Ztq5461a9pcWcEd3nGTyW7OV4B/0Mqof76m8oNpebifb5+p5uICyVUngf6Rm/WxNJ YhlIihh6/MFNOLGU202Gr5ZbEwmbz1P0eNauRiuUvm2Ol4tUcXt7LOjdFHJDJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767655014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fYx4UC1i+c5Eqwma0vzfDidiQFB8t2ihOfFNNtrfsQI=; b=NuohkAsupl5u13qsn60oFxtRh+oSj7zGJTIAMcblqNZ0kZkHbq6ert9jWj3Q1EKpR4A/z4 elsIdyal9eYqpQLNE77evRgdbRcOZ10U/UpNeU6yJJJwIUlbPB2+DwHPT0tOKoUEkQIqW5 zQuo0UhHV8A9xsyEZUpYLIHeuLw+WVfp9gnoURMSMOOVooRunpaiQzWiahbeM0exL+zXfR c62xm6IvTlZRE1IiSPDTw9BE5Lg/Os0R/DdzVjq63DN5gXH0HCT7ZzdD33it3lJ8tz7CHZ SxjdZWFxTMlNtS3ndNhOgEI4pz/stLx2kS5uHKYht/tkkTc2RsxUz4Hz/1x60w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767655014; a=rsa-sha256; cv=none; b=kf6OulGiuOrnzZn6sUK5kjWPFeV9ryka3VtKT7Hmmr9xjWVjp073bel+KDK/fnMH1oyrRv +wDsIt+G17p+HjKLx4klHTjN0eAWf8LYGOovY2itbxuQnjaMqH4Srva4Kz5XURYsrL4PMd ZeNuG/1HeO3O0UTU03JmNAMmCsbQ+q/3W1QUKwKtJ2i8ZrHPpJiHSo7LBmSaNZDizxqWPF /s/bYRcsvDqjY6MrqpIBJRgNE79y9mOhlw2lNWyayjYO/478F6SbbRXsDaDNK8z2HfLS8C ewapxqSS7VTYJ1aTZCRHpsXlnS93g35aYrI681uTC1g1S+jajAGBJzLsHsu4nA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dlVYf1g23zhjP for ; Mon, 05 Jan 2026 23:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 315eb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 05 Jan 2026 23:16:54 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 55305b590797 - main - x86: change ap_boot_mtx from spinlock mutex to naive lock List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 55305b590797524dd1cecfc9406869700e925e51 Auto-Submitted: auto-generated Date: Mon, 05 Jan 2026 23:16:54 +0000 Message-Id: <695c4666.315eb.774c8d12@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=55305b590797524dd1cecfc9406869700e925e51 commit 55305b590797524dd1cecfc9406869700e925e51 Author: Konstantin Belousov AuthorDate: 2026-01-03 01:09:32 +0000 Commit: Konstantin Belousov CommitDate: 2026-01-05 23:12:22 +0000 x86: change ap_boot_mtx from spinlock mutex to naive lock Problem is that the printfs done under the spinlock might be very slow, then spinlock triggers the panic due to some AP holding the mutex too long. We do want to ensure that the printfs are serialized, still. Also, reduce the scope of the lock. The local APIC and MTRR initializations are local to the AP, while mca_init() protects the shared state with mca-private spinlock. PR: 289297 Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54464 --- sys/amd64/amd64/mp_machdep.c | 1 - sys/i386/i386/mp_machdep.c | 2 -- sys/x86/include/x86_smp.h | 1 - sys/x86/x86/mp_x86.c | 17 ++++++++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c index 96ed0a2cc3ba..61f1bdb6f942 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -344,7 +344,6 @@ start_all_aps(void) u_char mpbiosreason; amd64_mp_alloc_pcpu(); - mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN); MPASS(bootMP_size <= PAGE_SIZE); m_boottramp = vm_page_alloc_noobj_contig(0, 1, 0, diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c index f7d9289b1848..18ec0d83fad3 100644 --- a/sys/i386/i386/mp_machdep.c +++ b/sys/i386/i386/mp_machdep.c @@ -369,8 +369,6 @@ start_all_aps(void) u_int32_t mpbioswarmvec; int apic_id, cpu; - mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN); - pmap_remap_lower(true); /* install the AP 1st level boot code */ diff --git a/sys/x86/include/x86_smp.h b/sys/x86/include/x86_smp.h index f5015e9d8a24..045beb3b0f9a 100644 --- a/sys/x86/include/x86_smp.h +++ b/sys/x86/include/x86_smp.h @@ -35,7 +35,6 @@ extern char *bootSTK; extern void *bootstacks[]; extern unsigned int bootMP_size; extern volatile int aps_ready; -extern struct mtx ap_boot_mtx; extern int cpu_logical; extern int cpu_cores; extern volatile uint32_t smp_tlb_generation; diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 6b1715853763..0c32657290a0 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -124,7 +124,7 @@ volatile cpuset_t resuming_cpus; volatile cpuset_t toresume_cpus; /* used to hold the AP's until we are ready to release them */ -struct mtx ap_boot_mtx; +static int ap_boot_lock; /* Set to 1 once we're ready to let the APs out of the pen. */ volatile int aps_ready = 0; @@ -1086,8 +1086,6 @@ init_secondary_tail(void) PCPU_SET(curthread, PCPU_GET(idlethread)); schedinit_ap(); - mtx_lock_spin(&ap_boot_mtx); - mca_init(); /* Init local apic for irq's */ @@ -1096,6 +1094,15 @@ init_secondary_tail(void) /* Set memory range attributes for this CPU to match the BSP */ mem_range_AP_init(); + /* + * Use naive spinning lock instead of the real spinlock, since + * printfs() below might take a very long time and trigger + * spinlock timeout panics. This is the only use of the + * ap_boot_lock anyway. + */ + while (atomic_cmpset_acq_int(&ap_boot_lock, 0, 1) == 0) + ia32_pause(); + smp_cpus++; CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", cpuid); @@ -1117,6 +1124,8 @@ init_secondary_tail(void) atomic_store_rel_int(&smp_started, 1); } + atomic_store_rel_int(&ap_boot_lock, 0); + #ifdef __amd64__ if (pmap_pcid_enabled) load_cr4(rcr4() | CR4_PCIDE); @@ -1125,8 +1134,6 @@ init_secondary_tail(void) load_fs(_ufssel); #endif - mtx_unlock_spin(&ap_boot_mtx); - /* Wait until all the AP's are up. */ while (atomic_load_acq_int(&smp_started) == 0) ia32_pause();