From patchwork Wed Jul 12 03:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 13309544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2358FC0015E for ; Wed, 12 Jul 2023 03:16:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F33506B0072; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE0E48D0001; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9868D6B0072; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 623026B0078 for ; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3329BB03D1 for ; Wed, 12 Jul 2023 03:16:29 +0000 (UTC) X-FDA: 81001496898.16.01630BA Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf30.hostedemail.com (Postfix) with ESMTP id 30F2A80010 for ; Wed, 12 Jul 2023 03:16:25 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689131787; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NBAGQU2ubKyI1+YBwA1SLOrKSa0seSj8mfFvDVfCZBQ=; b=winDS8aB4cjkWg08Z/bfD3JGX8i4iQXIZFbHJHuFbpWjiFjpH3ZDCzRA1mdjkG0OiPlufn F+ImnIz+lsiwvAOhgqO9L0YPeYud4UbfqTZkFCeerhN3patPixReut0tkf5pOjW824NUfX 0gnlkTKIhAZvQH5dWcYvzs67AUIjPc0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689131787; a=rsa-sha256; cv=none; b=Iz49v2mLy9gOe/WvYuGjmob5/w6LHXaJuG1knS38EZ6Y0nkBYBpqj/4okkZrX3YAWUEDIw yZXZp7+EhGz654k4pjTVkIMrq7/j1YUe1jnchpBENb/TzgZ/XJxg13Cc2xOVhz83xWGfDe Ww7lKlqk+aTjWNPE3Hgmz229CmYppe4= Received: from loongson.cn (unknown [10.2.9.158]) by gateway (Coremail) with SMTP id _____8DxqOoGG65kescDAA--.1201S3; Wed, 12 Jul 2023 11:16:22 +0800 (CST) Received: from kvm-1-158.loongson.cn (unknown [10.2.9.158]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxWM0GG65kA7cpAA--.53483S3; Wed, 12 Jul 2023 11:16:22 +0800 (CST) From: Bibo Mao To: Huacai Chen , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: Andrew Morton , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, WANG Xuerui Subject: [PATCH 1/3] mm/percpu: Remove some local variables in pcpu_populate_pte Date: Wed, 12 Jul 2023 11:16:20 +0800 Message-Id: <20230712031622.1888321-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230712031622.1888321-1-maobibo@loongson.cn> References: <20230712031622.1888321-1-maobibo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxWM0GG65kA7cpAA--.53483S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7uFWrCr1UWw4fXrWUJr13trc_yoW8Xr4Up3 93W3s29r4fJwnrGan3Gas8Wr17Xw4rta4Fk3srXr1rZ3W3ZrnxWr4jyw42ga42yFWfZF1x Jr45Ja9rAan0v3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAF wI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14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xgf7Buy9BEWMnfAX7x3BrtPjqteAWVA+QrYbjkKSH/xNNUYI29nuB7Z4/Y3RhdSX/IClc3tVzFx36oEaqcOjgpvi9ehLqiRwkAyPGJ8Jqw1db3qPKW32XsMcNv40y8PbQzZA0fYJFriA95H59pZ2n2DT1Y2FZetVRaYNwkdFr4ypKAwzHITUDMxHalbMJ6m3va5/JlCV/w Sz8KQxuO j+l/4VpDB7ZT4QC50P6K9Qm+L1q1bdBSV2I4RHCmwea3vUnNpeXRB6hODwjxe6nwV/R8rBRtf0OLSDIKLxOlSN2kUhg== 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: In function pcpu_populate_pte there are already variable defined, it can be reused for later use, here remove duplicated local variables. Signed-off-by: Bibo Mao --- mm/percpu.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 28e07ede46f6..85e3f9b2a61f 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -3189,32 +3189,26 @@ void __init __weak pcpu_populate_pte(unsigned long addr) pmd_t *pmd; if (pgd_none(*pgd)) { - p4d_t *new; - - new = memblock_alloc(P4D_TABLE_SIZE, P4D_TABLE_SIZE); - if (!new) + p4d = memblock_alloc(P4D_TABLE_SIZE, P4D_TABLE_SIZE); + if (!p4d) goto err_alloc; - pgd_populate(&init_mm, pgd, new); + pgd_populate(&init_mm, pgd, p4d); } p4d = p4d_offset(pgd, addr); if (p4d_none(*p4d)) { - pud_t *new; - - new = memblock_alloc(PUD_TABLE_SIZE, PUD_TABLE_SIZE); - if (!new) + pud = memblock_alloc(PUD_TABLE_SIZE, PUD_TABLE_SIZE); + if (!pud) goto err_alloc; - p4d_populate(&init_mm, p4d, new); + p4d_populate(&init_mm, p4d, pud); } pud = pud_offset(p4d, addr); if (pud_none(*pud)) { - pmd_t *new; - - new = memblock_alloc(PMD_TABLE_SIZE, PMD_TABLE_SIZE); - if (!new) + pmd = memblock_alloc(PMD_TABLE_SIZE, PMD_TABLE_SIZE); + if (!pmd) goto err_alloc; - pud_populate(&init_mm, pud, new); + pud_populate(&init_mm, pud, pmd); } pmd = pmd_offset(pud, addr); From patchwork Wed Jul 12 03:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 13309545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7179C001DF for ; Wed, 12 Jul 2023 03:16:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4598A6B0075; Tue, 11 Jul 2023 23:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4083E6B0078; Tue, 11 Jul 2023 23:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 282216B007D; Tue, 11 Jul 2023 23:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 047716B0075 for ; Tue, 11 Jul 2023 23:16:30 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D2E4A8049B for ; Wed, 12 Jul 2023 03:16:29 +0000 (UTC) X-FDA: 81001496898.13.2E4DEA6 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf17.hostedemail.com (Postfix) with ESMTP id 4E53C40002 for ; Wed, 12 Jul 2023 03:16:26 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf17.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689131788; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kpf2TOnfnAldaYjQQiIArCJYAXNKZBGy6ac+ggD4GQ8=; b=C8KbueXuGDNsXSmG7Jv94R2aLXDgwvg9U/R9QbTMgF7Qg+54ILIA3hId8EdepDZbWBBpf4 BmmZaX87mBRCIAUwkuULSY3VXiYzK2iO0o0ARSbhqdWYaL1SJbdBz2pCQCiC18jjDlt2c1 dtcwY3hyUTko9dYNeMUQCLLCgsUplok= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf17.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689131788; a=rsa-sha256; cv=none; b=naXyVBWInW3DLReAhBO3TSkEZzHd56tQi/YnTTvOF2FxKVmemW4VKbbIk9ylmw7c1ZI4hd vNUUgm2usTUPS30MOzMBmNE4gbxf2DWOEyLymqamnm9mmQqHR8jL3c3UQZ9nd4TSgw5Wud Pw7kvLxMde2Epy8kSkUKYgrar6LBxDA= Received: from loongson.cn (unknown [10.2.9.158]) by gateway (Coremail) with SMTP id _____8Cx7+sGG65kgccDAA--.9820S3; Wed, 12 Jul 2023 11:16:22 +0800 (CST) Received: from kvm-1-158.loongson.cn (unknown [10.2.9.158]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxWM0GG65kA7cpAA--.53483S4; Wed, 12 Jul 2023 11:16:22 +0800 (CST) From: Bibo Mao To: Huacai Chen , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: Andrew Morton , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, WANG Xuerui Subject: [PATCH 2/3] LoongArch: Code cleanup in function pcpu_populate_pte Date: Wed, 12 Jul 2023 11:16:21 +0800 Message-Id: <20230712031622.1888321-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230712031622.1888321-1-maobibo@loongson.cn> References: <20230712031622.1888321-1-maobibo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxWM0GG65kA7cpAA--.53483S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7WF17Xr48Ar4xXrWDtw45CFX_yoW8Zr4xp3 93GwnYvFs8Gwn7Jay3JryfWr43JwsYg3W5K3yUur1fAFyIqrnrGw4DG3s7uFyUtF4fZFWI gF4rtasIva1DX3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAF wI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7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YZOsW65UpAoL4N/TDH6wsQV3eJBW7BcIfJvRbaJlkFCsakime48a7LOtTN0y40iRxq6O0PXhqDwxwYLPnqBb42AuKYwrjWplaEgAanO4TOmT0vx6142kejpIYMNEZmB5HeZcwYLSoNLaRYou6zEl7/AGn/ApSHVhOTJggFOkyBrOJuqhJRnULmVEQQLF7mVundqqgIAh0DCgCZHpo1OPKeMJwu3Dr5e4EmwnaOdPCQsCNkMpNbNRCYSFeCMckhI493GohzkipjXHV93shNS5yveFeELRKFZ0YEc9rZrj1BHzXSwriMRUElSntI2kiP75w4bjPANDxfgy1O16XUc6Ohd5fmC5475AgI+tLIM0w M7MKuvVr T31bZ+Yl1Z/Fpc2ElHNz9dn1edA2ycO3h4oSzVuzn9FMUqWgmeDBu0+n7J9UNNay5FLeaGqIgTEJevJpcYnABT0CAng== 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: There are some code cleanups in function pcpu_populate_pte: 1. Replace memblock_alloc with memblock_alloc_raw for pud and pmd since they will be reinitialized with pud_init and pmd_init. 2. Add memory allocation failure handling 3. Replace pgd_populate with p4d_populate, it will be useful if there four-level page tables. Signed-off-by: Bibo Mao --- arch/loongarch/kernel/numa.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c index 708665895b47..778e1c20bfb0 100644 --- a/arch/loongarch/kernel/numa.c +++ b/arch/loongarch/kernel/numa.c @@ -73,33 +73,40 @@ void __init pcpu_populate_pte(unsigned long addr) pmd_t *pmd; if (p4d_none(*p4d)) { - pud_t *new; - - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE); - pgd_populate(&init_mm, pgd, new); + pud = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); + if (!pud) + goto err_alloc; + p4d_populate(&init_mm, p4d, pud); #ifndef __PAGETABLE_PUD_FOLDED - pud_init(new); + pud_init(pud); #endif } pud = pud_offset(p4d, addr); if (pud_none(*pud)) { - pmd_t *new; - - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE); - pud_populate(&init_mm, pud, new); + pmd = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); + if (!pmd) + goto err_alloc; + pud_populate(&init_mm, pud, pmd); #ifndef __PAGETABLE_PMD_FOLDED - pmd_init(new); + pmd_init(pmd); #endif } pmd = pmd_offset(pud, addr); if (!pmd_present(*pmd)) { - pte_t *new; + pte_t *pte; - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE); - pmd_populate_kernel(&init_mm, pmd, new); + pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + if (!pte) + goto err_alloc; + pmd_populate_kernel(&init_mm, pmd, pte); } + + return; + +err_alloc: + panic("%s: Failed to allocate memory\n", __func__); } void __init setup_per_cpu_areas(void) From patchwork Wed Jul 12 03:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 13309543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33CA2EB64DD for ; Wed, 12 Jul 2023 03:16:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBBD46B0071; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3D696B0078; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8008A6B0075; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5A8E36B0071 for ; Tue, 11 Jul 2023 23:16:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2BDA21604C0 for ; Wed, 12 Jul 2023 03:16:29 +0000 (UTC) X-FDA: 81001496898.18.789751B Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf09.hostedemail.com (Postfix) with ESMTP id 9D5F4140007 for ; Wed, 12 Jul 2023 03:16:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689131787; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x6RfI1DFQeVBNO13B5rgs49oK+XW0frP6HG7LYXMi/s=; b=z/y83oAjRx4f8nextBadFGU2DoJBaa/El1T8R8Q7awmVC4PVLesksf33tmf/XCd0BQbOKN Gy4lz751lgdh9QJoRnJSFaPUybJF7ZdCbRY6DP8WV3CSghoZloINGHNx8Ot1vwzg3Y+tuT Tdj9eOw+YpuPaAI5g9rIVSL9frEfim8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689131787; a=rsa-sha256; cv=none; b=GxHug4nvNgqs1CJouypyswscSpzO96KPge18stRAP4lK9FlwBN7frYL6Wf7ZqU9NZQwVIo D8NSLkFeZjXh5dKaz8OHBps5Tm3jTrAaAflXz8U+E+VM5T2NgsrevNsM2THgF6hG4R59+D VMs7v6z30559KQX1nC4dTzeYgMcJGho= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none Received: from loongson.cn (unknown [10.2.9.158]) by gateway (Coremail) with SMTP id _____8Dxg_AHG65kiscDAA--.10765S3; Wed, 12 Jul 2023 11:16:23 +0800 (CST) Received: from kvm-1-158.loongson.cn (unknown [10.2.9.158]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxWM0GG65kA7cpAA--.53483S5; Wed, 12 Jul 2023 11:16:22 +0800 (CST) From: Bibo Mao To: Huacai Chen , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: Andrew Morton , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, WANG Xuerui Subject: [PATCH 3/3] LoongArch: mm: Add unified function populate_kernel_pte Date: Wed, 12 Jul 2023 11:16:22 +0800 Message-Id: <20230712031622.1888321-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230712031622.1888321-1-maobibo@loongson.cn> References: <20230712031622.1888321-1-maobibo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxWM0GG65kA7cpAA--.53483S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZry3uF15JFWkGr1xXryktFc_yoWrKrWrpF 9xCw1vvr4rGr97J39rJr93Wr1UJw4kK3Waga9rWFyrAF4aqr17Wr1kWwn7ZFyUtFWfZayS gr4rtasIva1qqwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI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DYOPNjVO4PEAzb5Uqu+KsxfksFNYB0o0Y3xWawPFHxJysNz/n/RUGIFHFbJUuEG5fE1LJpdeisw2qfCLLco74PWmr+xgrlg0PwAE6U4ElLH4IFvwirxRUVZrqHEDjQmCX+co/ReKe0uGM/zOHd5Kx3nf72Gl7nFmjjpIel2tMTykKUViSl+BouBuZLvVRpBNHHM6PbykGpgg1K3bHCxH6YtOAwXgr3qzLPAN6iOBm9Dl0wlYuIAHcOQqY3jE0ceamffnbB0MKZtms4yhhg3ARXwJDWv9D/4Aw8cCFJACSlQTvYeIj5W0ZmSoQJzafnlb7trnXYFakZCVU9VrvEPpWII3NZLeoEyj2KQoR/n/QtU/K2BhHAbRqHD+fYjXNNLKJsmkoR45EoIZXCGiPIbq9tbfnfOZ9BpbCpG77wiWt+VQcd5aQCxc56p1IGkH5F8zvFvo71UnO2Fh82UakuSWFU3Lpa6u30WAajGYFG1SNZNLf3Lyzu9VU2qHF7e82K7eGDpSJKhC88XKL+qrWBq9NBHUfRz4dpgxcujailM2sFI/fp0TdpHXe/DV6yBEc78w3ibRwa+EeltP2hEr3H81lQ+amTHqTTOhbTPqsFxIhkdLRQc5+fSh16EFZhxIengse10zGc9g5QoLaCkuq0SpODVfSWPV2OI5JbfttI3yKHDhGm307n8iR DmP9CyOv +tJ++/1kj1Xz+JOmL7R/3RYYPJ84p2m1bZkXSbMl+fYeSU4SfX44Vrn6Vlx7Pu5OrNwrurlN3hqqX/a47WrxW/Ozzyg== 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: Function pcpu_populate_pte and fixmap_pte are similar, they populate one page from kernel address space. And there is confusion between pgd and p4d in function fixmap_pte, such as pgd_none always returns zero. This patch adds unified function populate_kernel_pte and replaces pcpu_populate_pte and fixmap_pte. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/pgalloc.h | 1 + arch/loongarch/kernel/numa.c | 40 +-------------------- arch/loongarch/mm/init.c | 52 ++++++++++++++++------------ 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/arch/loongarch/include/asm/pgalloc.h b/arch/loongarch/include/asm/pgalloc.h index af1d1e4a6965..ca17b573dba6 100644 --- a/arch/loongarch/include/asm/pgalloc.h +++ b/arch/loongarch/include/asm/pgalloc.h @@ -91,4 +91,5 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) #endif /* __PAGETABLE_PUD_FOLDED */ +extern pte_t * __init populate_kernel_pte(unsigned long addr); #endif /* _ASM_PGALLOC_H */ diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c index 778e1c20bfb0..24a693b76873 100644 --- a/arch/loongarch/kernel/numa.c +++ b/arch/loongarch/kernel/numa.c @@ -67,46 +67,8 @@ static int __init pcpu_cpu_distance(unsigned int from, unsigned int to) void __init pcpu_populate_pte(unsigned long addr) { - pgd_t *pgd = pgd_offset_k(addr); - p4d_t *p4d = p4d_offset(pgd, addr); - pud_t *pud; - pmd_t *pmd; - - if (p4d_none(*p4d)) { - pud = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); - if (!pud) - goto err_alloc; - p4d_populate(&init_mm, p4d, pud); -#ifndef __PAGETABLE_PUD_FOLDED - pud_init(pud); -#endif - } - - pud = pud_offset(p4d, addr); - if (pud_none(*pud)) { - pmd = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); - if (!pmd) - goto err_alloc; - pud_populate(&init_mm, pud, pmd); -#ifndef __PAGETABLE_PMD_FOLDED - pmd_init(pmd); -#endif - } - - pmd = pmd_offset(pud, addr); - if (!pmd_present(*pmd)) { - pte_t *pte; - - pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE); - if (!pte) - goto err_alloc; - pmd_populate_kernel(&init_mm, pmd, pte); - } - + populate_kernel_pte(addr); return; - -err_alloc: - panic("%s: Failed to allocate memory\n", __func__); } void __init setup_per_cpu_areas(void) diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c index 3b7d8129570b..6cd2948373ae 100644 --- a/arch/loongarch/mm/init.c +++ b/arch/loongarch/mm/init.c @@ -191,46 +191,49 @@ void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *al #endif #endif -static pte_t *fixmap_pte(unsigned long addr) +pte_t * __init populate_kernel_pte(unsigned long addr) { - pgd_t *pgd; - p4d_t *p4d; + pgd_t *pgd = pgd_offset_k(addr); + p4d_t *p4d = p4d_offset(pgd, addr); pud_t *pud; pmd_t *pmd; - pgd = pgd_offset_k(addr); - p4d = p4d_offset(pgd, addr); - - if (pgd_none(*pgd)) { - pud_t *new __maybe_unused; - - new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - pgd_populate(&init_mm, pgd, new); + if (p4d_none(*p4d)) { + pud = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); + if (!pud) + goto err_alloc; + p4d_populate(&init_mm, p4d, pud); #ifndef __PAGETABLE_PUD_FOLDED - pud_init(new); + pud_init(pud); #endif } pud = pud_offset(p4d, addr); if (pud_none(*pud)) { - pmd_t *new __maybe_unused; - - new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - pud_populate(&init_mm, pud, new); + pmd = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); + if (!pmd) + goto err_alloc; + pud_populate(&init_mm, pud, pmd); #ifndef __PAGETABLE_PMD_FOLDED - pmd_init(new); + pmd_init(pmd); #endif } pmd = pmd_offset(pud, addr); - if (pmd_none(*pmd)) { - pte_t *new __maybe_unused; + if (!pmd_present(*pmd)) { + pte_t *pte; - new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - pmd_populate_kernel(&init_mm, pmd, new); + pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + if (!pte) + goto err_alloc; + pmd_populate_kernel(&init_mm, pmd, pte); } return pte_offset_kernel(pmd, addr); + +err_alloc: + panic("%s: Failed to allocate memory\n", __func__); + return NULL; } void __init __set_fixmap(enum fixed_addresses idx, @@ -241,7 +244,12 @@ void __init __set_fixmap(enum fixed_addresses idx, BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses); - ptep = fixmap_pte(addr); + /* + * Now only FIX_EARLYCON_MEM_BASE fixed map is used + * __set_fixmap must be called before mem_init since function + * populate_kernel_pte allocates memory with memblock_alloc method. + */ + ptep = populate_kernel_pte(addr); if (!pte_none(*ptep)) { pte_ERROR(*ptep); return;