On 7/7/25 07:27, Lorenzo Stoakes wrote:
> Right now it appears that the code is relying upon the returned destination
> address having bits outside PAGE_MASK to indicate whether an error value is
> specified, and decrementing the increased refcount on the uffd ctx if so.
> 
> This is not a safe means of determining an error value, so instead, be
> specific. It makes far more sense to do so in a dedicated error path, so
> add mremap_userfaultfd_fail() for this purpose and use this when an error
> arises.
> 
> A vm_userfaultfd_ctx is not established until we are at the point where
> mremap_userfaultfd_prep() is invoked in copy_vma_and_data(), so this is a
> no-op until this happens.
> 
> That is - uffd remap notification only occurs if the VMA is actually moved
> - at which point a UFFD_EVENT_REMAP event is raised.
> 
> No errors can occur after this point currently, though it's certainly not
> guaranteed this will always remain the case, and we mustn't rely on this.
> 
> However, the reason for needing to handle this case is that, when an error
> arises on a VMA move at the point of adjusting page tables, we revert this
> operation, and propagate the error.
> 
> At this point, it is not correct to raise a uffd remap event, and we must
> handle it.
> 
> This refactoring makes it abundantly clear what we are doing.
> 
> We assume vrm->new_addr is always valid, which a prior change made the case
> even for mremap() invocations which don't move the VMA, however given no
> uffd context would be set up in this case it's immaterial to this change
> anyway.
> 
> No functional change intended.
> 
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoa...@oracle.com>

Reviewed-by: Vlastimil Babka <vba...@suse.cz>

Guess that renders my previous nit unimportant.


Reply via email to