Skip to content

Commit 29a951d

Browse files
committed
mm: fix clear_refs_write locking
Turning page table entries read-only requires the mmap_sem held for writing. So stop doing the odd games with turning things from read locks to write locks and back. Just get the write lock. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1d94330 commit 29a951d

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

fs/proc/task_mmu.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,41 +1215,26 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
12151215
.type = type,
12161216
};
12171217

1218+
if (mmap_write_lock_killable(mm)) {
1219+
count = -EINTR;
1220+
goto out_mm;
1221+
}
12181222
if (type == CLEAR_REFS_MM_HIWATER_RSS) {
1219-
if (mmap_write_lock_killable(mm)) {
1220-
count = -EINTR;
1221-
goto out_mm;
1222-
}
1223-
12241223
/*
12251224
* Writing 5 to /proc/pid/clear_refs resets the peak
12261225
* resident set size to this mm's current rss value.
12271226
*/
12281227
reset_mm_hiwater_rss(mm);
1229-
mmap_write_unlock(mm);
1230-
goto out_mm;
1228+
goto out_unlock;
12311229
}
12321230

1233-
if (mmap_read_lock_killable(mm)) {
1234-
count = -EINTR;
1235-
goto out_mm;
1236-
}
12371231
tlb_gather_mmu(&tlb, mm, 0, -1);
12381232
if (type == CLEAR_REFS_SOFT_DIRTY) {
12391233
for (vma = mm->mmap; vma; vma = vma->vm_next) {
12401234
if (!(vma->vm_flags & VM_SOFTDIRTY))
12411235
continue;
1242-
mmap_read_unlock(mm);
1243-
if (mmap_write_lock_killable(mm)) {
1244-
count = -EINTR;
1245-
goto out_mm;
1246-
}
1247-
for (vma = mm->mmap; vma; vma = vma->vm_next) {
1248-
vma->vm_flags &= ~VM_SOFTDIRTY;
1249-
vma_set_page_prot(vma);
1250-
}
1251-
mmap_write_downgrade(mm);
1252-
break;
1236+
vma->vm_flags &= ~VM_SOFTDIRTY;
1237+
vma_set_page_prot(vma);
12531238
}
12541239

12551240
mmu_notifier_range_init(&range, MMU_NOTIFY_SOFT_DIRTY,
@@ -1261,7 +1246,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
12611246
if (type == CLEAR_REFS_SOFT_DIRTY)
12621247
mmu_notifier_invalidate_range_end(&range);
12631248
tlb_finish_mmu(&tlb, 0, -1);
1264-
mmap_read_unlock(mm);
1249+
out_unlock:
1250+
mmap_write_unlock(mm);
12651251
out_mm:
12661252
mmput(mm);
12671253
}

0 commit comments

Comments
 (0)