From nobody Tue Oct 28 19:23:39 2025 X-Original-To: dev-commits-src-branches@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 4cx0fN215Jz6DMB2; Tue, 28 Oct 2025 19:23:40 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cx0fN1T3Yz3VL1; Tue, 28 Oct 2025 19:23:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761679420; 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=78iYwRdvXVrVIUyegHQYzfaHD/ZBj4hERKbsARNETO0=; b=kuJZxjWebOLQwfhkIsKnMwSCnBjtuRRPlHwQzeG3H0lxqTIjtRvA8Iuj4IksVeEFb5vQkZ hE4iONkszWwcqfgvm+ovFpcV4Anr+eWOmG0yiVYuYTjjDYP1PaBrbgu04BwTN7iq/D75Pb Jj0oQwwXkj+dXSe/RZ3bp0b2kUV02gyBP3KoMPtq/SOUfDLepjfAk/7QBLSq1Gfg++qWMZ 9zqDMJgUdVzdYoO6c3X+1ilpSaZZ8mmolNqDlgg+BtaTA8elmRvDn5saIiIgzTqkREECiy VQ9SXyDtF7BTP0CjVVYFNM10Jam8Hx0h7M2lRTmSesRcdzoCugWyWI97f5XQNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761679420; 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=78iYwRdvXVrVIUyegHQYzfaHD/ZBj4hERKbsARNETO0=; b=VsmdENx/c/HKE0lPAmbCFVmpLsWFRqR2Uxllc9HN2xL/xUtFfWUyS4WLoqRKGxDRDBF2CX Mxe8lVGCkXW3lkeLwUib88dXokic3tl1nz1Ri/N4OZpGXsnJZ9zXH6tDvCrjblLwdesK0t YB1HUcGsDR2FGOOyQeAgqMcUyNgyU84b6+q6IIyDQVpfirLafKfDMLqimBcZQ0SGXTnT98 rgzXjD9khiAXEvLtoS62HRNR9PV5zADxKdrft7Pj42OjDbwGf8yqs4EaaTG1Ipp8udBd9G ofOa0LoiROeOuM6ASeUtfuT810gti0WmWQkfHIkKaX3NxfQNpSYNx36qmlpCag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761679420; a=rsa-sha256; cv=none; b=F/pUMBshG0Knht/T/eSmPXnI5ZDTdWxgx0+WGVEq0TyjZANCuk60lYzKr+Pr5KgUwcAmCE GkEJD6YLt+1g9TQZfHmlCQ1cDhB21T88RyPkvkhnL4zc09ryL/blRJz/nkkMCc3opH9EcN rObaWGO9ZKHgxJhV/AIMn7jRC1FJznaq2WUKbjB7nU0FPEqyXrHEOFjcOBBsZ0HDvYfEVJ wMnewUk8Ow2RV2ZEIt5G8lgCciQxoh5Yd2TCWzMwrTQluX1nztlu6MJpUKnm03pohdnYO5 yVYggeZZvriW/fS5Mciqrg9UtwOZHpHoAQVxFkFV4To0zNZ9y/nrQxvKhaOQPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cx0fN0Hb7z13lf; Tue, 28 Oct 2025 19:23:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 59SJNdMF049450; Tue, 28 Oct 2025 19:23:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59SJNd0M049447; Tue, 28 Oct 2025 19:23:39 GMT (envelope-from git) Date: Tue, 28 Oct 2025 19:23:39 GMT Message-Id: <202510281923.59SJNd0M049447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Jonathan T. Looney" Subject: git: f5d3c2c7d9db - stable/14 - x86: Reduce amount of time the MCA lock is held while emitting records List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jtl X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f5d3c2c7d9db359f04ddaf8dbdcc1cd2f4b4dfa8 Auto-Submitted: auto-generated The branch stable/14 has been updated by jtl: URL: https://cgit.FreeBSD.org/src/commit/?id=f5d3c2c7d9db359f04ddaf8dbdcc1cd2f4b4dfa8 commit f5d3c2c7d9db359f04ddaf8dbdcc1cd2f4b4dfa8 Author: Jonathan T. Looney AuthorDate: 2025-10-06 15:07:33 +0000 Commit: Jonathan T. Looney CommitDate: 2025-10-28 19:23:08 +0000 x86: Reduce amount of time the MCA lock is held while emitting records The MCA spin lock is acquired in the hardware interrupt context to record MCA messages. It is also acquired by a task handler to emit those messages. Reduce the amount of time the task handler holds the lock to reduce the maximum amount of time the hardware interrupt handler may need to spin on the lock. Reviewed by: glebius, markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D52938 (cherry picked from commit e770e32aa3a017b35fcf24e7c6f14fc2a209bad5) --- sys/x86/x86/mca.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/x86/x86/mca.c b/sys/x86/x86/mca.c index e43c88b3a27b..7ee22895e0a7 100644 --- a/sys/x86/x86/mca.c +++ b/sys/x86/x86/mca.c @@ -796,9 +796,9 @@ mca_record_entry(enum scan_mode mode, const struct mca_record *record) mtx_lock_spin(&mca_lock); rec = STAILQ_FIRST(&mca_freelist); if (rec == NULL) { + mtx_unlock_spin(&mca_lock); printf("MCA: Unable to allocate space for an event.\n"); mca_log(record); - mtx_unlock_spin(&mca_lock); return; } STAILQ_REMOVE_HEAD(&mca_freelist, link); @@ -1017,6 +1017,7 @@ static void mca_process_records(enum scan_mode mode) { struct mca_internal *mca; + STAILQ_HEAD(, mca_internal) tmplist; /* * If in an interrupt context, defer the post-scan activities to a @@ -1028,10 +1029,21 @@ mca_process_records(enum scan_mode mode) return; } + /* + * Copy the pending list to the stack so we can drop the spin lock + * while we are emitting logs. + */ + STAILQ_INIT(&tmplist); mtx_lock_spin(&mca_lock); - while ((mca = STAILQ_FIRST(&mca_pending)) != NULL) { - STAILQ_REMOVE_HEAD(&mca_pending, link); + STAILQ_SWAP(&mca_pending, &tmplist, mca_internal); + mtx_unlock_spin(&mca_lock); + + STAILQ_FOREACH(mca, &tmplist, link) mca_log(&mca->rec); + + mtx_lock_spin(&mca_lock); + while ((mca = STAILQ_FIRST(&tmplist)) != NULL) { + STAILQ_REMOVE_HEAD(&tmplist, link); mca_store_record(mca); } mtx_unlock_spin(&mca_lock);