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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2A45CCD18E for ; Wed, 15 Oct 2025 11:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=b7JiK8Qm1019qOvccQAM6vd3YrX733NvJa6pwVmgHUQ=; b=e662qehCfb3KszP984sxIbXPAz sJLnzFu9KvYj5Qs8Il9Joda3Ewi5FcBmEtL/e6nor6VxlLwzloJTeRbUa1Ijyrzwgc6NdKWJchm1D kj2K3GYLCw2ZSvN2biRyitRVnTjXcoOR46gh74zcDNCepovUpBYI2r3AWsd09K9+DYvuo9k2X6hlV OG+xzoARU4r3OwtEdxaXERJwmNZqdKuas+KWIvenvphIePn7LPvxKj8AFBV2ZqN8bi6V8yK/S8324 RXoapJqSontjll3bDkH2FigzcbfFwo2TzPNN87Lk0BXeN2w5VQ40QYGp23MUdHHXv/D8yekXjTHbi tLBQ2o9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v8zg2-00000001PpP-2Iz7; Wed, 15 Oct 2025 11:28:18 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v8zfz-00000001Pp4-3QO4 for linux-arm-kernel@lists.infradead.org; Wed, 15 Oct 2025 11:28:17 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E6A5339; Wed, 15 Oct 2025 04:28:06 -0700 (PDT) Received: from a079125.blr.arm.com (a079125.arm.com [10.164.21.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 372F53F66E; Wed, 15 Oct 2025 04:28:09 -0700 (PDT) From: Linu Cherian To: Catalin Marinas , Will Deacon , Andrew Morton , Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Anshuman Khandual , Kevin Brodsky , Zhenhua Huang , Dev Jain , Lorenzo Stoakes , Yang Shi , Linu Cherian Subject: [PATCH v3 0/2] arm64/mm: prevent panic on -ENOMEM in arch_add_memory() Date: Wed, 15 Oct 2025 16:57:56 +0530 Message-ID: <20251015112758.2701604-1-linu.cherian@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251015_042815_892740_A611D34C X-CRM114-Status: GOOD ( 10.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org arch_add_memory() acts as a means to hotplug memory into a system. It invokes __create_pgd_mapping() which further unwinds to call pgtable_alloc(). Initially, this path was only invoked during early boot and therefore it made sense to BUG_ON() in case pgtable_alloc() failed. Now however, we risk running into a kernel crash if we try to hotplug memory into a system that is already extremely tight on available memory. This is undesirable and hence __create_pgd_mapping() and it's helpers are reworked to be able to propagate the error from pgtable_alloc() allowing the system to fail gracefully. Keeping in mind that it is still essential to BUG_ON()/panic if pgtable_alloc() encounters failure at the time of boot, a wrapper is created around __create_pgd_mapping() which is designed to panic() if it encounters a non-zero return value. This wrapper is then invoked from the init functions instead of __create_pgd_mapping(), thereby keeping the original functionality intact. This theoretical bug was identified by Ryan Roberts as a part of code review of the following series[1]. [1] https://lore.kernel.org/linux-arm-kernel/20250304222018.615808-4-yang@os.amperecomputing.com/ Changelog v3: * Added a Fixes tag to patch 1 and CCed to stable * Fixed a maybe-uninitialized case in alloc_init_pud * Update pgd_pgtable_alloc_init_mm to make use of pgd_pgtable_alloc_init_mm_gfp * Few other trivial cleanups v2: * With cleanup merged as part of, "arm64: mm: Move KPTI helpers to mmu.c" changes in patch 2(v1) got much simplified and squashed to patch 1 itself. * Patch 2 now does a trivial renaming for better readability * Make use of INVALID_PHYS_ADDR for error checks instead of 0. * Do early function return where we do not have any common cleanup in return path * Remove redundant variable initialization * Changed BUG_ON to panic * Renamed ___create_pgd_mapping to early_create_pgd_mapping Chaitanya S Prakash (1): arm64/mm: Allow __create_pgd_mapping() to propagate pgtable_alloc() errors Linu Cherian (1): arm64/mm: Rename try_pgd_pgtable_alloc_init_mm arch/arm64/mm/mmu.c | 216 +++++++++++++++++++++++++++----------------- 1 file changed, 135 insertions(+), 81 deletions(-) -- 2.43.0