[PATCH] fixup! mm/migrate: fix read-only page got writable when recover pte

From: Peter Xu
Date: Thu Dec 01 2022 - 10:19:22 EST


Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
mm/migrate.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index c13c828d34f3..d14f1f3ab073 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -214,7 +214,14 @@ static bool remove_migration_pte(struct folio *folio,
if (is_writable_migration_entry(entry))
pte = maybe_mkwrite(pte, vma);
else
- /* NOTE: mk_pte can have write bit set */
+ /*
+ * NOTE: mk_pte() can have write bit set per memory
+ * type (e.g. shmem), or pte_mkdirty() per archs
+ * (e.g., sparc64). If this is a read migration
+ * entry, we need to make sure when we recover the
+ * pte from migration entry to present entry the
+ * write bit is cleared.
+ */
pte = pte_wrprotect(pte);

if (pte_swp_uffd_wp(*pvmw.pte)) {
--
2.37.3


--CjNznIJt6mVQmyak--