Lines Matching refs:profile

14  * construct a crypto profile, then associate it with the disk's request_queue.
27 #include <linux/blk-crypto-profile.h>
42 struct blk_crypto_profile *profile;
45 static inline void blk_crypto_hw_enter(struct blk_crypto_profile *profile)
48 * Calling into the driver requires profile->lock held and the device
50 * and release profile->lock via blk_crypto_reprogram_all_keys().
52 if (profile->dev)
53 pm_runtime_get_sync(profile->dev);
54 down_write(&profile->lock);
57 static inline void blk_crypto_hw_exit(struct blk_crypto_profile *profile)
59 up_write(&profile->lock);
60 if (profile->dev)
61 pm_runtime_put_sync(profile->dev);
66 * @profile: the blk_crypto_profile to initialize
74 int blk_crypto_profile_init(struct blk_crypto_profile *profile,
81 memset(profile, 0, sizeof(*profile));
84 * profile->lock of an underlying device can nest inside profile->lock
88 lockdep_register_key(&profile->lockdep_key);
89 __init_rwsem(&profile->lock, "&profile->lock", &profile->lockdep_key);
96 profile->slots = kvcalloc(num_slots, sizeof(profile->slots[0]),
98 if (!profile->slots)
101 profile->num_slots = num_slots;
103 init_waitqueue_head(&profile->idle_slots_wait_queue);
104 INIT_LIST_HEAD(&profile->idle_slots);
107 profile->slots[slot].profile = profile;
108 list_add_tail(&profile->slots[slot].idle_slot_node,
109 &profile->idle_slots);
112 spin_lock_init(&profile->idle_slots_lock);
122 profile->log_slot_ht_size = ilog2(slot_hashtable_size);
123 profile->slot_hashtable =
125 sizeof(profile->slot_hashtable[0]), GFP_KERNEL);
126 if (!profile->slot_hashtable)
129 INIT_HLIST_HEAD(&profile->slot_hashtable[i]);
134 blk_crypto_profile_destroy(profile);
139 static void blk_crypto_profile_destroy_callback(void *profile)
141 blk_crypto_profile_destroy(profile);
147 * @profile: the blk_crypto_profile to initialize
156 struct blk_crypto_profile *profile,
159 int err = blk_crypto_profile_init(profile, num_slots);
166 profile);
171 blk_crypto_hash_bucket_for_key(struct blk_crypto_profile *profile,
174 return &profile->slot_hashtable[
175 hash_ptr(key, profile->log_slot_ht_size)];
181 struct blk_crypto_profile *profile = slot->profile;
184 spin_lock_irqsave(&profile->idle_slots_lock, flags);
186 spin_unlock_irqrestore(&profile->idle_slots_lock, flags);
190 blk_crypto_find_keyslot(struct blk_crypto_profile *profile,
194 blk_crypto_hash_bucket_for_key(profile, key);
205 blk_crypto_find_and_grab_keyslot(struct blk_crypto_profile *profile,
210 slot = blk_crypto_find_keyslot(profile, key);
228 return slot - slot->profile->slots;
234 * @profile: the crypto profile of the device the key will be used on
244 * Context: Process context. Takes and releases profile->lock.
248 blk_status_t blk_crypto_get_keyslot(struct blk_crypto_profile *profile,
262 if (profile->num_slots == 0)
265 down_read(&profile->lock);
266 slot = blk_crypto_find_and_grab_keyslot(profile, key);
267 up_read(&profile->lock);
272 blk_crypto_hw_enter(profile);
273 slot = blk_crypto_find_and_grab_keyslot(profile, key);
275 blk_crypto_hw_exit(profile);
283 if (!list_empty(&profile->idle_slots))
286 blk_crypto_hw_exit(profile);
287 wait_event(profile->idle_slots_wait_queue,
288 !list_empty(&profile->idle_slots));
291 slot = list_first_entry(&profile->idle_slots, struct blk_crypto_keyslot,
295 err = profile->ll_ops.keyslot_program(profile, key, slot_idx);
297 wake_up(&profile->idle_slots_wait_queue);
298 blk_crypto_hw_exit(profile);
307 blk_crypto_hash_bucket_for_key(profile, key));
313 blk_crypto_hw_exit(profile);
327 struct blk_crypto_profile *profile = slot->profile;
331 &profile->idle_slots_lock, flags)) {
332 list_add_tail(&slot->idle_slot_node, &profile->idle_slots);
333 spin_unlock_irqrestore(&profile->idle_slots_lock, flags);
334 wake_up(&profile->idle_slots_wait_queue);
339 * __blk_crypto_cfg_supported() - Check whether the given crypto profile
341 * @profile: the crypto profile to check
344 * Return: %true if @profile supports the given @cfg.
346 bool __blk_crypto_cfg_supported(struct blk_crypto_profile *profile,
349 if (!profile)
351 if (!(profile->modes_supported[cfg->crypto_mode] & cfg->data_unit_size))
353 if (profile->max_dun_bytes_supported < cfg->dun_bytes)
363 int __blk_crypto_evict_key(struct blk_crypto_profile *profile,
369 if (profile->num_slots == 0) {
370 if (profile->ll_ops.keyslot_evict) {
371 blk_crypto_hw_enter(profile);
372 err = profile->ll_ops.keyslot_evict(profile, key, -1);
373 blk_crypto_hw_exit(profile);
379 blk_crypto_hw_enter(profile);
380 slot = blk_crypto_find_keyslot(profile, key);
395 err = profile->ll_ops.keyslot_evict(profile, key,
405 blk_crypto_hw_exit(profile);
411 * @profile: The crypto profile
416 * Context: Process context. Takes and releases profile->lock.
418 void blk_crypto_reprogram_all_keys(struct blk_crypto_profile *profile)
422 if (profile->num_slots == 0)
426 down_write(&profile->lock);
427 for (slot = 0; slot < profile->num_slots; slot++) {
428 const struct blk_crypto_key *key = profile->slots[slot].key;
434 err = profile->ll_ops.keyslot_program(profile, key, slot);
437 up_write(&profile->lock);
441 void blk_crypto_profile_destroy(struct blk_crypto_profile *profile)
443 if (!profile)
445 lockdep_unregister_key(&profile->lockdep_key);
446 kvfree(profile->slot_hashtable);
447 kvfree_sensitive(profile->slots,
448 sizeof(profile->slots[0]) * profile->num_slots);
449 memzero_explicit(profile, sizeof(*profile));
453 bool blk_crypto_register(struct blk_crypto_profile *profile,
460 q->crypto_profile = profile;
468 * @parent: the crypto profile for the parent device
469 * @child: the crypto profile for the child device, or NULL
474 * Only use this when setting up the crypto profile for a layered device, before
499 * @target: the target profile
500 * @reference: the reference profile
530 * profile to match those of another crypto
531 * profile.
532 * @dst: The crypto profile whose capabilities to update.
533 * @src: The crypto profile whose capabilities this function will update @dst's