From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FAB71552FD for ; Tue, 8 Jul 2025 01:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751939908; cv=none; b=rd0RPRT+Uefi5NeRnTIO3wlUjWIh9xnEfA1g6meJRYJfXEcWo+cS5SvYUTUgUlP+Z9GwXgXEhLWTJz4K0kj5D8wLk3MYXsKuFDY5N/q9CY4tZM1L4cZ0hP7Vp11x438mlYSSkw5BwkceumavN047DQSNAkBfECqL65OZF8G3mgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751939908; c=relaxed/simple; bh=q775A+V21KpF/n+bMH6rsrTsO7jGKNnJXg+MnHR6LT8=; h=Date:To:From:Subject:Message-Id; b=uSmFXDlAuNTlbWpDs1dGX/tJsOR8Te9uccvtg9TAdGlKkfAsm2Q7+WzM7OY9QicpgE/9yKqa85/3laND7QXX1XIcfhasMsmWLmGSJCKSjlr2XF2ZRxS2OUzNCI4dC3KHXCB7/UT6u3ijVi7U4COjsAVM04ugKmQAgBPjWBJQq94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=cEIom6fV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="cEIom6fV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9AF7C4CEE3; Tue, 8 Jul 2025 01:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1751939908; bh=q775A+V21KpF/n+bMH6rsrTsO7jGKNnJXg+MnHR6LT8=; h=Date:To:From:Subject:From; b=cEIom6fV6UAJ/0CCBwH0Y5pUHIFuHRcp4Ors4+y07se7nt1K8MfQlqptdo5K7C2it oS1BunuzDbG2aXPR6AOdVdWhFfbROEBeI4ug5vbePc/vJ2BWluBjQflm0E+N2g16l7 sL85sXfMfhzGADBi08gJZFmZ2t6ZSwhNXQ5kyjoo= Date: Mon, 07 Jul 2025 18:58:27 -0700 To: mm-commits@vger.kernel.org,viro@zeniv.linux.org.uk,vbabka@suse.cz,riel@surriel.com,peterx@redhat.com,lkp@intel.com,liam.howlett@oracle.com,jannh@google.com,jack@suse.cz,brauner@kernel.org,lorenzo.stoakes@oracle.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-mremap-cleanup-post-processing-stage-of-mremap.patch added to mm-new branch Message-Id: <20250708015827.E9AF7C4CEE3@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/mremap: cleanup post-processing stage of mremap has been added to the -mm mm-new branch. Its filename is mm-mremap-cleanup-post-processing-stage-of-mremap.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mremap-cleanup-post-processing-stage-of-mremap.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Lorenzo Stoakes Subject: mm/mremap: cleanup post-processing stage of mremap Date: Mon, 7 Jul 2025 06:27:47 +0100 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/d21f091bb617d0ac31b6e541d6c6ce28afe880c1.1751865330.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes Cc: Al Viro Cc: Christian Brauner Cc: Jan Kara Cc: Jann Horn Cc: kernel test robot Cc: Liam Howlett Cc: Peter Xu Cc: Rik van Riel Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/mremap.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) --- a/mm/mremap.c~mm-mremap-cleanup-post-processing-stage-of-mremap +++ a/mm/mremap.c @@ -1729,6 +1729,15 @@ static int check_prep_vma(struct vma_rem return 0; } +static void notify_uffd(struct vma_remap_struct *vrm, unsigned long ret) +{ + struct mm_struct *mm = current->mm; + + userfaultfd_unmap_complete(mm, vrm->uf_unmap_early); + mremap_userfaultfd_complete(vrm->uf, vrm->addr, ret, vrm->old_len); + userfaultfd_unmap_complete(mm, vrm->uf_unmap); +} + static unsigned long do_mremap(struct vma_remap_struct *vrm) { struct mm_struct *mm = current->mm; @@ -1754,18 +1763,13 @@ static unsigned long do_mremap(struct vm res = vrm_implies_new_addr(vrm) ? mremap_to(vrm) : mremap_at(vrm); out: - if (vrm->mmap_locked) { + if (vrm->mmap_locked) mmap_write_unlock(mm); - vrm->mmap_locked = false; - - if (!offset_in_page(res) && vrm->mlocked && vrm->new_len > vrm->old_len) - mm_populate(vrm->new_addr + vrm->old_len, vrm->delta); - } - userfaultfd_unmap_complete(mm, vrm->uf_unmap_early); - mremap_userfaultfd_complete(vrm->uf, vrm->addr, res, vrm->old_len); - userfaultfd_unmap_complete(mm, vrm->uf_unmap); + if (!IS_ERR_VALUE(res) && vrm->mlocked && vrm->new_len > vrm->old_len) + mm_populate(vrm->new_addr + vrm->old_len, vrm->delta); + notify_uffd(vrm, res); return res; } _ Patches currently in -mm which might be from lorenzo.stoakes@oracle.com are docs-mm-expand-vma-doc-to-highlight-pte-freeing-non-vma-traversal.patch mm-ksm-have-ksm-vma-checks-not-require-a-vma-pointer.patch mm-ksm-refer-to-special-vmas-via-vm_special-in-ksm_compatible.patch mm-prevent-ksm-from-breaking-vma-merging-for-new-vmas.patch mm-prevent-ksm-from-breaking-vma-merging-for-new-vmas-fix.patch tools-testing-selftests-add-vma-merge-tests-for-ksm-merge.patch mm-use-per_vma-lock-for-madv_dontneed-fix.patch mm-pagewalk-split-walk_page_range_novma-into-kernel-user-parts.patch secretmem-remove-uses-of-struct-page-fix.patch mm-vma-use-vmg-target-to-specify-target-vma-for-new-vma-merge.patch mm-vma-use-vmg-target-to-specify-target-vma-for-new-vma-merge-fix.patch mm-change-vm_get_page_prot-to-accept-vm_flags_t-argument.patch mm-change-vm_get_page_prot-to-accept-vm_flags_t-argument-fix.patch mm-update-core-kernel-code-to-use-vm_flags_t-consistently.patch mm-update-architecture-and-driver-code-to-use-vm_flags_t.patch mm-madvise-remove-the-visitor-pattern-and-thread-anon_vma-state.patch mm-madvise-thread-mm_struct-through-madvise_behavior.patch mm-madvise-thread-vma-range-state-through-madvise_behavior.patch mm-madvise-thread-all-madvise-state-through-madv_behavior.patch mm-madvise-eliminate-very-confusing-manipulation-of-prev-vma.patch mm-madvise-eliminate-very-confusing-manipulation-of-prev-vma-fix.patch tools-testing-selftests-add-mremap-unfaulted-faulted-test-cases.patch mm-mremap-perform-some-simple-cleanups.patch mm-mremap-refactor-initial-parameter-sanity-checks.patch mm-mremap-put-vma-check-and-prep-logic-into-helper-function.patch mm-mremap-cleanup-post-processing-stage-of-mremap.patch mm-mremap-use-an-explicit-uffd-failure-path-for-mremap.patch mm-mremap-use-an-explicit-uffd-failure-path-for-mremap-fix.patch mm-mremap-check-remap-conditions-earlier.patch mm-mremap-move-remap_is_valid-into-check_prep_vma.patch mm-mremap-clean-up-mlock-populate-behaviour.patch mm-mremap-permit-mremap-move-of-multiple-vmas.patch tools-testing-selftests-extend-mremap_test-to-test-multi-vma-mremap.patch