From patchwork Wed Dec 22 13:08:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697086 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 9D038C433EF for ; Wed, 22 Dec 2021 13:13:58 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=31ZYUZBVMkWc2aLODOUepOAEuD4XjX19sNRLLKzB/60=; b=sm7Hnxb6tL4p2S 5XvAqrlRDe6ywi/5pFjX5pqOUktXGMbwrndWs/3LA+4l0g00FloQgyRPFgVEU6nJX663OaLUBE1Hr 3Y+hXaTnaK/7ePkYbOZ71zRqkbzfMaxMCQu5xFsNdaobW8+y6xGyk+JwjRrfLOJ1hueQCsreg1NQS 4e44GGDP4tAhEarqCV4m315zteXQwVKwkZw4GeTE+J9jjCqvWcB2Cwl6wnuXnQcb1OApRq8xnDhLF fOiEpa/SFnyPKAYM/vuJQPv1vQGztvD6sNVYTG455v2QQ4gTELv/edn88sLoViXgLGvxBqAq/ZJZ7 fmunRHUDiKGwQEquELDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Q0-00APIC-VD; Wed, 22 Dec 2021 13:12:33 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pq-00AP80-LJ; Wed, 22 Dec 2021 13:12:24 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JJtvB3pMVz1DKCC; Wed, 22 Dec 2021 21:09:10 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:19 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:18 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 01/17] x86/setup: Move CRASH_ALIGN and CRASH_ADDR_{LOW|HIGH}_MAX to asm/kexec.h Date: Wed, 22 Dec 2021 21:08:04 +0800 Message-ID: <20211222130820.1754-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051223_087644_AF9EECB9 X-CRM114-Status: GOOD ( 15.79 ) 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 From: Chen Zhou We want to make function reserve_crashkernel[_low](), which is implemented by X86, available to other architectures. It references macro CRASH_ALIGN and will be moved to public crash_core.c. But the defined values of CRASH_ALIGN may be different in different architectures. So moving the definition of CRASH_ALIGN to asm/kexec.h is a good choice. The reason for moving CRASH_ADDR_{LOW|HIGH}_MAX is the same as above. Signed-off-by: Chen Zhou Co-developed-by: Zhen Lei Signed-off-by: Zhen Lei --- arch/x86/include/asm/kexec.h | 24 ++++++++++++++++++++++++ arch/x86/kernel/setup.c | 24 ------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 11b7c06e2828c30..a0223a6c0238a15 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -18,6 +18,30 @@ # define KEXEC_CONTROL_CODE_MAX_SIZE 2048 +/* 16M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_16M + +/* + * Keep the crash kernel below this limit. + * + * Earlier 32-bits kernels would limit the kernel to the low 512 MB range + * due to mapping restrictions. + * + * 64-bit kdump kernels need to be restricted to be under 64 TB, which is + * the upper limit of system RAM in 4-level paging mode. Since the kdump + * jump could be from 5-level paging to 4-level paging, the jump will fail if + * the kernel is put above 64 TB, and during the 1st kernel bootup there's + * no good way to detect the paging mode of the target kernel which will be + * loaded for dumping. + */ +#ifdef CONFIG_X86_32 +# define CRASH_ADDR_LOW_MAX SZ_512M +# define CRASH_ADDR_HIGH_MAX SZ_512M +#else +# define CRASH_ADDR_LOW_MAX SZ_4G +# define CRASH_ADDR_HIGH_MAX SZ_64T +#endif + #ifndef __ASSEMBLY__ #include diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 6a190c7f4d71b05..ae8f63661363e25 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -392,30 +392,6 @@ static void __init memblock_x86_reserve_range_setup_data(void) #ifdef CONFIG_KEXEC_CORE -/* 16M alignment for crash kernel regions */ -#define CRASH_ALIGN SZ_16M - -/* - * Keep the crash kernel below this limit. - * - * Earlier 32-bits kernels would limit the kernel to the low 512 MB range - * due to mapping restrictions. - * - * 64-bit kdump kernels need to be restricted to be under 64 TB, which is - * the upper limit of system RAM in 4-level paging mode. Since the kdump - * jump could be from 5-level paging to 4-level paging, the jump will fail if - * the kernel is put above 64 TB, and during the 1st kernel bootup there's - * no good way to detect the paging mode of the target kernel which will be - * loaded for dumping. - */ -#ifdef CONFIG_X86_32 -# define CRASH_ADDR_LOW_MAX SZ_512M -# define CRASH_ADDR_HIGH_MAX SZ_512M -#else -# define CRASH_ADDR_LOW_MAX SZ_4G -# define CRASH_ADDR_HIGH_MAX SZ_64T -#endif - static int __init reserve_crashkernel_low(void) { #ifdef CONFIG_X86_64 From patchwork Wed Dec 22 13:08:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697090 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 0A527C433F5 for ; Wed, 22 Dec 2021 13:15:43 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=qDCvj1BRFnDq+mj5i+si+256nfZq2fApYVjHNNe+o94=; b=dNP9x1UOWcrzQl o5wowwvdtp85xm7QBE/GXoZFL1ML2yTfN6SrbBFR2LzC3jKDoYzP4Wdg1Wwdh0Foa34Xyo+F39r+0 +ThRUYxABsmT/j1pvXioOtI/HJvYD2Se42qwVSa2bbnaVIwG7ZwrJRhb/Zzl0gXP2URr0SWY3cHPs g4EdPn5kSuA1KCJFG2hpTLrjmK6OK00zxiJ4BUxPKOPIc+2c5OXB6i6oCvML2L2jpRGGrfdNRrZcx I3rk2cwcfyNQC4snufIFJX1hMlp9MGwLSxH5Jl8Qximkjmy5DQY5rlKy9AK14u18T4w7tN6TmBqZx du9ax5BJyxuUGal9mq0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Rl-00AQLl-2X; Wed, 22 Dec 2021 13:14:21 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pr-00AP8U-By; Wed, 22 Dec 2021 13:12:26 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtvC2WQ7zZdp0; Wed, 22 Dec 2021 21:09:11 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:20 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:19 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 02/17] x86/setup: Move xen_pv_domain() check and insert_resource() to setup_arch() Date: Wed, 22 Dec 2021 21:08:05 +0800 Message-ID: <20211222130820.1754-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051223_840382_67BB8C37 X-CRM114-Status: GOOD ( 14.34 ) 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 From: Chen Zhou We will make the functions reserve_crashkernel() as generic, the xen_pv_domain() check in reserve_crashkernel() is relevant only to x86, the same as insert_resource() in reserve_crashkernel[_low](). So move xen_pv_domain() check and insert_resource() to setup_arch() to keep them in x86. Suggested-by: Mike Rapoport Signed-off-by: Chen Zhou Co-developed-by: Zhen Lei Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index ae8f63661363e25..acf2f2eedfe3415 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -434,7 +434,6 @@ static int __init reserve_crashkernel_low(void) crashk_low_res.start = low_base; crashk_low_res.end = low_base + low_size - 1; - insert_resource(&iomem_resource, &crashk_low_res); #endif return 0; } @@ -458,11 +457,6 @@ static void __init reserve_crashkernel(void) high = true; } - if (xen_pv_domain()) { - pr_info("Ignoring crashkernel for a Xen PV domain\n"); - return; - } - /* 0 means: find the address automatically */ if (!crash_base) { /* @@ -508,11 +502,6 @@ static void __init reserve_crashkernel(void) crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; - insert_resource(&iomem_resource, &crashk_res); -} -#else -static void __init reserve_crashkernel(void) -{ } #endif @@ -1120,7 +1109,17 @@ void __init setup_arch(char **cmdline_p) * Reserve memory for crash kernel after SRAT is parsed so that it * won't consume hotpluggable memory. */ - reserve_crashkernel(); +#ifdef CONFIG_KEXEC_CORE + if (xen_pv_domain()) + pr_info("Ignoring crashkernel for a Xen PV domain\n"); + else { + reserve_crashkernel(); + if (crashk_res.end > crashk_res.start) + insert_resource(&iomem_resource, &crashk_res); + if (crashk_low_res.end > crashk_low_res.start) + insert_resource(&iomem_resource, &crashk_low_res); + } +#endif memblock_find_dma_reserve(); From patchwork Wed Dec 22 13:08:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697087 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 01D1AC433F5 for ; Wed, 22 Dec 2021 13:14:23 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=hgZxG62qM7RaF+mNeOqzrl2NPnjTyw86feTGBAFTZWw=; b=qTsyNMVOMysRYY tP5RIm5icfiGFTkOr2tWH4CQ7aFM/7ONPzSxfWrWrF9yxDVY0eOlZbBx+Jcz/TTGaouHTFQ0fhqXV tFkd0EiLs5dr1O5aVcQvaj0oaCAxwGAzgNezxsb5ouQtliC1eTF+hrEJknH3yKaD7evvDjJsxWq2z C8NmaHJkGBExT9wfop3MWgBUa80eeil1kPcvEpx+O0rQAkUw2zH2eJzLgZj66tQqW8OwS1HsIaJel +M3PdcsYx8FDR9ZJShy4/xk+pRYSmnR/qqSWCSK+YGdqJTzPZC4ZYy7Th0Piuf4qMuJrbHQcU6q/l FFlQK3RoQk6OIFuQdQVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01QP-00APen-4X; Wed, 22 Dec 2021 13:12:57 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pr-00AP9h-FI; Wed, 22 Dec 2021 13:12:25 +0000 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtyQ2kstzcc55; Wed, 22 Dec 2021 21:11:58 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:21 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:20 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 03/17] x86/setup: Adjust the range of codes separated by CONFIG_X86_64 Date: Wed, 22 Dec 2021 21:08:06 +0800 Message-ID: <20211222130820.1754-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051223_772834_A846FF25 X-CRM114-Status: GOOD ( 11.67 ) 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 Currently, only X86_64 requires that at least 256M low memory be reserved. X86_32 does not have this requirement. So move all the code related to reserve_crashkernel_low() into macro CONFIG_X86_64. Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index acf2f2eedfe3415..d9080bfa131a654 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -392,9 +392,9 @@ static void __init memblock_x86_reserve_range_setup_data(void) #ifdef CONFIG_KEXEC_CORE +#ifdef CONFIG_X86_64 static int __init reserve_crashkernel_low(void) { -#ifdef CONFIG_X86_64 unsigned long long base, low_base = 0, low_size = 0; unsigned long low_mem_limit; int ret; @@ -434,9 +434,10 @@ static int __init reserve_crashkernel_low(void) crashk_low_res.start = low_base; crashk_low_res.end = low_base + low_size - 1; -#endif + return 0; } +#endif static void __init reserve_crashkernel(void) { @@ -490,10 +491,12 @@ static void __init reserve_crashkernel(void) } } +#ifdef CONFIG_X86_64 if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { memblock_phys_free(crash_base, crash_size); return; } +#endif pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", (unsigned long)(crash_size >> 20), From patchwork Wed Dec 22 13:08:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697089 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 061D9C433F5 for ; Wed, 22 Dec 2021 13:15:13 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=g7NtpkIjGhkd7Q99Veu7udYaspcDIQ7M+gcTsXAhldQ=; b=n7rk/L0FU0p0+K JsoASG0BmqAZD4/I+TXUSEnDflfyaQWEFuKT3dHxY8386Bflr3NdEXv3BEuZ8jqJgycg92MwYNt1+ TwlA9KuB4sVpli0WT9qPCAvqgRalSnvl/d8LzhsZbUsAk7Yvi9LkOQESAUHq4B9cJawkHk1DDvABc ynuc6TOw03dLLgEdke3eQZSn5BADDtB58bC3JEMpaYZ88FYwEF6LJlr/AQ+rZZml7ATVgd1ma1wdp eGirda1BPAcpcn1CHQjRDGibCE26b8bd6hEL3Gdtu/4MlGF2e68jB6oqR9ATlvBSlcpgxNRzG2UuN UzJyoiXJvAJ9VHrjGYbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01R8-00AQ2G-2x; Wed, 22 Dec 2021 13:13:42 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pt-00APAg-Ks; Wed, 22 Dec 2021 13:12:27 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JJtxw0zbpz91s6; Wed, 22 Dec 2021 21:11:32 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:22 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:21 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 04/17] x86/setup: Add helper parse_crashkernel_in_order() Date: Wed, 22 Dec 2021 21:08:07 +0800 Message-ID: <20211222130820.1754-5-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051226_165965_90595E58 X-CRM114-Status: GOOD ( 14.32 ) 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 Currently, there are two possible combinations of configurations. (1) crashkernel=X[@offset] (2) crashkernel=X,high, with or without crashkernel=X,low (1) has the highest priority, if it is configured correctly, (2) will be ignored. Similarly, in combination (2), crashkernel=X,low is valid only when crashkernel=X,high is valid. Putting the operations of parsing all "crashkernel=" configurations in one function helps to sort out the strong dependency. So add helper parse_crashkernel_in_order(). The "__maybe_unused" will be removed in the next patch. Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index d9080bfa131a654..f997074d36f2484 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -439,6 +439,57 @@ static int __init reserve_crashkernel_low(void) } #endif +#define CRASHKERNEL_MEM_NONE 0x0 /* crashkernel= is not exist or invalid */ +#define CRASHKERNEL_MEM_CLASSIC 0x1 /* crashkernel=X[@offset] is valid */ +#define CRASHKERNEL_MEM_HIGH 0x2 /* crashkernel=X,high is valid */ +#define CRASHKERNEL_MEM_LOW 0x4 /* crashkernel=X,low is valid */ + +/** + * parse_crashkernel_in_order - Parse all "crashkernel=" configurations in + * priority order until a valid combination is found. + * @cmdline: The bootup command line. + * @system_ram: Total system memory size. + * @crash_size: Save the memory size specified by "crashkernel=X[@offset]" or + * "crashkernel=X,high". + * @crash_base: Save the base address specified by "crashkernel=X@offset" + * @low_size: Save the memory size specified by "crashkernel=X,low" + * + * Returns the status flag of the parsing result of "crashkernel=", such as + * CRASHKERNEL_MEM_NONE, CRASHKERNEL_MEM_HIGH. + */ +__maybe_unused +static int __init parse_crashkernel_in_order(char *cmdline, + unsigned long long system_ram, + unsigned long long *crash_size, + unsigned long long *crash_base, + unsigned long long *low_size) +{ + int ret, flag = CRASHKERNEL_MEM_NONE; + + BUG_ON(!crash_size || !crash_base || !low_size); + + /* crashkernel=X[@offset] */ + ret = parse_crashkernel(cmdline, system_ram, crash_size, crash_base); + if (!ret && crash_size > 0) + return CRASHKERNEL_MEM_CLASSIC; + +#ifdef CONFIG_X86_64 + /* crashkernel=X,high */ + ret = parse_crashkernel_high(cmdline, system_ram, crash_size, crash_base); + if (ret || crash_size <= 0) + return CRASHKERNEL_MEM_NONE; + + flag = CRASHKERNEL_MEM_HIGH; + + /* crashkernel=Y,low */ + ret = parse_crashkernel_low(cmdline, system_ram, low_size, crash_base); + if (!ret) + flag |= CRASHKERNEL_MEM_LOW; +#endif + + return flag; +} + static void __init reserve_crashkernel(void) { unsigned long long crash_size, crash_base, total_mem; From patchwork Wed Dec 22 13:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697092 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 2A5A6C433EF for ; Wed, 22 Dec 2021 13:16:42 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=dJ9VqvxSLt+uufscIh6y1FRm/jmad5iCKK4OQiARlKo=; b=01FZ44OyWyoiAu dXdYG50Hj7zC4XFtTi+vFH++gaqSc79VQ98bxEHuPivapOt14caNFa41nci+rjn1Xc8ztHJNwzorE HeL7DSUhOydave2qcZlmVvWU2m6ahALUEWbIGovfIhZjIzxf9hj9cmQ2bICkXrKgteJXEF0MOQpfl SJch4VY4oCo2CY011MVWURYjRmyLut9VXaDXvJp6aQSYJGygGyxAl6UCIMVerf1f3e9c1NHZEnEy3 h7D1P2t6eEeM5BUkh0tiZxCxbceJNpDg9xd/BZOmeINXzCsC7BzD7CXLakREzo/WWY7pmGdBtj1uS JvwaRaD0twIahud18P5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Sf-00AQqc-Av; Wed, 22 Dec 2021 13:15:17 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pu-00APBz-Jo; Wed, 22 Dec 2021 13:12:29 +0000 Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JJtwC0WRgz8vyV; Wed, 22 Dec 2021 21:10:03 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:23 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:22 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 05/17] x86/setup: Use parse_crashkernel_in_order() to make code logic clear Date: Wed, 22 Dec 2021 21:08:08 +0800 Message-ID: <20211222130820.1754-6-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051227_168868_241D6120 X-CRM114-Status: GOOD ( 18.13 ) 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 Currently, the parsing of "crashkernel=X,high" and the parsing of "crashkernel=X,low" are not in the same function, but they are strongly dependent, which affects readability. Use parse_crashkernel_in_order() to bring them together. In addition, the operation to ensure at least 256M low memory is moved out of reserve_craskernel_low() so that it only needs to focus on low memory allocation. Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 69 ++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index f997074d36f2484..07a58313db5c5f7 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -393,32 +393,16 @@ static void __init memblock_x86_reserve_range_setup_data(void) #ifdef CONFIG_KEXEC_CORE #ifdef CONFIG_X86_64 -static int __init reserve_crashkernel_low(void) +static int __init reserve_crashkernel_low(unsigned long long low_size) { - unsigned long long base, low_base = 0, low_size = 0; + unsigned long long low_base = 0; unsigned long low_mem_limit; - int ret; low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); - /* crashkernel=Y,low */ - ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base); - if (ret) { - /* - * two parts from kernel/dma/swiotlb.c: - * -swiotlb size: user-specified with swiotlb= or default. - * - * -swiotlb overflow buffer: now hardcoded to 32k. We round it - * to 8M for other buffers that may need to stay low too. Also - * make sure we allocate enough extra low memory so that we - * don't run out of DMA buffers for 32-bit devices. - */ - low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); - } else { - /* passed with crashkernel=0,low ? */ - if (!low_size) - return 0; - } + /* passed with crashkernel=0,low ? */ + if (!low_size) + return 0; low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); if (!low_base) { @@ -457,7 +441,6 @@ static int __init reserve_crashkernel_low(void) * Returns the status flag of the parsing result of "crashkernel=", such as * CRASHKERNEL_MEM_NONE, CRASHKERNEL_MEM_HIGH. */ -__maybe_unused static int __init parse_crashkernel_in_order(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, @@ -492,22 +475,15 @@ static int __init parse_crashkernel_in_order(char *cmdline, static void __init reserve_crashkernel(void) { - unsigned long long crash_size, crash_base, total_mem; - bool high = false; - int ret; + unsigned long long crash_size, crash_base, total_mem, low_size; + int flag; total_mem = memblock_phys_mem_size(); - /* crashkernel=XM */ - ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); - if (ret != 0 || crash_size <= 0) { - /* crashkernel=X,high */ - ret = parse_crashkernel_high(boot_command_line, total_mem, - &crash_size, &crash_base); - if (ret != 0 || crash_size <= 0) - return; - high = true; - } + flag = parse_crashkernel_in_order(boot_command_line, total_mem, + &crash_size, &crash_base, &low_size); + if (flag == CRASHKERNEL_MEM_NONE) + return; /* 0 means: find the address automatically */ if (!crash_base) { @@ -519,7 +495,7 @@ static void __init reserve_crashkernel(void) * So try low memory first and fall back to high memory * unless "crashkernel=size[KMG],high" is specified. */ - if (!high) + if (!(flag & CRASHKERNEL_MEM_HIGH)) crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, CRASH_ALIGN, CRASH_ADDR_LOW_MAX); @@ -543,9 +519,24 @@ static void __init reserve_crashkernel(void) } #ifdef CONFIG_X86_64 - if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { - memblock_phys_free(crash_base, crash_size); - return; + if (crash_base >= (1ULL << 32)) { + if (!(flag & CRASHKERNEL_MEM_LOW)) { + /* + * two parts from kernel/dma/swiotlb.c: + * -swiotlb size: user-specified with swiotlb= or default. + * + * -swiotlb overflow buffer: now hardcoded to 32k. We round it + * to 8M for other buffers that may need to stay low too. Also + * make sure we allocate enough extra low memory so that we + * don't run out of DMA buffers for 32-bit devices. + */ + low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); + } + + if (reserve_crashkernel_low(low_size)) { + memblock_phys_free(crash_base, crash_size); + return; + } } #endif From patchwork Wed Dec 22 13:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697091 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 41DC0C433EF for ; Wed, 22 Dec 2021 13:16:21 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=nenV/Ke3NVLBP6DX5RYqmEfKVc9BoZ9IAGMvvoioHSM=; b=23jnkbMBCS2cuB ktGHaj5Y1FL05gLktx14w6Uq9w6FbyFefhPc/JTYyau1/Rp1tdtWT0lLagfrG13V8wQjTpFnNuoZA y2RccIBglXkztiEFL2LzUPLPd24vAI5YLION7pkFmz77n9ck9RIlT9FMqSgz2dXROiBjCH29hIW0h 6yweInwELOBYOoeCtVVdCGF0GyoXnwZMZl//FTrSoCSE6aPHgYg8RyEM5GNoMd9LUYsw7N88MJjvi 3UKL5qe8+UzySqUbZSxOLTJdf0KjInsUBjwkWmnsB4Czo7Flhiw4nMFOREHutDa3e9rtAn1BarNIj uLuYdl9d/gRiQFkV356Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01SC-00AQbU-LK; Wed, 22 Dec 2021 13:14:48 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pu-00APDK-D1; Wed, 22 Dec 2021 13:12:28 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtyT3TtlzcbyR; Wed, 22 Dec 2021 21:12:01 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:24 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:23 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 06/17] x86/setup: Update comments in reserve_crashkernel() Date: Wed, 22 Dec 2021 21:08:09 +0800 Message-ID: <20211222130820.1754-7-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051226_820947_4E327D4A X-CRM114-Status: GOOD ( 14.83 ) 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 Add comments to describe which bootup parameters are processed by the code, and make comments close to the code being commented. Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 07a58313db5c5f7..52aa925877ca787 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -485,20 +485,20 @@ static void __init reserve_crashkernel(void) if (flag == CRASHKERNEL_MEM_NONE) return; - /* 0 means: find the address automatically */ if (!crash_base) { /* - * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, - * crashkernel=x,high reserves memory over 4G, also allocates - * 256M extra low memory for DMA buffers and swiotlb. - * But the extra memory is not required for all machines. - * So try low memory first and fall back to high memory - * unless "crashkernel=size[KMG],high" is specified. + * For the case of crashkernel=X[@offset] and offset is omitted, + * try the low memory first. */ if (!(flag & CRASHKERNEL_MEM_HIGH)) crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, CRASH_ALIGN, CRASH_ADDR_LOW_MAX); + + /* + * If low memory allocation failed above, or for the case of + * crashkernel=X,high, try the high memory. + */ if (!crash_base) crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, CRASH_ALIGN, @@ -510,6 +510,10 @@ static void __init reserve_crashkernel(void) } else { unsigned long long start; + /* + * The case of crashkernel=X@offset and offset is specified. + * Only user-specified space can be reserved. + */ start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, crash_base + crash_size); if (start != crash_base) { @@ -520,6 +524,10 @@ static void __init reserve_crashkernel(void) #ifdef CONFIG_X86_64 if (crash_base >= (1ULL << 32)) { + /* + * Ensure that at least 256M extra low memory is allocated for + * DMA buffers and swiotlb, if low memory size is not specified. + */ if (!(flag & CRASHKERNEL_MEM_LOW)) { /* * two parts from kernel/dma/swiotlb.c: From patchwork Wed Dec 22 13:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697096 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 A6750C433F5 for ; Wed, 22 Dec 2021 13:18:49 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=+eiTwzX//JWqgSVFcwQt2Mv1LoYXZ769nQqtu0N6osE=; b=x0XFoL9k6Si9mQ 9AuJjuDTfew/++l/myu5CtB9Mzvb+E8CoKyXEanKYQl0tZ0PqcrxyEO0fMWPtgema0KSB8nBdhd8c peTfk0JgwtYsrXRh5MDLycgxSi8EAbY5vI8gJZm1u+9N1OkaMnjLUP6AGVfRz933OHz0Tt0QZveh4 icZweRHox42qDaGz+7roGYBOQ4VOGMtFikrK40IdRRFPENRQCc8mbh3tE8aYYb6fkQirpoy2a/kyq E+ynj4raSST8tWNkngqbXOiw77dPNeOaKU8tsbqOngdruF6m2i0u4J3pxkfEt+HaBzTm/KK7kd83z z1gKkFV0IFWgIdd7Ruag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Ue-00ARyA-2N; Wed, 22 Dec 2021 13:17:20 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Py-00API6-Vn; Wed, 22 Dec 2021 13:12:34 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtyY65N5zcbxj; Wed, 22 Dec 2021 21:12:05 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:25 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:24 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 07/17] x86/setup: Eliminate a magic number in reserve_crashkernel() Date: Wed, 22 Dec 2021 21:08:10 +0800 Message-ID: <20211222130820.1754-8-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051231_272022_E8102D41 X-CRM114-Status: GOOD ( 12.09 ) 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 From: Chen Zhou Replace '(1ULL << 32)' with CRASH_ADDR_LOW_MAX to improve readability, they are equal. Signed-off-by: Chen Zhou Signed-off-by: Zhen Lei --- arch/x86/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 52aa925877ca787..abff57ffbe92884 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -523,7 +523,7 @@ static void __init reserve_crashkernel(void) } #ifdef CONFIG_X86_64 - if (crash_base >= (1ULL << 32)) { + if (crash_base >= CRASH_ADDR_LOW_MAX) { /* * Ensure that at least 256M extra low memory is allocated for * DMA buffers and swiotlb, if low memory size is not specified. From patchwork Wed Dec 22 13:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697093 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 33BEDC433EF for ; Wed, 22 Dec 2021 13:17:10 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=oUpGY38D5iQl07OGFpPT4Zq/cAfXmeUGNd+CK23+6PY=; b=XZHXk6f41WDUTP kd814VX26sninkpsMgmsh3kqRwraV5fIXeh/EmtmKPxoQ8fStQo4o27ppJb4ON9QZMaztSAODZiBg TmD1fj6QXLyCAoPdVvd1MUozgHrcRLBcdU1sCU08a551cPi4shwi9WUi5F3h3dkD6dgzhDzymDo4s XNW6pctRo+8npZimaZQWaHeHO5tuSrC1bMvwBFPLyPJXiaHK5jinTKVcEDvwSbC61ewb3J2sYHAp3 SJBQWFaMekjD67hCh7afg/AcItFyugVy56Qmc9RK2EZgVl0XKoFMIeOjIK2ngV2lC6Qraec5TPH9f 6b6JHCa4iJxgYRMdLUpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01T3-00AR3h-CK; Wed, 22 Dec 2021 13:15:42 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pw-00APG5-EH; Wed, 22 Dec 2021 13:12:30 +0000 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtvK3JFvzZddm; Wed, 22 Dec 2021 21:09:17 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:26 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:25 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 08/17] x86/setup: Add build option ARCH_WANT_RESERVE_CRASH_KERNEL Date: Wed, 22 Dec 2021 21:08:11 +0800 Message-ID: <20211222130820.1754-9-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051228_908305_AC5554A8 X-CRM114-Status: GOOD ( 16.25 ) 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 From: Chen Zhou There are multiple ARCHs that implement reserve_crashkernel(), all of them are marked as static. Currently, we want to combine the implementations on x86 and arm64 into one, and move it to public crash_core.c. To avoid symbol conflicts on other platforms, add a new build option ARCH_WANT_RESERVE_CRASH_KERNEL. And change CONFIG_X86_64 to CONFIG_64BIT, so it can be shared with arm64, or other users in future. Signed-off-by: Chen Zhou Co-developed-by: Zhen Lei Signed-off-by: Zhen Lei --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 2 ++ arch/x86/kernel/setup.c | 10 +++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index d3c4ab249e9c275..f53dd7852290b9a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -11,6 +11,9 @@ source "arch/$(SRCARCH)/Kconfig" menu "General architecture-dependent options" +config ARCH_WANT_RESERVE_CRASH_KERNEL + bool + config CRASH_CORE bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 5c2ccb85f2efb86..bd78ed8193079b9 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -12,6 +12,7 @@ config X86_32 depends on !64BIT # Options that are inherently 32-bit kernel only: select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_WANT_RESERVE_CRASH_KERNEL if KEXEC_CORE select CLKSRC_I8253 select CLONE_BACKWARDS select GENERIC_VDSO_32 @@ -28,6 +29,7 @@ config X86_64 select ARCH_HAS_GIGANTIC_PAGE select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_WANT_RESERVE_CRASH_KERNEL if KEXEC_CORE select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index abff57ffbe92884..beb73cce4b8b826 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -390,9 +390,9 @@ static void __init memblock_x86_reserve_range_setup_data(void) * --------- Crashkernel reservation ------------------------------ */ -#ifdef CONFIG_KEXEC_CORE +#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL -#ifdef CONFIG_X86_64 +#ifdef CONFIG_64BIT static int __init reserve_crashkernel_low(unsigned long long low_size) { unsigned long long low_base = 0; @@ -456,7 +456,7 @@ static int __init parse_crashkernel_in_order(char *cmdline, if (!ret && crash_size > 0) return CRASHKERNEL_MEM_CLASSIC; -#ifdef CONFIG_X86_64 +#ifdef CONFIG_64BIT /* crashkernel=X,high */ ret = parse_crashkernel_high(cmdline, system_ram, crash_size, crash_base); if (ret || crash_size <= 0) @@ -522,7 +522,7 @@ static void __init reserve_crashkernel(void) } } -#ifdef CONFIG_X86_64 +#ifdef CONFIG_64BIT if (crash_base >= CRASH_ADDR_LOW_MAX) { /* * Ensure that at least 256M extra low memory is allocated for @@ -556,7 +556,7 @@ static void __init reserve_crashkernel(void) crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; } -#endif +#endif /* CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL */ static struct resource standard_io_resources[] = { { .name = "dma1", .start = 0x00, .end = 0x1f, From patchwork Wed Dec 22 13:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697094 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 D2E12C433EF for ; Wed, 22 Dec 2021 13:17:49 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=K65BEkvAScUEVJ4eHXEg2m2m/xeJJumQ9h5ExjrkhyU=; b=YXDoNHDVocttCI TGkO2OZWjtllzkRwYLcw3+qbj0EHwR/nviv7fLZvfBf0wT2571nGBx+m2OX1OTnjsOnpV2isa0Q48 hrNEm3j7TpH5YNaeBgav1ZCx0Ebo4b0/gTK5TQAW5gAknbeVTTXxtV2ohNeaugtlAQCwh8lNFLURf zUxWC+OcrNHMOlBCLy5RpDgV9lifvH7HyXf1gcQL7lQMjG/YIrHXIMMKJPh+6FrgKPGGt7vMwLqFw 4FRPmeLWXgX4o6x4BsgsgCu/yasxVa5zyBZ3SzYrNKk/IJGdUMdpw7CA3LTDut2wOb6lFcgluMNxS 0BGYoFuShg6oANNlbXMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Tb-00ARMj-Kn; Wed, 22 Dec 2021 13:16:15 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Px-00APGW-IT; Wed, 22 Dec 2021 13:12:33 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JJtwH11Czz8vxr; Wed, 22 Dec 2021 21:10:07 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:27 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:26 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 09/17] x86/setup: Move reserve_crashkernel[_low]() into crash_core.c Date: Wed, 22 Dec 2021 21:08:12 +0800 Message-ID: <20211222130820.1754-10-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051230_021577_33645734 X-CRM114-Status: GOOD ( 23.83 ) 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 From: Chen Zhou Make the functions reserve_crashkernel[_low]() as generic. Since reserve_crashkernel[_low]() implementations are quite similar on other architectures as well, we can have more users of this later. Signed-off-by: Chen Zhou Co-developed-by: Zhen Lei Signed-off-by: Zhen Lei --- arch/x86/include/asm/kexec.h | 4 + arch/x86/kernel/setup.c | 172 ---------------------------------- kernel/crash_core.c | 176 ++++++++++++++++++++++++++++++++++- 3 files changed, 179 insertions(+), 173 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index a0223a6c0238a15..21fd1f2796e1057 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -216,6 +216,10 @@ typedef void crash_vmclear_fn(void); extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss; extern void kdump_nmi_shootdown_cpus(void); +#ifdef CONFIG_KEXEC_CORE +extern void __init reserve_crashkernel(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_KEXEC_H */ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index beb73cce4b8b826..ba56e410f01811d 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -386,178 +386,6 @@ static void __init memblock_x86_reserve_range_setup_data(void) } } -/* - * --------- Crashkernel reservation ------------------------------ - */ - -#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL - -#ifdef CONFIG_64BIT -static int __init reserve_crashkernel_low(unsigned long long low_size) -{ - unsigned long long low_base = 0; - unsigned long low_mem_limit; - - low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); - - /* passed with crashkernel=0,low ? */ - if (!low_size) - return 0; - - low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); - if (!low_base) { - pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", - (unsigned long)(low_size >> 20)); - return -ENOMEM; - } - - pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", - (unsigned long)(low_size >> 20), - (unsigned long)(low_base >> 20), - (unsigned long)(low_mem_limit >> 20)); - - crashk_low_res.start = low_base; - crashk_low_res.end = low_base + low_size - 1; - - return 0; -} -#endif - -#define CRASHKERNEL_MEM_NONE 0x0 /* crashkernel= is not exist or invalid */ -#define CRASHKERNEL_MEM_CLASSIC 0x1 /* crashkernel=X[@offset] is valid */ -#define CRASHKERNEL_MEM_HIGH 0x2 /* crashkernel=X,high is valid */ -#define CRASHKERNEL_MEM_LOW 0x4 /* crashkernel=X,low is valid */ - -/** - * parse_crashkernel_in_order - Parse all "crashkernel=" configurations in - * priority order until a valid combination is found. - * @cmdline: The bootup command line. - * @system_ram: Total system memory size. - * @crash_size: Save the memory size specified by "crashkernel=X[@offset]" or - * "crashkernel=X,high". - * @crash_base: Save the base address specified by "crashkernel=X@offset" - * @low_size: Save the memory size specified by "crashkernel=X,low" - * - * Returns the status flag of the parsing result of "crashkernel=", such as - * CRASHKERNEL_MEM_NONE, CRASHKERNEL_MEM_HIGH. - */ -static int __init parse_crashkernel_in_order(char *cmdline, - unsigned long long system_ram, - unsigned long long *crash_size, - unsigned long long *crash_base, - unsigned long long *low_size) -{ - int ret, flag = CRASHKERNEL_MEM_NONE; - - BUG_ON(!crash_size || !crash_base || !low_size); - - /* crashkernel=X[@offset] */ - ret = parse_crashkernel(cmdline, system_ram, crash_size, crash_base); - if (!ret && crash_size > 0) - return CRASHKERNEL_MEM_CLASSIC; - -#ifdef CONFIG_64BIT - /* crashkernel=X,high */ - ret = parse_crashkernel_high(cmdline, system_ram, crash_size, crash_base); - if (ret || crash_size <= 0) - return CRASHKERNEL_MEM_NONE; - - flag = CRASHKERNEL_MEM_HIGH; - - /* crashkernel=Y,low */ - ret = parse_crashkernel_low(cmdline, system_ram, low_size, crash_base); - if (!ret) - flag |= CRASHKERNEL_MEM_LOW; -#endif - - return flag; -} - -static void __init reserve_crashkernel(void) -{ - unsigned long long crash_size, crash_base, total_mem, low_size; - int flag; - - total_mem = memblock_phys_mem_size(); - - flag = parse_crashkernel_in_order(boot_command_line, total_mem, - &crash_size, &crash_base, &low_size); - if (flag == CRASHKERNEL_MEM_NONE) - return; - - if (!crash_base) { - /* - * For the case of crashkernel=X[@offset] and offset is omitted, - * try the low memory first. - */ - if (!(flag & CRASHKERNEL_MEM_HIGH)) - crash_base = memblock_phys_alloc_range(crash_size, - CRASH_ALIGN, CRASH_ALIGN, - CRASH_ADDR_LOW_MAX); - - /* - * If low memory allocation failed above, or for the case of - * crashkernel=X,high, try the high memory. - */ - if (!crash_base) - crash_base = memblock_phys_alloc_range(crash_size, - CRASH_ALIGN, CRASH_ALIGN, - CRASH_ADDR_HIGH_MAX); - if (!crash_base) { - pr_info("crashkernel reservation failed - No suitable area found.\n"); - return; - } - } else { - unsigned long long start; - - /* - * The case of crashkernel=X@offset and offset is specified. - * Only user-specified space can be reserved. - */ - start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, - crash_base + crash_size); - if (start != crash_base) { - pr_info("crashkernel reservation failed - memory is in use.\n"); - return; - } - } - -#ifdef CONFIG_64BIT - if (crash_base >= CRASH_ADDR_LOW_MAX) { - /* - * Ensure that at least 256M extra low memory is allocated for - * DMA buffers and swiotlb, if low memory size is not specified. - */ - if (!(flag & CRASHKERNEL_MEM_LOW)) { - /* - * two parts from kernel/dma/swiotlb.c: - * -swiotlb size: user-specified with swiotlb= or default. - * - * -swiotlb overflow buffer: now hardcoded to 32k. We round it - * to 8M for other buffers that may need to stay low too. Also - * make sure we allocate enough extra low memory so that we - * don't run out of DMA buffers for 32-bit devices. - */ - low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); - } - - if (reserve_crashkernel_low(low_size)) { - memblock_phys_free(crash_base, crash_size); - return; - } - } -#endif - - pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", - (unsigned long)(crash_size >> 20), - (unsigned long)(crash_base >> 20), - (unsigned long)(total_mem >> 20)); - - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size - 1; -} -#endif /* CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL */ - static struct resource standard_io_resources[] = { { .name = "dma1", .start = 0x00, .end = 0x1f, .flags = IORESOURCE_BUSY | IORESOURCE_IO }, diff --git a/kernel/crash_core.c b/kernel/crash_core.c index eb53f5ec62c900f..64ed082382f3f18 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -5,9 +5,11 @@ */ #include -#include +#include #include #include +#include +#include #include #include @@ -295,6 +297,178 @@ int __init parse_crashkernel_low(char *cmdline, "crashkernel=", suffix_tbl[SUFFIX_LOW]); } +/* + * --------- Crashkernel reservation ------------------------------ + */ + +#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL + +#ifdef CONFIG_64BIT +static int __init reserve_crashkernel_low(unsigned long long low_size) +{ + unsigned long long low_base = 0; + unsigned long low_mem_limit; + + low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); + + /* passed with crashkernel=0,low ? */ + if (!low_size) + return 0; + + low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); + if (!low_base) { + pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", + (unsigned long)(low_size >> 20)); + return -ENOMEM; + } + + pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", + (unsigned long)(low_size >> 20), + (unsigned long)(low_base >> 20), + (unsigned long)(low_mem_limit >> 20)); + + crashk_low_res.start = low_base; + crashk_low_res.end = low_base + low_size - 1; + + return 0; +} +#endif + +#define CRASHKERNEL_MEM_NONE 0x0 /* crashkernel= is not exist or invalid */ +#define CRASHKERNEL_MEM_CLASSIC 0x1 /* crashkernel=X[@offset] is valid */ +#define CRASHKERNEL_MEM_HIGH 0x2 /* crashkernel=X,high is valid */ +#define CRASHKERNEL_MEM_LOW 0x4 /* crashkernel=X,low is valid */ + +/** + * parse_crashkernel_in_order - Parse all "crashkernel=" configurations in + * priority order until a valid combination is found. + * @cmdline: The bootup command line. + * @system_ram: Total system memory size. + * @crash_size: Save the memory size specified by "crashkernel=X[@offset]" or + * "crashkernel=X,high". + * @crash_base: Save the base address specified by "crashkernel=X@offset" + * @low_size: Save the memory size specified by "crashkernel=X,low" + * + * Returns the status flag of the parsing result of "crashkernel=", such as + * CRASHKERNEL_MEM_NONE, CRASHKERNEL_MEM_HIGH. + */ +static int __init parse_crashkernel_in_order(char *cmdline, + unsigned long long system_ram, + unsigned long long *crash_size, + unsigned long long *crash_base, + unsigned long long *low_size) +{ + int ret, flag = CRASHKERNEL_MEM_NONE; + + BUG_ON(!crash_size || !crash_base || !low_size); + + /* crashkernel=X[@offset] */ + ret = parse_crashkernel(cmdline, system_ram, crash_size, crash_base); + if (!ret && crash_size > 0) + return CRASHKERNEL_MEM_CLASSIC; + +#ifdef CONFIG_64BIT + /* crashkernel=X,high */ + ret = parse_crashkernel_high(cmdline, system_ram, crash_size, crash_base); + if (ret || crash_size <= 0) + return CRASHKERNEL_MEM_NONE; + + flag = CRASHKERNEL_MEM_HIGH; + + /* crashkernel=Y,low */ + ret = parse_crashkernel_low(cmdline, system_ram, low_size, crash_base); + if (!ret) + flag |= CRASHKERNEL_MEM_LOW; +#endif + + return flag; +} + +void __init reserve_crashkernel(void) +{ + unsigned long long crash_size, crash_base, total_mem, low_size; + int flag; + + total_mem = memblock_phys_mem_size(); + + flag = parse_crashkernel_in_order(boot_command_line, total_mem, + &crash_size, &crash_base, &low_size); + if (flag == CRASHKERNEL_MEM_NONE) + return; + + if (!crash_base) { + /* + * For the case of crashkernel=X[@offset] and offset is omitted, + * try the low memory first. + */ + if (!(flag & CRASHKERNEL_MEM_HIGH)) + crash_base = memblock_phys_alloc_range(crash_size, + CRASH_ALIGN, CRASH_ALIGN, + CRASH_ADDR_LOW_MAX); + + /* + * If low memory allocation failed above, or for the case of + * crashkernel=X,high, try the high memory. + */ + if (!crash_base) + crash_base = memblock_phys_alloc_range(crash_size, + CRASH_ALIGN, CRASH_ALIGN, + CRASH_ADDR_HIGH_MAX); + if (!crash_base) { + pr_info("crashkernel reservation failed - No suitable area found.\n"); + return; + } + } else { + unsigned long long start; + + /* + * The case of crashkernel=X@offset and offset is specified. + * Only user-specified space can be reserved. + */ + start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, + crash_base + crash_size); + if (start != crash_base) { + pr_info("crashkernel reservation failed - memory is in use.\n"); + return; + } + } + +#ifdef CONFIG_64BIT + if (crash_base >= CRASH_ADDR_LOW_MAX) { + /* + * Ensure that at least 256M extra low memory is allocated for + * DMA buffers and swiotlb, if low memory size is not specified. + */ + if (!(flag & CRASHKERNEL_MEM_LOW)) { + /* + * two parts from kernel/dma/swiotlb.c: + * -swiotlb size: user-specified with swiotlb= or default. + * + * -swiotlb overflow buffer: now hardcoded to 32k. We round it + * to 8M for other buffers that may need to stay low too. Also + * make sure we allocate enough extra low memory so that we + * don't run out of DMA buffers for 32-bit devices. + */ + low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); + } + + if (reserve_crashkernel_low(low_size)) { + memblock_phys_free(crash_base, crash_size); + return; + } + } +#endif + + pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", + (unsigned long)(crash_size >> 20), + (unsigned long)(crash_base >> 20), + (unsigned long)(total_mem >> 20)); + + crashk_res.start = crash_base; + crashk_res.end = crash_base + crash_size - 1; +} +#endif /* CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL */ + Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len) { From patchwork Wed Dec 22 13:08:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697095 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 F0280C433EF for ; Wed, 22 Dec 2021 13:18:14 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=lTZiG8qQw4xSCjRfvGlKDE2o5t3uiyZU6Lau3SfObt8=; b=zlaVi41D1CiJ8o zudPn7uspQrd6f4ODEgU3LetZP7/hTYprJQNfMd0j6mz+A/hyygqGrowW8k6Y25M4KbFhJPyg5tQW shBANxEXcB7YsdOzmSZpq+dJHaW1zmLARP2B96L0cS18c+U7Yl+MhoMM7PTPCZuqd9g00mQnv6Ihy Nfmj+bMyIKis1bdY3G0aevhHvjEpfqVMNrpjJ/+bORDWVMHwlskZv/HbiS0qhc9NDVgbhs3PS8j+5 Rwd+eHPMscsK5otwfZAYm4CNLZMfv4mcMYdO/2fh860U8QLRMh5M2chwYIL4NnKVvsVcFzAHzoive 6xEHaQJme6Ax0t1E4cjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01U5-00ARe2-T6; Wed, 22 Dec 2021 13:16:46 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Py-00APHf-Is; Wed, 22 Dec 2021 13:12:33 +0000 Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtvM4003zZdj9; Wed, 22 Dec 2021 21:09:19 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:28 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:27 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 10/17] kdump: Simplify the parameters of __parse_crashkernel() Date: Wed, 22 Dec 2021 21:08:13 +0800 Message-ID: <20211222130820.1754-11-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051231_039550_EC66AF5E X-CRM114-Status: GOOD ( 12.99 ) 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 After commit adbc742bf786 ("x86, kdump: Change crashkernel_high/low= to crashkernel=,high/low"), all kdump bootup parameters start with "crashkernel=". Therefore, it is better for __parse_crashkernel() to use it directly than for the caller to pass it. So the parameter 'name' can be omitted. Similarly, we can pass the suffix type instead of the suffix name to avoid the global variable 'suffix_tbl' appearing in multiple places. There is no change in functionality, but it makes the code look a little more concise. Signed-off-by: Zhen Lei --- kernel/crash_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 64ed082382f3f18..496dae2718cf026 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -233,11 +233,12 @@ static int __init __parse_crashkernel(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base, - const char *name, - const char *suffix) + int suffix_type) { char *first_colon, *first_space; char *ck_cmdline; + const char *name = "crashkernel="; + const char *suffix = suffix_tbl[suffix_type]; BUG_ON(!crash_size || !crash_base); *crash_size = 0; @@ -275,8 +276,7 @@ int __init parse_crashkernel(char *cmdline, unsigned long long *crash_size, unsigned long long *crash_base) { - return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, - "crashkernel=", NULL); + return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_NULL); } int __init parse_crashkernel_high(char *cmdline, @@ -284,8 +284,7 @@ int __init parse_crashkernel_high(char *cmdline, unsigned long long *crash_size, unsigned long long *crash_base) { - return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, - "crashkernel=", suffix_tbl[SUFFIX_HIGH]); + return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_HIGH); } int __init parse_crashkernel_low(char *cmdline, @@ -293,8 +292,7 @@ int __init parse_crashkernel_low(char *cmdline, unsigned long long *crash_size, unsigned long long *crash_base) { - return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, - "crashkernel=", suffix_tbl[SUFFIX_LOW]); + return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_LOW); } /* From patchwork Wed Dec 22 13:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697097 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 79D7AC433FE for ; Wed, 22 Dec 2021 13:19:48 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=W9Aa/5qRg3FFlAYSWdaqV2jSOMwDBeivcbEgYkGTXs4=; b=XwI2wbOJJnkUx9 AfhYxoQlYWDdDczbRQZjrPmjKhJ3sfOxtpsterempZ6FVdIoQ/5Bcsy9tuXmzt4xQ+HyZ2AuRZ+IP /ce8ac7Qq1kNXhTIXZPjGm+aEE3SHvlo9GwIV0DJS52GQAjbeDCC9duOIpTdoQjyfr54QU1U6qZbS 5JFm14SQVfBYiasd/zoQIcF4JeiIWiJ98lDQQ10exQQL1SF5VhZZKljf9B8tfZ6rjQPJucdvJZvnS RqOAJoUF9OUkvWsNS+T+61OdM+nmgjpNI5RXmegYg9cRAuho0N18vAOiuWPrnYpHuvYkwTjI9lBHa UgNtX5m8i9qnmCdR3GjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01VQ-00ASMm-9y; Wed, 22 Dec 2021 13:18:08 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Pz-00APJV-PV; Wed, 22 Dec 2021 13:12:35 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JJtwK2yMTz8w1g; Wed, 22 Dec 2021 21:10:09 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:29 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:28 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 11/17] kdump: Make parse_crashkernel_{high|low} static Date: Wed, 22 Dec 2021 21:08:14 +0800 Message-ID: <20211222130820.1754-12-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051232_231723_D3EFC78E X-CRM114-Status: GOOD ( 10.13 ) 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 Currently, parse_crashkernel_{high|low} is only referenced by parse_crashkernel_in_order(), and they are in the same file. So make it static, and move it into "#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL". Signed-off-by: Zhen Lei --- include/linux/crash_core.h | 4 ---- kernel/crash_core.c | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index de62a722431e7db..529a0a783190bfe 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -79,9 +79,5 @@ void final_note(Elf_Word *buf); int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base); -int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, - unsigned long long *crash_size, unsigned long long *crash_base); -int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, - unsigned long long *crash_size, unsigned long long *crash_base); #endif /* LINUX_CRASH_CORE_H */ diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 496dae2718cf026..a037076b89a9bb2 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -279,7 +279,15 @@ int __init parse_crashkernel(char *cmdline, return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_NULL); } -int __init parse_crashkernel_high(char *cmdline, + +/* + * --------- Crashkernel reservation ------------------------------ + */ + +#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL + +#ifdef CONFIG_64BIT +static int __init parse_crashkernel_high(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base) @@ -287,7 +295,7 @@ int __init parse_crashkernel_high(char *cmdline, return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_HIGH); } -int __init parse_crashkernel_low(char *cmdline, +static int __init parse_crashkernel_low(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base) @@ -295,13 +303,6 @@ int __init parse_crashkernel_low(char *cmdline, return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_LOW); } -/* - * --------- Crashkernel reservation ------------------------------ - */ - -#ifdef CONFIG_ARCH_WANT_RESERVE_CRASH_KERNEL - -#ifdef CONFIG_64BIT static int __init reserve_crashkernel_low(unsigned long long low_size) { unsigned long long low_base = 0; From patchwork Wed Dec 22 13:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697098 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 E03D6C433EF for ; Wed, 22 Dec 2021 13:20:26 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=qJicMOnxVn3ePcBgnB61AiS+5jAKz7NzLv03PM6cPfk=; b=Fq3L4EcoIyboiR a6kFkKF7XRTGDA1vpaRY2ariRNmoKLIN6XRtT79Ax9y5pu/FFZz8ufjQgoqTIcgGFAKZoO/c68jkZ qePFXOYNOP3jQdyFAze/h/LpAQV6alf8pnoDxxdaMlcgNTQ0vva1WapqmWfMme1iTThBDlZIAiwA/ n29AHmWAHZMNiTKhty2QowSZdaV5Ufdsq+BWzMsPZqNJ/6SSl5IOa1pL7p8A6FPUp959XwNXu3ep0 S2XNm7bzJ+DOLW9Ir8eFT6s/QxswMTYsAjcuFxHF7KB5mHi2t7CCVXmdFpZZIPQhVxGxYzRsoBSYW wW3y1RGyU4eRy1aBJmxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01W7-00ASh7-MM; Wed, 22 Dec 2021 13:18:52 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Q0-00APKn-RK; Wed, 22 Dec 2021 13:12:37 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtvP5yZHzZdSQ; Wed, 22 Dec 2021 21:09:21 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:30 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:29 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 12/17] kdump: Reduce unused parameters of parse_crashkernel_{high|low} Date: Wed, 22 Dec 2021 21:08:15 +0800 Message-ID: <20211222130820.1754-13-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051233_332482_B5C72D2B X-CRM114-Status: GOOD ( 11.32 ) 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 The parameters 'system_ram' and 'crash_base' is only needed by the case of "crashkernel=X@[offset]". The argument list of parse_crashkernel_suffix() can help prove this point. Signed-off-by: Zhen Lei --- kernel/crash_core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index a037076b89a9bb2..67f5065e3c3cfcc 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -288,19 +288,19 @@ int __init parse_crashkernel(char *cmdline, #ifdef CONFIG_64BIT static int __init parse_crashkernel_high(char *cmdline, - unsigned long long system_ram, - unsigned long long *crash_size, - unsigned long long *crash_base) + unsigned long long *crash_size) { - return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_HIGH); + unsigned long long base; + + return __parse_crashkernel(cmdline, 0, crash_size, &base, SUFFIX_HIGH); } static int __init parse_crashkernel_low(char *cmdline, - unsigned long long system_ram, - unsigned long long *crash_size, - unsigned long long *crash_base) + unsigned long long *crash_size) { - return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, SUFFIX_LOW); + unsigned long long base; + + return __parse_crashkernel(cmdline, 0, crash_size, &base, SUFFIX_LOW); } static int __init reserve_crashkernel_low(unsigned long long low_size) @@ -368,14 +368,14 @@ static int __init parse_crashkernel_in_order(char *cmdline, #ifdef CONFIG_64BIT /* crashkernel=X,high */ - ret = parse_crashkernel_high(cmdline, system_ram, crash_size, crash_base); + ret = parse_crashkernel_high(cmdline, crash_size); if (ret || crash_size <= 0) return CRASHKERNEL_MEM_NONE; flag = CRASHKERNEL_MEM_HIGH; /* crashkernel=Y,low */ - ret = parse_crashkernel_low(cmdline, system_ram, low_size, crash_base); + ret = parse_crashkernel_low(cmdline, low_size); if (!ret) flag |= CRASHKERNEL_MEM_LOW; #endif From patchwork Wed Dec 22 13:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697102 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 5F94CC433EF for ; Wed, 22 Dec 2021 13:25:05 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=GNBraLTazc5npyKbWbANTJ/98NLzfvfa7tpXD0UpOf4=; b=rkcHw5QH1Gj0sW xZtsI+BFeO8HpmG/22RiaDYAarll7G4xOCSFnmHDovR1ir7dSfnwlbq3gMrFFAo3v7W14obNXTmF6 cTDFxn320krDnNtUJ9ms3VGvTDR9odwl0WxqxuNktPIDBkN7aQQT/qWRCBIc1A3P/10nzv9YS9sKx R4SPGSFuBW0h9KJ7UyRLLWUEnJ6Q7aO7k8BU5oGV577ZjINyLTi8RPim4mDz6NjkIbq/ujcSlVJ3U BjRBWakCO6KbG2lNIlHMQhC7TJX6q431Plgcb/jonuoeJmv9WIDyk0rZQB6hiMPeEg7a6z4ixe7cf 4NEjbF4iwB3c9on02TKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01aP-00AUb0-6g; Wed, 22 Dec 2021 13:23:17 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01QJ-00APb9-6f; Wed, 22 Dec 2021 13:12:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=LM3Xc9oCwdFtfUgD37BWxTuD/atilhm0ry5rNohD/1c=; b=AZG2Q+LCiWfuy2FOC9kVaglJP3 6hrhPekhrm7GlMqev2ixBfSDusPNuAHDvlCzxaZceR/bgeMzmuFDb9Iwu8BlgvavGXbf+SbAfVzc3 EzVylowxP5X6Egu+kCzzXESYcpz6wtvqsAKUZh46VYqWKFsqn+qIt3Jae2GDtQJkCIg3YUST+vTMG +jtNiyWujlF7hqnLB7Q/1m2AF67uwgZb9XFAL1gfTaY9fT7qRyqvZKECUEYk/YAJsy3MH65yt4ze3 eF1wQjdtoXMddVexM9vE1bEoDHqDS9l+/lzeq3/71xlyEqnQIONuHjWNZrvYsI6eNVukH72NZFl5V tGy6Su9A==; Received: from szxga02-in.huawei.com ([45.249.212.188]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01QF-002va3-2y; Wed, 22 Dec 2021 13:12:49 +0000 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JJty52rqVz91td; Wed, 22 Dec 2021 21:11:41 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:31 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:30 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 13/17] arm64: kdump: introduce some macros for crash kernel reservation Date: Wed, 22 Dec 2021 21:08:16 +0800 Message-ID: <20211222130820.1754-14-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_131247_999836_1964F334 X-CRM114-Status: GOOD ( 11.68 ) 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 From: Chen Zhou Introduce macro CRASH_ALIGN for alignment, macro CRASH_ADDR_LOW_MAX for upper bound of low crash memory, macro CRASH_ADDR_HIGH_MAX for upper bound of high crash memory, use macros instead. Besides, keep consistent with x86, use CRASH_ALIGN as the lower bound of crash kernel reservation. Signed-off-by: Chen Zhou Signed-off-by: Zhen Lei Tested-by: John Donnelly Tested-by: Dave Kleikamp --- arch/arm64/include/asm/kexec.h | 6 ++++++ arch/arm64/mm/init.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 9839bfc163d7147..1b9edc69f0244ca 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -25,6 +25,12 @@ #define KEXEC_ARCH KEXEC_ARCH_AARCH64 +/* 2M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_2M + +#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit +#define CRASH_ADDR_HIGH_MAX MEMBLOCK_ALLOC_ACCESSIBLE + #ifndef __ASSEMBLY__ /** diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index a8834434af99ae0..be4595dc7459115 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -75,7 +75,7 @@ phys_addr_t arm64_dma_phys_limit __ro_after_init; static void __init reserve_crashkernel(void) { unsigned long long crash_base, crash_size; - unsigned long long crash_max = arm64_dma_phys_limit; + unsigned long long crash_max = CRASH_ADDR_LOW_MAX; int ret; ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), @@ -91,7 +91,7 @@ static void __init reserve_crashkernel(void) crash_max = crash_base + crash_size; /* Current arm64 boot protocol requires 2MB alignment */ - crash_base = memblock_phys_alloc_range(crash_size, SZ_2M, + crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, crash_base, crash_max); if (!crash_base) { pr_warn("cannot allocate crashkernel (size:0x%llx)\n", From patchwork Wed Dec 22 13:08:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697099 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 5E1F3C433F5 for ; Wed, 22 Dec 2021 13:21:44 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=hXTV3dg1ZbFUoPcxF5GMyABnr1yRQQdGGxeW1arSqGo=; b=S/RzcBhgJiRNnf bmAxaM39HLeeCQstcZbz7jmvddEd9ooZc4WRBEbmDYB63mKhdYdwM+NwXhgZWGt9g+HDhiWTqTkd2 CeaNIGldbOV0I2G960D+9Rj0ZrciZULJDMRVEHet52wfZ5Dj7PE+3gVhQnzGMCZxhjcNKCPnllRIL 7srv+hA1pGZYAu/SSK7xsVJu62Yt6/Tdsjyq1zg8IvEnfR07BU6sdAEaPY5FSo/5u2ujtJTRHIpiy FuaEwxue0lZo1YhuGaNxAZfZiRJZHxWgl8iqOKW2/ihVRFeIVbFXK1ZsgGnO/aOD58XcrZd3nRW8A /voZI1EPunLWbYRXOZlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01XK-00ATGW-Uq; Wed, 22 Dec 2021 13:20:07 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Q2-00APNO-VX; Wed, 22 Dec 2021 13:12:42 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JJtvR5tZ9zZdmv; Wed, 22 Dec 2021 21:09:23 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:32 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:31 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 14/17] arm64: kdump: reimplement crashkernel=X Date: Wed, 22 Dec 2021 21:08:17 +0800 Message-ID: <20211222130820.1754-15-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051235_444673_329FD9CA X-CRM114-Status: GOOD ( 24.80 ) 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 From: Chen Zhou There are following issues in arm64 kdump: 1. We use crashkernel=X to reserve crashkernel below 4G, which will fail when there is no enough low memory. 2. If reserving crashkernel above 4G, in this case, crash dump kernel will boot failure because there is no low memory available for allocation. To solve these issues, change the behavior of crashkernel=X and introduce crashkernel=X,[high,low]. crashkernel=X tries low allocation in DMA zone, and fall back to high allocation if it fails. We can also use "crashkernel=X,high" to select a region above DMA zone, which also tries to allocate at least 256M in DMA zone automatically. "crashkernel=Y,low" can be used to allocate specified size low memory. Another minor change, there may be two regions reserved for crash dump kernel, in order to distinct from the high region and make no effect to the use of existing kexec-tools, rename the low region as "Crash kernel (low)". Signed-off-by: Chen Zhou Signed-off-by: Zhen Lei Tested-by: John Donnelly Tested-by: Dave Kleikamp --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 4 ++ arch/arm64/kernel/machine_kexec_file.c | 12 +++++- arch/arm64/kernel/setup.c | 13 +++++- arch/arm64/mm/init.c | 59 +++++--------------------- 5 files changed, 38 insertions(+), 51 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c4207cf9bb17ffb..4b99efa36da3793 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -95,6 +95,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANT_RESERVE_CRASH_KERNEL if KEXEC_CORE select ARCH_WANTS_NO_INSTR select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBA diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 1b9edc69f0244ca..3bde0079925d771 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -96,6 +96,10 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_CORE +extern void __init reserve_crashkernel(void); +#endif + #if defined(CONFIG_KEXEC_CORE) void cpu_soft_restart(unsigned long el2_switch, unsigned long entry, unsigned long arg0, unsigned long arg1, diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 59c648d51848886..889951291cc0f9c 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -65,10 +65,18 @@ static int prepare_elf_headers(void **addr, unsigned long *sz) /* Exclude crashkernel region */ ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + goto out; + + if (crashk_low_res.end) { + ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); + if (ret) + goto out; + } - if (!ret) - ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); +out: kfree(cmem); return ret; } diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index be5f85b0a24de69..4bb2e55366be64d 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -248,7 +248,18 @@ static void __init request_standard_resources(void) kernel_data.end <= res->end) request_resource(res, &kernel_data); #ifdef CONFIG_KEXEC_CORE - /* Userspace will find "Crash kernel" region in /proc/iomem. */ + /* + * Userspace will find "Crash kernel" or "Crash kernel (low)" + * region in /proc/iomem. + * In order to distinct from the high region and make no effect + * to the use of existing kexec-tools, rename the low region as + * "Crash kernel (low)". + */ + if (crashk_low_res.end && crashk_low_res.start >= res->start && + crashk_low_res.end <= res->end) { + crashk_low_res.name = "Crash kernel (low)"; + request_resource(res, &crashk_low_res); + } if (crashk_res.end && crashk_res.start >= res->start && crashk_res.end <= res->end) request_resource(res, &crashk_res); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index be4595dc7459115..85c83e4eff2b6c4 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -64,57 +65,11 @@ EXPORT_SYMBOL(memstart_addr); */ phys_addr_t arm64_dma_phys_limit __ro_after_init; -#ifdef CONFIG_KEXEC_CORE -/* - * reserve_crashkernel() - reserves memory for crash kernel - * - * This function reserves memory area given in "crashkernel=" kernel command - * line parameter. The memory reserved is used by dump capture kernel when - * primary kernel is crashing. - */ +#ifndef CONFIG_KEXEC_CORE static void __init reserve_crashkernel(void) { - unsigned long long crash_base, crash_size; - unsigned long long crash_max = CRASH_ADDR_LOW_MAX; - int ret; - - ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &crash_size, &crash_base); - /* no crashkernel= or invalid value specified */ - if (ret || !crash_size) - return; - - crash_size = PAGE_ALIGN(crash_size); - - /* User specifies base address explicitly. */ - if (crash_base) - crash_max = crash_base + crash_size; - - /* Current arm64 boot protocol requires 2MB alignment */ - crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, - crash_base, crash_max); - if (!crash_base) { - pr_warn("cannot allocate crashkernel (size:0x%llx)\n", - crash_size); - return; - } - - pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", - crash_base, crash_base + crash_size, crash_size >> 20); - - /* - * The crashkernel memory will be removed from the kernel linear - * map. Inform kmemleak so that it won't try to access it. - */ - kmemleak_ignore_phys(crash_base); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size - 1; } -#else -static void __init reserve_crashkernel(void) -{ -} -#endif /* CONFIG_KEXEC_CORE */ +#endif /* * Return the maximum physical address for a zone accessible by the given bits @@ -362,6 +317,14 @@ void __init bootmem_init(void) * reserved, so do it here. */ reserve_crashkernel(); +#ifdef CONFIG_KEXEC_CORE + /* + * The low region is intended to be used for crash dump kernel devices, + * just mark the low region as "nomap" simply. + */ + if (crashk_low_res.end) + memblock_mark_nomap(crashk_low_res.start, resource_size(&crashk_low_res)); +#endif memblock_dump_all(); } From patchwork Wed Dec 22 13:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697100 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 2417AC433EF for ; Wed, 22 Dec 2021 13:22:45 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=Uc+yaqMplGNHv/7aM13KOtjQS0FLnVADAEwRn4IQljs=; b=bvLg+b4eYutcIA h7MQcAdlul75EdE/o3A0MLahBIEpk7rtJA72C3m5MaAX8yOM7i46abY751iFk4Uo8811rgKziSoiG wjsUAe3fPtpdv15htMPI4YkOquSclSKr9G4oDLvfU3Jz7PAN+JgQqO7dvClYQpBsFM4sqAECMRSfe OZWrqgqYSoEdzhZzJx+alyTplaXXAwswObnz5qCcYv0AffiFSQQBjNv8P49/n2PoHxjnB37Rd/70J XKZ2nTDeZ0Pjumo6czGFeC7Hrk23ZeYgASb2cIzQKmakbPCoHRYTwMcL+Y/W5en4HW0LDFxfIjt7U U99O9DaGEelbp9BLL12w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01YB-00ATft-OF; Wed, 22 Dec 2021 13:21:00 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Q3-00APOb-OS; Wed, 22 Dec 2021 13:12:42 +0000 Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JJtwP2gm9z8vrd; Wed, 22 Dec 2021 21:10:13 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:33 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:32 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 15/17] of: fdt: Aggregate the processing of "linux, usable-memory-range" Date: Wed, 22 Dec 2021 21:08:18 +0800 Message-ID: <20211222130820.1754-16-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051236_200169_A7BE8F25 X-CRM114-Status: GOOD ( 12.31 ) 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 Currently, we parse the "linux,usable-memory-range" property in early_init_dt_scan_chosen(), to obtain the specified memory range of the crash kernel. We then reserve the required memory after early_init_dt_scan_memory() has identified all available physical memory. Because the two pieces of code are separated far, the readability and maintainability are reduced. So bring them together. Suggested-by: Rob Herring Signed-off-by: Zhen Lei Reviewed-by: Rob Herring Tested-by: Dave Kleikamp --- drivers/of/fdt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bdca35284cebd56..37b477a51175359 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -965,8 +965,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) elfcorehdr_addr, elfcorehdr_size); } -static phys_addr_t cap_mem_addr; -static phys_addr_t cap_mem_size; +static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND; /** * early_init_dt_check_for_usable_mem_range - Decode usable memory range @@ -977,6 +976,11 @@ static void __init early_init_dt_check_for_usable_mem_range(unsigned long node) { const __be32 *prop; int len; + phys_addr_t cap_mem_addr; + phys_addr_t cap_mem_size; + + if ((long)node < 0) + return; pr_debug("Looking for usable-memory-range property... "); @@ -989,6 +993,8 @@ static void __init early_init_dt_check_for_usable_mem_range(unsigned long node) pr_debug("cap_mem_start=%pa cap_mem_size=%pa\n", &cap_mem_addr, &cap_mem_size); + + memblock_cap_memory_range(cap_mem_addr, cap_mem_size); } #ifdef CONFIG_SERIAL_EARLYCON @@ -1137,9 +1143,10 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) return 0; + chosen_node_offset = node; + early_init_dt_check_for_initrd(node); early_init_dt_check_for_elfcorehdr(node); - early_init_dt_check_for_usable_mem_range(node); /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l); @@ -1275,7 +1282,7 @@ void __init early_init_dt_scan_nodes(void) of_scan_flat_dt(early_init_dt_scan_memory, NULL); /* Handle linux,usable-memory-range property */ - memblock_cap_memory_range(cap_mem_addr, cap_mem_size); + early_init_dt_check_for_usable_mem_range(chosen_node_offset); } bool __init early_init_dt_scan(void *params) From patchwork Wed Dec 22 13:08:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697101 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 0C357C433F5 for ; Wed, 22 Dec 2021 13:23:55 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=Q+Jc8MMCU5J3VnUnF1iRh7cDSC/7z1fmpNwHajokH1A=; b=eWj+Jz2W8PWa12 9Q8jakEA1sgSAqxXGTxa/Huk6QdLXoCuJSQDowWG9b/pVXC+t2dYAwnuzutQV++zPxbZ9Dx2cfElw yS0XqOEFbiEA663g4tdVH1g6iG1iO7+/Ad7NaIE+IWbt6bCRIdOlGoThP9YHWsTsB0KWWm3SgwYTq B/BG1NIieeqOYZxy/h/wLXzYFKem85qglBYUZ05hSGKdj8Swzbb185g89kNYUWvgmzsNX9WbXrvlv GO1S78XeCaS09e/QexCYE1iPJWC5bU//fJe5WokRbvayrqD243w1p1twiimeT9wf4MSs5AqK7O+bB n1Hw1Qy55raQ8rDKnL5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01ZL-00AU8a-Pi; Wed, 22 Dec 2021 13:22:12 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01Q4-00APPn-Ru; Wed, 22 Dec 2021 13:12:45 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JJtvV0QZBz1DK75; Wed, 22 Dec 2021 21:09:26 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:34 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:33 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 16/17] of: fdt: Add memory for devices by DT property "linux, usable-memory-range" Date: Wed, 22 Dec 2021 21:08:19 +0800 Message-ID: <20211222130820.1754-17-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_051237_345857_E83D8ADF X-CRM114-Status: GOOD ( 15.61 ) 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 From: Chen Zhou When reserving crashkernel in high memory, some low memory is reserved for crash dump kernel devices and never mapped by the first kernel. This memory range is advertised to crash dump kernel via DT property under /chosen, linux,usable-memory-range = We reused the DT property linux,usable-memory-range and made the low memory region as the second range "BASE2 SIZE2", which keeps compatibility with existing user-space and older kdump kernels. Crash dump kernel reads this property at boot time and call memblock_add() to add the low memory region after memblock_cap_memory_range() has been called. Signed-off-by: Chen Zhou Co-developed-by: Zhen Lei Signed-off-by: Zhen Lei Reviewed-by: Rob Herring Tested-by: Dave Kleikamp --- drivers/of/fdt.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 37b477a51175359..f7b72fa773250ad 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -967,6 +967,15 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND; +/* + * The main usage of linux,usable-memory-range is for crash dump kernel. + * Originally, the number of usable-memory regions is one. Now there may + * be two regions, low region and high region. + * To make compatibility with existing user-space and older kdump, the low + * region is always the last range of linux,usable-memory-range if exist. + */ +#define MAX_USABLE_RANGES 2 + /** * early_init_dt_check_for_usable_mem_range - Decode usable memory range * location from flat tree @@ -974,10 +983,9 @@ static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND; */ static void __init early_init_dt_check_for_usable_mem_range(unsigned long node) { - const __be32 *prop; - int len; - phys_addr_t cap_mem_addr; - phys_addr_t cap_mem_size; + struct memblock_region rgn[MAX_USABLE_RANGES] = {0}; + const __be32 *prop, *endp; + int len, i; if ((long)node < 0) return; @@ -985,16 +993,21 @@ static void __init early_init_dt_check_for_usable_mem_range(unsigned long node) pr_debug("Looking for usable-memory-range property... "); prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); - if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells))) + if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells))) return; - cap_mem_addr = dt_mem_next_cell(dt_root_addr_cells, &prop); - cap_mem_size = dt_mem_next_cell(dt_root_size_cells, &prop); + endp = prop + (len / sizeof(__be32)); + for (i = 0; i < MAX_USABLE_RANGES && prop < endp; i++) { + rgn[i].base = dt_mem_next_cell(dt_root_addr_cells, &prop); + rgn[i].size = dt_mem_next_cell(dt_root_size_cells, &prop); - pr_debug("cap_mem_start=%pa cap_mem_size=%pa\n", &cap_mem_addr, - &cap_mem_size); + pr_debug("cap_mem_regions[%d]: base=%pa, size=%pa\n", + i, &rgn[i].base, &rgn[i].size); + } - memblock_cap_memory_range(cap_mem_addr, cap_mem_size); + memblock_cap_memory_range(rgn[0].base, rgn[0].size); + for (i = 1; i < MAX_USABLE_RANGES && rgn[i].size; i++) + memblock_add(rgn[i].base, rgn[i].size); } #ifdef CONFIG_SERIAL_EARLYCON From patchwork Wed Dec 22 13:08:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 12697103 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 4DB80C433EF for ; Wed, 22 Dec 2021 13:26:21 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=EW2UVJJDArjSqMfIiEaxUgtfuwkoJoxyYKRBQhoUj4M=; b=eQVrptc1cN9kyr pejhIKsx2ISQQe2TYV3UFaWOj8SQ/xkLBsfVKUl83X1rAk0Kxsurxz4tzi6euWC+uIJm7t6Yx0axr +XzN06BfWzKFslCkJY8yD0AcjeMrBykWJ9GoB853il9YxNKqwhjwd9mSyh/GxKkxa0KEOOFcjquwn nTbhqJpe8j9SrGAD9AEiu3cjIMPr+8lYSkMiGi8dMZWjgTQCgYZBhjTUInTJkYKb+Y0ycXCnJ+7nz r/g3eoHE/WD38Ps+bGY1vksf0A1Gd37WOJbMs34VC66nLzapS6ACUT/XC4SQwDGFzPsonwBXE9v2+ OtSkkhfzvksAD7k9Xy5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01bf-00AV6V-4h; Wed, 22 Dec 2021 13:24:36 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01QK-00APbo-4H; Wed, 22 Dec 2021 13:12:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=8Kqufq3IqQUv/q2D6eeFLNBo3zf+mIbAgPux6qWmfjU=; b=ZshH7SyK6L6HtrRZ6+nA9+CSkr g41KKUHefevxTYNeIeT0U56zFTfvFSJ60xMeIkSPALKnwaqxBciH4VGbso9OUws8AiiTHXPy0b8hs 7tbh5Ong4pO9+Q2C943c6wteytjmx84b1ezyMhhrFVkM5B5CNYwchft93AHlaLqI8CqIpb9xCFh/3 WrmPW0LwyJPobTi8tmGoEMoVXUGWgafsX8QVRSEZHUtlhGnfJN4IB9bmuMx8+OhiA/D5VKT/6PZPu mex6FzTykHYr6ndqzOefdnmiV35gmUKxzksX3SPswNvN7GxkgJA1scURf1WUiryaKtvNYD7Y74grW 4IEG61zQ==; Received: from szxga08-in.huawei.com ([45.249.212.255]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n01QF-002va6-7I; Wed, 22 Dec 2021 13:12:50 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JJtvW0nZQz1DKBK; Wed, 22 Dec 2021 21:09:27 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:36 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 22 Dec 2021 21:12:34 +0800 From: Zhen Lei To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , Dave Young , Baoquan He , Vivek Goyal , Eric Biederman , , Catalin Marinas , "Will Deacon" , , Rob Herring , Frank Rowand , , Jonathan Corbet , CC: Zhen Lei , Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , "John Donnelly" Subject: [PATCH v18 17/17] kdump: update Documentation about crashkernel Date: Wed, 22 Dec 2021 21:08:20 +0800 Message-ID: <20211222130820.1754-18-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20211222130820.1754-1-thunder.leizhen@huawei.com> References: <20211222130820.1754-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_131248_057059_96BD89A5 X-CRM114-Status: GOOD ( 16.68 ) 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 From: Chen Zhou For arm64, the behavior of crashkernel=X has been changed, which tries low allocation in DMA zone and fall back to high allocation if it fails. We can also use "crashkernel=X,high" to select a high region above DMA zone, which also tries to allocate at least 256M low memory in DMA zone automatically and "crashkernel=Y,low" can be used to allocate specified size low memory. So update the Documentation. Signed-off-by: Chen Zhou Signed-off-by: Zhen Lei --- Documentation/admin-guide/kdump/kdump.rst | 11 +++++++++-- Documentation/admin-guide/kernel-parameters.txt | 13 ++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/kdump/kdump.rst b/Documentation/admin-guide/kdump/kdump.rst index cb30ca3df27c9b2..d4c287044be0c70 100644 --- a/Documentation/admin-guide/kdump/kdump.rst +++ b/Documentation/admin-guide/kdump/kdump.rst @@ -361,8 +361,15 @@ Boot into System Kernel kernel will automatically locate the crash kernel image within the first 512MB of RAM if X is not given. - On arm64, use "crashkernel=Y[@X]". Note that the start address of - the kernel, X if explicitly specified, must be aligned to 2MiB (0x200000). + On arm64, use "crashkernel=X" to try low allocation in DMA zone and + fall back to high allocation if it fails. + We can also use "crashkernel=X,high" to select a high region above + DMA zone, which also tries to allocate at least 256M low memory in + DMA zone automatically. + "crashkernel=Y,low" can be used to allocate specified size low memory. + Use "crashkernel=Y@X" if you really have to reserve memory from + specified start address X. Note that the start address of the kernel, + X if explicitly specified, must be aligned to 2MiB (0x200000). Load the Dump-capture Kernel ============================ diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index fc34332c8d9a6df..ff5f15008707cab 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -783,6 +783,9 @@ [KNL, X86-64] Select a region under 4G first, and fall back to reserve region above 4G when '@offset' hasn't been specified. + [KNL, ARM64] Try low allocation in DMA zone and fall back + to high allocation if it fails when '@offset' hasn't been + specified. See Documentation/admin-guide/kdump/kdump.rst for further details. crashkernel=range1:size1[,range2:size2,...][@offset] @@ -798,7 +801,9 @@ be above 4G if system have more than 4G ram installed. Otherwise memory region will be allocated below 4G, if available. - It will be ignored if crashkernel=X is specified. + It will be ignored if crashkernel=X is correctly specified. + [KNL, ARM64] range in high memory. + Allow kernel to allocate physical memory region from top. crashkernel=size[KMG],low [KNL, X86-64] range under 4G. When crashkernel=X,high is passed, kernel could allocate physical memory region @@ -807,13 +812,15 @@ requires at least 64M+32K low memory, also enough extra low memory is needed to make sure DMA buffers for 32-bit devices won't run out. Kernel would try to allocate at - at least 256M below 4G automatically. + least 256M below 4G automatically. This one let user to specify own low range under 4G for second kernel instead. 0: to disable low allocation. It will be ignored when crashkernel=X,high is not used or memory reserved is below 4G. - + [KNL, ARM64] range in low memory. + This one let user to specify a low range in DMA zone for + crash dump kernel. cryptomgr.notests [KNL] Disable crypto self-tests