From patchwork Thu Sep 8 03:42:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 667235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3sV5v16zqYz9s3v for ; Thu, 8 Sep 2016 13:49:49 +1000 (AEST) Received: from localhost ([::1]:44768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqLS-0007XQ-Uy for incoming@patchwork.ozlabs.org; Wed, 07 Sep 2016 23:49:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqFd-00024h-FC for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhqFa-0005VB-Aa for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:45 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:5665) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqFZ-0005Us-MC for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:43:42 -0400 Received: from 172.24.1.36 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CHM27391; Thu, 08 Sep 2016 11:43:11 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Sep 2016 11:43:02 +0800 From: Gonglei To: , Date: Thu, 8 Sep 2016 11:42:34 +0800 Message-ID: <1473306156-176628-13-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1473306156-176628-1-git-send-email-arei.gonglei@huawei.com> References: <1473306156-176628-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.57D0DE50.0066, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d2b5ebab9aca4bbda7296878172b04df X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [PATCH v1 12/14] virtio-crypto: add destroy session logic 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, john.griffin@intel.com, jianjay.zhou@huawei.com, Varun.Sethi@freescale.com, denglingli@chinamobile.com, hanweidong@huawei.com, agraf@suse.de, Gonglei , nmorey@kalray.eu, vincent.jardin@6wind.com, Ola.Liljedahl@arm.com, luonengjun@huawei.com, xin.zeng@intel.com, peter.huangpeng@huawei.com, liang.j.ma@intel.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, Jani.Kokkonen@huawei.com, brian.a.keating@intel.com, claudio.fontana@huawei.com, mike.caraman@nxp.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Gonglei --- hw/virtio/virtio-crypto.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index b3ad974..0888725 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -145,6 +145,33 @@ err: return -1; } +static void +virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto, + struct virtio_crypto_destroy_session_req *close_sess_req, + uint32_t queue_id) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); + int ret; + CryptoClientState *cc = vcrypto->crypto->ccs; + uint64_t session_id; + uint32_t status; + int queue_index = virtio_crypto_vq2q(queue_id); + + session_id = virtio_ldq_p(vdev, &close_sess_req->session_id); + DPRINTF("close session, id=%" PRIu64 "\n", session_id); + cc = qemu_get_crypto_subqueue(vcrypto->crypto, queue_index); + ret = qemu_crypto_close_session(cc, session_id); + if (ret == 0) { + status = VIRTIO_CRYPTO_OP_OK; + } else { + error_report("destroy session failed"); + status = VIRTIO_CRYPTO_OP_ERR; + } + + /* Set the result, notify the frontend driver soon */ + virtio_stl_p(vdev, &close_sess_req->status, status); +} + static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); @@ -184,12 +211,15 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) break; case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION: - case VIRTIO_CRYPTO_HASH_CREATE_SESSION: case VIRTIO_CRYPTO_HASH_DESTROY_SESSION: - case VIRTIO_CRYPTO_MAC_CREATE_SESSION: case VIRTIO_CRYPTO_MAC_DESTROY_SESSION: - case VIRTIO_CRYPTO_AEAD_CREATE_SESSION: case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION: + virtio_crypto_handle_close_session(vcrypto, + &ctrl.u.destroy_session, queue_id); + break; + case VIRTIO_CRYPTO_HASH_CREATE_SESSION: + case VIRTIO_CRYPTO_MAC_CREATE_SESSION: + case VIRTIO_CRYPTO_AEAD_CREATE_SESSION: default: error_report("virtio-crypto unsupported ctrl opcode: %u", opcode);