]> git.ipfire.org Git - people/arne_f/kernel.git/commit - mm/z3fold.c
mm/z3fold.c: use kref to prevent page free/compact race
authorVitaly Wool <vitalywool@gmail.com>
Fri, 17 Nov 2017 23:26:16 +0000 (15:26 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Nov 2017 08:40:44 +0000 (08:40 +0000)
commitc1a14af38a50f714fb32581fcd083b49a28c7d41
treed33e235307f9f0391ed489c6431018eec5564c39
parent769bfea594f5edb92b077b50ee58866a989ca2bb
mm/z3fold.c: use kref to prevent page free/compact race

commit 5d03a6613957785e94af7a4a6212ad4af66aa5c2 upstream.

There is a race in the current z3fold implementation between
do_compact() called in a work queue context and the page release
procedure when page's kref goes to 0.

do_compact() may be waiting for page lock, which is released by
release_z3fold_page_locked right before putting the page onto the
"stale" list, and then the page may be freed as do_compact() modifies
its contents.

The mechanism currently implemented to handle that (checking the
PAGE_STALE flag) is not reliable enough.  Instead, we'll use page's kref
counter to guarantee that the page is not released if its compaction is
scheduled.  It then becomes compaction function's responsibility to
decrease the counter and quit immediately if the page was actually
freed.

Link: http://lkml.kernel.org/r/20171117092032.00ea56f42affbed19f4fcc6c@gmail.com
Signed-off-by: Vitaly Wool <vitaly.wool@sonymobile.com>
Cc: <Oleksiy.Avramchenko@sony.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/z3fold.c