From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B2DF145B13; Thu, 11 Apr 2024 10:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712829767; cv=none; b=sNoQ2cnlWM8OfBowH6EChDcDQMAAHSDdYuqdi5jV/FytVkYextwNiclI72rEwOx7bsDzIJpKty4AFk0Pcf71NqADiFbK/aWbqHzw3KyH9cwfRi/zwZX4MW6ckGOpu2x/NvfOivdrdG3gjmXfwaFWf1Xl6eleGzZYrNL1hPWJNws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712829767; c=relaxed/simple; bh=TE4dgqA3ggw51zojwt6J9BuA6RUTqEPlnPfsWRrPAsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CjX5nV5D1UzOtydvP17y/bnBFZ/jJyrlz/QF0+WNNfaLxZew7U3CeHftRYXv9xdDmGMxhFdaJMN0ajUFYrlVDfi80bYtIE6DSRGYuyG0ylWbwVOEETDoMg/25+tag4vBCLarT8QW2gWgZz+Lt1Y9+oNklCDDgmmTXRnx2TdSjhg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QoiG+7bo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QoiG+7bo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7676C43394; Thu, 11 Apr 2024 10:02:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712829767; bh=TE4dgqA3ggw51zojwt6J9BuA6RUTqEPlnPfsWRrPAsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QoiG+7bou4AMXfTGrmB8yskvgKeIhxHVDiykYHt3MfHm9l8JlUbMIvGCiy0WEQBeY fL2UslqT/Ttr0PAVBKUTan230C9akBlfJejeCVD1rZ7DO+/N43nzXlngRUqrhegY46 HDAA3uRdC2cdu4RgJjcts9C5VjzG0tyMWsTZtqnc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zi Yan , David Hildenbrand Subject: [PATCH 4.19 081/175] mm/migrate: set swap entry values of THP tail pages properly. Date: Thu, 11 Apr 2024 11:55:04 +0200 Message-ID: <20240411095422.001743978@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095419.532012976@linuxfoundation.org> References: <20240411095419.532012976@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -514,8 +514,12 @@ int migrate_page_move_mapping(struct add 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);