From patchwork Fri Jan 3 10:51:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weikang Guo X-Patchwork-Id: 13925485 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 5FEB0E7718F for ; Fri, 3 Jan 2025 10:52:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E45496B008A; Fri, 3 Jan 2025 05:52:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DFED96B0089; Fri, 3 Jan 2025 05:52:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6D776B008A; Fri, 3 Jan 2025 05:52:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A21466B0088 for ; Fri, 3 Jan 2025 05:52:17 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1F3B4C072D for ; Fri, 3 Jan 2025 10:52:17 +0000 (UTC) X-FDA: 82965825810.14.E457323 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf29.hostedemail.com (Postfix) with ESMTP id 53E1712000C for ; Fri, 3 Jan 2025 10:51:02 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BM4CFqfb; spf=pass (imf29.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735901511; 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:dkim-signature; bh=rq36yhx+vIwlwQqelDChXzPpuerxjjjClrW9h8Ys2vo=; b=watyUKtET+3pX1MIP4I+MHAsuy3R2W8dOVc5Dn0yiK3qVml42gXy1KcdMAw7w1Ou5OY1JP /w57950khDa2AmBb+jibOMmnhLz4HVmLkAQ1pxwdP1P/NHEb8ke1wpa+9gQJFvifJrxCql WF9kOG0x2pNATjnUR9/KLLt6TgYieP8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735901511; a=rsa-sha256; cv=none; b=guaEh3I/+TlZAVTYnqYqhLB7gh+2waHZ+DqSIVFm7o/ugArCHqLLsFPf1nMCV8QW5HP9Fy zxf++86S0Zqh68NaR5nQpkMhBRs7qkbhpW0WabddQSxEmFy+OBbNjQWj/9QWeVhFp/3i9E 5Uk7QQZkmszun5Vurj/dfgu1THrBRBo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BM4CFqfb; spf=pass (imf29.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21644aca3a0so90049725ad.3 for ; Fri, 03 Jan 2025 02:52:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735901534; x=1736506334; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rq36yhx+vIwlwQqelDChXzPpuerxjjjClrW9h8Ys2vo=; b=BM4CFqfbSFKOWZ7ViNl07sRifA/eB9VPbfLYzpVu3Qg0cMoujhCG/U6TIG1zwK7hqa Y7ouU1/BW0SN21IZ8Zoeui2ShXuKhuG039w4GAaLTjXNgJ1iOP6/BHrLSeHcIPXrh9Pr E28gMoz/d77w62oV1weRVJy9pJFA+LIZcyjc0YiKRsmqZ03z9WYwFZg2PUUEp79AAqpv 1AyAhP3JRlCRixwCmYFRrOq3nd0xGPa33zgFZQZqdiNm+UYGCVhUWEwX7p8dG1ypUWWJ 0+ZCayY0Oi8vRG+hPS4XCtqXNovpoMfn5nLu7IEvpJnpoaIiHgDWyK/pDoMQlN0d0Mir rknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735901534; x=1736506334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rq36yhx+vIwlwQqelDChXzPpuerxjjjClrW9h8Ys2vo=; b=LNoJHTcZeezXRSNgYXg3pDXeTUtko/Ez8NZbgoyxAGW6DFenQyKtMNvfuQXByWJnVG pKooCI1uacVEsIRK6pTNxPv2FbfOzoctNs0bi5VgaTz6LpIXfnvdjnwMZpy8A1YE9fZx Obz9SyyiOPCcBgbQ2R8E51maMaw2GSW62n6ARKRgf2gl7EPhdWRIQGJNuU5JPvJ16CoO Pgns7mW+OKdb4PtZik8j8Nc8Hvtnmq5uFKVeah+Ky18qLbze+N216+dhcHH0ru7DGAZf DRiXlf0U0E50msgsOXdvb+TxdREB7vwaxMczPED3bCHCWKsFxU2E5y0UuKArqUOBRUfB 2NSA== X-Gm-Message-State: AOJu0YwhICsB78aydrwO5twNJkyP2SO5E4638tHv/LEA71wl74QtlqWb NG8dDQQwAp/Lt6SSbjZUny82QOII/kQsVqD2J2Ie4SgMhkMsmTlb X-Gm-Gg: ASbGncsYIJb9Nzf1CERmcjrdvggbpYVM+EFamb8Pa1Bxy42L5UQ4/eARfcGdu7/nzSK MFzJgxSKK/b31Xg6fyK1Q29M15oYfOkGIrPcsvQuEHm1NjqHuG1V7cd0cw2kPygeFGRYa6PMUb3 EPwQVwYUk1IoQX8GiQfproa73tQ21WG/iduOo0n1BhRs/WD2tXxTwzcBnGOq+DEu73H6QzicLoS f4YAbf2zWkMd9DwlIuRI8Tyv1azl0u96rDK9ftw8cp/DmqqoTuiHftElPN1cC2m57y9Fgh9UH1g XXnC X-Google-Smtp-Source: AGHT+IHh4XC8NkolJbSkhLb/aO+URp4mmTVdrbAljgMgsTmiDDrpYkNiEyeb0fF1Qk2SmB7XiqjqSg== X-Received: by 2002:a05:6a00:3d0c:b0:725:973f:9d53 with SMTP id d2e1a72fcca58-72abde3bcd1mr66794855b3a.15.1735901533906; Fri, 03 Jan 2025 02:52:13 -0800 (PST) Received: from localhost.localdomain ([36.110.106.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8157edsm26802019b3a.20.2025.01.03.02.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 02:52:13 -0800 (PST) From: Guo Weikang To: Mike Rapoport , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guo Weikang Subject: [PATCH 3/3] mm/memblock: Modify the default failure behavior of memblock_alloc_low(from) Date: Fri, 3 Jan 2025 18:51:58 +0800 Message-Id: <20250103105158.1350689-3-guoweikang.kernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250103105158.1350689-1-guoweikang.kernel@gmail.com> References: <20250103105158.1350689-1-guoweikang.kernel@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 53E1712000C X-Stat-Signature: mn3ogacdt79mxk9r6mwpw1hnrua5iepi X-Rspam-User: X-HE-Tag: 1735901462-182931 X-HE-Meta: U2FsdGVkX19k2JZo9gj/Gk++uf5khVZVLN9GEq9MueKQNGFGI6EMbkOpVOY0AuBVpWZAo/ipH2/39Qz2qES9uDXaTaisevkf8/bLKmAvka7N4L6TWfCkm7bQRVNq1rPViUvbwCYX1mdfXZn0xG+ozS8V6mi/OwvO4LWhhnpc2wRpD6De8pUqCweXGVjVoQ1dni3L4mDZijPiV2Gt8CR8bcy1crdTtYkpicl49dxsqnrSMSTtdnAA3JsFPxnG6+JPMA2r98oOHewHSRD0SKs0/IUvPyFq4hQQOz15tcSIzUsgH/BsS7l2Yemov5Z2w8nT6JfinVeqy5ayYJoNgHoOofM1ar7/JyMTAFlxa1iA2v6KhLO3VVsBR83Fvt2mFbh+I9vyhlXKoby/mWDgMkv3Vpwy23obtv86S5SojPRVDOL7PYiVauCs+f07upqHmAV5faejr217a2ZWQwjXFYT3MP/zy6AjNOEfXGkSQm3dTLT7Z11b9FH+sgIo2M0bq19gnXBaeYt59LqcUyIcZc581acPbgtMkSBY36pc/gXCOOOOHwbyslfwri+sQ/r8FWvYoMClKAmgQ9ms/VVt4jabKqYm5qYvGMOCI7WltPljvenXBMEClnKmtD9nczNfexDi03Sn74seixUVJ+79STN+/mssPVlWaxnSYeDt7A4jne+RzX/TtlVnNUyJ5pms2EVCRXL3Z/HjNRE9Rr9jLyNHWfKeWFncnzCxArKPgxnHY3TrQyFNge7betRL/HKkT7BWBfT4j4UUWy5h0mky1KOtfme2PNXQkmtPNDyR3UI6myXJaz/yksOwuw5tVHo0pcStE1GOCsFSqRz79JMdKZN+lmZhA3iJqD0CQWcvYdGcKBX8y5L7/rUohjjF1OtdMnKTk/bsj9bJ3Wtl5BW729oifNelguk5wOvVE6AnKaOe4bd/ptsq47/3XpZTUcIhlLo7EGAxOcBgA3jC1PEaHXp JQUizvmQ /4KekU2TXBvJgshA6cL39Wb0Y8GpwmLvODFJmKcnlRtstCZBXkx4bE48UdHwIqqaYroyeccCcF0baoEkmbyH7Jt10+24FNmUPzSX90aCViBUXL38hE4fs6ylwxOzzEQ1HvwQqhJAfHtEYmjY/rxa8xfc+3ryvFUyoXtwQhRSx757sntX4aJlelONMGU6hraSSbqbgiYbirCBEzQowkwMxHrMOD37/HWxMWkJp8YpBxY+HMYy51WjFdSr44R/pNAjx++3+JoRxYWpF4f9ZiLCjEZGGen5rQdKiHjM1vuJkWsQTtHeSPrtxiivCO9/8rAUmEM4Ybv6KNw1pHaVNv+5kEj0JrrxDcO0Fy0tDgJ6rwlJ652BwSbUAGPGaDgSY4lr2bSRTeXFsY+w5gI/V12Q/aOK7vGQwdqZ8AL07bFmXa2ln9iMA1N+3bBXDtn6uege6oN1R3KPYwWNrX/UNO5r8+6uD6fZ0wq99tt3CVNyClhA1VBmB0RS3ZdkuqgKQ8vAl3wcN1y/KV+MH6vk= 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: List-Subscribe: List-Unsubscribe: Just like memblock_alloc, the default failure behavior of memblock_alloc_low and memblock_alloc_from is now modified to trigger a panic when allocation fails. Signed-off-by: Guo Weikang --- arch/arc/mm/highmem.c | 4 ---- arch/csky/mm/init.c | 5 ---- arch/m68k/atari/stram.c | 4 ---- arch/m68k/mm/motorola.c | 9 ------- arch/mips/include/asm/dmi.h | 2 +- arch/mips/mm/init.c | 5 ---- arch/s390/kernel/setup.c | 4 ---- arch/s390/kernel/smp.c | 3 --- arch/sparc/mm/init_64.c | 13 ---------- arch/um/kernel/mem.c | 20 ---------------- arch/xtensa/mm/mmu.c | 4 ---- include/linux/memblock.h | 30 ++++++++++++----------- mm/memblock.c | 47 +++++++++++++++++++++++++++++++++++++ mm/percpu.c | 6 ++--- 14 files changed, 67 insertions(+), 89 deletions(-) diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c index c79912a6b196..4ed597b19388 100644 --- a/arch/arc/mm/highmem.c +++ b/arch/arc/mm/highmem.c @@ -53,10 +53,6 @@ static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr) pte_t *pte_k; pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pte_k) - panic("%s: Failed to allocate %lu bytes align=0x%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - pmd_populate_kernel(&init_mm, pmd_k, pte_k); return pte_k; } diff --git a/arch/csky/mm/init.c b/arch/csky/mm/init.c index bde7cabd23df..04de02a83564 100644 --- a/arch/csky/mm/init.c +++ b/arch/csky/mm/init.c @@ -174,11 +174,6 @@ void __init fixrange_init(unsigned long start, unsigned long end, for (; (k < PTRS_PER_PMD) && (vaddr != end); pmd++, k++) { if (pmd_none(*pmd)) { pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pte) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, - PAGE_SIZE); - set_pmd(pmd, __pmd(__pa(pte))); BUG_ON(pte != pte_offset_kernel(pmd, 0)); } diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c index 922e53bcb853..14f761330b29 100644 --- a/arch/m68k/atari/stram.c +++ b/arch/m68k/atari/stram.c @@ -96,10 +96,6 @@ void __init atari_stram_reserve_pages(void *start_mem) pr_debug("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n"); stram_pool.start = (resource_size_t)memblock_alloc_low(pool_size, PAGE_SIZE); - if (!stram_pool.start) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, pool_size, PAGE_SIZE); - stram_pool.end = stram_pool.start + pool_size - 1; request_resource(&iomem_resource, &stram_pool); stram_virt_offset = 0; diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c index ce016ae8c972..83bbada15be2 100644 --- a/arch/m68k/mm/motorola.c +++ b/arch/m68k/mm/motorola.c @@ -227,11 +227,6 @@ static pte_t * __init kernel_page_table(void) if (PAGE_ALIGNED(last_pte_table)) { pte_table = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pte_table) { - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - } - clear_page(pte_table); mmu_page_ctor(pte_table); @@ -275,10 +270,6 @@ static pmd_t * __init kernel_ptr_table(void) last_pmd_table += PTRS_PER_PMD; if (PAGE_ALIGNED(last_pmd_table)) { last_pmd_table = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!last_pmd_table) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - clear_page(last_pmd_table); mmu_page_ctor(last_pmd_table); } diff --git a/arch/mips/include/asm/dmi.h b/arch/mips/include/asm/dmi.h index dc397f630c66..9698d072cc4d 100644 --- a/arch/mips/include/asm/dmi.h +++ b/arch/mips/include/asm/dmi.h @@ -11,7 +11,7 @@ #define dmi_unmap(x) iounmap(x) /* MIPS initialize DMI scan before SLAB is ready, so we use memblock here */ -#define dmi_alloc(l) memblock_alloc_low(l, PAGE_SIZE) +#define dmi_alloc(l) memblock_alloc_low_no_panic(l, PAGE_SIZE) #if defined(CONFIG_MACH_LOONGSON64) #define SMBIOS_ENTRY_POINT_SCAN_START 0xFFFE000 diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c index 4583d1a2a73e..cca62f23769f 100644 --- a/arch/mips/mm/init.c +++ b/arch/mips/mm/init.c @@ -257,11 +257,6 @@ void __init fixrange_init(unsigned long start, unsigned long end, if (pmd_none(*pmd)) { pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pte) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, - PAGE_SIZE); - set_pmd(pmd, __pmd((unsigned long)pte)); BUG_ON(pte != pte_offset_kernel(pmd, 0)); } diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index e51426113f26..854d3744dacf 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -397,10 +397,6 @@ static void __init setup_lowcore(void) */ BUILD_BUG_ON(sizeof(struct lowcore) != LC_PAGES * PAGE_SIZE); lc = memblock_alloc_low(sizeof(*lc), sizeof(*lc)); - if (!lc) - panic("%s: Failed to allocate %zu bytes align=%zx\n", - __func__, sizeof(*lc), sizeof(*lc)); - lc->pcpu = (unsigned long)per_cpu_ptr(&pcpu_devices, 0); lc->restart_psw.mask = PSW_KERNEL_BITS & ~PSW_MASK_DAT; lc->restart_psw.addr = __pa(restart_int_handler); diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c index 9eb4508b4ca4..467d4f390837 100644 --- a/arch/s390/kernel/smp.c +++ b/arch/s390/kernel/smp.c @@ -631,9 +631,6 @@ void __init smp_save_dump_secondary_cpus(void) return; /* Allocate a page as dumping area for the store status sigps */ page = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!page) - panic("ERROR: Failed to allocate %lx bytes below %lx\n", - PAGE_SIZE, 1UL << 31); /* Set multi-threading state to the previous system. */ pcpu_set_smt(sclp.mtid_prev); diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c index 05882bca5b73..8c813c755eb8 100644 --- a/arch/sparc/mm/init_64.c +++ b/arch/sparc/mm/init_64.c @@ -1789,8 +1789,6 @@ static unsigned long __ref kernel_map_range(unsigned long pstart, new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); - if (!new) - goto err_alloc; alloc_bytes += PAGE_SIZE; pgd_populate(&init_mm, pgd, new); } @@ -1801,8 +1799,6 @@ static unsigned long __ref kernel_map_range(unsigned long pstart, new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); - if (!new) - goto err_alloc; alloc_bytes += PAGE_SIZE; p4d_populate(&init_mm, p4d, new); } @@ -1817,8 +1813,6 @@ static unsigned long __ref kernel_map_range(unsigned long pstart, } new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); - if (!new) - goto err_alloc; alloc_bytes += PAGE_SIZE; pud_populate(&init_mm, pud, new); } @@ -1833,8 +1827,6 @@ static unsigned long __ref kernel_map_range(unsigned long pstart, } new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); - if (!new) - goto err_alloc; alloc_bytes += PAGE_SIZE; pmd_populate_kernel(&init_mm, pmd, new); } @@ -1854,11 +1846,6 @@ static unsigned long __ref kernel_map_range(unsigned long pstart, } return alloc_bytes; - -err_alloc: - panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); - return -ENOMEM; } static void __init flush_all_kernel_tsbs(void) diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 53248ed04771..9c161fb4ed3a 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -83,10 +83,6 @@ static void __init one_page_table_init(pmd_t *pmd) if (pmd_none(*pmd)) { pte_t *pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pte) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - set_pmd(pmd, __pmd(_KERNPG_TABLE + (unsigned long) __pa(pte))); BUG_ON(pte != pte_offset_kernel(pmd, 0)); @@ -97,10 +93,6 @@ static void __init one_md_table_init(pud_t *pud) { #if CONFIG_PGTABLE_LEVELS > 2 pmd_t *pmd_table = (pmd_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pmd_table) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table))); BUG_ON(pmd_table != pmd_offset(pud, 0)); #endif @@ -110,10 +102,6 @@ static void __init one_ud_table_init(p4d_t *p4d) { #if CONFIG_PGTABLE_LEVELS > 3 pud_t *pud_table = (pud_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!pud_table) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - set_p4d(p4d, __p4d(_KERNPG_TABLE + (unsigned long) __pa(pud_table))); BUG_ON(pud_table != pud_offset(p4d, 0)); #endif @@ -163,10 +151,6 @@ static void __init fixaddr_user_init( void) fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir); v = (unsigned long) memblock_alloc_low(size, PAGE_SIZE); - if (!v) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, size, PAGE_SIZE); - memcpy((void *) v , (void *) FIXADDR_USER_START, size); p = __pa(v); for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE, @@ -184,10 +168,6 @@ void __init paging_init(void) empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!empty_zero_page) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, PAGE_SIZE, PAGE_SIZE); - max_zone_pfn[ZONE_NORMAL] = end_iomem >> PAGE_SHIFT; free_area_init(max_zone_pfn); diff --git a/arch/xtensa/mm/mmu.c b/arch/xtensa/mm/mmu.c index 92e158c69c10..aee020c986a3 100644 --- a/arch/xtensa/mm/mmu.c +++ b/arch/xtensa/mm/mmu.c @@ -33,10 +33,6 @@ static void * __init init_pmd(unsigned long vaddr, unsigned long n_pages) __func__, vaddr, n_pages); pte = memblock_alloc_low(n_pages * sizeof(pte_t), PAGE_SIZE); - if (!pte) - panic("%s: Failed to allocate %lu bytes align=%lx\n", - __func__, n_pages * sizeof(pte_t), PAGE_SIZE); - for (i = 0; i < n_pages; ++i) pte_clear(NULL, 0, pte + i); diff --git a/include/linux/memblock.h b/include/linux/memblock.h index b68c141ebc44..3f940bf628a9 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -430,20 +430,22 @@ void *__memblock_alloc_panic(phys_addr_t size, phys_addr_t align, #define memblock_alloc_raw_no_panic(size, align) \ __memblock_alloc_panic(size, align, __func__, false, true) -static inline void *memblock_alloc_from(phys_addr_t size, - phys_addr_t align, - phys_addr_t min_addr) -{ - return memblock_alloc_try_nid(size, align, min_addr, - MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); -} - -static inline void *memblock_alloc_low(phys_addr_t size, - phys_addr_t align) -{ - return memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, - ARCH_LOW_ADDRESS_LIMIT, NUMA_NO_NODE); -} +void *__memblock_alloc_from_panic(phys_addr_t size, phys_addr_t align, + phys_addr_t min_addr,const char *func, + bool should_panic); + +#define memblock_alloc_from(size, align, min_addr) \ + __memblock_alloc_from_panic(size, align, min_addr, __func__, true) +#define memblock_alloc_from_no_panic(size, align, min_addr) \ + __memblock_alloc_from_panic(size, align, min_addr, __func__, false) + +void *__memblock_alloc_low_panic(phys_addr_t size, phys_addr_t align, + const char *func, bool should_panic); + +#define memblock_alloc_low(size, align) \ + __memblock_alloc_low_panic(size, align, __func__, true) +#define memblock_alloc_low_no_panic(size, align) \ + __memblock_alloc_low_panic(size, align, __func__, false) static inline void *memblock_alloc_node(phys_addr_t size, phys_addr_t align, int nid) diff --git a/mm/memblock.c b/mm/memblock.c index 4974ae2ee5ec..22922c81ff77 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1722,6 +1722,53 @@ void *__init __memblock_alloc_panic(phys_addr_t size, phys_addr_t align, return addr; } +/** + * __memblock_alloc_from_panic - Try to allocate memory and panic on failure + * @size: size of memory block to be allocated in bytes + * @align: alignment of the region and block's size + * @min_addr: the lower bound of the memory region from where the allocation + * is preferred (phys address) + * @func: caller func name + * @should_panic: whether failed panic + * + * In case of failure, it calls panic with the formatted message. + * This function should not be used directly, please use the macro + * memblock_alloc_from and memblock_alloc_from_no_panic. + */ +void *__init __memblock_alloc_from_panic(phys_addr_t size, phys_addr_t align, + phys_addr_t min_addr, const char *func, + bool should_panic) +{ + void *addr = memblock_alloc_try_nid(size, align, min_addr, + MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); + + if (unlikely(!addr && should_panic)) + panic("%s: Failed to allocate %pap bytes\n", func, &size); + return addr; +} + +/** + * __memblock_alloc_low_panic - Try to allocate memory and panic on failure + * @size: size of memory block to be allocated in bytes + * @align: alignment of the region and block's size + * @func: caller func name + * @should_panic: whether failed panic + * + * In case of failure, it calls panic with the formatted message. + * This function should not be used directly, please use the macro + * memblock_alloc_low and memblock_alloc_low_no_panic. + */ +void *__init __memblock_alloc_low_panic(phys_addr_t size, phys_addr_t align, + const char *func,bool should_panic) +{ + void *addr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, + ARCH_LOW_ADDRESS_LIMIT, NUMA_NO_NODE); + + if (unlikely(!addr && should_panic)) + panic("%s: Failed to allocate %pap bytes\n", func, &size); + return addr; +} + /** * memblock_free_late - free pages directly to buddy allocator * @base: phys starting address of the boot memory block diff --git a/mm/percpu.c b/mm/percpu.c index a381d626ed32..980fba4292be 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2933,7 +2933,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align, node = cpu_to_nd_fn(cpu); if (node == NUMA_NO_NODE || !node_online(node) || !NODE_DATA(node)) { - ptr = memblock_alloc_from(size, align, goal); + ptr = memblock_alloc_from_no_panic(size, align, goal); pr_info("cpu %d has no node %d or node-local memory\n", cpu, node); pr_debug("per cpu data for cpu%d %zu bytes at 0x%llx\n", @@ -2948,7 +2948,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align, } return ptr; #else - return memblock_alloc_from(size, align, goal); + return memblock_alloc_from_no_panic(size, align, goal); #endif } @@ -3318,7 +3318,7 @@ void __init setup_per_cpu_areas(void) ai = pcpu_alloc_alloc_info(1, 1); fc = memblock_alloc_from(unit_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); - if (!ai || !fc) + if (!ai) panic("Failed to allocate memory for percpu areas."); /* kmemleak tracks the percpu allocations separately */ kmemleak_ignore_phys(__pa(fc));