From owner-svn-src-all@freebsd.org Thu Jul 23 21:43:07 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8B94B364F50; Thu, 23 Jul 2020 21:43:07 +0000 (UTC) (envelope-from jhb@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BCQmq350Fz4CGQ; Thu, 23 Jul 2020 21:43:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 343F71FD8D; Thu, 23 Jul 2020 21:43:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06NLh7Rm089485; Thu, 23 Jul 2020 21:43:07 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06NLh7nM089484; Thu, 23 Jul 2020 21:43:07 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <202007232143.06NLh7nM089484@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 23 Jul 2020 21:43:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363461 - head/sys/opencrypto X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/opencrypto X-SVN-Commit-Revision: 363461 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 21:43:07 -0000 Author: jhb Date: Thu Jul 23 21:43:06 2020 New Revision: 363461 URL: https://svnweb.freebsd.org/changeset/base/363461 Log: Consolidate duplicated code into a ktls_ocf_dispatch function. This function manages the loop around crypto_dispatch and coordination with ktls_ocf_callback. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D25757 Modified: head/sys/opencrypto/ktls_ocf.c Modified: head/sys/opencrypto/ktls_ocf.c ============================================================================== --- head/sys/opencrypto/ktls_ocf.c Thu Jul 23 21:40:03 2020 (r363460) +++ head/sys/opencrypto/ktls_ocf.c Thu Jul 23 21:43:06 2020 (r363461) @@ -101,6 +101,40 @@ ktls_ocf_callback(struct cryptop *crp) } static int +ktls_ocf_dispatch(struct ocf_session *os, struct cryptop *crp) +{ + struct ocf_operation oo; + int error; + + oo.os = os; + oo.done = false; + + crp->crp_opaque = &oo; + crp->crp_callback = ktls_ocf_callback; + for (;;) { + error = crypto_dispatch(crp); + if (error) + break; + + mtx_lock(&os->lock); + while (!oo.done) + mtx_sleep(&oo, &os->lock, 0, "ocfktls", 0); + mtx_unlock(&os->lock); + + if (crp->crp_etype != EAGAIN) { + error = crp->crp_etype; + break; + } + + crp->crp_etype = 0; + crp->crp_flags &= ~CRYPTO_F_DONE; + oo.done = false; + counter_u64_add(ocf_retries, 1); + } + return (error); +} + +static int ktls_ocf_tls12_gcm_encrypt(struct ktls_session *tls, const struct tls_record_layer *hdr, uint8_t *trailer, struct iovec *iniov, struct iovec *outiov, int iovcnt, uint64_t seqno, @@ -110,7 +144,6 @@ ktls_ocf_tls12_gcm_encrypt(struct ktls_session *tls, struct tls_aead_data ad; struct cryptop crp; struct ocf_session *os; - struct ocf_operation oo; struct iovec iov[iovcnt + 1]; int i, error; uint16_t tls_comp_len; @@ -118,9 +151,6 @@ ktls_ocf_tls12_gcm_encrypt(struct ktls_session *tls, os = tls->cipher; - oo.os = os; - oo.done = false; - uio.uio_iov = iniov; uio.uio_iovcnt = iovcnt; uio.uio_offset = 0; @@ -180,35 +210,14 @@ ktls_ocf_tls12_gcm_encrypt(struct ktls_session *tls, crypto_use_uio(&crp, &uio); if (!inplace) crypto_use_output_uio(&crp, &out_uio); - crp.crp_opaque = &oo; - crp.crp_callback = ktls_ocf_callback; counter_u64_add(ocf_tls12_gcm_crypts, 1); if (inplace) counter_u64_add(ocf_inplace, 1); else counter_u64_add(ocf_separate_output, 1); - for (;;) { - error = crypto_dispatch(&crp); - if (error) - break; + error = ktls_ocf_dispatch(os, &crp); - mtx_lock(&os->lock); - while (!oo.done) - mtx_sleep(&oo, &os->lock, 0, "ocfktls", 0); - mtx_unlock(&os->lock); - - if (crp.crp_etype != EAGAIN) { - error = crp.crp_etype; - break; - } - - crp.crp_etype = 0; - crp.crp_flags &= ~CRYPTO_F_DONE; - oo.done = false; - counter_u64_add(ocf_retries, 1); - } - crypto_destroyreq(&crp); return (error); } @@ -223,16 +232,12 @@ ktls_ocf_tls13_gcm_encrypt(struct ktls_session *tls, char nonce[12]; struct cryptop crp; struct ocf_session *os; - struct ocf_operation oo; struct iovec iov[iovcnt + 1], out_iov[iovcnt + 1]; int i, error; bool inplace; os = tls->cipher; - oo.os = os; - oo.done = false; - crypto_initreq(&crp, os->sid); /* Setup the nonce. */ @@ -294,8 +299,6 @@ ktls_ocf_tls13_gcm_encrypt(struct ktls_session *tls, crp.crp_op = CRYPTO_OP_ENCRYPT | CRYPTO_OP_COMPUTE_DIGEST; crp.crp_flags = CRYPTO_F_CBIMM | CRYPTO_F_IV_SEPARATE; - crp.crp_opaque = &oo; - crp.crp_callback = ktls_ocf_callback; memcpy(crp.crp_iv, nonce, sizeof(nonce)); @@ -304,26 +307,7 @@ ktls_ocf_tls13_gcm_encrypt(struct ktls_session *tls, counter_u64_add(ocf_inplace, 1); else counter_u64_add(ocf_separate_output, 1); - for (;;) { - error = crypto_dispatch(&crp); - if (error) - break; - - mtx_lock(&os->lock); - while (!oo.done) - mtx_sleep(&oo, &os->lock, 0, "ocfktls", 0); - mtx_unlock(&os->lock); - - if (crp.crp_etype != EAGAIN) { - error = crp.crp_etype; - break; - } - - crp.crp_etype = 0; - crp.crp_flags &= ~CRYPTO_F_DONE; - oo.done = false; - counter_u64_add(ocf_retries, 1); - } + error = ktls_ocf_dispatch(os, &crp); crypto_destroyreq(&crp); return (error);