[dpdk-dev] [PATCH v6 4/8] lib/librte_vhost: add request handler
Maxime Coquelin
maxime.coquelin at redhat.com
Thu Apr 5 10:22:12 CEST 2018
On 04/04/2018 04:25 PM, Fan Zhang wrote:
> This patch adds the implementation that parses virtio crypto request
> to dpdk crypto operation.
>
> Signed-off-by: Fan Zhang <roy.fan.zhang at intel.com>
> ---
> lib/librte_vhost/rte_vhost_crypto.h | 14 +
> lib/librte_vhost/vhost_crypto.c | 622 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 636 insertions(+)
> create mode 100644 lib/librte_vhost/rte_vhost_crypto.h
>
...
> diff --git a/lib/librte_vhost/vhost_crypto.c b/lib/librte_vhost/vhost_crypto.c
> index 34587c27e..5608e94ad 100644
> --- a/lib/librte_vhost/vhost_crypto.c
> +++ b/lib/librte_vhost/vhost_crypto.c
> @@ -8,9 +8,11 @@
...
> +static uint8_t
> +prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
> + struct vhost_crypto_data_req *vc_req,
> + struct virtio_crypto_cipher_data_req *cipher,
> + struct vring_desc *cur_desc)
> +{
> + struct vring_desc *head = vc_req->head;
> + struct vring_desc *desc = cur_desc;
> + struct rte_vhost_memory *mem = vc_req->mem;
> + struct rte_mbuf *m_src = op->sym->m_src, *m_dst = op->sym->m_dst;
> + uint8_t *iv_data = rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET);
> + uint8_t ret = 0;
> +
> + /* prepare */
> + /* iv */
> + if (unlikely(copy_data(iv_data, head, mem, &desc,
> + cipher->para.iv_len) < 0)) {
> + ret = VIRTIO_CRYPTO_BADMSG;
> + goto error_exit;
> + }
> +
> +#ifdef RTE_LIBRTE_VHOST_DEBUG
> + rte_hexdump(stdout, "IV:", iv_data, cipher->para.iv_len);
> +#endif
> +
> + m_src->data_len = cipher->para.src_data_len;
> +
> + switch (vcrypto->option) {
> + case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE:
> + m_src->buf_iova = gpa_to_hpa(vcrypto->dev, desc->addr,
> + cipher->para.src_data_len);
> + m_src->buf_addr = get_data_ptr(head, mem, &desc,
> + cipher->para.src_data_len);
> + if (unlikely(m_src->buf_iova == 0 ||
> + m_src->buf_addr == NULL)) {
> + VC_LOG_ERR("zero_copy may fail due to cross page data");
> + ret = VIRTIO_CRYPTO_ERR;
> + goto error_exit;
> + }
> + break;
> + case RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE:
> + if (unlikely(cipher->para.src_data_len >
> + RTE_MBUF_DEFAULT_BUF_SIZE)) {
> + VC_LOG_ERR("Not enough space to do data copy");
> + ret = VIRTIO_CRYPTO_ERR;
> + goto error_exit;
> + }
> + if (unlikely(copy_data(rte_pktmbuf_mtod(m_src, uint8_t *), head,
> + mem, &desc, cipher->para.src_data_len))
> + < 0) {
> + ret = VIRTIO_CRYPTO_BADMSG;
> + goto error_exit;
> + }
> + break;
> + default:
> + ret = VIRTIO_CRYPTO_BADMSG;
> + goto error_exit;
> + break;
Note: I removed the break to make checkpatch happy.
More information about the dev
mailing list