Skip to content

Commit e8569dd

Browse files
andysantorvalds
authored andcommitted
mm/hugetlb.c: call MMU notifiers when copying a hugetlb page range
When copy_hugetlb_page_range() is called to copy a range of hugetlb mappings, the secondary MMUs are not notified if there is a protection downgrade, which breaks COW semantics in KVM. This patch adds the necessary MMU notifier calls. Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se> Acked-by: Steve Capper <steve.capper@linaro.org> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 549543d commit e8569dd

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎mm/hugetlb.c‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,17 +2346,27 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
23462346
int cow;
23472347
struct hstate *h = hstate_vma(vma);
23482348
unsigned long sz = huge_page_size(h);
2349+
unsigned long mmun_start; /* For mmu_notifiers */
2350+
unsigned long mmun_end; /* For mmu_notifiers */
2351+
int ret = 0;
23492352

23502353
cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
23512354

2355+
mmun_start = vma->vm_start;
2356+
mmun_end = vma->vm_end;
2357+
if (cow)
2358+
mmu_notifier_invalidate_range_start(src, mmun_start, mmun_end);
2359+
23522360
for (addr = vma->vm_start; addr < vma->vm_end; addr += sz) {
23532361
spinlock_t *src_ptl, *dst_ptl;
23542362
src_pte = huge_pte_offset(src, addr);
23552363
if (!src_pte)
23562364
continue;
23572365
dst_pte = huge_pte_alloc(dst, addr, sz);
2358-
if (!dst_pte)
2359-
goto nomem;
2366+
if (!dst_pte) {
2367+
ret = -ENOMEM;
2368+
break;
2369+
}
23602370

23612371
/* If the pagetables are shared don't copy or take references */
23622372
if (dst_pte == src_pte)
@@ -2377,10 +2387,11 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
23772387
spin_unlock(src_ptl);
23782388
spin_unlock(dst_ptl);
23792389
}
2380-
return 0;
23812390

2382-
nomem:
2383-
return -ENOMEM;
2391+
if (cow)
2392+
mmu_notifier_invalidate_range_end(src, mmun_start, mmun_end);
2393+
2394+
return ret;
23842395
}
23852396

23862397
static int is_hugetlb_entry_migration(pte_t pte)

0 commit comments

Comments
 (0)