Skip to content

Commit a073d63

Browse files
zhangtianyang-ztychenhuacai
authored andcommitted
LoongArch: Let {pte,pmd}_modify() record the status of _PAGE_DIRTY
Now if the PTE/PMD is dirty with _PAGE_DIRTY but without _PAGE_MODIFIED, after {pte,pmd}_modify() we lose _PAGE_DIRTY, then {pte,pmd}_dirty() return false and lead to data loss. This can happen in certain scenarios such as HW PTW doesn't set _PAGE_MODIFIED automatically, so here we need _PAGE_MODIFIED to record the dirty status (_PAGE_DIRTY). The new modification involves checking whether the original PTE/PMD has the _PAGE_DIRTY flag. If it exists, the _PAGE_MODIFIED bit is also set, ensuring that the {pte,pmd}_dirty() interface can always return accurate information. Cc: stable@vger.kernel.org Co-developed-by: Liupu Wang <wangliupu@loongson.cn> Signed-off-by: Liupu Wang <wangliupu@loongson.cn> Signed-off-by: Tianyang Zhang <zhangtianyang@loongson.cn>
1 parent ce5ad03 commit a073d63

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

arch/loongarch/include/asm/pgtable.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
424424

425425
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
426426
{
427+
if (pte_val(pte) & _PAGE_DIRTY)
428+
pte_val(pte) |= _PAGE_MODIFIED;
429+
427430
return __pte((pte_val(pte) & _PAGE_CHG_MASK) |
428431
(pgprot_val(newprot) & ~_PAGE_CHG_MASK));
429432
}
@@ -547,9 +550,11 @@ static inline struct page *pmd_page(pmd_t pmd)
547550

548551
static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
549552
{
550-
pmd_val(pmd) = (pmd_val(pmd) & _HPAGE_CHG_MASK) |
551-
(pgprot_val(newprot) & ~_HPAGE_CHG_MASK);
552-
return pmd;
553+
if (pmd_val(pmd) & _PAGE_DIRTY)
554+
pmd_val(pmd) |= _PAGE_MODIFIED;
555+
556+
return __pmd((pmd_val(pmd) & _HPAGE_CHG_MASK) |
557+
(pgprot_val(newprot) & ~_HPAGE_CHG_MASK));
553558
}
554559

555560
static inline pmd_t pmd_mkinvalid(pmd_t pmd)

0 commit comments

Comments
 (0)