keyslot-manager.c 18 KB

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