Re: [PATCH v2 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
From: David Hildenbrand (Arm)
Date: Tue Nov 17 2026 - 04:57:17 EST
On 11/16/26 23:48, Tal Zussman wrote:
> On 11/16/26 3:26 PM, David Hildenbrand (Arm) wrote:
>> On 11/16/26 21:02, 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>
>>> Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
>>> ---
>>> fs/proc/task_mmu.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>>> index ee7f509d376e..013eeea7d1a3 100644
>>> --- a/fs/proc/task_mmu.c
>>> +++ b/fs/proc/task_mmu.c
>>> @@ -2520,7 +2520,7 @@ static void make_uffd_wp_pmd(struct vm_area_struct *vma,
>>> old = pmdp_invalidate_ad(vma, addr, pmdp);
>>> pmd = pmd_mkuffd(old);
>>> set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
>>> - } else if (pmd_is_migration_entry(pmd)) {
>>> + } else if (pmd_is_valid_softleaf(pmd)) {
>>> pmd = set_uffd_wp_softleaf_pmd(pmd);
>>> set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
>>> }
>>>
>>
>> This really should be squashed int #3 I think. Or what's the reason for keeping
>> this separate?
>>
>
> I viewed them as separate bugs with different Fixes: targets, one from v6.7 and
> one from v6.19, so it seemed reasonable to keep them separate. But patch 3 handles
> device private entries already anyways, so I can squash this in.
Oh, indeed, different fixes tags.
Okay then!
Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
--
Cheers,
David