From: Eric Biggers <ebiggers@kernel.org>
To: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: Jens Axboe <axboe@kernel.dk>, Satya Tangirala <satyat@google.com>,
linux-block@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH] blk-crypto: dynamically allocate fallback profile
Date: Tue, 8 Aug 2023 23:55:02 -0700 [thread overview]
Message-ID: <20230809065502.GA1571@sol.localdomain> (raw)
In-Reply-To: <20230808172536.211434-1-sweettea-kernel@dorminy.me>
On Tue, Aug 08, 2023 at 01:25:30PM -0400, Sweet Tea Dorminy wrote:
> blk_crypto_profile_init() calls lockdep_register_key(), which asserts
> that the provided memory is not a static object. Unfortunately,
> blk-crypto-fallback currently has a single static blk_crypto_profile,
> which means trying to use the fallback with lockdep explodes in
> blk_crypto_fallback_init().
>
> Fortunately it is simple enough to use a dynamically allocated profile
> for fallback, allowing the use of lockdep.
>
> Fixes: 488f6682c832e ("block: blk-crypto-fallback for Inline Encryption")
> Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
> ---
> block/blk-crypto-fallback.c | 27 +++++++++++++++------------
> 1 file changed, 15 insertions(+), 12 deletions(-)
Thanks for catching this! My bad for not running xfstests with the inlinecrypt
mount option recently. Can you use the correct Fixes tag:?
Fixes: 2fb48d88e77f ("blk-crypto: use dynamic lock class for blk_crypto_profile::lock")
Cc: stable@vger.kernel.org
Also, when describing the problem please try to be more specific than
"explodes". I just get a WARN_ON. Beyond that, presumably it just makes
lockdep not track blk_crypto_fallback_profile.lock?
> @@ -534,29 +534,32 @@ static int blk_crypto_fallback_init(void)
> {
> int i;
> int err;
> - struct blk_crypto_profile *profile = &blk_crypto_fallback_profile;
>
> if (blk_crypto_fallback_inited)
> return 0;
>
> get_random_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
>
> + blk_crypto_fallback_profile =
> + kzalloc(sizeof(*blk_crypto_fallback_profile), GFP_KERNEL);
> +
Maybe add a comment:
/* Dynamic allocation is needed because of lockdep_register_key(). */
Also, kzalloc() should be checked for failure.
Can you consider folding the following into your patch?
diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c
index de94e9bffec6d..0764668a78157 100644
--- a/block/blk-crypto-fallback.c
+++ b/block/blk-crypto-fallback.c
@@ -540,17 +540,21 @@ static int blk_crypto_fallback_init(void)
get_random_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
- blk_crypto_fallback_profile =
- kzalloc(sizeof(*blk_crypto_fallback_profile), GFP_KERNEL);
-
err = bioset_init(&crypto_bio_split, 64, 0, 0);
if (err)
goto out;
+ /* Dynamic allocation is needed because of lockdep_register_key(). */
+ blk_crypto_fallback_profile =
+ kzalloc(sizeof(*blk_crypto_fallback_profile), GFP_KERNEL);
+ if (!blk_crypto_fallback_profile) {
+ err = -ENOMEM;
+ goto fail_free_bioset;
+ }
+
err = blk_crypto_profile_init(blk_crypto_fallback_profile,
blk_crypto_num_keyslots);
if (err)
- goto fail_free_bioset;
+ goto fail_free_profile;
err = -ENOMEM;
blk_crypto_fallback_profile->ll_ops = blk_crypto_fallback_ll_ops;
@@ -601,6 +605,8 @@ static int blk_crypto_fallback_init(void)
destroy_workqueue(blk_crypto_wq);
fail_destroy_profile:
blk_crypto_profile_destroy(blk_crypto_fallback_profile);
+fail_free_profile:
+ kfree(blk_crypto_fallback_profile);
fail_free_bioset:
bioset_exit(&crypto_bio_split);
out:
prev parent reply other threads:[~2023-08-09 6:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 17:25 [PATCH] blk-crypto: dynamically allocate fallback profile Sweet Tea Dorminy
2023-08-09 6:55 ` Eric Biggers [this message]
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=20230809065502.GA1571@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=axboe@kernel.dk \
--cc=kernel-team@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=satyat@google.com \
--cc=sweettea-kernel@dorminy.me \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.