Re: [PATCH 20/32] mm/migrate_device: don't collect secretmem pages

From: Gregory Price (Meta)

Date: Tue Dec 01 2026 - 08:54:48 EST


On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> secretmem folios are removed from the directmap. GUP refuses secretmem
> VMAs for that reason, but migrate_vma_setup() hands out secretmem folios
> to drivers.
>
> Consequently, drivers that are not aware of this might access these
> folios through the directmap, resulting in a kernel page fault. For
> example, test_hmm copies the folio content using copy_highpage(), and
> nouveau and amdkfd use dma_map_page(), where swiotlb bounce buffering
> reads the folio through the directmap.
>
> Note that migrate_vma_pages() refuses to migrate file folios to device
> memory, but only after the driver already copied the folio content.
>
> Let's fix it by not collecting secretmem folios in migrate_vma_setup(),
> just like GUP refuses them.
>
> This has low urgency, as it requires a driver to migrate secretmem to
> device memory.
>
> Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: adjust description and comment ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

tested with test_hmm.c and produced an Oops - enoent after the fix

Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>

--
~Gregory