From: Kefeng Wang <hidden> Date: 2021-08-09 09:32:31
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-rc5.
v3:
- search for a range that fits instead of always picking the end from
vmalloc area suggested by Catalin.
- use NUMA_NO_NODE to avoid "virt_to_phys used for non-linear address:"
issue in arm64 kasan_populate_early_vm_area_shadow().
- add Acked-by: Marco Elver [off-list ref] to patch v3
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 | 16 ++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 6 +++
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 17 +++++---
6 files changed, 115 insertions(+), 15 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-08-09 09:32:32
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 | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
Nitpick: I'd use the same pattern as in vm_area_add_early(), i.e. a
'for' loop. You might as well insert it directly than calling the add
function and going through the loop again. Not a strong preference
either way.
+ next = head->next;
+ curr = head;
+ head = next;
+ addr = ALIGN((unsigned long)curr->addr + curr->size, align);
+ if (next && (unsigned long)next->addr - addr > vm->size)
Is greater or equal sufficient?
+ break;
+ }
vm->addr = (void *)addr;
Another nitpick: it's very unlikely on a 64-bit architecture but not
impossible on 32-bit to hit VMALLOC_END here. Maybe some BUG_ON.
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Nitpick: I'd use the same pattern as in vm_area_add_early(), i.e. a
'for' loop. You might as well insert it directly than calling the add
function and going through the loop again. Not a strong preference
either way.
quoted
+ next = head->next;
+ curr = head;
+ head = next;
+ addr = ALIGN((unsigned long)curr->addr + curr->size, align);
+ if (next && (unsigned long)next->addr - addr > vm->size)
Is greater or equal sufficient?
quoted
+ break;
+ }
vm->addr = (void *)addr;
Another nitpick: it's very unlikely on a 64-bit architecture but not
impossible on 32-bit to hit VMALLOC_END here. Maybe some BUG_ON.
Hi Catalin, thank for your review, I will update in the next version,
Could you take a look the following change, is it OK?
void __init vm_area_register_early(struct vm_struct *vm, size_t align)
{
struct vm_struct *next, *cur, **p;
unsigned long addr = ALIGN(VMALLOC_START, align);
BUG_ON(vmap_initialized);
for (p = &vmlist; (cur = *p) != NULL, next = cur->next; p =
&next) {
addr = ALIGN((unsigned long)cur->addr + cur->size,
align);
if (next && (unsigned long)next->addr - addr >=
vm->size) {
p = &next;
break;
}
}
BUG_ON(addr > VMALLOC_END - vm->size);
vm->addr = (void *)addr;
vm->next = *p;
*p = vm;
}
From: Kefeng Wang <hidden> Date: 2021-08-09 09:32:36
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(-)
On Mon, Aug 09, 2021 at 05:37:49PM +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.
Signed-off-by: Kefeng Wang <redacted>
From: Kefeng Wang <hidden> Date: 2021-08-09 11:10:16
On 2021/8/9 17:37, 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.
Should add Acked-by: Marco Elver [off-list ref] [for KASAN parts] ,
missed here :(
From: Marco Elver <elver@google.com> Date: 2021-08-09 11:22:00
On Mon, 9 Aug 2021 at 13:10, Kefeng Wang [off-list ref] wrote:
On 2021/8/9 17:37, 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.
Should add Acked-by: Marco Elver [off-list ref] [for KASAN parts] ,
From: Kefeng Wang <hidden> Date: 2021-08-09 13:35:04
On 2021/8/9 19:21, Marco Elver wrote:
On Mon, 9 Aug 2021 at 13:10, Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/9 17:37, 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.
Should add Acked-by: Marco Elver [off-list ref] [for KASAN parts] ,
From: Kefeng Wang <hidden> Date: 2021-08-12 06:07:42
Hi Catalin and Will,
The drivers/base/arch_numa.c is only shared by riscv and arm64,
and the change from patch2 won't broke riscv.
Could all patches be merged by arm64 tree? or any new comments?
Many thanks.
On 2021/8/9 17:37, 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-rc5.
v3:
- search for a range that fits instead of always picking the end from
vmalloc area suggested by Catalin.
- use NUMA_NO_NODE to avoid "virt_to_phys used for non-linear address:"
issue in arm64 kasan_populate_early_vm_area_shadow().
- add Acked-by: Marco Elver [off-list ref] to patch v3
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 | 16 ++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 6 +++
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 17 +++++---
6 files changed, 115 insertions(+), 15 deletions(-)
From: Kefeng Wang <hidden> Date: 2021-08-23 02:29:40
On 2021/8/12 14:07, Kefeng Wang wrote:
Hi Catalin and Will,
The drivers/base/arch_numa.c is only shared by riscv and arm64,
and the change from patch2 won't broke riscv.
Could all patches be merged by arm64 tree? or any new comments?
Kindly ping...
Many thanks.
On 2021/8/9 17:37, 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.
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-rc5.
v3:
- search for a range that fits instead of always picking the end from
vmalloc area suggested by Catalin.
- use NUMA_NO_NODE to avoid "virt_to_phys used for non-linear address:"
issue in arm64 kasan_populate_early_vm_area_shadow().
- add Acked-by: Marco Elver [off-list ref] to patch v3
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 | 16 ++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 6 +++
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 17 +++++---
6 files changed, 115 insertions(+), 15 deletions(-)
On Thu, Aug 12, 2021 at 02:07:36PM +0800, Kefeng Wang wrote:
The drivers/base/arch_numa.c is only shared by riscv and arm64,
and the change from patch2 won't broke riscv.
Could all patches be merged by arm64 tree? or any new comments?
The series touches drivers/ and mm/ but missing acks from both Greg and
Andrew (cc'ing them).
I'm also happy for the series to go in via the mm tree in case Andrew
wants to take it.
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel