Skip to content

Commit 8d34694

Browse files
kosakitorvalds
authored andcommitted
revert "mm: mempolicy: Let vma_merge and vma_split handle vma->vm_policy linkages"
Commit 05f144a ("mm: mempolicy: Let vma_merge and vma_split handle vma->vm_policy linkages") removed vma->vm_policy updates code but it is the purpose of mbind_range(). Now, mbind_range() is virtually a no-op and while it does not allow memory corruption it is not the right fix. This patch is a revert. [mgorman@suse.de: Edited changelog] Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Mel Gorman <mgorman@suse.de> Cc: Christoph Lameter <cl@linux.com> Cc: Josh Boyer <jwboyer@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1fb3f8c commit 8d34694

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

mm/mempolicy.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,27 @@ check_range(struct mm_struct *mm, unsigned long start, unsigned long end,
607607
return first;
608608
}
609609

610+
/* Apply policy to a single VMA */
611+
static int policy_vma(struct vm_area_struct *vma, struct mempolicy *new)
612+
{
613+
int err = 0;
614+
struct mempolicy *old = vma->vm_policy;
615+
616+
pr_debug("vma %lx-%lx/%lx vm_ops %p vm_file %p set_policy %p\n",
617+
vma->vm_start, vma->vm_end, vma->vm_pgoff,
618+
vma->vm_ops, vma->vm_file,
619+
vma->vm_ops ? vma->vm_ops->set_policy : NULL);
620+
621+
if (vma->vm_ops && vma->vm_ops->set_policy)
622+
err = vma->vm_ops->set_policy(vma, new);
623+
if (!err) {
624+
mpol_get(new);
625+
vma->vm_policy = new;
626+
mpol_put(old);
627+
}
628+
return err;
629+
}
630+
610631
/* Step 2: apply policy to a range and do splits. */
611632
static int mbind_range(struct mm_struct *mm, unsigned long start,
612633
unsigned long end, struct mempolicy *new_pol)
@@ -655,23 +676,9 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
655676
if (err)
656677
goto out;
657678
}
658-
659-
/*
660-
* Apply policy to a single VMA. The reference counting of
661-
* policy for vma_policy linkages has already been handled by
662-
* vma_merge and split_vma as necessary. If this is a shared
663-
* policy then ->set_policy will increment the reference count
664-
* for an sp node.
665-
*/
666-
pr_debug("vma %lx-%lx/%lx vm_ops %p vm_file %p set_policy %p\n",
667-
vma->vm_start, vma->vm_end, vma->vm_pgoff,
668-
vma->vm_ops, vma->vm_file,
669-
vma->vm_ops ? vma->vm_ops->set_policy : NULL);
670-
if (vma->vm_ops && vma->vm_ops->set_policy) {
671-
err = vma->vm_ops->set_policy(vma, new_pol);
672-
if (err)
673-
goto out;
674-
}
679+
err = policy_vma(vma, new_pol);
680+
if (err)
681+
goto out;
675682
}
676683

677684
out:

0 commit comments

Comments
 (0)