一、以下是请求过程:
static inline int crypto_wait_req(int err, struct crypto_wait *wait)
{
switch (err) {
case -EINPROGRESS:
case -EBUSY:
wait_for_completion(&wait->completion);
reinit_completion(&wait->completion);
err = wait->err;
break;
};
return err;
}
static inline void crypto_init_wait(struct crypto_wait *wait)
{
init_completion(&wait->completion);
}
二、 completion 用法
通常wait_for_completion需要completion唤醒配合,如下:
#include <linux/completion.h>
static struct completion my_completion; // 1. 定义完成事件
static int my_thread_function(void *data) {
pr_info("Thread started...\n");
msleep(5000); // 模拟一个长时间的操作
pr_info("Operation completed!\n");
complete(&my_completion); // 3. 标记完成事件
return 0;
}
static int __init my_init(void) {
struct task_struct *thread;
pr_info("Module init...\n");
// 初始化完成事件
init_completion(&my_completion);
// 创建一个内核线程
thread = kthread_run(my_thread_function, NULL, "my_thread");
if (IS_ERR(thread)) {
pr_err("Failed to create thread.\n");
return PTR_ERR(thread);
}
// 等待完成事件
wait_for_completion(&my_completion); //2. 阻塞当前线程,直到完成事件被标记为已完成。
pr_info("Main thread: Operation completed!\n");
return 0;
}
三、 set_callback
static inline void ahash_request_set_callback(struct ahash_request *req,
u32 flags,
crypto_completion_t compl,
void *data)
{
req->base.complete = compl;
req->base.data = data;
req->base.flags = flags;
}
四、crypto_ahash_update
硬件加速请求。
+static int ccp_do_sm3_update(struct

本文详细解释了Linux内核中的加密API(如crypto_wait_req和completion机制),以及如何配合硬件加速器(如ccp_crypto_enqueue_request)进行操作,涉及任务调度、中断处理和完成事件的使用。还介绍了ccp引擎的工作流程,包括算法调用和任务队列管理。
最低0.47元/天 解锁文章
514

被折叠的 条评论
为什么被折叠?



