From: Kefeng Wang <hidden> Date: 2021-07-20 02:52:45
Percpu embedded first chunk allocator is the firstly option, but it
could fails on ARM64, eg,
"percpu: max_distance=0x5fcfdc640000 too large for vmalloc space 0x781fefff0000"
"percpu: max_distance=0x600000540000 too large for vmalloc space 0x7dffb7ff0000"
"percpu: max_distance=0x5fff9adb0000 too large for vmalloc space 0x5dffb7ff0000"
then we could meet "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
even the system could not boot successfully.
Let's implement page mapping percpu first chunk allocator as a fallback
to the embedding allocator to increase the robustness of the system.
Also fix a crash when both NEED_PER_CPU_PAGE_FIRST_CHUNK and KASAN_VMALLOC enabled.
Tested on ARM64 qemu with cmdline "percpu_alloc=page" based on v5.14-rc2.
V2:
- fix build error when CONFIG_KASAN disabled, found by lkp@intel.com
- drop wrong __weak comment from kasan_populate_early_vm_area_shadow(),
found by Marco Elver [off-list ref]
Kefeng Wang (3):
vmalloc: Choose a better start address in vm_area_register_early()
arm64: Support page mapping percpu first chunk allocator
kasan: arm64: Fix pcpu_page_first_chunk crash with KASAN_VMALLOC
arch/arm64/Kconfig | 4 ++
arch/arm64/mm/kasan_init.c | 17 ++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 6 +++
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 9 +++--
6 files changed, 110 insertions(+), 13 deletions(-)
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Kefeng Wang <hidden> Date: 2021-07-20 02:52:08
There are some fixed locations in the vmalloc area be reserved
in ARM(see iotable_init()) and ARM64(see map_kernel()), but for
pcpu_page_first_chunk(), it calls vm_area_register_early() and
choose VMALLOC_START as the start address of vmap area which
could be conflicted with above address, then could trigger a
BUG_ON in vm_area_add_early().
Let's choose the end of existing address range in vmlist as the
start address instead of VMALLOC_START to avoid the BUG_ON.
Signed-off-by: Kefeng Wang <redacted>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
From: Kefeng Wang <hidden> Date: 2021-07-20 02:53:26
Percpu embedded first chunk allocator is the firstly option, but it
could fails on ARM64, eg,
"percpu: max_distance=0x5fcfdc640000 too large for vmalloc space 0x781fefff0000"
"percpu: max_distance=0x600000540000 too large for vmalloc space 0x7dffb7ff0000"
"percpu: max_distance=0x5fff9adb0000 too large for vmalloc space 0x5dffb7ff0000"
then we could meet "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
even the system could not boot successfully.
Let's implement page mapping percpu first chunk allocator as a fallback
to the embedding allocator to increase the robustness of the system.
Signed-off-by: Kefeng Wang <redacted>
---
arch/arm64/Kconfig | 4 ++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++++-----
2 files changed, 76 insertions(+), 10 deletions(-)
From: Marco Elver <elver@google.com> Date: 2021-07-22 11:01:11
On Tue, Jul 20, 2021 at 10:51AM +0800, Kefeng Wang wrote:
With KASAN_VMALLOC and NEED_PER_CPU_PAGE_FIRST_CHUNK, it crashs,
Unable to handle kernel paging request at virtual address ffff7000028f2000
...
swapper pgtable: 64k pages, 48-bit VAs, pgdp=0000000042440000
[ffff7000028f2000] pgd=000000063e7c0003, p4d=000000063e7c0003, pud=000000063e7c0003, pmd=000000063e7b0003, pte=0000000000000000
Internal error: Oops: 96000007 [#1] PREEMPT SMP
Modules linked in:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.13.0-rc4-00003-gc6e6e28f3f30-dirty #62
Hardware name: linux,dummy-virt (DT)
pstate: 200000c5 (nzCv daIF -PAN -UAO -TCO BTYPE=--)
pc : kasan_check_range+0x90/0x1a0
lr : memcpy+0x88/0xf4
sp : ffff80001378fe20
...
Call trace:
kasan_check_range+0x90/0x1a0
pcpu_page_first_chunk+0x3f0/0x568
setup_per_cpu_areas+0xb8/0x184
start_kernel+0x8c/0x328
The vm area used in vm_area_register_early() has no kasan shadow memory,
Let's add a new kasan_populate_early_vm_area_shadow() function to populate
the vm area shadow memory to fix the issue.
Signed-off-by: Kefeng Wang <redacted>
Acked-by: Marco Elver <elver@google.com>
for the kasan bits.
From: Kefeng Wang <hidden> Date: 2021-07-22 12:14:39
On 2021/7/22 19:00, Marco Elver wrote:
On Tue, Jul 20, 2021 at 10:51AM +0800, Kefeng Wang wrote:
quoted
With KASAN_VMALLOC and NEED_PER_CPU_PAGE_FIRST_CHUNK, it crashs,
Unable to handle kernel paging request at virtual address ffff7000028f2000
...
swapper pgtable: 64k pages, 48-bit VAs, pgdp=0000000042440000
[ffff7000028f2000] pgd=000000063e7c0003, p4d=000000063e7c0003, pud=000000063e7c0003, pmd=000000063e7b0003, pte=0000000000000000
Internal error: Oops: 96000007 [#1] PREEMPT SMP
Modules linked in:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.13.0-rc4-00003-gc6e6e28f3f30-dirty #62
Hardware name: linux,dummy-virt (DT)
pstate: 200000c5 (nzCv daIF -PAN -UAO -TCO BTYPE=--)
pc : kasan_check_range+0x90/0x1a0
lr : memcpy+0x88/0xf4
sp : ffff80001378fe20
...
Call trace:
kasan_check_range+0x90/0x1a0
pcpu_page_first_chunk+0x3f0/0x568
setup_per_cpu_areas+0xb8/0x184
start_kernel+0x8c/0x328
The vm area used in vm_area_register_early() has no kasan shadow memory,
Let's add a new kasan_populate_early_vm_area_shadow() function to populate
the vm area shadow memory to fix the issue.
Signed-off-by: Kefeng Wang <redacted>
Acked-by: Marco Elver <elver@google.com>
for the kasan bits.
From: Kefeng Wang <hidden> Date: 2021-07-26 01:19:17
Hi Will and Catalin,any comments,kindly ping, thanks.
On 2021/7/20 10:51, Kefeng Wang wrote:
Percpu embedded first chunk allocator is the firstly option, but it
could fails on ARM64, eg,
"percpu: max_distance=0x5fcfdc640000 too large for vmalloc space 0x781fefff0000"
"percpu: max_distance=0x600000540000 too large for vmalloc space 0x7dffb7ff0000"
"percpu: max_distance=0x5fff9adb0000 too large for vmalloc space 0x5dffb7ff0000"
then we could meet "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
even the system could not boot successfully.
Let's implement page mapping percpu first chunk allocator as a fallback
to the embedding allocator to increase the robustness of the system.
Also fix a crash when both NEED_PER_CPU_PAGE_FIRST_CHUNK and KASAN_VMALLOC enabled.
Tested on ARM64 qemu with cmdline "percpu_alloc=page" based on v5.14-rc2.
V2:
- fix build error when CONFIG_KASAN disabled, found by lkp@intel.com
- drop wrong __weak comment from kasan_populate_early_vm_area_shadow(),
found by Marco Elver [off-list ref]
Kefeng Wang (3):
vmalloc: Choose a better start address in vm_area_register_early()
arm64: Support page mapping percpu first chunk allocator
kasan: arm64: Fix pcpu_page_first_chunk crash with KASAN_VMALLOC
arch/arm64/Kconfig | 4 ++
arch/arm64/mm/kasan_init.c | 17 ++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 6 +++
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 9 +++--
6 files changed, 110 insertions(+), 13 deletions(-)
On Tue, Jul 20, 2021 at 10:51:03AM +0800, Kefeng Wang wrote:
quoted hunk
There are some fixed locations in the vmalloc area be reserved
in ARM(see iotable_init()) and ARM64(see map_kernel()), but for
pcpu_page_first_chunk(), it calls vm_area_register_early() and
choose VMALLOC_START as the start address of vmap area which
could be conflicted with above address, then could trigger a
BUG_ON in vm_area_add_early().
Let's choose the end of existing address range in vmlist as the
start address instead of VMALLOC_START to avoid the BUG_ON.
Signed-off-by: Kefeng Wang <redacted>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Is there a risk of breaking other architectures? It doesn't look like to
me but I thought I'd ask.
Also, instead of always picking the end, could we search for a range
that fits?
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Tue, Jul 20, 2021 at 10:51:04AM +0800, Kefeng Wang wrote:
Percpu embedded first chunk allocator is the firstly option, but it
could fails on ARM64, eg,
"percpu: max_distance=0x5fcfdc640000 too large for vmalloc space 0x781fefff0000"
"percpu: max_distance=0x600000540000 too large for vmalloc space 0x7dffb7ff0000"
"percpu: max_distance=0x5fff9adb0000 too large for vmalloc space 0x5dffb7ff0000"
then we could meet "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
even the system could not boot successfully.
Let's implement page mapping percpu first chunk allocator as a fallback
to the embedding allocator to increase the robustness of the system.
It looks like x86, powerpc and sparc implement their own
setup_per_cpu_areas(). I had a quick look on finding some commonalities
but I think it's a lot more hassle to make a generic version out of them
(powerpc looks the simplest though). I think we could add a generic
variant with the arm64 support and later migrate other architectures to
it if possible.
The patch looks ok to me otherwise but I'd need an ack from Greg as it
touches drivers/.
BTW, do we need something similar for the non-NUMA
setup_per_cpu_areas()? I can see this patch only enables
NEED_PER_CPU_PAGE_FIRST_CHUNK if NUMA.
Leaving the rest of the patch below for Greg.
From: Kefeng Wang <hidden> Date: 2021-08-02 02:39:09
On 2021/8/1 23:23, Catalin Marinas wrote:
On Tue, Jul 20, 2021 at 10:51:03AM +0800, Kefeng Wang wrote:
quoted
There are some fixed locations in the vmalloc area be reserved
in ARM(see iotable_init()) and ARM64(see map_kernel()), but for
pcpu_page_first_chunk(), it calls vm_area_register_early() and
choose VMALLOC_START as the start address of vmap area which
could be conflicted with above address, then could trigger a
BUG_ON in vm_area_add_early().
Let's choose the end of existing address range in vmlist as the
start address instead of VMALLOC_START to avoid the BUG_ON.
Signed-off-by: Kefeng Wang <redacted>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Is there a risk of breaking other architectures? It doesn't look like to
me but I thought I'd ask.
Before this patch, vm_init_off is to record the offset from VMALLOC_START,
but it use VMALLOC_START as start address on the function
vm_area_register_early()
called firstly, this will cause the BUG_ON.
With this patch, the most important change is that we choose the start
address via
dynamic calculate the 'start' address by traversing the list.
[wkf@localhost linux-next]$ git grep vm_area_register_early
arch/alpha/mm/init.c: vm_area_register_early(&console_remap_vm, PAGE_SIZE);
arch/x86/xen/p2m.c: vm_area_register_early(&vm, PMD_SIZE *
PMDS_PER_MID_PAGE);
mm/percpu.c: vm_area_register_early(&vm, PAGE_SIZE);
[wkf@localhost linux-next]$ git grep vm_area_add_early
arch/arm/mm/ioremap.c: vm_area_add_early(vm);
arch/arm64/mm/mmu.c: vm_area_add_early(vma);
x86/alpha won't call vm_area_add_early(), only arm64 could call both vm_area_add_early()
and vm_area_register_early() when this patchset is merged. so it won't break other architectures.
Also, instead of always picking the end, could we search for a range
that fits?
We only need a space in vmalloc range, using end or a range in the
middle is not different.
From: Kefeng Wang <hidden> Date: 2021-08-02 02:47:12
On 2021/8/1 23:53, Catalin Marinas wrote:
On Tue, Jul 20, 2021 at 10:51:04AM +0800, Kefeng Wang wrote:
quoted
Percpu embedded first chunk allocator is the firstly option, but it
could fails on ARM64, eg,
"percpu: max_distance=0x5fcfdc640000 too large for vmalloc space 0x781fefff0000"
"percpu: max_distance=0x600000540000 too large for vmalloc space 0x7dffb7ff0000"
"percpu: max_distance=0x5fff9adb0000 too large for vmalloc space 0x5dffb7ff0000"
then we could meet "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
even the system could not boot successfully.
Let's implement page mapping percpu first chunk allocator as a fallback
to the embedding allocator to increase the robustness of the system.
It looks like x86, powerpc and sparc implement their own
setup_per_cpu_areas(). I had a quick look on finding some commonalities
but I think it's a lot more hassle to make a generic version out of them
(powerpc looks the simplest though). I think we could add a generic
variant with the arm64 support and later migrate other architectures to
it if possible.
Ok, let's do it later, I could try to make some cleanup after the
patchset is merged ;)
The patch looks ok to me otherwise but I'd need an ack from Greg as it
touches drivers/.
the arch_numa is only used ARM64 and riscv, the
NEED_PER_CPU_PAGE_FIRST_CHUNK
is not enabled on RISCV, so it's no bad effect.
BTW, do we need something similar for the non-NUMA
setup_per_cpu_areas()? I can see this patch only enables
NEED_PER_CPU_PAGE_FIRST_CHUNK if NUMA.
Leaving the rest of the patch below for Greg.
On Mon, Aug 02, 2021 at 10:39:04AM +0800, Kefeng Wang wrote:
On 2021/8/1 23:23, Catalin Marinas wrote:
quoted
On Tue, Jul 20, 2021 at 10:51:03AM +0800, Kefeng Wang wrote:
quoted
There are some fixed locations in the vmalloc area be reserved
in ARM(see iotable_init()) and ARM64(see map_kernel()), but for
pcpu_page_first_chunk(), it calls vm_area_register_early() and
choose VMALLOC_START as the start address of vmap area which
could be conflicted with above address, then could trigger a
BUG_ON in vm_area_add_early().
Let's choose the end of existing address range in vmlist as the
start address instead of VMALLOC_START to avoid the BUG_ON.
Signed-off-by: Kefeng Wang <redacted>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Is there a risk of breaking other architectures? It doesn't look like to
me but I thought I'd ask.
Before this patch, vm_init_off is to record the offset from VMALLOC_START,
but it use VMALLOC_START as start address on the function
vm_area_register_early()
called firstly, this will cause the BUG_ON.
With this patch, the most important change is that we choose the start
address via
dynamic calculate the 'start' address by traversing the list.
[wkf@localhost linux-next]$ git grep vm_area_register_early
arch/alpha/mm/init.c: vm_area_register_early(&console_remap_vm, PAGE_SIZE);
arch/x86/xen/p2m.c: vm_area_register_early(&vm, PMD_SIZE *
PMDS_PER_MID_PAGE);
mm/percpu.c: vm_area_register_early(&vm, PAGE_SIZE);
[wkf@localhost linux-next]$ git grep vm_area_add_early
arch/arm/mm/ioremap.c: vm_area_add_early(vm);
arch/arm64/mm/mmu.c: vm_area_add_early(vma);
x86/alpha won't call vm_area_add_early(), only arm64 could call both vm_area_add_early()
and vm_area_register_early() when this patchset is merged. so it won't break other architectures.
Thanks for checking.
quoted
Also, instead of always picking the end, could we search for a range
that fits?
We only need a space in vmalloc range, using end or a range in the middle
is not different.
I was thinking of making it more future-proof in case one registers a
vm area towards the end of the range. It's fairly easy to pick a range
in the middle now that you are adding a list traversal.
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Kefeng Wang <hidden> Date: 2021-08-05 12:46:26
On 2021/8/4 19:14, Catalin Marinas wrote:
On Mon, Aug 02, 2021 at 10:39:04AM +0800, Kefeng Wang wrote:
quoted
On 2021/8/1 23:23, Catalin Marinas wrote:
quoted
On Tue, Jul 20, 2021 at 10:51:03AM +0800, Kefeng Wang wrote:
quoted
There are some fixed locations in the vmalloc area be reserved
in ARM(see iotable_init()) and ARM64(see map_kernel()), but for
pcpu_page_first_chunk(), it calls vm_area_register_early() and
choose VMALLOC_START as the start address of vmap area which
could be conflicted with above address, then could trigger a
BUG_ON in vm_area_add_early().
Let's choose the end of existing address range in vmlist as the
start address instead of VMALLOC_START to avoid the BUG_ON.
Signed-off-by: Kefeng Wang <redacted>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Is there a risk of breaking other architectures? It doesn't look like to
me but I thought I'd ask.
Before this patch, vm_init_off is to record the offset from VMALLOC_START,
but it use VMALLOC_START as start address on the function
vm_area_register_early()
called firstly, this will cause the BUG_ON.
With this patch, the most important change is that we choose the start
address via
dynamic calculate the 'start' address by traversing the list.
[wkf@localhost linux-next]$ git grep vm_area_register_early
arch/alpha/mm/init.c: vm_area_register_early(&console_remap_vm, PAGE_SIZE);
arch/x86/xen/p2m.c: vm_area_register_early(&vm, PMD_SIZE *
PMDS_PER_MID_PAGE);
mm/percpu.c: vm_area_register_early(&vm, PAGE_SIZE);
[wkf@localhost linux-next]$ git grep vm_area_add_early
arch/arm/mm/ioremap.c: vm_area_add_early(vm);
arch/arm64/mm/mmu.c: vm_area_add_early(vma);
x86/alpha won't call vm_area_add_early(), only arm64 could call both vm_area_add_early()
and vm_area_register_early() when this patchset is merged. so it won't break other architectures.
Thanks for checking.
quoted
quoted
Also, instead of always picking the end, could we search for a range
that fits?
We only need a space in vmalloc range, using end or a range in the middle
is not different.
I was thinking of making it more future-proof in case one registers a
vm area towards the end of the range. It's fairly easy to pick a range
in the middle now that you are adding a list traversal.
ok, will chose a suitable hole in the vmalloc range.