diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c --- a/sys/arm64/arm64/vfp.c +++ b/sys/arm64/arm64/vfp.c @@ -199,6 +199,32 @@ critical_exit(); } +/* + * Update the VFP state for a forked process or new thread. The PCB will + * have been copied from the old thread. + */ +void +vfp_new_thread(struct thread *newtd, struct thread *oldtd, bool fork) +{ + struct pcb *newpcb; + + newpcb = newtd->td_pcb; + + /* Kernel threads start with clean VFP */ + if ((oldtd->td_pflags & TDP_KTHREAD) != 0) { + newpcb->pcb_fpflags &= + ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE); + } else { + MPASS((newpcb->pcb_fpflags & (PCB_FP_KERN|PCB_FP_NOSAVE)) == 0); + if (!fork) { + newpcb->pcb_fpflags &= ~PCB_FP_STARTED; + } + } + + newpcb->pcb_fpusaved = &newpcb->pcb_fpustate; + newpcb->pcb_vfpcpu = UINT_MAX; +} + /* * Reset the FP state to avoid leaking state from the parent process across * execve() (and to ensure that we get a consistent floating point environment diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c --- a/sys/arm64/arm64/vm_machdep.c +++ b/sys/arm64/arm64/vm_machdep.c @@ -109,8 +109,8 @@ td2->td_pcb->pcb_x[20] = (uintptr_t)td2; td2->td_pcb->pcb_lr = (uintptr_t)fork_trampoline; td2->td_pcb->pcb_sp = (uintptr_t)td2->td_frame; - td2->td_pcb->pcb_fpusaved = &td2->td_pcb->pcb_fpustate; - td2->td_pcb->pcb_vfpcpu = UINT_MAX; + + vfp_new_thread(td2, td1, true); /* Setup to release spin count in fork_exit(). */ td2->td_md.md_spinlock_count = 1; @@ -187,9 +187,9 @@ td->td_pcb->pcb_x[20] = (uintptr_t)td; td->td_pcb->pcb_lr = (uintptr_t)fork_trampoline; td->td_pcb->pcb_sp = (uintptr_t)td->td_frame; - td->td_pcb->pcb_fpflags &= ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE); - td->td_pcb->pcb_fpusaved = &td->td_pcb->pcb_fpustate; - td->td_pcb->pcb_vfpcpu = UINT_MAX; + + /* Update VFP state for the new thread */ + vfp_new_thread(td, td0, false); /* Setup to release spin count in fork_exit(). */ td->td_md.md_spinlock_count = 1; diff --git a/sys/arm64/include/vfp.h b/sys/arm64/include/vfp.h --- a/sys/arm64/include/vfp.h +++ b/sys/arm64/include/vfp.h @@ -68,6 +68,7 @@ void vfp_init(void); void vfp_discard(struct thread *); +void vfp_new_thread(struct thread *, struct thread *, bool); void vfp_reset_state(struct thread *, struct pcb *); void vfp_restore_state(void); void vfp_save_state(struct thread *, struct pcb *);