From owner-svn-src-head@freebsd.org Thu Jul 16 21:30:47 2020 Return-Path: Delivered-To: svn-src-head@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 6E16736E741; Thu, 16 Jul 2020 21:30:47 +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 4B76qq2M45z47Sw; Thu, 16 Jul 2020 21:30:47 +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 30E64ED2A; Thu, 16 Jul 2020 21:30:47 +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 06GLUkOR017251; Thu, 16 Jul 2020 21:30:46 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06GLUkmA017248; Thu, 16 Jul 2020 21:30:46 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <202007162130.06GLUkmA017248@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 16 Jul 2020 21:30:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363262 - in head: share/man/man9 sys/opencrypto X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in head: share/man/man9 sys/opencrypto X-SVN-Commit-Revision: 363262 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2020 21:30:47 -0000 Author: jhb Date: Thu Jul 16 21:30:46 2020 New Revision: 363262 URL: https://svnweb.freebsd.org/changeset/base/363262 Log: Add crypto_initreq() and crypto_destroyreq(). These routines are similar to crypto_getreq() and crypto_freereq() but operate on caller-supplied storage instead of allocating crypto requests from a UMA zone. Reviewed by: markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D25691 Modified: head/share/man/man9/Makefile head/share/man/man9/crypto_request.9 head/sys/opencrypto/crypto.c head/sys/opencrypto/cryptodev.h Modified: head/share/man/man9/Makefile ============================================================================== --- head/share/man/man9/Makefile Thu Jul 16 20:44:04 2020 (r363261) +++ head/share/man/man9/Makefile Thu Jul 16 21:30:46 2020 (r363262) @@ -927,9 +927,11 @@ MLINKS+=crypto_driver.9 crypto_copyback.9 \ crypto_driver.9 CRYPTODEV_PROCESS.9 \ crypto_driver.9 hmac_init_ipad.9 \ crypto_driver.9 hmac_init_opad.9 -MLINKS+=crypto_request.9 crypto_dispatch.9 \ +MLINKS+=crypto_request.9 crypto_destroyreq.9 \ + crypto_request.9 crypto_dispatch.9 \ crypto_request.9 crypto_freereq.9 \ crypto_request.9 crypto_getreq.9 \ + crypto_request.9 crypto_initreq.9 \ crypto_request.9 crypto_use_buf.9 \ crypto_request.9 crypto_use_mbuf.9 \ crypto_request.9 crypto_use_output_buf.9 \ Modified: head/share/man/man9/crypto_request.9 ============================================================================== --- head/share/man/man9/crypto_request.9 Thu Jul 16 20:44:04 2020 (r363261) +++ head/share/man/man9/crypto_request.9 Thu Jul 16 21:30:46 2020 (r363262) @@ -30,7 +30,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 22, 2020 +.Dd July 16, 2020 .Dt CRYPTO_REQUEST 9 .Os .Sh NAME @@ -41,10 +41,14 @@ .Ft int .Fn crypto_dispatch "struct cryptop *crp" .Ft void +.Fn crypto_destroyreq "struct cryptop *crp" +.Ft void .Fn crypto_freereq "struct cryptop *crp" .Ft "struct cryptop *" .Fn crypto_getreq "crypto_session_t cses" "int how" .Ft void +.Fn crypto_initreq "crypto_session_t cses" "int how" +.Ft void .Fn crypto_use_buf "struct cryptop *crp" "void *buf" "int len" .Ft void .Fn crypto_use_mbuf "struct cryptop *crp" "struct mbuf *m" @@ -62,10 +66,27 @@ an instance of .Vt struct cryptop and is associated with an active session. .Pp -New requests are allocated by -.Fn crypto_getreq . +Requests can either be allocated dynamically or use caller-supplied +storage. +Dynamically allocated requests should be allocated by +.Fn crypto_getreq +and freed by +.Fn crypto_freereq +once the request has completed. +Requests using caller-supplied storage should be initialized by +.Fn crypto_initreq +at the start of each operation and destroyed by +.Fn crypto_destroyreq +once the request has completed. +.Pp +For both +.Fn crypto_getreq +and +.Fn crypto_initreq , .Fa cses is a reference to an active session. +For +.Fn crypto_getreq , .Fa how is passed to .Xr malloc 9 @@ -73,7 +94,9 @@ and should be set to either .Dv M_NOWAIT or .Dv M_WAITOK . -The caller should then set fields in the returned structure to describe +.Pp +Once a request has been initialized, +the caller should set fields in the structure to describe request-specific parameters. Unused fields should be left as-is. .Pp @@ -92,7 +115,9 @@ Note that a request's callback function may be invoked returns. .Pp Once a request has signaled completion by invoking its callback function, -it should be feed via +it should be freed via +.Fn crypto_destroyreq +or .Fn crypto_freereq . .Pp Cryptographic operations include several fields to describe the request. Modified: head/sys/opencrypto/crypto.c ============================================================================== --- head/sys/opencrypto/crypto.c Thu Jul 16 20:44:04 2020 (r363261) +++ head/sys/opencrypto/crypto.c Thu Jul 16 21:30:46 2020 (r363262) @@ -1734,12 +1734,8 @@ crypto_invoke(struct cryptocap *cap, struct cryptop *c } void -crypto_freereq(struct cryptop *crp) +crypto_destroyreq(struct cryptop *crp) { - - if (crp == NULL) - return; - #ifdef DIAGNOSTIC { struct cryptop *crp2; @@ -1764,10 +1760,31 @@ crypto_freereq(struct cryptop *crp) } } #endif +} +void +crypto_freereq(struct cryptop *crp) +{ + if (crp == NULL) + return; + + crypto_destroyreq(crp); uma_zfree(cryptop_zone, crp); } +static void +_crypto_initreq(struct cryptop *crp, crypto_session_t cses) +{ + crp->crp_session = cses; +} + +void +crypto_initreq(struct cryptop *crp, crypto_session_t cses) +{ + memset(crp, 0, sizeof(*crp)); + _crypto_initreq(crp, cses); +} + struct cryptop * crypto_getreq(crypto_session_t cses, int how) { @@ -1775,7 +1792,8 @@ crypto_getreq(crypto_session_t cses, int how) MPASS(how == M_WAITOK || how == M_NOWAIT); crp = uma_zalloc(cryptop_zone, how | M_ZERO); - crp->crp_session = cses; + if (crp != NULL) + _crypto_initreq(crp, cses); return (crp); } Modified: head/sys/opencrypto/cryptodev.h ============================================================================== --- head/sys/opencrypto/cryptodev.h Thu Jul 16 20:44:04 2020 (r363261) +++ head/sys/opencrypto/cryptodev.h Thu Jul 16 21:30:46 2020 (r363262) @@ -622,6 +622,8 @@ extern void crypto_done(struct cryptop *crp); extern void crypto_kdone(struct cryptkop *); extern int crypto_getfeat(int *); +extern void crypto_destroyreq(struct cryptop *crp); +extern void crypto_initreq(struct cryptop *crp, crypto_session_t cses); extern void crypto_freereq(struct cryptop *crp); extern struct cryptop *crypto_getreq(crypto_session_t cses, int how);