Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9ee2d78 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mark Salyzyn
Browse files

UPSTREAM: dm crypt: avoid deadlock in mempools



(cherry pick from commit 7145c241a1bf2841952c3e297c4080b357b3e52d)

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.

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 that fails, we fallback to a
blocking allocations with a mutex.

Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Bug: 25392275
Change-Id: I6b326fb2432bba5f658f522f2c555ad5d2bb65b8
parent 0c348b04
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment