Skip to content

Commit

Permalink
ksm: fix unlocked iteration over vmas in cmp_and_merge_page()
Browse files Browse the repository at this point in the history
In this place mm is unlocked, so vmas or list may change.  Down read
mmap_sem to protect them from modifications.

Link: http://lkml.kernel.org/r/150512788393.10691.8868381099691121308.stgit@localhost.localdomain
Fixes: e86c59b ("mm/ksm: improve deduplication of zero pages with colouring")
Signed-off-by: Kirill Tkhai <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Reviewed-by: Andrea Arcangeli <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: zhong jiang <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Claudio Imbrenda <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Kirill Tkhai authored and torvalds committed Oct 4, 2017
1 parent fa87b91 commit 4b22927
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mm/ksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ static void stable_tree_append(struct rmap_item *rmap_item,
*/
static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item)
{
struct mm_struct *mm = rmap_item->mm;
struct rmap_item *tree_rmap_item;
struct page *tree_page = NULL;
struct stable_node *stable_node;
Expand Down Expand Up @@ -2062,9 +2063,11 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item)
if (ksm_use_zero_pages && (checksum == zero_checksum)) {
struct vm_area_struct *vma;

vma = find_mergeable_vma(rmap_item->mm, rmap_item->address);
down_read(&mm->mmap_sem);
vma = find_mergeable_vma(mm, rmap_item->address);
err = try_to_merge_one_page(vma, page,
ZERO_PAGE(rmap_item->address));
up_read(&mm->mmap_sem);
/*
* In case of failure, the page was not really empty, so we
* need to continue. Otherwise we're done.
Expand Down

0 comments on commit 4b22927

Please sign in to comment.