Re: [RFC PATCH 1/3] mm/memory.c: convert __copy_remote_vm_str() to folios

From: Matthew Wilcox
Date: Wed Jun 25 2025 - 23:02:41 EST


On Wed, Jun 25, 2025 at 07:00:22PM +0100, Matthew Wilcox wrote:
> > + folio_offset = offset_in_folio(folio, addr);
>
> Umm. Not sure this is safe. A folio might be mapped misaligned, so
> 'addr' might not give you the right offset within the folio. I think
> you might need to use addr - (vma->vm_pgoff << PAGE_SHIFT). But I'd
> defer to others here ... particularly when it comes to anonymous folios.

Sorry, this calculation is obviously wrong. It should be something like
the calculation in linear_page_index(), only without throwing away the
bottom PAGE_SHIFT bits. But that's for file VMAs only, and I'm not sure
what should be done for anon vmas. Possibly there is no way?