1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2019 Google LLC
4 */
5
6 /**
7 * DOC: The Keyslot Manager
8 *
9 * Many devices with inline encryption support have a limited number of "slots"
10 * into which encryption contexts may be programmed, and requests can be tagged
11 * with a slot number to specify the key to use for en/decryption.
12 *
13 * As the number of slots is limited, and programming keys is expensive on
14 * many inline encryption hardware, we don't want to program the same key into
15 * multiple slots - if multiple requests are using the same key, we want to
16 * program just one slot with that key and use that slot for all requests.
17 *
18 * The keyslot manager manages these keyslots appropriately, and also acts as
19 * an abstraction between the inline encryption hardware and the upper layers.
20 *
21 * Lower layer devices will set up a keyslot manager in their request queue
22 * and tell it how to perform device specific operations like programming/
23 * evicting keys from keyslots.
24 *
25 * Upper layers will call blk_ksm_get_slot_for_key() to program a
26 * key into some slot in the inline encryption hardware.
27 */
28
29 #define pr_fmt(fmt) "blk-crypto: " fmt
30
31 #include <linux/keyslot-manager.h>
32 #include <linux/device.h>
33 #include <linux/atomic.h>
34 #include <linux/mutex.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/wait.h>
37 #include <linux/blkdev.h>
38
39 struct blk_ksm_keyslot {
40 atomic_t slot_refs;
41 struct list_head idle_slot_node;
42 struct hlist_node hash_node;
43 const struct blk_crypto_key *key;
44 struct blk_keyslot_manager *ksm;
45 };
46
blk_ksm_hw_enter(struct blk_keyslot_manager * ksm)47 static inline void blk_ksm_hw_enter(struct blk_keyslot_manager *ksm)
48 {
49 /*
50 * Calling into the driver requires ksm->lock held and the device
51 * resumed. But we must resume the device first, since that can acquire
52 * and release ksm->lock via blk_ksm_reprogram_all_keys().
53 */
54 if (ksm->dev)
55 pm_runtime_get_sync(ksm->dev);
56 down_write(&ksm->lock);
57 }
58
blk_ksm_hw_exit(struct blk_keyslot_manager * ksm)59 static inline void blk_ksm_hw_exit(struct blk_keyslot_manager *ksm)
60 {
61 up_write(&ksm->lock);
62 if (ksm->dev)
63 pm_runtime_put_sync(ksm->dev);
64 }
65
blk_ksm_is_passthrough(struct blk_keyslot_manager * ksm)66 static inline bool blk_ksm_is_passthrough(struct blk_keyslot_manager *ksm)
67 {
68 return ksm->num_slots == 0;
69 }
70
71 /**
72 * blk_ksm_init() - Initialize a keyslot manager
73 * @ksm: The keyslot_manager to initialize.
74 * @num_slots: The number of key slots to manage.
75 *
76 * Allocate memory for keyslots and initialize a keyslot manager. Called by
77 * e.g. storage drivers to set up a keyslot manager in their request_queue.
78 *
79 * Return: 0 on success, or else a negative error code.
80 */
blk_ksm_init(struct blk_keyslot_manager * ksm,unsigned int num_slots)81 int blk_ksm_init(struct blk_keyslot_manager *ksm, unsigned int num_slots)
82 {
83 unsigned int slot;
84 unsigned int i;
85 unsigned int slot_hashtable_size;
86
87 memset(ksm, 0, sizeof(*ksm));
88
89 if (num_slots == 0)
90 return -EINVAL;
91
92 ksm->slots = kvcalloc(num_slots, sizeof(ksm->slots[0]), GFP_KERNEL);
93 if (!ksm->slots)
94 return -ENOMEM;
95
96 ksm->num_slots = num_slots;
97
98 init_rwsem(&ksm->lock);
99
100 init_waitqueue_head(&ksm->idle_slots_wait_queue);
101 INIT_LIST_HEAD(&ksm->idle_slots);
102
103 for (slot = 0; slot < num_slots; slot++) {
104 ksm->slots[slot].ksm = ksm;
105 list_add_tail(&ksm->slots[slot].idle_slot_node,
106 &ksm->idle_slots);
107 }
108
109 spin_lock_init(&ksm->idle_slots_lock);
110
111 slot_hashtable_size = roundup_pow_of_two(num_slots);
112 /*
113 * hash_ptr() assumes bits != 0, so ensure the hash table has at least 2
114 * buckets. This only makes a difference when there is only 1 keyslot.
115 */
116 if (slot_hashtable_size < 2)
117 slot_hashtable_size = 2;
118
119 ksm->log_slot_ht_size = ilog2(slot_hashtable_size);
120 ksm->slot_hashtable = kvmalloc_array(slot_hashtable_size,
121 sizeof(ksm->slot_hashtable[0]),
122 GFP_KERNEL);
123 if (!ksm->slot_hashtable)
124 goto err_destroy_ksm;
125 for (i = 0; i < slot_hashtable_size; i++)
126 INIT_HLIST_HEAD(&ksm->slot_hashtable[i]);
127
128 return 0;
129
130 err_destroy_ksm:
131 blk_ksm_destroy(ksm);
132 return -ENOMEM;
133 }
134 EXPORT_SYMBOL_GPL(blk_ksm_init);
135
blk_ksm_destroy_callback(void * ksm)136 static void blk_ksm_destroy_callback(void *ksm)
137 {
138 blk_ksm_destroy(ksm);
139 }
140
141 /**
142 * devm_blk_ksm_init() - Resource-managed blk_ksm_init()
143 * @dev: The device which owns the blk_keyslot_manager.
144 * @ksm: The blk_keyslot_manager to initialize.
145 * @num_slots: The number of key slots to manage.
146 *
147 * Like blk_ksm_init(), but causes blk_ksm_destroy() to be called automatically
148 * on driver detach.
149 *
150 * Return: 0 on success, or else a negative error code.
151 */
devm_blk_ksm_init(struct device * dev,struct blk_keyslot_manager * ksm,unsigned int num_slots)152 int devm_blk_ksm_init(struct device *dev, struct blk_keyslot_manager *ksm,
153 unsigned int num_slots)
154 {
155 int err = blk_ksm_init(ksm, num_slots);
156
157 if (err)
158 return err;
159
160 return devm_add_action_or_reset(dev, blk_ksm_destroy_callback, ksm);
161 }
162 EXPORT_SYMBOL_GPL(devm_blk_ksm_init);
163
164 static inline struct hlist_head *
blk_ksm_hash_bucket_for_key(struct blk_keyslot_manager * ksm,const struct blk_crypto_key * key)165 blk_ksm_hash_bucket_for_key(struct blk_keyslot_manager *ksm,
166 const struct blk_crypto_key *key)
167 {
168 return &ksm->slot_hashtable[hash_ptr(key, ksm->log_slot_ht_size)];
169 }
170
blk_ksm_remove_slot_from_lru_list(struct blk_ksm_keyslot * slot)171 static void blk_ksm_remove_slot_from_lru_list(struct blk_ksm_keyslot *slot)
172 {
173 struct blk_keyslot_manager *ksm = slot->ksm;
174 unsigned long flags;
175
176 spin_lock_irqsave(&ksm->idle_slots_lock, flags);
177 list_del(&slot->idle_slot_node);
178 spin_unlock_irqrestore(&ksm->idle_slots_lock, flags);
179 }
180
blk_ksm_find_keyslot(struct blk_keyslot_manager * ksm,const struct blk_crypto_key * key)181 static struct blk_ksm_keyslot *blk_ksm_find_keyslot(
182 struct blk_keyslot_manager *ksm,
183 const struct blk_crypto_key *key)
184 {
185 const struct hlist_head *head = blk_ksm_hash_bucket_for_key(ksm, key);
186 struct blk_ksm_keyslot *slotp;
187
188 hlist_for_each_entry(slotp, head, hash_node) {
189 if (slotp->key == key)
190 return slotp;
191 }
192 return NULL;
193 }
194
blk_ksm_find_and_grab_keyslot(struct blk_keyslot_manager * ksm,const struct blk_crypto_key * key)195 static struct blk_ksm_keyslot *blk_ksm_find_and_grab_keyslot(
196 struct blk_keyslot_manager *ksm,
197 const struct blk_crypto_key *key)
198 {
199 struct blk_ksm_keyslot *slot;
200
201 slot = blk_ksm_find_keyslot(ksm, key);
202 if (!slot)
203 return NULL;
204 if (atomic_inc_return(&slot->slot_refs) == 1) {
205 /* Took first reference to this slot; remove it from LRU list */
206 blk_ksm_remove_slot_from_lru_list(slot);
207 }
208 return slot;
209 }
210
blk_ksm_get_slot_idx(struct blk_ksm_keyslot * slot)211 unsigned int blk_ksm_get_slot_idx(struct blk_ksm_keyslot *slot)
212 {
213 return slot - slot->ksm->slots;
214 }
215 EXPORT_SYMBOL_GPL(blk_ksm_get_slot_idx);
216
217 /**
218 * blk_ksm_get_slot_for_key() - Program a key into a keyslot.
219 * @ksm: The keyslot manager to program the key into.
220 * @key: Pointer to the key object to program, including the raw key, crypto
221 * mode, and data unit size.
222 * @slot_ptr: A pointer to return the pointer of the allocated keyslot.
223 *
224 * Get a keyslot that's been programmed with the specified key. If one already
225 * exists, return it with incremented refcount. Otherwise, wait for a keyslot
226 * to become idle and program it.
227 *
228 * Context: Process context. Takes and releases ksm->lock.
229 * Return: BLK_STS_OK on success (and keyslot is set to the pointer of the
230 * allocated keyslot), or some other blk_status_t otherwise (and
231 * keyslot is set to NULL).
232 */
blk_ksm_get_slot_for_key(struct blk_keyslot_manager * ksm,const struct blk_crypto_key * key,struct blk_ksm_keyslot ** slot_ptr)233 blk_status_t blk_ksm_get_slot_for_key(struct blk_keyslot_manager *ksm,
234 const struct blk_crypto_key *key,
235 struct blk_ksm_keyslot **slot_ptr)
236 {
237 struct blk_ksm_keyslot *slot;
238 int slot_idx;
239 int err;
240
241 *slot_ptr = NULL;
242
243 if (blk_ksm_is_passthrough(ksm))
244 return BLK_STS_OK;
245
246 down_read(&ksm->lock);
247 slot = blk_ksm_find_and_grab_keyslot(ksm, key);
248 up_read(&ksm->lock);
249 if (slot)
250 goto success;
251
252 for (;;) {
253 blk_ksm_hw_enter(ksm);
254 slot = blk_ksm_find_and_grab_keyslot(ksm, key);
255 if (slot) {
256 blk_ksm_hw_exit(ksm);
257 goto success;
258 }
259
260 /*
261 * If we're here, that means there wasn't a slot that was
262 * already programmed with the key. So try to program it.
263 */
264 if (!list_empty(&ksm->idle_slots))
265 break;
266
267 blk_ksm_hw_exit(ksm);
268 wait_event(ksm->idle_slots_wait_queue,
269 !list_empty(&ksm->idle_slots));
270 }
271
272 slot = list_first_entry(&ksm->idle_slots, struct blk_ksm_keyslot,
273 idle_slot_node);
274 slot_idx = blk_ksm_get_slot_idx(slot);
275
276 err = ksm->ksm_ll_ops.keyslot_program(ksm, key, slot_idx);
277 if (err) {
278 wake_up(&ksm->idle_slots_wait_queue);
279 blk_ksm_hw_exit(ksm);
280 return errno_to_blk_status(err);
281 }
282
283 /* Move this slot to the hash list for the new key. */
284 if (slot->key)
285 hlist_del(&slot->hash_node);
286 slot->key = key;
287 hlist_add_head(&slot->hash_node, blk_ksm_hash_bucket_for_key(ksm, key));
288
289 atomic_set(&slot->slot_refs, 1);
290
291 blk_ksm_remove_slot_from_lru_list(slot);
292
293 blk_ksm_hw_exit(ksm);
294 success:
295 *slot_ptr = slot;
296 return BLK_STS_OK;
297 }
298
299 /**
300 * blk_ksm_put_slot() - Release a reference to a slot
301 * @slot: The keyslot to release the reference of.
302 *
303 * Context: Any context.
304 */
blk_ksm_put_slot(struct blk_ksm_keyslot * slot)305 void blk_ksm_put_slot(struct blk_ksm_keyslot *slot)
306 {
307 struct blk_keyslot_manager *ksm;
308 unsigned long flags;
309
310 if (!slot)
311 return;
312
313 ksm = slot->ksm;
314
315 if (atomic_dec_and_lock_irqsave(&slot->slot_refs,
316 &ksm->idle_slots_lock, flags)) {
317 list_add_tail(&slot->idle_slot_node, &ksm->idle_slots);
318 spin_unlock_irqrestore(&ksm->idle_slots_lock, flags);
319 wake_up(&ksm->idle_slots_wait_queue);
320 }
321 }
322
323 /**
324 * blk_ksm_crypto_cfg_supported() - Find out if a crypto configuration is
325 * supported by a ksm.
326 * @ksm: The keyslot manager to check
327 * @cfg: The crypto configuration to check for.
328 *
329 * Checks for crypto_mode/data unit size/dun bytes support.
330 *
331 * Return: Whether or not this ksm supports the specified crypto config.
332 */
blk_ksm_crypto_cfg_supported(struct blk_keyslot_manager * ksm,const struct blk_crypto_config * cfg)333 bool blk_ksm_crypto_cfg_supported(struct blk_keyslot_manager *ksm,
334 const struct blk_crypto_config *cfg)
335 {
336 if (!ksm)
337 return false;
338 if (!(ksm->crypto_modes_supported[cfg->crypto_mode] &
339 cfg->data_unit_size))
340 return false;
341 if (ksm->max_dun_bytes_supported < cfg->dun_bytes)
342 return false;
343 if (cfg->is_hw_wrapped) {
344 if (!(ksm->features & BLK_CRYPTO_FEATURE_WRAPPED_KEYS))
345 return false;
346 } else {
347 if (!(ksm->features & BLK_CRYPTO_FEATURE_STANDARD_KEYS))
348 return false;
349 }
350 return true;
351 }
352
353 /*
354 * This is an internal function that evicts a key from an inline encryption
355 * device that can be either a real device or the blk-crypto-fallback "device".
356 * It is used only by blk_crypto_evict_key(); see that function for details.
357 */
blk_ksm_evict_key(struct blk_keyslot_manager * ksm,const struct blk_crypto_key * key)358 int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
359 const struct blk_crypto_key *key)
360 {
361 struct blk_ksm_keyslot *slot;
362 int err;
363
364 if (blk_ksm_is_passthrough(ksm)) {
365 if (ksm->ksm_ll_ops.keyslot_evict) {
366 blk_ksm_hw_enter(ksm);
367 err = ksm->ksm_ll_ops.keyslot_evict(ksm, key, -1);
368 blk_ksm_hw_exit(ksm);
369 return err;
370 }
371 return 0;
372 }
373
374 blk_ksm_hw_enter(ksm);
375 slot = blk_ksm_find_keyslot(ksm, key);
376 if (!slot) {
377 /*
378 * Not an error, since a key not in use by I/O is not guaranteed
379 * to be in a keyslot. There can be more keys than keyslots.
380 */
381 err = 0;
382 goto out;
383 }
384
385 if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
386 /* BUG: key is still in use by I/O */
387 err = -EBUSY;
388 goto out_remove;
389 }
390 err = ksm->ksm_ll_ops.keyslot_evict(ksm, key,
391 blk_ksm_get_slot_idx(slot));
392 out_remove:
393 /*
394 * Callers free the key even on error, so unlink the key from the hash
395 * table and clear slot->key even on error.
396 */
397 hlist_del(&slot->hash_node);
398 slot->key = NULL;
399 out:
400 blk_ksm_hw_exit(ksm);
401 return err;
402 }
403
404 /**
405 * blk_ksm_reprogram_all_keys() - Re-program all keyslots.
406 * @ksm: The keyslot manager
407 *
408 * Re-program all keyslots that are supposed to have a key programmed. This is
409 * intended only for use by drivers for hardware that loses its keys on reset.
410 *
411 * Context: Process context. Takes and releases ksm->lock.
412 */
blk_ksm_reprogram_all_keys(struct blk_keyslot_manager * ksm)413 void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm)
414 {
415 unsigned int slot;
416
417 if (blk_ksm_is_passthrough(ksm))
418 return;
419
420 /* This is for device initialization, so don't resume the device */
421 down_write(&ksm->lock);
422 for (slot = 0; slot < ksm->num_slots; slot++) {
423 const struct blk_crypto_key *key = ksm->slots[slot].key;
424 int err;
425
426 if (!key)
427 continue;
428
429 err = ksm->ksm_ll_ops.keyslot_program(ksm, key, slot);
430 WARN_ON(err);
431 }
432 up_write(&ksm->lock);
433 }
434 EXPORT_SYMBOL_GPL(blk_ksm_reprogram_all_keys);
435
blk_ksm_destroy(struct blk_keyslot_manager * ksm)436 void blk_ksm_destroy(struct blk_keyslot_manager *ksm)
437 {
438 if (!ksm)
439 return;
440 kvfree(ksm->slot_hashtable);
441 kvfree_sensitive(ksm->slots, sizeof(ksm->slots[0]) * ksm->num_slots);
442 memzero_explicit(ksm, sizeof(*ksm));
443 }
444 EXPORT_SYMBOL_GPL(blk_ksm_destroy);
445
blk_ksm_register(struct blk_keyslot_manager * ksm,struct request_queue * q)446 bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q)
447 {
448 if (blk_integrity_queue_supports_integrity(q)) {
449 pr_warn("Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
450 return false;
451 }
452 q->ksm = ksm;
453 return true;
454 }
455 EXPORT_SYMBOL_GPL(blk_ksm_register);
456
blk_ksm_unregister(struct request_queue * q)457 void blk_ksm_unregister(struct request_queue *q)
458 {
459 q->ksm = NULL;
460 }
461
462 /**
463 * blk_ksm_derive_raw_secret() - Derive software secret from wrapped key
464 * @ksm: The keyslot manager
465 * @wrapped_key: The wrapped key
466 * @wrapped_key_size: Size of the wrapped key in bytes
467 * @secret: (output) the software secret
468 * @secret_size: (output) the number of secret bytes to derive
469 *
470 * Given a hardware-wrapped key, ask the hardware to derive a secret which
471 * software can use for cryptographic tasks other than inline encryption. The
472 * derived secret is guaranteed to be cryptographically isolated from the key
473 * with which any inline encryption with this wrapped key would actually be
474 * done. I.e., both will be derived from the unwrapped key.
475 *
476 * Return: 0 on success, -EOPNOTSUPP if hardware-wrapped keys are unsupported,
477 * or another -errno code.
478 */
blk_ksm_derive_raw_secret(struct blk_keyslot_manager * ksm,const u8 * wrapped_key,unsigned int wrapped_key_size,u8 * secret,unsigned int secret_size)479 int blk_ksm_derive_raw_secret(struct blk_keyslot_manager *ksm,
480 const u8 *wrapped_key,
481 unsigned int wrapped_key_size,
482 u8 *secret, unsigned int secret_size)
483 {
484 int err;
485
486 if (ksm->ksm_ll_ops.derive_raw_secret) {
487 blk_ksm_hw_enter(ksm);
488 err = ksm->ksm_ll_ops.derive_raw_secret(ksm, wrapped_key,
489 wrapped_key_size,
490 secret, secret_size);
491 blk_ksm_hw_exit(ksm);
492 } else {
493 err = -EOPNOTSUPP;
494 }
495
496 return err;
497 }
498 EXPORT_SYMBOL_GPL(blk_ksm_derive_raw_secret);
499
500 /**
501 * blk_ksm_intersect_modes() - restrict supported modes by child device
502 * @parent: The keyslot manager for parent device
503 * @child: The keyslot manager for child device, or NULL
504 *
505 * Clear any crypto mode support bits in @parent that aren't set in @child.
506 * If @child is NULL, then all parent bits are cleared.
507 *
508 * Only use this when setting up the keyslot manager for a layered device,
509 * before it's been exposed yet.
510 */
blk_ksm_intersect_modes(struct blk_keyslot_manager * parent,const struct blk_keyslot_manager * child)511 void blk_ksm_intersect_modes(struct blk_keyslot_manager *parent,
512 const struct blk_keyslot_manager *child)
513 {
514 if (child) {
515 unsigned int i;
516
517 parent->max_dun_bytes_supported =
518 min(parent->max_dun_bytes_supported,
519 child->max_dun_bytes_supported);
520 for (i = 0; i < ARRAY_SIZE(child->crypto_modes_supported);
521 i++) {
522 parent->crypto_modes_supported[i] &=
523 child->crypto_modes_supported[i];
524 }
525 parent->features &= child->features;
526 } else {
527 parent->max_dun_bytes_supported = 0;
528 memset(parent->crypto_modes_supported, 0,
529 sizeof(parent->crypto_modes_supported));
530 parent->features = 0;
531 }
532 }
533 EXPORT_SYMBOL_GPL(blk_ksm_intersect_modes);
534
535 /**
536 * blk_ksm_is_superset() - Check if a KSM supports a superset of crypto modes
537 * and DUN bytes that another KSM supports. Here,
538 * "superset" refers to the mathematical meaning of the
539 * word - i.e. if two KSMs have the *same* capabilities,
540 * they *are* considered supersets of each other.
541 * @ksm_superset: The KSM that we want to verify is a superset
542 * @ksm_subset: The KSM that we want to verify is a subset
543 *
544 * Return: True if @ksm_superset supports a superset of the crypto modes and DUN
545 * bytes that @ksm_subset supports.
546 */
blk_ksm_is_superset(struct blk_keyslot_manager * ksm_superset,struct blk_keyslot_manager * ksm_subset)547 bool blk_ksm_is_superset(struct blk_keyslot_manager *ksm_superset,
548 struct blk_keyslot_manager *ksm_subset)
549 {
550 int i;
551
552 if (!ksm_subset)
553 return true;
554
555 if (!ksm_superset)
556 return false;
557
558 for (i = 0; i < ARRAY_SIZE(ksm_superset->crypto_modes_supported); i++) {
559 if (ksm_subset->crypto_modes_supported[i] &
560 (~ksm_superset->crypto_modes_supported[i])) {
561 return false;
562 }
563 }
564
565 if (ksm_subset->max_dun_bytes_supported >
566 ksm_superset->max_dun_bytes_supported) {
567 return false;
568 }
569
570 if (ksm_subset->features & ~ksm_superset->features)
571 return false;
572
573 return true;
574 }
575 EXPORT_SYMBOL_GPL(blk_ksm_is_superset);
576
577 /**
578 * blk_ksm_update_capabilities() - Update the restrictions of a KSM to those of
579 * another KSM
580 * @target_ksm: The KSM whose restrictions to update.
581 * @reference_ksm: The KSM to whose restrictions this function will update
582 * @target_ksm's restrictions to.
583 *
584 * Blk-crypto requires that crypto capabilities that were
585 * advertised when a bio was created continue to be supported by the
586 * device until that bio is ended. This is turn means that a device cannot
587 * shrink its advertised crypto capabilities without any explicit
588 * synchronization with upper layers. So if there's no such explicit
589 * synchronization, @reference_ksm must support all the crypto capabilities that
590 * @target_ksm does
591 * (i.e. we need blk_ksm_is_superset(@reference_ksm, @target_ksm) == true).
592 *
593 * Note also that as long as the crypto capabilities are being expanded, the
594 * order of updates becoming visible is not important because it's alright
595 * for blk-crypto to see stale values - they only cause blk-crypto to
596 * believe that a crypto capability isn't supported when it actually is (which
597 * might result in blk-crypto-fallback being used if available, or the bio being
598 * failed).
599 */
blk_ksm_update_capabilities(struct blk_keyslot_manager * target_ksm,struct blk_keyslot_manager * reference_ksm)600 void blk_ksm_update_capabilities(struct blk_keyslot_manager *target_ksm,
601 struct blk_keyslot_manager *reference_ksm)
602 {
603 memcpy(target_ksm->crypto_modes_supported,
604 reference_ksm->crypto_modes_supported,
605 sizeof(target_ksm->crypto_modes_supported));
606
607 target_ksm->max_dun_bytes_supported =
608 reference_ksm->max_dun_bytes_supported;
609
610 target_ksm->features = reference_ksm->features;
611 }
612 EXPORT_SYMBOL_GPL(blk_ksm_update_capabilities);
613
614 /**
615 * blk_ksm_init_passthrough() - Init a passthrough keyslot manager
616 * @ksm: The keyslot manager to init
617 *
618 * Initialize a passthrough keyslot manager.
619 * Called by e.g. storage drivers to set up a keyslot manager in their
620 * request_queue, when the storage driver wants to manage its keys by itself.
621 * This is useful for inline encryption hardware that doesn't have the concept
622 * of keyslots, and for layered devices.
623 */
blk_ksm_init_passthrough(struct blk_keyslot_manager * ksm)624 void blk_ksm_init_passthrough(struct blk_keyslot_manager *ksm)
625 {
626 memset(ksm, 0, sizeof(*ksm));
627 init_rwsem(&ksm->lock);
628 }
629 EXPORT_SYMBOL_GPL(blk_ksm_init_passthrough);
630