diff options
author | John Baldwin <jhb@FreeBSD.org> | 2020-05-25 22:12:04 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2020-05-25 22:12:04 +0000 |
commit | 9c0e3d3a534c3e3e7f6bfce0a150ed2a0841685a (patch) | |
tree | 30ce1a860bcb9456d7c684bc82df9b370545b172 /sys/netipsec | |
parent | 852c303b61d12d13b56ed7affe31df193aadf9ae (diff) |
Add support for optional separate output buffers to in-kernel crypto.
Some crypto consumers such as GELI and KTLS for file-backed sendfile
need to store their output in a separate buffer from the input.
Currently these consumers copy the contents of the input buffer into
the output buffer and queue an in-place crypto operation on the output
buffer. Using a separate output buffer avoids this copy.
- Create a new 'struct crypto_buffer' describing a crypto buffer
containing a type and type-specific fields. crp_ilen is gone,
instead buffers that use a flat kernel buffer have a cb_buf_len
field for their length. The length of other buffer types is
inferred from the backing store (e.g. uio_resid for a uio).
Requests now have two such structures: crp_buf for the input buffer,
and crp_obuf for the output buffer.
- Consumers now use helper functions (crypto_use_*,
e.g. crypto_use_mbuf()) to configure the input buffer. If an output
buffer is not configured, the request still modifies the input
buffer in-place. A consumer uses a second set of helper functions
(crypto_use_output_*) to configure an output buffer.
- Consumers must request support for separate output buffers when
creating a crypto session via the CSP_F_SEPARATE_OUTPUT flag and are
only permitted to queue a request with a separate output buffer on
sessions with this flag set. Existing drivers already reject
sessions with unknown flags, so this permits drivers to be modified
to support this extension without requiring all drivers to change.
- Several data-related functions now have matching versions that
operate on an explicit buffer (e.g. crypto_apply_buf,
crypto_contiguous_subsegment_buf, bus_dma_load_crp_buf).
- Most of the existing data-related functions operate on the input
buffer. However crypto_copyback always writes to the output buffer
if a request uses a separate output buffer.
- For the regions in input/output buffers, the following conventions
are followed:
- AAD and IV are always present in input only and their
fields are offsets into the input buffer.
- payload is always present in both buffers. If a request uses a
separate output buffer, it must set a new crp_payload_start_output
field to the offset of the payload in the output buffer.
- digest is in the input buffer for verify operations, and in the
output buffer for compute operations. crp_digest_start is relative
to the appropriate buffer.
- Add a crypto buffer cursor abstraction. This is a more general form
of some bits in the cryptosoft driver that tried to always use uio's.
However, compared to the original code, this avoids rewalking the uio
iovec array for requests with multiple vectors. It also avoids
allocate an iovec array for mbufs and populating it by instead walking
the mbuf chain directly.
- Update the cryptosoft(4) driver to support separate output buffers
making use of the cursor abstraction.
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D24545
Notes
Notes:
svn path=/head/; revision=361481
Diffstat (limited to 'sys/netipsec')
-rw-r--r-- | sys/netipsec/xform_ah.c | 12 | ||||
-rw-r--r-- | sys/netipsec/xform_esp.c | 12 | ||||
-rw-r--r-- | sys/netipsec/xform_ipcomp.c | 12 |
3 files changed, 12 insertions, 24 deletions
diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c index 456ba7e85865..8c6032a070c1 100644 --- a/sys/netipsec/xform_ah.c +++ b/sys/netipsec/xform_ah.c @@ -654,13 +654,11 @@ ah_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) } /* Crypto operation descriptor. */ - crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */ crp->crp_op = CRYPTO_OP_COMPUTE_DIGEST; crp->crp_flags = CRYPTO_F_CBIFSYNC; if (V_async_crypto) crp->crp_flags |= CRYPTO_F_ASYNC | CRYPTO_F_ASYNC_KEEPORDER; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = ah_input_cb; crp->crp_opaque = xd; @@ -695,7 +693,7 @@ ah_input_cb(struct cryptop *crp) int authsize, rplen, ahsize, error, skip, protoff; uint8_t nxt; - m = crp->crp_mbuf; + m = crp->crp_buf.cb_mbuf; xd = crp->crp_opaque; CURVNET_SET(xd->vnet); sav = xd->sav; @@ -1031,13 +1029,11 @@ ah_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, } /* Crypto operation descriptor. */ - crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */ crp->crp_op = CRYPTO_OP_COMPUTE_DIGEST; crp->crp_flags = CRYPTO_F_CBIFSYNC; if (V_async_crypto) crp->crp_flags |= CRYPTO_F_ASYNC | CRYPTO_F_ASYNC_KEEPORDER; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = ah_output_cb; crp->crp_opaque = xd; @@ -1073,7 +1069,7 @@ ah_output_cb(struct cryptop *crp) u_int idx; int skip, error; - m = (struct mbuf *) crp->crp_buf; + m = crp->crp_buf.cb_mbuf; xd = (struct xform_data *) crp->crp_opaque; CURVNET_SET(xd->vnet); sp = xd->sp; diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c index ba1cb7044390..214df48157c9 100644 --- a/sys/netipsec/xform_esp.c +++ b/sys/netipsec/xform_esp.c @@ -366,12 +366,10 @@ esp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) } /* Crypto operation descriptor */ - crp->crp_ilen = m->m_pkthdr.len; /* Total input length */ crp->crp_flags = CRYPTO_F_CBIFSYNC; if (V_async_crypto) crp->crp_flags |= CRYPTO_F_ASYNC | CRYPTO_F_ASYNC_KEEPORDER; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = esp_input_cb; crp->crp_opaque = xd; @@ -446,7 +444,7 @@ esp_input_cb(struct cryptop *crp) crypto_session_t cryptoid; int hlen, skip, protoff, error, alen; - m = crp->crp_mbuf; + m = crp->crp_buf.cb_mbuf; xd = crp->crp_opaque; CURVNET_SET(xd->vnet); sav = xd->sav; @@ -840,12 +838,10 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, xd->vnet = curvnet; /* Crypto operation descriptor. */ - crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */ crp->crp_flags |= CRYPTO_F_CBIFSYNC; if (V_async_crypto) crp->crp_flags |= CRYPTO_F_ASYNC | CRYPTO_F_ASYNC_KEEPORDER; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = esp_output_cb; crp->crp_opaque = xd; @@ -884,7 +880,7 @@ esp_output_cb(struct cryptop *crp) xd = (struct xform_data *) crp->crp_opaque; CURVNET_SET(xd->vnet); - m = (struct mbuf *) crp->crp_buf; + m = crp->crp_buf.cb_mbuf; sp = xd->sp; sav = xd->sav; idx = xd->idx; diff --git a/sys/netipsec/xform_ipcomp.c b/sys/netipsec/xform_ipcomp.c index 0529b2dda7c5..b2d98b82bf87 100644 --- a/sys/netipsec/xform_ipcomp.c +++ b/sys/netipsec/xform_ipcomp.c @@ -249,10 +249,8 @@ ipcomp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) crp->crp_payload_length = m->m_pkthdr.len - (skip + hlen); /* Crypto operation descriptor */ - crp->crp_ilen = m->m_pkthdr.len - (skip + hlen); crp->crp_flags = CRYPTO_F_CBIFSYNC; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = ipcomp_input_cb; crp->crp_opaque = xd; @@ -291,7 +289,7 @@ ipcomp_input_cb(struct cryptop *crp) int skip, protoff; uint8_t nproto; - m = crp->crp_mbuf; + m = crp->crp_buf.cb_mbuf; xd = crp->crp_opaque; CURVNET_SET(xd->vnet); sav = xd->sav; @@ -506,10 +504,8 @@ ipcomp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, xd->cryptoid = cryptoid; /* Crypto operation descriptor */ - crp->crp_ilen = m->m_pkthdr.len; /* Total input length */ crp->crp_flags = CRYPTO_F_CBIFSYNC; - crp->crp_mbuf = m; - crp->crp_buf_type = CRYPTO_BUF_MBUF; + crypto_use_mbuf(crp, m); crp->crp_callback = ipcomp_output_cb; crp->crp_opaque = xd; @@ -537,7 +533,7 @@ ipcomp_output_cb(struct cryptop *crp) u_int idx; int error, skip, protoff; - m = crp->crp_mbuf; + m = crp->crp_buf.cb_mbuf; xd = crp->crp_opaque; CURVNET_SET(xd->vnet); idx = xd->idx; |