Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp460473pxj; Thu, 20 May 2021 13:29:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU1THQ+IV4q9Ptt1IlAyXqgfRSDZBf7pBkLpPVZaDMzf+BfHsgPW44TEpYlUUm8Dc8dXGN X-Received: by 2002:a05:6e02:1a67:: with SMTP id w7mr6228450ilv.137.1621542553904; Thu, 20 May 2021 13:29:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621542553; cv=none; d=google.com; s=arc-20160816; b=XEmknULhk93J0uE0qgzSpVxgL/+gyRafCR4P6vvgGDh7OIqJsWe3n4XNeyVwxz/Gea lsTU9MevYNY/iXkSeuGjwcBF9rQfgW1VvZvDF8LFeA/m/r7O/RghAMHVDzi6FJXuXrg8 vDZMBP7m9mWJUqjRGamDWBN/1+YcWvWjSokwZSsnQLL+rpkQrcMHL7qlTUrCmmjj1EVK iwVyfFTa5qvl2l/nBwy9qzfrG0AShodsH+AnwX6dIPEEXWNBGYMDVUUg0jm2g9uysTVA Oiqc0vziB/zV2ct/ou/pvKyxgdF67WK3pen2TIP9Qz0vqMCQLr//Pe4jLGOceysU4tgI 8KJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zFsdzCD/eeKaYNjTqdibKr7X/m+jca+kl7x5oVashNM=; b=MLGE9LU7bgYomRnMZbbJm/dXnko8xN+fFKcbzUVhbKGBuwZ9eNxZjGnYvk+4OhnUj9 nl3tIvtPNK3hwSTlgjWm6K0Xr03BDBDoHVBWRok0a+74jCJUKGqHoD85KPaLExEEwQ2l pftfL+DrQ4/W9PtEtxT/j55N8ToVwJhwnPIAI7Bfxxi1bpAWLsS+e5thfXDBuBL1S9V2 ULjeX85oB55tAmmhalfJ8X8QIfu9vvIffzK7qbKUdgrv3VQy7/Q3bmX/auOdbSZfwZQp GTwWcTFxurH27PqhpavHxZhheRb0JU28OA8in0Eoz11lTJN9YsyyNxZK07HcVsH+iHDY Pm3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lXuBviGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si3048760ioh.5.2021.05.20.13.29.00; Thu, 20 May 2021 13:29:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lXuBviGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238381AbhETKyJ (ORCPT + 99 others); Thu, 20 May 2021 06:54:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:39660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237734AbhETKil (ORCPT ); Thu, 20 May 2021 06:38:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C02A61C71; Thu, 20 May 2021 09:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504499; bh=olxwLQKUoh0pv7hlajAdGVNyIeCmb2yMv6GLGAzdL9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lXuBviGuzR6qq0xJoczMWa68My7HUW6WZ8Y5gCveYU0jvkpsopt3njgUJdFdLrhzX j1+NjCU9Bfxd7xW0KTzDZPYtZWQNkXWC/wuHCZfC/waMV/iIm1fn+5ms3omFsy1eUp 2YzdDUjRy9GeImorrRYFS9K/u9Pxrchv9XvqIWDc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Hugh Dickins , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 272/323] ksm: fix potential missing rmap_item for stable_node Date: Thu, 20 May 2021 11:22:44 +0200 Message-Id: <20210520092129.548113494@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ 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 Cc: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/ksm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/ksm.c b/mm/ksm.c index 65d4bf52f543..6d3bc2723c9b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -768,6 +768,7 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item) stable_node->rmap_hlist_len--; put_anon_vma(rmap_item->anon_vma); + rmap_item->head = NULL; rmap_item->address &= PAGE_MASK; } else if (rmap_item->address & UNSTABLE_FLAG) { -- 2.30.2