From patchwork Wed Mar 6 15:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13584235 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 99EAFC5475B for ; Wed, 6 Mar 2024 15:51:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30D8A6B006E; Wed, 6 Mar 2024 10:51:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BD626B0074; Wed, 6 Mar 2024 10:51:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1ACA46B007E; Wed, 6 Mar 2024 10:51:18 -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 0A0E16B006E for ; Wed, 6 Mar 2024 10:51:18 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CBFEF1C0C6A for ; Wed, 6 Mar 2024 15:51:17 +0000 (UTC) X-FDA: 81867053394.23.B0363A4 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) by imf15.hostedemail.com (Postfix) with ESMTP id C3306A000B for ; Wed, 6 Mar 2024 15:51:15 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="D 3/9g3o"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=gErwOZy4; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf15.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.157 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709740275; 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=3hLb531CJDlQKpGCSmq0lUwZE8UEmO8lXvTFABPknBA=; b=LR6fhBal5NjVUlYBiZBciveYC4frKdq23qMR8EQ+neRrw1XrmQS977lzNbnjKKfqmlfRlk 0YhrbCZaAWDznUR1C4U4wVn04xQvtFfQvpC6JQDUMlzonrVKblSdXO7/h9pMzLePr+2hLK +pjn1xwyg4Ub2Qam5PdDyz3j7l1uKBg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="D 3/9g3o"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=gErwOZy4; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf15.hostedemail.com: domain of zi.yan@sent.com designates 103.168.172.157 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709740275; a=rsa-sha256; cv=none; b=n9rF+yfuCAQYyM4fhaxPmv0sXutGuc0P9FgvFktF29J5Bz72ea7qNvR2IMMLbllB/N3Pcr Qp3ZMoaPveIlydnegpOyJjy37UDTeNsTjIPGJNnFdnqiMk2QOXL3fNe2t82GJmVbNw09+o F06glRRbkh1mZU2vb5SefQ9gOpYo1a8= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 17A9C114013D; Wed, 6 Mar 2024 10:51:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 06 Mar 2024 10:51:15 -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=1709740275; x= 1709826675; bh=3hLb531CJDlQKpGCSmq0lUwZE8UEmO8lXvTFABPknBA=; b=D 3/9g3oTudqQUm9Z/eAdhH1JmskU9nj4fs3/Ka1KoYhTo56/wweaAl33Q6Ovkrx2o nOvj63G4RBqGnegHRdlCIxDrM1MBPApp+Hi/RV9TS9H1DnXkkqbkCuXwO4LIdvsx Irhsh0IHoZ4sU2jQ48qHF4ljre5FZ6Mdtweb+qclVojQe5kzDXiGNCJVRveyw6FJ qS7CecFYuAZCp1Mu5QDTbB8t4sdCp8J5ZvjwB1lHseecFqwl9zJDIfXzxXEnOfbr WSSf8SjRFRgu8SWOZ/CuDORXsO450opXPH5wGWPa7+E65C1VQULDciEspEw/cPrV N9XJ3cViJhoOT+urcfSfg== 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=1709740275; x=1709826675; bh=3 hLb531CJDlQKpGCSmq0lUwZE8UEmO8lXvTFABPknBA=; b=gErwOZy4rk2w+xwnG RIW3kwOj3U1QfzirSiocqhBdCJ3OLSVmEfTC47iIYXstuhV24dQW67pO0ODvpiYl Lz8TKD4l29yXqgq7XsXOxJAoFYNNnq8WR6GeLvZ6mo87Omp1w2UuBxer8tJ5/sZn IbYygh6vHedx1GsJ1G4seD8E2FmLrgGlYpApU5Nrst1sUnkB3uFoXdQ/SszJK82l E7SwxeJZhT3tWfpWJNRZkLwqyoSz/3Tvuk6TVKxPDoaGvRBl84Hyw3TJqbVgvmi2 fGYk0BLapr7O5+hFkUneqAeySjFm2r3X9mq69qSNtZ8AEhTGBGIN5L3hQYnoxML6 MhLuQ== 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:51:14 -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.4.y] mm/migrate: set swap entry values of THP tail pages properly. Date: Wed, 6 Mar 2024 10:51:13 -0500 Message-ID: <20240306155113.118119-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: n436zi8i7or5x46dirxr8k75x6tb8zmk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C3306A000B X-HE-Tag: 1709740275-517450 X-HE-Meta: U2FsdGVkX1/C6JQ30iDpSUio8RBdOqkeYUZOgBvG+Rr1YYLfOlTxAWKYyH25q1fhY4Tb2SgZu9bHog0w2g/qeFsYgwAo6SFKeslowP89lY8MWT4UlLHZjUZ82g30ppqgdjERtOKkUIyjH1foPdK3Twkp7od0rifg8cm+65y7eLTk0hKkExGK19BRHsEujKwL+SbWZqGeUo4yQx1aUZ78nPy7bZxV+LiL9jjogN/kkIopFICSWNThCE6GFqFzO4P/mUb2tkLVL2R0qoShP/mjn7BgbA4SEY2s85fb8uji5bxDdRKa9RZZRt5twv1bfitqojBiBtcKOLUvfJKdFJwVbOYLAdhgq/FPFLB5KR17y2PYAKEN3VLEdXyChGuEzU0Vue/9McRAJaJh3ORDiIfciYRORQ0w7ym+29FM1pNISNgAkoVD3Ws2YlF/5IkiQnMpibrYPt+OcTO0s1jV/9itzv4jdLfWInU3hqqO/3pCJthk9bGD+yK9X4bZcFJAwpaWKC0w7I1RY43D0UPAHmPqNMecPD4l2ozYIW9u6iGhO7rZ34Wr3Ns1ohkWCcJqQEezKIwhBlBzJG84bv4ewhZM+ovy70GH05WmWEPCXkGdulAcFtu1eo9sSNC2j4sgzfWnfEQkLCiXDuXkQ1pA6vYTz90f6a5cWnea2L+lFXCDjIT67LO5mAp4XDWw6poyfsGezpuYKthbXuaGUH/Ba6BthTdLpC9tnVL+iChRMAH14KQu0GXt/Y/OlVOzVSxUlNj07SvGUoAcx8ZxjnTcmU3qp2jDPEn7UuH7LVJhs0oXZmfIeSqHByT3F5iAwOalzcuBzAq5uj57+HXo+5LZu8r+l5UlSGMGGvoteZktj3xSG3Hio3PJS5roVEhgxtTR0PEUZabuXi3ZkGzP5sWNu1eoepQhpDR1Z/besvBFC1vx8NXM3DGrhrYukJGkXS/vqN1godVc9iMWaK+h9DBpkwG BMNOWbNd SSnaNQL3ZYgyfbZSTjdHauHRkl19fQO9d4bxiu1HoNaUjEIhmFVyDHE3/vWL3+GnYwarCvy+DpXVa/gHwDvA3iEztIZUQ1TyKzmbIq8VM9J7FHEI= 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 034b0662fd3b..9cfd53eaeb4e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -441,8 +441,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);