Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp212118ybb; Tue, 7 Apr 2020 20:57:47 -0700 (PDT) X-Google-Smtp-Source: APiQypIutwgTd/gWbf0xUp0VV11tDylQFOK4JS42YSjY5M2s8XEiixe6mMNvLkEbrPnjXb8TogUA X-Received: by 2002:aca:d446:: with SMTP id l67mr1068067oig.115.1586318267648; Tue, 07 Apr 2020 20:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586318267; cv=none; d=google.com; s=arc-20160816; b=O8l473HqXeU1u/znwIR3+Dgu0vrbPSxYhV5zoYHWE0wfiNRM85ZO4V3gjQELYkYmQp bpDDa1dfu5YqLDpPAerq5zvm2DtTd7JmYN4eyOdVZuuNBe+mNATXnI21T6LIKOAm1APx OLn2ASHRSNd4e9GgMpHHX/rIpA5vve6OPurdJlCKbC8yJ/G/7bOpwAyoDQC0HFwEIVU0 UxqVKdHxt+dymFYfrzmQCvDqcHBdr7fCotD+Ah11yOrO5w1WYqlXJumjMupzU7hf7hY9 R431c1VSeOS95GY6OcA/P2Ujm7a+dC66AkBGdZHpabWs3slEu8iIsChsVDQfMCHdWH+d gN8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=R63k+AfysXRo+KgVRO7Z6nFDHUcUfFcV6SnK1eQRL6M=; b=HMuz4j/GJxGDoI+HdBHjRCwMh2TAoEy/tjUJw3YSnw77zaBqbDz0vYkZZepIiUZu2V 7b0Oi5IIBiUctDWSh5Q+7BFqmLVLN17wepOx9HBxuwXlALFlTXTLcNLUXmGG5mFBYjnb 5gIL792kSYfmdY6X9MtWUsxtku39hZ1lrmoGmu3XBw7wEtHcFlfKSEseMoUWfEodRtDx 6yAVTzywb86unNhBMx3I48l8ZBudr79+PE5yGyFNwpUP4AdrsgmI2CaB7wooTR+gqGc2 EOoRoiKyMCKOXpSxc77qVGOjffZispqM++j2VL8B5PKxJm3JG7volpdYurIyUNkN77qa Jf6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EbA4+PTD; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2si1860326oix.42.2020.04.07.20.57.33; Tue, 07 Apr 2020 20:57:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EbA4+PTD; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726555AbgDHD5U (ORCPT + 99 others); Tue, 7 Apr 2020 23:57:20 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:53775 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgDHD5S (ORCPT ); Tue, 7 Apr 2020 23:57:18 -0400 Received: by mail-pg1-f201.google.com with SMTP id c33so4375334pgl.20 for ; Tue, 07 Apr 2020 20:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=R63k+AfysXRo+KgVRO7Z6nFDHUcUfFcV6SnK1eQRL6M=; b=EbA4+PTDy2+dipLkMxCGkSOn3xK3neIY4SLpHSjfVMC8UMOcn6o/Nw/1JbY8nYjtqB tABJBFWJEJmgNu8RcJT4kbUo0F980e48dMipw3hYe985GvZ+IXqD6muziFCcEFghtg2S 8w42m9TeIMdmKp8Cj8uAcxnT188v3/6ig7aq51qrIQ09GES4aMaQzydyzMj8EqoPg3kx f2H2/+Om8n00RcqYl7vfTwwsLRM+C+mrOZHe0qfjVph+Z4Oy64Ry+yrq2q8tCHkiff2N zF1wI+Fcqee7eU6oOsnJ8MNKrIuO6sRwQHjzlUwWytrU+v6REm3F2uLDMN2FAVTwz8oz vsSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=R63k+AfysXRo+KgVRO7Z6nFDHUcUfFcV6SnK1eQRL6M=; b=AZY3I5nv/cknkPwZWuTF/lziRH8fkBvkgTtFq7y6S/PooSrKd34xgpyIvxsOl99FV3 18mNslEhzQhqL7724l81qrW6zqkC6X+b5nAdqXs1oGWbapG7W4kdAWo0+6O+W6vvp8iC hJ9Gh9hoMd+GCupI5FY4vpzy111TeAQ3o3QDdz5KebbiEynTpP+Z0r8EWHK0/lhXKF6Z R9k8+OGarKrI36+QEMKpjwsymZgTq3lWkAjcFnuUMlGWoX8XBZ8JKutcG/k1aQ5xOIOj qyTcgNpp7oh1lAyg7QjU6cGi1aPX+CYYrqLMdns+xvnHElPb4YTQGXN2mFmvvmdttbfF 3pVQ== X-Gm-Message-State: AGi0PubkRjpJdyQ9IzszDJ/jhqFwwy5nKdbhArBX5MrbApaPYYq3evL2 B5qqZLfoj5O2oVtcbYmWi5yq2lniUlc= X-Received: by 2002:a17:90a:c583:: with SMTP id l3mr3082112pjt.84.1586318236101; Tue, 07 Apr 2020 20:57:16 -0700 (PDT) Date: Tue, 7 Apr 2020 20:56:46 -0700 In-Reply-To: <20200408035654.247908-1-satyat@google.com> Message-Id: <20200408035654.247908-5-satyat@google.com> Mime-Version: 1.0 References: <20200408035654.247908-1-satyat@google.com> X-Mailer: git-send-email 2.26.0.110.g2183baf09c-goog Subject: [PATCH v10 04/12] block: Make blk-integrity preclude hardware inline encryption From: Satya Tangirala To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org Cc: Barani Muthukumaran , Kuohong Wang , Kim Boojin , Satya Tangirala Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Whenever a device supports blk-integrity, the kernel will now always 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 --- block/bio-integrity.c | 3 +++ block/blk-integrity.c | 7 +++++++ block/keyslot-manager.c | 19 +++++++++++++++++++ include/linux/blkdev.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index bf62c25cde8f4..3579ac0f6ec1f 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -42,6 +42,9 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, 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; diff --git a/block/blk-integrity.c b/block/blk-integrity.c index ff1070edbb400..b45711fc37df4 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -409,6 +409,13 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template 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. Unregistering keyslot manager from request queue, to disable hardware inline encryption.\n"); + blk_ksm_unregister(disk->queue); + } +#endif } EXPORT_SYMBOL(blk_integrity_register); diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index bae8d67a1f3fd..7cdd428f343e8 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -25,6 +25,9 @@ * 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 #include #include @@ -376,3 +379,19 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm) 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. Hardware inline encryption is being disabled.\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; +} diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 98aae4638fda9..17738dab8ae04 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1562,6 +1562,12 @@ struct blk_integrity *bdev_get_integrity(struct block_device *bdev) 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; @@ -1642,6 +1648,11 @@ static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) { 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; @@ -1693,6 +1704,25 @@ static inline struct bio_vec *rq_integrity_vec(struct request *rq) #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); -- 2.26.0.110.g2183baf09c-goog