From patchwork Fri Jan 3 10:51:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weikang Guo X-Patchwork-Id: 13925484 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 CBAFDE77198 for ; Fri, 3 Jan 2025 10:52:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 541826B0082; Fri, 3 Jan 2025 05:52:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F23E6B0083; Fri, 3 Jan 2025 05:52:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 393756B0085; Fri, 3 Jan 2025 05:52:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 21A7A6B0082 for ; Fri, 3 Jan 2025 05:52:13 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C34541404E4 for ; Fri, 3 Jan 2025 10:52:12 +0000 (UTC) X-FDA: 82965824424.21.EFC514C Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf02.hostedemail.com (Postfix) with ESMTP id 1990D8000E for ; Fri, 3 Jan 2025 10:50:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fvMqkuOe; spf=pass (imf02.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=1735901496; 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=Cy+yX6wEbnIcQp94PEsxSyfI8yNEpKG8JNMSnjXRqAI=; b=xfYh5CLxt8EIUZZfKlNMXecxRUeCyXzxZyR4J3Yq1OntbicJuMQBEy3cm9DmnE9Twn9LpT xqnbPf54970VAfYQDCXqdQUYRY7Tj9rNUniRfxPeBoe22DjFKh0ugZSDdjeyTB6CGFfrd4 d7D3VhQt8ZrjZZBNjYBKQ6RW/iKMdS0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735901496; a=rsa-sha256; cv=none; b=JwDNgluX+UDmSBKfLHGlhkKw7fSbf7Qo+TaWo4vxwQuDBaO8P2EXaR+FbO1Y7/t8j50dXQ ipgN/XNOYhZj+KGC7+gzuAE4BMx6S9AicX8XQxEA0m9Kb7glcVdwpIyQydmqT/MgGCO73E WDpgkx1GECVDgXbtyb+BhBpvoo3ycck= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fvMqkuOe; spf=pass (imf02.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-21631789fcdso125084025ad.1 for ; Fri, 03 Jan 2025 02:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735901530; x=1736506330; 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=Cy+yX6wEbnIcQp94PEsxSyfI8yNEpKG8JNMSnjXRqAI=; b=fvMqkuOeDNdRgFSc33zeMTtDoFkn+sUkrr4kK2S/zr4PTtHzlyUAXFPPNhsw4+jBz6 NhS7WjLrmkQGcygx+I5cSil1yAcvhBR7qXwdzJSqJ/V10O5MR+Dgjb+c+64ylb9dgkuK Kcbe9tXZOF94rM3zSvKm2EW36Sj6O5v5e8nMf7vK8FIMpQrnIwJcSQY3EBZ7K8P4yU5e 02X5VO2stI5yQEhM6455G8pBexdXv7jCCJVGgpFByTj18LTqnT+7r3VLRCsBJj3lPqSW c9WPKiBXKbOUHUiwycrfbjwcDwebAevzPosEFB4TK62TvMBcDJovGoeohVemGuvXGsTV RFrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735901530; x=1736506330; 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=Cy+yX6wEbnIcQp94PEsxSyfI8yNEpKG8JNMSnjXRqAI=; b=aZgsD21zGeu2BrYg8b0Gd+E77PspSSd0ly4U836vlItOUkMJJVeKEI5Sw3OmOgIM3j WySkPuchsBa1igZLOF2/OxFoVKqIcwvY2xA7oTH4dZXERwIsfe+ETfQNrbLPI4OMtbtW lcp+IBlltko2Xqx+dH//44iGceGYJ4Ihhx6mG6Z6Dpp9ZYTKtGTjZUTvwkoF3WUpGQ25 LuZrPsFCSoNyCJfJwiOwvx3WXj5xBP21xoyyqcRIAQnolhlWKpfG5YUqdO7fhMLPQvNB +L0thX+aIOeVFHfmAOFd7HQ+7hEHMorj8HFeztAb9MY0XFgvTlr7SaXKbBtRMni/mkdW wUJw== X-Gm-Message-State: AOJu0YybWGdTiVcgyW+K/D/jjuU78BRzP/wLVFq+/UwbTeB5Rz6koSG2 Jg6Co3Qt6DkkPNq49zkacp8R46qc23ErHa1FIqJQIz2j3okqdq6M X-Gm-Gg: ASbGncuEskDSnXZUxtpPxA5nS0zd8282LfaHeoG8ny8MlARZ/DjCFzlHqfGpN7APtBf 5Hb6vEYhD+Rt/WaI0rsSgOwnIYz4wDJTe5akl1Iudg2OwhvNgzr4TOPTOA5wjGKmMvFSSMIZ1Yz 3gcR9DJRmnQFlxMi4tc38tLPWe/uBrA+asDt/cwxWMJgpkX7RupHGR7qKq8SyKdvradT1cto9ZK lK1xBtJT68wKAwOAWHOvNxWTZUtA44UwLc0YxoeFmG/wBJmxrxqqJBLP+YP0TMiXWIDRC641rDY 3QNW X-Google-Smtp-Source: AGHT+IEFyETklwSj2j6erSwDIdU9K6u5rhSzXwT6aCJIlf3JqQYNREYAUxQsw/AQtYTFrVfR+9hOOQ== X-Received: by 2002:a05:6a20:43ac:b0:1e1:e2d8:fd4a with SMTP id adf61e73a8af0-1e5e1e04618mr69199866637.5.1735901529701; Fri, 03 Jan 2025 02:52:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 02:52:09 -0800 (PST) From: Guo Weikang To: Mike Rapoport , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guo Weikang Subject: [PATCH 2/3] mm/memblock: Modify the default failure behavior of memblock_alloc_raw to panic Date: Fri, 3 Jan 2025 18:51:57 +0800 Message-Id: <20250103105158.1350689-2-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: rspam02 X-Rspamd-Queue-Id: 1990D8000E X-Stat-Signature: 4k8n5jgdrirpbg7qks91n5564hfshiqj X-Rspam-User: X-HE-Tag: 1735901431-343603 X-HE-Meta: U2FsdGVkX19HCuBm8uH4PYX+MLD8SOor8WFTXMJEzC3vjWUQoiQ1a4OHnnwkWkoMVW3364YBub51l25uD/+6X/Man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twUBp2Q2uz4WpOurnoEC1VmNW7E8Qz4a0VNpu5/EYuRzAuACLHHTjRDO6tnEa9QdrrPBCf41B3fK8niQT6pHbBTM94ShhP+p7n7UJXqCzqlBO7+X6FQkP21qeNV+YDka08DHtLQaNHoRiSSB127iOzSY/FKoIDL676QQDpk83UmN1s5UUV4f0v0w3hbpHpXCSAT2+b1y1WT2eidD7c2RYJdu4f9Rm5QxSuUpUDi3NwLvheGfWLTHs8OmHquY+7l9tTCZLkYI4/KH/HWvQ0E+qRbm0n4q80UmB8RqTfBQHk/DllqLuP2aRs82Wl8KKtswW1fjhbI1YvOzmB3lJBQ5HMqhICbiRpk= 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_raw is now modified to trigger a panic when allocation fails. memblock_alloc_no_panic has been introduced to handle cases where panic behavior is not desired. Signed-off-by: Guo Weikang --- arch/openrisc/mm/init.c | 3 --- arch/powerpc/kernel/paca.c | 4 ---- arch/powerpc/kernel/prom.c | 3 --- arch/powerpc/platforms/pseries/plpks.c | 2 +- include/linux/memblock.h | 17 +++++++---------- mm/memblock.c | 13 +++++++++++-- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/arch/openrisc/mm/init.c b/arch/openrisc/mm/init.c index d0cb1a0126f9..9e0047764f54 100644 --- a/arch/openrisc/mm/init.c +++ b/arch/openrisc/mm/init.c @@ -96,9 +96,6 @@ static void __init map_ram(void) /* Alloc one page for holding PTE's... */ pte = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE); - if (!pte) - panic("%s: Failed to allocate page for PTEs\n", - __func__); set_pmd(pme, __pmd(_KERNPG_TABLE + __pa(pte))); /* Fill the newly allocated page with PTE'S */ diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 7502066c3c53..9d15799e97d4 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -246,10 +246,6 @@ void __init allocate_paca_ptrs(void) paca_ptrs_size = sizeof(struct paca_struct *) * nr_cpu_ids; paca_ptrs = memblock_alloc_raw(paca_ptrs_size, SMP_CACHE_BYTES); - if (!paca_ptrs) - panic("Failed to allocate %d bytes for paca pointers\n", - paca_ptrs_size); - memset(paca_ptrs, 0x88, paca_ptrs_size); } diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index e0059842a1c6..3aba66ddd2c8 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -128,9 +128,6 @@ static void __init move_device_tree(void) !memblock_is_memory(start + size - 1) || overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) { p = memblock_alloc_raw(size, PAGE_SIZE); - if (!p) - panic("Failed to allocate %lu bytes to move device tree\n", - size); memcpy(p, initial_boot_params, size); initial_boot_params = p; DBG("Moved device tree to 0x%px\n", p); diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c index b1667ed05f98..1bcbed41ce44 100644 --- a/arch/powerpc/platforms/pseries/plpks.c +++ b/arch/powerpc/platforms/pseries/plpks.c @@ -671,7 +671,7 @@ void __init plpks_early_init_devtree(void) return; } - ospassword = memblock_alloc_raw(len, SMP_CACHE_BYTES); + ospassword = memblock_alloc_raw_no_panic(len, SMP_CACHE_BYTES); if (!ospassword) { pr_err("Error allocating memory for password.\n"); goto out; diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 6b21a3834225..b68c141ebc44 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -418,20 +418,17 @@ static __always_inline void *memblock_alloc(phys_addr_t size, phys_addr_t align) } void *__memblock_alloc_panic(phys_addr_t size, phys_addr_t align, - const char *func, bool should_panic); + const char *func, bool should_panic, bool raw); #define memblock_alloc(size, align) \ - __memblock_alloc_panic(size, align, __func__, true) + __memblock_alloc_panic(size, align, __func__, true, false) #define memblock_alloc_no_panic(size, align) \ - __memblock_alloc_panic(size, align, __func__, false) + __memblock_alloc_panic(size, align, __func__, false, false) -static inline void *memblock_alloc_raw(phys_addr_t size, - phys_addr_t align) -{ - return memblock_alloc_try_nid_raw(size, align, MEMBLOCK_LOW_LIMIT, - MEMBLOCK_ALLOC_ACCESSIBLE, - NUMA_NO_NODE); -} +#define memblock_alloc_raw(size, align) \ + __memblock_alloc_panic(size, align, __func__, true, true) +#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, diff --git a/mm/memblock.c b/mm/memblock.c index 901da45ecf8b..4974ae2ee5ec 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1697,15 +1697,24 @@ void * __init memblock_alloc_try_nid( * @align: alignment of the region and block's size * @func: caller func name * @should_panic: whether failed panic + * @raw: whether zeroing mem * * In case of failure, it calls panic with the formatted message. * This function should not be used directly, please use the macro * memblock_alloc and memblock_alloc_no_panic. + * memblock_alloc_raw and memblock_alloc_raw_no_panic. */ void *__init __memblock_alloc_panic(phys_addr_t size, phys_addr_t align, - const char *func, bool should_panic) + const char *func, bool should_panic, + bool raw) { - void *addr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, + void *addr; + + if (unlikely(raw)) + addr = memblock_alloc_try_nid_raw(size, align, MEMBLOCK_LOW_LIMIT, + MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); + else + addr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); if (unlikely(!addr && should_panic))