git: 565c887a7752 - main - armv8_crypto: fix recursive fpu_kern_enter call

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Fri, 01 Sep 2023 10:07:15 UTC
The branch main has been updated by andrew:

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

commit 565c887a775284bfb1a15eadee2c3f312d288c01
Author:     Zachary Leaf <zachary.leaf@arm.com>
AuthorDate: 2023-08-31 13:11:53 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-09-01 09:56:58 +0000

    armv8_crypto: fix recursive fpu_kern_enter call
    
    Now armv8_crypto is using FPU_KERN_NOCTX, this results in a kernel panic
    in armv8_crypto.c:armv8_crypto_cipher_setup:
    
        panic: recursive fpu_kern_enter while in PCB_FP_NOSAVE state
    
    This is because in armv8_crypto.c:armv8_crypto_cipher_process,
    directly after calling fpu_kern_enter() a call is made to
    armv8_crypto_cipher_setup(), resulting in nested calls to
    fpu_kern_enter() without the required fpu_kern_leave() in between.
    
    Move fpu_kern_enter() in armv8_crypto_cipher_process() after the
    call to armv8_crypto_cipher_setup() to resolve this.
    
    Reviewed by:    markj, andrew
    Fixes: 6485286f536f ("armv8_crypto: Switch to using FPU_KERN_NOCTX")
    Sponsored by: Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D41671
---
 sys/crypto/armv8/armv8_crypto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/crypto/armv8/armv8_crypto.c b/sys/crypto/armv8/armv8_crypto.c
index fd1d845c29b0..fcbc7e77de29 100644
--- a/sys/crypto/armv8/armv8_crypto.c
+++ b/sys/crypto/armv8/armv8_crypto.c
@@ -336,8 +336,6 @@ armv8_crypto_cipher_process(struct armv8_crypto_session *ses,
 		crypto_cursor_copy(&fromc, &toc);
 	}
 
-	fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX);
-
 	if (crp->crp_cipher_key != NULL) {
 		armv8_crypto_cipher_setup(ses, csp, crp->crp_cipher_key,
 		    csp->csp_cipher_klen);
@@ -345,6 +343,8 @@ armv8_crypto_cipher_process(struct armv8_crypto_session *ses,
 
 	crypto_read_iv(crp, iv);
 
+	fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX);
+
 	error = 0;
 	switch (csp->csp_cipher_alg) {
 	case CRYPTO_AES_CBC: