提交 fc684bc1 编写于 作者: P Peter Xu 提交者: Yang Yingliang

mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible

stable inclusion
from linux-4.19.142
commit 734654ae7962be55c44ff3fb0bb0652b5149cc17

--------------------------------

commit 75802ca6 upstream.

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.

Mike said:

: 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: 017b1660 ("mm: migration: fix migration of huge PMD shared pages")
Signed-off-by: NPeter Xu <peterx@redhat.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/20200730201636.74778-1-peterx@redhat.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NMike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 80797a20
...@@ -4832,25 +4832,21 @@ static bool vma_shareable(struct vm_area_struct *vma, unsigned long addr) ...@@ -4832,25 +4832,21 @@ static bool vma_shareable(struct vm_area_struct *vma, unsigned long addr)
void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
unsigned long *start, unsigned long *end) unsigned long *start, unsigned long *end)
{ {
unsigned long check_addr = *start; unsigned long a_start, a_end;
if (!(vma->vm_flags & VM_MAYSHARE)) if (!(vma->vm_flags & VM_MAYSHARE))
return; return;
for (check_addr = *start; check_addr < *end; check_addr += PUD_SIZE) { /* Extend the range to be PUD aligned for a worst case scenario */
unsigned long a_start = check_addr & PUD_MASK; a_start = ALIGN_DOWN(*start, PUD_SIZE);
unsigned long a_end = a_start + PUD_SIZE; a_end = ALIGN(*end, PUD_SIZE);
/* /*
* If sharing is possible, adjust start/end if necessary. * Intersect the range with the vma range, since pmd sharing won't be
*/ * across vma after all
if (range_in_vma(vma, a_start, a_end)) { */
if (a_start < *start) *start = max(vma->vm_start, a_start);
*start = a_start; *end = min(vma->vm_end, a_end);
if (a_end > *end)
*end = a_end;
}
}
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册