From nobody Thu Dec 09 20:17:48 2021 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 1BF0518DA4E0; Thu, 9 Dec 2021 20:17:50 +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 4J951m51xSz4qrT; Thu, 9 Dec 2021 20:17:48 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5BBF9549A; Thu, 9 Dec 2021 20:17:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B9KHmXC053855; Thu, 9 Dec 2021 20:17:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B9KHmuH053854; Thu, 9 Dec 2021 20:17:48 GMT (envelope-from git) Date: Thu, 9 Dec 2021 20:17:48 GMT Message-Id: <202112092017.1B9KHmuH053854@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: dc475c9bee02 - main - cryptosoft: Stop single-threading requests within a session. 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/main X-Git-Reftype: branch X-Git-Commit: dc475c9bee02f1a480362450b3680f0e3bfee529 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639081069; 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=JTDUhpO2d6+Np9ovh4cu5VGosJySnXQ7bJLaPXIU+iU=; b=qzXlZMWsIceT87CY0ZHf8NbbsPKS76UIf0+gcgiTZtY3vE5qJYt86IXwwMm+P+ryQZGA8n SK+hzIiNEaQ1dFUrocl5lj7GSiXVtoDPwKrN1P0H1NRWm3f6KtnrwxJgFyu3R+OqaichO/ 2SOSG1rmcJ0YzoBTjIZp+uahRbBjTP0OSdGo+nk1cwMKLj5mfefNQoDEOKCoFWDV2GMyx/ 0aoKavdO98+HklISQ6N6jkuxfCStthJqjxKjw8t8lvk6rm2kozq090NZ5r6z4lCXNqCvQ4 cRVTZQZzTJGtUyDmYqGqjzXz5ALanFss6EjGgAcKSbLxrmb+0ugFGmaH3PrQLw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639081069; a=rsa-sha256; cv=none; b=lljb4dnVxP5c8ebADJlI8jSAYwmpOvuD7iO5tv5zbYpOanHoFg3IbgoJySwFWL8oZTccYT kAUZbk4L7ZH4lehYfAFjgQkE7WORDLbNGknQC2OYaXcpZT5ZbT1etkh2WJcT77N28l62CZ iISAaONrAw2IP/85apVN0G3Pkxq4OVIPRA6q6gnPoKcWQh0RVKEKe9DIIcaPJZ6XgNX296 7DILgX7IP9TQWRTwW42gAnMVw7yeAC8FyPhuyVaD7YFPHn2BwFSJrh+7OgYxOe8fJ7YW61 kQMMw7BlyZpdXfs6r67BMZmjMA6wfF+kcwSeUUFYqKKNtr82qLTd+vyM0KKfRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=dc475c9bee02f1a480362450b3680f0e3bfee529 commit dc475c9bee02f1a480362450b3680f0e3bfee529 Author: John Baldwin AuthorDate: 2021-12-09 19:52:43 +0000 Commit: John Baldwin CommitDate: 2021-12-09 19:52:43 +0000 cryptosoft: Stop single-threading requests within a session. All of the request handlers no longer modify session state, so remove the mutex limiting operations to one per session. In addition, change the pointer to the session state passed to process callbacks to const. Suggested by: mjg Reviewed by: mjg, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33317 --- sys/opencrypto/cryptosoft.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 576efeaec20f..54a44592b1f2 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -44,11 +44,8 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include -#include #include #include @@ -78,8 +75,7 @@ struct swcr_compdec { }; struct swcr_session { - struct mtx swcr_lock; - int (*swcr_process)(struct swcr_session *, struct cryptop *); + int (*swcr_process)(const struct swcr_session *, struct cryptop *); struct swcr_auth swcr_auth; struct swcr_encdec swcr_encdec; @@ -92,7 +88,7 @@ static void swcr_freesession(device_t dev, crypto_session_t cses); /* Used for CRYPTO_NULL_CBC. */ static int -swcr_null(struct swcr_session *ses, struct cryptop *crp) +swcr_null(const struct swcr_session *ses, struct cryptop *crp) { return (0); @@ -102,7 +98,7 @@ swcr_null(struct swcr_session *ses, struct cryptop *crp) * Apply a symmetric encryption/decryption algorithm. */ static int -swcr_encdec(struct swcr_session *ses, struct cryptop *crp) +swcr_encdec(const struct swcr_session *ses, struct cryptop *crp) { unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN]; unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN]; @@ -288,7 +284,7 @@ swcr_encdec(struct swcr_session *ses, struct cryptop *crp) * Compute or verify hash. */ static int -swcr_authcompute(struct swcr_session *ses, struct cryptop *crp) +swcr_authcompute(const struct swcr_session *ses, struct cryptop *crp) { u_char aalg[HASH_MAX_LEN]; const struct crypto_session_params *csp; @@ -368,7 +364,7 @@ CTASSERT(INT_MAX <= (1ll<<39) - 256); /* GCM: plain text < 2^39-256 */ CTASSERT(INT_MAX <= (uint64_t)-1); /* GCM: associated data <= 2^64-1 */ static int -swcr_gmac(struct swcr_session *ses, struct cryptop *crp) +swcr_gmac(const struct swcr_session *ses, struct cryptop *crp) { uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))]; u_char *blk = (u_char *)blkbuf; @@ -450,7 +446,7 @@ swcr_gmac(struct swcr_session *ses, struct cryptop *crp) } static int -swcr_gcm(struct swcr_session *ses, struct cryptop *crp) +swcr_gcm(const struct swcr_session *ses, struct cryptop *crp) { uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))]; u_char *blk = (u_char *)blkbuf; @@ -675,7 +671,7 @@ build_ccm_aad_length(u_int aad_length, uint8_t *blk) } static int -swcr_ccm_cbc_mac(struct swcr_session *ses, struct cryptop *crp) +swcr_ccm_cbc_mac(const struct swcr_session *ses, struct cryptop *crp) { u_char iv[AES_BLOCK_LEN]; u_char blk[CCM_CBC_BLOCK_LEN]; @@ -737,7 +733,7 @@ swcr_ccm_cbc_mac(struct swcr_session *ses, struct cryptop *crp) } static int -swcr_ccm(struct swcr_session *ses, struct cryptop *crp) +swcr_ccm(const struct swcr_session *ses, struct cryptop *crp) { const struct crypto_session_params *csp; uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))]; @@ -910,7 +906,7 @@ out: } static int -swcr_chacha20_poly1305(struct swcr_session *ses, struct cryptop *crp) +swcr_chacha20_poly1305(const struct swcr_session *ses, struct cryptop *crp) { const struct crypto_session_params *csp; uint64_t blkbuf[howmany(CHACHA20_NATIVE_BLOCK_LEN, sizeof(uint64_t))]; @@ -1065,7 +1061,7 @@ out: * Apply a cipher and a digest to perform EtA. */ static int -swcr_eta(struct swcr_session *ses, struct cryptop *crp) +swcr_eta(const struct swcr_session *ses, struct cryptop *crp) { int error; @@ -1085,7 +1081,7 @@ swcr_eta(struct swcr_session *ses, struct cryptop *crp) * Apply a compression/decompression algorithm */ static int -swcr_compdec(struct swcr_session *ses, struct cryptop *crp) +swcr_compdec(const struct swcr_session *ses, struct cryptop *crp) { const struct comp_algo *cxf; uint8_t *data, *out; @@ -1455,7 +1451,6 @@ swcr_newsession(device_t dev, crypto_session_t cses, int error; ses = crypto_get_driver_session(cses); - mtx_init(&ses->swcr_lock, "swcr session lock", NULL, MTX_DEF); error = 0; switch (csp->csp_mode) { @@ -1559,8 +1554,6 @@ swcr_freesession(device_t dev, crypto_session_t cses) ses = crypto_get_driver_session(cses); - mtx_destroy(&ses->swcr_lock); - zfree(ses->swcr_encdec.sw_ctx, M_CRYPTO_DATA); zfree(ses->swcr_auth.sw_ictx, M_CRYPTO_DATA); zfree(ses->swcr_auth.sw_octx, M_CRYPTO_DATA); @@ -1575,11 +1568,9 @@ swcr_process(device_t dev, struct cryptop *crp, int hint) struct swcr_session *ses; ses = crypto_get_driver_session(crp->crp_session); - mtx_lock(&ses->swcr_lock); crp->crp_etype = ses->swcr_process(ses, crp); - mtx_unlock(&ses->swcr_lock); crypto_done(crp); return (0); }