Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: T Pratham <t-pratham@ti.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Kamlesh Gurudasani <kamlesh@ti.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Praneeth Bajjuri <praneeth@ti.com>,
	Manorit Chawdhry <m-chawdhry@ti.com>,
	linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH v4 2/2] crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
Date: Tue, 13 May 2025 16:00:07 +0800	[thread overview]
Message-ID: <aCL8BxpHr5OpT04k@gondor.apana.org.au> (raw)
In-Reply-To: <20250508101723.846210-4-t-pratham@ti.com>

On Thu, May 08, 2025 at 03:37:41PM +0530, T Pratham wrote:
>
> +static int dthe_cipher_init_tfm(struct crypto_skcipher *tfm)
> +{
> +	struct dthe_tfm_ctx *ctx = crypto_skcipher_ctx(tfm);
> +	struct dthe_data *dev_data = dthe_get_dev(ctx);
> +
> +	void __iomem *aes_base_reg = dev_data->regs + DTHE_P_AES_BASE;
> +	u32 aes_irqenable_val = readl_relaxed(aes_base_reg + DTHE_P_AES_IRQENABLE);
> +	u32 aes_sysconfig_val = readl_relaxed(aes_base_reg + DTHE_P_AES_SYSCONFIG);
> +
> +	memzero_explicit(ctx, sizeof(*ctx));
> +	ctx->dev_data = dev_data;
> +	ctx->ctx_info.aes_ctx = kzalloc(sizeof(*ctx->ctx_info.aes_ctx), GFP_KERNEL);
> +	if (!ctx->ctx_info.aes_ctx)
> +		return -ENOMEM;

The ctx_info union should just become part of ctx instead of a
separate allocation.

> +	crypto_skcipher_set_reqsize(tfm, sizeof(struct dthe_aes_req_ctx));

Please set cra_reqsize instead in the algorithm.

> +	aes_sysconfig_val |= DTHE_AES_SYSCONFIG_DMA_DATA_IN_OUT_EN;
> +	writel_relaxed(aes_sysconfig_val, aes_base_reg + DTHE_P_AES_SYSCONFIG);
> +
> +	aes_irqenable_val |= DTHE_AES_IRQENABLE_EN_ALL;
> +	writel_relaxed(aes_irqenable_val, aes_base_reg + DTHE_P_AES_IRQENABLE);

This does not look right.  The tfm allocation happens once for each
key, and they could be done concurrently.  You should not be operating
on the hardware in the init_tfm function.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2025-05-13  8:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 10:07 [PATCH v4 0/2] Add support for Texas Instruments DTHE V2 crypto accelerator T Pratham
2025-05-08 10:07 ` [PATCH v4 1/2] dt-bindings: crypto: Add binding for TI DTHE V2 T Pratham
2025-05-08 10:23   ` Krzysztof Kozlowski
2025-05-08 11:11   ` Rob Herring (Arm)
2025-06-03 10:52     ` T Pratham
2025-06-03 12:25       ` Krzysztof Kozlowski
2025-05-08 10:07 ` [PATCH v4 2/2] crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC) T Pratham
2025-05-13  8:00   ` Herbert Xu [this message]

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=aCL8BxpHr5OpT04k@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=kamlesh@ti.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m-chawdhry@ti.com \
    --cc=praneeth@ti.com \
    --cc=t-pratham@ti.com \
    --cc=vigneshr@ti.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