Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] mm: dup_mmap down new mmap_sem

One anomaly remains from when Andrea rationalized the responsibilities of
mmap_sem and page_table_lock: in dup_mmap we add vmas to the child holding its
page_table_lock, but not the mmap_sem which normally guards the vma list and
rbtree. Which could be an issue for unuse_mm: though since it just walks down
the list (today with page_table_lock, tomorrow not), it's probably okay. Will
need a memory barrier? Oh, keep it simple, Nick and I agreed, no harm in
taking child's mmap_sem here.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Hugh Dickins and committed by
Linus Torvalds
7ee78232 fd3e42fc

+4 -5
+4 -5
kernel/fork.c
··· 192 192 193 193 down_write(&oldmm->mmap_sem); 194 194 flush_cache_mm(oldmm); 195 + down_write(&mm->mmap_sem); 196 + 195 197 mm->locked_vm = 0; 196 198 mm->mmap = NULL; 197 199 mm->mmap_cache = NULL; ··· 253 251 } 254 252 255 253 /* 256 - * Link in the new vma and copy the page table entries: 257 - * link in first so that swapoff can see swap entries. 258 - * Note that, exceptionally, here the vma is inserted 259 - * without holding mm->mmap_sem. 254 + * Link in the new vma and copy the page table entries. 260 255 */ 261 256 spin_lock(&mm->page_table_lock); 262 257 *pprev = tmp; ··· 274 275 goto out; 275 276 } 276 277 retval = 0; 277 - 278 278 out: 279 + up_write(&mm->mmap_sem); 279 280 flush_tlb_mm(oldmm); 280 281 up_write(&oldmm->mmap_sem); 281 282 return retval;