mm: mmap: Merge vma after call_mmap() if possible
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Tue, 14 Jul 2020 11:07:44 +0800 linmiaohe <[email protected]> wrote:
From: Miaohe Lin <[email protected]>
The
vm_flagsmay be changed aftercall_mmap()because drivers may set some flags for their own purpose. As a result, we failed to merge the adjacent vma due to the differentvm_flagsas userspace can't pass in the same one. Try to merge vma aftercall_mmap()to fix this issue.
Quoted 16 lines
Quoted 4 lines
Signed-off-by Hongxiang Lou <[email protected]>Signed-off-by Miaohe Lin <[email protected]>---
(quoted diff) +1
-0+ /* If vm_flags changed after call_mmap(), we should try merge vma againReview
Quoted 10 lines
(quoted diff) +10
-0+ * as we may succeed this time. + */ + if (unlikely(vm_flags != vma->vm_flags && prev)) { + merge = vma_merge(mm, prev, vma->vm_start, vma->vm_end, vma->vm_flags, + NULL, vma->vm_file, vma->vm_pgoff, NULL, NULL_VM_UFFD_CTX); + if (merge) { + fput(file); + vm_area_free(vma); + vma = merge; + goto unmap_writable;Shouldn't we update local variable
vm_flags' here, to pick up the change? And possiblyaddr'?
Yes, we should. vm_flags and addr should be updated to continue the work. Many thanks for your great review. I will fix it and test again. I will send a patch v2 soon.