Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp379558pxj; Tue, 18 May 2021 05:36:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzqU8ZNSSbpZMM35FGXCGiHqnmyZV3YFEWgEnCS8Cik3KYK5LftsvGB1p/ftQTKezcRtmu X-Received: by 2002:a05:6402:27c6:: with SMTP id c6mr6865719ede.200.1621341373385; Tue, 18 May 2021 05:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621341373; cv=none; d=google.com; s=arc-20160816; b=UsUaFGTixzWoBdT/7Dg+V8T1eS4OexpN5Ch/ic+iY2kfe+Gwy1DpWclxFeX3yzof4d TY2fI5EeQhzlfOfZHjhHQ24fBJvG7GjmyLIDG3wVV/T4SXaoIkQOgePKjI3vrLaJaH9m mPxHSjshW5j1EpO793/c3NhyVUWMHDtJse4EQyDlsNd1KF3P4p4FgYE0r994TS/5uaFJ CLBnfCNgihK3yE+56LrTV7BAQMBMqEUcJTxYoe9badhBmhKrfcc/17vS2iHBuogpa7Wd 4UdVp+A8Dtuf+vNQzvHt5YbebN//ar25BCJ5MBkK+Vf9NNRomkOrPtRA4qLbtQivgJjJ rg4Q== 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=iGq4OI6qWEw6atRTC5Run/ZTKOMJ+IggMIJMzR4l9tM=; b=TRfG1yn8YAHCt0ysxjZmzeflzCyHx3cFNVi0TExV40lSkXHXWzspkTsIO1RftuZ3PO HGXIUARt91LVHkKpyKF0KZ8cN/RkylfjLeejp09dDVRsMv3X6QW/pqxizm7YJUgppU/1 1V+c6bB66RKhuVODGDO1vm0cbpFx+AUWtdDPib3XV6TU3S3gIGC/e3liW0t+oYW6FQi9 /LuxVhb0AgT4swqIh+XAP5c1Q6x2dMeIOp4HrkTti1lyxmAlUg4yauPCawtoTBRr1jDp 3J917BoyMXQL5nz7AgvGyGScT+x7U3drObhIOoqNjkwgwoo+bSrt5rHNdVCjghOiDFVY /s1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Qka3AMw; 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 a20si13942524eje.479.2021.05.18.05.35.46; Tue, 18 May 2021 05:36: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=1Qka3AMw; 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 S242549AbhEQPdq (ORCPT + 99 others); Mon, 17 May 2021 11:33:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:55936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243963AbhEQPSj (ORCPT ); Mon, 17 May 2021 11:18:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 827A861C72; Mon, 17 May 2021 14:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262018; bh=kyz1Z4j1fx7MLGJPzpfVnpMljw7rHnaU+HUC3GaINkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Qka3AMwdOlx4iKO47+xMb0jDBPSNquzZfosc9SJspF40NWfyeKjrKydkn+eQJsAA WxYouxCJSAu92lw3+mIRE3fXYgW26821UGs6DAufwiT4B4dAd7Kp2+kaps5BRU8njw iYXsjQrVacJ5SvqgiVfa7w5LLdxYQHm1ufrrf2KQ= 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 5.11 204/329] ksm: fix potential missing rmap_item for stable_node Date: Mon, 17 May 2021 16:01:55 +0200 Message-Id: <20210517140309.012809493@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 9694ee2c71de..b32391ccf6d5 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -794,6 +794,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