svn commit: r363262 - in head: share/man/man9 sys/opencrypto
John Baldwin
jhb at FreeBSD.org
Thu Jul 16 21:30:47 UTC 2020
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);
More information about the svn-src-head
mailing list