From patchwork Mon Jun 19 05:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 109741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2809810vqr; Sun, 18 Jun 2023 23:40:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7biTQdAduzKO4ir0mYDFKTPGboUCTEaPsXrHNVR3bha2NFFqtAbx2XXEmNM9pun0QIK4uo X-Received: by 2002:a05:6808:f02:b0:39e:d865:3b6a with SMTP id m2-20020a0568080f0200b0039ed8653b6amr2524285oiw.52.1687156817376; Sun, 18 Jun 2023 23:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687156817; cv=none; d=google.com; s=arc-20160816; b=gYxrIJwJ1rkBU8ZEMAhi8pJ+zHN03q4uHL79YanZFy+KSBGynWR7uY7IedAybltGOv 8tw4p6X35K9z49AXfA42bvS+y9AXa6GDHMgS+UUZ4W73tssT+f2O0u9IahGJn96HgG5n cWxyd77T/7FFylQ5DLH0vBacszz3u8efEG8GYp2JdGCET8T01TNBtOvkaQnOAvmPrMdy uAarKy/z4HpE0WY0gN49uKOUlukHmXE9UQJWqQn009vZnM5cKbi+4D825rZlEfO8itiv /+PtIfy6+3Y2zmfMbviyywipEZUBzy9ZBCABoWU1Vr3xUFVtITL8XTb6WexnjIRfrFeD 9ePQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lpHql56o0Ol2+6lYVJK23uRll0Ruosuke+wpToxzf9M=; b=j+S8J5k7pFDWNL3jfsJRZDAGVbgSPNoRYKdetZLogRci99FdsxS13ALAV4pJG4OViO qsl60ri+VQmzfV+fiW9u0MPhwpiqGlFanbu4yzA0w8VzRC8DIcEiuwaga3/DrNNE3SCQ h0wO7bnvo8Z/ecoTEY4LO4UIpyHR4VKwReBiGPXWL1vKnq/GzbTn8tfNfDj33w5N4u49 TjYOke1W4hn7UyCxLq05IfIeisYWH+MfseueCfcLXmaGDsHC46kyr5wxkLkEmd+sArWQ 5wfAN6soVq+Ge7/pE7HsL5FB41rKgwAFDoqLwtFnkwJB5V+AxjXSxG2diI0SMNytFxms af5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MYdfjl05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a17090a134e00b00250a4d72bc9si6734176pjf.108.2023.06.18.23.40.04; Sun, 18 Jun 2023 23:40:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MYdfjl05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbjFSGBG (ORCPT + 99 others); Mon, 19 Jun 2023 02:01:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjFSGBD (ORCPT ); Mon, 19 Jun 2023 02:01:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F261B8 for ; Sun, 18 Jun 2023 23:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687154414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lpHql56o0Ol2+6lYVJK23uRll0Ruosuke+wpToxzf9M=; b=MYdfjl05DvjAIsROHhiJtpBB8ZuJytwHe57IYAXXkucPW4r2kXKYElShnE3lyO0YnHt5G8 YMAnJIDV/8fkbqS5U+7IiyMolSQ+IsZC2AFPZXQ4p6iK/cDQwqhhZbI0Hy87Exl8+QTGNn D0iV8Li43nfzgbRH6pMzA2FimrW6wj0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-33-TNwaER-hPVO9kiL19i_CkQ-1; Mon, 19 Jun 2023 02:00:07 -0400 X-MC-Unique: TNwaER-hPVO9kiL19i_CkQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37189811E78; Mon, 19 Jun 2023 06:00:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-194.pek2.redhat.com [10.72.12.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB953112132C; Mon, 19 Jun 2023 06:00:01 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, thunder.leizhen@huawei.com, John.p.donnelly@oracle.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, horms@kernel.org, chenjiahao16@huawei.com, linux-riscv@lists.infradead.org, x86@kernel.org, bp@alien8.de, Baoquan He Subject: [RFC PATCH 1/4] kdump: rename parse_crashkernel() to parse_crashkernel_common() Date: Mon, 19 Jun 2023 13:59:48 +0800 Message-Id: <20230619055951.45620-2-bhe@redhat.com> In-Reply-To: <20230619055951.45620-1-bhe@redhat.com> References: <20230619055951.45620-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769112146506802324?= X-GMAIL-MSGID: =?utf-8?q?1769112146506802324?= Now there are parse_crashkernel_high() and parse_crashkernel_low() parsing crashkernel=,high|low. Function parse_crashkernel() could be misunderstood as a generic interface parsing all possible crashkernel kernel parameters. Hence, rename parse_crashkernel() to parse_crashkernel_common() to differentiate it from parse_crashkernel_high() and parse_crashkernel_low(), to remove possible ambiguity. Signed-off-by: Baoquan He --- arch/arm/kernel/setup.c | 4 ++-- arch/arm64/mm/init.c | 4 ++-- arch/ia64/kernel/setup.c | 4 ++-- arch/loongarch/kernel/setup.c | 3 ++- arch/mips/cavium-octeon/setup.c | 2 +- arch/mips/kernel/setup.c | 4 ++-- arch/powerpc/kernel/fadump.c | 5 +++-- arch/powerpc/kexec/core.c | 4 ++-- arch/powerpc/mm/nohash/kaslr_booke.c | 4 ++-- arch/riscv/mm/init.c | 5 +++-- arch/s390/kernel/setup.c | 4 ++-- arch/sh/kernel/machine_kexec.c | 5 +++-- arch/x86/kernel/setup.c | 3 ++- include/linux/crash_core.h | 2 +- kernel/crash_core.c | 14 +++++--------- 15 files changed, 34 insertions(+), 33 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 75cd4699e7b3..7f3dc9ff32f7 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1016,8 +1016,8 @@ static void __init reserve_crashkernel(void) int ret; total_mem = get_total_mem(); - ret = parse_crashkernel(boot_command_line, total_mem, - &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, total_mem, + &crash_size, &crash_base); /* invalid value specified or crashkernel=0 */ if (ret || !crash_size) return; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index c28c2c8483cc..2fc4ea0b5b7a 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -114,8 +114,8 @@ static void __init reserve_crashkernel(void) return; /* crashkernel=X[@offset] */ - ret = parse_crashkernel(cmdline, memblock_phys_mem_size(), - &crash_size, &crash_base); + ret = parse_crashkernel_common(cmdline, memblock_phys_mem_size(), + &crash_size, &crash_base); if (ret == -ENOENT) { ret = parse_crashkernel_high(cmdline, 0, &crash_size, &crash_base); if (ret || !crash_size) diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index c05728044272..91531fce0ba3 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -276,8 +276,8 @@ static void __init setup_crashkernel(unsigned long total, int *n) unsigned long long base = 0, size = 0; int ret; - ret = parse_crashkernel(boot_command_line, total, - &size, &base); + ret = parse_crashkernel_common(boot_command_line, total, + &size, &base); if (ret == 0 && size > 0) { if (!base) { sort_regions(rsvd_region, *n); diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 4444b13418f0..17f9d3d58906 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -267,7 +267,8 @@ static void __init arch_parse_crashkernel(void) unsigned long long crash_base, crash_size; total_mem = memblock_phys_mem_size(); - ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, total_mem, + &crash_size, &crash_base); if (ret < 0 || crash_size <= 0) return; diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c index c5561016f577..bdcac8a4d85e 100644 --- a/arch/mips/cavium-octeon/setup.c +++ b/arch/mips/cavium-octeon/setup.c @@ -885,7 +885,7 @@ void __init prom_init(void) strcat(arcs_cmdline, arg); /* * To do: switch parsing to new style, something like: - * parse_crashkernel(arg, sysinfo->system_dram_size, + * parse_crashkernel_common(arg, sysinfo->system_dram_size, * &crashk_size, &crashk_base); */ #endif diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index c0e65135481b..99f3ed8aeb35 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -457,8 +457,8 @@ static void __init mips_parse_crashkernel(void) int ret; total_mem = memblock_phys_mem_size(); - ret = parse_crashkernel(boot_command_line, total_mem, - &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, total_mem, + &crash_size, &crash_base); if (ret != 0 || crash_size <= 0) return; diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index ea0a073abd96..b4a038cbd1cf 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -312,8 +312,9 @@ static __init u64 fadump_calculate_reserve_size(void) * option. If yes, then use that but ignore base as fadump reserves * memory at a predefined offset. */ - ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &size, &base); + ret = parse_crashkernel_common(boot_command_line, + memblock_phys_mem_size(), + &size, &base); if (ret == 0 && size > 0) { unsigned long max_size; diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index de64c7962991..853de54cc2db 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -108,8 +108,8 @@ void __init reserve_crashkernel(void) total_mem_sz = memory_limit ? memory_limit : memblock_phys_mem_size(); /* use common parsing */ - ret = parse_crashkernel(boot_command_line, total_mem_sz, - &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, total_mem_sz, + &crash_size, &crash_base); if (ret == 0 && crash_size > 0) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; diff --git a/arch/powerpc/mm/nohash/kaslr_booke.c b/arch/powerpc/mm/nohash/kaslr_booke.c index 2fb3edafe9ab..8c049659056f 100644 --- a/arch/powerpc/mm/nohash/kaslr_booke.c +++ b/arch/powerpc/mm/nohash/kaslr_booke.c @@ -177,8 +177,8 @@ static void __init get_crash_kernel(void *fdt, unsigned long size) unsigned long long crash_size, crash_base; int ret; - ret = parse_crashkernel(boot_command_line, size, &crash_size, - &crash_base); + ret = parse_crashkernel_common(boot_command_line, size, + &crash_size, &crash_base); if (ret != 0 || crash_size == 0) return; if (crash_base == 0) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4fa420faa780..6d4b27fc254b 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1326,8 +1326,9 @@ static void __init reserve_crashkernel(void) return; } - ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, + memblock_phys_mem_size(), + &crash_size, &crash_base); if (ret || !crash_size) return; diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index fe10da1a271e..9693f155936e 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -625,8 +625,8 @@ static void __init reserve_crashkernel(void) phys_addr_t low, high; int rc; - rc = parse_crashkernel(boot_command_line, ident_map_size, &crash_size, - &crash_base); + rc = parse_crashkernel_common(boot_command_line, ident_map_size, + &crash_size, &crash_base); crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN); crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN); diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c index 223c14f44af7..9775f6fe245c 100644 --- a/arch/sh/kernel/machine_kexec.c +++ b/arch/sh/kernel/machine_kexec.c @@ -153,8 +153,9 @@ void __init reserve_crashkernel(void) unsigned long long crash_size, crash_base; int ret; - ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &crash_size, &crash_base); + ret = parse_crashkernel_common(boot_command_line, + memblock_phys_mem_size(), + &crash_size, &crash_base); if (ret == 0 && crash_size > 0) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 16babff771bd..b2b67b8c1c1e 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -558,7 +558,8 @@ static void __init reserve_crashkernel(void) total_mem = memblock_phys_mem_size(); /* crashkernel=XM */ - ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); + ret = parse_crashkernel_common(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, diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index de62a722431e..6ec10ed5c6a6 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -77,7 +77,7 @@ Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len); void final_note(Elf_Word *buf); -int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, +int __init parse_crashkernel_common(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); diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 90ce1dfd591c..57738ca0ee7f 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -273,17 +273,13 @@ static int __init __parse_crashkernel(char *cmdline, return parse_crashkernel_simple(ck_cmdline, crash_size, crash_base); } -/* - * That function is the entry point for command line parsing and should be - * called from the arch-specific code. - */ -int __init parse_crashkernel(char *cmdline, - unsigned long long system_ram, - unsigned long long *crash_size, - unsigned long long *crash_base) +int __init parse_crashkernel_common(char *cmdline, + unsigned long long system_ram, + unsigned long long *crash_size, + unsigned long long *crash_base) { return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, - "crashkernel=", NULL); + "crashkernel=", NULL); } int __init parse_crashkernel_high(char *cmdline, From patchwork Mon Jun 19 05:59:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 109739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2806208vqr; Sun, 18 Jun 2023 23:28:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4OAAoMvSnNzKL0anUfLckDlVHDdSk+Uaj3CM/NNN1c2U7SAbIwH21/LxwNUdFVJER+MLro X-Received: by 2002:a05:6358:9f84:b0:127:bde8:eeb0 with SMTP id fy4-20020a0563589f8400b00127bde8eeb0mr171178rwb.27.1687156138274; Sun, 18 Jun 2023 23:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687156138; cv=none; d=google.com; s=arc-20160816; b=s+gQtsqmiFlPy/hb3asYQ1vrVwvTGcA9KHruz24VREdhpq4/afAuqcPvfTt7Qn+gQ3 wAix31QtxinOpRcJGkyg7lAe1anmkl/5GNSmbh8YDc7TgRj8VODTTuzPEG7wvgRf4QLV 6MzrGwYW+ZKmTiFlZZwqpjRQhnSMvB2ZfwVTIkeeSQwAgs3WObAm4Od2jggPjKuPErCF djhWW15xT0RzMNcLga40ddQOGi21HKGVP0DhYtk2nLZRwGE/tXBZucHJ32xLeh9bwznB r8Fq8yd8u7NpLAH/SgrPRM0a1T7tKLSt52D/PkTTB/6w4Sru4ilS3i2CGiuKQRmbcm/v qBmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=npvsI02z3jgn80ioRaeUDRVaANboeER9FhCASltPe50=; b=eZNp81UVaGG6EXbic0ONSOAkbesYrapBkw7ivQktBteZbomlh87SnfYFgZb+1i4Bdz j335YzdMPGSDLve3X3yL1cvVLlMnYMyE7pIaJRhia5787IfHnLwpfCe7ob/9W7GPfnki 734DZs98+oH7xv9B7cK03kil/zhxNX7rdJ9Lt1TIWYrXT2iJUi2mjE6KZGN+a+Eu6CjF Ttlx9X0R1xFJFLZq+e8KG5jNfrYfN8xwR0cEiVxAlVS34zJmvtn2QxDSmqf6xVr6uT/o K/vLPccxP4aW6LbGm+Gp1+V4rv9d4PYyOWJyYXj8KY/u6ibx3djFRnhjpifjCVWDNiR5 YXXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WHsyGYRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g18-20020aa79f12000000b0063b8a054e06si2271845pfr.259.2023.06.18.23.28.45; Sun, 18 Jun 2023 23:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WHsyGYRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbjFSGBK (ORCPT + 99 others); Mon, 19 Jun 2023 02:01:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbjFSGBD (ORCPT ); Mon, 19 Jun 2023 02:01:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D3351BB for ; Sun, 18 Jun 2023 23:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687154415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=npvsI02z3jgn80ioRaeUDRVaANboeER9FhCASltPe50=; b=WHsyGYRXl7bWPA0OSbyhf9Xe8H/CXzeaOuiXShNatrIkZFZCU5rABt3gRWdWZuULt+34FC JWqt0Ki7a9sE9hwgQtUF1sh3Gvu1CmqRWl3r43Tf8kX8KwHv1JeHdhxB3PglmIST1BlP7H 7CQ/iFSCFdJMHYseFaWyO7JxJucXGHk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-o-LmskG3NvWmoSivbOLQRw-1; Mon, 19 Jun 2023 02:00:13 -0400 X-MC-Unique: o-LmskG3NvWmoSivbOLQRw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E92AD101A54E; Mon, 19 Jun 2023 06:00:12 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-194.pek2.redhat.com [10.72.12.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DDA9112132C; Mon, 19 Jun 2023 06:00:07 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, thunder.leizhen@huawei.com, John.p.donnelly@oracle.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, horms@kernel.org, chenjiahao16@huawei.com, linux-riscv@lists.infradead.org, x86@kernel.org, bp@alien8.de, Baoquan He Subject: [RFC PATCH 2/4] kdump: add generic functions to parse crashkernel and do reservation Date: Mon, 19 Jun 2023 13:59:49 +0800 Message-Id: <20230619055951.45620-3-bhe@redhat.com> In-Reply-To: <20230619055951.45620-1-bhe@redhat.com> References: <20230619055951.45620-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769111434873311197?= X-GMAIL-MSGID: =?utf-8?q?1769111434873311197?= In architecture like x86_64, arm64 and riscv, they have vast virtual address space and usually have huge physical memory RAM. Their crashkernel reservation doesn't have to be limited under 4G RAM, but can be extended to the whole physical memory via crashkernel=,high support. Now add function parse_crashkernel_generic() to parse all possible crashkernel parameters, including crashkernel=xM[@offset], crashkernel=,high|low. And add function reserve_crashkernel_generic() to reserve crashkernel memory if users specify any case of above kernel pamameters. This is preparation to simplify code of crashkernel=,high support in architecutures. Signed-off-by: Baoquan He --- include/linux/crash_core.h | 31 ++++++++ kernel/crash_core.c | 144 +++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index 6ec10ed5c6a6..1b12868cad1b 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -84,4 +84,35 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +int __init parse_crashkernel_generic(char *cmdline, + unsigned long long *crash_size, + unsigned long long *crash_base, + unsigned long long *low_size, + bool *high); + +void __init reserve_crashkernel_generic(char *cmdline, + unsigned long long crash_size, + unsigned long long crash_base, + unsigned long long crash_low_size, + bool high); +#else + +static inline int __init parse_crashkernel_generic(char *cmdline, + unsigned long long *crash_size, + unsigned long long *crash_base, + unsigned long long *low_size, + bool *high) +{ + return 0; +} + +static inline void __init reserve_crashkernel_generic(char *cmdline, + unsigned long long crash_size, + unsigned long long crash_base, + unsigned long long crash_low_size, + bool high) +{} +#endif + #endif /* LINUX_CRASH_CORE_H */ diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 57738ca0ee7f..b82dc8c970de 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include @@ -310,6 +313,147 @@ static int __init parse_crashkernel_dummy(char *arg) } early_param("crashkernel", parse_crashkernel_dummy); + +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +int __init parse_crashkernel_generic(char *cmdline, + unsigned long long *crash_size, + unsigned long long *crash_base, + unsigned long long *low_size, + bool *high) +{ + int ret; + + /* crashkernel=X[@offset] */ + ret = parse_crashkernel_common(cmdline, memblock_phys_mem_size(), + crash_size, crash_base); + if (ret == -ENOENT) { + ret = parse_crashkernel_high(cmdline, 0, crash_size, crash_base); + if (ret || !*crash_size) + return -1; + + /* + * crashkernel=Y,low can be specified or not, but invalid value + * is not allowed. + */ + ret = parse_crashkernel_low(cmdline, 0, low_size, crash_base); + if (ret == -ENOENT) + *low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; + else if (ret) + return -1; + + *high = true; + } else if (ret || !*crash_size) { + /* The specified value is invalid */ + return -1; + } + + return 0; +} + +static int __init reserve_crashkernel_low(unsigned long long low_size) +{ +#ifdef CONFIG_64BIT + unsigned long long low_base; + + low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); + if (!low_base) { + pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size); + return -ENOMEM; + } + + pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n", + low_base, low_base + low_size, low_size >> 20); + + 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; +} + +void __init reserve_crashkernel_generic(char *cmdline, + unsigned long long crash_size, + unsigned long long crash_base, + unsigned long long crash_low_size, + bool high) +{ + unsigned long long search_end = CRASH_ADDR_LOW_MAX, search_base = 0; + bool fixed_base = false; + + /* User specifies base address explicitly. */ + if (crash_base) { + fixed_base = true; + search_base = crash_base; + search_end = crash_base + crash_size; + } + + if (high) { + search_base = CRASH_ADDR_LOW_MAX; + search_end = CRASH_ADDR_HIGH_MAX; + } + +retry: + crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, + search_base, search_end); + if (!crash_base) { + /* + * For crashkernel=size[KMG]@offset[KMG], print out failure + * message if can't reserve the specified region. + */ + if (fixed_base) { + pr_warn("crashkernel reservation failed - memory is in use.\n"); + return; + } + + /* + * For crashkernel=size[KMG], if the first attempt was for + * low memory, fall back to high memory, the minimum required + * low memory will be reserved later. + */ + if (!high && search_end == CRASH_ADDR_LOW_MAX) { + search_end = CRASH_ADDR_HIGH_MAX; + search_base = CRASH_ADDR_LOW_MAX; + crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; + goto retry; + } + + /* + * For crashkernel=size[KMG],high, if the first attempt was + * for high memory, fall back to low memory. + */ + if (high && search_end == CRASH_ADDR_HIGH_MAX) { + search_end = CRASH_ADDR_LOW_MAX; + search_base = 0; + goto retry; + } + pr_warn("cannot allocate crashkernel (size:0x%llx)\n", + crash_size); + return; + } + + if ((crash_base > CRASH_ADDR_LOW_MAX) && + crash_low_size && reserve_crashkernel_low(crash_low_size)) { + memblock_phys_free(crash_base, 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); + if (crashk_low_res.end) + kmemleak_ignore_phys(crashk_low_res.start); + + crashk_res.start = crash_base; + crashk_res.end = crash_base + crash_size - 1; + insert_resource(&iomem_resource, &crashk_res); +} +#endif + Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len) { From patchwork Mon Jun 19 05:59:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 109735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2803672vqr; Sun, 18 Jun 2023 23:20:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oHrrUEk0nsUMu50rqlpkOZRH7AlD4t2cv6PiZFiVJAjbfG5Bqw83Gw176GY2rPOBH8Ct0 X-Received: by 2002:a17:90a:8812:b0:256:857f:823d with SMTP id s18-20020a17090a881200b00256857f823dmr4158144pjn.48.1687155624946; Sun, 18 Jun 2023 23:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687155624; cv=none; d=google.com; s=arc-20160816; b=RRCfz56bWA3N48pnKlHebM3Q1T0QPphF9V+fv2Jzd8Fkmdrdu/ltBOj9Rb+MTQvxDj wKh3u7e+8zDqcO+xxkyEHi3DVenjKpUpsjjb3P2stHYk9rICD9O6/GI/KIbJLyAzWMj0 nmjNB3Zf397G5z3oPXW78jOl3DR1EgCedE7bjPZaUhwDWxnaqHK9/YqcdWMFjnwYuf7V Lm+8SVaTicG/XS+ET5bjN6ggn+pJL32hNRSQe77dOB1Bmtvj/ZYcDciIZQu9Cm4Vq2A7 6eFDFzfD3MuV3haHj47EHkG8fGeylt1kDzR8g8ko2ZFYlyCGSp64RTdLgGbQD8t4bpEa rwZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TjI57jex/20Fz+IWygLfQD5ZM+iuVugBPe4GpcvFMYM=; b=Jq78AduFkaJOz9VzNYgwrnLUX40Zg+vA8gw2asCrRXrd6Wu07Dh6RHcUZ7Wy/DRJ4b X6dWeW+yXyd1vtuSPIFwJeAFv5F66aDw8B4+mQHUP5lIsqtFGwTPZBpyeejF4xILtW9N YkF7XsXoGGWyphQ1mc4egHB8K2L9q8THCniR8zMLh2kfLelpRFt4IRhH1Ll/hOuAh7wD +S9UdrzLvKlMfLOB5vcADeWMrHRFr5O6Hxl+zVgVju8r+ZyiGiOWT+Hch8lHztEDvZRy UYJ4znPjlyu3LOxLwgUdfn1akxSIY6svZ7kkUx7QjBwr79n9l8B8srQYwJQpgWVLgTzZ qG8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c4kY5URj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fz16-20020a17090b025000b002509d96227esi6708264pjb.173.2023.06.18.23.20.12; Sun, 18 Jun 2023 23:20:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c4kY5URj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjFSGBT (ORCPT + 99 others); Mon, 19 Jun 2023 02:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjFSGBL (ORCPT ); Mon, 19 Jun 2023 02:01:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0AD01BE for ; Sun, 18 Jun 2023 23:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687154423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TjI57jex/20Fz+IWygLfQD5ZM+iuVugBPe4GpcvFMYM=; b=c4kY5URjZLGQ3MObtdaM0vVkWVGo5q6GlMyg10eWGDyCWJTA6XGLU77fyk1nENjCJy35iI MM/bUG0sa1Y7UrDPnJYTWQojvPhoM96zmK2viy3By325W4Vgu7Mhh8JWt0s5Q+S3ANH2tl ltC797uTAPufskmNpznj5pLooFVeQAM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-mJSciuafPJi0h08VMxMpow-1; Mon, 19 Jun 2023 02:00:19 -0400 X-MC-Unique: mJSciuafPJi0h08VMxMpow-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19734101A52C; Mon, 19 Jun 2023 06:00:19 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-194.pek2.redhat.com [10.72.12.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8B95112132C; Mon, 19 Jun 2023 06:00:13 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, thunder.leizhen@huawei.com, John.p.donnelly@oracle.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, horms@kernel.org, chenjiahao16@huawei.com, linux-riscv@lists.infradead.org, x86@kernel.org, bp@alien8.de, Baoquan He Subject: [RFC PATCH 3/4] arm64: kdump: use generic interfaces to simplify crashkernel reservation code Date: Mon, 19 Jun 2023 13:59:50 +0800 Message-Id: <20230619055951.45620-4-bhe@redhat.com> In-Reply-To: <20230619055951.45620-1-bhe@redhat.com> References: <20230619055951.45620-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769110896131349915?= X-GMAIL-MSGID: =?utf-8?q?1769110896131349915?= With the help of generic functions parse_crashkernel_generic() and reserve_crashkernel_generic(), crashkernel reservation can be simplified by steps: 1) Provide CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in ; 2) Add arch_reserve_crashkernel() to call parse_crashkernel_generic() and reserve_crashkernel_generic(); 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/arm64/Kconfig. The old reserve_crashkernel_low() and reserve_crashkernel() can be removed. Signed-off-by: Baoquan He --- arch/arm64/Kconfig | 3 + arch/arm64/include/asm/kexec.h | 8 ++ arch/arm64/mm/init.c | 141 ++------------------------------- 3 files changed, 19 insertions(+), 133 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 343e1e1cae10..0a846b30b91f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1453,6 +1453,9 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 9ac9572a3bbe..6f044ab6917d 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -132,4 +132,12 @@ extern int load_other_segments(struct kimage *image, #endif /* __ASSEMBLY__ */ +/* Current arm64 boot protocol requires 2MB alignment */ +#define CRASH_ALIGN SZ_2M + +#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit +#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1) + +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) + #endif diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 2fc4ea0b5b7a..3480a0476052 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -64,149 +64,24 @@ EXPORT_SYMBOL(memstart_addr); */ phys_addr_t __ro_after_init arm64_dma_phys_limit; -/* Current arm64 boot protocol requires 2MB alignment */ -#define CRASH_ALIGN SZ_2M - -#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit -#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1) -#define CRASH_HIGH_SEARCH_BASE SZ_4G - -#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) - -static int __init reserve_crashkernel_low(unsigned long long low_size) -{ - unsigned long long low_base; - - low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); - if (!low_base) { - pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size); - return -ENOMEM; - } - - pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n", - low_base, low_base + low_size, low_size >> 20); - - crashk_low_res.start = low_base; - crashk_low_res.end = low_base + low_size - 1; - insert_resource(&iomem_resource, &crashk_low_res); - - return 0; -} - -/* - * 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. - */ -static void __init reserve_crashkernel(void) +static void __init arch_reserve_crashkernel(void) { - unsigned long long crash_low_size = 0, search_base = 0; - unsigned long long crash_max = CRASH_ADDR_LOW_MAX; + unsigned long long low_size = 0; unsigned long long crash_base, crash_size; char *cmdline = boot_command_line; - bool fixed_base = false; bool high = false; int ret; if (!IS_ENABLED(CONFIG_KEXEC_CORE)) return; - /* crashkernel=X[@offset] */ - ret = parse_crashkernel_common(cmdline, memblock_phys_mem_size(), - &crash_size, &crash_base); - if (ret == -ENOENT) { - ret = parse_crashkernel_high(cmdline, 0, &crash_size, &crash_base); - if (ret || !crash_size) - return; - - /* - * crashkernel=Y,low can be specified or not, but invalid value - * is not allowed. - */ - ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, &crash_base); - if (ret == -ENOENT) - crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; - else if (ret) - return; - - search_base = CRASH_HIGH_SEARCH_BASE; - crash_max = CRASH_ADDR_HIGH_MAX; - high = true; - } else if (ret || !crash_size) { - /* The specified value is invalid */ + ret = parse_crashkernel_generic(cmdline, &crash_size, &crash_base, + &low_size, &high); + if (ret) return; - } - - crash_size = PAGE_ALIGN(crash_size); - - /* User specifies base address explicitly. */ - if (crash_base) { - fixed_base = true; - search_base = crash_base; - crash_max = crash_base + crash_size; - } - -retry: - crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, - search_base, crash_max); - if (!crash_base) { - /* - * For crashkernel=size[KMG]@offset[KMG], print out failure - * message if can't reserve the specified region. - */ - if (fixed_base) { - pr_warn("crashkernel reservation failed - memory is in use.\n"); - return; - } - - /* - * For crashkernel=size[KMG], if the first attempt was for - * low memory, fall back to high memory, the minimum required - * low memory will be reserved later. - */ - if (!high && crash_max == CRASH_ADDR_LOW_MAX) { - crash_max = CRASH_ADDR_HIGH_MAX; - search_base = CRASH_ADDR_LOW_MAX; - crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; - goto retry; - } - - /* - * For crashkernel=size[KMG],high, if the first attempt was - * for high memory, fall back to low memory. - */ - if (high && crash_max == CRASH_ADDR_HIGH_MAX) { - crash_max = CRASH_ADDR_LOW_MAX; - search_base = 0; - goto retry; - } - pr_warn("cannot allocate crashkernel (size:0x%llx)\n", - crash_size); - return; - } - - if ((crash_base >= CRASH_ADDR_LOW_MAX) && crash_low_size && - reserve_crashkernel_low(crash_low_size)) { - memblock_phys_free(crash_base, 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); - if (crashk_low_res.end) - kmemleak_ignore_phys(crashk_low_res.start); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size - 1; - insert_resource(&iomem_resource, &crashk_res); + reserve_crashkernel_generic(cmdline, crash_size, crash_base, + low_size, high); } /* @@ -454,7 +329,7 @@ void __init bootmem_init(void) * request_standard_resources() depends on crashkernel's memory being * reserved, so do it here. */ - reserve_crashkernel(); + arch_reserve_crashkernel(); memblock_dump_all(); } From patchwork Mon Jun 19 05:59:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 109734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2799266vqr; Sun, 18 Jun 2023 23:07:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6E6Syvs0yqk+5OP7h0HEqIsn7yelTCaBg2f8L+paHXG43n+dJSn7n+EwbfJYzd2VArZur3 X-Received: by 2002:a05:6a20:72a3:b0:121:6f57:8fb9 with SMTP id o35-20020a056a2072a300b001216f578fb9mr109518pzk.58.1687154851542; Sun, 18 Jun 2023 23:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687154851; cv=none; d=google.com; s=arc-20160816; b=nA/lgWnfza7gtOJxA2xR7OQ1ttz5sddsRtV5xBLRMNy7fl5HOdHNchvi/eYAXtFGzL uTp2W1v6ytfJ8Mq/OPu5H9+ZqJXGETO3XGAnygHcwe/f6cYk5uHCtky9Y8JTSMp0DQz+ GThAuANd6ewUb5E4cNrDEcav85Gp3jVVmkQeSXvHu6cP41Np0jgseiqWaHpEBEVzFF0k PDlcMuTRRQkgyWf+qeaG5itrTcJKmOFR+L2XUO53qWG7ADJtyMpfEAsHJ1h8OB3ol2Yk qt4AUqwrlFnj7QZxs1nYa/lOJ9YkmHHW1Pq21qESgwqaU6aZke/kIKpFHWGqzIBiy5RE i7fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vw/5HYzo6kjapeqPkMMNvl8DuGkmtln/x/NXEn9LsOk=; b=owcc0tNv5lvjNj+EnnI1YlSNHoyiUFh3EKAkBwJ96+vhf/Vu3wdRLVQKYJINQaOHvp fLmC0qyby2BiPbvTo5uuz9lLIKr/7olnmh3hOJZ1sOveXFrOJgB/vySi/cR/2eAG0lhS 5MNjXoULBWp71igKGm7l/Z3oFuhtLYh2guvmqPT484FABXnf1vc7a8SffkjBKyjTcN25 OTIYINzLyVH+cyJ78WDy5ZJNGW5mDQMQkgYfmDHvmq1dYqYOuaYxQ8WlACYgClFLVJmw bpZ2eEjbGezS6mRHdcq91ei63cwkmI0c4BiR5D2IxK24tXisYWir333id0qffWWnt7P9 htUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aHWz7KgJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020aa796ea000000b006688156de26si948510pfq.26.2023.06.18.23.07.17; Sun, 18 Jun 2023 23:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aHWz7KgJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjFSGBY (ORCPT + 99 others); Mon, 19 Jun 2023 02:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjFSGBS (ORCPT ); Mon, 19 Jun 2023 02:01:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D48E7E42 for ; Sun, 18 Jun 2023 23:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687154429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vw/5HYzo6kjapeqPkMMNvl8DuGkmtln/x/NXEn9LsOk=; b=aHWz7KgJ4A9aQz1YwdHaLaHNOqgD5lLtTUlMTBJKuCPSD8Lue33ddKh1TrFZkjBOBIFd+8 8hFbEOi4PNL235ocKrh6Z+WS42XLjsC1qiO40yT2ZYmI5aVdr3hlNURTntz4IpakuGPY52 DBrj+6ZosL8fcmB5tIgxG/6kaa73fN8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-280-92C_1a6VNYSGuxWUmp4KFw-1; Mon, 19 Jun 2023 02:00:25 -0400 X-MC-Unique: 92C_1a6VNYSGuxWUmp4KFw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 754D4380673B; Mon, 19 Jun 2023 06:00:24 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-194.pek2.redhat.com [10.72.12.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6A8C112132E; Mon, 19 Jun 2023 06:00:19 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, thunder.leizhen@huawei.com, John.p.donnelly@oracle.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, horms@kernel.org, chenjiahao16@huawei.com, linux-riscv@lists.infradead.org, x86@kernel.org, bp@alien8.de, Baoquan He Subject: [RFC PATCH 4/4] x86: kdump: use generic interfaces to simplify crashkernel reservation code Date: Mon, 19 Jun 2023 13:59:51 +0800 Message-Id: <20230619055951.45620-5-bhe@redhat.com> In-Reply-To: <20230619055951.45620-1-bhe@redhat.com> References: <20230619055951.45620-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769110085751410526?= X-GMAIL-MSGID: =?utf-8?q?1769110085751410526?= With the help of generic functions parse_crashkernel_generic() and reserve_crashkernel_generic(), crashkernel reservation can be simplified by steps: 1) Provide CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in ; 2) Add arch_reserve_crashkernel() to call parse_crashkernel_generic() and reserve_crashkernel_generic(), and do the ARCH specific work if needed. 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/x86/Kconfig. When adding DEFAULT_CRASH_KERNEL_LOW_SIZE, add crash_low_size_default() to calculate crashkernel low memory because x86_64 has special requirement. The old reserve_crashkernel_low() and reserve_crashkernel() can be removed. Signed-off-by: Baoquan He --- arch/x86/Kconfig | 3 + arch/x86/include/asm/kexec.h | 32 ++++++++ arch/x86/kernel/setup.c | 142 ++++------------------------------- 3 files changed, 50 insertions(+), 127 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 53bab123a8ee..fb91a5064c8d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2076,6 +2076,9 @@ config KEXEC_FILE config ARCH_HAS_KEXEC_PURGATORY def_bool KEXEC_FILE +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 5b77bbc28f96..84a7d1f6f153 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -66,6 +66,37 @@ struct kimage; # define KEXEC_ARCH KEXEC_ARCH_X86_64 #endif +/* + * --------- Crashkernel reservation ------------------------------ + */ + +/* 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 + +# define DEFAULT_CRASH_KERNEL_LOW_SIZE crash_low_size_default() + /* * This function is responsible for capturing register states if coming * via panic otherwise just fix up the ss and sp if coming via kernel @@ -209,6 +240,7 @@ typedef void crash_vmclear_fn(void); extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss; extern void kdump_nmi_shootdown_cpus(void); +extern unsigned long crash_low_size_default(void); #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_KEXEC_H */ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index b2b67b8c1c1e..11ae1f0c9487 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -475,151 +475,39 @@ static void __init memblock_x86_reserve_range_setup_data(void) * --------- Crashkernel reservation ------------------------------ */ -/* 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) +unsigned long crash_low_size_default(void) { #ifdef CONFIG_X86_64 - unsigned long long base, low_base = 0, low_size = 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; - } - - 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; - insert_resource(&iomem_resource, &crashk_low_res); -#endif + return max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); +#else return 0; +#endif } -static void __init reserve_crashkernel(void) +static void __init arch_reserve_crashkernel(void) { - unsigned long long crash_size, crash_base, total_mem; + unsigned long long crash_base, crash_size, low_size = 0; + char *cmdline = boot_command_line; bool high = false; int ret; if (!IS_ENABLED(CONFIG_KEXEC_CORE)) return; - total_mem = memblock_phys_mem_size(); - - /* crashkernel=XM */ - ret = parse_crashkernel_common(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; - } + ret = parse_crashkernel_generic(cmdline, &crash_size, &crash_base, + &low_size, &high); + if (ret) + return; if (xen_pv_domain()) { pr_info("Ignoring crashkernel for a Xen PV domain\n"); 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. - */ - if (!high) - crash_base = memblock_phys_alloc_range(crash_size, - CRASH_ALIGN, CRASH_ALIGN, - CRASH_ADDR_LOW_MAX); - 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; - - 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; - } - } - - if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { - memblock_phys_free(crash_base, crash_size); - return; - } - - 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)); + reserve_crashkernel_generic(cmdline, crash_size, crash_base, + low_size, high); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size - 1; - insert_resource(&iomem_resource, &crashk_res); + return; } static struct resource standard_io_resources[] = { @@ -1229,7 +1117,7 @@ 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(); + arch_reserve_crashkernel(); memblock_find_dma_reserve();