Skip to contentSkip to conversation

mm/THP: Use pmd_populate to update the pmd with pgtable_t pointer

PATCH In review Aneesh Kumar K.V 2 participants 8 messages May 12, 2013 – May 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/THP: Use pmd_populate to update the pmd with pgtable_t pointer

From: "Aneesh Kumar K.V" <[email protected]>

We should not use set_pmd_at to update pmd_t with pgtable_t pointer. set_pmd_at is used to set pmd with huge pte entries and architectures like ppc64, clear few flags from the pte when saving a new entry. Without this change we observe bad pte errors like below on ppc64 with THP enabled.

BUG: Bad page map in process ld mm=0xc000001ee39f4780 pte:7fc3f37848000001 pmd:c000001ec0000000
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
index bf281ce..cc47b29 100644
@@ -2333,7 +2333,7 @@ static void collapse_huge_page(struct mm_struct *mm,
 		pte_unmap(pte);
 		spin_lock(&mm->page_table_lock);
 		BUG_ON(!pmd_none(*pmd));
-		set_pmd_at(mm, address, pmd, _pmd);
+		pmd_populate(mm, pmd, _pmd);
 		spin_unlock(&mm->page_table_lock);
 		anon_vma_unlock_write(vma->anon_vma);
 		goto out;
Signature · 7 lines
1.8.1.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Hi Aneesh,

Quoted 25 lines · Aneesh Kumar K.V

updated one fixing a compile warning.

From f721c77eb0d6aaf75758e8e93991a05207680ac8 Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Sun, 12 May 2013 01:59:00 +0530
Subject: [PATCH] mm/THP: Use pmd_populate to update the pmd with pgtable_t
pointer

We should not use set_pmd_at to update pmd_t with pgtable_t pointer. set_pmd_at is used to set pmd with huge pte entries and architectures like ppc64, clear few flags from the pte when saving a new entry. Without this change we observe bad pte errors like below on ppc64 with THP enabled.

BUG: Bad page map in process ld mm=0xc000001ee39f4780 pte:7fc3f37848000001 pmd:c000001ec0000000
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +0 -0
index 03a89a2..f0bad1f 100644

mm/huge_memory.c static void collapse_huge_page(struct mm_struct *mm, · line 2331

Quoted 8 lines
mm/huge_memory.c +1 -1
@@ -2325,7 +2325,7 @@ static void collapse_huge_page(struct mm_struct *mm,
 		pte_unmap(pte);
 		spin_lock(&mm->page_table_lock);
 		BUG_ON(!pmd_none(*pmd));
-		set_pmd_at(mm, address, pmd, _pmd);
+		pmd_populate(mm, pmd, (pgtable_t)_pmd);
 		spin_unlock(&mm->page_table_lock);
 		anon_vma_unlock_write(vma->anon_vma);
 		goto out;

Great, looks like you found the ppc problem with gcc builds and that explains also why it cannot happen on x86.

But about the fix, did you test it? The above should be:
pmd_populate(mm, pmd, pmd_pgtable(_pmd)) instead.

_pmd is not a pointer to a page struct and the cast seems to be hiding a bug. _pmd if something is a physical address potentially with some high bit set not making it a good physical address either.

So you can only use set_pmd_at when establishing hugepmds, and never for establishing regular pmds that points to regular pagetables. I guess a comment would be good to add too.

Thanks!
Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 23 lines · Andrea Arcangeli

Hi Aneesh,

Quoted 20 lines · Aneesh Kumar K.V

updated one fixing a compile warning.

From f721c77eb0d6aaf75758e8e93991a05207680ac8 Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Sun, 12 May 2013 01:59:00 +0530
Subject: [PATCH] mm/THP: Use pmd_populate to update the pmd with pgtable_t
pointer

We should not use set_pmd_at to update pmd_t with pgtable_t pointer. set_pmd_at is used to set pmd with huge pte entries and architectures like ppc64, clear few flags from the pte when saving a new entry. Without this change we observe bad pte errors like below on ppc64 with THP enabled.

BUG: Bad page map in process ld mm=0xc000001ee39f4780 pte:7fc3f37848000001 pmd:c000001ec0000000
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

mm/huge_memory.c static void collapse_huge_page(struct mm_struct *mm, · line 2331

Quoted 13 lines
mm/huge_memory.c +1 -1
index 03a89a2..f0bad1f 100644
@@ -2325,7 +2325,7 @@ static void collapse_huge_page(struct mm_struct *mm,
 		pte_unmap(pte);
 		spin_lock(&mm->page_table_lock);
 		BUG_ON(!pmd_none(*pmd));
-		set_pmd_at(mm, address, pmd, _pmd);
+		pmd_populate(mm, pmd, (pgtable_t)_pmd);
 		spin_unlock(&mm->page_table_lock);
 		anon_vma_unlock_write(vma->anon_vma);
 		goto out;

Great, looks like you found the ppc problem with gcc builds and that explains also why it cannot happen on x86.

yes. That was the reason for the failure.

Quoted 4 lines

But about the fix, did you test it? The above should be:
pmd_populate(mm, pmd, pmd_pgtable(_pmd)) instead.

Yes and it worked in powerpc because we have for ppc64

static inline pgtable_t pmd_pgtable(pmd_t pmd)

{
	return (pgtable_t)(pmd_val(pmd) & ~PMD_MASKED_BITS);
}

That is because we share the PTE page with multiple pmds

Quoted 8 lines

_pmd is not a pointer to a page struct and the cast seems to be hiding a bug. _pmd if something is a physical address potentially with some high bit set not making it a good physical address either.

So you can only use set_pmd_at when establishing hugepmds, and never for establishing regular pmds that points to regular pagetables. I guess a comment would be good to add too.

I will send an updated patch.

-aneesh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 42 lines · Aneesh Kumar K.V
Quoted 23 lines · Andrea Arcangeli

Hi Aneesh,

Quoted 20 lines · Aneesh Kumar K.V

updated one fixing a compile warning.

From f721c77eb0d6aaf75758e8e93991a05207680ac8 Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Sun, 12 May 2013 01:59:00 +0530
Subject: [PATCH] mm/THP: Use pmd_populate to update the pmd with pgtable_t
pointer

We should not use set_pmd_at to update pmd_t with pgtable_t pointer. set_pmd_at is used to set pmd with huge pte entries and architectures like ppc64, clear few flags from the pte when saving a new entry. Without this change we observe bad pte errors like below on ppc64 with THP enabled.

BUG: Bad page map in process ld mm=0xc000001ee39f4780 pte:7fc3f37848000001 pmd:c000001ec0000000
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

mm/huge_memory.c static void collapse_huge_page(struct mm_struct *mm, · line 2331

Quoted 13 lines
mm/huge_memory.c +1 -1
index 03a89a2..f0bad1f 100644
@@ -2325,7 +2325,7 @@ static void collapse_huge_page(struct mm_struct *mm,
 		pte_unmap(pte);
 		spin_lock(&mm->page_table_lock);
 		BUG_ON(!pmd_none(*pmd));
-		set_pmd_at(mm, address, pmd, _pmd);
+		pmd_populate(mm, pmd, (pgtable_t)_pmd);
 		spin_unlock(&mm->page_table_lock);
 		anon_vma_unlock_write(vma->anon_vma);
 		goto out;

Great, looks like you found the ppc problem with gcc builds and that explains also why it cannot happen on x86.

Quoted 2 lines

yes. That was the reason for the failure.

The compiler crash was due to the fact that we didn't do hardware hash pte flush on pmdp_clear_flush. That means we had previous translations available while we did a hugepage copy on collapse. Once we fixed that we started hitting the above Bad page map error. The interesting part for THP on ppc64 is that we have

static inline void flush_tlb_range(struct vm_area_struct *vma,
unsigned long start, unsigned long end)
{
}

That means we don't really wait for those page table walks with local irq disabled to finish in both split page and collapse huge page. I handled that by looking at _PAGE_SPLITTING before we mark the pte _PAGE_BUSY.

Details are captured here
https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-May/106406.html

https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-May/106410.html

It would be nice if you could review the patches.

-aneesh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Hi Aneesh,

Quoted 1 line · Aneesh Kumar K.V

https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-May/106406.html

You need ACCESS_ONCE() in all "pgd = ACCESS_ONCE(*pgdp)", "pud = ACCESS_ONCE(*pudp)" otherwise the compiler could decide your change is a noop.

I think you could remove the #ifdef CONFIG_TRANSPARENT_HUGEPAGE too.

Thanks,
Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 8 lines · Andrea Arcangeli

Hi Aneesh,

Quoted 1 line · Aneesh Kumar K.V

https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-May/106406.html

You need ACCESS_ONCE() in all "pgd = ACCESS_ONCE(*pgdp)", "pud = ACCESS_ONCE(*pudp)" otherwise the compiler could decide your change is a noop.

Will do. I guess we have similar one for x86 here

http://article.gmane.org/gmane.linux.kernel/1483617

May be ppc64 gup walk also need similar changes ?

Quoted 2 lines

I think you could remove the #ifdef CONFIG_TRANSPARENT_HUGEPAGE too.

That was becaue i had pte_pmd available only with that config. I will see if we can fix that.

-aneesh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 4 lines · Aneesh Kumar K.V
Quoted 2 lines · Andrea Arcangeli

Hi Aneesh,

Quoted 8 lines
Quoted 6 lines · Aneesh Kumar K.V
Quoted 1 line

https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-May/106406.html

You need ACCESS_ONCE() in all "pgd = ACCESS_ONCE(*pgdp)", "pud = ACCESS_ONCE(*pudp)" otherwise the compiler could decide your change is a noop.

Will do. I guess we have similar one for x86 here

Exactly.

Quoted 4 lines

http://article.gmane.org/gmane.linux.kernel/1483617

May be ppc64 gup walk also need similar changes ?

I think so, yes.

Quoted 4 lines
Quoted 1 line

I think you could remove the #ifdef CONFIG_TRANSPARENT_HUGEPAGE too.

That was becaue i had pte_pmd available only with that config. I will see if we can fix that.

Ok, up to you.

Thanks,
Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>