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=-10.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,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 6AC0BC432BE for ; Fri, 27 Aug 2021 08:36:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CDA9160F92 for ; Fri, 27 Aug 2021 08:36:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CDA9160F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3718A8D0002; Fri, 27 Aug 2021 04:36:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 322228D0001; Fri, 27 Aug 2021 04:36:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 210788D0002; Fri, 27 Aug 2021 04:36:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 03CF28D0001 for ; Fri, 27 Aug 2021 04:36:34 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id ADD2225F3B for ; Fri, 27 Aug 2021 08:36:34 +0000 (UTC) X-FDA: 78520204308.04.1CE9B9B Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf24.hostedemail.com (Postfix) with ESMTP id C08BBB0000B2 for ; Fri, 27 Aug 2021 08:36:33 +0000 (UTC) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GwtND5BGGz8BMF; Fri, 27 Aug 2021 16:36:12 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 27 Aug 2021 16:36:29 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 27 Aug 2021 16:36:28 +0800 Subject: Re: [PATCH v3 1/3] vmalloc: Choose a better start address in vm_area_register_early() To: Catalin Marinas CC: , , , , , , , , References: <20210809093750.131091-1-wangkefeng.wang@huawei.com> <20210809093750.131091-2-wangkefeng.wang@huawei.com> <20210825175953.GI3420@arm.com> From: Kefeng Wang Message-ID: <587a3a75-bbee-2ae4-8e69-563b9f277306@huawei.com> Date: Fri, 27 Aug 2021 16:36:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20210825175953.GI3420@arm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com X-Stat-Signature: hncphadeg1e6fegmhhfjpx1owwyx76r5 X-Rspamd-Queue-Id: C08BBB0000B2 X-Rspamd-Server: rspam04 X-HE-Tag: 1630053393-891351 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 2021/8/26 1:59, Catalin Marinas wrote: > On Mon, Aug 09, 2021 at 05:37:48PM +0800, Kefeng Wang wrote: >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c >> index d5cd52805149..1e8fe08725b8 100644 >> --- a/mm/vmalloc.c >> +++ b/mm/vmalloc.c >> @@ -2238,11 +2238,17 @@ void __init vm_area_add_early(struct vm_struct= *vm) >> */ >> void __init vm_area_register_early(struct vm_struct *vm, size_t alig= n) >> { >> - static size_t vm_init_off __initdata; >> - unsigned long addr; >> - >> - addr =3D ALIGN(VMALLOC_START + vm_init_off, align); >> - vm_init_off =3D PFN_ALIGN(addr + vm->size) - VMALLOC_START; >> + struct vm_struct *head =3D vmlist, *curr, *next; >> + unsigned long addr =3D ALIGN(VMALLOC_START, align); >> + >> + while (head !=3D NULL) { > 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 =3D head->next; >> + curr =3D head; >> + head =3D next; >> + addr =3D ALIGN((unsigned long)curr->addr + curr->size, align); >> + if (next && (unsigned long)next->addr - addr > vm->size) > Is greater or equal sufficient? > >> + break; >> + } >> =20 >> vm->addr =3D (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) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct vm_struct *next,= *cur, **p; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long addr =3D = ALIGN(VMALLOC_START, align); BUG_ON(vmap_initialized); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (p =3D &vmlist; (cu= r =3D *p) !=3D NULL, next =3D cur->next; p =3D=20 &next) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 addr =3D ALIGN((unsigned long)cur->addr + cur->s= ize,=20 align); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 if (next && (unsigned long)next->addr - addr >=3D= =20 vm->size) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = p =3D &next; break; } } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BUG_ON(addr > VMALLOC_E= ND - vm->size); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vm->addr =3D (void *)ad= dr; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vm->next =3D *p; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *p =3D vm; } >