Re: [PATCH] crypto: caam/jr - fix algorithms exit/cleanup

From: Herbert Xu
Date: Wed Mar 15 2023 - 00:34:03 EST


On Tue, Mar 14, 2023 at 11:37:33PM +0530, meenakshi.aggarwal@xxxxxxx wrote:
> From: Horia GeantA <horia.geanta@xxxxxxx>
>
> Current implementations is not being able to gracefully unregister
> crypto algorithms from crypto API while there are users / allocated
> tfms (cra_refcnt > 1).
>
> When unloading the caam_jr module, the .remove callback for the last JR
> device exits with -EBUSY and doesn't perform the clean-up
> (crypto algorithms unregistering etc.).
>
> One side effect of this is leading to an oops, which occurs due to a
> corruption in the linked list of "misc devices"
> (drivers/char/misc.c - misc_list)
>
> Signed-off-by: Horia GeantA <horia.geanta@xxxxxxx>
> ---
> drivers/crypto/caam/jr.c | 39 +++++++++++++++++++++++++++++++++------
> 1 file changed, 33 insertions(+), 6 deletions(-)

Sorry, I don't think this is the right way to go.

We need to disassociate the registration of the Crypto algorithms
(soft) from the presence of the hardware (hard).

Sure, you can certainly refuse to register any algorithms until
the first piece of hardware shows up. But once you are registered,
you must not unregister yourself from the Crypto API until the module
actually goes away (when built-in that means never).

The complexity then goes into making sure that your driver fails
gracefully when the device goes away in the *middle* of a crypto
computation.

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