Date: Tue, 19 Jul 2022 07:37:25 GMT From: Andrew Turner <andrew@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 5ab7ba992e69 - stable/13 - Split out vfp_new_thread Message-ID: <202207190737.26J7bPUf021579@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=5ab7ba992e697a21729842d3839e46ff595b6aea commit 5ab7ba992e697a21729842d3839e46ff595b6aea Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2022-06-24 11:53:15 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2022-07-19 07:03:31 +0000 Split out vfp_new_thread To keep the vfp thread creation code in one place move into vfp.c. This will also help with adding SVE support as it depends on VFP. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35615 (cherry picked from commit baf8f20a4af43283a1fbee49b0c2ad906074f20f) --- sys/arm64/arm64/vfp.c | 26 ++++++++++++++++++++++++++ sys/arm64/arm64/vm_machdep.c | 10 +++++----- sys/arm64/include/vfp.h | 1 + 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c index c740832f9ef0..755143d656dc 100644 --- a/sys/arm64/arm64/vfp.c +++ b/sys/arm64/arm64/vfp.c @@ -199,6 +199,32 @@ vfp_save_state(struct thread *td, struct pcb *pcb) 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 index f99721023320..2d3e5e342889 100644 --- a/sys/arm64/arm64/vm_machdep.c +++ b/sys/arm64/arm64/vm_machdep.c @@ -109,8 +109,8 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags) td2->td_pcb->pcb_x[9] = (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 @@ cpu_copy_thread(struct thread *td, struct thread *td0) td->td_pcb->pcb_x[9] = (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 index 650eb6938f5e..b093ecd768cc 100644 --- a/sys/arm64/include/vfp.h +++ b/sys/arm64/include/vfp.h @@ -67,6 +67,7 @@ struct thread; 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 *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207190737.26J7bPUf021579>