Skip to content

Commit cae85cb

Browse files
jankaratorvalds
authored andcommitted
mm/memory.c: fix modifying of page protection by insert_pfn()
Aneesh has reported that PPC triggers the following warning when excercising DAX code: IP set_pte_at+0x3c/0x190 LR insert_pfn+0x208/0x280 Call Trace: insert_pfn+0x68/0x280 dax_iomap_pte_fault.isra.7+0x734/0xa40 __xfs_filemap_fault+0x280/0x2d0 do_wp_page+0x48c/0xa40 __handle_mm_fault+0x8d0/0x1fd0 handle_mm_fault+0x140/0x250 __do_page_fault+0x300/0xd60 handle_page_fault+0x18 Now that is WARN_ON in set_pte_at which is VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep)); The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present. Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE. Link: http://lkml.kernel.org/r/20190311084537.16029-1-jack@suse.cz Fixes: b2770da "mm: add vm_insert_mixed_mkwrite()" Signed-off-by: Jan Kara <jack@suse.cz> Reported-by: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Acked-by: Dan Williams <dan.j.williams@intel.com> Cc: Chandan Rajendra <chandan@linux.ibm.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c412a76 commit cae85cb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mm/memory.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,10 +1549,12 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
15491549
WARN_ON_ONCE(!is_zero_pfn(pte_pfn(*pte)));
15501550
goto out_unlock;
15511551
}
1552-
entry = *pte;
1553-
goto out_mkwrite;
1554-
} else
1555-
goto out_unlock;
1552+
entry = pte_mkyoung(*pte);
1553+
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
1554+
if (ptep_set_access_flags(vma, addr, pte, entry, 1))
1555+
update_mmu_cache(vma, addr, pte);
1556+
}
1557+
goto out_unlock;
15561558
}
15571559

15581560
/* Ok, finally just insert the thing.. */
@@ -1561,7 +1563,6 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
15611563
else
15621564
entry = pte_mkspecial(pfn_t_pte(pfn, prot));
15631565

1564-
out_mkwrite:
15651566
if (mkwrite) {
15661567
entry = pte_mkyoung(entry);
15671568
entry = maybe_mkwrite(pte_mkdirty(entry), vma);

0 commit comments

Comments
 (0)