From patchwork Mon Apr 18 09:00:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 12816415 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 762C1C433EF for ; Mon, 18 Apr 2022 09:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbiDRJHV (ORCPT ); Mon, 18 Apr 2022 05:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237402AbiDRJHU (ORCPT ); Mon, 18 Apr 2022 05:07:20 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E5313F29 for ; Mon, 18 Apr 2022 02:04:39 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id b7so2216642plh.2 for ; Mon, 18 Apr 2022 02:04:39 -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=t/X33EVipdTkyOBkLhSrJ+Mg2HbAbb6q5VYpCkTBi/E=; b=P39Vpj74J1EUV1LZWKg7ijX1J7sLbeV4w1bJO63YJrnaC80C2vbK4KNvwEqhKecXkg pbTRgxKyapfmMDY2+Zl4VukLGABNVoCzDwkTugB1BU2SLJZ94zI5OFGJMVZ6XG0toF7b SsqdNp43PWEjmcVyDp1gHOToKJ2UCxYEJnBNwqJFI45n9MbOMgOdXOHldN2qz0FOjCHA U8fYoNxJD96RdFkUiSPKsKhJEgC3iYbCr3Eup0YT4UrkcR+OtXeRHbPjNBj7irixqjp6 fSEKPRV76xqpGIUj4MjzshPeMbhp2eyTNPYjwGnI39Px3wVe4miL1d/vZjhvWqepGTsR IufA== 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=t/X33EVipdTkyOBkLhSrJ+Mg2HbAbb6q5VYpCkTBi/E=; b=wtAFS4Bn/D7pAJPfgyQvUfm+o0TE/4TZFpmWERv1j8s8eOjILerAYXj8G+VJZ+pN8m n/xBVCc/gaVERaBOt9VYFrWCjNmu9hxhnp2s20q/mujUAy46VIxJvsztkIN5mzk7VId8 1ht7uc8ghREFmI1qLSLI3UkN5O1QbgHj4VfhK3HpJM2pBrHr7caMXKgaba1kpXEMEhyM +VOmAAyMN35CeP95PGdWwbBuKNqc8PYX0Gv7gE8r3wIJF9PQFKGjP2mGmlagxPls7VgA S0MkkKKJnVbgcoSRahZMg7QaTZu/lh77BW1JZYXtUbXFIP2Q6xBX25UbrMgEbMfuReFO RyZQ== X-Gm-Message-State: AOAM532E3XpPmhI0gQ/wxfFUs8sYzyfh1lzrSiL7zuHvNnp19KbtQhXt gfvmayDasEjUgzgfDMuW7TXBOA== X-Google-Smtp-Source: ABdhPJxBF6Kvfmj7zAWFA5qnv4v0KI+bJQ1IuDkiWEMFez7bDk10Hxz6uXKToPPEJyvyPwKi1x2fzQ== X-Received: by 2002:a17:902:b410:b0:158:faef:79b0 with SMTP id x16-20020a170902b41000b00158faef79b0mr4310497plr.40.1650272678930; Mon, 18 Apr 2022 02:04:38 -0700 (PDT) Received: from always-x1.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id m21-20020a17090a7f9500b001c97c6bcaf4sm16408071pjl.39.2022.04.18.02.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 02:04:38 -0700 (PDT) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com Cc: jasowang@redhat.com, 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 v2 2/4] virtio-crypto: move helpers into virtio_crypto_common.c Date: Mon, 18 Apr 2022 17:00:49 +0800 Message-Id: <20220418090051.372803-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220418090051.372803-1-pizhenwei@bytedance.com> References: <20220418090051.372803-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Move virtcrypto_clear_request and virtcrypto_dataq_callback into virtio_crypto_common.c to make code clear. Then the xx_core.c supports: - probe/remove/irq affinity seting for a virtio device - basic virtio related operations xx_common.c supports: - common helpers/functions for algos Signed-off-by: zhenwei pi --- drivers/crypto/virtio/virtio_crypto_common.c | 31 +++++++++++++++++++ drivers/crypto/virtio/virtio_crypto_common.h | 2 ++ drivers/crypto/virtio/virtio_crypto_core.c | 32 -------------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_common.c b/drivers/crypto/virtio/virtio_crypto_common.c index 93df73c40dd3..4a23524896fe 100644 --- a/drivers/crypto/virtio/virtio_crypto_common.c +++ b/drivers/crypto/virtio/virtio_crypto_common.c @@ -8,6 +8,14 @@ #include "virtio_crypto_common.h" +void virtcrypto_clear_request(struct virtio_crypto_request *vc_req) +{ + if (vc_req) { + kfree_sensitive(vc_req->req_data); + kfree(vc_req->sgs); + } +} + static void virtio_crypto_ctrlq_callback(struct virtio_crypto_ctrl_request *vc_ctrl_req) { complete(&vc_ctrl_req->compl); @@ -59,3 +67,26 @@ void virtcrypto_ctrlq_callback(struct virtqueue *vq) } while (!virtqueue_enable_cb(vq)); spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags); } + +void virtcrypto_dataq_callback(struct virtqueue *vq) +{ + struct virtio_crypto *vcrypto = vq->vdev->priv; + struct virtio_crypto_request *vc_req; + unsigned long flags; + unsigned int len; + unsigned int qid = vq->index; + + spin_lock_irqsave(&vcrypto->data_vq[qid].lock, flags); + do { + virtqueue_disable_cb(vq); + while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) { + spin_unlock_irqrestore( + &vcrypto->data_vq[qid].lock, flags); + if (vc_req->alg_cb) + vc_req->alg_cb(vc_req, len); + spin_lock_irqsave( + &vcrypto->data_vq[qid].lock, flags); + } + } while (!virtqueue_enable_cb(vq)); + spin_unlock_irqrestore(&vcrypto->data_vq[qid].lock, flags); +} diff --git a/drivers/crypto/virtio/virtio_crypto_common.h b/drivers/crypto/virtio/virtio_crypto_common.h index b90ac0ce30d2..b33c0d4423eb 100644 --- a/drivers/crypto/virtio/virtio_crypto_common.h +++ b/drivers/crypto/virtio/virtio_crypto_common.h @@ -150,4 +150,6 @@ int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct scatterl unsigned int out_sgs, unsigned int in_sgs, struct virtio_crypto_ctrl_request *vc_ctrl_req); +void virtcrypto_dataq_callback(struct virtqueue *vq); + #endif /* _VIRTIO_CRYPTO_COMMON_H */ diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c index e668d4b1bc6a..d8edefcb966c 100644 --- a/drivers/crypto/virtio/virtio_crypto_core.c +++ b/drivers/crypto/virtio/virtio_crypto_core.c @@ -13,38 +13,6 @@ #include "virtio_crypto_common.h" -void -virtcrypto_clear_request(struct virtio_crypto_request *vc_req) -{ - if (vc_req) { - kfree_sensitive(vc_req->req_data); - kfree(vc_req->sgs); - } -} - -static void virtcrypto_dataq_callback(struct virtqueue *vq) -{ - struct virtio_crypto *vcrypto = vq->vdev->priv; - struct virtio_crypto_request *vc_req; - unsigned long flags; - unsigned int len; - unsigned int qid = vq->index; - - spin_lock_irqsave(&vcrypto->data_vq[qid].lock, flags); - do { - virtqueue_disable_cb(vq); - while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) { - spin_unlock_irqrestore( - &vcrypto->data_vq[qid].lock, flags); - if (vc_req->alg_cb) - vc_req->alg_cb(vc_req, len); - spin_lock_irqsave( - &vcrypto->data_vq[qid].lock, flags); - } - } while (!virtqueue_enable_cb(vq)); - spin_unlock_irqrestore(&vcrypto->data_vq[qid].lock, flags); -} - static int virtcrypto_find_vqs(struct virtio_crypto *vi) { vq_callback_t **callbacks;