[PATCH v4 1/3] vmalloc: Choose a better start address in vm_area_register_early()

1 view
Skip to first unread message

Kefeng Wang

unread,
Sep 10, 2021, 1:30:43 AMSep 10
to wi...@kernel.org, catalin...@arm.com, ryabin...@gmail.com, andre...@gmail.com, dvy...@google.com, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linu...@kvack.org, el...@google.com, ak...@linux-foundation.org, gre...@linuxfoundation.org, kasa...@googlegroups.com, Kefeng Wang
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 a suit start address by traversing the vmlist.

Signed-off-by: Kefeng Wang <wangkef...@huawei.com>
---
mm/vmalloc.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index d77830ff604c..5ee3cbeffa26 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2272,15 +2272,21 @@ void __init vm_area_add_early(struct vm_struct *vm)
*/
void __init vm_area_register_early(struct vm_struct *vm, size_t align)
{
- static size_t vm_init_off __initdata;
- unsigned long addr;
+ unsigned long addr = ALIGN(VMALLOC_START, align);
+ struct vm_struct *cur, **p;

- addr = ALIGN(VMALLOC_START + vm_init_off, align);
- vm_init_off = PFN_ALIGN(addr + vm->size) - VMALLOC_START;
+ BUG_ON(vmap_initialized);

- vm->addr = (void *)addr;
+ for (p = &vmlist; (cur = *p) != NULL; p = &cur->next) {
+ if ((unsigned long)cur->addr - addr >= vm->size)
+ break;
+ addr = ALIGN((unsigned long)cur->addr + cur->size, align);
+ }

- vm_area_add_early(vm);
+ BUG_ON(addr > VMALLOC_END - vm->size);
+ vm->addr = (void *)addr;
+ vm->next = *p;
+ *p = vm;
}

static void vmap_init_free_space(void)
--
2.26.2

Catalin Marinas

unread,
Oct 12, 2021, 2:21:27 PMOct 12
to Kefeng Wang, wi...@kernel.org, ryabin...@gmail.com, andre...@gmail.com, dvy...@google.com, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linu...@kvack.org, el...@google.com, ak...@linux-foundation.org, gre...@linuxfoundation.org, kasa...@googlegroups.com
On Fri, Sep 10, 2021 at 01:33:52PM +0800, Kefeng Wang wrote:
> 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 a suit start address by traversing the vmlist.
>
> Signed-off-by: Kefeng Wang <wangkef...@huawei.com>

Reviewed-by: Catalin Marinas <catalin...@arm.com>
Reply all
Reply to author
Forward
0 new messages