git: 0ae7446ed3fa - stable/13 - Reduce an arm64 VFP critical section

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 15 May 2023 15:46:01 UTC
The branch stable/13 has been updated by andrew:

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

commit 0ae7446ed3faf51ce457178f538eca04b22774d7
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2023-01-18 09:30:36 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-05-15 10:54:57 +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
    
    (cherry picked from commit a85cf421d1bfec7e753bfee781355785b00d89d4)
---
 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 fab0ee2ba993..21435362f3e3 100644
--- a/sys/arm64/arm64/exec_machdep.c
+++ b/sys/arm64/arm64/exec_machdep.c
@@ -512,8 +512,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;
 
@@ -521,7 +520,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"));
@@ -531,8 +532,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
 }