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 08DEB46C851; Fri, 7 Aug 2026 15:14:19 +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=1786115660; cv=none; b=Jo4cuV5gzPcW9d0gj4EO5nrN+tN+7W2D0UiipEpjk5WcGFGgB3t8fZgnM3ey3GTSKXSzVKVr6KwR4Lj2/aU4cf+0RSar/ZUbonXzs0kgrX1tHaYv1xuub6SarY8t2IZ/+uUVY2kdHsib/2E3an7/wLtsDrgj6/5Re//vzv1Y87g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115660; c=relaxed/simple; bh=ZSlGUOMjpc/rtrkRoLMKHOKlbjQcXpF/v7OOTZZncfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qRjbze8/pSD2NZY+lCdTqwEBddQ/10AM2Oe165AAPbP657CkmxfQ2+QnwqahfrSW2UcWp6ASnmmQ+X46zrscQkOcQ6WrCQs+qiF+cWjmE1xa8dODh4akg2pmhVoNwhzo1GJRMx4V3oxdaAy9E3GhV8G0O71DAzOZ6xCL0scwtvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YH8oUSvN; 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="YH8oUSvN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43AF61F00A3D; Fri, 7 Aug 2026 15:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786115658; bh=+Z6Tf47iyPQYSd2WN6dvOSdyG/QcBxfoKnCu4mZ6aQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YH8oUSvNyc+t7CWB5c0cJ5SSD2OV1r0sO2ObnqWIWuxXvq4juefVls6iW+K7B+Nno uoUDv+oMe1ZIKMHRbTG2XdjZGlWAjD82DbRmQvAIqGUToCKCGtQQa7JRKqG7y3yzJZ HT/mQ4uBOV9WR80TceQ4QOEj5j6gxan7ficDrutk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kiryl Shutsemau , Muhammad Usama Anjum , David Hildenbrand , Jann Horn , "Liam R. Howlett" , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Pedro Falcato , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Andrew Morton , Sasha Levin Subject: [PATCH 6.18 354/396] fs/proc/task_mmu: fix PAGEMAP_SCAN written state for unpopulated ptes Date: Fri, 7 Aug 2026 16:38:34 +0200 Message-ID: <20260807143431.920895917@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143424.272339768@linuxfoundation.org> References: <20260807143424.272339768@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kiryl Shutsemau (Meta) [ Upstream commit 07b4377bdbe74a3ec0c8da5849d014f70e003384 ] PAGEMAP_SCAN reports an unpopulated pte differently depending on which path serves the request. The PAGE_IS_WRITTEN fast path in pagemap_scan_pmd_entry() reports a pte_none as written (and, under PM_SCAN_WP_MATCHING, arms a marker); pagemap_page_category() returns 0 for the same pte_none. A request that cannot take the fast path (an extra category bit, category_anyof_mask or category_inverted) therefore reports the pte as clean and skips arming it. A range that was populated and then MADV_DONTNEED'd reads as written via one mask and clean via another, and in the latter case is not re-armed for the next round -- an incremental-dump consumer (e.g. CRIU) using a richer mask drops the zapped range and stops tracking writes to it. Report pte_none as written in pagemap_page_category() too. A pte_none carries no uffd-wp marker, i.e. it is not write-protected -- the same condition under which the present and swap cases already report PAGE_IS_WRITTEN. The fast path applies no VMA test, so neither does this. The hugetlb and fully-unpopulated-PMD (no page table) scans have no PAGE_IS_WRITTEN fast path, so they do not exhibit the per-entry divergence and are left unchanged. Add a pagemap_ioctl selftest that populates a range, drops it with MADV_DONTNEED, and checks that the fast path and the generic (category_anyof_mask) path both report every page written. Link: https://lore.kernel.org/20260707151349.92143-1-kirill@shutemov.name Fixes: 12f6b01a0bcb ("fs/proc/task_mmu: add fast paths to get/clear PAGE_IS_WRITTEN flag") Signed-off-by: Kiryl Shutsemau Cc: Muhammad Usama Anjum Cc: David Hildenbrand Cc: Jann Horn Cc: Liam R. Howlett Cc: Lorenzo Stoakes Cc: Michal Hocko Cc: Mike Rapoport Cc: Pedro Falcato Cc: Peter Xu Cc: Shuah Khan Cc: Suren Baghdasaryan Cc: Vlastimil Babka Assisted-by: Claude:claude-fable-5 Cc: Signed-off-by: Andrew Morton (cherry picked from commit 07b4377bdbe74a3ec0c8da5849d014f70e003384) [ kas: fix only; selftest hunk dropped (pagemap_ioctl.c differs on this tree). Add the pte_none early-return before the pte_present branch ] Signed-off-by: Kiryl Shutsemau (Meta) Signed-off-by: Sasha Levin --- fs/proc/task_mmu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 0cec16f9e9afd..48455e2a66a1e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2326,6 +2326,19 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p, { unsigned long categories = 0; + if (pte_none(pte)) { + /* + * An unpopulated pte carries no uffd-wp marker, i.e. it is not + * write-protected, the same condition under which the present + * and swap cases below report PAGE_IS_WRITTEN. Report it here + * too so this generic path agrees with the PAGE_IS_WRITTEN fast + * path in pagemap_scan_pmd_entry(), which reports pte_none as + * written and, under PM_SCAN_WP_MATCHING, arms a marker. The + * fast path applies no VMA test, so neither does this. + */ + return PAGE_IS_WRITTEN; + } + if (pte_present(pte)) { struct page *page; -- 2.53.0