Skip to content

Commit

Permalink
mm/z3fold.c: lock z3fold page before __SetPageMovable()
Browse files Browse the repository at this point in the history
Following zsmalloc.c's example we call trylock_page() and unlock_page().
Also make z3fold_page_migrate() assert that newpage is passed in locked,
as per the documentation.

[[email protected]: fix trylock_page return value test, per Shakeel]
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Henry Burns <[email protected]>
Suggested-by: Vitaly Wool <[email protected]>
Acked-by: Vitaly Wool <[email protected]>
Acked-by: David Rientjes <[email protected]>
Reviewed-by: Shakeel Butt <[email protected]>
Cc: Vitaly Vul <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Xidong Wang <[email protected]>
Cc: Jonathan Adams <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
HenryBurns authored and torvalds committed Jul 12, 2019
1 parent dd92399 commit 810481a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mm/z3fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,16 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
set_bit(PAGE_HEADLESS, &page->private);
goto headless;
}
__SetPageMovable(page, pool->inode->i_mapping);
if (can_sleep) {
lock_page(page);
__SetPageMovable(page, pool->inode->i_mapping);
unlock_page(page);
} else {
if (trylock_page(page)) {
__SetPageMovable(page, pool->inode->i_mapping);
unlock_page(page);
}
}
z3fold_page_lock(zhdr);

found:
Expand Down Expand Up @@ -1331,6 +1340,7 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa

VM_BUG_ON_PAGE(!PageMovable(page), page);
VM_BUG_ON_PAGE(!PageIsolated(page), page);
VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);

zhdr = page_address(page);
pool = zhdr_to_pool(zhdr);
Expand Down

0 comments on commit 810481a

Please sign in to comment.