Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd70cec8

Browse files
MiaoheLintorvalds
authored andcommitted
mm: mmap: merge vma after call_mmap() if possible
The vm_flags may be changed after call_mmap() because drivers may set someflags for their own purpose. As a result, we failed to merge the adjacentvma due to the different vm_flags as userspace can't pass in the same one.Try to merge vma after call_mmap() to fix this issue.Signed-off-by: Hongxiang Lou <louhongxiang@huawei.com>Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>Signed-off-by: Andrew Morton <akpm@linux-foundation.org>Reviewed-by: Andrew Morton <akpm@linux-foundation.org>Link:http://lkml.kernel.org/r/1594954065-23733-1-git-send-email-linmiaohe@huawei.comSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parenteee0793 commitd70cec8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

‎mm/mmap.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
16901690
structlist_head*uf)
16911691
{
16921692
structmm_struct*mm=current->mm;
1693-
structvm_area_struct*vma,*prev;
1693+
structvm_area_struct*vma,*prev,*merge;
16941694
interror;
16951695
structrb_node**rb_link,*rb_parent;
16961696
unsigned longcharged=0;
@@ -1774,6 +1774,25 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
17741774
if (error)
17751775
gotounmap_and_free_vma;
17761776

1777+
/* If vm_flags changed after call_mmap(), we should try merge vma again
1778+
* as we may succeed this time.
1779+
*/
1780+
if (unlikely(vm_flags!=vma->vm_flags&&prev)) {
1781+
merge=vma_merge(mm,prev,vma->vm_start,vma->vm_end,vma->vm_flags,
1782+
NULL,vma->vm_file,vma->vm_pgoff,NULL,NULL_VM_UFFD_CTX);
1783+
if (merge) {
1784+
fput(file);
1785+
vm_area_free(vma);
1786+
vma=merge;
1787+
/* Update vm_flags and possible addr to pick up the change. We don't
1788+
* warn here if addr changed as the vma is not linked by vma_link().
1789+
*/
1790+
addr=vma->vm_start;
1791+
vm_flags=vma->vm_flags;
1792+
gotounmap_writable;
1793+
}
1794+
}
1795+
17771796
/* Can addr have changed??
17781797
*
17791798
* Answer: Yes, several device drivers can do it in their
@@ -1796,6 +1815,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
17961815
vma_link(mm,vma,prev,rb_link,rb_parent);
17971816
/* Once vma denies write, undo our temporary denial count */
17981817
if (file) {
1818+
unmap_writable:
17991819
if (vm_flags&VM_SHARED)
18001820
mapping_unmap_writable(file->f_mapping);
18011821
if (vm_flags&VM_DENYWRITE)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp