Re: [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect

From: Mike Rapoport

Date: Wed Nov 18 2026 - 09:36:26 EST


On Tue, Nov 17, 2026 at 11:28:43PM -0500, Tal Zussman wrote:
> PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects pages in a VMA
> registered for async uffd-wp, and sets the uffd bit on non-present
> entries as they are. An entry with the uffd bit set must not be
> writable, so that the page is write-protected once it is mapped again.
> change_protection() therefore downgrades writable migration and
> device-private entries to readable ones first, but PAGEMAP_SCAN does
> not.
>
> For a writable migration entry at the PTE level,
> remove_migration_pte() restores a writable PTE without the uffd bit. So
> if a page is under migration while PAGEMAP_SCAN write-protects it, the
> write protection is lost. A user tracking writes with async uffd-wp
> sees the page reported as written on the next scan although nothing
> wrote to it.
>
> With CONFIG_PAGE_TABLE_CHECK, setting the uffd bit on a writable
> non-present PTE or PMD also triggers a warning.
>
> To fix it, downgrade writable migration and device-private entries
> before setting the uffd bit, as change_protection() does, at the PTE,
> PMD, and hugetlb levels.
>
> Add softleaf_is_writable() and softleaf_mkreadable() to leafops.h for
> the downgrade. The open-coded copies in change_protection() can be
> converted to them separately.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Reported-by: Breno Leitao <leitao@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/avNEgmvYdoukt6MS@xxxxxxxxx/
> Cc: stable@xxxxxxxxxxxxxxx
> Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>

Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

> ---
> fs/proc/task_mmu.c | 40 +++++++++++++++++++++++++++++++++++---
> include/linux/leafops.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 88 insertions(+), 3 deletions(-)

--
Sincerely yours,
Mike.