Re: [PATCH] sparc64: Fix gup_huge_pmd

From: Nitin Gupta
Date: Thu Jun 22 2017 - 10:38:09 EST


Hi Julian,


On 6/22/17 3:53 AM, Julian Calaby wrote:
On Thu, Jun 22, 2017 at 7:50 AM, Nitin Gupta <nitin.m.gupta@xxxxxxxxxx> wrote:
The function assumes that each PMD points to head of a
huge page. This is not correct as a PMD can point to
start of any 8M region with a, say 256M, hugepage. The
fix ensures that it points to the correct head of any PMD
huge page.

Signed-off-by: Nitin Gupta <nitin.m.gupta@xxxxxxxxxx>
---
arch/sparc/mm/gup.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
index cd0e32b..9116a6f 100644
--- a/arch/sparc/mm/gup.c
+++ b/arch/sparc/mm/gup.c
@@ -80,6 +80,8 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
refs = 0;
head = pmd_page(pmd);
page = head + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
+ if (PageTail(head))
+ head = compound_head(head);
Stupid question: shouldn't this go before the page calculation?

No, it should be after page calculation: First, 'head' points to base of
the PMD page, then 'page' points to an offset within that page. Finally,
we make sure that head variable points to head of the compound page
which contains the addr.

I think confusion comes from the use of 'head' for pointing to a
non-head page. So, maybe it would be more clear to write that part
of the function this way:

page = pmd_page(pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
head = compound_head(page);

Thanks,
Nitin