提交 0a85e51d 编写于 作者: K Kirill A. Shutemov 提交者: Linus Torvalds

thp: reduce indentation level in change_huge_pmd()

Patch series "thp: fix few MADV_DONTNEED races"

For MADV_DONTNEED to work properly with huge pages, it's critical to not
clear pmd intermittently unless you hold down_write(mmap_sem).

Otherwise MADV_DONTNEED can miss the THP which can lead to userspace
breakage.

See example of such race in commit message of patch 2/4.

All these races are found by code inspection.  I haven't seen them
triggered.  I don't think it's worth to apply them to stable@.

This patch (of 4):

Restructure code in preparation for a fix.

Link: http://lkml.kernel.org/r/20170302151034.27829-2-kirill.shutemov@linux.intel.comSigned-off-by: NKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: NVlastimil Babka <vbabka@suse.cz>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 76e32a2a
...@@ -1724,12 +1724,15 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1724,12 +1724,15 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
{ {
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
spinlock_t *ptl; spinlock_t *ptl;
int ret = 0; pmd_t entry;
bool preserve_write;
int ret;
ptl = __pmd_trans_huge_lock(pmd, vma); ptl = __pmd_trans_huge_lock(pmd, vma);
if (ptl) { if (!ptl)
pmd_t entry; return 0;
bool preserve_write = prot_numa && pmd_write(*pmd);
preserve_write = prot_numa && pmd_write(*pmd);
ret = 1; ret = 1;
/* /*
...@@ -1737,24 +1740,21 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1737,24 +1740,21 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
* data is likely to be read-cached on the local CPU and * data is likely to be read-cached on the local CPU and
* local/remote hits to the zero page are not interesting. * local/remote hits to the zero page are not interesting.
*/ */
if (prot_numa && is_huge_zero_pmd(*pmd)) { if (prot_numa && is_huge_zero_pmd(*pmd))
spin_unlock(ptl); goto unlock;
return ret;
} if (prot_numa && pmd_protnone(*pmd))
goto unlock;
if (!prot_numa || !pmd_protnone(*pmd)) {
entry = pmdp_huge_get_and_clear_notify(mm, addr, pmd); entry = pmdp_huge_get_and_clear_notify(mm, addr, pmd);
entry = pmd_modify(entry, newprot); entry = pmd_modify(entry, newprot);
if (preserve_write) if (preserve_write)
entry = pmd_mk_savedwrite(entry); entry = pmd_mk_savedwrite(entry);
ret = HPAGE_PMD_NR; ret = HPAGE_PMD_NR;
set_pmd_at(mm, addr, pmd, entry); set_pmd_at(mm, addr, pmd, entry);
BUG_ON(vma_is_anonymous(vma) && !preserve_write && BUG_ON(vma_is_anonymous(vma) && !preserve_write && pmd_write(entry));
pmd_write(entry)); unlock:
}
spin_unlock(ptl); spin_unlock(ptl);
}
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册