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>] [day] [month] [year] [list]
Message-Id: <20221125185857.3110155-1-peterx@redhat.com>
Date:   Fri, 25 Nov 2022 13:58:57 -0500
From:   Peter Xu <peterx@...hat.com>
To:     linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc:     peterx@...hat.com, Andrew Morton <akpm@...ux-foundation.org>,
        Anatoly Pugachev <matorola@...il.com>,
        Raghavendra K T <raghavendra.kt@....com>,
        Thorsten Leemhuis <regressions@...mhuis.info>, Hev <r@....cc>
Subject: [PATCH] mm/thp: Re-apply mkdirty for small pages after split

We used to have 624a2c94f5b7 fixing the regression reported here by Anatoly
Pugachev on sparc64:

https://lore.kernel.org/r/20221021160603.GA23307@u164.east.ru

Where we temporarily ignored the dirty bit for small pages.

Then, Hev <r@....cc> also reported similar issue on loongarch:

(the original mail was private, but Anatoly copied the list here)
https://lore.kernel.org/r/CADxRZqxqb7f_WhMh=jweZP+ynf_JwGd-0VwbYgp4P+T0-AXosw@mail.gmail.com

Hev pointed out that the issue is having HW write bit set within the
pte_mkdirty() so the split pte can be written after split even if e.g. they
were shared by more than one processes, causing data corrupt.

Hev also tried to explain why loongarch set HW write bit in mkdirty:

https://lore.kernel.org/r/CAHirt9itKO_K_HPboXh5AyJtt16Zf0cD73PtHvM=na39u_ztxA@mail.gmail.com

One way to fix it is as what Huacai proposed here for loongarch (then we
can re-apply the dirty bit in thp split):

https://lore.kernel.org/r/20221117042532.4064448-1-chenhuacai@loongson.cnn

We may need similar thing for sparc64, though.

For now since we've found the root cause of the dirty bit issue the simpler
solution (which won't lose the dirty bit for small) that will work for both
is we wr-protect after pte_mkdirty(), so the HW write bit can be persistent
after thp split.

Add a comment for wrprotect, so we will not mess up the ordering later.

With 624a2c94f5b7 this is not a fix anymore, but just brings back the dirty
bit for thp split safely, so we re-apply the optimization but in safe way.

Provide a T-B credit to Hev too (not the exact same patch but the same
outcome) for loongarch.

Cc: Anatoly Pugachev <matorola@...il.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Raghavendra K T <raghavendra.kt@....com>
Cc: Thorsten Leemhuis <regressions@...mhuis.info>
Tested-by: Hev <r@....cc> # loongarch
Signed-off-by: Peter Xu <peterx@...hat.com>
---

PS: Anatoly, feel free to try this too on sparc64.  Applicable to either
branch (Linus's, or akpm's) as long as latest.

Signed-off-by: Peter Xu <peterx@...hat.com>
---
 mm/huge_memory.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ae1e2d80bb6e..5f93ba064323 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2192,16 +2192,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
 			entry = maybe_mkwrite(entry, vma);
 			if (anon_exclusive)
 				SetPageAnonExclusive(page + i);
-			if (!write)
-				entry = pte_wrprotect(entry);
 			if (!young)
 				entry = pte_mkold(entry);
+			/* NOTE: this may set soft-dirty too on some archs */
+			if (dirty)
+				entry = pte_mkdirty(entry);
 			/*
-			 * NOTE: we don't do pte_mkdirty when dirty==true
-			 * because it breaks sparc64 which can sigsegv
-			 * random process.  Need to revisit when we figure
-			 * out what is special with sparc64.
+			 * NOTE: this needs to happen after pte_mkdirty,
+			 * because some archs (sparc64, loongarch) could
+			 * set hw write bit when mkdirty.
 			 */
+			if (!write)
+				entry = pte_wrprotect(entry);
 			if (soft_dirty)
 				entry = pte_mksoft_dirty(entry);
 			if (uffd_wp)
-- 
2.37.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ