Re: block: sleeping in atomic warnings

From: Linus Torvalds
Date: Tue Feb 07 2023 - 11:15:42 EST


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.

Linus