Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Make blk-integrity preclude hardware inline encryption

Whenever a device supports blk-integrity, make the kernel pretend that
the device doesn't support inline encryption (essentially by setting the
keyslot manager in the request queue to NULL).

There's no hardware currently that supports both integrity and inline
encryption. However, it seems possible that there will be such hardware
in the near future (like the NVMe key per I/O support that might support
both inline encryption and PI).

But properly integrating both features is not trivial, and without
real hardware that implements both, it is difficult to tell if it will
be done correctly by the majority of hardware that support both.
So it seems best not to support both features together right now, and
to decide what to do at probe time.

Signed-off-by: Satya Tangirala <satyat@google.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Satya Tangirala and committed by
Jens Axboe
d145dc23 a892c8d5

+59
+3
block/bio-integrity.c
··· 42 42 struct bio_set *bs = bio->bi_pool; 43 43 unsigned inline_vecs; 44 44 45 + if (WARN_ON_ONCE(bio_has_crypt_ctx(bio))) 46 + return ERR_PTR(-EOPNOTSUPP); 47 + 45 48 if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) { 46 49 bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask); 47 50 inline_vecs = nr_vecs;
+7
block/blk-integrity.c
··· 409 409 bi->tag_size = template->tag_size; 410 410 411 411 disk->queue->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES; 412 + 413 + #ifdef CONFIG_BLK_INLINE_ENCRYPTION 414 + if (disk->queue->ksm) { 415 + pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n"); 416 + blk_ksm_unregister(disk->queue); 417 + } 418 + #endif 412 419 } 413 420 EXPORT_SYMBOL(blk_integrity_register); 414 421
+19
block/keyslot-manager.c
··· 25 25 * Upper layers will call blk_ksm_get_slot_for_key() to program a 26 26 * key into some slot in the inline encryption hardware. 27 27 */ 28 + 29 + #define pr_fmt(fmt) "blk-crypto: " fmt 30 + 28 31 #include <linux/keyslot-manager.h> 29 32 #include <linux/atomic.h> 30 33 #include <linux/mutex.h> ··· 379 376 memzero_explicit(ksm, sizeof(*ksm)); 380 377 } 381 378 EXPORT_SYMBOL_GPL(blk_ksm_destroy); 379 + 380 + bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q) 381 + { 382 + if (blk_integrity_queue_supports_integrity(q)) { 383 + pr_warn("Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n"); 384 + return false; 385 + } 386 + q->ksm = ksm; 387 + return true; 388 + } 389 + EXPORT_SYMBOL_GPL(blk_ksm_register); 390 + 391 + void blk_ksm_unregister(struct request_queue *q) 392 + { 393 + q->ksm = NULL; 394 + }
+30
include/linux/blkdev.h
··· 1583 1583 return blk_get_integrity(bdev->bd_disk); 1584 1584 } 1585 1585 1586 + static inline bool 1587 + blk_integrity_queue_supports_integrity(struct request_queue *q) 1588 + { 1589 + return q->integrity.profile; 1590 + } 1591 + 1586 1592 static inline bool blk_integrity_rq(struct request *rq) 1587 1593 { 1588 1594 return rq->cmd_flags & REQ_INTEGRITY; ··· 1669 1663 { 1670 1664 return NULL; 1671 1665 } 1666 + static inline bool 1667 + blk_integrity_queue_supports_integrity(struct request_queue *q) 1668 + { 1669 + return false; 1670 + } 1672 1671 static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) 1673 1672 { 1674 1673 return 0; ··· 1724 1713 } 1725 1714 1726 1715 #endif /* CONFIG_BLK_DEV_INTEGRITY */ 1716 + 1717 + #ifdef CONFIG_BLK_INLINE_ENCRYPTION 1718 + 1719 + bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q); 1720 + 1721 + void blk_ksm_unregister(struct request_queue *q); 1722 + 1723 + #else /* CONFIG_BLK_INLINE_ENCRYPTION */ 1724 + 1725 + static inline bool blk_ksm_register(struct blk_keyslot_manager *ksm, 1726 + struct request_queue *q) 1727 + { 1728 + return true; 1729 + } 1730 + 1731 + static inline void blk_ksm_unregister(struct request_queue *q) { } 1732 + 1733 + #endif /* CONFIG_BLK_INLINE_ENCRYPTION */ 1734 + 1727 1735 1728 1736 struct block_device_operations { 1729 1737 int (*open) (struct block_device *, fmode_t);