Skip to content

Commit d145dc2

Browse files
Satya Tangiralaaxboe
authored andcommitted
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>
1 parent a892c8d commit d145dc2

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎block/bio-integrity.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
4242
struct bio_set *bs = bio->bi_pool;
4343
unsigned inline_vecs;
4444

45+
if (WARN_ON_ONCE(bio_has_crypt_ctx(bio)))
46+
return ERR_PTR(-EOPNOTSUPP);
47+
4548
if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) {
4649
bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask);
4750
inline_vecs = nr_vecs;

‎block/blk-integrity.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template
409409
bi->tag_size = template->tag_size;
410410

411411
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
412419
}
413420
EXPORT_SYMBOL(blk_integrity_register);
414421

‎block/keyslot-manager.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* Upper layers will call blk_ksm_get_slot_for_key() to program a
2626
* key into some slot in the inline encryption hardware.
2727
*/
28+
29+
#define pr_fmt(fmt) "blk-crypto: " fmt
30+
2831
#include <linux/keyslot-manager.h>
2932
#include <linux/atomic.h>
3033
#include <linux/mutex.h>
@@ -376,3 +379,19 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm)
376379
memzero_explicit(ksm, sizeof(*ksm));
377380
}
378381
EXPORT_SYMBOL_GPL(blk_ksm_destroy);
382+
383+
bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q)
384+
{
385+
if (blk_integrity_queue_supports_integrity(q)) {
386+
pr_warn("Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
387+
return false;
388+
}
389+
q->ksm = ksm;
390+
return true;
391+
}
392+
EXPORT_SYMBOL_GPL(blk_ksm_register);
393+
394+
void blk_ksm_unregister(struct request_queue *q)
395+
{
396+
q->ksm = NULL;
397+
}

‎include/linux/blkdev.h‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,12 @@ struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
15831583
return blk_get_integrity(bdev->bd_disk);
15841584
}
15851585

1586+
static inline bool
1587+
blk_integrity_queue_supports_integrity(struct request_queue *q)
1588+
{
1589+
return q->integrity.profile;
1590+
}
1591+
15861592
static inline bool blk_integrity_rq(struct request *rq)
15871593
{
15881594
return rq->cmd_flags & REQ_INTEGRITY;
@@ -1663,6 +1669,11 @@ static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
16631669
{
16641670
return NULL;
16651671
}
1672+
static inline bool
1673+
blk_integrity_queue_supports_integrity(struct request_queue *q)
1674+
{
1675+
return false;
1676+
}
16661677
static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b)
16671678
{
16681679
return 0;
@@ -1714,6 +1725,25 @@ static inline struct bio_vec *rq_integrity_vec(struct request *rq)
17141725

17151726
#endif /* CONFIG_BLK_DEV_INTEGRITY */
17161727

1728+
#ifdef CONFIG_BLK_INLINE_ENCRYPTION
1729+
1730+
bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q);
1731+
1732+
void blk_ksm_unregister(struct request_queue *q);
1733+
1734+
#else /* CONFIG_BLK_INLINE_ENCRYPTION */
1735+
1736+
static inline bool blk_ksm_register(struct blk_keyslot_manager *ksm,
1737+
struct request_queue *q)
1738+
{
1739+
return true;
1740+
}
1741+
1742+
static inline void blk_ksm_unregister(struct request_queue *q) { }
1743+
1744+
#endif /* CONFIG_BLK_INLINE_ENCRYPTION */
1745+
1746+
17171747
struct block_device_operations {
17181748
int (*open) (struct block_device *, fmode_t);
17191749
void (*release) (struct gendisk *, fmode_t);

0 commit comments

Comments
 (0)