From patchwork Mon Nov 6 06:56:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk0g0dXpz9s7p for ; Mon, 6 Nov 2017 17:58:11 +1100 (AEDT) Received: from localhost ([::1]:46709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbMH-0006HK-3l for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 01:58:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLY-0006FV-5Z for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLW-0008Gw-VL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:24 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2277) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLW-0008AE-5w for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:22 -0500 Received: from 172.30.72.59 (EHLO DGGEMS412-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKL32628; Mon, 06 Nov 2017 14:57:19 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:57:05 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:53 +0800 Message-ID: <1509951422-20060-2-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020202.5A0007CF.00B5, 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: 3eb1beb8808d68031bf787fb0b7aa57f 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 01/10] virtio-crypto: remove virtio_crypto_op_ctrl_req structure 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The struct virtio_crypto_op_ctrl_req is not needed, we can use 'header + payload' instead as suggested by Halil. This can makes the code simpler to add MUX-mode support in the next patch. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 48 ++++++++++++++++++++------ include/standard-headers/linux/virtio_crypto.h | 19 +--------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 19c82e0..c7f6cc4 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -210,7 +210,7 @@ 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; + struct virtio_crypto_ctrl_header hdr; VirtQueueElement *elem; struct iovec *in_iov; struct iovec *out_iov; @@ -239,25 +239,38 @@ 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))) { + + s = sizeof(hdr); + if (unlikely(s != iov_to_buf(out_iov, out_num, 0, &hdr, s))) { 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)); + iov_discard_front(&out_iov, &out_num, s); - opcode = ldl_le_p(&ctrl.header.opcode); - queue_id = ldl_le_p(&ctrl.header.queue_id); + opcode = ldl_le_p(&hdr.opcode); + queue_id = ldl_le_p(&hdr.queue_id); switch (opcode) { case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION: + { + struct virtio_crypto_sym_create_session_req req; + + iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); + /* The unused part of the req will be ingored */ + s = VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX; + if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { + virtio_error(vdev, "virtio-crypto request additional " + "parameters too short"); + virtqueue_detach_element(vq, elem, 0); + break; + } + 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); + &req, 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); @@ -281,12 +294,26 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) virtqueue_push(vq, elem, sizeof(input)); virtio_notify(vdev, vq); break; + } case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION: case VIRTIO_CRYPTO_HASH_DESTROY_SESSION: case VIRTIO_CRYPTO_MAC_DESTROY_SESSION: case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION: + { + struct virtio_crypto_destroy_session_req req; + + iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); + /* The unused part of the req will be ingored */ + s = VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX; + if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { + virtio_error(vdev, "virtio-crypto request additional " + "parameters too short"); + virtqueue_detach_element(vq, elem, 0); + break; + } + status = virtio_crypto_handle_close_session(vcrypto, - &ctrl.u.destroy_session, queue_id); + &req, 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))) { @@ -297,6 +324,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) virtqueue_push(vq, elem, sizeof(status)); virtio_notify(vdev, vq); break; + } case VIRTIO_CRYPTO_HASH_CREATE_SESSION: case VIRTIO_CRYPTO_MAC_CREATE_SESSION: case VIRTIO_CRYPTO_AEAD_CREATE_SESSION: diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/standard-headers/linux/virtio_crypto.h index 5ff0b4e..6677c82 100644 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -234,24 +234,7 @@ struct virtio_crypto_destroy_session_req { uint8_t padding[48]; }; -/* The request of the control virtqueue's packet */ -struct virtio_crypto_op_ctrl_req { - struct virtio_crypto_ctrl_header header; - - union { - struct virtio_crypto_sym_create_session_req - sym_create_session; - struct virtio_crypto_hash_create_session_req - hash_create_session; - struct virtio_crypto_mac_create_session_req - mac_create_session; - struct virtio_crypto_aead_create_session_req - aead_create_session; - struct virtio_crypto_destroy_session_req - destroy_session; - uint8_t padding[56]; - } u; -}; +#define VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX 56 struct virtio_crypto_op_header { #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ From patchwork Mon Nov 6 06:56:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVl464FPJz9s7p for ; Mon, 6 Nov 2017 18:46:14 +1100 (AEDT) Received: from localhost ([::1]:46843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc6m-0004is-NY for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:46:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc3u-0003Cz-0W for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBc3p-0003on-Ci for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:14 -0500 Received: from [45.249.212.32] (port=41900 helo=huawei.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc3p-0003oI-0d for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:09 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7645718C3C9E5; Mon, 6 Nov 2017 14:57:16 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:57:06 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:54 +0800 Message-ID: <1509951422-20060-3-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.32 Subject: [Qemu-devel] [RFC 02/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Adds some macros about the features of multiplexing mode and supports the session create for this mode. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 13 +++++++++++-- include/standard-headers/linux/virtio_crypto.h | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index c7f6cc4..04c34d8 100644 --- 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, @@ -223,6 +228,9 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) uint8_t status; size_t s; +#define ctrl_req_payload_size(vdev, req) \ + (virtio_crypto_in_mux_mode((vdev)) ? sizeof((req)) : \ + VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX) for (;;) { elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { @@ -259,7 +267,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); /* The unused part of the req will be ingored */ - s = VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX; + s = ctrl_req_payload_size(vdev, req); if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { virtio_error(vdev, "virtio-crypto request additional " "parameters too short"); @@ -304,7 +312,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); /* The unused part of the req will be ingored */ - s = VIRTIO_CRYPTO_CTRL_REQ_PAYLOAD_SIZE_NONMUX; + s = ctrl_req_payload_size(vdev, req); if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { virtio_error(vdev, "virtio-crypto request additional " "parameters too short"); @@ -346,6 +354,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) g_free(elem); } /* end for loop */ +#undef ctrl_req_payload_size } static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq, diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/standard-headers/linux/virtio_crypto.h index 6677c82..8793be6 100644 --- 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 +/* 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)) struct virtio_crypto_ctrl_header { From patchwork Mon Nov 6 06:56:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk0d3yy1z9s7p for ; Mon, 6 Nov 2017 17:58:09 +1100 (AEDT) Received: from localhost ([::1]:46708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbMF-0006GK-JJ for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 01:58:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLW-0006FG-Fz for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLR-00084d-Pj for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:22 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2276) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLR-00080O-6W for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:17 -0500 Received: from 172.30.72.59 (EHLO DGGEMS409-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKL32606; Mon, 06 Nov 2017 14:57:13 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:57:06 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:55 +0800 Message-ID: <1509951422-20060-4-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020201.5A0007C9.0047, 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: 260f5bd255ac14fe316b8376c252f479 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 03/10] virtio-crypto: remove queue_id field in ctrl header 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The queue_id is needless bacause we can get the info from VirtQueue->queue_index. For existing frontend driver, this field is always zero, so we can just mark this field as reserved and ingore its value. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 8 +++----- include/standard-headers/linux/virtio_crypto.h | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 04c34d8..9ffe26d 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -221,7 +221,6 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) 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; @@ -258,7 +257,6 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) iov_discard_front(&out_iov, &out_num, s); opcode = ldl_le_p(&hdr.opcode); - queue_id = ldl_le_p(&hdr.queue_id); switch (opcode) { case VIRTIO_CRYPTO_CIPHER_CREATE_SESSION: @@ -277,8 +275,8 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) memset(&input, 0, sizeof(input)); session_id = virtio_crypto_create_sym_session(vcrypto, - &req, queue_id, opcode, - out_iov, out_num); + &req, virtio_get_queue_index(vq), + opcode, out_iov, out_num); /* Serious errors, need to reset virtio crypto device */ if (session_id == -EFAULT) { virtqueue_detach_element(vq, elem, 0); @@ -321,7 +319,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) } status = virtio_crypto_handle_close_session(vcrypto, - &req, queue_id); + &req, virtio_get_queue_index(vq)); /* 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))) { diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/standard-headers/linux/virtio_crypto.h index 8793be6..5e586e5 100644 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -67,8 +67,7 @@ struct virtio_crypto_ctrl_header { uint32_t opcode; uint32_t algo; uint32_t flag; - /* data virtqueue id */ - uint32_t queue_id; + uint32_t reserved; }; struct virtio_crypto_cipher_session_para { From patchwork Mon Nov 6 06:56:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk3r2yV9z9s7p for ; Mon, 6 Nov 2017 18:00:56 +1100 (AEDT) Received: from localhost ([::1]:46727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbOw-0000F0-Fw for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:00:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLe-0006Ii-CR for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLd-0008V2-8a for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:30 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2332) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLc-0008Ot-MG for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:29 -0500 Received: from 172.30.72.58 (EHLO DGGEMS408-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32721; Mon, 06 Nov 2017 14:57:25 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:57:07 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:56 +0800 Message-ID: <1509951422-20060-5-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020204.5A0007D6.0023, 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: ccf953ba60ff87332ddbbf54ca546924 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 04/10] virtio-crypto: remove virtio_crypto_op_data_req structure 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The struct virtio_crypto_op_data_req is not needed, we can use 'header + payload' instead. This makes the code simpler to add MUX-mode support in the next patch. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 34 ++++++++++++++++++-------- include/standard-headers/linux/virtio_crypto.h | 13 +--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 9ffe26d..828d7ef 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -611,7 +611,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); VirtQueueElement *elem = &request->elem; int queue_index = virtio_crypto_vq2q(virtio_get_queue_index(request->vq)); - struct virtio_crypto_op_data_req req; + struct virtio_crypto_op_header hdr; int ret; struct iovec *in_iov; struct iovec *out_iov; @@ -622,6 +622,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) uint64_t session_id; CryptoDevBackendSymOpInfo *sym_op_info = NULL; Error *local_err = NULL; + size_t s; if (elem->out_num < 1 || elem->in_num < 1) { virtio_error(vdev, "virtio-crypto dataq missing headers"); @@ -632,12 +633,13 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) 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, &req, sizeof(req)) - != sizeof(req))) { + + s = sizeof(hdr); + if (unlikely(s != iov_to_buf(out_iov, out_num, 0, &hdr, s))) { 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, s); if (in_iov[in_num - 1].iov_len < sizeof(struct virtio_crypto_inhdr)) { @@ -658,16 +660,27 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) request->in_num = in_num; request->in_iov = in_iov; - opcode = ldl_le_p(&req.header.opcode); - session_id = ldq_le_p(&req.header.session_id); + opcode = ldl_le_p(&hdr.opcode); + session_id = ldq_le_p(&hdr.session_id); switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: - ret = virtio_crypto_handle_sym_req(vcrypto, - &req.u.sym_req, - &sym_op_info, - out_iov, out_num); + { + struct virtio_crypto_sym_data_req req; + + iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); + /* The unused part of the req will be ingored */ + s = VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX; + if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { + virtio_error(vdev, "virtio-crypto request additional " + "parameters too short"); + return -1; + } + + ret = virtio_crypto_handle_sym_req(vcrypto, &req, + &sym_op_info, + out_iov, out_num); /* Serious errors, need to reset virtio crypto device */ if (ret == -EFAULT) { return -1; @@ -694,6 +707,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) virtio_crypto_free_request(request); } break; + } case VIRTIO_CRYPTO_HASH: case VIRTIO_CRYPTO_MAC: case VIRTIO_CRYPTO_AEAD_ENCRYPT: diff --git a/include/standard-headers/linux/virtio_crypto.h b/include/standard-headers/linux/virtio_crypto.h index 5e586e5..81357e5 100644 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -379,18 +379,7 @@ struct virtio_crypto_aead_data_req { uint8_t padding[32]; }; -/* The request of the data virtqueue's packet */ -struct virtio_crypto_op_data_req { - struct virtio_crypto_op_header header; - - union { - struct virtio_crypto_sym_data_req sym_req; - struct virtio_crypto_hash_data_req hash_req; - struct virtio_crypto_mac_data_req mac_req; - struct virtio_crypto_aead_data_req aead_req; - uint8_t padding[48]; - } u; -}; +#define VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX 48 #define VIRTIO_CRYPTO_OK 0 #define VIRTIO_CRYPTO_ERR 1 From patchwork Mon Nov 6 06:56:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834500 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVl5r5dwlz9s7p for ; Mon, 6 Nov 2017 18:47:44 +1100 (AEDT) Received: from localhost ([::1]:46846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc8E-00062k-Az for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:47:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc3u-0003Cy-01 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBc3p-0003oZ-Ar for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:14 -0500 Received: from [45.249.212.32] (port=41892 helo=huawei.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc3o-0003oF-Ur for qemu-devel@nongnu.org; Mon, 06 Nov 2017 02:43:09 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3037210C9DC5C; Mon, 6 Nov 2017 14:57:13 +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.361.1; Mon, 6 Nov 2017 14:57:08 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:57 +0800 Message-ID: <1509951422-20060-6-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.32 Subject: [Qemu-devel] [RFC 05/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Adds dataq operation support for MUX mode. Signed-off-by: Longpeng(Mike) --- hw/virtio/virtio-crypto.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 828d7ef..10a0c35 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -663,6 +663,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) opcode = ldl_le_p(&hdr.opcode); session_id = ldq_le_p(&hdr.session_id); +#define data_req_payload_size(vdev, req) \ + (virtio_crypto_in_mux_mode((vdev)) ? sizeof((req)) : \ + VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX) switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: @@ -671,7 +674,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); /* The unused part of the req will be ingored */ - s = VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX; + s = data_req_payload_size(vdev, req); if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { virtio_error(vdev, "virtio-crypto request additional " "parameters too short"); @@ -718,6 +721,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) virtio_crypto_req_complete(request, VIRTIO_CRYPTO_NOTSUPP); virtio_crypto_free_request(request); } +#undef data_req_payload_size return 0; } From patchwork Mon Nov 6 06:56:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk0h0hxgz9s82 for ; Mon, 6 Nov 2017 17:58:12 +1100 (AEDT) Received: from localhost ([::1]:46710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbMI-0006IN-4B for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 01:58:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLa-0006Gk-Dy for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLV-0008Fb-Te for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2329) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLV-00088u-AS for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:21 -0500 Received: from 172.30.72.58 (EHLO DGGEMS406-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32700; Mon, 06 Nov 2017 14:57:18 +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.361.1; Mon, 6 Nov 2017 14:57:08 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:58 +0800 Message-ID: <1509951422-20060-7-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020201.5A0007CE.00D6, 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: 79b9684b4f5e46c1bf3d156717c5ca16 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 06/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 67edfa5..e06ab12 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -120,6 +120,21 @@ static int cryptodev_backend_sym_operation( return -VIRTIO_CRYPTO_ERR; } +static int cryptodev_backend_sym_stateless_operation( + CryptoDevBackend *backend, + CryptoDevBackendSymStatelessInfo *op_info, + uint32_t queue_index, Error **errp) +{ + CryptoDevBackendClass *bc = + 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( return cryptodev_backend_sym_operation(backend, op_info, queue_index, errp); + } else if (req->flags == CRYPTODEV_BACKEND_ALG_SYM_STATELESS) { + CryptoDevBackendSymStatelessInfo *op_info; + op_info = 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-crypto.h index a00a0bf..465ad20 100644 --- 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; diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index a9d0d1e..aa2fcd8 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -58,6 +58,7 @@ typedef struct CryptoDevBackend CryptoDevBackend; enum CryptoDevBackendAlgType { CRYPTODEV_BACKEND_ALG_SYM, + CRYPTODEV_BACKEND_ALG_SYM_STATELESS, CRYPTODEV_BACKEND_ALG__MAX, }; @@ -146,6 +147,20 @@ typedef struct CryptoDevBackendSymOpInfo { uint8_t data[0]; } CryptoDevBackendSymOpInfo; +/** + * 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; @@ -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; From patchwork Mon Nov 6 06:56:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk6b1p5Sz9s7p for ; Mon, 6 Nov 2017 18:03:18 +1100 (AEDT) Received: from localhost ([::1]:46734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbRD-0002CE-Bk for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:03:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLa-0006Gm-Ge for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLY-0008IT-2E for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2330) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLW-0008Ao-O8 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:23 -0500 Received: from 172.30.72.60 (EHLO DGGEMS405-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32702; Mon, 06 Nov 2017 14:57:19 +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.361.1; Mon, 6 Nov 2017 14:57:09 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:56:59 +0800 Message-ID: <1509951422-20060-8-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020201.5A0007D0.0034, 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: f4dea901c5efefc75520ac81596d37ed 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 07/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We can support stateless crypto request now. The stateless cipher request componet is: header + payload + key + iv + src_data + dst_data and The algorithm chainning stateless request component is: header + payload + key + auth_key + iv + aad + src_data + dst_data + hash_result Signed-off-by: Gonglei [simplify the code] Signed-off-by: Longpeng(Mike) Signed-off-by: Longpeng(Mike) --- backends/cryptodev-builtin.c | 3 +- hw/virtio/virtio-crypto.c | 311 +++++++++++++++++++++++-- include/standard-headers/linux/virtio_crypto.h | 161 +++++++++++++ include/sysemu/cryptodev.h | 3 + 4 files changed, 462 insertions(+), 16 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 657c0ba..6df23b9 100644 --- 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 = LONG_MAX - sizeof(CryptoDevBackendSymOpInfo); + backend->conf.max_size = LONG_MAX - + sizeof(CryptoDevBackendSymStatelessInfo); backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN; backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 10a0c35..e46c4a3 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -38,6 +38,28 @@ static inline bool virtio_crypto_in_mux_mode(VirtIODevice *vdev) return virtio_vdev_has_feature(vdev, VIRTIO_CRYPTO_F_MUX_MODE); } +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 != VIRTIO_CRYPTO_FLAG_SESSION_MODE); + default: + break; + } + + return false; +} + static int virtio_crypto_cipher_session_helper(VirtIODevice *vdev, CryptoDevBackendSymSessionInfo *info, @@ -370,9 +392,10 @@ static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq, static void virtio_crypto_free_request(VirtIOCryptoReq *req) { + size_t max_len; + if (req) { if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { - size_t max_len; CryptoDevBackendSymOpInfo *op_info = req->u.sym_op_info; max_len = op_info->iv_len + @@ -384,6 +407,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 == CRYPTODEV_BACKEND_ALG_SYM_STATELESS) { + CryptoDevBackendSymStatelessInfo *sym_stateless_info; + + sym_stateless_info = req->u.sym_stateless_info; + max_len = 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); } @@ -431,6 +469,9 @@ static void virtio_crypto_req_complete(VirtIOCryptoReq *req, uint8_t status) if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { virtio_crypto_sym_input_data_helper(vdev, req, status, req->u.sym_op_info); + } else if (req->flags == 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); @@ -605,6 +646,221 @@ virtio_crypto_handle_sym_req(VirtIOCrypto *vcrypto, } 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 = VIRTIO_DEVICE(vcrypto); + CryptoDevBackendSymStatelessInfo *sym_stateless_info; + + uint32_t op_type; + uint32_t src_len = 0, dst_len = 0; + uint32_t iv_len = 0; + uint32_t aad_len = 0, hash_result_len = 0; + uint32_t hash_start_src_offset = 0, len_to_hash = 0; + uint32_t cipher_start_src_offset = 0, len_to_cipher = 0; + uint32_t key_len = 0, auth_key_len = 0; + + uint64_t max_len, curr_size = 0; + size_t s; + + op_type = ldl_le_p(&req->op_type); + + if (op_type == VIRTIO_CRYPTO_SYM_OP_CIPHER) { + key_len = ldl_le_p(&req->u.cipher.para.sess_para.keylen); + iv_len = ldl_le_p(&req->u.cipher.para.iv_len); + src_len = ldl_le_p(&req->u.cipher.para.src_data_len); + dst_len = ldl_le_p(&req->u.cipher.para.dst_data_len); + } else if (op_type == VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) { + key_len = ldl_le_p(&req->u.chain.para.sess_para.cipher.keylen); + auth_key_len = + ldl_le_p(&req->u.chain.para.sess_para.hash.auth_key_len); + iv_len = ldl_le_p(&req->u.chain.para.iv_len); + src_len = ldl_le_p(&req->u.chain.para.src_data_len); + dst_len = ldl_le_p(&req->u.chain.para.dst_data_len); + + aad_len = ldl_le_p(&req->u.chain.para.aad_len); + hash_result_len = ldl_le_p(&req->u.chain.para.hash_result_len); + hash_start_src_offset = ldl_le_p( + &req->u.chain.para.hash_start_src_offset); + cipher_start_src_offset = ldl_le_p( + &req->u.chain.para.cipher_start_src_offset); + len_to_cipher = ldl_le_p(&req->u.chain.para.len_to_cipher); + len_to_hash = 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 = (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 = + g_malloc0(sizeof(CryptoDevBackendSymStatelessInfo) + max_len); + sym_stateless_info->session_info.key_len = key_len; + sym_stateless_info->session_info.auth_key_len = auth_key_len; + sym_stateless_info->op_info.iv_len = iv_len; + sym_stateless_info->op_info.src_len = src_len; + sym_stateless_info->op_info.dst_len = dst_len; + sym_stateless_info->op_info.aad_len = aad_len; + sym_stateless_info->op_info.digest_result_len = hash_result_len; + sym_stateless_info->op_info.hash_start_src_offset = + hash_start_src_offset; + sym_stateless_info->op_info.len_to_hash = len_to_hash; + sym_stateless_info->op_info.cipher_start_src_offset = + cipher_start_src_offset; + sym_stateless_info->op_info.len_to_cipher = len_to_cipher; + + sym_stateless_info->session_info.op_type = + sym_stateless_info->op_info.op_type = op_type; + if (op_type == VIRTIO_CRYPTO_SYM_OP_CIPHER) { + sym_stateless_info->session_info.cipher_alg = + ldl_le_p(&req->u.cipher.para.sess_para.algo); + sym_stateless_info->session_info.direction = + ldl_le_p(&req->u.cipher.para.sess_para.op); + } else { /* It must be algorithm chain here */ + sym_stateless_info->session_info.cipher_alg = + ldl_le_p(&req->u.chain.para.sess_para.cipher.algo); + sym_stateless_info->session_info.direction = + ldl_le_p(&req->u.chain.para.sess_para.cipher.op); + sym_stateless_info->session_info.hash_alg = + ldl_le_p(&req->u.chain.para.sess_para.hash.algo); + sym_stateless_info->session_info.hash_mode = + ldl_le_p(&req->u.chain.para.sess_para.hash.hash_mode); + sym_stateless_info->session_info.alg_chain_order = + ldl_le_p(&req->u.chain.para.sess_para.alg_chain_order); + } + + DPRINTF("cipher_alg=%" PRIu32 ", info->direction=%" 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_result + */ + if (key_len > 0) { + DPRINTF("key_len=%" PRIu32 "\n", key_len); + sym_stateless_info->session_info.cipher_key = + sym_stateless_info->op_info.data + curr_size; + + s = iov_to_buf(iov, out_num, 0, + sym_stateless_info->session_info.cipher_key, key_len); + if (unlikely(s != key_len)) { + virtio_error(vdev, "virtio-crypto cipher key incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, key_len); + curr_size += key_len; + } + if (auth_key_len > 0) { + DPRINTF("auth_key_len=%" PRIu32 "\n", auth_key_len); + sym_stateless_info->session_info.auth_key = + sym_stateless_info->op_info.data + curr_size; + + s = iov_to_buf(iov, out_num, 0, + sym_stateless_info->session_info.auth_key, auth_key_len); + if (unlikely(s != auth_key_len)) { + virtio_error(vdev, "virtio-crypto auth key incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, auth_key_len); + curr_size += auth_key_len; + } + if (iv_len > 0) { + DPRINTF("iv_len=%" PRIu32 "\n", iv_len); + sym_stateless_info->op_info.iv = + sym_stateless_info->op_info.data + curr_size; + + s = iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.iv, iv_len); + if (unlikely(s != iv_len)) { + virtio_error(vdev, "virtio-crypto iv incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, iv_len); + curr_size += iv_len; + } + + /* Handle additional authentication data if exists */ + if (aad_len > 0) { + DPRINTF("aad_len=%" PRIu32 "\n", aad_len); + sym_stateless_info->op_info.aad_data = + sym_stateless_info->op_info.data + curr_size; + + s = iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.aad_data, aad_len); + if (unlikely(s != aad_len)) { + virtio_error(vdev, "virtio-crypto additional auth data incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, aad_len); + + curr_size += aad_len; + } + /* Handle the source data */ + if (src_len > 0) { + DPRINTF("src_len=%" PRIu32 "\n", src_len); + sym_stateless_info->op_info.src = + sym_stateless_info->op_info.data + curr_size; + + s = iov_to_buf(iov, out_num, 0, + sym_stateless_info->op_info.src, src_len); + if (unlikely(s != src_len)) { + virtio_error(vdev, "virtio-crypto source data incorrect"); + goto err; + } + iov_discard_front(&iov, &out_num, src_len); + + curr_size += src_len; + } + + /* Handle the destination data */ + sym_stateless_info->op_info.dst = + sym_stateless_info->op_info.data + curr_size; + curr_size += dst_len; + + DPRINTF("dst_len=%" PRIu32 "\n", dst_len); + + /* Handle the hash digest result */ + if (hash_result_len > 0) { + DPRINTF("hash_result_len=%" PRIu32 "\n", hash_result_len); + sym_stateless_info->op_info.digest_result = + sym_stateless_info->op_info.data + curr_size; + } + + *stateless_info = sym_stateless_info; + + return 0; + +err: + g_free(sym_stateless_info); + return -EFAULT; +} + +static int virtio_crypto_handle_request(VirtIOCryptoReq *request) { VirtIOCrypto *vcrypto = request->vcrypto; @@ -620,7 +876,10 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) uint32_t opcode; uint8_t status = VIRTIO_CRYPTO_ERR; uint64_t session_id; - CryptoDevBackendSymOpInfo *sym_op_info = NULL; + union { + CryptoDevBackendSymOpInfo *sym_op_info; + CryptoDevBackendSymStatelessInfo *stateless_info; + } info; Error *local_err = NULL; size_t s; @@ -663,27 +922,41 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) opcode = ldl_le_p(&hdr.opcode); session_id = ldq_le_p(&hdr.session_id); -#define data_req_payload_size(vdev, req) \ - (virtio_crypto_in_mux_mode((vdev)) ? sizeof((req)) : \ +#define data_req_payload_size(vdev, base) \ + (virtio_crypto_in_mux_mode((vdev)) ? (base) : \ VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX) switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: { - struct virtio_crypto_sym_data_req req; - - iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)); + bool is_stateless; + size_t base; + union { + struct virtio_crypto_sym_data_req req; + struct virtio_crypto_sym_data_req_stateless stateless_req; + } u_req; + + is_stateless = virtio_crypto_stateless_req(vdev, opcode, hdr.flag); + base = is_stateless ? sizeof(u_req.stateless_req) : sizeof(u_req.req); + iov_to_buf(out_iov, out_num, 0, &u_req, base); /* The unused part of the req will be ingored */ - s = data_req_payload_size(vdev, req); + s = data_req_payload_size(vdev, base); if (unlikely(s != iov_discard_front(&out_iov, &out_num, s))) { virtio_error(vdev, "virtio-crypto request additional " "parameters too short"); return -1; } - ret = virtio_crypto_handle_sym_req(vcrypto, &req, - &sym_op_info, - out_iov, out_num); + if (is_stateless) { + ret = virtio_crypto_handle_sym_stateless_req(vcrypto, + &u_req.stateless_req, + &info.stateless_info, + out_iov, out_num); + } else { + ret = virtio_crypto_handle_sym_req(vcrypto, &u_req.req, + &info.sym_op_info, + out_iov, out_num); + } /* Serious errors, need to reset virtio crypto device */ if (ret == -EFAULT) { return -1; @@ -691,11 +964,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 = session_id; + if (is_stateless) { + info.stateless_info->op_info.op_code = opcode; + request->flags = CRYPTODEV_BACKEND_ALG_SYM_STATELESS; + request->u.sym_stateless_info = info.stateless_info; + } else { + info.sym_op_info->op_code = opcode; + session_id = ldq_le_p(&hdr.session_id); + info.sym_op_info->session_id = session_id; + /* Set request's parameter */ + request->flags = CRYPTODEV_BACKEND_ALG_SYM; + request->u.sym_op_info = info.sym_op_info; + } - /* Set request's parameter */ - request->flags = CRYPTODEV_BACKEND_ALG_SYM; - request->u.sym_op_info = sym_op_info; ret = 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/standard-headers/linux/virtio_crypto.h index 81357e5..285914d 100644 --- a/include/standard-headers/linux/virtio_crypto.h +++ b/include/standard-headers/linux/virtio_crypto.h @@ -260,6 +260,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; @@ -381,6 +382,166 @@ struct virtio_crypto_aead_data_req { #define VIRTIO_CRYPTO_DATA_REQ_PAYLOAD_SIZE_NONMUX 48 +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]; +}; + #define VIRTIO_CRYPTO_OK 0 #define VIRTIO_CRYPTO_ERR 1 #define VIRTIO_CRYPTO_BADMSG 2 diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index aa2fcd8..9f83082 100644 --- 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; From patchwork Mon Nov 6 06:57:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk3f5MFnz9s7p for ; Mon, 6 Nov 2017 18:00:46 +1100 (AEDT) Received: from localhost ([::1]:46719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbOm-0008T4-Rx for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:00:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLa-0006Gl-FL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLX-0008Hz-Qz for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2331) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLW-0008Aw-Tf for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:23 -0500 Received: from 172.30.72.60 (EHLO DGGEMS405-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32703; Mon, 06 Nov 2017 14:57:20 +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.361.1; Mon, 6 Nov 2017 14:57:09 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:57:00 +0800 Message-ID: <1509951422-20060-9-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020204.5A0007D0.003E, 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: a03920536339c00fbfbb4c212d9e5256 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 08/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 6df23b9..ba6d15c 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -152,73 +152,56 @@ err: return -1; } -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 != VIRTIO_CRYPTO_SYM_OP_CIPHER) { - error_setg(errp, "Unsupported optype :%u", sess_info->op_type); - return -1; - } - - index = 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 = QCRYPTO_CIPHER_MODE_ECB; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_ECB; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CBC: - mode = QCRYPTO_CIPHER_MODE_CBC; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_CBC; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CTR: - mode = QCRYPTO_CIPHER_MODE_CTR; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_CTR; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_XTS: - mode = QCRYPTO_CIPHER_MODE_XTS; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_XTS; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_3DES_ECB: - mode = QCRYPTO_CIPHER_MODE_ECB; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_ECB; + *algo = QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CBC: - mode = QCRYPTO_CIPHER_MODE_CBC; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_CBC; + *algo = QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CTR: - mode = QCRYPTO_CIPHER_MODE_CTR; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_CTR; + *algo = 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; } + 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 != VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported optype :%u", sess_info->op_type); + return -1; + } + + index = 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 = cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -1; + } + cipher = qcrypto_cipher_new(algo, mode, sess_info->cipher_key, sess_info->key_len, From patchwork Mon Nov 6 06:57:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk9L4JMSz9s7p for ; Mon, 6 Nov 2017 18:05:42 +1100 (AEDT) Received: from localhost ([::1]:46746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbTY-00042f-LB for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:05:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLl-0006Pl-UV for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLh-0000C2-9e for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:38 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2278) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLg-00005R-NP for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:33 -0500 Received: from 172.30.72.58 (EHLO DGGEMS403-HUB.china.huawei.com) ([172.30.72.58]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKL32654; Mon, 06 Nov 2017 14:57:30 +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.361.1; Mon, 6 Nov 2017 14:57:10 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:57:01 +0800 Message-ID: <1509951422-20060-10-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020206.5A0007DA.004C, 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: bd7140c685ac2a2fc51860b79a8d464f 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 09/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 ba6d15c..e0737e0 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -335,6 +335,13 @@ static int cryptodev_builtin_sym_operation( return -VIRTIO_CRYPTO_NOTSUPP; } + if (op_info->op_code != VIRTIO_CRYPTO_CIPHER_ENCRYPT && + op_info->op_code != VIRTIO_CRYPTO_CIPHER_DECRYPT) { + error_setg(errp, + "Unsupported op code: %u", op_info->op_code); + return -VIRTIO_CRYPTO_NOTSUPP; + } + sess = builtin->sessions[op_info->session_id]; if (op_info->iv_len > 0) { @@ -389,6 +396,84 @@ static void cryptodev_builtin_cleanup( cryptodev_backend_set_ready(backend, false); } +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 = NULL; + + sess_info = &op_info->session_info; + sym_op_info = &op_info->op_info; + + if (sess_info->op_type != 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 = cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -VIRTIO_CRYPTO_NOTSUPP; + } + + cipher = 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 = qcrypto_cipher_setiv(cipher, sym_op_info->iv, + sym_op_info->iv_len, errp); + if (ret < 0) { + ret = -VIRTIO_CRYPTO_ERR; + goto out; + } + } + + if (sess_info->direction == VIRTIO_CRYPTO_OP_ENCRYPT) { + ret = qcrypto_cipher_encrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret = -VIRTIO_CRYPTO_ERR; + goto out; + } + } else { + ret = qcrypto_cipher_decrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret = -VIRTIO_CRYPTO_ERR; + goto out; + } + } + break; + + default: + error_setg(errp, "Unsupported op_code: %" PRIu32 "", + sym_op_info->op_code); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + ret = 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 *data) bc->create_session = cryptodev_builtin_sym_create_session; bc->close_session = cryptodev_builtin_sym_close_session; bc->do_sym_op = cryptodev_builtin_sym_operation; + bc->do_sym_stateless_op = cryptodev_builtin_sym_stateless_operation; } static const TypeInfo cryptodev_builtin_info = { From patchwork Mon Nov 6 06:57:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834483 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVk3k5S9Nz9s7p for ; Mon, 6 Nov 2017 18:00:50 +1100 (AEDT) Received: from localhost ([::1]:46722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbOq-000058-QP for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 02:00:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLa-0006Gj-6y for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLV-0008F3-Ii for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2328) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLV-00088Z-0B for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:21 -0500 Received: from 172.30.72.58 (EHLO DGGEMS406-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32699; Mon, 06 Nov 2017 14:57:18 +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.361.1; Mon, 6 Nov 2017 14:57:10 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:57:02 +0800 Message-ID: <1509951422-20060-11-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020201.5A0007CE.0097, 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: 0028352d428785b848405f97456a9424 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 10/10] 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: wangxinxin.wang@huawei.com, weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 e46c4a3..8f27a86 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1069,6 +1069,11 @@ static uint64_t virtio_crypto_get_features(VirtIODevice *vdev, uint64_t features, Error **errp) { + VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); + + /* Firstly sync all virtio-crypto possible supported features */ + features |= vcrypto->host_features; + return features; } @@ -1184,6 +1189,16 @@ static const VMStateDescription vmstate_virtio_crypto = { }; static Property virtio_crypto_properties[] = { + 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-crypto.h index 465ad20..30ea51d 100644 --- 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; #endif /* _QEMU_VIRTIO_CRYPTO_H */