From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 461FE38F930; Tue, 16 Jun 2026 17:12:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629932; cv=none; b=gZzjIIvEyrukMiPhTwmadOhkO/1PKrlMroRfYYHiPu+Vx9n8uySC+QdhdHLmUAZENyai49eCY6f1dHZlrUfVx9DNZwxsQ6K6Yv1UIRdGYGTDYAugS/7bYOz3vf1GcWLWuokMpyPsi9jAPDlyhk5p1E2nXTWqhMtZp4ngj/LZBug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629932; c=relaxed/simple; bh=HJVqyhphqPrkwchCpH3n6ibWaF/mY0EtNprzPGl2Yac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DbN7oSwwDyzVkKsdUliTHHWdI0p7iqM7DwlK7sPAcpFEmdaVsPQb/PwzFW3IAGzC+/KCe52xYoIXFv3/M0DmwHKgxnilhzgTt8uOkgZMnlhCnJBUtKJX/p+eAKWKmdmWSS0PX3zTIErcIVV6a6I2h9UW26wEY5Ufk1co0RfVdGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hM0ourFD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hM0ourFD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 104BC1F000E9; Tue, 16 Jun 2026 17:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781629931; bh=a6psGwqIGUkPSV+IqGes3Tk7MYXvyi0926r8g+NqIkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hM0ourFDBF+6o9Ku/o/K0+X4GdOrjg+DYHKgik2QY0UE4Lz+e37NpwEuEqgezXrex O2joDhnQ+h6eTaS0T+xStpfhv27dskRd2Bn+59rOXfLGdJV818dC36r7fB+w2oCrTb yTyUYj4bhaXsbEsdk3dm4JIxKcwHpbK0SEDfVmWw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yin Tirui , Lorenzo Stoakes , "David Hildenbrand (arm)" , Lance Yang , Dev Jain , Baolin Wang , Barry Song , Chen Jun , Kefeng Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Vlastimil Babka , Yang Shi , Zi Yan , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 372/452] mm/huge_memory: update file PMD counter before folio_put() Date: Tue, 16 Jun 2026 20:29:59 +0530 Message-ID: <20260616145136.558285254@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@linuxfoundation.org> User-Agent: quilt/0.69 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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yin Tirui [ Upstream commit 8d878059924f12c1bc24556a92ec56add74de3c8 ] __split_huge_pmd_locked() updates the file/shmem RSS counter after dropping the PMD mapping's folio reference. If folio_put() drops the last reference, mm_counter_file() can later read freed folio state via folio_test_swapbacked(). Move the counter update before folio_put(). Link: https://lore.kernel.org/20260526101337.1984081-1-yintirui@huawei.com Fixes: fadae2953072 ("thp: use mm_file_counter to determine update which rss counter") Signed-off-by: Yin Tirui Reviewed-by: Lorenzo Stoakes Acked-by: David Hildenbrand (arm) Reviewed-by: Lance Yang Reviewed-by: Dev Jain Cc: Baolin Wang Cc: Barry Song Cc: Chen Jun Cc: Kefeng Wang Cc: Liam R. Howlett Cc: Nico Pache Cc: Ryan Roberts Cc: Vlastimil Babka Cc: Yang Shi Cc: Zi Yan Cc: Signed-off-by: Andrew Morton [ changed folio API calls (folio_remove_rmap_pmd/mm_counter_file(folio)/folio_put) to page-based equivalents (page_remove_rmap/mm_counter_file(page)/put_page) ] Signed-off-by: Sasha Levin --- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 78f5df12b8eb37..4443cc44cbf9f1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2095,7 +2095,9 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, if (!PageReferenced(page) && pmd_young(old_pmd)) SetPageReferenced(page); page_remove_rmap(page, vma, true); + add_mm_counter(mm, mm_counter_file(page), -HPAGE_PMD_NR); put_page(page); + return; } add_mm_counter(mm, mm_counter_file(page), -HPAGE_PMD_NR); return; -- 2.53.0