crypto/algapi.c
Source file repositories/reference/linux-study-clean/crypto/algapi.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/algapi.c- Extension
.c- Size
- 25143 bytes
- Lines
- 1120
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/algapi.hlinux/err.hlinux/errno.hlinux/fips.hlinux/init.hlinux/kernel.hlinux/list.hlinux/module.hlinux/rtnetlink.hlinux/slab.hlinux/string.hlinux/workqueue.hinternal.h
Detected Declarations
function crypto_check_module_sigfunction crypto_check_algfunction crypto_free_instancefunction crypto_destroy_instance_workfnfunction crypto_destroy_instancefunction algorithmfunction crypto_remove_instancefunction crypto_remove_spawnsfunction crypto_alg_finish_registrationfunction list_for_each_entryfunction __crypto_register_algfunction list_for_each_entryfunction crypto_alg_testedfunction crypto_remove_finalfunction list_for_each_entry_safefunction crypto_free_algfunction crypto_register_algfunction crypto_remove_algfunction crypto_unregister_algfunction crypto_register_algsfunction crypto_unregister_algsfunction crypto_register_templatefunction list_for_each_entryfunction crypto_register_templatesfunction crypto_unregister_templatefunction hlist_for_each_entry_safefunction crypto_unregister_templatesfunction crypto_register_instancefunction crypto_unregister_instancefunction crypto_grab_spawnfunction crypto_drop_spawnfunction crypto_register_notifierfunction crypto_unregister_notifierfunction crypto_check_attr_typefunction __crypto_inst_setnamefunction crypto_init_queuefunction crypto_enqueue_requestfunction crypto_enqueue_request_headfunction crypto_inc_bytefunction crypto_incfunction crypto_alg_extsizefunction crypto_type_has_algfunction crypto_start_testsfunction list_for_each_entryfunction crypto_algapi_initfunction crypto_algapi_exitexport crypto_remove_spawnsexport crypto_alg_tested
Annotated Snippet
while (!list_empty(spawns)) {
struct crypto_instance *inst;
spawn = list_first_entry(spawns, struct crypto_spawn,
list);
inst = spawn->inst;
list_move(&spawn->list, &stack);
spawn->dead = !spawn->registered || &inst->alg != nalg;
if (!spawn->registered)
break;
BUG_ON(&inst->alg == alg);
if (&inst->alg == nalg)
break;
spawns = &inst->alg.cra_users;
/*
* Even if spawn->registered is true, the
* instance itself may still be unregistered.
* This is because it may have failed during
* registration. Therefore we still need to
* make the following test.
*
* We may encounter an unregistered instance here, since
* an instance's spawns are set up prior to the instance
* being registered. An unregistered instance will have
* NULL ->cra_users.next, since ->cra_users isn't
* properly initialized until registration. But an
* unregistered instance cannot have any users, so treat
* it the same as ->cra_users being empty.
*/
if (spawns->next == NULL)
break;
}
} while ((spawns = crypto_more_spawns(alg, &stack, &top,
&secondary_spawns)));
/*
* Remove all instances that are marked as dead. Also
* complete the resurrection of the others by moving them
* back to the cra_users list.
*/
list_for_each_entry_safe(spawn, n, &secondary_spawns, list) {
if (!spawn->dead)
list_move(&spawn->list, &spawn->alg->cra_users);
else if (spawn->registered)
crypto_remove_instance(spawn->inst, list);
}
}
EXPORT_SYMBOL_GPL(crypto_remove_spawns);
static void crypto_alg_finish_registration(struct crypto_alg *alg,
struct list_head *algs_to_put)
__must_hold(&crypto_alg_sem)
{
struct crypto_alg *q;
list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (q == alg)
continue;
if (crypto_is_moribund(q))
continue;
if (crypto_is_larval(q))
continue;
if (strcmp(alg->cra_name, q->cra_name))
continue;
if (strcmp(alg->cra_driver_name, q->cra_driver_name) &&
q->cra_priority > alg->cra_priority)
continue;
crypto_remove_spawns(q, algs_to_put, alg);
}
crypto_notify(CRYPTO_MSG_ALG_LOADED, alg);
}
static struct crypto_larval *crypto_alloc_test_larval(struct crypto_alg *alg)
{
struct crypto_larval *larval;
if (!IS_ENABLED(CONFIG_CRYPTO_SELFTESTS) ||
(alg->cra_flags & CRYPTO_ALG_INTERNAL))
Annotation
- Immediate include surface: `crypto/algapi.h`, `linux/err.h`, `linux/errno.h`, `linux/fips.h`, `linux/init.h`, `linux/kernel.h`, `linux/list.h`, `linux/module.h`.
- Detected declarations: `function crypto_check_module_sig`, `function crypto_check_alg`, `function crypto_free_instance`, `function crypto_destroy_instance_workfn`, `function crypto_destroy_instance`, `function algorithm`, `function crypto_remove_instance`, `function crypto_remove_spawns`, `function crypto_alg_finish_registration`, `function list_for_each_entry`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration implementation candidate.
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.