Unverified Commit 041ba628 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!12988 mm/mremap: fix move_normal_pmd/retract_page_tables race

parents 518cee10 aea07f4e
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,
{
	spinlock_t *old_ptl, *new_ptl;
	struct mm_struct *mm = vma->vm_mm;
	bool res = false;
	pmd_t pmd;

	if (!arch_supports_page_table_move())
@@ -279,19 +280,25 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,
	if (new_ptl != old_ptl)
		spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING);

	/* Clear the pmd */
	pmd = *old_pmd;

	/* Racing with collapse? */
	if (unlikely(!pmd_present(pmd) || pmd_leaf(pmd)))
		goto out_unlock;
	/* Clear the pmd */
	pmd_clear(old_pmd);
	res = true;

	VM_BUG_ON(!pmd_none(*new_pmd));

	pmd_populate(mm, new_pmd, pmd_pgtable(pmd));
	flush_tlb_range(vma, old_addr, old_addr + PMD_SIZE);
out_unlock:
	if (new_ptl != old_ptl)
		spin_unlock(new_ptl);
	spin_unlock(old_ptl);

	return true;
	return res;
}
#else
static inline bool move_normal_pmd(struct vm_area_struct *vma,