From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B292FC4338F for ; Wed, 4 Aug 2021 11:15:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B16B60FC4 for ; Wed, 4 Aug 2021 11:15:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7B16B60FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w2SwFp3c6xRVZTTFkyH35X28Y0gq1FIa5NEjaYhFCMo=; b=kC/vHMfO+vIYiP vPwSGkC4mdCsHFeWJtDnholovh04lfD3vEMCjL4HanSLV89Uvi8ojIdzdIVSIjkReNGL/hFdwuGsD pNdKcVi9H/2m1OarEoGcV5oHdvZ/amnJ83I/klYGMhiNSlg+IvNuoesuolSdw1Sr8AAmDvhiIJ3Jv uF8c8AwsaBAKb4v9XSutyxUVbj3twHRj8T/dVKlkfOrYOi6eA5WkSrWjf3YA9yjRSidF4eXJ057HQ 5VLJCzu6T2UN3hsxXuiru8FYO4Q5nAfR1zoQUJw1Hwor6Atkm/DEHaMFy8zSbzWPemcr2fPeQPFHg 1aT9gQX5902TvZ+epRmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBEqi-005r8n-7u; Wed, 04 Aug 2021 11:14:12 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBEqd-005r7Q-SR for linux-arm-kernel@lists.infradead.org; Wed, 04 Aug 2021 11:14:09 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 224EA60FC4; Wed, 4 Aug 2021 11:14:04 +0000 (UTC) Date: Wed, 4 Aug 2021 12:14:02 +0100 From: Catalin Marinas To: Kefeng Wang Cc: Will Deacon , Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: Re: [PATCH v2 1/3] vmalloc: Choose a better start address in vm_area_register_early() Message-ID: <20210804111402.GB4857@arm.com> References: <20210720025105.103680-1-wangkefeng.wang@huawei.com> <20210720025105.103680-2-wangkefeng.wang@huawei.com> <20210801152311.GB28489@arm.com> <0de87be6-7041-c58b-a01f-3d6e3333c6f0@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0de87be6-7041-c58b-a01f-3d6e3333c6f0@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210804_041407_991019_84556AB2 X-CRM114-Status: GOOD ( 35.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 02, 2021 at 10:39:04AM +0800, Kefeng Wang wrote: > On 2021/8/1 23:23, Catalin Marinas wrote: > > On Tue, Jul 20, 2021 at 10:51:03AM +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 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 > > > --- > > > mm/vmalloc.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > = > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > index d5cd52805149..a98cf97f032f 100644 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -2238,12 +2238,14 @@ void __init vm_area_add_early(struct vm_struc= t *vm) > > > */ > > > void __init vm_area_register_early(struct vm_struct *vm, size_t ali= gn) > > > { > > > - static size_t vm_init_off __initdata; > > > + unsigned long vm_start =3D VMALLOC_START; > > > + struct vm_struct *tmp; > > > unsigned long addr; > > > - addr =3D ALIGN(VMALLOC_START + vm_init_off, align); > > > - vm_init_off =3D PFN_ALIGN(addr + vm->size) - VMALLOC_START; > > > + for (tmp =3D vmlist; tmp; tmp =3D tmp->next) > > > + vm_start =3D (unsigned long)tmp->addr + tmp->size; > > > + addr =3D ALIGN(vm_start, align); > > > vm->addr =3D (void *)addr; > > > vm_area_add_early(vm); > > 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,=A0 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:=A0=A0=A0=A0 vm_area_register_early(&vm, PMD_SIZE * > PMDS_PER_MID_PAGE); > mm/percpu.c:=A0=A0=A0 vm_area_register_early(&vm, PAGE_SIZE); > [wkf@localhost linux-next]$ git grep vm_area_add_early > arch/arm/mm/ioremap.c:=A0 vm_area_add_early(vm); > arch/arm64/mm/mmu.c:=A0=A0=A0 vm_area_add_early(vma); > = > x86/alpha won't call vm_area_add_early(), only arm64 could call both vm_a= rea_add_early() > and vm_area_register_early() when this patchset is merged. so it won't b= reak other architectures. Thanks for checking. > > Also, instead of always picking the end, could we search for a range > > that fits? > = > We only need a space in vmalloc range,=A0 using end or a range in the mid= dle > 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 mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF00C4338F for ; Wed, 4 Aug 2021 11:14:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3026860E97 for ; Wed, 4 Aug 2021 11:14:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3026860E97 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B93B48D005C; Wed, 4 Aug 2021 07:14:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B43748D002D; Wed, 4 Aug 2021 07:14:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A324F8D005C; Wed, 4 Aug 2021 07:14:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id 88C578D002D for ; Wed, 4 Aug 2021 07:14:08 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0E07720411 for ; Wed, 4 Aug 2021 11:14:08 +0000 (UTC) X-FDA: 78437138976.20.28E5516 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP id 95803601190F for ; Wed, 4 Aug 2021 11:14:07 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 224EA60FC4; Wed, 4 Aug 2021 11:14:04 +0000 (UTC) Date: Wed, 4 Aug 2021 12:14:02 +0100 From: Catalin Marinas To: Kefeng Wang Cc: Will Deacon , Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: Re: [PATCH v2 1/3] vmalloc: Choose a better start address in vm_area_register_early() Message-ID: <20210804111402.GB4857@arm.com> References: <20210720025105.103680-1-wangkefeng.wang@huawei.com> <20210720025105.103680-2-wangkefeng.wang@huawei.com> <20210801152311.GB28489@arm.com> <0de87be6-7041-c58b-a01f-3d6e3333c6f0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <0de87be6-7041-c58b-a01f-3d6e3333c6f0@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 95803601190F Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf14.hostedemail.com: domain of cmarinas@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Stat-Signature: uj3h115uafdxc859qjmbzs7qqto1s48o X-HE-Tag: 1628075647-694358 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Aug 02, 2021 at 10:39:04AM +0800, Kefeng Wang wrote: > On 2021/8/1 23:23, Catalin Marinas wrote: > > On Tue, Jul 20, 2021 at 10:51:03AM +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(). > > >=20 > > > Let's choose the end of existing address range in vmlist as the > > > start address instead of VMALLOC_START to avoid the BUG_ON. > > >=20 > > > Signed-off-by: Kefeng Wang > > > --- > > > mm/vmalloc.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > >=20 > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > index d5cd52805149..a98cf97f032f 100644 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -2238,12 +2238,14 @@ void __init vm_area_add_early(struct vm_str= uct *vm) > > > */ > > > void __init vm_area_register_early(struct vm_struct *vm, size_t a= lign) > > > { > > > - static size_t vm_init_off __initdata; > > > + unsigned long vm_start =3D VMALLOC_START; > > > + struct vm_struct *tmp; > > > unsigned long addr; > > > - addr =3D ALIGN(VMALLOC_START + vm_init_off, align); > > > - vm_init_off =3D PFN_ALIGN(addr + vm->size) - VMALLOC_START; > > > + for (tmp =3D vmlist; tmp; tmp =3D tmp->next) > > > + vm_start =3D (unsigned long)tmp->addr + tmp->size; > > > + addr =3D ALIGN(vm_start, align); > > > vm->addr =3D (void *)addr; > > > vm_area_add_early(vm); > > Is there a risk of breaking other architectures? It doesn't look like= to > > me but I thought I'd ask. >=20 > Before this patch, vm_init_off is to record the offset from VMALLOC_STA= RT, >=20 > but it use VMALLOC_START as start address on the function > vm_area_register_early() >=20 > called firstly,=A0 this will cause the BUG_ON. >=20 > With this patch, the most important change is that we choose the start > address via >=20 > dynamic calculate the 'start' address by traversing the list. >=20 > [wkf@localhost linux-next]$ git grep vm_area_register_early > arch/alpha/mm/init.c: vm_area_register_early(&console_remap_vm, PAGE_SI= ZE); > arch/x86/xen/p2m.c:=A0=A0=A0=A0 vm_area_register_early(&vm, PMD_SIZE * > PMDS_PER_MID_PAGE); > mm/percpu.c:=A0=A0=A0 vm_area_register_early(&vm, PAGE_SIZE); > [wkf@localhost linux-next]$ git grep vm_area_add_early > arch/arm/mm/ioremap.c:=A0 vm_area_add_early(vm); > arch/arm64/mm/mmu.c:=A0=A0=A0 vm_area_add_early(vma); >=20 > 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. > > Also, instead of always picking the end, could we search for a range > > that fits? >=20 > We only need a space in vmalloc range,=A0 using end or a range in the m= iddle > 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. --=20 Catalin