From nobody Mon Oct 05 13:37:55 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 4hz0nb5qSnz6js5T for ; Mon, 05 Oct 2026 13:37:55 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hz0nb3rP4z4rMn for ; Mon, 05 Oct 2026 13:37:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791207475; 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=uL/DHqRFtMY1BuxuLcKYYvhm9+vr6bGuKASFABgUP98=; b=Dp7GrT+ItQyY+Wl0gcXCxYfiywtREX+VRc9d2Vv19zQu/sUukgwRo3DBh5SqQevDiOrSCp 6+G0MOO5IMCvfI6BUHHZEL14VKXmmq8wyS1MepGxiJpj9i4JcXa1WCWdTqhYXWqwB+RepS cBfcfDZEMkJpqcKTnbBh4GRUv/oRrlbgENmMbA/9X1GUlA36FWuHv6Rfk6H5CGU9s5nhUX Td8bUbRqo1dGVDIsAlFN0pDe8yajI49fHo5VsCJkaNSbVFj97yobUq9fQnPm/qxsawFeth 1ywE3/D5uuMKBNTwHqrzqzp96Vq9+24PeNCugmf7f85K8ao369xYfyB2/+QXzw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791207475; b=L4tCTCFJpFUSkPNH3t553evVY+xYPZmVs1ttFkXYzZNVexG+is2bH/JpBUk7EVFX+l1iF/ 1NNZhVdt5IFkwy8/xoVbNDXbg+xLuRLtUfXQo/1rGdY/oZR1R81xjnkFwyOOTaqgYTevPj pheeGBNZ/+ZKDVAgtS5oOr/IHoMmsALawpaRd1GxABF/5M8/j9XFAKgVTEAjq6+dtnTf7B N+0ZXIh4nTgkhvtaujOjz+3n1fUbRJinXUfzNEwCY2bZMNwcoR4H8gWYZCRPws89Fwtn/S SBDAGp/OkyXqt2BEr2qI3tLSv3wOky6jjUa7QjBMWqe0DcWekiLpudYFEJ9SRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791207475; 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=uL/DHqRFtMY1BuxuLcKYYvhm9+vr6bGuKASFABgUP98=; b=dvfHMYlM+9SVhPXAtB7u2NCEK9fWCm7Lu+W/ZvxqopTc5V1aw5+PyAIEV0T2tCk1pWnsEB niv44y/39E7c0CRLm56b8KtDSi1C1/ISiWu296Ttbpda9iaHO3G/tS7ZkhcWRvzdgwDlQP TgJK3+YDxRjisIY2wdPt0Dyz6hUsMBEbQQPKpNHeqEDpyi5yYHGoigF0eG9wRf20yGHIQ8 BM3Ia0VqyTOWrLMbT4o8PQe93PqgCgyt7siO/+WrtulhX6OfJD4Ke5VShAwvfeID3rp/OH FOTkRkj87f/auw74YpFGXgCtU9ShYwB36giaf53BXPISjR903nL/RLsY/MDK5Q== 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 4hz0nb25w3zLhx for ; Mon, 05 Oct 2026 13:37:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 406fb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 05 Oct 2026 13:37:55 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Kubaj Subject: git: 1f1043d550ea - main - powerpc: keep FP, VMX and VSX ownership changes atomic with preemption 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pkubaj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f1043d550ea2b8282e692019f17a88896212a76 Auto-Submitted: auto-generated Date: Mon, 05 Oct 2026 13:37:55 +0000 Message-Id: <6ac3a833.406fb.44575d79@gitrepo.freebsd.org> The branch main has been updated by pkubaj: URL: https://cgit.FreeBSD.org/src/commit/?id=1f1043d550ea2b8282e692019f17a88896212a76 commit 1f1043d550ea2b8282e692019f17a88896212a76 Author: Piotr Kubaj AuthorDate: 2026-09-21 12:48:06 +0000 Commit: Piotr Kubaj CommitDate: 2026-10-05 13:37:46 +0000 powerpc: keep FP, VMX and VSX ownership changes atomic with preemption trap() and set_mcontext() change the FP/VMX/VSX ownership state in several steps with preemption enabled. A context switch in between leaves the thread computing with another thread's register contents: - enable_fpu()/enable_vec() set PCB_FPU/PCB_VEC before loading the registers, so a switch mid-load saves a half-loaded unit over the PCB. - set_mcontext() clears the frame's MSR bits and then the PCB flags; a switch in between re-enables the unit, and the thread returns to user space with it enabled but not owned, so it is neither saved nor restored until the next signal. Both paths run after every sigreturn(2), setcontext(2) and swapcontext(3). A POWER9 test that keeps f14-f31 live across a signal, with other threads using the FPU on the same CPU, saw 283 corrupted round trips out of 882000; none after this change. Hold a critical section around both, as amd64 and arm64 do. Reviewed by: jhibbits MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D60054 --- sys/powerpc/powerpc/exec_machdep.c | 8 +++++++- sys/powerpc/powerpc/trap.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index 18e0ba004a13..7192feae6055 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -522,7 +522,14 @@ set_mcontext(struct thread *td, mcontext_t *mcp) * * Additionally, ensure VSX is disabled as well, as it is illegal * to leave it turned on when FP or VEC are off. + * + * The MSR bits in the frame and the PCB flags must change together: + * if the thread is switched out in between, cpu_switchin() still + * sees the flags, reloads the registers and puts the MSR bits back + * into the frame, and the thread then runs with the units enabled + * but without owning them. */ + critical_enter(); tf->srr1 &= ~(PSL_FP | PSL_VSX | PSL_VEC); pcb->pcb_flags &= ~(PCB_FPU | PCB_VSX | PCB_VEC); @@ -536,7 +543,6 @@ set_mcontext(struct thread *td, mcontext_t *mcp) * sigresume is callled will used by the resumed thread, instead of the * previously saved data from the mcontext. */ - critical_enter(); msr = mfmsr() & ~(PSL_FP | PSL_VSX | PSL_VEC); isync(); mtmsr(msr); diff --git a/sys/powerpc/powerpc/trap.c b/sys/powerpc/powerpc/trap.c index 6843ce49b48f..b04506cf10d9 100644 --- a/sys/powerpc/powerpc/trap.c +++ b/sys/powerpc/powerpc/trap.c @@ -294,24 +294,30 @@ trap(struct trapframe *frame) case EXC_FPU: KASSERT((td->td_pcb->pcb_flags & PCB_FPU) != PCB_FPU, ("FPU already enabled for thread")); + critical_enter(); enable_fpu(td); + critical_exit(); break; case EXC_VEC: KASSERT((td->td_pcb->pcb_flags & PCB_VEC) != PCB_VEC, ("Altivec already enabled for thread")); + critical_enter(); enable_vec(td); + critical_exit(); break; case EXC_VSX: KASSERT((td->td_pcb->pcb_flags & PCB_VSX) != PCB_VSX, ("VSX already enabled for thread")); + critical_enter(); if (!(td->td_pcb->pcb_flags & PCB_VEC)) enable_vec(td); if (td->td_pcb->pcb_flags & PCB_FPU) save_fpu(td); td->td_pcb->pcb_flags |= PCB_VSX; enable_fpu(td); + critical_exit(); break; case EXC_FAC: