From: Kefeng Wang <hidden> Date: 2021-07-05 11:07:33
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",
the system can't 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 next-20210630.
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 | 18 +++++++++
drivers/base/arch_numa.c | 82 +++++++++++++++++++++++++++++++++-----
include/linux/kasan.h | 2 +
mm/kasan/init.c | 5 +++
mm/vmalloc.c | 9 +++--
6 files changed, 107 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-05 11:08:03
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-05 11:08:03
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 many "WARNING: CPU: 15 PID: 461 at vmalloc.c:3087 pcpu_get_vm_areas+0x488/0x838",
the system can't 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: kernel test robot <hidden> Date: 2021-07-05 14:11:31
Hi Kefeng,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on next-20210701]
url: https://github.com/0day-ci/linux/commits/Kefeng-Wang/arm64-support-page-mapping-percpu-first-chunk-allocator/20210705-190907
base: fb0ca446157a86b75502c1636b0d81e642fe6bf1
config: i386-randconfig-a015-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/5f6b5a402ed3e390563ddbddf12973470fd4886d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kefeng-Wang/arm64-support-page-mapping-percpu-first-chunk-allocator/20210705-190907
git checkout 5f6b5a402ed3e390563ddbddf12973470fd4886d
# save the attached .config to linux build tree
make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>
All errors (new ones prefixed by >>):
mm/vmalloc.c: In function 'vm_area_register_early':
quoted
mm/vmalloc.c:2252:2: error: implicit declaration of function 'kasan_populate_early_vm_area_shadow' [-Werror=implicit-function-declaration]
2252 | kasan_populate_early_vm_area_shadow(vm->addr, vm->size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/kasan_populate_early_vm_area_shadow +2252 mm/vmalloc.c
2226
2227 /**
2228 * vm_area_register_early - register vmap area early during boot
2229 * @vm: vm_struct to register
2230 * @align: requested alignment
2231 *
2232 * This function is used to register kernel vm area before
2233 * vmalloc_init() is called. @vm->size and @vm->flags should contain
2234 * proper values on entry and other fields should be zero. On return,
2235 * vm->addr contains the allocated address.
2236 *
2237 * DO NOT USE THIS FUNCTION UNLESS YOU KNOW WHAT YOU'RE DOING.
2238 */
2239 void __init vm_area_register_early(struct vm_struct *vm, size_t align)
2240 {
2241 unsigned long vm_start = VMALLOC_START;
2242 struct vm_struct *tmp;
2243 unsigned long addr;
2244
2245 for (tmp = vmlist; tmp; tmp = tmp->next)
2246 vm_start = (unsigned long)tmp->addr + tmp->size;
2247
2248 addr = ALIGN(vm_start, align);
2249 vm->addr = (void *)addr;
2250
2251 vm_area_add_early(vm);
This function looks quite generic -- would any of this also apply to
other architectures? I see that ppc and sparc at least also define
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK.
@@ -279,6 +279,11 @@ int __ref kasan_populate_early_shadow(const void *shadow_start,return0;}+void__init__weakkasan_populate_early_vm_area_shadow(void*start,+unsignedlongsize)+{+}
I'm just wondering if this could be a generic function, perhaps with an
appropriate IS_ENABLED() check of a generic Kconfig option
(CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK ?) to short-circuit it, if it's
not only an arm64 problem.
But I haven't looked much further, so would appeal to you to either
confirm or reject this idea.
Thanks,
-- Marco
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
mm/vmalloc.c:2252:2: error: implicit declaration of function 'kasan_populate_early_vm_area_shadow' [-Werror,-Wimplicit-function-declaration]
kasan_populate_early_vm_area_shadow(vm->addr, vm->size);
^
1 error generated.
vim +/kasan_populate_early_vm_area_shadow +2252 mm/vmalloc.c
2226
2227 /**
2228 * vm_area_register_early - register vmap area early during boot
2229 * @vm: vm_struct to register
2230 * @align: requested alignment
2231 *
2232 * This function is used to register kernel vm area before
2233 * vmalloc_init() is called. @vm->size and @vm->flags should contain
2234 * proper values on entry and other fields should be zero. On return,
2235 * vm->addr contains the allocated address.
2236 *
2237 * DO NOT USE THIS FUNCTION UNLESS YOU KNOW WHAT YOU'RE DOING.
2238 */
2239 void __init vm_area_register_early(struct vm_struct *vm, size_t align)
2240 {
2241 unsigned long vm_start = VMALLOC_START;
2242 struct vm_struct *tmp;
2243 unsigned long addr;
2244
2245 for (tmp = vmlist; tmp; tmp = tmp->next)
2246 vm_start = (unsigned long)tmp->addr + tmp->size;
2247
2248 addr = ALIGN(vm_start, align);
2249 vm->addr = (void *)addr;
2250
2251 vm_area_add_early(vm);
This function looks quite generic -- would any of this also apply to
other architectures? I see that ppc and sparc at least also define
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK.
So I checked with my latest KASAN ppc64 series and my code also breaks
in a very similar way if you boot with percpu_alloc=page. It's not
something I knew about or tested with before!
Unfortunately kasan_map_populate - despite having a very
generic-sounding name - is actually arm64 specific. I don't know if
kasan_populate_early_shadow (which is generic) would be able to fill the
role or not. If we could keep it generic that would be better.
It looks like arm64 does indeed populate the kasan_early_shadow_p{te,md..}
values, but I don't really understand what it's doing - is it possible
to use the generic kasan_populate_early_shadow on arm64?
If so, should we put the call inside of vm_area_register_early?
Kind regards,
Daniel
@@ -279,6 +279,11 @@ int __ref kasan_populate_early_shadow(const void *shadow_start,return0;}+void__init__weakkasan_populate_early_vm_area_shadow(void*start,+unsignedlongsize)+{+}
I'm just wondering if this could be a generic function, perhaps with an
appropriate IS_ENABLED() check of a generic Kconfig option
(CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK ?) to short-circuit it, if it's
not only an arm64 problem.
But I haven't looked much further, so would appeal to you to either
confirm or reject this idea.
Thanks,
-- Marco
@@ -279,6 +279,11 @@ int __ref kasan_populate_early_shadow(const void *shadow_start,return0;}+void__init__weakkasan_populate_early_vm_area_shadow(void*start,+unsignedlongsize)+{+}
I'm just wondering if this could be a generic function, perhaps with an
appropriate IS_ENABLED() check of a generic Kconfig option
(CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK ?) to short-circuit it, if it's
not only an arm64 problem.
But I haven't looked much further, so would appeal to you to either
confirm or reject this idea.
Thanks,
-- Marco
From: Kefeng Wang <hidden> Date: 2021-07-06 04:13:58
On 2021/7/5 22:10, kernel test robot wrote:
Hi Kefeng,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on next-20210701]
url: https://github.com/0day-ci/linux/commits/Kefeng-Wang/arm64-support-page-mapping-percpu-first-chunk-allocator/20210705-190907
base: fb0ca446157a86b75502c1636b0d81e642fe6bf1
config: i386-randconfig-a015-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/5f6b5a402ed3e390563ddbddf12973470fd4886d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kefeng-Wang/arm64-support-page-mapping-percpu-first-chunk-allocator/20210705-190907
git checkout 5f6b5a402ed3e390563ddbddf12973470fd4886d
# save the attached .config to linux build tree
make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>
All errors (new ones prefixed by >>):
mm/vmalloc.c: In function 'vm_area_register_early':
quoted
quoted
mm/vmalloc.c:2252:2: error: implicit declaration of function 'kasan_populate_early_vm_area_shadow' [-Werror=implicit-function-declaration]
should add a stub function when KASAN is not enabled, thanks.
2252 | kasan_populate_early_vm_area_shadow(vm->addr, vm->size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/kasan_populate_early_vm_area_shadow +2252 mm/vmalloc.c