Commit 56379aed authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Liu Shixin
Browse files

mm: optimise vmf_anon_prepare() for VMAs without an anon_vma

mainline inclusion
from mainline-v6.10-rc1
commit 737019cf6ac5babb75645ad324aeead7bc04749d
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9R3AY
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=737019cf6ac5babb75645ad324aeead7bc04749d

--------------------------------

If the mmap_lock can be taken for read, we can call __anon_vma_prepare()
while holding it, saving ourselves a trip back through the fault handler.

Link: https://lkml.kernel.org/r/20240426144506.1290619-5-willy@infradead.org


Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarJann Horn <jannh@google.com>
Reviewed-by: default avatarSuren Baghdasaryan <surenb@google.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent 098c90dc
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -3233,16 +3233,21 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf)
vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
{
	struct vm_area_struct *vma = vmf->vma;
	vm_fault_t ret = 0;

	if (likely(vma->anon_vma))
		return 0;
	if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
		if (!mmap_read_trylock(vma->vm_mm)) {
			vma_end_read(vma);
			return VM_FAULT_RETRY;
		}
	}
	if (__anon_vma_prepare(vma))
		return VM_FAULT_OOM;
	return 0;
		ret = VM_FAULT_OOM;
	if (vmf->flags & FAULT_FLAG_VMA_LOCK)
		mmap_read_unlock(vma->vm_mm);
	return ret;
}

/*