From nobody Fri Dec 29 23:08:54 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T21K269Vsz55TDr; Fri, 29 Dec 2023 23:08:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T21K24Ghpz4GZ6; Fri, 29 Dec 2023 23:08:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703891334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OLiRfKKWpV+A0oAm4jES1BmA0Sz4KP0nvPL7MHIuTi8=; b=EdAl5tIr0vFPfQP9jiLQQohTd4+UakEBtNd0JZyd1Xi/mstt6GOCD5HxF6iOuidrgi97FV AN9gVvYPCnKluKGGzT25v/vPyGy9Sf29oTa9hf0qRwfebam7i7ZH5iFYL6X+6zpW/xrIOS ehHuu+DA3JavgTMfS4HYUdvSM/5Xgm4NYwcj6JKOKWs1onENu18XApM1ywmkU6qLTnVaP2 KezKj6To5FZYi/9JVV43bCtZ/00B8m/73YEdUGH0Zt9Jn2cLyNpFHEIO0HESoLFFM1mVF6 wSOhXSbsv3a0Kr9xWcH4GaF1m3ACsKQGYbR5FgxaoxBMF9ZbiINh/W48+qO8vg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703891334; a=rsa-sha256; cv=none; b=Bok0sqaMq2jQrP+CIOBsTwBxgtj1XZ8ilHZ5sMaprQpDjE4Fl4ZEwkYzlRskX2lFT8b0Ww XWzGpY8yAwgGb6O2/XxAxxgjvX6RwqO0eNgZ4SB2UGpnSyoywfBQpRSiDFZJ3SbkbjyGs5 +9vSpQa6Fyc5tg/N2F+mZluv6ey0Wj4gRz6cNWOWWYD7jedkuBVtcW0bgCPIm0qtezsqtt rw3xeORTM1gHuWaEe7kUvbKajVjKDj5qofA0l9oZziQJbqKyyKhPQYfIHoICl5bpYVFJFd ZnckBp1P0O6sxZ4v2Lb6gOGM6hzE5VUe3Nhj3x6nAqbD1SENWQCFhtA/+KKq1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703891334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OLiRfKKWpV+A0oAm4jES1BmA0Sz4KP0nvPL7MHIuTi8=; b=ep+SZySr4WQ81sJVeqXFZ5sizalYkRsLDAod7BZIjDxhxa6XZqeqNd2K0/+MhxyvuyOITp 7Jm6kbnXTH72FkV/UhkzDXljhSmEptal8Sqd+DVgT/nhYGtMcOoJJD7di78VNie6JA4nEe wqFCNZu8AmOdolCUQnRFvpO4I7n9LJUmn0HHEUbZlJSrWMGabEAZqhyuaFBDhRewnO+y2n 3jRT8Po7Oe7lImqa2qPf6vqcZpNcFZbmrPuhZdMzJ9ylwSmZQmBmnuptDMWEdok5JhG+Gq eSKC+KBLk/oKoJaFXfDzqfg/9HD39femTT5no5/ENm+WWii1JZlSAx2D6ZiEgw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T21K2387lzB9l; Fri, 29 Dec 2023 23:08:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BTN8scs075494; Fri, 29 Dec 2023 23:08:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BTN8sUH075491; Fri, 29 Dec 2023 23:08:54 GMT (envelope-from git) Date: Fri, 29 Dec 2023 23:08:54 GMT Message-Id: <202312292308.3BTN8sUH075491@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: cfc94a37d8d9 - stable/14 - aesni: Switch to using FPU_KERN_NOCTX. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: cfc94a37d8d9e7695f0d9bed14b88d4383d96798 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=cfc94a37d8d9e7695f0d9bed14b88d4383d96798 commit cfc94a37d8d9e7695f0d9bed14b88d4383d96798 Author: John Baldwin AuthorDate: 2023-08-28 23:22:15 +0000 Commit: John Baldwin CommitDate: 2023-12-29 21:49:42 +0000 aesni: Switch to using FPU_KERN_NOCTX. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D41577 (cherry picked from commit 937b4473be2129a700689fe4c8ea0311ccfb17b8) --- sys/crypto/aesni/aesni.c | 88 +++++------------------------------------------- 1 file changed, 9 insertions(+), 79 deletions(-) diff --git a/sys/crypto/aesni/aesni.c b/sys/crypto/aesni/aesni.c index 60e4a6e0f2fc..6d83743dece9 100644 --- a/sys/crypto/aesni/aesni.c +++ b/sys/crypto/aesni/aesni.c @@ -40,11 +40,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -63,28 +61,12 @@ #include #include -static struct mtx_padalign *ctx_mtx; -static struct fpu_kern_ctx **ctx_fpu; - struct aesni_softc { int32_t cid; bool has_aes; bool has_sha; }; -#define ACQUIRE_CTX(i, ctx) \ - do { \ - (i) = PCPU_GET(cpuid); \ - mtx_lock(&ctx_mtx[(i)]); \ - (ctx) = ctx_fpu[(i)]; \ - } while (0) -#define RELEASE_CTX(i, ctx) \ - do { \ - mtx_unlock(&ctx_mtx[(i)]); \ - (i) = -1; \ - (ctx) = NULL; \ - } while (0) - static int aesni_cipher_setup(struct aesni_session *ses, const struct crypto_session_params *csp); static int aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp); @@ -136,30 +118,10 @@ aesni_probe(device_t dev) return (0); } -static void -aesni_cleanctx(void) -{ - int i; - - /* XXX - no way to return driverid */ - CPU_FOREACH(i) { - if (ctx_fpu[i] != NULL) { - mtx_destroy(&ctx_mtx[i]); - fpu_kern_free_ctx(ctx_fpu[i]); - } - ctx_fpu[i] = NULL; - } - free(ctx_mtx, M_AESNI); - ctx_mtx = NULL; - free(ctx_fpu, M_AESNI); - ctx_fpu = NULL; -} - static int aesni_attach(device_t dev) { struct aesni_softc *sc; - int i; sc = device_get_softc(dev); @@ -171,21 +133,6 @@ aesni_attach(device_t dev) return (ENOMEM); } - ctx_mtx = malloc(sizeof *ctx_mtx * (mp_maxid + 1), M_AESNI, - M_WAITOK|M_ZERO); - ctx_fpu = malloc(sizeof *ctx_fpu * (mp_maxid + 1), M_AESNI, - M_WAITOK|M_ZERO); - - CPU_FOREACH(i) { -#ifdef __amd64__ - ctx_fpu[i] = fpu_kern_alloc_ctx_domain( - pcpu_find(i)->pc_domain, FPU_KERN_NORMAL); -#else - ctx_fpu[i] = fpu_kern_alloc_ctx(FPU_KERN_NORMAL); -#endif - mtx_init(&ctx_mtx[i], "anifpumtx", NULL, MTX_DEF|MTX_NEW); - } - detect_cpu_features(&sc->has_aes, &sc->has_sha); return (0); } @@ -199,8 +146,6 @@ aesni_detach(device_t dev) crypto_unregister_all(sc->cid); - aesni_cleanctx(); - return (0); } @@ -551,9 +496,9 @@ static int aesni_cipher_setup(struct aesni_session *ses, const struct crypto_session_params *csp) { - struct fpu_kern_ctx *ctx; uint8_t *schedbase; - int kt, ctxidx, error; + int error; + bool kt; schedbase = (uint8_t *)roundup2((uintptr_t)ses->schedules, AES_SCHED_ALIGN); @@ -607,11 +552,10 @@ aesni_cipher_setup(struct aesni_session *ses, ses->mlen = csp->csp_auth_mlen; } - kt = is_fpu_kern_thread(0) || (csp->csp_cipher_alg == 0); + kt = (csp->csp_cipher_alg == 0); if (!kt) { - ACQUIRE_CTX(ctxidx, ctx); - fpu_kern_enter(curthread, ctx, - FPU_KERN_NORMAL | FPU_KERN_KTHR); + fpu_kern_enter(curthread, NULL, + FPU_KERN_NORMAL | FPU_KERN_NOCTX); } error = 0; @@ -620,8 +564,7 @@ aesni_cipher_setup(struct aesni_session *ses, csp->csp_cipher_klen); if (!kt) { - fpu_kern_leave(curthread, ctx); - RELEASE_CTX(ctxidx, ctx); + fpu_kern_leave(curthread, NULL); } return (error); } @@ -630,9 +573,7 @@ static int aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp) { const struct crypto_session_params *csp; - struct fpu_kern_ctx *ctx; - int error, ctxidx; - bool kt; + int error; csp = crypto_get_params(crp->crp_session); switch (csp->csp_cipher_alg) { @@ -653,15 +594,7 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp) break; } - ctx = NULL; - ctxidx = 0; - error = 0; - kt = is_fpu_kern_thread(0); - if (!kt) { - ACQUIRE_CTX(ctxidx, ctx); - fpu_kern_enter(curthread, ctx, - FPU_KERN_NORMAL | FPU_KERN_KTHR); - } + fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX); /* Do work */ if (csp->csp_mode == CSP_MODE_ETA) { @@ -679,10 +612,7 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp) else error = aesni_cipher_crypt(ses, crp, csp); - if (!kt) { - fpu_kern_leave(curthread, ctx); - RELEASE_CTX(ctxidx, ctx); - } + fpu_kern_leave(curthread, NULL); return (error); }