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 381B57BAF5; Mon, 8 Apr 2024 14:00:21 +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=1712584821; cv=none; b=YHKQbtd2p6ELpKisv9H4liQv+hiWGQL2drE3qGT5JBTNxM3qpUJ5i3+wKvuDeUSiqLIcwcVLn4ImEvr7gfMhif20691SFUL2RpAmd71VfH5YJUZ1RahdprOT8Lt+5PjBrmJElDRrG71mzreGv3ypB16o885nk88EgYE+ii1oCaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712584821; c=relaxed/simple; bh=+CdtoDJd+zmV9Ed4q/zUXoIRe4gPNv0WKB1Gh54LFq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNn8+Rc3NOOgV0mqd/V8D0Xrvd0Sw0FPC+NXsRgqqPVpKXWuTQmQRaWsPwTZOnGnWg971uCbD8tpbPhJ+H5XXhhHg6qs+mXiDm2YmseYamTHo+e3hH22Z/pP5fAlAK3wS5FAvHn/Vd8xMS0g6g2Ws2YdDcEfMP5O3cNrVLWF8+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QQSykcIL; 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="QQSykcIL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B42CDC433C7; Mon, 8 Apr 2024 14:00:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712584821; bh=+CdtoDJd+zmV9Ed4q/zUXoIRe4gPNv0WKB1Gh54LFq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QQSykcILLbexo97stReAbE85OKozO65CoGM1hxZGAd1gQRoq/IBljVyZvWFKljYtd S8dwXKimUPzcNi31V+L1eQQeX2bvUuyzMUVCWQY+j2WPxE6+cNmhbFDafPe8TIxA+y n2qZr7mX6XN9iwglpxR9Pw6QQ05J9P+V1NXwvHDY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zi Yan , David Hildenbrand Subject: [PATCH 5.15 568/690] mm/migrate: set swap entry values of THP tail pages properly. Date: Mon, 8 Apr 2024 14:57:14 +0200 Message-ID: <20240408125420.194988854@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408125359.506372836@linuxfoundation.org> References: <20240408125359.506372836@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-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 @@ -424,8 +424,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);