Lines Matching defs:ksm
43 struct blk_keyslot_manager *ksm;
46 static inline void blk_ksm_hw_enter(struct blk_keyslot_manager *ksm)
49 * Calling into the driver requires ksm->lock held and the device
51 * and release ksm->lock via blk_ksm_reprogram_all_keys().
53 if (ksm->dev)
54 pm_runtime_get_sync(ksm->dev);
55 down_write(&ksm->lock);
58 static inline void blk_ksm_hw_exit(struct blk_keyslot_manager *ksm)
60 up_write(&ksm->lock);
61 if (ksm->dev)
62 pm_runtime_put_sync(ksm->dev);
67 * @ksm: The keyslot_manager to initialize.
75 int blk_ksm_init(struct blk_keyslot_manager *ksm, unsigned int num_slots)
81 memset(ksm, 0, sizeof(*ksm));
86 ksm->slots = kvcalloc(num_slots, sizeof(ksm->slots[0]), GFP_KERNEL);
87 if (!ksm->slots)
90 ksm->num_slots = num_slots;
92 init_rwsem(&ksm->lock);
94 init_waitqueue_head(&ksm->idle_slots_wait_queue);
95 INIT_LIST_HEAD(&ksm->idle_slots);
98 ksm->slots[slot].ksm = ksm;
99 list_add_tail(&ksm->slots[slot].idle_slot_node,
100 &ksm->idle_slots);
103 spin_lock_init(&ksm->idle_slots_lock);
113 ksm->log_slot_ht_size = ilog2(slot_hashtable_size);
114 ksm->slot_hashtable = kvmalloc_array(slot_hashtable_size,
115 sizeof(ksm->slot_hashtable[0]),
117 if (!ksm->slot_hashtable)
120 INIT_HLIST_HEAD(&ksm->slot_hashtable[i]);
125 blk_ksm_destroy(ksm);
131 blk_ksm_hash_bucket_for_key(struct blk_keyslot_manager *ksm,
134 return &ksm->slot_hashtable[hash_ptr(key, ksm->log_slot_ht_size)];
139 struct blk_keyslot_manager *ksm = slot->ksm;
142 spin_lock_irqsave(&ksm->idle_slots_lock, flags);
144 spin_unlock_irqrestore(&ksm->idle_slots_lock, flags);
148 struct blk_keyslot_manager *ksm,
151 const struct hlist_head *head = blk_ksm_hash_bucket_for_key(ksm, key);
162 struct blk_keyslot_manager *ksm,
167 slot = blk_ksm_find_keyslot(ksm, key);
179 return slot - slot->ksm->slots;
185 * @ksm: The keyslot manager to program the key into.
194 * Context: Process context. Takes and releases ksm->lock.
199 blk_status_t blk_ksm_get_slot_for_key(struct blk_keyslot_manager *ksm,
208 down_read(&ksm->lock);
209 slot = blk_ksm_find_and_grab_keyslot(ksm, key);
210 up_read(&ksm->lock);
215 blk_ksm_hw_enter(ksm);
216 slot = blk_ksm_find_and_grab_keyslot(ksm, key);
218 blk_ksm_hw_exit(ksm);
226 if (!list_empty(&ksm->idle_slots))
229 blk_ksm_hw_exit(ksm);
230 wait_event(ksm->idle_slots_wait_queue,
231 !list_empty(&ksm->idle_slots));
234 slot = list_first_entry(&ksm->idle_slots, struct blk_ksm_keyslot,
238 err = ksm->ksm_ll_ops.keyslot_program(ksm, key, slot_idx);
240 wake_up(&ksm->idle_slots_wait_queue);
241 blk_ksm_hw_exit(ksm);
249 hlist_add_head(&slot->hash_node, blk_ksm_hash_bucket_for_key(ksm, key));
255 blk_ksm_hw_exit(ksm);
269 struct blk_keyslot_manager *ksm;
275 ksm = slot->ksm;
278 &ksm->idle_slots_lock, flags)) {
279 list_add_tail(&slot->idle_slot_node, &ksm->idle_slots);
280 spin_unlock_irqrestore(&ksm->idle_slots_lock, flags);
281 wake_up(&ksm->idle_slots_wait_queue);
287 * supported by a ksm.
288 * @ksm: The keyslot manager to check
293 * Return: Whether or not this ksm supports the specified crypto config.
295 bool blk_ksm_crypto_cfg_supported(struct blk_keyslot_manager *ksm,
298 if (!ksm)
300 if (!(ksm->crypto_modes_supported[cfg->crypto_mode] &
303 if (ksm->max_dun_bytes_supported < cfg->dun_bytes)
313 int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
319 blk_ksm_hw_enter(ksm);
320 slot = blk_ksm_find_keyslot(ksm, key);
335 err = ksm->ksm_ll_ops.keyslot_evict(ksm, key,
345 blk_ksm_hw_exit(ksm);
351 * @ksm: The keyslot manager
356 * Context: Process context. Takes and releases ksm->lock.
358 void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm)
363 down_write(&ksm->lock);
364 for (slot = 0; slot < ksm->num_slots; slot++) {
365 const struct blk_crypto_key *key = ksm->slots[slot].key;
371 err = ksm->ksm_ll_ops.keyslot_program(ksm, key, slot);
374 up_write(&ksm->lock);
378 void blk_ksm_destroy(struct blk_keyslot_manager *ksm)
380 if (!ksm)
382 kvfree(ksm->slot_hashtable);
383 kvfree_sensitive(ksm->slots, sizeof(ksm->slots[0]) * ksm->num_slots);
384 memzero_explicit(ksm, sizeof(*ksm));
388 bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q)
394 q->ksm = ksm;
401 q->ksm = NULL;