kernel/bpf/crypto.c
Source file repositories/reference/linux-study-clean/kernel/bpf/crypto.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/crypto.c- Extension
.c- Size
- 11307 bytes
- Lines
- 400
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
linux/bpf.hlinux/bpf_crypto.hlinux/bpf_mem_alloc.hlinux/btf.hlinux/btf_ids.hlinux/filter.hlinux/scatterlist.hlinux/skbuff.hcrypto/skcipher.h
Detected Declarations
struct bpf_crypto_type_liststruct bpf_crypto_paramsstruct bpf_crypto_ctxfunction bpf_crypto_register_typefunction bpf_crypto_unregister_typefunction bpf_crypto_ctx_createfunction crypto_free_cbfunction bpf_crypto_ctx_acquirefunction bpf_crypto_ctx_releasefunction bpf_crypto_ctx_release_dtorfunction bpf_crypto_cryptfunction bpf_crypto_decryptfunction bpf_crypto_encryptfunction crypto_kfunc_initexport bpf_crypto_register_typeexport bpf_crypto_unregister_type
Annotated Snippet
struct bpf_crypto_type_list {
const struct bpf_crypto_type *type;
struct list_head list;
};
/* BPF crypto initialization parameters struct */
/**
* struct bpf_crypto_params - BPF crypto initialization parameters structure
* @type: The string of crypto operation type.
* @reserved: Reserved member, will be reused for more options in future
* Values:
* 0
* @algo: The string of algorithm to initialize.
* @key: The cipher key used to init crypto algorithm.
* @key_len: The length of cipher key.
* @authsize: The length of authentication tag used by algorithm.
*/
struct bpf_crypto_params {
char type[14];
u8 reserved[2];
char algo[128];
u8 key[256];
u32 key_len;
u32 authsize;
};
static LIST_HEAD(bpf_crypto_types);
static DECLARE_RWSEM(bpf_crypto_types_sem);
/**
* struct bpf_crypto_ctx - refcounted BPF crypto context structure
* @type: The pointer to bpf crypto type
* @tfm: The pointer to instance of crypto API struct.
* @siv_len: Size of IV and state storage for cipher
* @rcu: The RCU head used to free the crypto context with RCU safety.
* @usage: Object reference counter. When the refcount goes to 0, the
* memory is released back to the BPF allocator, which provides
* RCU safety.
*/
struct bpf_crypto_ctx {
const struct bpf_crypto_type *type;
void *tfm;
u32 siv_len;
struct rcu_head rcu;
refcount_t usage;
};
int bpf_crypto_register_type(const struct bpf_crypto_type *type)
{
struct bpf_crypto_type_list *node;
int err = -EBUSY;
down_write(&bpf_crypto_types_sem);
list_for_each_entry(node, &bpf_crypto_types, list) {
if (!strcmp(node->type->name, type->name))
goto unlock;
}
node = kmalloc_obj(*node);
err = -ENOMEM;
if (!node)
goto unlock;
node->type = type;
list_add(&node->list, &bpf_crypto_types);
err = 0;
unlock:
up_write(&bpf_crypto_types_sem);
return err;
}
EXPORT_SYMBOL_GPL(bpf_crypto_register_type);
int bpf_crypto_unregister_type(const struct bpf_crypto_type *type)
{
struct bpf_crypto_type_list *node;
int err = -ENOENT;
down_write(&bpf_crypto_types_sem);
list_for_each_entry(node, &bpf_crypto_types, list) {
if (strcmp(node->type->name, type->name))
continue;
list_del(&node->list);
kfree(node);
err = 0;
break;
}
up_write(&bpf_crypto_types_sem);
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/bpf_crypto.h`, `linux/bpf_mem_alloc.h`, `linux/btf.h`, `linux/btf_ids.h`, `linux/filter.h`, `linux/scatterlist.h`, `linux/skbuff.h`.
- Detected declarations: `struct bpf_crypto_type_list`, `struct bpf_crypto_params`, `struct bpf_crypto_ctx`, `function bpf_crypto_register_type`, `function bpf_crypto_unregister_type`, `function bpf_crypto_ctx_create`, `function crypto_free_cb`, `function bpf_crypto_ctx_acquire`, `function bpf_crypto_ctx_release`, `function bpf_crypto_ctx_release_dtor`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.