Re: block: sleeping in atomic warnings

From: Eric Biggers
Date: Tue Feb 07 2023 - 12:53:44 EST


On Tue, Feb 07, 2023 at 08:15:04AM -0800, Linus Torvalds wrote:
> On Tue, Feb 7, 2023 at 6:06 AM Dan Carpenter <error27@xxxxxxxxx> wrote:
> >
> > block/blk-crypto-profile.c:382 __blk_crypto_evict_key() warn: sleeping in atomic context
> > block/blk-crypto-profile.c:390 __blk_crypto_evict_key() warn: sleeping in atomic context
>
> Yeah, that looks very real, but doesn't really seem to be a block bug.
>
> __put_super() has a big comment that it's called under the sb_lock
> spinlock, so it's all in atomic context, but then:
>
> > -> __put_super()
> > -> fscrypt_destroy_keyring()
> > -> fscrypt_put_master_key_activeref()
> > -> fscrypt_destroy_prepared_key()
> > -> fscrypt_destroy_inline_crypt_key()
> > -> blk_crypto_evict_key()
>
> and we have a comment in __blk_crypto_evict_key() that it must be
> called in "process context".
>
> However, the *normal* unmount sequence does all the cleanup *before*
> it gets sb_lock, and calls fscrypt_destroy_keyring() in process
> context, which is probably why it never triggers in practice, because
> the "last put" is normally there, not in __put_super.
>
> Eric? Al?
>
> It smells like __put_super() may need to do some parts delayed, not
> under sb_lock.
>

It's a false positive. See the comment above fscrypt_destroy_keyring(), which
is meant to explain this, though I can update the comment to be clearer. If the
filesystem has been mounted, then fscrypt_destroy_keyring() is called from
generic_shutdown_super(), which can sleep, and the call from __put_super() is a
no-op. If the filesystem has not been mounted, then the call from __put_super()
is needed, but blk_crypto_evict_key() can never be executed in that case.

- Eric