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_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjx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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)