linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: <will@kernel.org>, <catalin.marinas@arm.com>,
	<ryabinin.a.a@gmail.com>, <andreyknvl@gmail.com>,
	<dvyukov@google.com>, <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<elver@google.com>, <akpm@linux-foundation.org>,
	<gregkh@linuxfoundation.org>
Cc: <kasan-dev@googlegroups.com>, Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH v4 1/3] vmalloc: Choose a better start address in vm_area_register_early()
Date: Fri, 10 Sep 2021 13:33:52 +0800	[thread overview]
Message-ID: <20210910053354.26721-2-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20210910053354.26721-1-wangkefeng.wang@huawei.com>

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 <wangkefeng.wang@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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-09-10  5:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10  5:33 [PATCH v4 0/3] arm64: support page mapping percpu first chunk allocator Kefeng Wang
2021-09-10  5:33 ` Kefeng Wang [this message]
2021-10-12 18:21   ` [PATCH v4 1/3] vmalloc: Choose a better start address in vm_area_register_early() Catalin Marinas
2021-09-10  5:33 ` [PATCH v4 2/3] arm64: Support page mapping percpu first chunk allocator Kefeng Wang
2021-09-17  6:24   ` Greg KH
2021-09-17  6:55     ` Kefeng Wang
2021-09-17  7:04       ` Greg KH
2021-09-17  7:24         ` Kefeng Wang
2021-09-10  5:33 ` [PATCH v4 3/3] kasan: arm64: Fix pcpu_page_first_chunk crash with KASAN_VMALLOC Kefeng Wang
2021-10-12 18:17   ` Catalin Marinas
2021-10-13  1:09     ` Kefeng Wang
2021-09-15  8:33 ` [PATCH v4 0/3] arm64: support page mapping percpu first chunk allocator Kefeng Wang
2021-09-16 15:41   ` Greg KH
     [not found]     ` <525cb266-ecfc-284e-d701-4a8b40fe413b@huawei.com>
2021-09-17  6:24       ` Greg KH
2021-09-28  7:48 ` Kefeng Wang
2021-10-08 13:33   ` Kefeng Wang
2021-10-10 21:36 ` Andrew Morton
2021-10-11  1:09   ` Kefeng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210910053354.26721-2-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).