git: a85cf421d1bf - main - Reduce an arm64 VFP critical section

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Wed, 18 Jan 2023 09:39:50 UTC
The branch main has been updated by andrew:

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

commit a85cf421d1bfec7e753bfee781355785b00d89d4
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2023-01-18 09:30:36 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-01-18 09:31:50 +0000

    Reduce an arm64 VFP critical section
    
    In set_fpcontext we only need a critical section around vfp_discard.
    The remainder of the code can run without it.
    
    While here add an assert to check the passed in thread is the
    current thread as the code already this.
    
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D38000
---
 sys/arm64/arm64/exec_machdep.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sys/arm64/arm64/exec_machdep.c b/sys/arm64/arm64/exec_machdep.c
index 258cb5d26b13..27ee2f80858d 100644
--- a/sys/arm64/arm64/exec_machdep.c
+++ b/sys/arm64/arm64/exec_machdep.c
@@ -519,8 +519,7 @@ set_fpcontext(struct thread *td, mcontext_t *mcp)
 #ifdef VFP
 	struct pcb *curpcb;
 
-	critical_enter();
-
+	MPASS(td == curthread);
 	if ((mcp->mc_flags & _MC_FP_VALID) != 0) {
 		curpcb = curthread->td_pcb;
 
@@ -528,7 +527,9 @@ set_fpcontext(struct thread *td, mcontext_t *mcp)
 		 * Discard any vfp state for the current thread, we
 		 * are about to override it.
 		 */
+		critical_enter();
 		vfp_discard(td);
+		critical_exit();
 
 		KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate,
 		    ("Called set_fpcontext while the kernel is using the VFP"));
@@ -538,8 +539,6 @@ set_fpcontext(struct thread *td, mcontext_t *mcp)
 		curpcb->pcb_fpustate.vfp_fpsr = mcp->mc_fpregs.fp_sr;
 		curpcb->pcb_fpflags = mcp->mc_fpregs.fp_flags & PCB_FP_USERMASK;
 	}
-
-	critical_exit();
 #endif
 }