Re: [PATCH v2] blk-crypto: use a NOIO scope while holding profile->lock
From: Eric Biggers
Date: Tue Nov 24 2026 - 20:45:05 EST
On Mon, Nov 23, 2026 at 10:14:08AM -0800, Laveesh Bansal wrote:
> setkey allocates with GFP_KERNEL (Adiantum)
We should just fix that one:
https://lore.kernel.org/linux-crypto/20261125013553.94480-1-ebiggers@xxxxxxxxxx/
We should still proceed with this patch, but there is really no need for
the crypto code to allocate memory in random places. I've been working
on getting rid of cases like this.
> Fixes: 488f6682c832 ("block: blk-crypto-fallback for Inline Encryption")
> Cc: stable@xxxxxxxxxxxxxxx # v7.3+
The v7.3+ should not be there.
> @@ -53,11 +54,14 @@ static inline void blk_crypto_hw_enter(struct blk_crypto_profile *profile)
> if (profile->dev)
> pm_runtime_get_sync(profile->dev);
> down_write(&profile->lock);
> + /* Reclaim evicts keys under this lock; don't recurse into the fs. */
> + profile->memflags = memalloc_noio_save();
> }
"don't recurse into the fs" describes memalloc_nofs_save(), but the code
actually uses memalloc_noio_save(). The code is right, so a better
comment might be:
/* Avoid recursing into I/O or fs reclaim while holding profile->lock */
> static inline void blk_crypto_hw_exit(struct blk_crypto_profile *profile)
> __releases(&profile->lock)
> {
> + memalloc_noio_restore(profile->memflags);
Storing the flags in blk_crypto_profile isn't necessary. It should just
be a stack variable, returned by blk_crypto_hw_enter() and consumed by
blk_crypto_hw_exit().
- Eric