From nobody Sun May 10 20:32:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 294B5C433EF for ; Sun, 24 Apr 2022 10:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239124AbiDXKsy (ORCPT ); Sun, 24 Apr 2022 06:48:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239046AbiDXKsm (ORCPT ); Sun, 24 Apr 2022 06:48:42 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC701A804 for ; Sun, 24 Apr 2022 03:45:40 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id z30so4330508pfw.6 for ; Sun, 24 Apr 2022 03:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wZYZZokAYbHkoKNpRYcwId0oz7EL0chjkDT9m64Fs88=; b=qN5AP1svMW7jIvuJ8Q5CJy6NrbX2K1Z1BSUZqSJm1WocHUzV1dNZqEBQ8x1zC8uTMt 2bIQhcnbS2AM92sqVj8/TQlCGC78fWde3/PiB1bY+r0gFs79ttYzhvBWeHEhbHHfIk9B BGirz+cY5s3VM6t+cJBAv28vupLecDbTh8AQRHN9fSnNHqKL/mUTNl/JqOv1i50NTP2u 3NReAkarqGfyKgiIQO36228zgcIjlaVCBmWFkCGibz4Q+iHiTDsqGr8JTGBR1q9cTLN/ qQb4z2EYFJb5xSNsUNRKgzUFPa5V2iTtMqoQC6zvbJBtlvogn8aWHEPUdWdzQJZq1LzJ yRtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wZYZZokAYbHkoKNpRYcwId0oz7EL0chjkDT9m64Fs88=; b=l+33pehW+qnM+37FpD3oD331PoTL1Dz0pbT3g2QsWrE2xHWc6yKmCO7M4jrJj8tRHR H+KyWJV1OhlPcfIq2W1Qd42JfamWOzMsG8mw9gGHPeBERIYw/wAuUZLR9dR9gNz2z33c zOy/tJxV1392ltvwYmh6X3eZOpAsSSzsTtrHFf/3oJIl5KinZE+tnc10w4Vv0QHmahwo falkty4xsmofyxNRLLpMlwJxESTGvn7DeB2n1KMDTcBM9vRIgzpO9Tw8OA5lsGwEOi7g 4wcpgFqDF1rdUpSaly40jLgA7OD5XNpyq+V/2P5cZfXOZlOydUZc3Ge9XbdbMnBelyXw CqUQ== X-Gm-Message-State: AOAM533tfy1ZwY0TXSi4zy2fD31bLW6gJNI/LcLOHIerTs23wrvC7ER1 szQ341w6pCMFUmw3RlUZgeoy9A== X-Google-Smtp-Source: ABdhPJybb5u79Rbo4xWJV/NXrG26SqZ6A85hpfGQ2sn65t8mv0Y5qVs6QIf2X45l1qDo7jjS18pPqA== X-Received: by 2002:a05:6a00:1816:b0:50c:7c7b:c06 with SMTP id y22-20020a056a00181600b0050c7c7b0c06mr13728675pfa.49.1650797140411; Sun, 24 Apr 2022 03:45:40 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm8287295pfi.86.2022.04.24.03.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 03:45:39 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-crypto@vger.kernel.org, helei.sig11@bytedance.com, davem@davemloft.net, zhenwei pi Subject: [PATCH v4 1/5] virtio-crypto: change code style Date: Sun, 24 Apr 2022 18:41:36 +0800 Message-Id: <20220424104140.44841-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220424104140.44841-1-pizhenwei@bytedance.com> References: <20220424104140.44841-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use temporary variable to make code easy to read and maintain. /* Pad cipher's parameters */ vcrypto->ctrl.u.sym_create_session.op_type =3D cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER); vcrypto->ctrl.u.sym_create_session.u.cipher.para.algo =3D vcrypto->ctrl.header.algo; vcrypto->ctrl.u.sym_create_session.u.cipher.para.keylen =3D cpu_to_le32(keylen); vcrypto->ctrl.u.sym_create_session.u.cipher.para.op =3D cpu_to_le32(op); --> sym_create_session =3D &ctrl->u.sym_create_session; sym_create_session->op_type =3D cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER); sym_create_session->u.cipher.para.algo =3D ctrl->header.algo; sym_create_session->u.cipher.para.keylen =3D cpu_to_le32(keylen); sym_create_session->u.cipher.para.op =3D cpu_to_le32(op); The new style shows more obviously: - the variable we want to operate. - an assignment statement in a single line. Cc: Michael S. Tsirkin Cc: Jason Wang Cc: Gonglei Signed-off-by: zhenwei pi --- .../virtio/virtio_crypto_akcipher_algs.c | 40 ++++++----- .../virtio/virtio_crypto_skcipher_algs.c | 72 +++++++++---------- 2 files changed, 59 insertions(+), 53 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_akcipher_algs.c index f3ec9420215e..20901a263fc8 100644 --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c @@ -106,23 +106,27 @@ static int virtio_crypto_alg_akcipher_init_session(st= ruct virtio_crypto_akcipher unsigned int inlen; int err; unsigned int num_out =3D 0, num_in =3D 0; + struct virtio_crypto_op_ctrl_req *ctrl; + struct virtio_crypto_session_input *input; =20 pkey =3D kmemdup(key, keylen, GFP_ATOMIC); if (!pkey) return -ENOMEM; =20 spin_lock(&vcrypto->ctrl_lock); - memcpy(&vcrypto->ctrl.header, header, sizeof(vcrypto->ctrl.header)); - memcpy(&vcrypto->ctrl.u, para, sizeof(vcrypto->ctrl.u)); - vcrypto->input.status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); + ctrl =3D &vcrypto->ctrl; + memcpy(&ctrl->header, header, sizeof(ctrl->header)); + memcpy(&ctrl->u, para, sizeof(ctrl->u)); + input =3D &vcrypto->input; + input->status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); =20 - sg_init_one(&outhdr_sg, &vcrypto->ctrl, sizeof(vcrypto->ctrl)); + sg_init_one(&outhdr_sg, ctrl, sizeof(*ctrl)); sgs[num_out++] =3D &outhdr_sg; =20 sg_init_one(&key_sg, pkey, keylen); sgs[num_out++] =3D &key_sg; =20 - sg_init_one(&inhdr_sg, &vcrypto->input, sizeof(vcrypto->input)); + sg_init_one(&inhdr_sg, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); @@ -134,12 +138,12 @@ static int virtio_crypto_alg_akcipher_init_session(st= ruct virtio_crypto_akcipher !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); =20 - if (le32_to_cpu(vcrypto->input.status) !=3D VIRTIO_CRYPTO_OK) { + if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; goto out; } =20 - ctx->session_id =3D le64_to_cpu(vcrypto->input.session_id); + ctx->session_id =3D le64_to_cpu(input->session_id); ctx->session_valid =3D true; err =3D 0; =20 @@ -149,7 +153,7 @@ static int virtio_crypto_alg_akcipher_init_session(stru= ct virtio_crypto_akcipher =20 if (err < 0) pr_err("virtio_crypto: Create session failed status: %u\n", - le32_to_cpu(vcrypto->input.status)); + le32_to_cpu(input->status)); =20 return err; } @@ -161,23 +165,27 @@ static int virtio_crypto_alg_akcipher_close_session(s= truct virtio_crypto_akciphe struct virtio_crypto *vcrypto =3D ctx->vcrypto; unsigned int num_out =3D 0, num_in =3D 0, inlen; int err; + struct virtio_crypto_op_ctrl_req *ctrl; + struct virtio_crypto_inhdr *ctrl_status; =20 spin_lock(&vcrypto->ctrl_lock); if (!ctx->session_valid) { err =3D 0; goto out; } - vcrypto->ctrl_status.status =3D VIRTIO_CRYPTO_ERR; - vcrypto->ctrl.header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_DESTRO= Y_SESSION); - vcrypto->ctrl.header.queue_id =3D 0; + ctrl_status =3D &vcrypto->ctrl_status; + ctrl_status->status =3D VIRTIO_CRYPTO_ERR; + ctrl =3D &vcrypto->ctrl; + ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSIO= N); + ctrl->header.queue_id =3D 0; =20 - destroy_session =3D &vcrypto->ctrl.u.destroy_session; + destroy_session =3D &ctrl->u.destroy_session; destroy_session->session_id =3D cpu_to_le64(ctx->session_id); =20 - sg_init_one(&outhdr_sg, &vcrypto->ctrl, sizeof(vcrypto->ctrl)); + sg_init_one(&outhdr_sg, ctrl, sizeof(*ctrl)); sgs[num_out++] =3D &outhdr_sg; =20 - sg_init_one(&inhdr_sg, &vcrypto->ctrl_status.status, sizeof(vcrypto->ctrl= _status.status)); + sg_init_one(&inhdr_sg, &ctrl_status->status, sizeof(ctrl_status->status)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); @@ -189,7 +197,7 @@ static int virtio_crypto_alg_akcipher_close_session(str= uct virtio_crypto_akciphe !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); =20 - if (vcrypto->ctrl_status.status !=3D VIRTIO_CRYPTO_OK) { + if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; goto out; } @@ -201,7 +209,7 @@ static int virtio_crypto_alg_akcipher_close_session(str= uct virtio_crypto_akciphe spin_unlock(&vcrypto->ctrl_lock); if (err < 0) { pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%l= lx\n", - vcrypto->ctrl_status.status, destroy_session->session_id); + ctrl_status->status, destroy_session->session_id); } =20 return err; diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_skcipher_algs.c index a618c46a52b8..e3c5bc8d6112 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -123,6 +123,9 @@ static int virtio_crypto_alg_skcipher_init_session( int op =3D encrypt ? VIRTIO_CRYPTO_OP_ENCRYPT : VIRTIO_CRYPTO_OP_DECRYPT; int err; unsigned int num_out =3D 0, num_in =3D 0; + struct virtio_crypto_op_ctrl_req *ctrl; + struct virtio_crypto_session_input *input; + struct virtio_crypto_sym_create_session_req *sym_create_session; =20 /* * Avoid to do DMA from the stack, switch to using @@ -135,24 +138,22 @@ static int virtio_crypto_alg_skcipher_init_session( =20 spin_lock(&vcrypto->ctrl_lock); /* Pad ctrl header */ - vcrypto->ctrl.header.opcode =3D - cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION); - vcrypto->ctrl.header.algo =3D cpu_to_le32(alg); + ctrl =3D &vcrypto->ctrl; + ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION); + ctrl->header.algo =3D cpu_to_le32(alg); /* Set the default dataqueue id to 0 */ - vcrypto->ctrl.header.queue_id =3D 0; + ctrl->header.queue_id =3D 0; =20 - vcrypto->input.status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); + input =3D &vcrypto->input; + input->status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); /* Pad cipher's parameters */ - vcrypto->ctrl.u.sym_create_session.op_type =3D - cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER); - vcrypto->ctrl.u.sym_create_session.u.cipher.para.algo =3D - vcrypto->ctrl.header.algo; - vcrypto->ctrl.u.sym_create_session.u.cipher.para.keylen =3D - cpu_to_le32(keylen); - vcrypto->ctrl.u.sym_create_session.u.cipher.para.op =3D - cpu_to_le32(op); - - sg_init_one(&outhdr, &vcrypto->ctrl, sizeof(vcrypto->ctrl)); + sym_create_session =3D &ctrl->u.sym_create_session; + sym_create_session->op_type =3D cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER); + sym_create_session->u.cipher.para.algo =3D ctrl->header.algo; + sym_create_session->u.cipher.para.keylen =3D cpu_to_le32(keylen); + sym_create_session->u.cipher.para.op =3D cpu_to_le32(op); + + sg_init_one(&outhdr, ctrl, sizeof(*ctrl)); sgs[num_out++] =3D &outhdr; =20 /* Set key */ @@ -160,7 +161,7 @@ static int virtio_crypto_alg_skcipher_init_session( sgs[num_out++] =3D &key_sg; =20 /* Return status and session id back */ - sg_init_one(&inhdr, &vcrypto->input, sizeof(vcrypto->input)); + sg_init_one(&inhdr, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr; =20 err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, @@ -180,20 +181,18 @@ static int virtio_crypto_alg_skcipher_init_session( !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); =20 - if (le32_to_cpu(vcrypto->input.status) !=3D VIRTIO_CRYPTO_OK) { + if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { spin_unlock(&vcrypto->ctrl_lock); pr_err("virtio_crypto: Create session failed status: %u\n", - le32_to_cpu(vcrypto->input.status)); + le32_to_cpu(input->status)); kfree_sensitive(cipher_key); return -EINVAL; } =20 if (encrypt) - ctx->enc_sess_info.session_id =3D - le64_to_cpu(vcrypto->input.session_id); + ctx->enc_sess_info.session_id =3D le64_to_cpu(input->session_id); else - ctx->dec_sess_info.session_id =3D - le64_to_cpu(vcrypto->input.session_id); + ctx->dec_sess_info.session_id =3D le64_to_cpu(input->session_id); =20 spin_unlock(&vcrypto->ctrl_lock); =20 @@ -211,30 +210,30 @@ static int virtio_crypto_alg_skcipher_close_session( struct virtio_crypto *vcrypto =3D ctx->vcrypto; int err; unsigned int num_out =3D 0, num_in =3D 0; + struct virtio_crypto_op_ctrl_req *ctrl; + struct virtio_crypto_inhdr *ctrl_status; =20 spin_lock(&vcrypto->ctrl_lock); - vcrypto->ctrl_status.status =3D VIRTIO_CRYPTO_ERR; + ctrl_status =3D &vcrypto->ctrl_status; + ctrl_status->status =3D VIRTIO_CRYPTO_ERR; /* Pad ctrl header */ - vcrypto->ctrl.header.opcode =3D - cpu_to_le32(VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION); + ctrl =3D &vcrypto->ctrl; + ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION); /* Set the default virtqueue id to 0 */ - vcrypto->ctrl.header.queue_id =3D 0; + ctrl->header.queue_id =3D 0; =20 - destroy_session =3D &vcrypto->ctrl.u.destroy_session; + destroy_session =3D &ctrl->u.destroy_session; =20 if (encrypt) - destroy_session->session_id =3D - cpu_to_le64(ctx->enc_sess_info.session_id); + destroy_session->session_id =3D cpu_to_le64(ctx->enc_sess_info.session_i= d); else - destroy_session->session_id =3D - cpu_to_le64(ctx->dec_sess_info.session_id); + destroy_session->session_id =3D cpu_to_le64(ctx->dec_sess_info.session_i= d); =20 - sg_init_one(&outhdr, &vcrypto->ctrl, sizeof(vcrypto->ctrl)); + sg_init_one(&outhdr, ctrl, sizeof(*ctrl)); sgs[num_out++] =3D &outhdr; =20 /* Return status and session id back */ - sg_init_one(&status_sg, &vcrypto->ctrl_status.status, - sizeof(vcrypto->ctrl_status.status)); + sg_init_one(&status_sg, &ctrl_status->status, sizeof(ctrl_status->status)= ); sgs[num_out + num_in++] =3D &status_sg; =20 err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, @@ -249,11 +248,10 @@ static int virtio_crypto_alg_skcipher_close_session( !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); =20 - if (vcrypto->ctrl_status.status !=3D VIRTIO_CRYPTO_OK) { + if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { spin_unlock(&vcrypto->ctrl_lock); pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%l= lx\n", - vcrypto->ctrl_status.status, - destroy_session->session_id); + ctrl_status->status, destroy_session->session_id); =20 return -EINVAL; } --=20 2.20.1 From nobody Sun May 10 20:32:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 506CCC433F5 for ; Sun, 24 Apr 2022 10:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239138AbiDXKtI (ORCPT ); Sun, 24 Apr 2022 06:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239105AbiDXKsq (ORCPT ); Sun, 24 Apr 2022 06:48:46 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FE1420BF3 for ; Sun, 24 Apr 2022 03:45:45 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id c12so20786888plr.6 for ; Sun, 24 Apr 2022 03:45:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UsAhpE+ugC3O5yltAsuOPgGj88elpiVZxkM4bSAZJVI=; b=CDPq45Eju4Udy1f/3D6Pgk+8kUjQzM6KhnVJojoEE5FKwex4nZ5L1UM9DRHQVoYGYF V7xtY5T+QZVO+YvYHKTxY2zcvwss27qoqS5V9nsCNnquT1esJgZnhFmiwonfvbYxoUZP V/SoodAVkcVl5VDO0OJ9yrrptHf4FhPQpvuJ8WPAmkStC768aCPo4vea48xuHq1BORd4 c/5/juNv1kQi2bYn3wDOsGhWjbObWk62EvPI1ObTs/PdsMAKc2cr8sVzvMjQCtF8+3g0 iCLheoLG9y/4CjdVFr1UEsGLT+o0+0kbXkMGo/eCSZkTBpQqSYX5nHj/XwsCdcpSJs3N qSYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UsAhpE+ugC3O5yltAsuOPgGj88elpiVZxkM4bSAZJVI=; b=47yr/KENu8Kbd9DZo4P37iYvWInQHVekU1GgNIdBj35yL9qXnXgLOBusdRY+ShRe2H R6aDdEfdOm572Vn9q12Dn/vL9vyCEOI1zZOXxnotIssOPAZH/YHKUBLXEeBhB1vsI1Dt QdPAaBdd3/XBYNl7RbBg4PNrczVmx4VxhCkLySbb//i/+fEMG2lNWA6vPWEKfiZ9P2yp fKj1Ym/0YFzMyAITzEvWBItv8qosUkdvUUHyYYKU5xrfjL4wUHSLxivPZmcr9nnhE11u sSRiy4D5r9Kv3a8Umm8+r+JsHy+7xa1LlWeYVPBWy0SGE748uq6adxJmVSuETFVFSyu3 UClw== X-Gm-Message-State: AOAM530j7wg9syjM3HExnTSFKMh+ODMmLPRbXbJUYSud720T6QVxsXq7 BAH49A4p2iNyIrIk4ZYzZ3qwDA== X-Google-Smtp-Source: ABdhPJy43fQlBPZDmMQtOyeaXbRgcCetLjUR1wmMWKTV8ELw8Mm1SFDDvLrIoITjZT4S9T1VAij4LQ== X-Received: by 2002:a17:90a:a82:b0:1c9:ef95:486 with SMTP id 2-20020a17090a0a8200b001c9ef950486mr25677254pjw.93.1650797145068; Sun, 24 Apr 2022 03:45:45 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm8287295pfi.86.2022.04.24.03.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 03:45:44 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-crypto@vger.kernel.org, helei.sig11@bytedance.com, davem@davemloft.net, zhenwei pi Subject: [PATCH v4 2/5] virtio-crypto: use private buffer for control request Date: Sun, 24 Apr 2022 18:41:37 +0800 Message-Id: <20220424104140.44841-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220424104140.44841-1-pizhenwei@bytedance.com> References: <20220424104140.44841-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Originally, all of the control requests share a single buffer( ctrl & input & ctrl_status fields in struct virtio_crypto), this allows queue depth 1 only, the performance of control queue gets limited by this design. In this patch, each request allocates request buffer dynamically, and free buffer after request, so the scope protected by ctrl_lock also get optimized here. It's possible to optimize control queue depth in the next step. A necessary comment is already in code, still describe it again: /* * Note: there are padding fields in request, clear them to zero before * sending to host to avoid to divulge any information. * Ex, virtio_crypto_ctrl_request::ctrl::u::destroy_session::padding[48] */ So use kzalloc to allocate buffer of struct virtio_crypto_ctrl_request. Cc: Michael S. Tsirkin Cc: Jason Wang Cc: Gonglei Signed-off-by: zhenwei pi Reported-by: Dan Carpenter Reported-by: kernel test robot --- .../virtio/virtio_crypto_akcipher_algs.c | 41 +++++++++++---- drivers/crypto/virtio/virtio_crypto_common.h | 17 +++++-- .../virtio/virtio_crypto_skcipher_algs.c | 50 ++++++++++++------- 3 files changed, 75 insertions(+), 33 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_akcipher_algs.c index 20901a263fc8..509884e8b201 100644 --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c @@ -108,16 +108,22 @@ static int virtio_crypto_alg_akcipher_init_session(st= ruct virtio_crypto_akcipher unsigned int num_out =3D 0, num_in =3D 0; struct virtio_crypto_op_ctrl_req *ctrl; struct virtio_crypto_session_input *input; + struct virtio_crypto_ctrl_request *vc_ctrl_req; =20 pkey =3D kmemdup(key, keylen, GFP_ATOMIC); if (!pkey) return -ENOMEM; =20 - spin_lock(&vcrypto->ctrl_lock); - ctrl =3D &vcrypto->ctrl; + vc_ctrl_req =3D kzalloc(sizeof(*vc_ctrl_req), GFP_KERNEL); + if (!vc_ctrl_req) { + err =3D -ENOMEM; + goto out; + } + + ctrl =3D &vc_ctrl_req->ctrl; memcpy(&ctrl->header, header, sizeof(ctrl->header)); memcpy(&ctrl->u, para, sizeof(ctrl->u)); - input =3D &vcrypto->input; + input =3D &vc_ctrl_req->input; input->status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); =20 sg_init_one(&outhdr_sg, ctrl, sizeof(*ctrl)); @@ -129,14 +135,18 @@ static int virtio_crypto_alg_akcipher_init_session(st= ruct virtio_crypto_akcipher sg_init_one(&inhdr_sg, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 + spin_lock(&vcrypto->ctrl_lock); err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); - if (err < 0) + if (err < 0) { + spin_unlock(&vcrypto->ctrl_lock); goto out; + } =20 virtqueue_kick(vcrypto->ctrl_vq); while (!virtqueue_get_buf(vcrypto->ctrl_vq, &inlen) && !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); + spin_unlock(&vcrypto->ctrl_lock); =20 if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; @@ -148,7 +158,7 @@ static int virtio_crypto_alg_akcipher_init_session(stru= ct virtio_crypto_akcipher err =3D 0; =20 out: - spin_unlock(&vcrypto->ctrl_lock); + kfree(vc_ctrl_req); kfree_sensitive(pkey); =20 if (err < 0) @@ -167,15 +177,22 @@ static int virtio_crypto_alg_akcipher_close_session(s= truct virtio_crypto_akciphe int err; struct virtio_crypto_op_ctrl_req *ctrl; struct virtio_crypto_inhdr *ctrl_status; + struct virtio_crypto_ctrl_request *vc_ctrl_req; =20 - spin_lock(&vcrypto->ctrl_lock); if (!ctx->session_valid) { err =3D 0; goto out; } - ctrl_status =3D &vcrypto->ctrl_status; + + vc_ctrl_req =3D kzalloc(sizeof(*vc_ctrl_req), GFP_KERNEL); + if (!vc_ctrl_req) { + err =3D -ENOMEM; + goto out; + } + + ctrl_status =3D &vc_ctrl_req->ctrl_status; ctrl_status->status =3D VIRTIO_CRYPTO_ERR; - ctrl =3D &vcrypto->ctrl; + ctrl =3D &vc_ctrl_req->ctrl; ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSIO= N); ctrl->header.queue_id =3D 0; =20 @@ -188,14 +205,18 @@ static int virtio_crypto_alg_akcipher_close_session(s= truct virtio_crypto_akciphe sg_init_one(&inhdr_sg, &ctrl_status->status, sizeof(ctrl_status->status)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 + spin_lock(&vcrypto->ctrl_lock); err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); - if (err < 0) + if (err < 0) { + spin_unlock(&vcrypto->ctrl_lock); goto out; + } =20 virtqueue_kick(vcrypto->ctrl_vq); while (!virtqueue_get_buf(vcrypto->ctrl_vq, &inlen) && !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); + spin_unlock(&vcrypto->ctrl_lock); =20 if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; @@ -206,7 +227,7 @@ static int virtio_crypto_alg_akcipher_close_session(str= uct virtio_crypto_akciphe ctx->session_valid =3D false; =20 out: - spin_unlock(&vcrypto->ctrl_lock); + kfree(vc_ctrl_req); if (err < 0) { pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%l= lx\n", ctrl_status->status, destroy_session->session_id); diff --git a/drivers/crypto/virtio/virtio_crypto_common.h b/drivers/crypto/= virtio/virtio_crypto_common.h index e693d4ee83a6..2422237ec4e6 100644 --- a/drivers/crypto/virtio/virtio_crypto_common.h +++ b/drivers/crypto/virtio/virtio_crypto_common.h @@ -13,6 +13,7 @@ #include #include #include +#include =20 =20 /* Internal representation of a data virtqueue */ @@ -65,11 +66,6 @@ struct virtio_crypto { /* Maximum size of per request */ u64 max_size; =20 - /* Control VQ buffers: protected by the ctrl_lock */ - struct virtio_crypto_op_ctrl_req ctrl; - struct virtio_crypto_session_input input; - struct virtio_crypto_inhdr ctrl_status; - unsigned long status; atomic_t ref_count; struct list_head list; @@ -85,6 +81,17 @@ struct virtio_crypto_sym_session_info { __u64 session_id; }; =20 +/* + * Note: there are padding fields in request, clear them to zero before + * sending to host to avoid to divulge any information. + * Ex, virtio_crypto_ctrl_request::ctrl::u::destroy_session::padding[48] + */ +struct virtio_crypto_ctrl_request { + struct virtio_crypto_op_ctrl_req ctrl; + struct virtio_crypto_session_input input; + struct virtio_crypto_inhdr ctrl_status; +}; + struct virtio_crypto_request; typedef void (*virtio_crypto_data_callback) (struct virtio_crypto_request *vc_req, int len); diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_skcipher_algs.c index e3c5bc8d6112..6aaf0869b211 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -126,6 +126,7 @@ static int virtio_crypto_alg_skcipher_init_session( struct virtio_crypto_op_ctrl_req *ctrl; struct virtio_crypto_session_input *input; struct virtio_crypto_sym_create_session_req *sym_create_session; + struct virtio_crypto_ctrl_request *vc_ctrl_req; =20 /* * Avoid to do DMA from the stack, switch to using @@ -136,15 +137,20 @@ static int virtio_crypto_alg_skcipher_init_session( if (!cipher_key) return -ENOMEM; =20 - spin_lock(&vcrypto->ctrl_lock); + vc_ctrl_req =3D kzalloc(sizeof(*vc_ctrl_req), GFP_KERNEL); + if (!vc_ctrl_req) { + err =3D -ENOMEM; + goto out; + } + /* Pad ctrl header */ - ctrl =3D &vcrypto->ctrl; + ctrl =3D &vc_ctrl_req->ctrl; ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION); ctrl->header.algo =3D cpu_to_le32(alg); /* Set the default dataqueue id to 0 */ ctrl->header.queue_id =3D 0; =20 - input =3D &vcrypto->input; + input =3D &vc_ctrl_req->input; input->status =3D cpu_to_le32(VIRTIO_CRYPTO_ERR); /* Pad cipher's parameters */ sym_create_session =3D &ctrl->u.sym_create_session; @@ -164,12 +170,12 @@ static int virtio_crypto_alg_skcipher_init_session( sg_init_one(&inhdr, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr; =20 + spin_lock(&vcrypto->ctrl_lock); err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto, GFP_ATOMIC); if (err < 0) { spin_unlock(&vcrypto->ctrl_lock); - kfree_sensitive(cipher_key); - return err; + goto out; } virtqueue_kick(vcrypto->ctrl_vq); =20 @@ -180,13 +186,13 @@ static int virtio_crypto_alg_skcipher_init_session( while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) && !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); + spin_unlock(&vcrypto->ctrl_lock); =20 if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { - spin_unlock(&vcrypto->ctrl_lock); pr_err("virtio_crypto: Create session failed status: %u\n", le32_to_cpu(input->status)); - kfree_sensitive(cipher_key); - return -EINVAL; + err =3D -EINVAL; + goto out; } =20 if (encrypt) @@ -194,10 +200,11 @@ static int virtio_crypto_alg_skcipher_init_session( else ctx->dec_sess_info.session_id =3D le64_to_cpu(input->session_id); =20 - spin_unlock(&vcrypto->ctrl_lock); - + err =3D 0; +out: + kfree(vc_ctrl_req); kfree_sensitive(cipher_key); - return 0; + return err; } =20 static int virtio_crypto_alg_skcipher_close_session( @@ -212,12 +219,16 @@ static int virtio_crypto_alg_skcipher_close_session( unsigned int num_out =3D 0, num_in =3D 0; struct virtio_crypto_op_ctrl_req *ctrl; struct virtio_crypto_inhdr *ctrl_status; + struct virtio_crypto_ctrl_request *vc_ctrl_req; =20 - spin_lock(&vcrypto->ctrl_lock); - ctrl_status =3D &vcrypto->ctrl_status; + vc_ctrl_req =3D kzalloc(sizeof(*vc_ctrl_req), GFP_KERNEL); + if (!vc_ctrl_req) + return -ENOMEM; + + ctrl_status =3D &vc_ctrl_req->ctrl_status; ctrl_status->status =3D VIRTIO_CRYPTO_ERR; /* Pad ctrl header */ - ctrl =3D &vcrypto->ctrl; + ctrl =3D &vc_ctrl_req->ctrl; ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION); /* Set the default virtqueue id to 0 */ ctrl->header.queue_id =3D 0; @@ -236,28 +247,31 @@ static int virtio_crypto_alg_skcipher_close_session( sg_init_one(&status_sg, &ctrl_status->status, sizeof(ctrl_status->status)= ); sgs[num_out + num_in++] =3D &status_sg; =20 + spin_lock(&vcrypto->ctrl_lock); err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto, GFP_ATOMIC); if (err < 0) { spin_unlock(&vcrypto->ctrl_lock); - return err; + goto out; } virtqueue_kick(vcrypto->ctrl_vq); =20 while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) && !virtqueue_is_broken(vcrypto->ctrl_vq)) cpu_relax(); + spin_unlock(&vcrypto->ctrl_lock); =20 if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { - spin_unlock(&vcrypto->ctrl_lock); pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%l= lx\n", ctrl_status->status, destroy_session->session_id); =20 return -EINVAL; } - spin_unlock(&vcrypto->ctrl_lock); =20 - return 0; + err =3D 0; +out: + kfree(vc_ctrl_req); + return err; } =20 static int virtio_crypto_alg_skcipher_init_sessions( --=20 2.20.1 From nobody Sun May 10 20:32:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C866C433EF for ; Sun, 24 Apr 2022 10:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239191AbiDXKtN (ORCPT ); Sun, 24 Apr 2022 06:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239046AbiDXKtC (ORCPT ); Sun, 24 Apr 2022 06:49:02 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17B8B22B04 for ; Sun, 24 Apr 2022 03:45:50 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id u7so5429900plg.13 for ; Sun, 24 Apr 2022 03:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=apUEf+EzBMbf1428+G4F3xeQ1aPIlddSTbIvkpGqC5w=; b=FngY3yqrzabvD/vuacUhlAn1J8NpUUinNeZzIt2T5wCHW3Sy0Kl/Y409vF0FIFNTpi +0YfeS3OYwpHT45QBeS1QieVSkwbA5ObJAhlJEDaOrPDz0J4Kb9oC+aipahZLqKivlPv gmC+Kh0UN8n64HPsLZSJ1b4KJConLmGm/ZveTvYn91MiubkNeua8hmNjC5AFsugCbMqU NdxPNI4HAABL7KoLWYoWp9oPkmKZ3OE9KOC1IYhHUY3JC3ikEq94R3B//HhoVzD7JK7U SkQPoD6yfGJDszULVthoNJgtuvvs1nIjRu7PnCvXl/AxrBCMY4fAUSP1PLkqv8+vDrEF 1OTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=apUEf+EzBMbf1428+G4F3xeQ1aPIlddSTbIvkpGqC5w=; b=bdThP+A5mZi+ahFpEIPTUtHEV0V3qIBnqPuEVRDCUq5gJymk7X2e+9OLhKQn/bdqrc TzJuggnQP5971NVONM5xWJhDnCcA0PM3R33GZ88VhXoSu8X3bsRSmKRsvuAH0WPoHS9Y ouon0PCWG4oR+JKtoFuxNr4ntUvIoGQCe0goGFNm0Ihdtj5rCyLGDCBqFNwkyWOP4NKg 8o52QX0bXwARDkAkPRxQwqk4kiELhwO0S4Q0TvwUEhLeIsfqrRxQdafik8IYOQ8b+gd0 MRvoG5At2rHawH/tOsxWbIZDpjoLRFqhixPfhBi/wunuvIuargWdYq8FQjF63cEOQdkb N79Q== X-Gm-Message-State: AOAM531XrNQQQ81Kwz2vL/d6vkHE0ig3+Oc6SrzvYp6+t8PfyQ9q76wK PDvH6avdZd3e97zyi1GEc7ox0w== X-Google-Smtp-Source: ABdhPJw5tSMenUvXwvNJ2sg0MUqVtoTzn/dzDU3c5kJs4cn50ytjtpzIU9gIGra6dulic/qFQbW2RQ== X-Received: by 2002:a17:902:f787:b0:152:157:eb7 with SMTP id q7-20020a170902f78700b0015201570eb7mr12677644pln.109.1650797149603; Sun, 24 Apr 2022 03:45:49 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm8287295pfi.86.2022.04.24.03.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 03:45:49 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-crypto@vger.kernel.org, helei.sig11@bytedance.com, davem@davemloft.net, zhenwei pi Subject: [PATCH v4 3/5] virtio-crypto: wait ctrl queue instead of busy polling Date: Sun, 24 Apr 2022 18:41:38 +0800 Message-Id: <20220424104140.44841-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220424104140.44841-1-pizhenwei@bytedance.com> References: <20220424104140.44841-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Originally, after submitting request into virtio crypto control queue, the guest side polls the result from the virt queue. This works like following: CPU0 CPU1 ... CPUx CPUy | | | | \ \ / / \--------spin_lock(&vcrypto->ctrl_lock)-------/ | virtqueue add & kick | busy poll virtqueue | spin_unlock(&vcrypto->ctrl_lock) ... There are two problems: 1, The queue depth is always 1, the performance of a virtio crypto device gets limited. Multi user processes share a single control queue, and hit spin lock race from control queue. Test on Intel Platinum 8260, a single worker gets ~35K/s create/close session operations, and 8 workers get ~40K/s operations with 800% CPU utilization. 2, The control request is supposed to get handled immediately, but in the current implementation of QEMU(v6.2), the vCPU thread kicks another thread to do this work, the latency also gets unstable. Tracking latency of virtio_crypto_alg_akcipher_close_session in 5s: usecs : count distribution 0 -> 1 : 0 | | 2 -> 3 : 7 | | 4 -> 7 : 72 | | 8 -> 15 : 186485 |************************| 16 -> 31 : 687 | | 32 -> 63 : 5 | | 64 -> 127 : 3 | | 128 -> 255 : 1 | | 256 -> 511 : 0 | | 512 -> 1023 : 0 | | 1024 -> 2047 : 0 | | 2048 -> 4095 : 0 | | 4096 -> 8191 : 0 | | 8192 -> 16383 : 2 | | This means that a CPU may hold vcrypto->ctrl_lock as long as 8192~16383us. To improve the performance of control queue, a request on control queue waits completion instead of busy polling to reduce lock racing, and gets completed by control queue callback. CPU0 CPU1 ... CPUx CPUy | | | | \ \ / / \--------spin_lock(&vcrypto->ctrl_lock)-------/ | virtqueue add & kick | ---------spin_unlock(&vcrypto->ctrl_lock)------ / / \ \ | | | | wait wait wait wait Test this patch, the guest side get ~200K/s operations with 300% CPU utilization. Cc: Michael S. Tsirkin Cc: Jason Wang Cc: Gonglei Signed-off-by: zhenwei pi --- .../virtio/virtio_crypto_akcipher_algs.c | 29 ++--------- drivers/crypto/virtio/virtio_crypto_common.h | 4 ++ drivers/crypto/virtio/virtio_crypto_core.c | 52 ++++++++++++++++++- .../virtio/virtio_crypto_skcipher_algs.c | 34 ++---------- 4 files changed, 64 insertions(+), 55 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_akcipher_algs.c index 509884e8b201..1e98502830cf 100644 --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c @@ -103,7 +103,6 @@ static int virtio_crypto_alg_akcipher_init_session(stru= ct virtio_crypto_akcipher struct scatterlist outhdr_sg, key_sg, inhdr_sg, *sgs[3]; struct virtio_crypto *vcrypto =3D ctx->vcrypto; uint8_t *pkey; - unsigned int inlen; int err; unsigned int num_out =3D 0, num_in =3D 0; struct virtio_crypto_op_ctrl_req *ctrl; @@ -135,18 +134,9 @@ static int virtio_crypto_alg_akcipher_init_session(str= uct virtio_crypto_akcipher sg_init_one(&inhdr_sg, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 - spin_lock(&vcrypto->ctrl_lock); - err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); - if (err < 0) { - spin_unlock(&vcrypto->ctrl_lock); + err =3D virtio_crypto_ctrl_vq_request(vcrypto, sgs, num_out, num_in, vc_c= trl_req); + if (err < 0) goto out; - } - - virtqueue_kick(vcrypto->ctrl_vq); - while (!virtqueue_get_buf(vcrypto->ctrl_vq, &inlen) && - !virtqueue_is_broken(vcrypto->ctrl_vq)) - cpu_relax(); - spin_unlock(&vcrypto->ctrl_lock); =20 if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; @@ -173,7 +163,7 @@ static int virtio_crypto_alg_akcipher_close_session(str= uct virtio_crypto_akciphe struct scatterlist outhdr_sg, inhdr_sg, *sgs[2]; struct virtio_crypto_destroy_session_req *destroy_session; struct virtio_crypto *vcrypto =3D ctx->vcrypto; - unsigned int num_out =3D 0, num_in =3D 0, inlen; + unsigned int num_out =3D 0, num_in =3D 0; int err; struct virtio_crypto_op_ctrl_req *ctrl; struct virtio_crypto_inhdr *ctrl_status; @@ -205,18 +195,9 @@ static int virtio_crypto_alg_akcipher_close_session(st= ruct virtio_crypto_akciphe sg_init_one(&inhdr_sg, &ctrl_status->status, sizeof(ctrl_status->status)); sgs[num_out + num_in++] =3D &inhdr_sg; =20 - spin_lock(&vcrypto->ctrl_lock); - err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, num_in, vcrypto= , GFP_ATOMIC); - if (err < 0) { - spin_unlock(&vcrypto->ctrl_lock); + err =3D virtio_crypto_ctrl_vq_request(vcrypto, sgs, num_out, num_in, vc_c= trl_req); + if (err < 0) goto out; - } - - virtqueue_kick(vcrypto->ctrl_vq); - while (!virtqueue_get_buf(vcrypto->ctrl_vq, &inlen) && - !virtqueue_is_broken(vcrypto->ctrl_vq)) - cpu_relax(); - spin_unlock(&vcrypto->ctrl_lock); =20 if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { err =3D -EINVAL; diff --git a/drivers/crypto/virtio/virtio_crypto_common.h b/drivers/crypto/= virtio/virtio_crypto_common.h index 2422237ec4e6..59a4c0259456 100644 --- a/drivers/crypto/virtio/virtio_crypto_common.h +++ b/drivers/crypto/virtio/virtio_crypto_common.h @@ -90,6 +90,7 @@ struct virtio_crypto_ctrl_request { struct virtio_crypto_op_ctrl_req ctrl; struct virtio_crypto_session_input input; struct virtio_crypto_inhdr ctrl_status; + struct completion compl; }; =20 struct virtio_crypto_request; @@ -141,5 +142,8 @@ int virtio_crypto_skcipher_algs_register(struct virtio_= crypto *vcrypto); void virtio_crypto_skcipher_algs_unregister(struct virtio_crypto *vcrypto); int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto); void virtio_crypto_akcipher_algs_unregister(struct virtio_crypto *vcrypto); +int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct sc= atterlist *sgs[], + unsigned int out_sgs, unsigned int in_sgs, + struct virtio_crypto_ctrl_request *vc_ctrl_req); =20 #endif /* _VIRTIO_CRYPTO_COMMON_H */ diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/vi= rtio/virtio_crypto_core.c index c6f482db0bc0..60490ffa3df1 100644 --- a/drivers/crypto/virtio/virtio_crypto_core.c +++ b/drivers/crypto/virtio/virtio_crypto_core.c @@ -22,6 +22,56 @@ virtcrypto_clear_request(struct virtio_crypto_request *v= c_req) } } =20 +static void virtio_crypto_ctrlq_callback(struct virtio_crypto_ctrl_request= *vc_ctrl_req) +{ + complete(&vc_ctrl_req->compl); +} + +static void virtcrypto_ctrlq_callback(struct virtqueue *vq) +{ + struct virtio_crypto *vcrypto =3D vq->vdev->priv; + struct virtio_crypto_ctrl_request *vc_ctrl_req; + unsigned long flags; + unsigned int len; + + spin_lock_irqsave(&vcrypto->ctrl_lock, flags); + do { + virtqueue_disable_cb(vq); + while ((vc_ctrl_req =3D virtqueue_get_buf(vq, &len)) !=3D NULL) { + spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags); + virtio_crypto_ctrlq_callback(vc_ctrl_req); + spin_lock_irqsave(&vcrypto->ctrl_lock, flags); + } + if (unlikely(virtqueue_is_broken(vq))) + break; + } while (!virtqueue_enable_cb(vq)); + spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags); +} + +int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct sc= atterlist *sgs[], + unsigned int out_sgs, unsigned int in_sgs, + struct virtio_crypto_ctrl_request *vc_ctrl_req) +{ + int err; + unsigned long flags; + + init_completion(&vc_ctrl_req->compl); + + spin_lock_irqsave(&vcrypto->ctrl_lock, flags); + err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, out_sgs, in_sgs, vc_ctrl= _req, GFP_ATOMIC); + if (err < 0) { + spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags); + return err; + } + + virtqueue_kick(vcrypto->ctrl_vq); + spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags); + + wait_for_completion(&vc_ctrl_req->compl); + + return 0; +} + static void virtcrypto_dataq_callback(struct virtqueue *vq) { struct virtio_crypto *vcrypto =3D vq->vdev->priv; @@ -73,7 +123,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi) goto err_names; =20 /* Parameters for control virtqueue */ - callbacks[total_vqs - 1] =3D NULL; + callbacks[total_vqs - 1] =3D virtcrypto_ctrlq_callback; names[total_vqs - 1] =3D "controlq"; =20 /* Allocate/initialize parameters for data virtqueues */ diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_skcipher_algs.c index 6aaf0869b211..e553ccadbcbc 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -118,7 +118,6 @@ static int virtio_crypto_alg_skcipher_init_session( int encrypt) { struct scatterlist outhdr, key_sg, inhdr, *sgs[3]; - unsigned int tmp; struct virtio_crypto *vcrypto =3D ctx->vcrypto; int op =3D encrypt ? VIRTIO_CRYPTO_OP_ENCRYPT : VIRTIO_CRYPTO_OP_DECRYPT; int err; @@ -170,23 +169,9 @@ static int virtio_crypto_alg_skcipher_init_session( sg_init_one(&inhdr, input, sizeof(*input)); sgs[num_out + num_in++] =3D &inhdr; =20 - spin_lock(&vcrypto->ctrl_lock); - err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, - num_in, vcrypto, GFP_ATOMIC); - if (err < 0) { - spin_unlock(&vcrypto->ctrl_lock); + err =3D virtio_crypto_ctrl_vq_request(vcrypto, sgs, num_out, num_in, vc_c= trl_req); + if (err < 0) goto out; - } - virtqueue_kick(vcrypto->ctrl_vq); - - /* - * Trapping into the hypervisor, so the request should be - * handled immediately. - */ - while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) && - !virtqueue_is_broken(vcrypto->ctrl_vq)) - cpu_relax(); - spin_unlock(&vcrypto->ctrl_lock); =20 if (le32_to_cpu(input->status) !=3D VIRTIO_CRYPTO_OK) { pr_err("virtio_crypto: Create session failed status: %u\n", @@ -212,7 +197,6 @@ static int virtio_crypto_alg_skcipher_close_session( int encrypt) { struct scatterlist outhdr, status_sg, *sgs[2]; - unsigned int tmp; struct virtio_crypto_destroy_session_req *destroy_session; struct virtio_crypto *vcrypto =3D ctx->vcrypto; int err; @@ -247,19 +231,9 @@ static int virtio_crypto_alg_skcipher_close_session( sg_init_one(&status_sg, &ctrl_status->status, sizeof(ctrl_status->status)= ); sgs[num_out + num_in++] =3D &status_sg; =20 - spin_lock(&vcrypto->ctrl_lock); - err =3D virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, num_out, - num_in, vcrypto, GFP_ATOMIC); - if (err < 0) { - spin_unlock(&vcrypto->ctrl_lock); + err =3D virtio_crypto_ctrl_vq_request(vcrypto, sgs, num_out, num_in, vc_c= trl_req); + if (err < 0) goto out; - } - virtqueue_kick(vcrypto->ctrl_vq); - - while (!virtqueue_get_buf(vcrypto->ctrl_vq, &tmp) && - !virtqueue_is_broken(vcrypto->ctrl_vq)) - cpu_relax(); - spin_unlock(&vcrypto->ctrl_lock); =20 if (ctrl_status->status !=3D VIRTIO_CRYPTO_OK) { pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%l= lx\n", --=20 2.20.1 From nobody Sun May 10 20:32:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B058C433F5 for ; Sun, 24 Apr 2022 10:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239024AbiDXKtX (ORCPT ); Sun, 24 Apr 2022 06:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239146AbiDXKtC (ORCPT ); Sun, 24 Apr 2022 06:49:02 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42C0220F9 for ; Sun, 24 Apr 2022 03:45:54 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id q12so11033294pgj.13 for ; Sun, 24 Apr 2022 03:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=px4I+RzeTWMMtdZKLYUD3e7jp1xURuzvNJsO7o4S7ms=; b=FGf98dBpvjagNdKAx1gz/khVHlDbxcMtXIymcpOlEQTvZ7bDLmKT4Am04RCOVey8Vt ieGah75ezFTyLKCImJc/u1A+PEJXMcGbrz5onNQN0C9vxShlPewcKN/5Ryd1YXtSvtIa NbsMhtvFrK6Pb855hBBaau4Z+Pwtyom6hj4VMqBa7wWsKrEEc4mw+ACkPzUoN5nGN8aR HIG/MNh++NR7fj1uegbKiu5GlAsttsouG6C0RMx8eb9QqW6Zm3lFD010+iPRoOIkDRZZ v8LTF+Q1IkD4In2BRjHr/E3Kqm1MOKQiJTTwbuuwjoBldmWmgQMOYfVCoWcTvPyzq/Bo vvrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=px4I+RzeTWMMtdZKLYUD3e7jp1xURuzvNJsO7o4S7ms=; b=nATEgBZayiixyaSlFMkXzCxTDDOmFBdIk/TbyoSSW2mGPaaT0PDW397MCUK0bFcMeO wH72Krc++69JOPDPG1BTdvL3KYtvPfSU+Po5osFSffKjgOk+NBdKqyXsu9S7Gh602CUi ZMYpsNb7S2cKsjwzH0jeEPNL7aKarp8K8vmo7Oe662T/b7964EEjucrXrGIxjpTYON5v K2G+kXY5kbZ8T5fNzcr5zoH9lELFQyOum1HCLahzME9dj2lnprYHvua/HGuSMf+Qx8s5 LgVoJ9yhzztLjZOLCTZRcHUqslSuy/b+xiDY2NeaUnCjl1kwRyCzR0R/Lw6YnyViiO5m QVlQ== X-Gm-Message-State: AOAM532S+5m1aZ9xMQ+uAVGZZwjsvnfbuDsJw/68Iga2bIDF5fuxen/T L03PgfrkCJVCLg541OARouEpHA== X-Google-Smtp-Source: ABdhPJwJx/jeBsrcyfzqw3BwOB5hWkRSrCnP2UooawE0svZYmbsKlXo42bKGvoqpZSZOVMWjI3ks0w== X-Received: by 2002:aa7:9041:0:b0:4fe:3d6c:1739 with SMTP id n1-20020aa79041000000b004fe3d6c1739mr13689501pfo.13.1650797154126; Sun, 24 Apr 2022 03:45:54 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm8287295pfi.86.2022.04.24.03.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 03:45:53 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-crypto@vger.kernel.org, helei.sig11@bytedance.com, davem@davemloft.net, zhenwei pi Subject: [PATCH v4 4/5] virtio-crypto: adjust dst_len at ops callback Date: Sun, 24 Apr 2022 18:41:39 +0800 Message-Id: <20220424104140.44841-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220424104140.44841-1-pizhenwei@bytedance.com> References: <20220424104140.44841-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he For some akcipher operations(eg, decryption of pkcs1pad(rsa)), the length of returned result maybe less than akcipher_req->dst_len, we need to recalculate the actual dst_len through the virt-queue protocol. Cc: Michael S. Tsirkin Cc: Jason Wang Cc: Gonglei Signed-off-by: lei he Signed-off-by: zhenwei pi --- drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_akcipher_algs.c index 1e98502830cf..1892901d2a71 100644 --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c @@ -90,9 +90,12 @@ static void virtio_crypto_dataq_akcipher_callback(struct= virtio_crypto_request * } =20 akcipher_req =3D vc_akcipher_req->akcipher_req; - if (vc_akcipher_req->opcode !=3D VIRTIO_CRYPTO_AKCIPHER_VERIFY) + if (vc_akcipher_req->opcode !=3D VIRTIO_CRYPTO_AKCIPHER_VERIFY) { + /* actuall length maybe less than dst buffer */ + akcipher_req->dst_len =3D len - sizeof(vc_req->status); sg_copy_from_buffer(akcipher_req->dst, sg_nents(akcipher_req->dst), vc_akcipher_req->dst_buf, akcipher_req->dst_len); + } virtio_crypto_akcipher_finalize_req(vc_akcipher_req, akcipher_req, error); } =20 --=20 2.20.1 From nobody Sun May 10 20:32:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEA5EC433F5 for ; Sun, 24 Apr 2022 10:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239215AbiDXKtd (ORCPT ); Sun, 24 Apr 2022 06:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239132AbiDXKtE (ORCPT ); Sun, 24 Apr 2022 06:49:04 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3973B252B9 for ; Sun, 24 Apr 2022 03:45:59 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id s14so20774167plk.8 for ; Sun, 24 Apr 2022 03:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bhiM3AjN7OQUvaBDZQVzT5dsdkup6eI4sw9Fv5sP5tE=; b=voSfwnuz4TazDsGKnkLUa3eLXrQvuZd0CeBraJuFrBeSJjuo6ZZnyyZ6IVf0DMCxDd 2jO3l101hWUMVw6fE6Q1scUwdoY55AfZrU59fgoeCmBV8NoDnheH2xHW9oOuLNYc32kS /Myz9unOyMQgMJYiLy50IfLa0wWwZPsTpzo+uY0oEcuxNFo+Xee80to77j8yDZ+BPT4y djGTubGoqSCw75gGJq5Xax5kSqm3psqt0E8BbnH2vId9AoT513Tt6AWKyFwJ+/iitQWt z87pqXiqtAqnUt/3mHP9bu0yoOsQRF02y/h4nYScuC/sgGnvBrK48Z2KddBDQnrw0ALc uUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bhiM3AjN7OQUvaBDZQVzT5dsdkup6eI4sw9Fv5sP5tE=; b=w+THnmUIJf68FsjKSnac/T8HOtBBRHwuPUV3cRsv+T4jRtaGColaR6+3IjCZRo1wNX ugq+KDONhvgEpW8etFnDsmgG6ORjrvT5litbhqFaoM9UVGj0X4NlUu7wY/Lb4h1nHocd iXlrPUDtSRlcFRJA6DSV7TTa8J//L6BM7sKfTdRkbLX+t6pH5EjZZ+ioTm8oil4aFKeU XTqMfDChT472nop+dSdn9LnDjay0SvDZM0tUCVEVtKrEZuM0zBIJM0MXw4i8eMIdHgOE 52L5+gKxz7gc1D9z+sMk4NuVn7RID9e3nOD4pVeyMd1y5AHqpMLxcckjTh23mdkMCQvB EFAg== X-Gm-Message-State: AOAM531fDfQ7MITFmNKdd15lnuGWO8BkwcLOfeOXHoxxmI6We0dg2sVN NDvKPM48AR6DFWSKWkp4wLRx/g== X-Google-Smtp-Source: ABdhPJxsLxoBTSXLJ8lKEHWxix35/c4WKDc8Lc+R21OTU1ppRMOI/MHE4yD26NyDYhl3/dU3YYeX9Q== X-Received: by 2002:a17:902:7296:b0:14b:4bc6:e81 with SMTP id d22-20020a170902729600b0014b4bc60e81mr12832804pll.132.1650797158606; Sun, 24 Apr 2022 03:45:58 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm8287295pfi.86.2022.04.24.03.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 03:45:58 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, jasowang@redhat.com Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-crypto@vger.kernel.org, helei.sig11@bytedance.com, davem@davemloft.net, zhenwei pi Subject: [PATCH v4 5/5] virtio-crypto: enable retry for virtio-crypto-dev Date: Sun, 24 Apr 2022 18:41:40 +0800 Message-Id: <20220424104140.44841-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220424104140.44841-1-pizhenwei@bytedance.com> References: <20220424104140.44841-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he Enable retry for virtio-crypto-dev, so that crypto-engine can process cipher-requests parallelly. Cc: Michael S. Tsirkin Cc: Jason Wang Cc: Gonglei Signed-off-by: lei he Signed-off-by: zhenwei pi --- drivers/crypto/virtio/virtio_crypto_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/vi= rtio/virtio_crypto_core.c index 60490ffa3df1..f67e0d4c1b0c 100644 --- a/drivers/crypto/virtio/virtio_crypto_core.c +++ b/drivers/crypto/virtio/virtio_crypto_core.c @@ -144,7 +144,8 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi) spin_lock_init(&vi->data_vq[i].lock); vi->data_vq[i].vq =3D vqs[i]; /* Initialize crypto engine */ - vi->data_vq[i].engine =3D crypto_engine_alloc_init(dev, 1); + vi->data_vq[i].engine =3D crypto_engine_alloc_init_and_set(dev, true, NU= LL, 1, + virtqueue_get_vring_size(vqs[i])); if (!vi->data_vq[i].engine) { ret =3D -ENOMEM; goto err_engine; --=20 2.20.1