]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
ksm: fix potential missing rmap_item for stable_node
authorMiaohe Lin <linmiaohe@huawei.com>
Wed, 5 May 2021 01:37:45 +0000 (18:37 -0700)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 18 Jun 2021 13:02:15 +0000 (15:02 +0200)
commite8d1066d66a0d759d130891dcc106df1082a35b1
tree03550a6b2ea414886458d3b0f6d568f7085dc5c0
parentbc8e6c696890845d89aa3b3646b18812a0959a25
ksm: fix potential missing rmap_item for stable_node

BugLink: https://bugs.launchpad.net/bugs/1930474
[ Upstream commit c89a384e2551c692a9fe60d093fd7080f50afc51 ]

When removing rmap_item from stable tree, STABLE_FLAG of rmap_item is
cleared with head reserved.  So the following scenario might happen: For
ksm page with rmap_item1:

cmp_and_merge_page
  stable_node->head = &migrate_nodes;
  remove_rmap_item_from_tree, but head still equal to stable_node;
  try_to_merge_with_ksm_page failed;
  return;

For the same ksm page with rmap_item2, stable node migration succeed this
time.  The stable_node->head does not equal to migrate_nodes now.  For ksm
page with rmap_item1 again:

cmp_and_merge_page
 stable_node->head != &migrate_nodes && rmap_item->head == stable_node
 return;

We would miss the rmap_item for stable_node and might result in failed
rmap_walk_ksm().  Fix this by set rmap_item->head to NULL when rmap_item
is removed from stable tree.

Link: https://lkml.kernel.org/r/20210330140228.45635-5-linmiaohe@huawei.com
Fixes: 4146d2d673e8 ("ksm: make !merge_across_nodes migration safe")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
mm/ksm.c