mm: thp: fix COW accuracy on double map THP
David reported the do_wp_page() fault would erroenously copy a subpage
mapped on a double map THP, that was actually exclusive, because some
other subpage wasn't exclusive.
The page_trans_huge_map_swapcount() was doing the right math for the
whole THP that is used to decide if the THP COW can reuse the page
without splitting the pmd and falling back to non-THP COW, but it was
inaccurate and causing too much COWing if used to take the non-THP COW
decision.
Since the day write and longterm GUP pins existed, COWing too much is
always a bug that causes loss of synchronicity, so this longstanding
issue also causd a loss of synchronicity of the GUP pin.
The fix is simple and it just consists of doing the same math but
subpage granular if the caller is only interested to reuse the
subpage, not the whole THP.
Fixes: 6d0a07edd17c ("mm: thp: calculate the mapcount correctly for THP pages during WP faults")
Reported-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
10 files changed