From patchwork Wed Mar 6 15:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13584238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A385C54E41 for ; Wed, 6 Mar 2024 15:52:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0AFB6B0083; Wed, 6 Mar 2024 10:52:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBAA66B0085; Wed, 6 Mar 2024 10:52:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C827C6B0088; Wed, 6 Mar 2024 10:52:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B5BF66B0083 for ; Wed, 6 Mar 2024 10:52:01 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 82762805A7 for ; Wed, 6 Mar 2024 15:52:01 +0000 (UTC) X-FDA: 81867055242.14.961BDE7 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) by imf14.hostedemail.com (Postfix) with ESMTP id 63CE3100012 for ; Wed, 6 Mar 2024 15:51:59 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="k dEmKqC"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=qndP8us+; spf=pass (imf14.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.157 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709740319; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=ff578PMopIxtDhAZSekNz6TpN9rdsoY/51EawT6DkeU=; b=1dsBzkjI/bH92DqCqposnhHa1QZReL82M4pgntQ+NoevCSJxrl6Og2RdLrBgbU2tdgrTnV 0Z+7Kr/qkhfIG0qSCGKwK2RdCOenVmS1dWsuxdsKGbohcgkgM77Y8GwHH8x+KxK49lhfh6 spiKL9eN5RCZ4iiVffAzWnj2Vox8fWM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709740319; a=rsa-sha256; cv=none; b=U4tPLD3D7eRLfQyal7TypKYchDOtpMJMq8470TvLq676xrJ6PdQweh55+7WFldnrFmFWKT 86kklLDgLTZ47wtpBzhadOkKsbl2d3sN9H2s91t2lGO9Lc7nWu0WGgNG9q8md3PcVq0reX 1kLOIm94e8Ak1EHn51vBhHlOCunx4ko= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="k dEmKqC"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=qndP8us+; spf=pass (imf14.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.157 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A59BE114010C; Wed, 6 Mar 2024 10:51:58 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Mar 2024 10:51:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :reply-to:subject:subject:to:to; s=fm1; t=1709740318; x= 1709826718; bh=ff578PMopIxtDhAZSekNz6TpN9rdsoY/51EawT6DkeU=; b=k dEmKqCYgAa244AhkT2l8FdhpDT5ao0XBEoGOpjuObR6HS1EZgGJRWB2lDlMiQMw0 KkxrS1olfoP1c3FWfjL5/XQ0rvI93pWZsVkbywZt0HCiQFrCm2JVC69Mjv+XPuRQ Fdn/1z4maHwkI0kfkSzcPLj9vyNe3y6OiX/D9NOiJ093APu4n5NoTfDsfMlelDcM 3/wu+Kg/RfXGqSFzDDNAO9AijOAVErnhRFMJrphYQfunpipsPeaUN5RMbdtHDXHQ szZXjP7r8lkZcT0iLe2Ce+r52PrnMVS6Pd3qePDcrHCP13AoPDqW/ws54/WQloRy zWpBjh8vwJiTvqBvE+7jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:reply-to :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1709740318; x=1709826718; bh=f f578PMopIxtDhAZSekNz6TpN9rdsoY/51EawT6DkeU=; b=qndP8us+gKjIAuHre CKIjxP89J/zPdtmk2Zfu8aNBxgrVeQrilAZPEfQpVb9s4EBbvCUnzXYiq8BgFh6x FM1FGJKpCLwlb76pFCyN8zHrgdAZBpP6T0zqOritsMqfwOhLuJ+lNULwBpuSvXti zaMb4l8PVByoXBmbI6how9grgj2WVfCyiNH1W6lHvkPfLuzu5EbHevIQglaCMwP/ gzw4IPOzUFt48xbHI3D8+DGnBkO+lNfgZG+0N7qnCGztPmDtzYLTfYN3WDaHEsp8 le0iA2/wdwvVRV/CK2kwiktM4Ld/C8to45tTRmffVV6ptPOXY5h2VEgjTNJS4VOU xbWoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkfforhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeetudevhe etheehieetiefhjeevjeeltdfgvdeiueeiudetffdtvedthfetvedtffenucffohhmrghi nhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Mar 2024 10:51:58 -0500 (EST) From: Zi Yan To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Zi Yan , linux-mm@kvack.org, Charan Teja Kalla , "Matthew Wilcox (Oracle)" , David Hildenbrand , Andrew Morton , Huang Ying , Naoya Horiguchi Subject: [PATCH STABLE v5.15.y] mm/migrate: set swap entry values of THP tail pages properly. Date: Wed, 6 Mar 2024 10:51:57 -0500 Message-ID: <20240306155157.118343-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: jfagtgtsufn9oc35tos9euto7drbaqeg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 63CE3100012 X-Rspam-User: X-HE-Tag: 1709740319-508522 X-HE-Meta: U2FsdGVkX18REM3R5gyvxQYn+Jp4NSQEKr6q8h4DvrTtbDr+dB9YWKVYg4Farlzgt7LsJsKAN/x04cYtAhLAehUPh46Okiq/CHYl8QLOIxshlQrfOOGVJn0p+EP0eBJDQKlp2PPk4mGdfLN1Lgf42LWbqMe6+oRllW7i3ken5hUy64XwaQsVRjfA3xLOOL6XFf1AFda/bwfxnE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ITgnxNXGtCZHcaUSrRxKVRm7hLfZJQFuT+QjqFRKVp1L2QVJho/Qqv6wfditMoqCGCb/N4KCo54ZeH46Xkiqqm3gp/K9FIVQffDGY2It5j6vvjvXkRDjO138hxXDoWeVur+JEGptWWvTYMwptsKKqsHDwtZGmHcLVKoTWizqbZMMeW5ke+FQkxbMBUg2hKSfIcWa+53MroX55R19wWrnBJbCsLjk02aIpGZ5dIj9dJZPkU2wIADo/5x+8fPM8ckEDSohPz9HrQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zi Yan The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption. This fix is stable-only, since after commit 07e09c483cbe ("mm/huge_memory: work on folio->swap instead of page->private when splitting folio"), subpages of a swapcached THP no longer requires the maintenance. Adding THPs to the swapcache was introduced in commit 38d8b4e6bdc87 ("mm, THP, swap: delay splitting THP during swap out"), where each subpage of a THP added to the swapcache had its own swapcache entry and required the ->private field to point to the correct swapcache entry. Later, when THP migration functionality was implemented in commit 616b8371539a6 ("mm: thp: enable thp migration in generic path"), it initially did not handle the subpages of swapcached THPs, failing to update their ->private fields or replace the subpage pointers in the swapcache. Subsequently, commit e71769ae5260 ("mm: enable thp migration for shmem thp") addressed the swapcache update aspect. This patch fixes the update of subpage ->private fields. Closes: https://lore.kernel.org/linux-mm/1707814102-22682-1-git-send-email-quic_charante@quicinc.com/ Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path") Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index c7d5566623ad..c37af50f312d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -424,8 +424,12 @@ int migrate_page_move_mapping(struct address_space *mapping, if (PageSwapBacked(page)) { __SetPageSwapBacked(newpage); if (PageSwapCache(page)) { + int i; + SetPageSwapCache(newpage); - set_page_private(newpage, page_private(page)); + for (i = 0; i < (1 << compound_order(page)); i++) + set_page_private(newpage + i, + page_private(page + i)); } } else { VM_BUG_ON_PAGE(PageSwapCache(page), page);