lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251104073006.1764241-1-zhangtianyang@loongson.cn>
Date: Tue,  4 Nov 2025 15:30:06 +0800
From: Tianyang Zhang <zhangtianyang@...ngson.cn>
To: chenhuacai@...nel.org,
	kernel@...0n.name,
	akpm@...ux-foundation.org,
	willy@...radead.org,
	david@...hat.com,
	linmag7@...il.com,
	thuth@...hat.com,
	maobibo@...ngson.cn,
	apopple@...dia.com
Cc: loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org,
	Tianyang Zhang <zhangtianyang@...ngson.cn>,
	Liupu Wang <wangliupu@...ngson.cn>
Subject: [PATCH] Loongarch:Make pte/pmd_modify can set _PAGE_MODIFIED

In the current pte_modify operation, _PAGE_DIRTY might be cleared. Since
the hardware-page-walk does not have a predefined _PAGE_MODIFIED flag,
this could lead to loss of valid data in certain scenarios.

The new modification involves checking whether the original PTE has the
_PAGE_DIRTY flag. If it exists, the _PAGE_MODIFIED bit is set, ensuring
that the pte_dirty interface can return accurate information.

Co-developed-by: Liupu Wang <wangliupu@...ngson.cn>
Signed-off-by: Liupu Wang <wangliupu@...ngson.cn>
Signed-off-by: Tianyang Zhang <zhangtianyang@...ngson.cn>
---
 arch/loongarch/include/asm/pgtable.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
index bd128696e96d..106abfa5183b 100644
--- a/arch/loongarch/include/asm/pgtable.h
+++ b/arch/loongarch/include/asm/pgtable.h
@@ -424,8 +424,13 @@ static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
-	return __pte((pte_val(pte) & _PAGE_CHG_MASK) |
-		     (pgprot_val(newprot) & ~_PAGE_CHG_MASK));
+	unsigned long val = (pte_val(pte) & _PAGE_CHG_MASK) |
+		     (pgprot_val(newprot) & ~_PAGE_CHG_MASK);
+
+	if (pte_val(pte) & _PAGE_DIRTY)
+		val |= _PAGE_MODIFIED;
+
+	return __pte(val);
 }
 
 extern void __update_tlb(struct vm_area_struct *vma,
@@ -547,9 +552,13 @@ static inline struct page *pmd_page(pmd_t pmd)
 
 static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
 {
-	pmd_val(pmd) = (pmd_val(pmd) & _HPAGE_CHG_MASK) |
+	unsigned long val = (pmd_val(pmd) & _HPAGE_CHG_MASK) |
 				(pgprot_val(newprot) & ~_HPAGE_CHG_MASK);
-	return pmd;
+
+	if (pmd_val(pmd) & _PAGE_DIRTY)
+		val |= _PAGE_MODIFIED;
+
+	return __pmd(val);
 }
 
 static inline pmd_t pmd_mkinvalid(pmd_t pmd)
-- 
2.41.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ