block/blk-crypto-profile.c
Source file repositories/reference/linux-study-clean/block/blk-crypto-profile.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-crypto-profile.c- Extension
.c- Size
- 20238 bytes
- Lines
- 665
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- 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
linux/blk-crypto-profile.hlinux/device.hlinux/atomic.hlinux/mutex.hlinux/pm_runtime.hlinux/wait.hlinux/blkdev.hlinux/blk-integrity.hblk-crypto-internal.h
Detected Declarations
struct blk_crypto_keyslotfunction blk_crypto_hw_enterfunction blk_crypto_hw_exitfunction blk_crypto_profile_initfunction blk_crypto_profile_destroy_callbackfunction devm_blk_crypto_profile_initfunction blk_crypto_hash_bucket_for_keyfunction blk_crypto_remove_slot_from_lru_listfunction blk_crypto_find_keyslotfunction hlist_for_each_entryfunction blk_crypto_find_and_grab_keyslotfunction blk_crypto_keyslot_indexfunction blk_crypto_get_keyslotfunction blk_crypto_put_keyslotfunction __blk_crypto_cfg_supportedfunction __blk_crypto_evict_keyfunction blk_crypto_reprogram_all_keysfunction blk_crypto_profile_destroyfunction blk_crypto_registerfunction blk_crypto_derive_sw_secretfunction blk_crypto_import_keyfunction blk_crypto_generate_keyfunction blk_crypto_prepare_keyfunction blk_crypto_intersect_capabilitiesfunction blk_crypto_has_capabilitiesfunction blk_crypto_update_capabilitiesexport blk_crypto_profile_initexport devm_blk_crypto_profile_initexport blk_crypto_keyslot_indexexport blk_crypto_reprogram_all_keysexport blk_crypto_profile_destroyexport blk_crypto_registerexport blk_crypto_derive_sw_secretexport blk_crypto_import_keyexport blk_crypto_generate_keyexport blk_crypto_prepare_keyexport blk_crypto_intersect_capabilitiesexport blk_crypto_has_capabilitiesexport blk_crypto_update_capabilities
Annotated Snippet
struct blk_crypto_keyslot {
atomic_t slot_refs;
struct list_head idle_slot_node;
struct hlist_node hash_node;
const struct blk_crypto_key *key;
struct blk_crypto_profile *profile;
};
static inline void blk_crypto_hw_enter(struct blk_crypto_profile *profile)
__acquires(&profile->lock)
{
/*
* Calling into the driver requires profile->lock held and the device
* resumed. But we must resume the device first, since that can acquire
* and release profile->lock via blk_crypto_reprogram_all_keys().
*/
if (profile->dev)
pm_runtime_get_sync(profile->dev);
down_write(&profile->lock);
}
static inline void blk_crypto_hw_exit(struct blk_crypto_profile *profile)
__releases(&profile->lock)
{
up_write(&profile->lock);
if (profile->dev)
pm_runtime_put_sync(profile->dev);
}
/**
* blk_crypto_profile_init() - Initialize a blk_crypto_profile
* @profile: the blk_crypto_profile to initialize
* @num_slots: the number of keyslots
*
* Storage drivers must call this when starting to set up a blk_crypto_profile,
* before filling in additional fields.
*
* Return: 0 on success, or else a negative error code.
*/
int blk_crypto_profile_init(struct blk_crypto_profile *profile,
unsigned int num_slots)
{
unsigned int slot;
unsigned int i;
unsigned int slot_hashtable_size;
memset(profile, 0, sizeof(*profile));
/*
* profile->lock of an underlying device can nest inside profile->lock
* of a device-mapper device, so use a dynamic lock class to avoid
* false-positive lockdep reports.
*/
lockdep_register_key(&profile->lockdep_key);
__init_rwsem(&profile->lock, "&profile->lock", &profile->lockdep_key);
if (num_slots == 0)
return 0;
/* Initialize keyslot management data. */
profile->slots = kvzalloc_objs(profile->slots[0], num_slots);
if (!profile->slots)
goto err_destroy;
profile->num_slots = num_slots;
init_waitqueue_head(&profile->idle_slots_wait_queue);
INIT_LIST_HEAD(&profile->idle_slots);
for (slot = 0; slot < num_slots; slot++) {
profile->slots[slot].profile = profile;
list_add_tail(&profile->slots[slot].idle_slot_node,
&profile->idle_slots);
}
spin_lock_init(&profile->idle_slots_lock);
slot_hashtable_size = roundup_pow_of_two(num_slots);
/*
* hash_ptr() assumes bits != 0, so ensure the hash table has at least 2
* buckets. This only makes a difference when there is only 1 keyslot.
*/
if (slot_hashtable_size < 2)
slot_hashtable_size = 2;
profile->log_slot_ht_size = ilog2(slot_hashtable_size);
profile->slot_hashtable =
kvmalloc_objs(profile->slot_hashtable[0], slot_hashtable_size);
if (!profile->slot_hashtable)
Annotation
- Immediate include surface: `linux/blk-crypto-profile.h`, `linux/device.h`, `linux/atomic.h`, `linux/mutex.h`, `linux/pm_runtime.h`, `linux/wait.h`, `linux/blkdev.h`, `linux/blk-integrity.h`.
- Detected declarations: `struct blk_crypto_keyslot`, `function blk_crypto_hw_enter`, `function blk_crypto_hw_exit`, `function blk_crypto_profile_init`, `function blk_crypto_profile_destroy_callback`, `function devm_blk_crypto_profile_init`, `function blk_crypto_hash_bucket_for_key`, `function blk_crypto_remove_slot_from_lru_list`, `function blk_crypto_find_keyslot`, `function hlist_for_each_entry`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- 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.