crypto/crypto_engine.c
Source file repositories/reference/linux-study-clean/crypto/crypto_engine.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/crypto_engine.c- Extension
.c- Size
- 17681 bytes
- Lines
- 657
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/internal/aead.hcrypto/internal/akcipher.hcrypto/internal/engine.hcrypto/internal/hash.hcrypto/internal/kpp.hcrypto/internal/skcipher.hlinux/err.hlinux/delay.hlinux/device.hlinux/kernel.hlinux/module.huapi/linux/sched/types.hinternal.h
Detected Declarations
struct crypto_engine_algfunction crypto_finalize_requestfunction crypto_pump_requestsfunction fullfunction crypto_pump_workfunction crypto_transfer_requestfunction crypto_transfer_request_to_enginefunction crypto_transfer_aead_request_to_enginefunction crypto_transfer_akcipher_request_to_enginefunction crypto_transfer_hash_request_to_enginefunction crypto_transfer_kpp_request_to_enginefunction crypto_transfer_skcipher_request_to_enginefunction crypto_finalize_aead_requestfunction crypto_finalize_akcipher_requestfunction crypto_finalize_hash_requestfunction crypto_finalize_kpp_requestfunction crypto_finalize_skcipher_requestfunction crypto_engine_startfunction crypto_engine_stopfunction crypto_engine_exitfunction crypto_engine_register_aeadfunction crypto_engine_unregister_aeadfunction crypto_engine_register_aeadsfunction crypto_engine_unregister_aeadsfunction crypto_engine_register_ahashfunction crypto_engine_unregister_ahashfunction crypto_engine_register_ahashesfunction crypto_engine_unregister_ahashesfunction crypto_engine_register_akcipherfunction crypto_engine_unregister_akcipherfunction crypto_engine_register_kppfunction crypto_engine_unregister_kppfunction crypto_engine_register_skcipherfunction crypto_engine_unregister_skcipherfunction crypto_engine_register_skciphersfunction crypto_engine_unregister_skciphersexport crypto_transfer_aead_request_to_engineexport crypto_transfer_akcipher_request_to_engineexport crypto_transfer_hash_request_to_engineexport crypto_transfer_kpp_request_to_engineexport crypto_transfer_skcipher_request_to_engineexport crypto_finalize_aead_requestexport crypto_finalize_akcipher_requestexport crypto_finalize_hash_requestexport crypto_finalize_kpp_requestexport crypto_finalize_skcipher_requestexport crypto_engine_startexport crypto_engine_stop
Annotated Snippet
struct crypto_engine_alg {
struct crypto_alg base;
struct crypto_engine_op op;
};
/**
* crypto_finalize_request - finalize one request if the request is done
* @engine: the hardware engine
* @req: the request need to be finalized
* @err: error number
*/
static void crypto_finalize_request(struct crypto_engine *engine,
struct crypto_async_request *req, int err)
{
unsigned long flags;
/*
* If hardware cannot enqueue more requests
* and retry mechanism is not supported
* make sure we are completing the current request
*/
if (!engine->retry_support) {
spin_lock_irqsave(&engine->queue_lock, flags);
if (engine->cur_req == req) {
engine->cur_req = NULL;
}
spin_unlock_irqrestore(&engine->queue_lock, flags);
}
lockdep_assert_in_softirq();
crypto_request_complete(req, err);
kthread_queue_work(engine->kworker, &engine->pump_requests);
}
/**
* crypto_pump_requests - dequeue one request from engine queue to process
* @engine: the hardware engine
* @in_kthread: true if we are in the context of the request pump thread
*
* This function checks if there is any request in the engine queue that
* needs processing and if so call out to the driver to initialize hardware
* and handle each request.
*/
static void crypto_pump_requests(struct crypto_engine *engine,
bool in_kthread)
{
struct crypto_async_request *async_req, *backlog;
struct crypto_engine_alg *alg;
struct crypto_engine_op *op;
unsigned long flags;
int ret;
spin_lock_irqsave(&engine->queue_lock, flags);
/* Make sure we are not already running a request */
if (!engine->retry_support && engine->cur_req)
goto out;
/* Check if the engine queue is idle */
if (!crypto_queue_len(&engine->queue) || !engine->running) {
if (!engine->busy)
goto out;
/* Only do teardown in the thread */
if (!in_kthread) {
kthread_queue_work(engine->kworker,
&engine->pump_requests);
goto out;
}
engine->busy = false;
goto out;
}
start_request:
/* Get the fist request from the engine queue to handle */
backlog = crypto_get_backlog(&engine->queue);
async_req = crypto_dequeue_request(&engine->queue);
if (!async_req)
goto out;
/*
* If hardware doesn't support the retry mechanism,
* keep track of the request we are processing now.
* We'll need it on completion (crypto_finalize_request).
*/
if (!engine->retry_support)
engine->cur_req = async_req;
Annotation
- Immediate include surface: `crypto/internal/aead.h`, `crypto/internal/akcipher.h`, `crypto/internal/engine.h`, `crypto/internal/hash.h`, `crypto/internal/kpp.h`, `crypto/internal/skcipher.h`, `linux/err.h`, `linux/delay.h`.
- Detected declarations: `struct crypto_engine_alg`, `function crypto_finalize_request`, `function crypto_pump_requests`, `function full`, `function crypto_pump_work`, `function crypto_transfer_request`, `function crypto_transfer_request_to_engine`, `function crypto_transfer_aead_request_to_engine`, `function crypto_transfer_akcipher_request_to_engine`, `function crypto_transfer_hash_request_to_engine`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.