From patchwork Wed Mar 6 15:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13584239 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 C1F07C5475B for ; Wed, 6 Mar 2024 15:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CD5B6B0088; Wed, 6 Mar 2024 10:52:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57DE86B0089; Wed, 6 Mar 2024 10:52:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4459A6B008A; Wed, 6 Mar 2024 10:52:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3263A6B0088 for ; Wed, 6 Mar 2024 10:52:22 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0705B1A03CA for ; Wed, 6 Mar 2024 15:52:22 +0000 (UTC) X-FDA: 81867056124.16.90DF303 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) by imf19.hostedemail.com (Postfix) with ESMTP id F31021A0023 for ; Wed, 6 Mar 2024 15:52:19 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="a iXBMJE"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=atQTcM8Z; spf=pass (imf19.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.147 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709740340; a=rsa-sha256; cv=none; b=TnuDS4ftKjF3UmrwsRYwSoHHeg0+TJY9A5bEkaZ4trP50eRB/CEV+iE/PdB+A0DWaGVuhT LnMRSb8ECLfeshxCVUj97P/sbeEUifhf+dcL681Vc2UdDX6jWUxysgqp1jUgAmn0RHCjlG JofZCK5/0JkdO+gppym98xG0x6f6opE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="a iXBMJE"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=atQTcM8Z; spf=pass (imf19.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.147 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=1709740340; 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=KZx88+PWHckkBWj3fAbJBJI9cPRjH7bxyyotuefqMm0=; b=p3JRtVU9Ah0KYM9SMNBghx0JFfFflG52GMIoCNtvt34CH4gQXKLy0d0s5auaOSSq4Zv3Gu 7eF+ESMxISCfVoGKfLnCEBaTscjAezR4J43YfTyE1KBGg2UNapM7Q9oDS41JbwTC+OsbbN qUVzmiV0mqYMsgwKDbx2UZNMYqDlnNQ= Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 4E38513800C3; Wed, 6 Mar 2024 10:52:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Mar 2024 10:52:19 -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=1709740339; x= 1709826739; bh=KZx88+PWHckkBWj3fAbJBJI9cPRjH7bxyyotuefqMm0=; b=a iXBMJEx8qzKXQiqR/r57ENae3EfNmoCp+nRkMeLDbptbeiBjZ8BD9c64+AqYvfj2 73wY4kahLM8p33OznCaQClKlsgL+9bWmLSRJrMmqrhbfC4FxnzUQ2lNsYc9U0xkY Ze8uGhOx6WBMc8VtGNg6Udl+QypHSZNAEXdqdupTmPtsGgpTGhguQEAtW7Kp5kBa Tz2rntyuncF7gYL4l3Y2eyO/Jxmq5uZxGrSpDU4B4DQmIqYumIQLFNVrdmd8aSvK wayvYjFzVmbqaqrZHBdDhcimVAYbbhaA8sXCR+R/wC1KN1O6aTNqFKDHinvP4CZg 2YSZf+t0RtjWEXHyUOHlQ== 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=1709740339; x=1709826739; bh=K Zx88+PWHckkBWj3fAbJBJI9cPRjH7bxyyotuefqMm0=; b=atQTcM8ZwA5b6u48m EyOfZ/t2B4cv8+boNIFz65taj51scm7/HmkzavMB8eJjUb3Xnd9NZc4yN+ZJ7Xo7 0wCVKTBRtYM1KPQ+z5zbREc1PVTAgp4gAyYcD8IBOzV1eog9l8vC6/DolwahCfO5 I20xcHr48xD8ymK0VAUh6c+77W0vikeEpillKM0krx3NRRTmfJ55QnBFqdR+xFfK bUS0S/+0M3KjYASWkw4NkuuxKf+m2aZSbvLf1lJNYYsPGlF1Co8tw56ie0h+5rHq rH29dlVOT67Zptfq+kdghYis/Jd8fIqP89Q06iSZK7YJguvZOwjVSkrr/X2509BR kPV3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkfforhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeetudevhe etheehieetiefhjeevjeeltdfgvdeiueeiudetffdtvedthfetvedtffenucffohhmrghi nhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Mar 2024 10:52:18 -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 v6.1.y] mm/migrate: set swap entry values of THP tail pages properly. Date: Wed, 6 Mar 2024 10:52:17 -0500 Message-ID: <20240306155217.118467-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: F31021A0023 X-Stat-Signature: em6z57b3ab6h58j74ar6mdqnguqm5zws X-Rspam-User: X-HE-Tag: 1709740339-204603 X-HE-Meta: U2FsdGVkX1+gpqZ+kTL5B0a8tUH8NsMXfQp2UrIQ8NLbYIOaruRoBpY4i9dMGdidKoyRzmgVJzb7++mp8rjgykLBHudkzg/KxmXvFBvU8klNPWvrywTok8u7YuqCVQCb08k7V8GbR6aZmTljG8suJ+zBB7Kl/JP8Euw8o830tC8ZGMqGUETtbxb7lBmcEn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lzNVb6l2hmjW5KKblBEetAYotiMsrs8TrEsF0ocy0ig24rj8mtXR2Y0CyeiAbLEklhW0XvD+DWnwvWDriuwWr6qg+X9deTmREvI6Ug4KdQhDIC/ytIzJZipJZoqnaSd95z31oenkd9klIJ7qij05zzNkY/Kl242eCp2JAZlbuNcjw2c0MEnrfrXOPCQqQAWiMWXOnniS+qmNwZY+I7z0jylbSikpOxGOhUDpXJNaZsMrysu2KP+IAihRXMT2bqAsKTeO1pmuk11FFgJJvIi1n+kV21Ou1jY2FNCDK5Pfg== 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 c93dd6a31c31..c5968021fde0 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -423,8 +423,12 @@ int folio_migrate_mapping(struct address_space *mapping, if (folio_test_swapbacked(folio)) { __folio_set_swapbacked(newfolio); if (folio_test_swapcache(folio)) { + int i; + folio_set_swapcache(newfolio); - newfolio->private = folio_get_private(folio); + for (i = 0; i < nr; i++) + set_page_private(folio_page(newfolio, i), + page_private(folio_page(folio, i))); } entries = nr; } else {