mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-28 13:22:57 +00:00
LoongArch: Set _PAGE_DIRTY only if _PAGE_WRITE is set in {pmd,pte}_mkdirty()
commitbf2f34a506
upstream. Now {pmd,pte}_mkdirty() set _PAGE_DIRTY bit unconditionally, this causes random segmentation fault after commit0ccf7f168e
("mm/thp: carry over dirty bit when thp splits on pmd"). The reason is: when fork(), parent process use pmd_wrprotect() to clear huge page's _PAGE_WRITE and _PAGE_DIRTY (for COW); then pte_mkdirty() set _PAGE_DIRTY as well as _PAGE_MODIFIED while splitting dirty huge pages; once _PAGE_DIRTY is set, there will be no tlb modify exception so the COW machanism fails; and at last memory corruption occurred between parent and child processes. So, we should set _PAGE_DIRTY only when _PAGE_WRITE is set in {pmd,pte}_ mkdirty(). Cc: stable@vger.kernel.org Cc: Peter Xu <peterx@redhat.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a1c7b0c490
commit
e19b63d000
1 changed files with 6 additions and 2 deletions
|
@ -349,7 +349,9 @@ static inline pte_t pte_mkclean(pte_t pte)
|
|||
|
||||
static inline pte_t pte_mkdirty(pte_t pte)
|
||||
{
|
||||
pte_val(pte) |= (_PAGE_DIRTY | _PAGE_MODIFIED);
|
||||
pte_val(pte) |= _PAGE_MODIFIED;
|
||||
if (pte_val(pte) & _PAGE_WRITE)
|
||||
pte_val(pte) |= _PAGE_DIRTY;
|
||||
return pte;
|
||||
}
|
||||
|
||||
|
@ -475,7 +477,9 @@ static inline pmd_t pmd_mkclean(pmd_t pmd)
|
|||
|
||||
static inline pmd_t pmd_mkdirty(pmd_t pmd)
|
||||
{
|
||||
pmd_val(pmd) |= (_PAGE_DIRTY | _PAGE_MODIFIED);
|
||||
pmd_val(pmd) |= _PAGE_MODIFIED;
|
||||
if (pmd_val(pmd) & _PAGE_WRITE)
|
||||
pmd_val(pmd) |= _PAGE_DIRTY;
|
||||
return pmd;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue