在 2025/5/19 下午1:57, Herbert Xu 写道:
On Tue, May 06, 2025 at 11:19:44AM +0800, Qunqin Zhao wrote:
+static int loongson_rng_init(struct crypto_tfm *tfm)
+{
+       struct loongson_rng_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct loongson_rng *rng;
+       int ret = -EBUSY;
+
+       mutex_lock(&rng_devices.lock);
+       list_for_each_entry(rng, &rng_devices.list, list) {
+               if (!rng->is_used) {
+                       rng->is_used = true;
+                       ctx->rng = rng;
+                       ret = 0;
+                       break;
+               }
+       }
+       mutex_unlock(&rng_devices.lock);
+
+       return ret;
+}
This isn't right.  The number of TFMs in the system is unlimited.
You should not pair each tfm with an individual hardwre device.
Then the HISI TRNG driver isn't a right demo?

If you want to do load-balancing you could certainly pick a device
per tfm, but each device must be able to support an unlimited number
of tfms.

This can also avoid concurrent access to a device, otherwise i need to

add mutex_lock/unlock in generate and seed callback.

Thanks,

Qunqin.


Cheers,


Reply via email to