OSDN Git Service

z3fold: fix page locking in z3fold_alloc()
authorVitaly Wool <vitalywool@gmail.com>
Thu, 13 Apr 2017 21:56:14 +0000 (14:56 -0700)
committer0ranko0P <ranko0p@outlook.com>
Tue, 24 Dec 2019 20:42:28 +0000 (04:42 +0800)
commit4fafbdaf538aeb42fdac1c3bc705d1e4fb9f2f28
tree234a4720c3919c279c18e4b35ac1733692f092d3
parentc43ee467526aa31dade1aeacb5835337330fa4e1
z3fold: fix page locking in z3fold_alloc()

Stress testing of the current z3fold implementation on a 8-core system
revealed it was possible that a z3fold page deleted from its unbuddied
list in z3fold_alloc() would be put on another unbuddied list by
z3fold_free() while z3fold_alloc() is still processing it.  This has
been introduced with commit 5a27aa822 ("z3fold: add kref refcounting")
due to the removal of special handling of a z3fold page not on any list
in z3fold_free().

To fix this, the z3fold page lock should be taken in z3fold_alloc()
before the pool lock is released.  To avoid deadlocking, we just try to
lock the page as soon as we get a hold of it, and if trylock fails, we
drop this page and take the next one.

Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: <Oleksiy.Avramchenko@sony.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/z3fold.c