Re: [dm-devel] [RFC PATCH 0/1] Add inline encryption support for dm-crypt

2022-01-14 Thread Eric Biggers
Hi Israel,

On Thu, Jan 13, 2022 at 08:09:00PM +0200, Israel Rukshin wrote:
> Hi,
> 
> I am working to add support for inline encryption/decryption
> at storage protocols like nvmf over RDMA. The HW that I am
> working with is ConnecX-6 Dx, which supports inline crypto
> and can send the data on the fabric at the same time.
> 
> This patchset is based on v5.16-rc4 with Eric Biggers patches
> of the HW wrapped keys.
> It can be retrieved from branch "wip-wrapped-keys" at
> https://git.kernel.org/pub/scm/fs/fscrypt/fscrypt.git
> 
> I tested this patch with modified nvme-rdma as the block device
> and created a DM crypt on top of it. I got performance enhancement
> compared to SW crypto. I tested the HW wrapped inline mode with
> the HW and the standard mode with a fallback algorithm.
> 
> Israel Rukshin (1):
>   dm crypt: Add inline encryption support
> 
>  block/blk-crypto.c|   3 +
>  drivers/md/dm-crypt.c | 202 --
>  2 files changed, 180 insertions(+), 25 deletions(-)

I appreciate the interest in my patchset that adds support for hardware-wrapped
inline encryption keys
(https://lore.kernel.org/linux-block/2026033240.39001-1-ebigg...@kernel.org).
So far I've received very little feedback on it.

One of the challenges I've been having is that I still have no platform on which
I can actually test hardware-wrapped keys with the upstream kernel.  The feature
cannot be accepted upstream until there is a way to test it.  It's almost
working on the SM8350 SoC, but I am waiting for Qualcomm to fix some things.

It sounds like you've implemented a block device driver that exposes support for
hardware-wrapped keys.  Can you please post that driver?

Can you also elaborate on how wrapped keys work in your case?  In particular,
are they compatible with the whole design which I've documented in detail in my
patchset?  That would include implementing the ->import_key, ->generate_key,
->prepare_key, and ->derive_sw_secret operations.  All the different parts are
important.  If something needs to be optional, that's something I can consider
incorporating into the design, but it would restrict the use cases.

Also, will your driver only support wrapped keys, or will it support standard
keys too?

- Eric

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [RFC PATCH 0/1] Add inline encryption support for dm-crypt

2022-01-14 Thread Eric Biggers
On Fri, Jan 14, 2022 at 09:51:20PM +0100, Milan Broz wrote:
> On 13/01/2022 19:09, Israel Rukshin wrote:
> > Hi,
> > 
> > I am working to add support for inline encryption/decryption
> > at storage protocols like nvmf over RDMA. The HW that I am
> > working with is ConnecX-6 Dx, which supports inline crypto
> > and can send the data on the fabric at the same time.
> 
> This idea comes from time to time, and it makes dm-crypt bloated,
> and mainly it moves responsibility for encryption to block layer
> crypto.
> It adds two completely different sector encryption paths there.
> 
> Also, see my comments here (for similar patches)
> https://lore.kernel.org/dm-devel/c94d425a-bca4-8a8b-47bf-451239d29...@gmail.com/
> 
> I think dm-crypt should stay as SW crypto only (using kernel crypto API,
> so HW acceleration is done through crypto drivers there).
> 
> A cleaner solution is to write a much simpler new dm-crypt-inline target,
> which will implement only inline encryption.
> (And userspace can decide which target to use.)
> Code should be just an extension to the dm-linear target, most
> of dm-crypt complexity is not needed here.
> 
> Also, please think about configuration - how do you want to configure it?
> 
> Just my opinion, it is, of course, up to DM maintainer if he takes such 
> patches.
> 

IMO, adding inline encryption support to dm-crypt would be fine.  Normally,
blk-crypto is just an alternate implementation of encryption/decryption.  I'm
not sure that a separate dm target is warranted just because of a different
implementation, as opposed to different *behavior*.  (Support for wrapped keys
does complicate things a bit, as they do change behavior.)  But, I'd also be
fine with a separate dm target if the dm maintainers prefer that route.

Note that in the Android Common Kernels, there is already a dm target called
"dm-default-key" which uses dm-crypt compatible syntax but uses blk-crypto
(inline encryption) rather than the crypto API:
https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/drivers/md/dm-default-key.c

It differs slightly from what is being proposed here in that dm-default-key's
purpose is to implement filesystem "metadata encryption", so it has logic to
skip encrypting blocks that have their encryption controlled at the filesystem
level due to being part of an encrypted file's contents.  I expect that logic
would be unacceptable upstream, as it's a layering violation.  (The long-term
plan is to handle metadata encryption entirely at the filesystem level instead.)

But with that potentially-controversial logic removed, it would basically be
dm-inline-crypt already, so it would be a good starting point.

- Eric

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [RFC PATCH 0/1] Add inline encryption support for dm-crypt

2022-01-14 Thread Milan Broz

On 13/01/2022 19:09, Israel Rukshin wrote:

Hi,

I am working to add support for inline encryption/decryption
at storage protocols like nvmf over RDMA. The HW that I am
working with is ConnecX-6 Dx, which supports inline crypto
and can send the data on the fabric at the same time.


This idea comes from time to time, and it makes dm-crypt bloated,
and mainly it moves responsibility for encryption to block layer
crypto.
It adds two completely different sector encryption paths there.

Also, see my comments here (for similar patches)
https://lore.kernel.org/dm-devel/c94d425a-bca4-8a8b-47bf-451239d29...@gmail.com/

I think dm-crypt should stay as SW crypto only (using kernel crypto API,
so HW acceleration is done through crypto drivers there).

A cleaner solution is to write a much simpler new dm-crypt-inline target,
which will implement only inline encryption.
(And userspace can decide which target to use.)
Code should be just an extension to the dm-linear target, most
of dm-crypt complexity is not needed here.

Also, please think about configuration - how do you want to configure it?

Just my opinion, it is, of course, up to DM maintainer if he takes such patches.

Thanks,
Milan

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



[dm-devel] [PATCH] dm rq: clear cloned bio ->bi_bdev to fix I/O accounting

2022-01-14 Thread Benjamin Marzinski
bio_clone_fast() sets the cloned bio to have the same ->bi_bdev as the
source bio. This means that when request-based dm called setup_clone(),
the cloned bio had its ->bi_bdev pointing to the dm device. After Commit
0b6e522cdc4a ("blk-mq: use ->bi_bdev for I/O accounting")
__blk_account_io_start() started using the request's ->bio->bi_bdev for
I/O accounting, if it was set. This caused IO going to the underlying
devices to use the dm device for their I/O accounting.

Request-based dm can't be used on top of partitions, so
dm_rq_bio_constructor() can just clear the cloned bio's ->bi_bdev and
have __blk_account_io_start() fall back to using rq->rq_disk->part0 for
the I/O accounting.

Signed-off-by: Benjamin Marzinski 
---
 drivers/md/dm-rq.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 579ab6183d4d..42099dc76e3c 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -328,6 +328,7 @@ static int dm_rq_bio_constructor(struct bio *bio, struct 
bio *bio_orig,
info->orig = bio_orig;
info->tio = tio;
bio->bi_end_io = end_clone_bio;
+   bio->bi_bdev = NULL;
 
return 0;
 }
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel



Re: [dm-devel] [PATCH 1/1] dm crypt: Add inline encryption support

2022-01-14 Thread Damien Le Moal



--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel