mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible
This is found by code observation only.
Firstly, the worst case scenario should assume the whole range was covered
by pmd sharing. The old algorithm might not work as expected for ranges
like (1g-2m, 1g+2m), where the adjusted range should be (0, 1g+2m) but the
expected range should be (0, 2g).
Since at it, remove the loop since it should not be required. With that,
the new code should be faster too when the invalidating range is huge.
: With range (1g-2m, 1g+2m) within a vma (0, 2g) the existing code will only
: adjust to (0, 1g+2m) which is incorrect.
: We should cc stable. The original reason for adjusting the range was to
: prevent data corruption (getting wrong page). Since the range is not
: always adjusted correctly, the potential for corruption still exists.
: However, I am fairly confident that adjust_range_if_pmd_sharing_possible
: is only gong to be called in two cases:
: 1) for a single page
: 2) for range == entire vma
: In those cases, the current code should produce the correct results.
: To be safe, let's just cc stable.
Fixes: 017b1660df89 ("mm: migration: fix migration of huge PMD shared pages")
Signed-off-by: Peter Xu <email@example.com>
Signed-off-by: Andrew Morton <firstname.lastname@example.org>
Reviewed-by: Mike Kravetz <email@example.com>
Cc: Andrea Arcangeli <firstname.lastname@example.org>
Cc: Matthew Wilcox <email@example.com>
Signed-off-by: Linus Torvalds <firstname.lastname@example.org>
1 file changed