git: 9ff643a8da47 - main - arm64: Adjust the MPASS in vfp_save_state_savectx

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 19 Nov 2024 17:47:02 UTC
The branch main has been updated by andrew:

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

commit 9ff643a8da476c38b29c071d00805d52b851ee03
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-11-18 15:34:09 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-11-19 17:31:00 +0000

    arm64: Adjust the MPASS in vfp_save_state_savectx
    
    In vfp_save_state_savectx we check if the pcb has a NULL vfp state.
    When it's called multiple times with the same pcb then we can panic
    because the vfp state has been set.
    
    Weaken the requirement for the state pointer to be NULL by also
    allowing it to point to the pcb vfp state area we are about to use.
    
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D47237
---
 sys/arm64/arm64/vfp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c
index a3aa77ed6180..bcddebfaf66e 100644
--- a/sys/arm64/arm64/vfp.c
+++ b/sys/arm64/arm64/vfp.c
@@ -577,10 +577,13 @@ vfp_save_state_savectx(struct pcb *pcb)
 {
 	/*
 	 * savectx() will be called on panic with dumppcb as an argument,
-	 * dumppcb doesn't have pcb_fpusaved set, so set it to save
-	 * the VFP registers.
+	 * dumppcb either has no pcb_fpusaved set or it was previously set
+	 * to its own fpu state.
+	 *
+	 * In both cases we can set it here to the pcb fpu state.
 	 */
-	MPASS(pcb->pcb_fpusaved == NULL);
+	MPASS(pcb->pcb_fpusaved == NULL ||
+	    pcb->pcb_fpusaved == &pcb->pcb_fpustate);
 	pcb->pcb_fpusaved = &pcb->pcb_fpustate;
 
 	vfp_save_state_common(curthread, pcb, true);