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 0CBFD22F76E for ; Sat, 12 Jul 2025 22:55:10 +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=1752360910; cv=none; b=ZTKWLMcuFJjvERAjN68IeO/qNJeJIr06kD62DVV3G5zK7M4ln/EB4Vd5iE5kr4+IZuhOHBFnqfseN6cXAk5MGJvTy3/uEVyZg+D+6XXTEXIZaFIwiMMmCp9a79V6Iz6T/qxXt5TBxiATpAWXVoVlW+HAbqjlqqwI02bEX0Z4SWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752360910; c=relaxed/simple; bh=GHByQByZf3A1omLxZb2hj87r7CqPywi08+1nDAEejz4=; h=Date:To:From:Subject:Message-Id; b=IfYCJULfNYMS3hbr8wawszw99MMKyO4eP3yyRDrVGv/B+xi3bIFN06uZ3zSyLUpqTFL0qZsnO8rBn6yW3vjMHmCPSgOd2MLmPreCU15x8+7n9pejF26GdazOxJ/HOqwJ6VpR59YhvyOSow2RWYqIut7zeLX0DvmdaJsFPMdRlq0= 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=RpW/v4or; 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="RpW/v4or" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2BACC4CEEF; Sat, 12 Jul 2025 22:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1752360909; bh=GHByQByZf3A1omLxZb2hj87r7CqPywi08+1nDAEejz4=; h=Date:To:From:Subject:From; b=RpW/v4orrVF4U8FUn3r8WewOFyPwR03TdSkbGkG/74tcp4bcPI3taE1XHscVvpKF6 jS+htqfratFeYrjBzgjy91Iar2fAKMI01dH6W9tS/vRMCX51mOn6s3Fq6cf4nb4YHO qyhktUeV14GEZCtAMEi1E6GOF+auqgtXqrCqb5hc= Date: Sat, 12 Jul 2025 15:55:09 -0700 To: mm-commits@vger.kernel.org,viro@zeniv.linux.org.uk,vbabka@suse.cz,riel@surriel.com,peterx@redhat.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-clean-up-mlock-populate-behaviour.patch added to mm-unstable branch Message-Id: <20250712225509.D2BACC4CEEF@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: clean up mlock populate behaviour has been added to the -mm mm-unstable branch. Its filename is mm-mremap-clean-up-mlock-populate-behaviour.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mremap-clean-up-mlock-populate-behaviour.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm 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: clean up mlock populate behaviour Date: Fri, 11 Jul 2025 12:38:22 +0100 When an mlock()'d VMA is expanded, we need to populate the expanded region to maintain the contract that all mlock()'d memory is present (albeit - with some period after mmap unlock where the expanded part of the mapping remains unfaulted). The current implementation is very unclear, so make it absolutely explicit under what circumstances we do this. Link: https://lkml.kernel.org/r/d5f18667cb416f31de846357559e85182a9d8f39.1752232673.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka Cc: Al Viro Cc: Christian Brauner Cc: Jan Kara Cc: Jann Horn Cc: Liam Howlett Cc: Peter Xu Cc: Rik van Riel Signed-off-by: Andrew Morton --- mm/mremap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/mm/mremap.c~mm-mremap-clean-up-mlock-populate-behaviour +++ a/mm/mremap.c @@ -65,7 +65,7 @@ struct vma_remap_struct { /* Internal state, determined in do_mremap(). */ unsigned long delta; /* Absolute delta of old_len,new_len. */ - bool mlocked; /* Was the VMA mlock()'d? */ + bool populate_expand; /* mlock()'d expanded, must populate. */ enum mremap_type remap_type; /* expand, shrink, etc. */ bool mmap_locked; /* Is mm currently write-locked? */ unsigned long charged; /* If VM_ACCOUNT, # pages to account. */ @@ -1010,10 +1010,8 @@ static void vrm_stat_account(struct vma_ struct vm_area_struct *vma = vrm->vma; vm_stat_account(mm, vma->vm_flags, pages); - if (vma->vm_flags & VM_LOCKED) { + if (vma->vm_flags & VM_LOCKED) mm->locked_vm += pages; - vrm->mlocked = true; - } } /* @@ -1653,6 +1651,10 @@ static int check_prep_vma(struct vma_rem if (new_len <= old_len) return 0; + /* We are expanding and the VMA is mlock()'d so we need to populate. */ + if (vma->vm_flags & VM_LOCKED) + vrm->populate_expand = true; + /* Need to be careful about a growing mapping */ pgoff = (addr - vma->vm_start) >> PAGE_SHIFT; pgoff += vma->vm_pgoff; @@ -1773,7 +1775,8 @@ out: if (vrm->mmap_locked) mmap_write_unlock(mm); - if (!failed && vrm->mlocked && vrm->new_len > vrm->old_len) + /* VMA mlock'd + was expanded, so populated expanded region. */ + if (!failed && vrm->populate_expand) mm_populate(vrm->new_addr + vrm->old_len, vrm->delta); notify_uffd(vrm, failed); _ Patches currently in -mm which might be from lorenzo.stoakes@oracle.com are 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-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 mm-mremap-permit-mremap-move-of-multiple-vmas-fix.patch tools-testing-selftests-extend-mremap_test-to-test-multi-vma-mremap.patch