git: c7b5351a0a75 - stable/14 - powerpc: don't drop FPU and VMX ownership in grab_mcontext()

From: Piotr Kubaj <pkubaj_at_FreeBSD.org>
Date: Sun, 22 Nov 2026 19:29:28 UTC
The branch stable/14 has been updated by pkubaj:

URL: https://cgit.FreeBSD.org/src/commit/?id=c7b5351a0a75c7a17645718550c1aac8467d0de8

commit c7b5351a0a75c7a17645718550c1aac8467d0de8
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2026-10-18 10:41:36 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2026-11-22 14:41:02 +0000

    powerpc: don't drop FPU and VMX ownership in grab_mcontext()
    
    grab_mcontext() saved the FP and vector registers with save_fpu() and
    save_vec(), which drop ownership: PCPU(fputhread) becomes NULL while
    PCB_FPU stays set and the thread keeps using the unit. A later
    cpu_update_pcb(), at fork(2) or thr_new(2), then skipped the save,
    since save_fpu_nodrop() only saves for the thread that owns the unit,
    and the child got the registers as they were at the getcontext() or
    signal rather than at the fork. Use the nodrop variants.
    
    A child forked after getcontext() saw the parent's f14 as it was at
    the getcontext(); it sees the current value now.
    
    Reviewed by:    adrian, jhibbits
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D60837
    
    (cherry picked from commit 8a79b6398f06f31947a2dada576c5f489c69d498)
---
 sys/powerpc/powerpc/exec_machdep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c
index e0e20f7cddf8..1fe22f504f92 100644
--- a/sys/powerpc/powerpc/exec_machdep.c
+++ b/sys/powerpc/powerpc/exec_machdep.c
@@ -414,7 +414,7 @@ grab_mcontext(struct thread *td, mcontext_t *mcp, int flags)
 			KASSERT(td == curthread,
 				("get_mcontext: fp save not curthread"));
 			critical_enter();
-			save_fpu(td);
+			save_fpu_nodrop(td);
 			critical_exit();
 		}
 		mcp->mc_flags |= _MC_FP_VALID;
@@ -448,7 +448,7 @@ grab_mcontext(struct thread *td, mcontext_t *mcp, int flags)
 			KASSERT(td == curthread,
 				("get_mcontext: altivec save not curthread"));
 			critical_enter();
-			save_vec(td);
+			save_vec_nodrop(td);
 			critical_exit();
 		}
 		mcp->mc_flags |= _MC_AV_VALID;