* [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures
@ 2019-05-28 5:36 Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 2/3] powerpc/mm/hugetlb: Fix kernel crash if we fail to allocate page table caches Aneesh Kumar K.V
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Aneesh Kumar K.V @ 2019-05-28 5:36 UTC (permalink / raw)
To: npiggin, paulus, mpe; +Cc: Aneesh Kumar K.V, linuxppc-dev
This fixes kernel crash that arises due to not handling page table allocation
failures while allocating hugetlb page table.
Fixes: e2b3d202d1db ("powerpc: Switch 16GB and 16MB explicit hugepages to a different page table format")
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
arch/powerpc/mm/hugetlbpage.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index b5d92dc32844..1de0f43a68e5 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -130,6 +130,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz
} else {
pdshift = PUD_SHIFT;
pu = pud_alloc(mm, pg, addr);
+ if (!pu)
+ return NULL;
if (pshift == PUD_SHIFT)
return (pte_t *)pu;
else if (pshift > PMD_SHIFT) {
@@ -138,6 +140,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz
} else {
pdshift = PMD_SHIFT;
pm = pmd_alloc(mm, pu, addr);
+ if (!pm)
+ return NULL;
if (pshift == PMD_SHIFT)
/* 16MB hugepage */
return (pte_t *)pm;
@@ -154,12 +158,16 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz
} else {
pdshift = PUD_SHIFT;
pu = pud_alloc(mm, pg, addr);
+ if (!pu)
+ return NULL;
if (pshift >= PUD_SHIFT) {
ptl = pud_lockptr(mm, pu);
hpdp = (hugepd_t *)pu;
} else {
pdshift = PMD_SHIFT;
pm = pmd_alloc(mm, pu, addr);
+ if (!pm)
+ return NULL;
ptl = pmd_lockptr(mm, pm);
hpdp = (hugepd_t *)pm;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] powerpc/mm/hugetlb: Fix kernel crash if we fail to allocate page table caches
2019-05-28 5:36 [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Aneesh Kumar K.V
@ 2019-05-28 5:36 ` Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 3/3] powerpc/mm/hugetlb: Don't enable HugeTLB if we don't have a page table cache Aneesh Kumar K.V
2019-07-08 1:19 ` [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Michael Ellerman
2 siblings, 0 replies; 4+ messages in thread
From: Aneesh Kumar K.V @ 2019-05-28 5:36 UTC (permalink / raw)
To: npiggin, paulus, mpe; +Cc: Aneesh Kumar K.V, linuxppc-dev
We only check for hugetlb allocations, because with hugetlb we do conditional
registration. For PGD/PUD/PMD levels we register them always in
pgtable_cache_init.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
arch/powerpc/mm/hugetlbpage.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 1de0f43a68e5..f55dc110f2ad 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -61,12 +61,17 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,
num_hugepd = 1;
}
+ if (!cachep) {
+ WARN_ONCE(1, "No page table cache created for hugetlb tables");
+ return -ENOMEM;
+ }
+
new = kmem_cache_alloc(cachep, pgtable_gfp_flags(mm, GFP_KERNEL));
BUG_ON(pshift > HUGEPD_SHIFT_MASK);
BUG_ON((unsigned long)new & HUGEPD_SHIFT_MASK);
- if (! new)
+ if (!new)
return -ENOMEM;
/*
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] powerpc/mm/hugetlb: Don't enable HugeTLB if we don't have a page table cache
2019-05-28 5:36 [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 2/3] powerpc/mm/hugetlb: Fix kernel crash if we fail to allocate page table caches Aneesh Kumar K.V
@ 2019-05-28 5:36 ` Aneesh Kumar K.V
2019-07-08 1:19 ` [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Michael Ellerman
2 siblings, 0 replies; 4+ messages in thread
From: Aneesh Kumar K.V @ 2019-05-28 5:36 UTC (permalink / raw)
To: npiggin, paulus, mpe; +Cc: Aneesh Kumar K.V, linuxppc-dev
This makes sure we don't enable HugeTLB if the cache is not configured.
I am still not sure about this. IMHO hugetlb support should be a hardware
support derivative and any cache allocation failure should be handled as I did
in the earlier patch. But then if we were not able to create hugetlb page table
cache, we can as well declare hugetlb support disabled thereby avoiding calling
into allocation routines.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
arch/powerpc/mm/hugetlbpage.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index f55dc110f2ad..d34540479b1a 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -601,6 +601,7 @@ __setup("hugepagesz=", hugepage_setup_sz);
static int __init hugetlbpage_init(void)
{
+ bool configured = false;
int psize;
if (hugetlb_disabled) {
@@ -651,10 +652,15 @@ static int __init hugetlbpage_init(void)
pgtable_cache_add(pdshift - shift);
else if (IS_ENABLED(CONFIG_PPC_FSL_BOOK3E) || IS_ENABLED(CONFIG_PPC_8xx))
pgtable_cache_add(PTE_T_ORDER);
+
+ configured = true;
}
- if (IS_ENABLED(CONFIG_HUGETLB_PAGE_SIZE_VARIABLE))
- hugetlbpage_init_default();
+ if (configured) {
+ if (IS_ENABLED(CONFIG_HUGETLB_PAGE_SIZE_VARIABLE))
+ hugetlbpage_init_default();
+ } else
+ pr_info("Failed to initialize. Disabling HugeTLB");
return 0;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures
2019-05-28 5:36 [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 2/3] powerpc/mm/hugetlb: Fix kernel crash if we fail to allocate page table caches Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 3/3] powerpc/mm/hugetlb: Don't enable HugeTLB if we don't have a page table cache Aneesh Kumar K.V
@ 2019-07-08 1:19 ` Michael Ellerman
2 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2019-07-08 1:19 UTC (permalink / raw)
To: Aneesh Kumar K.V, npiggin, paulus; +Cc: Aneesh Kumar K.V, linuxppc-dev
On Tue, 2019-05-28 at 05:36:24 UTC, "Aneesh Kumar K.V" wrote:
> This fixes kernel crash that arises due to not handling page table allocation
> failures while allocating hugetlb page table.
>
> Fixes: e2b3d202d1db ("powerpc: Switch 16GB and 16MB explicit hugepages to a different page table format")
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/2230ebf6e6dd0b7751e2921b40f6cfe34f09bb16
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-08 1:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-28 5:36 [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 2/3] powerpc/mm/hugetlb: Fix kernel crash if we fail to allocate page table caches Aneesh Kumar K.V
2019-05-28 5:36 ` [PATCH v2 3/3] powerpc/mm/hugetlb: Don't enable HugeTLB if we don't have a page table cache Aneesh Kumar K.V
2019-07-08 1:19 ` [PATCH v2 1/3] powerpc/mm: Handle page table allocation failures Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).