Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1625921pxk; Fri, 18 Sep 2020 19:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxksZVTylnkJClT6qSVCh8TCG2IF5e6jt8SvvSJjmt9mIxg9rexdW07cUWm+U5R6lNOAg7+ X-Received: by 2002:a17:906:9718:: with SMTP id k24mr36557473ejx.365.1600481063220; Fri, 18 Sep 2020 19:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600481063; cv=none; d=google.com; s=arc-20160816; b=ABH+SPmEOXD1e1gBrLFsTEevYzEi2eoExIAxTD68lE/Hc5dazEIjtwQ4PkLQY0DGHB SPVPR56araTHOOVvre1hyr5QmJQbfx9t/AyTuZTpWvRIqoDDbgzqmhEVpUlazbpYHO06 CC1aOMajfr/BQ5rjwCnxWU+v7a7zl96BXhYFaJMYnmv5xzBIQHQwmN3cjSAA4H9Cu5q5 yy3ebzfokOayOYG+X4p6fjmtKtRYnR0qjqz3ufSfJU6XxORKxi1hZVYMbPl2swdInY3h JY3WArkPd2ZFlOAn2+alkwlOgJSjoccoLXMaKdyAHfR0Jt6b/nhTYbJnLYAjKcC//qKo zzbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=/87e08Nc/uPBo5x38DRmvaIR164x+imuNy4zgSLPNNs=; b=SMj0SJhlyDWvsWbWBAvulLqcanm0WwyRjZmc4xA7rPXeQGgXlhMmT5wZhvv0YsuuBx kEZqa49aa2bzz9s1CYrEZhDJBOoLxtjvOlwpZ6EczblxBr96Qwe124ALq2jf5mUi5tV9 7DXabtoB58rtuMP9w+pnpOy9cEa5isEWhJtRybbKuxBy+azfGqLkfjDbX+bk+JVBIE73 SI9ANEqDSvzLhFRAAWrNEaX7gh8RimFPEfOJ3GnMlJJYUnt297PqacTK/g0lHAImjgUt FDJo0pUlfLjiYnuulLgzLFNlEFMtn8qWP8lyhccHNjg+Vfk4EuOXv3Mn/mPWOySn8Dbw q0EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u14si3384525ejt.556.2020.09.18.19.04.00; Fri, 18 Sep 2020 19:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726305AbgISCCo (ORCPT + 99 others); Fri, 18 Sep 2020 22:02:44 -0400 Received: from mail.loongson.cn ([114.242.206.163]:44436 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726252AbgISCCo (ORCPT ); Fri, 18 Sep 2020 22:02:44 -0400 X-Greylist: delayed 412 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Sep 2020 22:02:41 EDT Received: from bogon.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx6MQiZWVfIF8WAA--.1308S2; Sat, 19 Sep 2020 09:55:46 +0800 (CST) From: Youling Tang To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] MIPS: kexec: Add crashkernel=YM handling Date: Sat, 19 Sep 2020 09:55:46 +0800 Message-Id: <1600480546-10448-1-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dx6MQiZWVfIF8WAA--.1308S2 X-Coremail-Antispam: 1UD129KBjvJXoWxGw4xJF1UGF4fZw15Zw1UW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ger.kernel.org When the kernel crashkernel parameter is specified with just a size, we are supposed to allocate a region from RAM to store the crashkernel. However, MIPS merely reserves physical address zero with no checking that there is even RAM there. Fix this by lifting similar code from x86, importing it to MIPS with the MIPS specific parameters added. In the absence of any platform specific information, we allocate the crashkernel region from the first 512MB of physical memory (limited to CKSEG0 or KSEG0 address range). When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM). E.g. without this patch: The environment as follows: [ 0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a ... [ 0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ... The warning as follows: [ 0.000000] Invalid memory region reserved for crash kernel And the iomem as follows: 00200000-0effffff : System RAM 00200000-00b47f87 : Kernel code 00b47f88-00dfffff : Kernel data 00e60000-01f73c7f : Kernel bss 1a000000-1bffffff : pci@1a000000 ... With this patch: After increasing crash_base <= 0 handling. And the iomem as follows: 00200000-0effffff : System RAM 00200000-00b47f87 : Kernel code 00b47f88-00dfffff : Kernel data 00e60000-01f73c7f : Kernel bss 04000000-09ffffff : Crash kernel 1a000000-1bffffff : pci@1a000000 ... Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index bf5f5ac..59a88ea 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr); #endif #ifdef CONFIG_KEXEC + +/* 64M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_64M +#define CRASH_ADDR_MAX SZ_512M + static void __init mips_parse_crashkernel(void) { unsigned long long total_mem; @@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void) if (ret != 0 || crash_size <= 0) return; - if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) { - pr_warn("Invalid memory region reserved for crash kernel\n"); - return; + if (crash_base <= 0) { + crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX, + crash_size, CRASH_ALIGN); + if (!crash_base) { + pr_warn("crashkernel reservation failed - No suitable area found.\n"); + return; + } + } else { + unsigned long long start; + + start = memblock_find_in_range(crash_base, crash_base + crash_size, + crash_size, 1); + if (start != crash_base) { + pr_warn("Invalid memory region reserved for crash kernel\n"); + return; + } } crashk_res.start = crash_base; -- 2.1.0