Commit d5567c9d authored by Vitaly Wool's avatar Vitaly Wool Committed by Linus Torvalds

z3fold: fix potential race in z3fold_reclaim_page

It is possible that on a (partially) unsuccessful page reclaim,
kref_put() called in z3fold_reclaim_page() does not yield page release,
but the page is released shortly afterwards by another thread.  Then
z3fold_reclaim_page() would try to list_add() that (released) page again
which is obviously a bug.

To avoid that, spin_lock() has to be taken earlier, before the
kref_put() call mentioned earlier.

Link: default avatarVitaly Wool <>
Cc: Dan Streetman <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent d9d73e81
......@@ -875,16 +875,18 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
goto next;
if (test_bit(PAGE_HEADLESS, &page->private)) {
if (ret == 0) {
return 0;
} else if (kref_put(&zhdr->refcount, release_z3fold_page)) {
return 0;
* Add to the beginning of LRU.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment