From patchwork Wed Mar 6 15:51:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13584237 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 CBAB5C54E41 for ; Wed, 6 Mar 2024 15:51:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 642C26B0081; Wed, 6 Mar 2024 10:51:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F24D6B0082; Wed, 6 Mar 2024 10:51:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1566B0083; Wed, 6 Mar 2024 10:51:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3C2156B0081 for ; Wed, 6 Mar 2024 10:51:40 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 119091A0487 for ; Wed, 6 Mar 2024 15:51:40 +0000 (UTC) X-FDA: 81867054360.25.CCE9E82 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) by imf25.hostedemail.com (Postfix) with ESMTP id E54E7A0026 for ; Wed, 6 Mar 2024 15:51:37 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="G abD9tT"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=jAb8WsMO; spf=pass (imf25.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=1709740298; 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=6jc/qtxmjILWwrSyyKA19XZjJk/2gKrfVYgE5UGeLVE=; b=VLY9Ydof4fvXUfCx96tWOpdnIcCQIDwWQntRKBhA7/qrKstbR5m3VXKE7qdSJFHnG87aLs IZW0lejI8XbNk/ZLV0HUs4j8lhdT/epuCBmUoOLo7SzvroH42lxGFt0ZxBuZ86z/WAHgEr 9lY6jtBqptj2R4EK6Odnbx71oXH6FyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709740298; a=rsa-sha256; cv=none; b=8dOvuTcTE1iKqDSrhnymjYw2Rq33PhNZeBYcWCrTPUdAoOzs+sNncNxPj0xCTu7EJaaHnh /1gY0UFXMhLPGm1WGxKP+Gzc7SFIvHRE8u/jydiK8vuNCoN6DPQvE0sPPh57hpk8CLlAnB FLMMH+tKCjIClERaqLjSLKP1Na1P0U0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="G abD9tT"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=jAb8WsMO; spf=pass (imf25.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 compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3A0A011400AF; Wed, 6 Mar 2024 10:51:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 06 Mar 2024 10:51:37 -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=1709740297; x= 1709826697; bh=6jc/qtxmjILWwrSyyKA19XZjJk/2gKrfVYgE5UGeLVE=; b=G abD9tTYJ/urg0kJhmKFO5GLC8pc+9yJTf58aNhBMcmVW8Z6aBGXu0w5mOj494XR/ xpX3DB1hpOYJqH3bLUwOIDIQcCUC4a+de0upwvoQzYqMgD5jb8k1UJyvu0fqog83 gpzgaoDj1yG6fyBbJV4wYzZ7o1klLJIC6lXoyi2+PBh5BU2MsI+6GE8Pn4cQU24w 9UAvOx8YJJHJdR6qomOOAErf2jVnPKabpKV/QzTpnT+LK2ykGr225//f1dVC9Hfj 39mYE5AfxJdZUhyFSPVJ6RUB0EWK6ld4U0LxVTi+CYjYrVKsvX8aiYWBrZNo/hC5 M/1oP2lUDxS1b9lLkRYMA== 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=1709740297; x=1709826697; bh=6 jc/qtxmjILWwrSyyKA19XZjJk/2gKrfVYgE5UGeLVE=; b=jAb8WsMOOQyKTrXTr AnhzB5xMfS4udVhVmFJgWmDNSB1ueaBVRg/P+BdY9Kf5Ln6u9n1/uKfzpOXjNkbe HpXps2w2WrBHyELnSGRawX9g4TdBzTtaK9VYcIOMN6rzvZ3uGYfqmJfGYyCFKmjJ 9qdctDxeJmDyuxaUi4vytFlDrnyDlwQejVIUAZtZx5pLcd6+7lKrM9HJ/mjkNB3J 88yH37AuDE0PMG62oCnNm5T7/1vr3QsAWvjTnCQYDQ45bVR7ELs7HyNTJqty7MMB 4LG5R275FYySdbGpw/dFVJwISdM0V5QU9cSDjtKgZTzFKKrpiiR3qYfghU53/gxo DfagQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugdejkecutefuodetggdotefrodftvf 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:36 -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.10.y] mm/migrate: set swap entry values of THP tail pages properly. Date: Wed, 6 Mar 2024 10:51:35 -0500 Message-ID: <20240306155135.118231-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: E54E7A0026 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7t76merj7hdss31gjhwuepctpj3sb49n X-HE-Tag: 1709740297-763823 X-HE-Meta: U2FsdGVkX1/Ju1wvgDyhPR/70zj9FUsRBzI9cRQKPEgp2osmeoJRpPcj8graoJlKvvffLAYNsbERY5S+JUzDOfhnrWuEoq9MpumuUO9WX/jKItPbyRs5VMTJNyQZ2ODSginFlldWb7uj8o6JCFbS/SeAwOWQl1X8XD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BljxLN4+ZRfV5xESBV4wVDznFWCldM6sOAWbejdONrLYw0azUzjB583chTK1XLrAfqYS+MkBmLsCMeGhNSkeop/6wI8hsKKZE4k/HMmibZaAurzt/VaJ6UsINcXq9CxCSbd9EtiJ9bfNHT72Y6HwsKYKRYCoPX6Y/C4u24YQIs5m44bZ2ZgQDcNhdVx3fkEQ5Q4i7Jm0EWuJJE8hQjUPK0wkBm4uJqIUTPmfQtCNGohQmNoKr/9NmYFkEGzWm8ynVroQuGvw0Mh7aYsSpIKEpMnBAOp199UiDG5khEENoff72TqUpy+GBw09uTOQOMo86A25nvo1xQwZnUJ/SmyM8kHOfmQTGwgSUW2IQ 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 fcb7eb6a6eca..c0a8f3c9e256 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -447,8 +447,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);