struct bio_set *bs = bio->bi_pool;
        unsigned inline_vecs;
 
+       if (WARN_ON_ONCE(bio_has_crypt_ctx(bio)))
+               return ERR_PTR(-EOPNOTSUPP);
+
        if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) {
                bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask);
                inline_vecs = nr_vecs;
 
        bi->tag_size = template->tag_size;
 
        disk->queue->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
+
+#ifdef CONFIG_BLK_INLINE_ENCRYPTION
+       if (disk->queue->ksm) {
+               pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
+               blk_ksm_unregister(disk->queue);
+       }
+#endif
 }
 EXPORT_SYMBOL(blk_integrity_register);
 
 
  * Upper layers will call blk_ksm_get_slot_for_key() to program a
  * key into some slot in the inline encryption hardware.
  */
+
+#define pr_fmt(fmt) "blk-crypto: " fmt
+
 #include <linux/keyslot-manager.h>
 #include <linux/atomic.h>
 #include <linux/mutex.h>
        memzero_explicit(ksm, sizeof(*ksm));
 }
 EXPORT_SYMBOL_GPL(blk_ksm_destroy);
+
+bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q)
+{
+       if (blk_integrity_queue_supports_integrity(q)) {
+               pr_warn("Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
+               return false;
+       }
+       q->ksm = ksm;
+       return true;
+}
+EXPORT_SYMBOL_GPL(blk_ksm_register);
+
+void blk_ksm_unregister(struct request_queue *q)
+{
+       q->ksm = NULL;
+}
 
        return blk_get_integrity(bdev->bd_disk);
 }
 
+static inline bool
+blk_integrity_queue_supports_integrity(struct request_queue *q)
+{
+       return q->integrity.profile;
+}
+
 static inline bool blk_integrity_rq(struct request *rq)
 {
        return rq->cmd_flags & REQ_INTEGRITY;
 {
        return NULL;
 }
+static inline bool
+blk_integrity_queue_supports_integrity(struct request_queue *q)
+{
+       return false;
+}
 static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b)
 {
        return 0;
 
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+#ifdef CONFIG_BLK_INLINE_ENCRYPTION
+
+bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q);
+
+void blk_ksm_unregister(struct request_queue *q);
+
+#else /* CONFIG_BLK_INLINE_ENCRYPTION */
+
+static inline bool blk_ksm_register(struct blk_keyslot_manager *ksm,
+                                   struct request_queue *q)
+{
+       return true;
+}
+
+static inline void blk_ksm_unregister(struct request_queue *q) { }
+
+#endif /* CONFIG_BLK_INLINE_ENCRYPTION */
+
+
 struct block_device_operations {
        int (*open) (struct block_device *, fmode_t);
        void (*release) (struct gendisk *, fmode_t);