Commit f7adeff6 authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

mm: Fix warning in insert_pfn()

commit f2c57d91b0d96aa13ccff4e3b178038f17b00658 upstream.

In DAX mode a write pagefault can race with write(2) in the following

CPU0                            CPU1
                                write fault for mapped zero page (hole)
      - allocates blocks
        - invalidates radix tree entries in given range
                                    - no entry found, creates empty
                                    - finds already allocated block
                                    - WARNs and does nothing because there
                                      is still zero page mapped in PTE

This race results in WARN_ON from insert_pfn() and is occasionally
triggered by fstest generic/344. Note that the race is otherwise
harmless as before write(2) on CPU0 is finished, we will invalidate page
tables properly and thus user of mmap will see modified data from
write(2) from that point on. So just restrict the warning only to the
case when the PFN in PTE is not zero page.

Link: default avatarJan Kara <>
Reviewed-by: default avatarAndrew Morton <>
Cc: Ross Zwisler <>
Cc: Dan Williams <>
Cc: Dave Jiang <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent e2895110
......@@ -1804,10 +1804,15 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr,
* in may not match the PFN we have mapped if the
* mapped PFN is a writeable COW page. In the mkwrite
* case we are creating a writable PTE for a shared
* mapping and we expect the PFNs to match.
* mapping and we expect the PFNs to match. If they
* don't match, we are likely racing with block
* allocation and mapping invalidation so just skip the
* update.
if (WARN_ON_ONCE(pte_pfn(*pte) != pfn_t_to_pfn(pfn)))
if (pte_pfn(*pte) != pfn_t_to_pfn(pfn)) {
goto out_unlock;
entry = *pte;
goto out_mkwrite;
} else
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment