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)" X-Patchwork-Id: 10042713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1035760247 for ; Mon, 6 Nov 2017 07:46:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 010B5297A4 for ; Mon, 6 Nov 2017 07:46:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E99E4297AF; Mon, 6 Nov 2017 07:46:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66E42297A4 for ; Mon, 6 Nov 2017 07:46:39 +0000 (UTC) Received: from localhost ([::1]:46843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBc7C-0004is-Mn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Nov 2017 02:46:38 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 {