From patchwork Thu Sep 8 03:42:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9320363 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 B6E4A6077F for ; Thu, 8 Sep 2016 03:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A264629556 for ; Thu, 8 Sep 2016 03:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9715329558; Thu, 8 Sep 2016 03:49:22 +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 E1A9429556 for ; Thu, 8 Sep 2016 03:49:21 +0000 (UTC) Received: from localhost ([::1]:44765 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqL2-0006Yc-DV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Sep 2016 23:49:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqIm-0004oP-2b for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:47:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhqIh-00069u-Sn for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:46:59 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:10785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhqIh-00069E-0Y for qemu-devel@nongnu.org; Wed, 07 Sep 2016 23:46:55 -0400 Received: from 172.24.1.137 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.137]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQT21245; Thu, 08 Sep 2016 11:43:09 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Sep 2016 11:43:03 +0800 From: Gonglei To: , Date: Thu, 8 Sep 2016 11:42:35 +0800 Message-ID: <1473306156-176628-14-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.57D0DE4F.0135, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 08290acb9e3155d54ed80615e4be435a X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH v1 13/14] virtio-crypto: get correct input data address for each request 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We MUST use the original hva for input data, but not the copyed address, otherwise the guest can't get the results. Fix a non-initial problem in an exception case as well. Signed-off-by: Gonglei --- hw/virtio/virtio-crypto.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 0888725..55ce330 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -62,7 +62,8 @@ static int64_t virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto, struct virtio_crypto_sym_create_session_req *sess_req, uint32_t queue_id, - uint64_t *session_id) + uint64_t *session_id, + VirtQueueElement *elem) { VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); CryptoSymSessionInfo info; @@ -74,6 +75,8 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto, void *auth_key_hva; struct virtio_crypto_session_input *input; hwaddr len; + size_t input_offset; + struct iovec *iov = elem->in_sg; op_type = virtio_ldl_p(vdev, &sess_req->op_type); info.op_type = op_type; @@ -82,13 +85,20 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto, virtio_crypto_cipher_session_helper(vdev, &info, &sess_req->u.cipher.para, &sess_req->u.cipher.out); - input = &sess_req->u.cipher.input; + /* calculate the offset of input data */ + input_offset = offsetof(struct virtio_crypto_op_ctrl_req, + u.sym_create_session.u.cipher.input); + input = (void *)iov[0].iov_base + input_offset; } else if (op_type == VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) { /* cipher part */ virtio_crypto_cipher_session_helper(vdev, &info, &sess_req->u.chain.para.cipher_param, &sess_req->u.chain.out.cipher); - input = &sess_req->u.chain.input; + /* calculate the offset of input data */ + input_offset = offsetof(struct virtio_crypto_op_ctrl_req, + u.sym_create_session.u.chain.input); + input = (void *)iov[0].iov_base + input_offset; + /* hash part */ info.alg_chain_order = virtio_ldl_p(vdev, &sess_req->u.chain.para.alg_chain_order); @@ -124,6 +134,10 @@ virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto, goto err; } } else { + /* calculate the offset of input data */ + input_offset = offsetof(struct virtio_crypto_op_ctrl_req, + u.sym_create_session.u.cipher.input); + input = (void *)iov[0].iov_base + input_offset; /* VIRTIO_CRYPTO_SYM_OP_NONE */ error_report("unsupported cipher type"); goto err; @@ -148,7 +162,8 @@ err: static void virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto, struct virtio_crypto_destroy_session_req *close_sess_req, - uint32_t queue_id) + uint32_t queue_id, + VirtQueueElement *elem) { VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); int ret; @@ -156,6 +171,9 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto, uint64_t session_id; uint32_t status; int queue_index = virtio_crypto_vq2q(queue_id); + struct iovec *iov = elem->in_sg; + size_t status_offset; + void *in_status_ptr; session_id = virtio_ldq_p(vdev, &close_sess_req->session_id); DPRINTF("close session, id=%" PRIu64 "\n", session_id); @@ -168,8 +186,13 @@ virtio_crypto_handle_close_session(VirtIOCrypto *vcrypto, status = VIRTIO_CRYPTO_OP_ERR; } + /* calculate the offset of status bits */ + status_offset = offsetof(struct virtio_crypto_op_ctrl_req, + u.destroy_session.status); + in_status_ptr = (void *)iov[0].iov_base + status_offset; + /* Set the result, notify the frontend driver soon */ - virtio_stl_p(vdev, &close_sess_req->status, status); + virtio_stl_p(vdev, in_status_ptr, status); } static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) @@ -197,6 +220,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) iov_cnt = elem->in_num; iov = elem->in_sg; + s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); assert(s == sizeof(ctrl)); opcode = virtio_ldl_p(vdev, &ctrl.header.opcode); @@ -207,7 +231,8 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) virtio_crypto_create_sym_session(vcrypto, &ctrl.u.sym_create_session, queue_id, - &session_id); + &session_id, + elem); break; case VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION: @@ -215,7 +240,8 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) case VIRTIO_CRYPTO_MAC_DESTROY_SESSION: case VIRTIO_CRYPTO_AEAD_DESTROY_SESSION: virtio_crypto_handle_close_session(vcrypto, - &ctrl.u.destroy_session, queue_id); + &ctrl.u.destroy_session, queue_id, + elem); break; case VIRTIO_CRYPTO_HASH_CREATE_SESSION: case VIRTIO_CRYPTO_MAC_CREATE_SESSION: