Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2 8/9] mm/migrate_device: do not migrate a uffd-protected zero page
       [not found] ` <20261116-uffd-state-fixes-v2-8-4397a0196479@columbia.edu>
@ 2026-11-16 20:45   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; only message in thread
From: David Hildenbrand (Arm) @ 2026-11-16 20:45 UTC (permalink / raw)
  To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
	James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
	Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
	Jann Horn, Pedro Falcato, Michal Hocko, Michał Mirosław,
	Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
	Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn, Byungchul Park,
	Gregory Price, Ying Huang, Alistair Popple, Baolin Wang,
	Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
	Usama Arif, Kiryl Shutsemau, Muchun Song, Oscar Salvador,
	Mikołaj Lenczewski
  Cc: linux-mm, linux-kernel, linux-fsdevel, Thomas Hellström,
	Lyude Paul, Danilo Krummrich, Felix Kuehling, Jason Gunthorpe,
	Leon Romanovsky, dri-devel, intel-xe, nouveau, amd-gfx

On 11/16/26 21:02, Tal Zussman wrote:
> Device migration replaces a PTE that maps the zero page with a new PTE
> that is built only from the VMA flags, so its userfaultfd WP or RWP
> protection is lost. The same applies to the huge zero PMD. Writes and
> accesses to the page are then no longer reported to userfaultfd.
> 
> To fix it, do not migrate a uffd-protected zero page. Skip it during
> collection, and check again under the page table lock before inserting,
> as another thread can protect the page after it was collected.
> 
> The alternative would be to carry the uffd state over to the new entry,
> but a uffd-protected zero page in a range that a driver migrates should
> be rare.
> 
> Fixes: 292924b26024 ("userfaultfd: wp: apply _PAGE_UFFD_WP bit")
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: dri-devel@lists.freedesktop.org
> Cc: intel-xe@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> Cc: amd-gfx@lists.freedesktop.org
> Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
>  mm/migrate_device.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 9e19fadfa65c..140b99f72508 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -159,7 +159,16 @@ static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,
>  
>  		folio = pmd_folio(*pmdp);
>  		if (is_huge_zero_folio(folio)) {
> +			/*
> +			 * Nothing carries the uffd state of the zero page
> +			 * over, so skip it if its uffd bit is set.
> +			 */
> +			bool protected = userfaultfd_protected(walk->vma) &&
> +					 pmd_uffd(*pmdp);

Now that I read it 3 times in a row below, these needs a helper.

userfaultfd_pte_protected() ? userfaultfd_pte?

That might help you to get rid of the local variable (that should have been
called something that includes uffd and should have been const)


Maybe just add a simple helper for the pmd as well and use it below.


-- 
Cheers,

David

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-16 20:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261116-uffd-state-fixes-v2-0-4397a0196479@columbia.edu>
     [not found] ` <20261116-uffd-state-fixes-v2-8-4397a0196479@columbia.edu>
2026-11-16 20:45   ` [PATCH v2 8/9] mm/migrate_device: do not migrate a uffd-protected zero page David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox