Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mremap: cleanup post-processing stage of mremap

Separate out the uffd bits so it clear's what's happening.

Don't bother setting vrm->mmap_locked after unlocking, because after this
we are done anyway.

The only time we drop the mmap lock is on VMA shrink, at which point
vrm->new_len will be < vrm->old_len and the operation will not be
performed anyway, so move this code out of the if (vrm->mmap_locked)
block.

All addresses returned by mremap() are page-aligned, so the
offset_in_page() check on ret seems only to be incorrectly trying to
detect whether an error occurred - explicitly check for this.

No functional change intended.

Link: https://lkml.kernel.org/r/ebb8f29650b8e343fe98fefc67b3a61a24d1e0f1.1752770784.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Rik van Riel <riel@surriel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
e49e76c2 f256a7a4

+13 -9
+13 -9
mm/mremap.c
··· 1729 1729 return 0; 1730 1730 } 1731 1731 1732 + static void notify_uffd(struct vma_remap_struct *vrm, unsigned long to) 1733 + { 1734 + struct mm_struct *mm = current->mm; 1735 + 1736 + userfaultfd_unmap_complete(mm, vrm->uf_unmap_early); 1737 + mremap_userfaultfd_complete(vrm->uf, vrm->addr, to, vrm->old_len); 1738 + userfaultfd_unmap_complete(mm, vrm->uf_unmap); 1739 + } 1740 + 1732 1741 static unsigned long do_mremap(struct vma_remap_struct *vrm) 1733 1742 { 1734 1743 struct mm_struct *mm = current->mm; ··· 1763 1754 res = vrm_implies_new_addr(vrm) ? mremap_to(vrm) : mremap_at(vrm); 1764 1755 1765 1756 out: 1766 - if (vrm->mmap_locked) { 1757 + if (vrm->mmap_locked) 1767 1758 mmap_write_unlock(mm); 1768 - vrm->mmap_locked = false; 1769 1759 1770 - if (!offset_in_page(res) && vrm->mlocked && vrm->new_len > vrm->old_len) 1771 - mm_populate(vrm->new_addr + vrm->old_len, vrm->delta); 1772 - } 1760 + if (!IS_ERR_VALUE(res) && vrm->mlocked && vrm->new_len > vrm->old_len) 1761 + mm_populate(vrm->new_addr + vrm->old_len, vrm->delta); 1773 1762 1774 - userfaultfd_unmap_complete(mm, vrm->uf_unmap_early); 1775 - mremap_userfaultfd_complete(vrm->uf, vrm->addr, res, vrm->old_len); 1776 - userfaultfd_unmap_complete(mm, vrm->uf_unmap); 1777 - 1763 + notify_uffd(vrm, res); 1778 1764 return res; 1779 1765 } 1780 1766