Re: [PATCH] crypto: api - Add support for duplicating algorithms before registration

From: Eric Biggers
Date: Sun Apr 13 2025 - 12:03:23 EST


On Sat, Apr 12, 2025 at 01:16:43PM +0800, Herbert Xu wrote:
> On Fri, Apr 11, 2025 at 09:36:27AM +0800, Herbert Xu wrote:
> >
> > The patch goes on top of cryptodev. But it won't do anything
> > without a corresponding patch to caam that moves the algorithm
> > data structures into dynamically allocated memory, and adds a
> > cra_destroy hook to free that memory.
>
> Here's a patch on top that allows drivers to do this easily.
> Unfortunately it still won't help caam because it embeds the
> algorithm in a bigger structure, so the duplication needs to
> be done by hand.
>
> ---8<---
> If the bit CRYPTO_ALG_DUP_FIRST is set, an algorithm will be
> duplicated by kmemdup before registration. This is inteded for
> hardware-based algorithms that may be unplugged at will.
>
> Do not use this if the algorithm data structure is embedded in a
> bigger data structure. Perform the duplication in the driver
> instead.
>
> Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

Why does this make any sense? The lifetime of the algorithm struct memory
should be the same as that of the owning module, and drivers should ensure that.
In which case hacks like this are not needed.

- Eric