Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uadk: driver alloc and free resources by itself #555

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

gaozhangfei
Copy link
Collaborator

A driver should alloc and free resources by himself instead of the caller, considering multi-driver exists, the caller can not hold ctx for all drivers, so drv.init malloc private ctx and drv.exit free.

Add driver as para of alg ops, not only for getting private ctx, but easier for multi-driver support.


if (!priv)
return;

Copy link
Collaborator

@Liulongfang Liulongfang May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem when deleting directly here. After the priv is removed at the API layer, a solution needs to be added to prevent repeated uninitialization. Otherwise, the function of preventing double release will be gone, which will cause other problems.

Thanks.
Longfang.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en, for the drivers only supporting init once, drv.init can check whether drv.priv is null or not.
For the drivers support multi-entry, like adapter, just let it go. adapter has detected each workers.init.
if (worker->inited)
continue;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The priv here is still in the wd_cipher_setting structure. It is used to prevent repeated uninitialization of resources at the API layer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the driver does not support repeated exit, it is the driver's responsibility to prevent repeated un-initialization, not the caller's.
Now both hisi_sec_init and hisi_sec_exit has checked drv.priv.
For drivers permitted multi-init and multi-exit, it is OK, just like free().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this problem is not solved in the current patch. If merged into the patch will cause problems

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wd_alg_try_init(&wd_digest_setting.status) can prevent re-init2
Whether the driver can call init multi-times depends on the driver itself.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this wd_alg_try_init is possible.
You can add it and verify it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wd_alg_try_init still there, in wd_xxx_init, this patch does not change that.

@gaozhangfei
Copy link
Collaborator Author

rebased to master, to solve conflict

Copy link
Collaborator

@Liulongfang Liulongfang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

A driver should alloc and free resources by himself instead of the
caller, considering multi-driver exists, the caller can not hold ctxs
for all drivers, so drv.init malloc private ctx and drv.exit free.

Add driver as para of alg ops, not only for getting private ctx, but
easier for multi-driver support.

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants