From: Jens Axboe <axboe@kernel.dk>
To: Satya Tangirala <satyat@google.com>,
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
Cc: Kuohong Wang <kuohong.wang@mediatek.com>,
Ladvine D Almeida <ladvine.dalmeida@synopsys.com>,
Barani Muthukumaran <bmuthuku@qti.qualcomm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Parshuram Raju Thombare <pthombar@cadence.com>
Subject: Re: [PATCH 2/8] block: Add encryption context to struct bio
Date: Fri, 2 Aug 2019 13:46:45 -0700 [thread overview]
Message-ID: <7856ad79-6224-532d-ff9f-50ffc00f7203@kernel.dk> (raw)
In-Reply-To: <20190710225609.192252-3-satyat@google.com>
On 7/10/19 4:56 PM, Satya Tangirala wrote:
> We must have some way of letting a storage device driver know what
> encryption context it should use for en/decrypting a request. However,
> it's the filesystem/fscrypt that knows about and manages encryption
> contexts. As such, when the filesystem layer submits a bio to the block
> layer, and this bio eventually reaches a device driver with support for
> inline encryption, the device driver will need to have been told the
> encryption context for that bio.
>
> We want to communicate the encryption context from the filesystem layer
> to the storage device along with the bio, when the bio is submitted to the
> block layer. To do this, we add a struct bio_crypt_ctx to struct bio, which
> can represent an encryption context (note that we can't use the bi_private
> field in struct bio to do this because that field does not function to pass
> information across layers in the storage stack). We also introduce various
> functions to manipulate the bio_crypt_ctx and make the bio/request merging
> logic aware of the bio_crypt_ctx.
A few minor comments below. Don't see something totally horrible with
your approach.
> diff --git a/block/bio-crypt-ctx.c b/block/bio-crypt-ctx.c
> new file mode 100644
> index 000000000000..8b884ef32007
> --- /dev/null
> +++ b/block/bio-crypt-ctx.c
> @@ -0,0 +1,117 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright 2019 Google LLC
> + */
> +
> +#include <linux/bio.h>
> +#include <linux/blkdev.h>
> +#include <linux/slab.h>
> +#include <linux/keyslot-manager.h>
> +
> +struct bio_crypt_ctx *bio_crypt_alloc_ctx(gfp_t gfp_mask)
> +{
> + return kzalloc(sizeof(struct bio_crypt_ctx), gfp_mask);
> +}
I think you'll want this to be mempool backed.
> +EXPORT_SYMBOL(bio_crypt_alloc_ctx);
> +
> +void bio_crypt_free_ctx(struct bio *bio)
> +{
> + kzfree(bio->bi_crypt_context);
> + bio->bi_crypt_context = NULL;
> +}
> +EXPORT_SYMBOL(bio_crypt_free_ctx);
> +
> +int bio_crypt_clone(struct bio *dst, struct bio *src, gfp_t gfp_mask)
> +{
> + if (!bio_is_encrypted(src))
> + return 0;
Was going to suggest dumping this helper, but that won't work for the
case where inline encryption isn't enabled. How about renaming it so it
is easier to grok what it tests, bio_has_crypt_ctx() or something like
that.
> + dst->bi_crypt_context = bio_crypt_alloc_ctx(gfp_mask);
> + if (!dst->bi_crypt_context)
> + return -ENOMEM;
That's why you need the mempool...
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index 17713d7d98d5..f416e7f38270 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -531,6 +531,9 @@ static inline int ll_new_hw_segment(struct request_queue *q,
> if (blk_integrity_merge_bio(q, req, bio) == false)
> goto no_merge;
>
> + if (WARN_ON(!bio_crypt_ctx_compatible(bio, req->bio)))
> + goto no_merge;
This is really a debug check, as that shouldn't happen unless you have a
bug in your merge helpers. I think we can do one of two things here:
1) Rely on this check only for merging, similarly to what the integrity
code does. This means the WARN() goes away and (most of) the other
merge checks can go away.
2) Keep it, but change it to a WARN_ON_ONCE().
> @@ -696,8 +699,13 @@ static enum elv_merge blk_try_req_merge(struct request *req,
> {
> if (blk_discard_mergable(req))
> return ELEVATOR_DISCARD_MERGE;
> - else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next))
> + else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next)) {
> + if (!bio_crypt_ctx_back_mergeable(
> + req->bio, blk_rq_sectors(req), next->bio)) {
> + return ELEVATOR_NO_MERGE;
> + }
> return ELEVATOR_BACK_MERGE;
> + }
Weird line breaks aside, see above comment. More in this file.
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index ef9c6e2e92bc..4e664d6441d5 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -572,6 +572,196 @@ enum blk_crypt_mode_num {
> */
> };
>
> +#ifdef CONFIG_BLK_INLINE_ENCRYPTION
> +struct bio_crypt_ctx {
> + int keyslot;
> + u8 *raw_key;
> + enum blk_crypt_mode_num crypt_mode;
> + u64 data_unit_num;
> + unsigned int data_unit_size_bits;
> +
> + /*
> + * The keyslot manager where the key has been programmed
> + * with keyslot.
> + */
> + struct keyslot_manager *processing_ksm;
> +
> + /*
> + * Copy of the bvec_iter when this bio was submitted.
> + * We only want to en/decrypt the part of the bio
> + * as described by the bvec_iter upon submission because
> + * bio might be split before being resubmitted
> + */
> + struct bvec_iter crypt_iter;
> + u64 sw_data_unit_num;
> +};
[snip]
Let's move that to a separate file, with the other crypt specific bits.
Just include it from bio.h.
> +static inline u64 bio_crypt_data_unit_num(struct bio *bio)
> +{
> + WARN_ON(!bio_is_encrypted(bio));
> + return bio->bi_crypt_context->data_unit_num;
> +}
> +
> +static inline u64 bio_crypt_sw_data_unit_num(struct bio *bio)
> +{
> + WARN_ON(!bio_is_encrypted(bio));
> + return bio->bi_crypt_context->sw_data_unit_num;
> +}
These WARN()'s are a bit weird.
> +static inline u64 bio_crypt_data_unit_num(struct bio *bio)
> +{
> + WARN_ON(1);
> + return 0;
> +}
And this one definitely needs to go.
> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index 95202f80676c..0b794fe3530a 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -137,6 +137,8 @@ static inline void bio_issue_init(struct bio_issue *issue,
> ((u64)size << BIO_ISSUE_SIZE_SHIFT));
> }
>
> +struct bio_crypt_ctx;
Place this with the other forward declarations.
--
Jens Axboe
next prev parent reply other threads:[~2019-08-02 20:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 22:56 [PATCH v3 0/8] Inline Encryption Support Satya Tangirala via Linux-f2fs-devel
2019-07-10 22:56 ` [PATCH 1/8] block: Keyslot Manager for Inline Encryption Satya Tangirala via Linux-f2fs-devel
2019-07-10 22:56 ` [PATCH 2/8] block: Add encryption context to struct bio Satya Tangirala via Linux-f2fs-devel
2019-08-02 20:46 ` Jens Axboe [this message]
2019-07-10 22:56 ` [PATCH 3/8] block: blk-crypto for Inline Encryption Satya Tangirala via Linux-f2fs-devel
2019-07-11 5:47 ` Randy Dunlap
2019-07-15 15:40 ` Eric Biggers
2019-08-02 20:51 ` Jens Axboe
2019-07-10 22:56 ` [PATCH 4/8] scsi: ufs: UFS driver v2.1 spec crypto additions Satya Tangirala via Linux-f2fs-devel
2019-07-10 22:56 ` [PATCH 5/8] scsi: ufs: UFS crypto API Satya Tangirala via Linux-f2fs-devel
2019-07-10 22:56 ` [PATCH 6/8] scsi: ufs: Add inline encryption support to UFS Satya Tangirala via Linux-f2fs-devel
2019-07-10 22:56 ` [PATCH 7/8] fscrypt: wire up fscrypt to use blk-crypto Satya Tangirala via Linux-f2fs-devel
2019-07-12 19:27 ` Eric Biggers
2019-07-10 22:56 ` [PATCH 8/8] f2fs: Wire up f2fs to use inline encryption via fscrypt Satya Tangirala via Linux-f2fs-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7856ad79-6224-532d-ff9f-50ffc00f7203@kernel.dk \
--to=axboe@kernel.dk \
--cc=bmuthuku@qti.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuohong.wang@mediatek.com \
--cc=ladvine.dalmeida@synopsys.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=pthombar@cadence.com \
--cc=satyat@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox