From patchwork Wed Jul 17 07:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13735193 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 16560C3DA42 for ; Wed, 17 Jul 2024 07:52:50 +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-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Owner; bh=UoU1EVDOZylwAfXBAL211ySLSEgfQDQcYjbW99W35+I=; b=aR5kCw2a/2d0Iz5Y3ExFhKwvjz VJenqx+MB1RMYvTmDjc6CH8rTTi5dRkEeKBq8xKCq8xhTw1e4kMpse831VC928wAZzedW6Y6mu5Lz XKkKjdBXz0EPZW/ha9aMHLixywx89qYe/sYEepp/VT/b4JSScU1/t5HOF+U/aOrmGeILMQxLWlmMW OHvAQ8kjx60rREO0w3iNS8FiiQ+32qTaRc0O6qy3yStSKxL0ouhpUwylXrMQ+gqeeACWLNEPAQy0T nv96pC7FLG+lsxvnBjLX7ubpOAT3SQyfpg8/BYGMWgf9bir3UWUI2wn1VzwCxSI7zJVNqXmghBa7h ZH11IiPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTzSp-0000000D2G9-003K; Wed, 17 Jul 2024 07:52:39 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTzQO-0000000D1bB-1ZTa; Wed, 17 Jul 2024 07:50:28 +0000 Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WP7PC3JZ8znb9y; Wed, 17 Jul 2024 15:49:19 +0800 (CST) Received: from kwepemi100008.china.huawei.com (unknown [7.221.188.57]) by mail.maildlp.com (Postfix) with ESMTPS id 6C38F1800A3; Wed, 17 Jul 2024 15:49:57 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi100008.china.huawei.com (7.221.188.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 17 Jul 2024 15:49:56 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , CC: Subject: [PATCH -next v3 2/2] ARM: Fix crash memory reserve exceed system memory bug Date: Wed, 17 Jul 2024 15:54:39 +0800 Message-ID: <20240717075439.2705552-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240717075439.2705552-1-ruanjinjie@huawei.com> References: <20240717075439.2705552-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi100008.china.huawei.com (7.221.188.57) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240717_005008_620789_F0826BF3 X-CRM114-Status: GOOD ( 12.04 ) 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 Similar with x86_32, on Qemu vexpress-a9 with 1GB memory, the crash kernel "crashkernel=4G" is ok as below: Reserving 4096MB of memory at 2432MB for crashkernel (System RAM: 1024MB) The cause is that the crash_size is parsed and printed with "unsigned long long" data type which is 8 bytes but allocated used with "phys_addr_t" which is 4 bytes in memblock_phys_alloc_range(). Fix it by checking if the crash_size is greater than system RAM size and warn out if so as Baoquan suggested. After this patch, it fails and warn out as expected and no above confusing reserve success info. Signed-off-by: Jinjie Ruan Suggested-by: Baoquan He --- v3: - Handle the check in reserve_crashkernel() Baoquan suggested. - Split x86_32 and arm32. - Add Suggested-by. - Drop the wrong fix tag. v2: - Also fix for x86_32. - Update the fix method. - Peel off the other two patches. - Update the commit message. --- arch/arm/kernel/setup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index e6a857bf0ce6..791d5f046163 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1015,6 +1015,11 @@ static void __init reserve_crashkernel(void) if (ret || !crash_size) return; + if (crash_size >= total_mem) { + pr_warn("Crashkernel reserve memory cannot exceed physical memory."); + return; + } + if (crash_base <= 0) { unsigned long long crash_max = idmap_to_phys((u32)~0); unsigned long long lowmem_max = __pa(high_memory - 1) + 1;