From patchwork Mon Sep 11 01:10:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 9946453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B1B6604D5 for ; Mon, 11 Sep 2017 01:18:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F35428A83 for ; Mon, 11 Sep 2017 01:18:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83DD328A9B; Mon, 11 Sep 2017 01:18:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2195728A99 for ; Mon, 11 Sep 2017 01:18:24 +0000 (UTC) Received: from localhost ([::1]:54847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDMk-0000R9-TG for patchwork-qemu-devel@patchwork.kernel.org; Sun, 10 Sep 2017 21:18:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDGH-0004T3-OB for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDGC-0004Hp-W7 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:41 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2314) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDGC-0004E4-0a for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:36 -0400 Received: from 172.30.72.58 (EHLO DGGEMS405-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGZ05865; Mon, 11 Sep 2017 09:10:59 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:48 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:34 +0800 Message-ID: <1505092240-10864-3-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1505092240-10864-1-git-send-email-longpeng2@huawei.com> References: <1505092240-10864-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0201.59B5E2A3.0045, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: fb82c99edd6b295f1c3e7cb3140e8d0c X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [RFC 2/8] virtio-crypto: add session creation logic for mux mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: weidong.huang@huawei.com, mst@redhat.com, jasowang@redhat.com, john.griffin@intel.com, Varun.Sethi@freescale.com, denglingli@chinamobile.com, arei.gonglei@hotmail.com, agraf@suse.de, arei.gonglei@huawei.com, "Longpeng\(Mike\)" , vincent.jardin@6wind.com, Ola.Liljedahl@arm.com, luonengjun@huawei.com, xin.zeng@intel.com, liang.j.ma@intel.com, stefanha@redhat.com, Jani.Kokkonen@huawei.com, pasic@linux.vnet.ibm.com, brian.a.keating@intel.com, wangxinxin.wang@huawei.com, cohuck@redhat.com, mike.caraman@nxp.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Adds the session creatation logic for MUX mode. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 79 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 19c82e0..78f75c2 100755 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -33,6 +33,11 @@ static inline int virtio_crypto_vq2q(int queue_index) return queue_index; } +static inline bool virtio_crypto_in_mux_mode(VirtIODevice *vdev) +{ + return virtio_vdev_has_feature(vdev, VIRTIO_CRYPTO_F_MUX_MODE); +} + static int virtio_crypto_cipher_session_helper(VirtIODevice *vdev, CryptoDevBackendSymSessionInfo *info, @@ -210,18 +215,24 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto, static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); - struct virtio_crypto_op_ctrl_req ctrl; VirtQueueElement *elem; + struct virtio_crypto_session_input input; + struct virtio_crypto_ctrl_header *generic_hdr; + union { + struct virtio_crypto_op_ctrl_req ctrl; + struct virtio_crypto_op_ctrl_req_mux mux_ctrl; + } req; + struct iovec *in_iov; struct iovec *out_iov; unsigned in_num; unsigned out_num; uint32_t queue_id; uint32_t opcode; - struct virtio_crypto_session_input input; int64_t session_id; uint8_t status; - size_t s; + size_t s, exp_len; + void *sess; for (;;) { elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); @@ -239,25 +250,49 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) out_iov = elem->out_sg; in_num = elem->in_num; in_iov = elem->in_sg; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &ctrl, sizeof(ctrl)) - != sizeof(ctrl))) { + + if (virtio_crypto_in_mux_mode(vdev)) { + exp_len = sizeof(req.mux_ctrl); + generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.mux_ctrl); + } else { + exp_len = sizeof(req.ctrl); + generic_hdr = (struct virtio_crypto_ctrl_header *)(&req.ctrl); + } + + s = iov_to_buf(out_iov, out_num, 0, generic_hdr, exp_len); + if (unlikely(s != exp_len)) { virtio_error(vdev, "virtio-crypto request ctrl_hdr too short"); virtqueue_detach_element(vq, elem, 0); g_free(elem); break; } - iov_discard_front(&out_iov, &out_num, sizeof(ctrl)); - opcode = ldl_le_p(&ctrl.header.opcode); - queue_id = ldl_le_p(&ctrl.header.queue_id); + iov_discard_front(&out_iov, &out_num, exp_len); + + opcode = ldl_le_p(&generic_hdr->opcode); + queue_id = ldl_le_p(&generic_hdr->queue_id); switch (opcode) { case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION: + if (virtio_crypto_in_mux_mode(vdev)) { + sess = g_new0(struct virtio_crypto_sym_create_session_req, 1); + exp_len = sizeof(struct virtio_crypto_sym_create_session_req); + s = iov_to_buf(out_iov, out_num, 0, sess, exp_len); + if (unlikely(s != exp_len)) { + virtio_error(vdev, "virtio-crypto request additional " + "parameters too short"); + virtqueue_detach_element(vq, elem, 0); + break; + } + iov_discard_front(&out_iov, &out_num, exp_len); + } else { + sess = &req.ctrl.u.sym_create_session; + } + memset(&input, 0, sizeof(input)); - session_id = virtio_crypto_create_sym_session(vcrypto, - &ctrl.u.sym_create_session, - queue_id, opcode, - out_iov, out_num); + + session_id = virtio_crypto_create_sym_session(vcrypto, sess, + queue_id, opcode, out_iov, out_num); /* Serious errors, need to reset virtio crypto device */ if (session_id == -EFAULT) { virtqueue_detach_element(vq, elem, 0); @@ -285,8 +320,23 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) case VIRTIO_CRYPTO_HASH_DESTROY_SESSION: case VIRTIO_CRYPTO_MAC_DESTROY_SESSION: case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION: + if (virtio_crypto_in_mux_mode(vdev)) { + sess = g_new0(struct virtio_crypto_destroy_session_req, 1); + exp_len = sizeof(struct virtio_crypto_destroy_session_req); + s = iov_to_buf(out_iov, out_num, 0, sess, exp_len); + if (unlikely(s != exp_len)) { + virtio_error(vdev, "virtio-crypto request additional " + "parameters too short"); + virtqueue_detach_element(vq, elem, 0); + break; + } + iov_discard_front(&out_iov, &out_num, exp_len); + } else { + sess = &req.ctrl.u.destroy_session; + } + status = virtio_crypto_handle_close_session(vcrypto, - &ctrl.u.destroy_session, queue_id); + sess, queue_id); /* The status only occupy one byte, we can directly use it */ s = iov_from_buf(in_iov, in_num, 0, &status, sizeof(status)); if (unlikely(s != sizeof(status))) { @@ -316,6 +366,9 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) break; } /* end switch case */ + if (virtio_crypto_in_mux_mode(vdev)) { + g_free(sess); + } g_free(elem); } /* end for loop */ }