linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Deadlock when using crypto API for block devices
@ 2018-08-23 20:39 Mikulas Patocka
  2018-08-24  2:10 ` Herbert Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Mikulas Patocka @ 2018-08-23 20:39 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller
  Cc: linux-crypto, Mike Snitzer, dm-devel, linux-kernel

Hi

There's a deadlock reported here: 
https://bugzilla.kernel.org/show_bug.cgi?id=200835

* dm-crypt calls crypt_convert in xts mode
* init_crypt from xts.c calls kmalloc(GFP_KERNEL)
* kmalloc(GFP_KERNEL) recurses into the XFS filesystem, the filesystem 
	tries to submit some bios and wait for them, causing a deadlock

I was thinking how to fix it, there are several possibilities, but all 
have some caveats. So, I'd like to ask you as crypto code maintainers, 
what's the appropriate solution.


1. don't set CRYPTO_TFM_REQ_MAY_SLEEP in dm-crypt
=================================================
If we don't set it, dm-crypt will use GFP_ATOMIC and GFP_ATOMIC may fail. 
The function init_crypt in xts.c handles the failure gracefully - but the 
question is - does the whole crypto code handle allocation failures 
gracefully? If not and if it returns -ENOMEM somewhere, it would result in 
I/O errors and data corruption.

I'd like to ask if you as maintainers of the crypto API could say, whether 
the crypto code handles GFP_ATOMIC allocations failure gracefully or not.

Note that dm-crypt currently uses encryption, hashes and authernticated 
encryption, so if we go down this path, we must make sure that the code 
for these operations will never return -ENOMEM.

2. use memalloc_noio_save/memalloc_noio_restore in dm-crypt
===========================================================
This makes all allocations use GFP_NOIO implicitly, so it would fix the 
deadlock. But - the crypto API can offload encryption to the cryptd 
thread, and if the offload happens, the memalloc_noio_save flag is lost 
and the allocation can still be done with GFP_KERNEL and cause a deadlock.

3. introduce new flag CRYPTO_TFM_REQ_MAY_SLEEP_NOIO
===================================================
Would you like to introduce it?

4. make the whole crypto code use GFP_NOIO instead of GFP_KERNEL?
=================================================================


... any other suggestions?

Mikulas

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-08-24 16:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-23 20:39 Deadlock when using crypto API for block devices Mikulas Patocka
2018-08-24  2:10 ` Herbert Xu
2018-08-24 11:06   ` Mikulas Patocka
2018-08-24 11:22     ` Mikulas Patocka
2018-08-24 11:25       ` Herbert Xu
2018-08-24 11:24     ` Herbert Xu
2018-08-24 12:37       ` Mikulas Patocka
2018-08-24 13:00         ` Mikulas Patocka
2018-08-24 13:21           ` Herbert Xu
2018-08-24 13:22             ` Herbert Xu
2018-08-24 16:02               ` Dave Watson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).