aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/memory.c7
-rw-r--r--mm/mlock.c7
2 files changed, 12 insertions, 2 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 9144fae9a68b..b8f97b8575b7 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3299,7 +3299,12 @@ int make_pages_present(unsigned long addr, unsigned long end)
3299 vma = find_vma(current->mm, addr); 3299 vma = find_vma(current->mm, addr);
3300 if (!vma) 3300 if (!vma)
3301 return -ENOMEM; 3301 return -ENOMEM;
3302 write = (vma->vm_flags & VM_WRITE) != 0; 3302 /*
3303 * We want to touch writable mappings with a write fault in order
3304 * to break COW, except for shared mappings because these don't COW
3305 * and we would not want to dirty them for nothing.
3306 */
3307 write = (vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE;
3303 BUG_ON(addr >= end); 3308 BUG_ON(addr >= end);
3304 BUG_ON(end > vma->vm_end); 3309 BUG_ON(end > vma->vm_end);
3305 len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE; 3310 len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE;
diff --git a/mm/mlock.c b/mm/mlock.c
index b70919ce4f72..4f318642fbbe 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -171,7 +171,12 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
171 VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); 171 VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
172 172
173 gup_flags = FOLL_TOUCH | FOLL_GET; 173 gup_flags = FOLL_TOUCH | FOLL_GET;
174 if (vma->vm_flags & VM_WRITE) 174 /*
175 * We want to touch writable mappings with a write fault in order
176 * to break COW, except for shared mappings because these don't COW
177 * and we would not want to dirty them for nothing.
178 */
179 if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
175 gup_flags |= FOLL_WRITE; 180 gup_flags |= FOLL_WRITE;
176 181
177 /* We don't try to access the guard page of a stack vma */ 182 /* We don't try to access the guard page of a stack vma */