From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C70AC4346E for ; Thu, 24 Sep 2020 07:38:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBF8023787 for ; Thu, 24 Sep 2020 07:38:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z1qNiD11" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbgIXHis (ORCPT ); Thu, 24 Sep 2020 03:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727109AbgIXHir (ORCPT ); Thu, 24 Sep 2020 03:38:47 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1B58C0613D3 for ; Thu, 24 Sep 2020 00:38:47 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id w7so1377315pfi.4 for ; Thu, 24 Sep 2020 00:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/QqvBiEw9Gt+P3YHgYr+bWtezmhdKPwP2m5Qq1GcsHU=; b=Z1qNiD110OoTBunaz5mH/lzfaFLDg7xI1pk48kUrTkDdgKD+LwlEBxfuijD9u/v8Zh sKsLhHFZ/OAmWhbgFBZpDRWrsRPB9bcJ7o/Ri6hQo1gksLg9QWkuOKr5wZt5FcSC+jjT jIXc2hbjlU+X6idHsYaNi/Y4Y/B14HtcpONxvbHA7xmhAU/77Cx9XGBom8e0ceGtDSHM KH+ohR79tHOM9+Ldj+WzhE2h3YpTs+uE+JN4xFgBxBR0fy58mbpZWgMdBfCeqVrz7fEp swX3Yfh/zr9DYukBcTQZJr4/sY9CZbwMZzDyBDZjcl+FavL5gJ0+3nG66xJtHt7oUthE QQ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/QqvBiEw9Gt+P3YHgYr+bWtezmhdKPwP2m5Qq1GcsHU=; b=KT0A24u0yNkQdy/pyNUdPtuN7t2jIv+mer7QZplJZMAVqDbPl33RvWovOfahVfZ/Rh 4lG8F6MJlMbcmhGqDx9c/h6IFuXyIg7QZ8UmxmL9uXaJtdL0dtbhMkHtzHfHPnOa/Y4E a0NMX+rzDjQ6+7jhSIkzGtxV4OWdi16OjHAixxMBKXNEB0TnJo1aYHSVOhuC1NhlmOE7 91oA5hnl5RnyDBMsBt/OiTnekrHd00Gl9W6ee8LHy6crkkzUt0NK34MvtTkzjURfNRpt DHU71wq3kYJ7Z07COwICbVddVU0Wkd80BzsVTJ5TasmqeZozBrYpr4p8ty0kCIngdf+d 6Prw== X-Gm-Message-State: AOAM531jQsVVWbU917pEePAD6bXyPcAZ2VFPvBEZzIJkjcplq/g/K3NJ hsuC5mc66iXjiOGQLKvtZnQepw== X-Google-Smtp-Source: ABdhPJz6VQDT9+FEnimOkDrUbrnKtYN7Qcf2KHw/RUrvRZQCLUJOFfiid//U4dfanjU96NpT9qIOWw== X-Received: by 2002:a05:6a00:14cb:b029:142:2501:34eb with SMTP id w11-20020a056a0014cbb0290142250134ebmr3234176pfu.68.1600933126956; Thu, 24 Sep 2020 00:38:46 -0700 (PDT) Received: from google.com (124.190.199.35.bc.googleusercontent.com. [35.199.190.124]) by smtp.gmail.com with ESMTPSA id 9sm1926053pgx.76.2020.09.24.00.38.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 00:38:46 -0700 (PDT) Date: Thu, 24 Sep 2020 07:38:42 +0000 From: Satya Tangirala To: Mike Snitzer Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Jens Axboe , Alasdair Kergon , Eric Biggers Subject: Re: [PATCH 2/3] dm: add support for passing through inline crypto support Message-ID: <20200924073842.GA1894729@google.com> References: <20200909234422.76194-1-satyat@google.com> <20200909234422.76194-3-satyat@google.com> <20200924012103.GE10500@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924012103.GE10500@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Wed, Sep 23, 2020 at 09:21:03PM -0400, Mike Snitzer wrote: > On Wed, Sep 09 2020 at 7:44pm -0400, > Satya Tangirala wrote: > > > From: Eric Biggers > > > > Update the device-mapper core to support exposing the inline crypto > > support of the underlying device(s) through the device-mapper device. > > > > This works by creating a "passthrough keyslot manager" for the dm > > device, which declares support for encryption settings which all > > underlying devices support. When a supported setting is used, the bio > > cloning code handles cloning the crypto context to the bios for all the > > underlying devices. When an unsupported setting is used, the blk-crypto > > fallback is used as usual. > > > > Crypto support on each underlying device is ignored unless the > > corresponding dm target opts into exposing it. This is needed because > > for inline crypto to semantically operate on the original bio, the data > > must not be transformed by the dm target. Thus, targets like dm-linear > > can expose crypto support of the underlying device, but targets like > > dm-crypt can't. (dm-crypt could use inline crypto itself, though.) > > > > When a key is evicted from the dm device, it is evicted from all > > underlying devices. > > > > Signed-off-by: Eric Biggers > > Co-developed-by: Satya Tangirala > > Signed-off-by: Satya Tangirala > > --- > > block/blk-crypto.c | 1 + > > block/keyslot-manager.c | 34 ++++++++++++ > > drivers/md/dm-core.h | 4 ++ > > drivers/md/dm-table.c | 52 +++++++++++++++++++ > > drivers/md/dm.c | 92 ++++++++++++++++++++++++++++++++- > > include/linux/device-mapper.h | 6 +++ > > include/linux/keyslot-manager.h | 7 +++ > > 7 files changed, 195 insertions(+), 1 deletion(-) > > > > diff --git a/block/blk-crypto.c b/block/blk-crypto.c > > index 2d5e60023b08..33555cf0e3e7 100644 > > --- a/block/blk-crypto.c > > +++ b/block/blk-crypto.c > > @@ -402,3 +402,4 @@ int blk_crypto_evict_key(struct request_queue *q, > > */ > > return blk_crypto_fallback_evict_key(key); > > } > > +EXPORT_SYMBOL_GPL(blk_crypto_evict_key); > > diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c > > index 60ac406d54b9..e0f776c38d8a 100644 > > --- a/block/keyslot-manager.c > > +++ b/block/keyslot-manager.c > > @@ -416,6 +416,40 @@ void blk_ksm_unregister(struct request_queue *q) > > { > > q->ksm = NULL; > > } > > +EXPORT_SYMBOL_GPL(blk_ksm_unregister); > > + > > +/** > > + * blk_ksm_intersect_modes() - restrict supported modes by child device > > + * @parent: The keyslot manager for parent device > > + * @child: The keyslot manager for child device, or NULL > > + * > > + * Clear any crypto mode support bits in @parent that aren't set in @child. > > + * If @child is NULL, then all parent bits are cleared. > > + * > > + * Only use this when setting up the keyslot manager for a layered device, > > + * before it's been exposed yet. > > + */ > > +void blk_ksm_intersect_modes(struct blk_keyslot_manager *parent, > > + const struct blk_keyslot_manager *child) > > +{ > > + if (child) { > > + unsigned int i; > > + > > + parent->max_dun_bytes_supported = > > + min(parent->max_dun_bytes_supported, > > + child->max_dun_bytes_supported); > > + for (i = 0; i < ARRAY_SIZE(child->crypto_modes_supported); > > + i++) { > > + parent->crypto_modes_supported[i] &= > > + child->crypto_modes_supported[i]; > > + } > > + } else { > > + parent->max_dun_bytes_supported = 0; > > + memset(parent->crypto_modes_supported, 0, > > + sizeof(parent->crypto_modes_supported)); > > + } > > +} > > +EXPORT_SYMBOL_GPL(blk_ksm_intersect_modes); > > > > /** > > * blk_ksm_init_passthrough() - Init a passthrough keyslot manager > > diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h > > index c4ef1fceead6..4542050eebfc 100644 > > --- a/drivers/md/dm-core.h > > +++ b/drivers/md/dm-core.h > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > > > @@ -49,6 +50,9 @@ struct mapped_device { > > > > int numa_node_id; > > struct request_queue *queue; > > +#ifdef CONFIG_BLK_INLINE_ENCRYPTION > > + struct blk_keyslot_manager ksm; > > +#endif > > > > atomic_t holders; > > atomic_t open_count; > > Any reason you placed the ksm member where you did? > > Looking at 'struct blk_keyslot_manager' I'm really hating adding that > bloat to every DM device for a feature that really won't see much broad > use (AFAIK). > > Any chance you could allocate 'struct blk_keyslot_manager' as needed so > that most users of DM would only be carrying 1 extra pointer (set to > NULL)? I don't think there's any technical problem with doing that - the only other thing that would need addressing is that the patch uses "container_of" on that blk_keyslot_manager in dm_keyslot_evict() to get a pointer to the struct mapped_device. I could try adding a "private" field to struct blk_keyslot_manager and store a pointer to the struct mapped_device there). > > Thanks, > Mike >