git: 76eb059d05d6 - stable/15 - powerpc: don't drop FPU and VMX ownership in grab_mcontext()

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

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

commit 76eb059d05d6689449519d9cc3d85694698161f6
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2026-10-18 10:41:36 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2026-11-22 19:28:39 +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 a248aeeafaf7..8b02d5cf19be 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;