From patchwork Tue Sep 13 03:52:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9328341 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 230226048F for ; Tue, 13 Sep 2016 04:00:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1187029051 for ; Tue, 13 Sep 2016 04:00:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01EC42908A; Tue, 13 Sep 2016 04:00:53 +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 72D8229051 for ; Tue, 13 Sep 2016 04:00:53 +0000 (UTC) Received: from localhost ([::1]:46341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjetw-0003Gj-6p for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 00:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjepp-0000Ov-4N for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjepl-0003yx-6q for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:37 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:56043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjepi-0003x5-NM for qemu-devel@nongnu.org; Mon, 12 Sep 2016 23:56:33 -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 CHR85144; Tue, 13 Sep 2016 11:53:02 +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; Tue, 13 Sep 2016 11:52:54 +0800 From: Gonglei To: , Date: Tue, 13 Sep 2016 11:52:18 +0800 Message-ID: <1473738741-220600-13-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1473738741-220600-1-git-send-email-arei.gonglei@huawei.com> References: <1473738741-220600-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.0A020202.57D7781F.0037, 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: cba27fb601ce5764e008f26447a1622e 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 v2 12/15] 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: claudio.fontana@huawei.com, mst@redhat.com, xin.zeng@intel.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, agraf@suse.de, nmorey@kalray.eu, mike.caraman@nxp.com, Gonglei , stefanha@redhat.com, pbonzini@redhat.com, vincent.jardin@6wind.com, weidong.huang@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Gonglei --- hw/virtio/virtio-crypto.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 1090946..0d7ab63 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -146,6 +146,32 @@ 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) +{ + int ret; + CryptoClientState *cc = vcrypto->crypto->ccs; + uint64_t session_id; + uint32_t status; + int queue_index = virtio_crypto_vq2q(queue_id); + + session_id = 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 */ + close_sess_req->status = status; +} + static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); @@ -185,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);