Re: [PATCH 20/32] mm/migrate_device: don't collect secretmem pages
From: Alistair Popple
Date: Tue Dec 01 2026 - 23:04:18 EST
On 2026-11-29 at 21:06 +1100, "David Hildenbrand (Arm)" <david@xxxxxxxxxx> 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.
Ouch.
> Let's fix it by not collecting secretmem folios in migrate_vma_setup(),
> just like GUP refuses them.
Sounds good, but I think we should actually do that in migrate_vma_setup() not
migrate_vma_collect_pmd().
> 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>
> ---
> mm/migrate_device.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index a953e7acbea61..4d1b2067b60aa 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -13,6 +13,7 @@
> #include <linux/oom.h>
> #include <linux/pagewalk.h>
> #include <linux/rmap.h>
> +#include <linux/secretmem.h>
> #include <linux/leafops.h>
> #include <linux/pgalloc.h>
> #include <asm/tlbflush.h>
> @@ -244,6 +245,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
> struct folio *fault_folio;
> pte_t *ptep;
>
> + /*
> + * secretmem folios have no directmap and drivers are not aware of
> + * that; don't collect them, just like GUP refuses them.
> + */
> + if (vma_is_secretmem(vma))
> + return migrate_vma_collect_skip(start, end, walk);
> +
Ie. I think this should be in migrate_vma_setup(), as there is already a
nice long list of things we don't support migrating there. It serves as nice
documentation when trying to debug "why on earth did my driver refuse to migrate
this thing".
- Alistair
> again:
> /* The fault page is in another folio once its folio has been split */
> fault_folio = migrate->fault_page ?
>
> --
> 2.56.1
>