Re: [PATCH] mm/memory: use folio lock/ref helpers in do_swap_page

From: Hongfu Li

Date: Wed Jul 22 2026 - 02:28:22 EST


> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -4852,6 +4852,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> > vmf->page = softleaf_to_page(entry);
> > ret = remove_device_exclusive_entry(vmf);
> > } else if (softleaf_is_device_private(entry)) {
> > + struct folio *fault_folio;
> > +
> > if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
> > /*
> > * migrate_to_ram is not yet ready to operate
> > @@ -4863,6 +4865,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> > }
> >
> > vmf->page = softleaf_to_page(entry);
> > + fault_folio = page_folio(vmf->page);
> > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd,
> > vmf->address, &vmf->ptl);
>
> AI review thinks we shouldn't be reading vmf->page until after taking
> the page table lock:
>
> https://sashiko.dev/#/patchset/20260721013347.65698-1-hongfu.li@xxxxxxxxx

Thanks for the review.

The AI review makes a valid observation: `vmf->page` should not be accessed
before holding the page table lock.

I've moved `fault_folio = page_folio(vmf->page)` after `pte_offset_map_lock()`
and the PTE validation check, so `vmf->page` is now read under the page table
lock. This fix will be included in v2.

Best regards,
Hongfu