* [PATCH 2/5] powerpc/kconfig: move CONFIG_PPC32 into Kconfig.cputype
2020-01-14 17:54 [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Christophe Leroy
@ 2020-01-14 17:54 ` Christophe Leroy
2020-01-14 17:54 ` [PATCH 3/5] powerpc/32: force KASAN_VMALLOC for modules Christophe Leroy
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2020-01-14 17:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, erhard_f, dja
Cc: linux-kernel, linuxppc-dev
Move CONFIG_PPC32 at the same place as CONFIG_PPC64 for consistency.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/Kconfig | 4 ----
arch/powerpc/platforms/Kconfig.cputype | 4 ++++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index a247bbfb03d4..c2a604b9592b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -1,10 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
source "arch/powerpc/platforms/Kconfig.cputype"
-config PPC32
- bool
- default y if !PPC64
-
config 32BIT
bool
default y if PPC32
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 8d7f9c3dc771..536a2efcb7f0 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -1,4 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
+config PPC32
+ bool
+ default y if !PPC64
+
config PPC64
bool "64-bit kernel"
select ZLIB_DEFLATE
--
2.13.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] powerpc/32: force KASAN_VMALLOC for modules
2020-01-14 17:54 [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Christophe Leroy
2020-01-14 17:54 ` [PATCH 2/5] powerpc/kconfig: move CONFIG_PPC32 into Kconfig.cputype Christophe Leroy
@ 2020-01-14 17:54 ` Christophe Leroy
2020-01-14 17:54 ` [PATCH 4/5] powerpc/32: Simplify KASAN init Christophe Leroy
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2020-01-14 17:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, erhard_f, dja
Cc: linux-kernel, linuxppc-dev
Unloading/Reloading of modules seems to fail with KASAN_VMALLOC
but works properly with it.
Force selection of KASAN_VMALLOC when MODULES are selected, and
drop module_alloc() which was dedicated to KASAN for modules.
Reported-by: <erhard_f@mailbox.org>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=205283
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/mm/kasan/kasan_init_32.c | 31 +++++--------------------------
arch/powerpc/platforms/Kconfig.cputype | 1 +
2 files changed, 6 insertions(+), 26 deletions(-)
diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c
index 88036fb88350..b782d92622b4 100644
--- a/arch/powerpc/mm/kasan/kasan_init_32.c
+++ b/arch/powerpc/mm/kasan/kasan_init_32.c
@@ -12,7 +12,7 @@
#include <asm/code-patching.h>
#include <mm/mmu_decl.h>
-static pgprot_t kasan_prot_ro(void)
+static pgprot_t __init kasan_prot_ro(void)
{
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
return PAGE_READONLY;
@@ -20,7 +20,7 @@ static pgprot_t kasan_prot_ro(void)
return PAGE_KERNEL_RO;
}
-static void kasan_populate_pte(pte_t *ptep, pgprot_t prot)
+static void __init kasan_populate_pte(pte_t *ptep, pgprot_t prot)
{
unsigned long va = (unsigned long)kasan_early_shadow_page;
phys_addr_t pa = __pa(kasan_early_shadow_page);
@@ -30,7 +30,7 @@ static void kasan_populate_pte(pte_t *ptep, pgprot_t prot)
__set_pte_at(&init_mm, va, ptep, pfn_pte(PHYS_PFN(pa), prot), 0);
}
-static int __ref kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end)
+static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end)
{
pmd_t *pmd;
unsigned long k_cur, k_next;
@@ -70,7 +70,7 @@ static int __ref kasan_init_shadow_page_tables(unsigned long k_start, unsigned l
return 0;
}
-static void __ref *kasan_get_one_page(void)
+static void __init *kasan_get_one_page(void)
{
if (slab_is_available())
return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
@@ -78,7 +78,7 @@ static void __ref *kasan_get_one_page(void)
return memblock_alloc(PAGE_SIZE, PAGE_SIZE);
}
-static int __ref kasan_init_region(void *start, size_t size)
+static int __init kasan_init_region(void *start, size_t size)
{
unsigned long k_start = (unsigned long)kasan_mem_to_shadow(start);
unsigned long k_end = (unsigned long)kasan_mem_to_shadow(start + size);
@@ -196,27 +196,6 @@ void __init kasan_late_init(void)
kasan_unmap_early_shadow_vmalloc();
}
-#if defined(CONFIG_MODULES) && !defined(CONFIG_KASAN_VMALLOC)
-void *module_alloc(unsigned long size)
-{
- void *base;
-
- base = __vmalloc_node_range(size, MODULE_ALIGN, VMALLOC_START, VMALLOC_END,
- GFP_KERNEL, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS,
- NUMA_NO_NODE, __builtin_return_address(0));
-
- if (!base)
- return NULL;
-
- if (!kasan_init_region(base, size))
- return base;
-
- vfree(base);
-
- return NULL;
-}
-#endif
-
#ifdef CONFIG_PPC_BOOK3S_32
u8 __initdata early_hash[256 << 10] __aligned(256 << 10) = {0};
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 536a2efcb7f0..851a92ffe290 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -2,6 +2,7 @@
config PPC32
bool
default y if !PPC64
+ select KASAN_VMALLOC if KASAN && MODULES
config PPC64
bool "64-bit kernel"
--
2.13.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] powerpc/32: Simplify KASAN init
2020-01-14 17:54 [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Christophe Leroy
2020-01-14 17:54 ` [PATCH 2/5] powerpc/kconfig: move CONFIG_PPC32 into Kconfig.cputype Christophe Leroy
2020-01-14 17:54 ` [PATCH 3/5] powerpc/32: force KASAN_VMALLOC for modules Christophe Leroy
@ 2020-01-14 17:54 ` Christophe Leroy
2020-01-14 17:54 ` [PATCH 5/5] powerpc/32: reuse orphaned memblocks in kasan_init_shadow_page_tables() Christophe Leroy
2020-01-29 5:17 ` [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2020-01-14 17:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, erhard_f, dja
Cc: linux-kernel, linuxppc-dev
Since kasan_init_region() is not used anymore for modules,
KASAN init is done while slab_is_available() is false.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/mm/kasan/kasan_init_32.c | 26 +++++---------------------
1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c
index b782d92622b4..c4bf9ed04f88 100644
--- a/arch/powerpc/mm/kasan/kasan_init_32.c
+++ b/arch/powerpc/mm/kasan/kasan_init_32.c
@@ -34,7 +34,6 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned
{
pmd_t *pmd;
unsigned long k_cur, k_next;
- pgprot_t prot = slab_is_available() ? kasan_prot_ro() : PAGE_KERNEL;
pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start);
@@ -45,14 +44,11 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned
if ((void *)pmd_page_vaddr(*pmd) != kasan_early_shadow_pte)
continue;
- if (slab_is_available())
- new = pte_alloc_one_kernel(&init_mm);
- else
- new = memblock_alloc(PTE_FRAG_SIZE, PTE_FRAG_SIZE);
+ new = memblock_alloc(PTE_FRAG_SIZE, PTE_FRAG_SIZE);
if (!new)
return -ENOMEM;
- kasan_populate_pte(new, prot);
+ kasan_populate_pte(new, PAGE_KERNEL);
smp_wmb(); /* See comment in __pte_alloc */
@@ -63,39 +59,27 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned
new = NULL;
}
spin_unlock(&init_mm.page_table_lock);
-
- if (new && slab_is_available())
- pte_free_kernel(&init_mm, new);
}
return 0;
}
-static void __init *kasan_get_one_page(void)
-{
- if (slab_is_available())
- return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
-
- return memblock_alloc(PAGE_SIZE, PAGE_SIZE);
-}
-
static int __init kasan_init_region(void *start, size_t size)
{
unsigned long k_start = (unsigned long)kasan_mem_to_shadow(start);
unsigned long k_end = (unsigned long)kasan_mem_to_shadow(start + size);
unsigned long k_cur;
int ret;
- void *block = NULL;
+ void *block;
ret = kasan_init_shadow_page_tables(k_start, k_end);
if (ret)
return ret;
- if (!slab_is_available())
- block = memblock_alloc(k_end - k_start, PAGE_SIZE);
+ block = memblock_alloc(k_end - k_start, PAGE_SIZE);
for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) {
pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur);
- void *va = block ? block + k_cur - k_start : kasan_get_one_page();
+ void *va = block + k_cur - k_start;
pte_t pte = pfn_pte(PHYS_PFN(__pa(va)), PAGE_KERNEL);
if (!va)
--
2.13.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] powerpc/32: reuse orphaned memblocks in kasan_init_shadow_page_tables()
2020-01-14 17:54 [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Christophe Leroy
` (2 preceding siblings ...)
2020-01-14 17:54 ` [PATCH 4/5] powerpc/32: Simplify KASAN init Christophe Leroy
@ 2020-01-14 17:54 ` Christophe Leroy
2020-01-29 5:17 ` [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2020-01-14 17:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, erhard_f, dja
Cc: linux-kernel, linuxppc-dev
If concurrent PMD population has happened, re-use orphaned memblocks.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/mm/kasan/kasan_init_32.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c
index c4bf9ed04f88..d3cacd462560 100644
--- a/arch/powerpc/mm/kasan/kasan_init_32.c
+++ b/arch/powerpc/mm/kasan/kasan_init_32.c
@@ -34,17 +34,17 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned
{
pmd_t *pmd;
unsigned long k_cur, k_next;
+ pte_t *new = NULL;
pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start);
for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd++) {
- pte_t *new;
-
k_next = pgd_addr_end(k_cur, k_end);
if ((void *)pmd_page_vaddr(*pmd) != kasan_early_shadow_pte)
continue;
- new = memblock_alloc(PTE_FRAG_SIZE, PTE_FRAG_SIZE);
+ if (!new)
+ new = memblock_alloc(PTE_FRAG_SIZE, PTE_FRAG_SIZE);
if (!new)
return -ENOMEM;
--
2.13.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC
2020-01-14 17:54 [PATCH 1/5] powerpc/32: add support of KASAN_VMALLOC Christophe Leroy
` (3 preceding siblings ...)
2020-01-14 17:54 ` [PATCH 5/5] powerpc/32: reuse orphaned memblocks in kasan_init_shadow_page_tables() Christophe Leroy
@ 2020-01-29 5:17 ` Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2020-01-29 5:17 UTC (permalink / raw)
To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras, erhard_f, dja
Cc: linuxppc-dev, linux-kernel
On Tue, 2020-01-14 at 17:54:00 UTC, Christophe Leroy wrote:
> Add support of KASAN_VMALLOC on PPC32.
>
> To allow this, the early shadow covering the VMALLOC space
> need to be removed once high_memory var is set and before
> freeing memblock.
>
> And the VMALLOC area need to be aligned such that boundaries
> are covered by a full shadow page.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/3d4247fcc938d0ab5cf6fdb752dae07fdeab9736
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread