Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp558365pxj; Thu, 20 May 2021 16:11:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV/Zl0xmMEOBQqQgZ/2SA1qloAtk+MxBKFsnPGzwOsBKepl563PaPLzVW567dqmRnyLYnV X-Received: by 2002:a05:6402:22c9:: with SMTP id dm9mr7589467edb.281.1621552301676; Thu, 20 May 2021 16:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552301; cv=none; d=google.com; s=arc-20160816; b=ZuC1WQ1YioGlMCPfn5gJAJYKBN6fHbGdWG/jsul9QdZzv5+mgsKxSRFZQnw9gacZSY xo9pEL7EhE+0Cd8/fOK74UGDT5V6OgbfJE9rQJxaQeEJiuin1D7Pgg+wl1wkkm4cKH8x l5oXYuocwoyX237elzDu3/ieg+oj0ScpzxYHErqIMfVqy4/y8xmV9xHC2l4s4YnZJDap +YjSnyMUzT/Pk+KNFGTJnqH8VOxQo6riXw1EwzL68Z6GColdMYHJjOCjk5zCXQMdbXKa zNLZEeSP+UCKImoJH2SEoAcXaFh/gr1q2LZ8eBpPYujkK4Dqn6MmBGVJ/AbnOEGc2HmA h0jw== 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=t0KcUQab8Eqi4FZ2MoMlxUzmir2zAmEOJNdURrWFq/M=; b=XIZHLpoJNyadDOo9c8pSACjCF7+p7CCjkw5rVvvvA0UzIBWjAH3euiMAXrwdrJlfYM ZrkcCcg8Znasve6/ba3IrT+TDadF9rYqcWXUWOXzclh0/LZMGX0AUlTStFZNzre5AvmT us4o8JmOmudZsGgl9N7Weg6OAHCoBfMgn2L2UTo3nBirrI+3cDlsaud1f4PHPakPwQuR Zabw+Uq3B5DNcjPNKPHUy5u0g4fvm5FmHHgsxBomvyr8iZCv8GF291ZN+hecU/knj7yP OxlIDIDPHO/wn4w7U1nrshK3cQM2HlPzC9Vxn8PWwTEOSX4sfFd7C0qyL5rcCOkgRpVA 2buA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cUGCxf8e; 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 gt43si3250938ejc.459.2021.05.20.16.11.17; Thu, 20 May 2021 16:11:41 -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=cUGCxf8e; 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 S239244AbhETLXo (ORCPT + 99 others); Thu, 20 May 2021 07:23:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:59276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238055AbhETLDF (ORCPT ); Thu, 20 May 2021 07:03:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8FF9161926; Thu, 20 May 2021 10:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505058; bh=rKn9MHJ5/JUR77Gzufu0d8whZCTWHBYin00CJMH6BIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cUGCxf8eMujpsvibb88wuUhhCVdYzUm15XMcYY+Vc+5Qi/hhdMenIC6oMT6gLUqVv x8iyW6z5eOuIXgMUOzJtqestus2/Uc8i/QQEPNmWrXgEdKRE2FUI4R0GPgnJMmBani hG596ODTZ3sV606rElu9ly1qxg0/Q16RmkNUT5EI= 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.9 203/240] ksm: fix potential missing rmap_item for stable_node Date: Thu, 20 May 2021 11:23:15 +0200 Message-Id: <20210520092115.472450276@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 d6c81a5076a7..27ff68050d85 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -629,6 +629,7 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item) ksm_pages_shared--; 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