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 X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDB58C433EF for ; Tue, 14 Sep 2021 06:52:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 998806058D for ; Tue, 14 Sep 2021 06:52:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 998806058D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ygsf6Z/kah+OR1j/KPhLA+pNHEniWhrqsrdhhPONIAw=; b=VCDIXzQNmPSQNn j9101mE6Rq/DFBMM1rlAZJAI+LBdy15JBkbcs9H+YBHoDXTo77jrfJBCmEFvd6zGkNUuzlXLExw9m r9GjUnAnOZWbb4LDGhvT5NxHbglQi5IRdIuJe/S45PMCNKpbdXUdkPmhsmenbl9c+Gdwpuiz5/9pm gHF0nB4HuMaFY+HR0x0E0PBJnokl6/mejTWcCLDlOaLqdp3x5s0WCbyuLZQKabAk4GLp8uZryRZs/ 7Gx3BW37VlRyqLzIhmU8m/G/j/cqfVV5FzHi2oYRgdpzu9cYLPqkNhZfIpiXszmclr3CS+gaV5nX8 GtGLRkvAvtlC6ZCYUC9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQ2Gw-004KJJ-BK; Tue, 14 Sep 2021 06:50:26 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQ2Gr-004KHS-QC for linux-arm-kernel@lists.infradead.org; Tue, 14 Sep 2021 06:50:23 +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 9FD871FB; Mon, 13 Sep 2021 23:50:17 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.71.145]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 363713F719; Mon, 13 Sep 2021 23:50:14 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , James Morse , linux-kernel@vger.kernel.org Subject: [PATCH] arm64/mm/hotplug: Warn when memory limit has been reduced Date: Tue, 14 Sep 2021 12:21:10 +0530 Message-Id: <1631602270-29215-1-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210913_235021_996776_ED3B6CD0 X-CRM114-Status: GOOD ( 17.53 ) 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: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the max memory limit has been reduced with 'mem=' kernel command line option, there might be UEFI memory map described memory beyond that limit which could be hot removed. This might be problematic for subsequent kexec kernel which could just access such removed memory. Memory offline notifier exists because there is no other way to block the removal of boot memory, only the offlining (which isn't actually a problem) But with 'mem=', there is no chance to stop such boot memory being offlined as it where never in use by the kernel. As 'mem=' is a debug only option on arm64 platform, just warn for such a situation and move on. Cc: Catalin Marinas Cc: Will Deacon Cc: James Morse Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- This applies on v5.15-rc1 arch/arm64/include/asm/memory.h | 1 + arch/arm64/mm/init.c | 9 +++++++-- arch/arm64/mm/mmu.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index f1745a843414..361d4e01a864 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -353,6 +353,7 @@ static inline void *phys_to_virt(phys_addr_t x) }) void dump_mem_limit(void); +bool has_mem_limit_reduced(void); #endif /* !ASSEMBLY */ /* diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 37a81754d9b6..cf21edfc8b0f 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -211,6 +211,11 @@ EXPORT_SYMBOL(pfn_is_map_memory); static phys_addr_t memory_limit = PHYS_ADDR_MAX; +bool has_mem_limit_reduced(void) +{ + return memory_limit != PHYS_ADDR_MAX; +} + /* * Limit the memory size that was specified via FDT. */ @@ -285,7 +290,7 @@ void __init arm64_memblock_init(void) * high up in memory, add back the kernel region that must be accessible * via the linear mapping. */ - if (memory_limit != PHYS_ADDR_MAX) { + if (has_mem_limit_reduced()) { memblock_mem_limit_remove_map(memory_limit); memblock_add(__pa_symbol(_text), (u64)(_end - _text)); } @@ -461,7 +466,7 @@ void free_initmem(void) void dump_mem_limit(void) { - if (memory_limit != PHYS_ADDR_MAX) { + if (has_mem_limit_reduced()) { pr_emerg("Memory Limit: %llu MB\n", memory_limit >> 20); } else { pr_emerg("Memory Limit: none\n"); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index cfd9deb347c3..7ac39ee876c3 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1627,6 +1627,18 @@ static int __init prevent_bootmem_remove_init(void) if (!IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) return ret; + if (has_mem_limit_reduced()) { + /* + * Physical memory limit has been reduced via the 'mem=' kernel + * command line option. Memory beyond reduced limit could now be + * removed and reassigned (guest ?) transparently to the kernel. + * This might cause subsequent kexec kernel to crash or at least + * corrupt the memory when accessing UEFI memory map enumerated + * boot memory which might have been repurposed. + */ + pr_warn("Memory limit reduced, kexec might be problematic\n"); + } + validate_bootmem_online(); ret = register_memory_notifier(&prevent_bootmem_remove_nb); if (ret) -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel