]> git.karo-electronics.de Git - karo-tx-linux.git/commit
dm crypt: avoid deadlock in mempools
authorMikulas Patocka <mpatocka@redhat.com>
Fri, 28 Mar 2014 19:51:56 +0000 (15:51 -0400)
committerMike Snitzer <snitzer@redhat.com>
Thu, 29 May 2014 16:44:57 +0000 (12:44 -0400)
commit980971091db20e333fb556451f37fbb895dce3ff
tree7a6cf31b76644705744d118b35017d6449f131c5
parent8c47f205d60664f93834f382540481f35112f509
dm crypt: avoid deadlock in mempools

Fix a theoretical deadlock introduced in the previous commit ("dm crypt:
don't allocate pages for a partial request").

The function crypt_alloc_buffer may be called concurrently.  If we allocate
from the mempool concurrently, there is a possibility of deadlock.  For
example, if we have mempool of 256 pages, two processes, each wanting
256, pages allocate from the mempool concurrently, it may deadlock in a
situation where both processes have allocated 128 pages and the mempool
is exhausted.

In order to avoid such a scenario, we allocate the pages under a mutex.

In order to not degrade performance with excessive locking, we try
non-blocking allocations without a mutex first and if it fails, we
fallback to a blocking allocation with a mutex.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-crypt.c