Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp505102pxj; Tue, 18 May 2021 08:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwntd/bm/Jk9OVStpJVhc2AQzPPClqmqXlmImALTDZ42MFR/WhLcRmFeN8ME1Sy+9EdFzsh X-Received: by 2002:a17:906:aac8:: with SMTP id kt8mr6342646ejb.402.1621350687692; Tue, 18 May 2021 08:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621350687; cv=none; d=google.com; s=arc-20160816; b=PAZTzC29aIXn8zBOukQm4ZkOdOAKmao67+y7U0YME0agTJ88dgM14C3+Ey26Faor6J 3F+zc27jHva6pqAc5PvmjfaNOwwLxHtW/TOlQuoEZoznjISz1KSwEgmpcZtZBPnPr1yH TsE+HAVblsawbLyIXw1ScoAcngeuP6UrjjsbpFfiH6Tu2vXUpoVbvQOroKI3X0vJQgO3 o6KfFayLl/GFgtZQX7AHgbcVBEpOTGz53zoweVfhXk1gAIk2g8tabbafxHwifOFZ4z82 AyXwoY5tpCS8CjOgOgSPtdfN/4ANM3UjEL8ionEOPl83MfrdNMlXPmzQkQs0yfbsMEob n5Vg== 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=cecHJzX3kO4Cz/oD/b/kVUrG/nCRYfksg3lJDp31Jdc=; b=HuR+4KtlIMQMsbgKRpgHnDuGqIfREk/WxKwO/tBvl8GmBwexRs5dWv2LZMr1kTNzDJ 0GD5jQket39grAOQBE1hK3c5kW8LnAsO++pUe/fge7p4z0XBp7OhDRC4T6ozCA5OuJLM ZF0YkTR5OELVbeWIbM8Bo772gk51r7q7hLijc39lhZJ88xhOKeEQSAE+NyZeRz1gaHFu Ah8HSTfMczoHQAWir0Cy4ZlwedAK4Rv9WK5KtZHY6clcUeWh+l1Bb94hf69EJmdnmWKd SU+6j9K5ZjmTQlKVqrWChJb8QTbVPFG5H0VIO+uK1SLzdPLQ7CVArJCv1Hoj1NrDi7nd kuhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h71v7jxO; 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 y16si20099378edq.499.2021.05.18.08.10.55; Tue, 18 May 2021 08:11:27 -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=h71v7jxO; 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 S1344158AbhEQPxG (ORCPT + 99 others); Mon, 17 May 2021 11:53:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:40234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343676AbhEQPel (ORCPT ); Mon, 17 May 2021 11:34:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 55B4261CDD; Mon, 17 May 2021 14:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262367; bh=AQQsHeO/eAhoPS2KIBtkrM+ms+deUAjdQFkOP7e1G+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h71v7jxOEyYz/81h0/KGz6R9MB70YH4V2EyAChR0hPRusLO9Yy4uZf9GfhQPWiOX1 62VYziZ74KyVtuyZ3bSeIKd0UzNeodGFJXEV3b/TSw0NtqtR1/eD5xh9OKxPsmehld HIu7/qCGno+9HtOgWrvRzcKJbG69Pe9k0eza/B0s= 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.10 169/289] ksm: fix potential missing rmap_item for stable_node Date: Mon, 17 May 2021 16:01:34 +0200 Message-Id: <20210517140310.809863002@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 0960750bb316..25b8362a4f89 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