git: 8a79b6398f06 - main - powerpc: don't drop FPU and VMX ownership in grab_mcontext()

From: Piotr Kubaj <pkubaj_at_FreeBSD.org>
Date: Fri, 13 Nov 2026 19:54:52 UTC
The branch main has been updated by pkubaj:

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

commit 8a79b6398f06f31947a2dada576c5f489c69d498
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2026-10-18 10:41:36 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2026-11-13 19:53:00 +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
---
 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 68a52c463ce3..66ee64554965 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;