Re: [PATCH v2 4/9] mm/migrate: keep the uffd bit when restoring a writable migration entry

From: Tal Zussman

Date: Mon Nov 16 2026 - 17:42:13 EST


On 11/16/26 3:23 PM, David Hildenbrand (Arm) wrote:
> On 11/16/26 21:02, Tal Zussman wrote:
>> remove_migration_pte() makes the restored PTE writable for a writable
>> migration entry, and only looks at the uffd bit of the entry otherwise.
>> A writable migration entry that has the uffd bit set is therefore
>> restored as a writable PTE without the uffd bit, and the page is no
>> longer write-protected.
>>
>> An entry with the uffd bit set must be restored write-protected, whether
>> the entry is writable or not. remove_migration_pmd() gets this right: it
>> makes the PMD writable and sets the uffd bit as two independent steps,
>> and pmd_mkuffd() write-protects the result. To fix it, do the same at
>> the PTE level, where pte_mkuffd() write-protects the PTE as well.
>>
>> The only known path that created such entries is PAGEMAP_SCAN. With
>> PM_SCAN_WP_MATCHING, it write-protects the pages it scans, and it set
>> the uffd bit on a writable migration entry without downgrading it. Now
>> that PAGEMAP_SCAN downgrades them like change_protection() does, we
>> should no longer see them, so this change alone should not be visible to
>> userspace. If another path ever creates a writable migration entry with
>> the uffd bit set, the page now stays write-protected instead of losing
>> the uffd bit.
>
> I am severely confused. If it was properly fixed, why should we do the below?
>
> You should WARN if we get the uffd-wp bit set on something that is writable, not
> silently swallow it.
>
Yeah, so this is more of a hardening change than a pure fix. I think adding a
VM_WARN_ON_ONCE here makes sense, but the uffd bit should still be set so
writes don't go unreported (which is what remove_migration_pmd() does too).

remove_migration_pmd() should probably grow a warning for this case too then.