@@ -84,6 +84,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
bool uffd_wp = cp_flags & MM_CP_UFFD_WP;
bool uffd_wp_resolve = cp_flags & MM_CP_UFFD_WP_RESOLVE;
bool will_need = cp_flags & MM_CP_WILL_NEED;
+ bool try_change_writable = cp_flags & MM_CP_TRY_CHANGE_WRITABLE;
tlb_change_page_size(tlb, PAGE_SIZE);
@@ -114,7 +115,8 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
oldpte = *pte;
if (pte_present(oldpte)) {
pte_t ptent;
- bool preserve_write = prot_numa && pte_write(oldpte);
+ bool preserve_write = (prot_numa || try_change_writable) &&
+ pte_write(oldpte);
/*
* Avoid trapping faults against the zero or KSM
@@ -190,8 +192,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
* example, if a PTE is already dirty and no other
* COW or special handling is required.
*/
- if ((cp_flags & MM_CP_TRY_CHANGE_WRITABLE) &&
- !pte_write(ptent) &&
+ if (try_change_writable && !pte_write(ptent) &&
can_change_pte_writable(vma, addr, ptent)) {
ptent = pte_mkwrite(ptent);
if (will_need)