Re: [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
From: Mike Rapoport
Date: Wed Nov 18 2026 - 09:38:44 EST
On Tue, Nov 17, 2026 at 11:28:45PM -0500, Tal Zussman wrote:
> PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects a huge PMD through
> make_uffd_wp_pmd(), which handles a present THP and a migration entry
> but does nothing for a device-private THP. The PMD never gets the uffd
> bit.
>
> pagemap_thp_category() reports a non-present PMD without the uffd bit as
> written. A user tracking writes with async uffd-wp therefore sees every
> page of a device-private THP as written on every scan, whether it was
> written to or not. This requires a driver that migrates THPs to device
> memory.
>
> A device-private PMD must be write-protected like any other huge PMD. To
> fix it, pass any valid PMD softleaf entry to set_uffd_wp_softleaf_pmd(),
> not only a migration entry. It downgrades a writable entry and sets the
> uffd bit. When the THP migrates back, set_pmd_migration_entry() carries
> the uffd bit over to the migration entry, so the write protection is
> kept.
>
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> 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 | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
--
Sincerely yours,
Mike.