All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hugetlb: fix pages per hugetlb calculation
@ 2020-06-29 18:50 Mike Kravetz
  2020-06-29 18:54 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Kravetz @ 2020-06-29 18:50 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Matthew Wilcox, Michal Hocko, Kirill A . Shutemov, Andrew Morton,
	Mike Kravetz, stable

The routine hpage_nr_pages() was incorrectly used to calculate the
number of base pages in a hugetlb page.  hpage_nr_pages is designed
to be called for THP pages and will return HPAGE_PMD_NR for hugetlb
pages of any size.

Due to the context in which hpage_nr_pages was called, it is unlikely
to produce a user visible error.  The routine with the incorrect call
is only exercised in the case of hugetlb memory error or migration.
In addition, this would need to be on an architecture which supports
huge page sizes less than PMD_SIZE.  And, the vma containing the huge
page would also need to smaller than PMD_SIZE.

Fixes: c0d0381ade79 ("hugetlbfs: use i_mmap_rwsem for more pmd sharing synchronization")
Cc: stable@kernel.org
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 57ece74e3aae..fab4485b9e52 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1593,7 +1593,7 @@ static struct address_space *_get_hugetlb_page_mapping(struct page *hpage)
 
 	/* Use first found vma */
 	pgoff_start = page_to_pgoff(hpage);
-	pgoff_end = pgoff_start + hpage_nr_pages(hpage) - 1;
+	pgoff_end = pgoff_start + pages_per_huge_page(page_hstate(hpage)) - 1;
 	anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root,
 					pgoff_start, pgoff_end) {
 		struct vm_area_struct *vma = avc->vma;
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hugetlb: fix pages per hugetlb calculation
  2020-06-29 18:50 [PATCH] hugetlb: fix pages per hugetlb calculation Mike Kravetz
@ 2020-06-29 18:54 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2020-06-29 18:54 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Michal Hocko, Kirill A . Shutemov,
	Andrew Morton, stable

On Mon, Jun 29, 2020 at 11:50:03AM -0700, Mike Kravetz wrote:
> The routine hpage_nr_pages() was incorrectly used to calculate the
> number of base pages in a hugetlb page.  hpage_nr_pages is designed
> to be called for THP pages and will return HPAGE_PMD_NR for hugetlb
> pages of any size.
> 
> Due to the context in which hpage_nr_pages was called, it is unlikely
> to produce a user visible error.  The routine with the incorrect call
> is only exercised in the case of hugetlb memory error or migration.
> In addition, this would need to be on an architecture which supports
> huge page sizes less than PMD_SIZE.  And, the vma containing the huge
> page would also need to smaller than PMD_SIZE.
> 
> Fixes: c0d0381ade79 ("hugetlbfs: use i_mmap_rwsem for more pmd sharing synchronization")
> Cc: stable@kernel.org
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Inadvertently-Reported-by: Matthew Wilcox (Oracle) <willy@infradead.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-29 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 18:50 [PATCH] hugetlb: fix pages per hugetlb calculation Mike Kravetz
2020-06-29 18:54 ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.