From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092866327229.50983452579783; Sun, 10 Sep 2017 18:21:06 -0700 (PDT) Received: from localhost ([::1]:54866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDPN-0003LQ-Ld for importer@patchew.org; Sun, 10 Sep 2017 21:21:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDJE-00072H-IK for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:14:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDJ9-0005d7-Qz for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:14:44 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2259) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDJ9-0005b6-5f for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:14:39 -0400 Received: from 172.30.72.60 (EHLO DGGEMS402-HUB.china.huawei.com) ([172.30.72.60]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHB05987; Mon, 11 Sep 2017 09:10:54 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:47 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:33 +0800 Message-ID: <1505092240-10864-2-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.0A0B0204.59B5E2A0.00BC, 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: 7229957b809da7ae455ecd080660dbe8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC 1/8] virtio-crypto: add new definations for multiplexing 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds the defination of the control/operation header for multiplexing mode. Signed-off-by: Longpeng(Mike) --- include/standard-headers/linux/virtio_crypto.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/stand= ard-headers/linux/virtio_crypto.h index 5ff0b4e..987fb1e 100755 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -38,6 +38,13 @@ #define VIRTIO_CRYPTO_SERVICE_MAC 2 #define VIRTIO_CRYPTO_SERVICE_AEAD 3 =20 +/* The features for virtio crypto device */ +#define VIRTIO_CRYPTO_F_MUX_MODE 0 +#define VIRTIO_CRYPTO_F_CIPHER_STATELESS_MODE 1 +#define VIRTIO_CRYPTO_F_HASH_STATELESS_MODE 2 +#define VIRTIO_CRYPTO_F_MAC_STATELESS_MODE 3 +#define VIRTIO_CRYPTO_F_AEAD_STATELESS_MODE 4 + #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op)) =20 struct virtio_crypto_ctrl_header { @@ -234,7 +241,7 @@ struct virtio_crypto_destroy_session_req { uint8_t padding[48]; }; =20 -/* The request of the control virtqueue's packet */ +/* The request of the control virtqueue's packet for non-MUX mode */ struct virtio_crypto_op_ctrl_req { struct virtio_crypto_ctrl_header header; =20 @@ -253,6 +260,11 @@ struct virtio_crypto_op_ctrl_req { } u; }; =20 +/* The request of the control virtqueue's packet for MUX mode */ +struct virtio_crypto_op_ctrl_req_mux { + struct virtio_crypto_ctrl_header header; +}; + struct virtio_crypto_op_header { #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) @@ -390,7 +402,7 @@ struct virtio_crypto_aead_data_req { uint8_t padding[32]; }; =20 -/* The request of the data virtqueue's packet */ +/* The request of the data virtqueue's packet for non-MUX mode */ struct virtio_crypto_op_data_req { struct virtio_crypto_op_header header; =20 @@ -403,6 +415,11 @@ struct virtio_crypto_op_data_req { } u; }; =20 +/* The request of the data virtqueue's packet for MUX mode */ +struct virtio_crypto_op_data_req_mux { + struct virtio_crypto_op_header header; +}; + #define VIRTIO_CRYPTO_OK 0 #define VIRTIO_CRYPTO_ERR 1 #define VIRTIO_CRYPTO_BADMSG 2 --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092730937837.2403535580479; Sun, 10 Sep 2017 18:18:50 -0700 (PDT) Received: from localhost ([::1]:54853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDNB-0001hl-J2 for importer@patchew.org; Sun, 10 Sep 2017 21:18:49 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; } =20 +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 *vcry= pto, static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOCrypto *vcrypto =3D 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; =20 for (;;) { elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); @@ -239,25 +250,49 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *v= dev, VirtQueue *vq) out_iov =3D elem->out_sg; in_num =3D elem->in_num; in_iov =3D elem->in_sg; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &ctrl, sizeof(ctrl)) - !=3D sizeof(ctrl))) { + + if (virtio_crypto_in_mux_mode(vdev)) { + exp_len =3D sizeof(req.mux_ctrl); + generic_hdr =3D (struct virtio_crypto_ctrl_header *)(&req.mux_= ctrl); + } else { + exp_len =3D sizeof(req.ctrl); + generic_hdr =3D (struct virtio_crypto_ctrl_header *)(&req.ctrl= ); + } + + s =3D iov_to_buf(out_iov, out_num, 0, generic_hdr, exp_len); + if (unlikely(s !=3D 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)); =20 - opcode =3D ldl_le_p(&ctrl.header.opcode); - queue_id =3D ldl_le_p(&ctrl.header.queue_id); + iov_discard_front(&out_iov, &out_num, exp_len); + + opcode =3D ldl_le_p(&generic_hdr->opcode); + queue_id =3D ldl_le_p(&generic_hdr->queue_id); =20 switch (opcode) { case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION: + if (virtio_crypto_in_mux_mode(vdev)) { + sess =3D g_new0(struct virtio_crypto_sym_create_session_re= q, 1); + exp_len =3D sizeof(struct virtio_crypto_sym_create_session= _req); + s =3D iov_to_buf(out_iov, out_num, 0, sess, exp_len); + if (unlikely(s !=3D 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 =3D &req.ctrl.u.sym_create_session; + } + memset(&input, 0, sizeof(input)); - session_id =3D virtio_crypto_create_sym_session(vcrypto, - &ctrl.u.sym_create_session, - queue_id, opcode, - out_iov, out_num); + + session_id =3D 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 =3D=3D -EFAULT) { virtqueue_detach_element(vq, elem, 0); @@ -285,8 +320,23 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vd= ev, 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 =3D g_new0(struct virtio_crypto_destroy_session_req, = 1); + exp_len =3D sizeof(struct virtio_crypto_destroy_session_re= q); + s =3D iov_to_buf(out_iov, out_num, 0, sess, exp_len); + if (unlikely(s !=3D 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 =3D &req.ctrl.u.destroy_session; + } + status =3D 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 =3D iov_from_buf(in_iov, in_num, 0, &status, sizeof(status)); if (unlikely(s !=3D sizeof(status))) { @@ -316,6 +366,9 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vde= v, VirtQueue *vq) break; } /* end switch case */ =20 + if (virtio_crypto_in_mux_mode(vdev)) { + g_free(sess); + } g_free(elem); } /* end for loop */ } --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092416635579.8912363593412; Sun, 10 Sep 2017 18:13:36 -0700 (PDT) Received: from localhost ([::1]:54830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDI7-0005hO-Gv for importer@patchew.org; Sun, 10 Sep 2017 21:13:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG5-0004HC-KU for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG1-00046D-8N for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2310) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG0-00041Q-Jc for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:25 -0400 Received: from 172.30.72.59 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.59]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGZ05867; Mon, 11 Sep 2017 09:10:59 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:49 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:35 +0800 Message-ID: <1505092240-10864-4-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.59B5E2A4.000D, 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: 0d88df642c27b42db36e151cb9d2db9c 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 3/8] virtio-crypto: add dataq operation 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds dataq operation support for MUX mode. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 47 +++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 78f75c2..6076fb0 100755 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -629,7 +629,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) VirtIODevice *vdev =3D VIRTIO_DEVICE(vcrypto); VirtQueueElement *elem =3D &request->elem; int queue_index =3D virtio_crypto_vq2q(virtio_get_queue_index(request-= >vq)); - struct virtio_crypto_op_data_req req; + struct virtio_crypto_op_header *generic_hdr; int ret; struct iovec *in_iov; struct iovec *out_iov; @@ -640,6 +640,12 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) uint64_t session_id; CryptoDevBackendSymOpInfo *sym_op_info =3D NULL; Error *local_err =3D NULL; + size_t s, exp_len; + void *body; + union { + struct virtio_crypto_op_data_req req; + struct virtio_crypto_op_data_req_mux mux_req; + } op; =20 if (elem->out_num < 1 || elem->in_num < 1) { virtio_error(vdev, "virtio-crypto dataq missing headers"); @@ -650,12 +656,22 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) out_iov =3D elem->out_sg; in_num =3D elem->in_num; in_iov =3D elem->in_sg; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)) - !=3D sizeof(req))) { + + if (virtio_crypto_in_mux_mode(vdev)) { + exp_len =3D sizeof(op.mux_req); + generic_hdr =3D (struct virtio_crypto_op_header *)(&op.mux_req); + } else { + exp_len =3D sizeof(op.req); + generic_hdr =3D (struct virtio_crypto_op_header *)(&op.req); + } + + s =3D iov_to_buf(out_iov, out_num, 0, generic_hdr, exp_len); + if (unlikely(s !=3D exp_len)) { virtio_error(vdev, "virtio-crypto request outhdr too short"); return -1; } - iov_discard_front(&out_iov, &out_num, sizeof(req)); + + iov_discard_front(&out_iov, &out_num, exp_len); =20 if (in_iov[in_num - 1].iov_len < sizeof(struct virtio_crypto_inhdr)) { @@ -676,16 +692,27 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) request->in_num =3D in_num; request->in_iov =3D in_iov; =20 - opcode =3D ldl_le_p(&req.header.opcode); - session_id =3D ldq_le_p(&req.header.session_id); + opcode =3D ldl_le_p(&generic_hdr->opcode); + session_id =3D ldq_le_p(&generic_hdr->session_id); =20 switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: - ret =3D virtio_crypto_handle_sym_req(vcrypto, - &req.u.sym_req, - &sym_op_info, - out_iov, out_num); + if (virtio_crypto_in_mux_mode(vdev)) { + body =3D g_new0(struct virtio_crypto_sym_data_req, 1); + exp_len =3D sizeof(struct virtio_crypto_sym_data_req); + s =3D iov_to_buf(out_iov, out_num, 0, body, exp_len); + if (unlikely(s !=3D exp_len)) { + g_free(body); + return -1; + } + iov_discard_front(&out_iov, &out_num, exp_len); + } else { + body =3D &op.req.u.sym_req; + } + + ret =3D virtio_crypto_handle_sym_req(vcrypto, body, + &sym_op_info, out_iov, out_num); /* Serious errors, need to reset virtio crypto device */ if (ret =3D=3D -EFAULT) { return -1; --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092416637997.7546691707499; Sun, 10 Sep 2017 18:13:36 -0700 (PDT) Received: from localhost ([::1]:54829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDI6-0005gb-E7 for importer@patchew.org; Sun, 10 Sep 2017 21:13:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG5-0004HF-L6 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG0-00045W-Lf for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2311) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG0-00042A-05 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:24 -0400 Received: from 172.30.72.58 (EHLO DGGEMS407-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGZ05861; Mon, 11 Sep 2017 09:10:58 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:50 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:36 +0800 Message-ID: <1505092240-10864-5-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.0A0B0208.59B5E2A2.00B3, 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: 9f6fc4f4f0818c6979e99629858e8117 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 4/8] cryptodev: add stateless mode cipher support 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds stateless mode cipher support. Signed-off-by: Longpeng(Mike) --- backends/cryptodev.c | 21 +++++++++++++++++++++ include/hw/virtio/virtio-crypto.h | 1 + include/sysemu/cryptodev.h | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 1764c17..a76a312 100755 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -120,6 +120,21 @@ static int cryptodev_backend_sym_operation( return -VIRTIO_CRYPTO_ERR; } =20 +static int cryptodev_backend_sym_stateless_operation( + CryptoDevBackend *backend, + CryptoDevBackendSymStatelessInfo *op_info, + uint32_t queue_index, Error **errp) +{ + CryptoDevBackendClass *bc =3D + CRYPTODEV_BACKEND_GET_CLASS(backend); + + if (bc->do_sym_stateless_op) { + return bc->do_sym_stateless_op(backend, op_info, queue_index, errp= ); + } + + return -VIRTIO_CRYPTO_ERR; +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, void *opaque, @@ -133,6 +148,12 @@ int cryptodev_backend_crypto_operation( =20 return cryptodev_backend_sym_operation(backend, op_info, queue_index, errp); + } else if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM_STATELESS) { + CryptoDevBackendSymStatelessInfo *op_info; + op_info =3D req->u.sym_stateless_info; + + return cryptodev_backend_sym_stateless_operation(backend, + op_info, queue_index, errp); } else { error_setg(errp, "Unsupported cryptodev alg type: %" PRIu32 "", req->flags); diff --git a/include/hw/virtio/virtio-crypto.h b/include/hw/virtio/virtio-c= rypto.h index a00a0bf..465ad20 100755 --- a/include/hw/virtio/virtio-crypto.h +++ b/include/hw/virtio/virtio-crypto.h @@ -73,6 +73,7 @@ typedef struct VirtIOCryptoReq { struct VirtIOCrypto *vcrypto; union { CryptoDevBackendSymOpInfo *sym_op_info; + CryptoDevBackendSymStatelessInfo *sym_stateless_info; } u; } VirtIOCryptoReq; =20 diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index a9d0d1e..aa2fcd8 100755 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -58,6 +58,7 @@ typedef struct CryptoDevBackend CryptoDevBackend; =20 enum CryptoDevBackendAlgType { CRYPTODEV_BACKEND_ALG_SYM, + CRYPTODEV_BACKEND_ALG_SYM_STATELESS, CRYPTODEV_BACKEND_ALG__MAX, }; =20 @@ -146,6 +147,20 @@ typedef struct CryptoDevBackendSymOpInfo { uint8_t data[0]; } CryptoDevBackendSymOpInfo; =20 +/** + * CryptoDevBackendSymStatelessInfo: + * + * @session_info: session information, see above + * CryptoDevBackendSymSessionInfo + * @op_info: crypto operation information, see above + * CryptoDevBackendSymOpInfo, @session_id is ignored + * + **/ +typedef struct CryptoDevBackendSymStatelessInfo { + CryptoDevBackendSymSessionInfo session_info; + CryptoDevBackendSymOpInfo op_info; +} CryptoDevBackendSymStatelessInfo; + typedef struct CryptoDevBackendClass { ObjectClass parent_class; =20 @@ -161,6 +176,9 @@ typedef struct CryptoDevBackendClass { int (*do_sym_op)(CryptoDevBackend *backend, CryptoDevBackendSymOpInfo *op_info, uint32_t queue_index, Error **errp); + int (*do_sym_stateless_op)(CryptoDevBackend *backend, + CryptoDevBackendSymStatelessInfo *op_info, + uint32_t queue_index, Error **errp); } CryptoDevBackendClass; =20 =20 --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15050925670041022.0164793145962; Sun, 10 Sep 2017 18:16:07 -0700 (PDT) Received: from localhost ([::1]:54843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDKY-0007no-3I for importer@patchew.org; Sun, 10 Sep 2017 21:16:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG8-0004Ix-JY for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG5-00047p-Q2 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2313) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG4-00046Z-9E for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from 172.30.72.58 (EHLO DGGEMS402-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGZ05863; Mon, 11 Sep 2017 09:10:58 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:52 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:37 +0800 Message-ID: <1505092240-10864-6-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.0019, 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: de1eedecbfe452997c837bca434aca88 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 5/8] virtio-crypto: add stateless crypto request handler 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gonglei We can support stateless crypto request now. The stateless cipher request componet is: header + key + iv + src_data + dst_data and The algorithm chainning stateless request component is: header + key + auth_key + iv + aad + src_data + dst_data + hash_result Signed-off-by: Gonglei [simplify the code] Signed-off-by: Longpeng(Mike) --- backends/cryptodev-builtin.c | 3 +- hw/virtio/virtio-crypto.c | 310 +++++++++++++++++++++= ++-- include/standard-headers/linux/virtio_crypto.h | 161 +++++++++++++ include/sysemu/cryptodev.h | 3 + 4 files changed, 461 insertions(+), 16 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 657c0ba..6e10feb 100755 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -91,7 +91,8 @@ static void cryptodev_builtin_init( * Why this value? Just avoid to overflow when * memory allocation for each crypto request. */ - backend->conf.max_size =3D LONG_MAX - sizeof(CryptoDevBackendSymOpInfo= ); + backend->conf.max_size =3D LONG_MAX - + sizeof(CryptoDevBackendSymStatelessInfo); backend->conf.max_cipher_key_len =3D CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_= LEN; backend->conf.max_auth_key_len =3D CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; =20 diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 6076fb0..d58ffba 100755 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -38,6 +38,28 @@ static inline bool virtio_crypto_in_mux_mode(VirtIODevic= e *vdev) return virtio_vdev_has_feature(vdev, VIRTIO_CRYPTO_F_MUX_MODE); } =20 +static inline bool virtio_crypto_stateless_req(VirtIODevice *vdev, + uint32_t opcode, uint32_t flag) +{ + if (!virtio_crypto_in_mux_mode(vdev)) { + return false; + } + + switch (opcode) { + case VIRTIO_CRYPTO_CIPHER_ENCRYPT: + case VIRTIO_CRYPTO_CIPHER_DECRYPT: + if (!virtio_vdev_has_feature(vdev, + VIRTIO_CRYPTO_F_CIPHER_STATELESS_MODE)) { + return false; + } + return (flag !=3D VIRTIO_CRYPTO_FLAG_SESSION_MODE); + default: + break; + } + + return false; +} + static int virtio_crypto_cipher_session_helper(VirtIODevice *vdev, CryptoDevBackendSymSessionInfo *info, @@ -388,9 +410,10 @@ static void virtio_crypto_init_request(VirtIOCrypto *v= crypto, VirtQueue *vq, =20 static void virtio_crypto_free_request(VirtIOCryptoReq *req) { + size_t max_len; + if (req) { if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM) { - size_t max_len; CryptoDevBackendSymOpInfo *op_info =3D req->u.sym_op_info; =20 max_len =3D op_info->iv_len + @@ -402,6 +425,21 @@ static void virtio_crypto_free_request(VirtIOCryptoReq= *req) /* Zeroize and free request data structure */ memset(op_info, 0, sizeof(*op_info) + max_len); g_free(op_info); + } else if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM_STATELESS) { + CryptoDevBackendSymStatelessInfo *sym_stateless_info; + + sym_stateless_info =3D req->u.sym_stateless_info; + max_len =3D sym_stateless_info->session_info.key_len + + sym_stateless_info->session_info.auth_key_len + + sym_stateless_info->op_info.iv_len + + sym_stateless_info->op_info.src_len + + sym_stateless_info->op_info.dst_len + + sym_stateless_info->op_info.aad_len + + sym_stateless_info->op_info.digest_result_len; + /* Zeroize and free request data structure */ + memset(sym_stateless_info, 0, + sizeof(*sym_stateless_info) + max_len); + g_free(sym_stateless_info); } g_free(req); } @@ -449,6 +487,9 @@ static void virtio_crypto_req_complete(VirtIOCryptoReq = *req, uint8_t status) if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM) { virtio_crypto_sym_input_data_helper(vdev, req, status, req->u.sym_op_info); + } else if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM_STATELESS) { + virtio_crypto_sym_input_data_helper(vdev, req, status, + &req->u.sym_stateless_info->op_info); } stb_p(&req->in->status, status); virtqueue_push(req->vq, &req->elem, req->in_len); @@ -623,6 +664,221 @@ virtio_crypto_handle_sym_req(VirtIOCrypto *vcrypto, } =20 static int +virtio_crypto_handle_sym_stateless_req(VirtIOCrypto *vcrypto, + struct virtio_crypto_sym_data_req_stateless *req, + CryptoDevBackendSymStatelessInfo **stateless_info, + struct iovec *iov, unsigned int out_num) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(vcrypto); + CryptoDevBackendSymStatelessInfo *sym_stateless_info; + + uint32_t op_type; + uint32_t src_len =3D 0, dst_len =3D 0; + uint32_t iv_len =3D 0; + uint32_t aad_len =3D 0, hash_result_len =3D 0; + uint32_t hash_start_src_offset =3D 0, len_to_hash =3D 0; + uint32_t cipher_start_src_offset =3D 0, len_to_cipher =3D 0; + uint32_t key_len =3D 0, auth_key_len =3D 0; + + uint64_t max_len, curr_size =3D 0; + size_t s; + + op_type =3D ldl_le_p(&req->op_type); + + if (op_type =3D=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + key_len =3D ldl_le_p(&req->u.cipher.para.sess_para.keylen); + iv_len =3D ldl_le_p(&req->u.cipher.para.iv_len); + src_len =3D ldl_le_p(&req->u.cipher.para.src_data_len); + dst_len =3D ldl_le_p(&req->u.cipher.para.dst_data_len); + } else if (op_type =3D=3D VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) { + key_len =3D ldl_le_p(&req->u.chain.para.sess_para.cipher.keylen); + auth_key_len =3D + ldl_le_p(&req->u.chain.para.sess_para.hash.auth_key_len); + iv_len =3D ldl_le_p(&req->u.chain.para.iv_len); + src_len =3D ldl_le_p(&req->u.chain.para.src_data_len); + dst_len =3D ldl_le_p(&req->u.chain.para.dst_data_len); + + aad_len =3D ldl_le_p(&req->u.chain.para.aad_len); + hash_result_len =3D ldl_le_p(&req->u.chain.para.hash_result_len); + hash_start_src_offset =3D ldl_le_p( + &req->u.chain.para.hash_start_src_offset); + cipher_start_src_offset =3D ldl_le_p( + &req->u.chain.para.cipher_start_src_offset); + len_to_cipher =3D ldl_le_p(&req->u.chain.para.len_to_cipher); + len_to_hash =3D ldl_le_p(&req->u.chain.para.len_to_hash); + } else { + /* VIRTIO_CRYPTO_SYM_OP_NONE */ + error_report("virtio-crypto unsupported cipher type"); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + if (key_len > vcrypto->conf.max_cipher_key_len) { + virtio_error(vdev, + "virtio-crypto length of cipher key is too big: %u", key_len); + return -EFAULT; + } + + if (auth_key_len > vcrypto->conf.max_auth_key_len) { + virtio_error(vdev, + "virtio-crypto length of auth key is too big: %u", auth_key_len); + return -EFAULT; + } + + max_len =3D (uint64_t)key_len + auth_key_len + iv_len + aad_len + + src_len + dst_len + hash_result_len; + if (unlikely(max_len > vcrypto->conf.max_size)) { + virtio_error(vdev, "virtio-crypto too big length"); + return -EFAULT; + } + + sym_stateless_info =3D + g_malloc0(sizeof(CryptoDevBackendSymStatelessInfo) + max_len); + sym_stateless_info->session_info.key_len =3D key_len; + sym_stateless_info->session_info.auth_key_len =3D auth_key_len; + sym_stateless_info->op_info.iv_len =3D iv_len; + sym_stateless_info->op_info.src_len =3D src_len; + sym_stateless_info->op_info.dst_len =3D dst_len; + sym_stateless_info->op_info.aad_len =3D aad_len; + sym_stateless_info->op_info.digest_result_len =3D hash_result_len; + sym_stateless_info->op_info.hash_start_src_offset =3D + hash_start_src_offset; + sym_stateless_info->op_info.len_to_hash =3D len_to_hash; + sym_stateless_info->op_info.cipher_start_src_offset =3D + cipher_start_src_offset; + sym_stateless_info->op_info.len_to_cipher =3D len_to_cipher; + + sym_stateless_info->session_info.op_type =3D + sym_stateless_info->op_info.op_type =3D op_type; + if (op_type =3D=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + sym_stateless_info->session_info.cipher_alg =3D + ldl_le_p(&req->u.cipher.para.sess_para.algo); + sym_stateless_info->session_info.direction =3D + ldl_le_p(&req->u.cipher.para.sess_para.op); + } else { /* It must be algorithm chain here */ + sym_stateless_info->session_info.cipher_alg =3D + ldl_le_p(&req->u.chain.para.sess_para.cipher.algo); + sym_stateless_info->session_info.direction =3D + ldl_le_p(&req->u.chain.para.sess_para.cipher.op); + sym_stateless_info->session_info.hash_alg =3D + ldl_le_p(&req->u.chain.para.sess_para.hash.algo); + sym_stateless_info->session_info.hash_mode =3D + ldl_le_p(&req->u.chain.para.sess_para.hash.hash_mode); + sym_stateless_info->session_info.alg_chain_order =3D + ldl_le_p(&req->u.chain.para.sess_para.alg_chain_order); + } + + DPRINTF("cipher_alg=3D%" PRIu32 ", info->direction=3D%" PRIu32 "\n", + sym_stateless_info->session_info.cipher_alg, + sym_stateless_info->session_info.direction); + /* Begin to parse the buffer */ + + /* + * Cipher request components: + * header + key + iv + src_data + dst_data + * + * Alg_chainning request components: + * header + key + auth_key + iv + aad + src_data + dst_data + hash_r= esult + */ + if (key_len > 0) { + DPRINTF("key_len=3D%" PRIu32 "\n", key_len); + sym_stateless_info->session_info.cipher_key =3D + sym_stateless_info->op_info.data + curr_size; + + s =3D iov_to_buf(iov, out_num, 0, + sym_stateless_info->session_info.cipher_key, key_len); + if (unlikely(s !=3D key_len)) { + virtio_error(vdev, "virtio-crypto cipher key incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, key_len); + curr_size +=3D key_len; + } + if (auth_key_len > 0) { + DPRINTF("auth_key_len=3D%" PRIu32 "\n", auth_key_len); + sym_stateless_info->session_info.auth_key =3D + sym_stateless_info->op_info.data + curr_size; + + s =3D iov_to_buf(iov, out_num, 0, + sym_stateless_info->session_info.auth_key, auth_key_len); + if (unlikely(s !=3D auth_key_len)) { + virtio_error(vdev, "virtio-crypto auth key incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, auth_key_len); + curr_size +=3D auth_key_len; + } + if (iv_len > 0) { + DPRINTF("iv_len=3D%" PRIu32 "\n", iv_len); + sym_stateless_info->op_info.iv =3D + sym_stateless_info->op_info.data + curr_size; + + s =3D iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.iv, iv_len); + if (unlikely(s !=3D iv_len)) { + virtio_error(vdev, "virtio-crypto iv incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, iv_len); + curr_size +=3D iv_len; + } + + /* Handle additional authentication data if exists */ + if (aad_len > 0) { + DPRINTF("aad_len=3D%" PRIu32 "\n", aad_len); + sym_stateless_info->op_info.aad_data =3D + sym_stateless_info->op_info.data + curr_size; + + s =3D iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.aad_data, aad_len); + if (unlikely(s !=3D aad_len)) { + virtio_error(vdev, "virtio-crypto additional auth data incorre= ct"); + goto err; + } + iov_discard_front(&iov, &out_num, aad_len); + + curr_size +=3D aad_len; + } + /* Handle the source data */ + if (src_len > 0) { + DPRINTF("src_len=3D%" PRIu32 "\n", src_len); + sym_stateless_info->op_info.src =3D + sym_stateless_info->op_info.data + curr_size; + + s =3D iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.src, src_len); + if (unlikely(s !=3D src_len)) { + virtio_error(vdev, "virtio-crypto source data incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, src_len); + + curr_size +=3D src_len; + } + + /* Handle the destination data */ + sym_stateless_info->op_info.dst =3D + sym_stateless_info->op_info.data + curr_size; + curr_size +=3D dst_len; + + DPRINTF("dst_len=3D%" PRIu32 "\n", dst_len); + + /* Handle the hash digest result */ + if (hash_result_len > 0) { + DPRINTF("hash_result_len=3D%" PRIu32 "\n", hash_result_len); + sym_stateless_info->op_info.digest_result =3D + sym_stateless_info->op_info.data + curr_size; + } + + *stateless_info =3D sym_stateless_info; + + return 0; + +err: + g_free(sym_stateless_info); + return -EFAULT; +} + +static int virtio_crypto_handle_request(VirtIOCryptoReq *request) { VirtIOCrypto *vcrypto =3D request->vcrypto; @@ -630,6 +886,17 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) VirtQueueElement *elem =3D &request->elem; int queue_index =3D virtio_crypto_vq2q(virtio_get_queue_index(request-= >vq)); struct virtio_crypto_op_header *generic_hdr; + union { + struct virtio_crypto_op_data_req req; + struct virtio_crypto_op_data_req_mux mux_req; + } op; + + bool is_stateless_req =3D false; + union { + CryptoDevBackendSymOpInfo *sym_op_info; + CryptoDevBackendSymStatelessInfo *stateless_info; + } info; + int ret; struct iovec *in_iov; struct iovec *out_iov; @@ -638,14 +905,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) uint32_t opcode; uint8_t status =3D VIRTIO_CRYPTO_ERR; uint64_t session_id; - CryptoDevBackendSymOpInfo *sym_op_info =3D NULL; Error *local_err =3D NULL; size_t s, exp_len; void *body; - union { - struct virtio_crypto_op_data_req req; - struct virtio_crypto_op_data_req_mux mux_req; - } op; =20 if (elem->out_num < 1 || elem->in_num < 1) { virtio_error(vdev, "virtio-crypto dataq missing headers"); @@ -693,14 +955,19 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) request->in_iov =3D in_iov; =20 opcode =3D ldl_le_p(&generic_hdr->opcode); - session_id =3D ldq_le_p(&generic_hdr->session_id); =20 switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: if (virtio_crypto_in_mux_mode(vdev)) { - body =3D g_new0(struct virtio_crypto_sym_data_req, 1); - exp_len =3D sizeof(struct virtio_crypto_sym_data_req); + if (virtio_crypto_stateless_req(vdev, opcode, generic_hdr->fla= g)) { + body =3D g_new0(struct virtio_crypto_sym_data_req_stateles= s, 1); + exp_len =3D sizeof(struct virtio_crypto_sym_data_req_state= less); + is_stateless_req =3D true; + } else { + body =3D g_new0(struct virtio_crypto_sym_data_req, 1); + exp_len =3D sizeof(struct virtio_crypto_sym_data_req); + } s =3D iov_to_buf(out_iov, out_num, 0, body, exp_len); if (unlikely(s !=3D exp_len)) { g_free(body); @@ -711,8 +978,13 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) body =3D &op.req.u.sym_req; } =20 - ret =3D virtio_crypto_handle_sym_req(vcrypto, body, - &sym_op_info, out_iov, out_num); + if (is_stateless_req) { + ret =3D virtio_crypto_handle_sym_stateless_req(vcrypto, body, + &info.stateless_info, out_iov, out_num); + } else { + ret =3D virtio_crypto_handle_sym_req(vcrypto, body, + &info.sym_op_info, out_iov, out_num); + } /* Serious errors, need to reset virtio crypto device */ if (ret =3D=3D -EFAULT) { return -1; @@ -720,11 +992,19 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) virtio_crypto_req_complete(request, VIRTIO_CRYPTO_NOTSUPP); virtio_crypto_free_request(request); } else { - sym_op_info->session_id =3D session_id; + if (is_stateless_req) { + info.stateless_info->op_info.op_code =3D opcode; + request->flags =3D CRYPTODEV_BACKEND_ALG_SYM_STATELESS; + request->u.sym_stateless_info =3D info.stateless_info; + } else { + info.sym_op_info->op_code =3D opcode; + session_id =3D ldq_le_p(&generic_hdr->session_id); + info.sym_op_info->session_id =3D session_id; + /* Set request's parameter */ + request->flags =3D CRYPTODEV_BACKEND_ALG_SYM; + request->u.sym_op_info =3D info.sym_op_info; + } =20 - /* Set request's parameter */ - request->flags =3D CRYPTODEV_BACKEND_ALG_SYM; - request->u.sym_op_info =3D sym_op_info; ret =3D cryptodev_backend_crypto_operation(vcrypto->cryptodev, request, queue_index, &local_err); if (ret < 0) { diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/stand= ard-headers/linux/virtio_crypto.h index 987fb1e..0ea61b2 100755 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -283,6 +283,7 @@ struct virtio_crypto_op_header { uint32_t algo; /* session_id should be service-specific algorithms */ uint64_t session_id; +#define VIRTIO_CRYPTO_FLAG_SESSION_MODE 1 /* control flag to control the request */ uint32_t flag; uint32_t padding; @@ -415,6 +416,166 @@ struct virtio_crypto_op_data_req { } u; }; =20 +struct virtio_crypto_cipher_para_stateless { + struct { + /* See VIRTIO_CRYPTO_CIPHER* above */ + uint32_t algo; + /* length of key */ + uint32_t keylen; + + /* See VIRTIO_CRYPTO_OP_* above */ + uint32_t op; + } sess_para; + + /* + * Byte Length of valid IV/Counter + */ + uint32_t iv_len; + /* length of source data */ + uint32_t src_data_len; + /* length of dst data */ + uint32_t dst_data_len; +}; + +struct virtio_crypto_alg_chain_data_para_stateless { + struct { + /* See VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_* above */ + uint32_t alg_chain_order; + /* length of the additional authenticated data in bytes */ + uint32_t aad_len; + + struct { + /* See VIRTIO_CRYPTO_CIPHER* above */ + uint32_t algo; + /* length of key */ + uint32_t keylen; + /* See VIRTIO_CRYPTO_OP_* above */ + uint32_t op; + } cipher; + + struct { + /* See VIRTIO_CRYPTO_HASH_* or _MAC_* above */ + uint32_t algo; + /* length of authenticated key */ + uint32_t auth_key_len; + /* See VIRTIO_CRYPTO_SYM_HASH_MODE_* above */ + uint32_t hash_mode; + } hash; + } sess_para; + + uint32_t iv_len; + /* Length of source data */ + uint32_t src_data_len; + /* Length of destination data */ + uint32_t dst_data_len; + /* Starting point for cipher processing in source data */ + uint32_t cipher_start_src_offset; + /* Length of the source data that the cipher will be computed on */ + uint32_t len_to_cipher; + /* Starting point for hash processing in source data */ + uint32_t hash_start_src_offset; + /* Length of the source data that the hash will be computed on */ + uint32_t len_to_hash; + /* Length of the additional auth data */ + uint32_t aad_len; + /* Length of the hash result */ + uint32_t hash_result_len; + uint32_t reserved; +}; + +struct virtio_crypto_hash_para_stateless { + struct { + /* See VIRTIO_CRYPTO_HASH_* above */ + uint32_t algo; + } sess_para; + + /* length of source data */ + uint32_t src_data_len; + /* hash result length */ + uint32_t hash_result_len; + uint32_t reserved; +}; + +struct virtio_crypto_mac_para_stateless { + struct { + /* See VIRTIO_CRYPTO_MAC_* above */ + uint32_t algo; + /* length of authenticated key */ + uint32_t auth_key_len; + } sess_para; + + /* length of source data */ + uint32_t src_data_len; + /* hash result length */ + uint32_t hash_result_len; +}; + +struct virtio_crypto_aead_para_stateless { + struct { + /* See VIRTIO_CRYPTO_AEAD_* above */ + uint32_t algo; + /* length of key */ + uint32_t key_len; + /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ + uint32_t op; + } sess_para; + + /* + * Byte Length of valid IV data pointed to by the below iv_addr + * parameter. + */ + uint32_t iv_len; + /* Authentication tag length */ + uint32_t tag_len; + /* length of the additional authenticated data (AAD) in bytes */ + uint32_t aad_len; + /* length of source data */ + uint32_t src_data_len; + /* length of dst data, it should be at least src_data_len + tag_len */ + uint32_t dst_data_len; +}; + +struct virtio_crypto_cipher_data_req_stateless { + /* Device-readable part */ + struct virtio_crypto_cipher_para_stateless para; + uint8_t padding[48]; +}; + +struct virtio_crypto_hash_data_req_stateless { + /* Device-readable part */ + struct virtio_crypto_hash_para_stateless para; + uint8_t padding[64]; +}; + +struct virtio_crypto_mac_data_req_stateless { + /* Device-readable part */ + struct virtio_crypto_mac_para_stateless para; + uint8_t padding[64]; +}; + +struct virtio_crypto_alg_chain_data_req_stateless { + /* Device-readable part */ + struct virtio_crypto_alg_chain_data_para_stateless para; +}; + +struct virtio_crypto_sym_data_req_stateless { + union { + struct virtio_crypto_cipher_data_req_stateless cipher; + struct virtio_crypto_alg_chain_data_req_stateless chain; + uint8_t padding[72]; + } u; + + /* See above VIRTIO_CRYPTO_SYM_OP_* */ + uint32_t op_type; + uint32_t padding; +}; + +struct virtio_crypto_aead_data_req_stateless { + /* Device-readable part */ + struct virtio_crypto_aead_para_stateless para; + uint8_t padding[48]; +}; + /* The request of the data virtqueue's packet for MUX mode */ struct virtio_crypto_op_data_req_mux { struct virtio_crypto_op_header header; diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index aa2fcd8..9f83082 100755 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -103,6 +103,7 @@ typedef struct CryptoDevBackendSymSessionInfo { * * @session_id: session index which was previously * created by cryptodev_backend_sym_create_session() + * @op_code: operation code (refer to virtio_crypto.h) * @aad_len: byte length of additional authenticated data * @iv_len: byte length of initialization vector or counter * @src_len: byte length of source data @@ -129,6 +130,8 @@ typedef struct CryptoDevBackendSymSessionInfo { */ typedef struct CryptoDevBackendSymOpInfo { uint64_t session_id; + /* corresponding with virtio crypto spec */ + uint32_t op_code; uint32_t aad_len; uint32_t iv_len; uint32_t src_len; --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092418104405.6541976662505; Sun, 10 Sep 2017 18:13:38 -0700 (PDT) Received: from localhost ([::1]:54831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDI9-0005jQ-4B for importer@patchew.org; Sun, 10 Sep 2017 21:13:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG5-0004HK-Sp for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG1-00045o-2i for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2257) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG0-00041D-2a for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:25 -0400 Received: from 172.30.72.59 (EHLO DGGEMS404-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHB06012; Mon, 11 Sep 2017 09:11:00 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:53 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:38 +0800 Message-ID: <1505092240-10864-7-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.0A0B0205.59B5E2A5.001B, 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: 1cd8c6a770e990a286b0f3307a590b81 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC 6/8] cryptodev: extract one util function 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gonglei So that the new function can be used by both seesion creation and the following stateless crypto operation. Signed-off-by: Gonglei Signed-off-by: Longpeng(Mike) --- backends/cryptodev-builtin.c | 100 +++++++++++++++++++++++++--------------= ---- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 6e10feb..ab3d88d 100755 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -152,73 +152,56 @@ err: return -1; } =20 -static int cryptodev_builtin_create_cipher_session( - CryptoDevBackendBuiltin *builtin, +static int +cryptodev_builtin_get_cipher_alg_mode( CryptoDevBackendSymSessionInfo *sess_info, + int *algo, int *mode, Error **errp) { - int algo; - int mode; - QCryptoCipher *cipher; - int index; - CryptoDevBackendBuiltinSession *sess; - - if (sess_info->op_type !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { - error_setg(errp, "Unsupported optype :%u", sess_info->op_type); - return -1; - } - - index =3D cryptodev_builtin_get_unused_session_index(builtin); - if (index < 0) { - error_setg(errp, "Total number of sessions created exceeds %u", - MAX_NUM_SESSIONS); - return -1; - } - switch (sess_info->cipher_alg) { case VIRTIO_CRYPTO_CIPHER_AES_ECB: - mode =3D QCRYPTO_CIPHER_MODE_ECB; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_ECB; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CBC: - mode =3D QCRYPTO_CIPHER_MODE_CBC; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_CBC; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CTR: - mode =3D QCRYPTO_CIPHER_MODE_CTR; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_CTR; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_XTS: - mode =3D QCRYPTO_CIPHER_MODE_XTS; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_XTS; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_3DES_ECB: - mode =3D QCRYPTO_CIPHER_MODE_ECB; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_ECB; + *algo =3D QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CBC: - mode =3D QCRYPTO_CIPHER_MODE_CBC; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_CBC; + *algo =3D QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CTR: - mode =3D QCRYPTO_CIPHER_MODE_CTR; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_CTR; + *algo =3D QCRYPTO_CIPHER_ALG_3DES; break; default: error_setg(errp, "Unsupported cipher alg :%u", @@ -226,6 +209,39 @@ static int cryptodev_builtin_create_cipher_session( return -1; } =20 + return 0; +} + +static int cryptodev_builtin_create_cipher_session( + CryptoDevBackendBuiltin *builtin, + CryptoDevBackendSymSessionInfo *sess_info, + Error **errp) +{ + int algo; + int mode; + QCryptoCipher *cipher; + int index; + CryptoDevBackendBuiltinSession *sess; + int ret; + + if (sess_info->op_type !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported optype :%u", sess_info->op_type); + return -1; + } + + index =3D cryptodev_builtin_get_unused_session_index(builtin); + if (index < 0) { + error_setg(errp, "Total number of sessions created exceeds %u", + MAX_NUM_SESSIONS); + return -1; + } + + ret =3D cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -1; + } + cipher =3D qcrypto_cipher_new(algo, mode, sess_info->cipher_key, sess_info->key_len, --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092563848637.5013602583776; Sun, 10 Sep 2017 18:16:03 -0700 (PDT) Received: from localhost ([::1]:54842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDKV-0007mL-1I for importer@patchew.org; Sun, 10 Sep 2017 21:16:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG6-0004HM-30 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG3-00046m-BO for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:30 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2258) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG2-00044Z-D3 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:27 -0400 Received: from 172.30.72.59 (EHLO DGGEMS403-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHB06019; Mon, 11 Sep 2017 09:11:03 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:54 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:39 +0800 Message-ID: <1505092240-10864-8-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.0A0B0205.59B5E2A8.002E, 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: cad29c4c6fcdff6afc1ffa45d899c509 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC 7/8] cryptodev-builtin: add stateless cipher support 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds stateless cipher support for builtin-backend Signed-off-by: Gonglei [simplify the code & correct the return value] Signed-off-by: Longpeng(Mike) --- backends/cryptodev-builtin.c | 86 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 86 insertions(+) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index ab3d88d..1152ea2 100755 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -335,6 +335,13 @@ static int cryptodev_builtin_sym_operation( return -VIRTIO_CRYPTO_NOTSUPP; } =20 + if (op_info->op_code !=3D VIRTIO_CRYPTO_CIPHER_ENCRYPT && + op_info->op_code !=3D VIRTIO_CRYPTO_CIPHER_DECRYPT) { + error_setg(errp, + "Unsupported op code: %u", op_info->op_code); + return -VIRTIO_CRYPTO_NOTSUPP; + } + sess =3D builtin->sessions[op_info->session_id]; =20 if (op_info->iv_len > 0) { @@ -389,6 +396,84 @@ static void cryptodev_builtin_cleanup( cryptodev_backend_set_ready(backend, false); } =20 +static int +cryptodev_builtin_sym_stateless_operation( + CryptoDevBackend *backend, + CryptoDevBackendSymStatelessInfo *op_info, + uint32_t queue_index, Error **errp) +{ + CryptoDevBackendSymSessionInfo *sess_info; + CryptoDevBackendSymOpInfo *sym_op_info; + int algo, mode; + int ret; + QCryptoCipher *cipher =3D NULL; + + sess_info =3D &op_info->session_info; + sym_op_info =3D &op_info->op_info; + + if (sess_info->op_type !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported op_type: %u", sess_info->op_type); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + switch (sym_op_info->op_code) { + case VIRTIO_CRYPTO_CIPHER_ENCRYPT: + case VIRTIO_CRYPTO_CIPHER_DECRYPT: + ret =3D cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -VIRTIO_CRYPTO_NOTSUPP; + } + + cipher =3D qcrypto_cipher_new(algo, mode, + sess_info->cipher_key, + sess_info->key_len, + errp); + if (!cipher) { + return -VIRTIO_CRYPTO_ERR; + } + + if (sym_op_info->iv_len > 0) { + ret =3D qcrypto_cipher_setiv(cipher, sym_op_info->iv, + sym_op_info->iv_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } + + if (sess_info->direction =3D=3D VIRTIO_CRYPTO_OP_ENCRYPT) { + ret =3D qcrypto_cipher_encrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } else { + ret =3D qcrypto_cipher_decrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } + break; + + default: + error_setg(errp, "Unsupported op_code: %" PRIu32 "", + sym_op_info->op_code); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + ret =3D VIRTIO_CRYPTO_OK; + +out: + qcrypto_cipher_free(cipher); + return ret; +} + static void cryptodev_builtin_class_init(ObjectClass *oc, void *data) { @@ -399,6 +484,7 @@ cryptodev_builtin_class_init(ObjectClass *oc, void *dat= a) bc->create_session =3D cryptodev_builtin_sym_create_session; bc->close_session =3D cryptodev_builtin_sym_close_session; bc->do_sym_op =3D cryptodev_builtin_sym_operation; + bc->do_sym_stateless_op =3D cryptodev_builtin_sym_stateless_operation; } =20 static const TypeInfo cryptodev_builtin_info =3D { --=20 1.8.3.1 From nobody Sat Apr 27 07:07:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505092414863679.7909076212937; Sun, 10 Sep 2017 18:13:34 -0700 (PDT) Received: from localhost ([::1]:54828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDI4-0005fu-Oe for importer@patchew.org; Sun, 10 Sep 2017 21:13:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG5-0004HG-LJ for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG3-00046y-W1 for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2312) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG3-00045u-Ad for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:27 -0400 Received: from 172.30.72.60 (EHLO DGGEMS406-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGZ05878; Mon, 11 Sep 2017 09:11:04 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:55 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:40 +0800 Message-ID: <1505092240-10864-9-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.59B5E2A8.00C2, 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: 648eda8833e128d54396ba254e4a3e33 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 8/8] virtio-crypto: add host feature bits support 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: pasic@linux.vnet.ibm.com, Ola.Liljedahl@arm.com, brian.a.keating@intel.com, wangxinxin.wang@huawei.com, mst@redhat.com, xin.zeng@intel.com, jasowang@redhat.com, cohuck@redhat.com, luonengjun@huawei.com, agraf@suse.de, john.griffin@intel.com, mike.caraman@nxp.com, arei.gonglei@huawei.com, liang.j.ma@intel.com, stefanha@redhat.com, Varun.Sethi@freescale.com, Jani.Kokkonen@huawei.com, vincent.jardin@6wind.com, denglingli@chinamobile.com, weidong.huang@huawei.com, arei.gonglei@hotmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gonglei We enable all feature bits acquiescently. Signed-off-by: Gonglei --- hw/virtio/virtio-crypto.c | 15 +++++++++++++++ include/hw/virtio/virtio-crypto.h | 1 + 2 files changed, 16 insertions(+) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index d58ffba..69c5ad5 100755 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1095,6 +1095,11 @@ static uint64_t virtio_crypto_get_features(VirtIODev= ice *vdev, uint64_t features, Error **errp) { + VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); + + /* Firstly sync all virtio-crypto possible supported features */ + features |=3D vcrypto->host_features; + return features; } =20 @@ -1210,6 +1215,16 @@ static const VMStateDescription vmstate_virtio_crypt= o =3D { }; =20 static Property virtio_crypto_properties[] =3D { + DEFINE_PROP_BIT("mux_mode", VirtIOCrypto, host_features, + VIRTIO_CRYPTO_F_MUX_MODE, true), + DEFINE_PROP_BIT("cipher_stateless_mode", VirtIOCrypto, host_features, + VIRTIO_CRYPTO_F_CIPHER_STATELESS_MODE, true), + DEFINE_PROP_BIT("hash_stateless_mode", VirtIOCrypto, host_features, + VIRTIO_CRYPTO_F_HASH_STATELESS_MODE, true), + DEFINE_PROP_BIT("mac_stateless_mode", VirtIOCrypto, host_features, + VIRTIO_CRYPTO_F_MAC_STATELESS_MODE, true), + DEFINE_PROP_BIT("aead_stateless_mode", VirtIOCrypto, host_features, + VIRTIO_CRYPTO_F_AEAD_STATELESS_MODE, true), DEFINE_PROP_LINK("cryptodev", VirtIOCrypto, conf.cryptodev, TYPE_CRYPTODEV_BACKEND, CryptoDevBackend *), DEFINE_PROP_END_OF_LIST(), diff --git a/include/hw/virtio/virtio-crypto.h b/include/hw/virtio/virtio-c= rypto.h index 465ad20..30ea51d 100755 --- a/include/hw/virtio/virtio-crypto.h +++ b/include/hw/virtio/virtio-crypto.h @@ -97,6 +97,7 @@ typedef struct VirtIOCrypto { int multiqueue; uint32_t curr_queues; size_t config_size; + uint32_t host_features; } VirtIOCrypto; =20 #endif /* _QEMU_VIRTIO_CRYPTO_H */ --=20 1.8.3.1