From patchwork Wed Mar 6 15:50:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13584234 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 7DF58C5475B for ; Wed, 6 Mar 2024 15:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5CE6B0072; Wed, 6 Mar 2024 10:50:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E56536B007D; Wed, 6 Mar 2024 10:50:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1F3A6B007E; Wed, 6 Mar 2024 10:50:58 -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 C0AE66B0072 for ; Wed, 6 Mar 2024 10:50:58 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5CF63C02C4 for ; Wed, 6 Mar 2024 15:50:58 +0000 (UTC) X-FDA: 81867052596.04.DA4228A Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) by imf05.hostedemail.com (Postfix) with ESMTP id 1ECFC10001A for ; Wed, 6 Mar 2024 15:50:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="V A9scI+"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=nm8+3aoW; spf=pass (imf05.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=1709740256; 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=qzePdldU740unyHstJjgnlk+QHTFGgi426JeFTsNY58=; b=DpSpVKsLA94wHC4VU2NLrFECEebudrSThafoho/Pyg9cQBpSLkMotvRjQqjYnsnu0KYVSo 7vbvC9xd2bQiOZW8ODGOzGZyXDHRrurvmTsK6JiN57uzDK5h2IWclSw3WsTQo1ES6V4TBk +/ydvK+AiimpLWmY6LhYKsSBX93ddN0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709740256; a=rsa-sha256; cv=none; b=bSFQIMC/B9HYI2epTh7oF/uGm+KDpkPwQU+7Gx7ScoxI2Y2zBQV2wkMleoYTrIbD1YfRlq tkE5VQlG45kZ8uToKiwBlJkgp+x8r0telENJ5jmCUSLQaMt2/A7IH1CNxzCBFySyGpeS6L 6UrYtbhJ3bfzP9eJu6sBK7MuYynot0U= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="V A9scI+"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=nm8+3aoW; spf=pass (imf05.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 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 542B01380105; Wed, 6 Mar 2024 10:50:55 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Mar 2024 10:50:55 -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=1709740255; x= 1709826655; bh=qzePdldU740unyHstJjgnlk+QHTFGgi426JeFTsNY58=; b=V A9scI+iwkEt5vW6faJK5izhvN3X4EP1eliDsldgmRxSBzhQSC5n2V6aZ0Mn0Eiwa mrphAWdZ/Pn7bSJzIfqiLhnYt6CDNyTlH8gPkV4y63AVtRvV5N18VF+MyUBidv90 cTnkUT7lceQyRmot6LeYnbTT32AT7otpX6cqgkDWqjJQe/6dUkpKCErCkNSHftzs 1jL/XaBhRSQ/bRHZQjeMYDzNCX3ftWQ2Pb/aMEGYBuwUjmT0s+5lWcFPgV23Ccrb ilh1uYzEs1OOR7tnAvXSi2Gkktfbl6YMM5ppeb76xqP0PHveijRg6TrxrFqT9ZBR Avka29XV7LnxshnWN7z2A== 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=1709740255; x=1709826655; bh=q zePdldU740unyHstJjgnlk+QHTFGgi426JeFTsNY58=; b=nm8+3aoWU0UM5Y2fU T7NGWkEwQrFT5VPG8XT5E51H+7iZrcbOtGg4ShtH1ZzWSFOwc1lWiapNoCwlGDj0 ii775ApiOKSTNIhSYkZnQdyA0JFF6082arEp+w58C/RrG+ree7+AjuYfaRTHUKWz yk6hN+JAUzQ1MfLMnXg7Gm2S7sRoapl3vEswVGSku2t+HE2AywYr6nCbLQZgwHXU UQ3VeWY3VvOaBqpOyBcw14cD/wEIOyX+xrPKuEL/V3nbNAvrq9eldV87McLvoh6F erode6JAMRP6VS7iqxM9WBCUrDE1IdQmvw6SP6izu05D9Mpq8QugzJpVmqexGAFX dazfQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkfforhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeetudevhe etheehieetiefhjeevjeeltdfgvdeiueeiudetffdtvedthfetvedtffenucffohhmrghi nhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Mar 2024 10:50:54 -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 v4.19.y] mm/migrate: set swap entry values of THP tail pages properly. Date: Wed, 6 Mar 2024 10:50:52 -0500 Message-ID: <20240306155052.118007-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: bugqoa8tk49bzjidi858wim1j4mbm8rd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1ECFC10001A X-Rspam-User: X-HE-Tag: 1709740255-472233 X-HE-Meta: U2FsdGVkX19rUNRUIR5iXezVUo+icPXwfA0XXnXQj575F/Yw6O2QvTZ9MW7eQGejraq2GYJRaOGuVPfxggG3hXF0s0FlfvwE9lfrrz0EG2qCtuuETdavbwTXX9qlee2RQVJc4A1RuyNoCgPTEA1EhNa3nwKaiaxxIxJDKsBCtVdVqP7qmfRL/dsUevOXK+b9vxwnXKEL/JuaS3C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JYTxEsG3ZpfHFwWr39o6O9HgoKXrr/N3RFMlvrNZ7Txif/BzhtKpBoJY1hxH/Gt8Lrdnu3g95TK4vt7SPSXfuurrseD680PaTQBYE6c+sCGfblPXNvHDViHNq++fB8rO3DkS6Jqo1Le1TrZz1piWtsCddqy9qPF6Qf/KMzveTfRJozpmXYWjKRhZzApTUQ9wRVG8+Genu1/mK9zqs6W7Gb8ZoBBKlenyZwnJxgtPash3vcl+0893qvul25ZPWx+W7SaVc6GxKRoPdFyG8akXPgRXXTjoCQHC5pb/zZ7YtzOA49ewvqX3bBjKIkm+x9bI2jW5S 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 171573613c39..893ea04498f7 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -514,8 +514,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);