From: "Michael S. Tsirkin" <mst@redhat.com>
To: Bibo Mao <maobibo@loongson.cn>
Cc: Gonglei <arei.gonglei@huawei.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
virtualization@lists.linux.dev, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/9] crypto: virtio: Add req_data with structure virtio_crypto_sym_request
Date: Thu, 4 Dec 2025 07:46:11 -0500 [thread overview]
Message-ID: <20251204074310-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20251204112227.2659404-7-maobibo@loongson.cn>
On Thu, Dec 04, 2025 at 07:22:23PM +0800, Bibo Mao wrote:
> With normal encrypt/decrypt workflow, req_data with struct type
> virtio_crypto_op_data_req will be allocated. Here put req_data in
> virtio_crypto_sym_request, it is pre-allocated when encrypt/decrypt
> interface is called.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> drivers/crypto/virtio/virtio_crypto_core.c | 3 ++-
> drivers/crypto/virtio/virtio_crypto_skcipher_algs.c | 12 +++---------
> 2 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> index ccc6b5c1b24b..e60ad1d94e7f 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -17,7 +17,8 @@ void
> virtcrypto_clear_request(struct virtio_crypto_request *vc_req)
> {
> if (vc_req) {
> - kfree_sensitive(vc_req->req_data);
> + if (vc_req->req_data)
> + kfree_sensitive(vc_req->req_data);
kfree of NULL is a nop, why make this change?
> kfree(vc_req->sgs);
> }
> }
> diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> index 7b3f21a40d78..a7c7c726e6d9 100644
> --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> @@ -26,6 +26,7 @@ struct virtio_crypto_skcipher_ctx {
>
> struct virtio_crypto_sym_request {
> struct virtio_crypto_request base;
> + struct virtio_crypto_op_data_req req_data;
>
> /* Cipher or aead */
> uint32_t type;
> @@ -350,14 +351,8 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req,
> if (!sgs)
> return -ENOMEM;
>
> - req_data = kzalloc_node(sizeof(*req_data), GFP_KERNEL,
> - dev_to_node(&vcrypto->vdev->dev));
> - if (!req_data) {
> - kfree(sgs);
> - return -ENOMEM;
> - }
> -
> - vc_req->req_data = req_data;
> + req_data = &vc_sym_req->req_data;
> + vc_req->req_data = NULL;
> vc_sym_req->type = VIRTIO_CRYPTO_SYM_OP_CIPHER;
> /* Head of operation */
> if (vc_sym_req->encrypt) {
> @@ -450,7 +445,6 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req,
> free_iv:
> kfree_sensitive(iv);
> free:
> - kfree_sensitive(req_data);
So the request is no longer erased with memset on error. Is that not
a problem?
> kfree(sgs);
> return err;
> }
> --
> 2.39.3
next prev parent reply other threads:[~2025-12-04 12:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251204112227.2659404-1-maobibo@loongson.cn>
2025-12-04 11:22 ` [PATCH v2 1/9] crypto: virtio: Add spinlock protection with virtqueue notification Bibo Mao
2025-12-05 1:21 ` Jason Wang
2025-12-05 1:56 ` Bibo Mao
2025-12-04 11:22 ` [PATCH v2 2/9] crypto: virtio: Replace package id with numa node id Bibo Mao
2025-12-04 11:22 ` [PATCH v2 3/9] crypto: virtio: Add algo pointer in virtio_crypto_skcipher_ctx Bibo Mao
2025-12-04 11:22 ` [PATCH v2 4/9] crypto: virtio: Use generic API aes_check_keylen() Bibo Mao
2025-12-04 11:22 ` [PATCH v2 5/9] crypto: virtio: Remove AES specified marcro AES_BLOCK_SIZE Bibo Mao
2025-12-04 11:22 ` [PATCH v2 6/9] crypto: virtio: Add req_data with structure virtio_crypto_sym_request Bibo Mao
2025-12-04 12:46 ` Michael S. Tsirkin [this message]
2025-12-05 1:23 ` Bibo Mao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251204074310-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=davem@davemloft.net \
--cc=eperezma@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=jasowang@redhat.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maobibo@loongson.cn \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®