Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3695836rdb; Wed, 27 Dec 2023 17:24:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqdmTorLvWkqrEnrjLYR8RYqDG4ISA25D8jQUaJPCaCVicctorOW7oJrQ0XCjFv72l+uam X-Received: by 2002:a92:ca4a:0:b0:35f:f707:3ec1 with SMTP id q10-20020a92ca4a000000b0035ff7073ec1mr11417300ilo.32.1703726697840; Wed, 27 Dec 2023 17:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703726697; cv=none; d=google.com; s=arc-20160816; b=AkguCQmpCBkGDlAKE047FqePrWyhXcoKBIipdnyPt33Zq71sSEM/N22LMLlTFxskCI TMKjw3BWC8jORg1KfRBjcXJh/3EoLtb9eWrCSYq+8Qs69SCC1uZm1mg4u+vYJESsCHcT TmWGB5MsUMZ4+tS03e4dRGII4xBF7RbI/atcE50CrRo5Zd25p4ct1RZqd7yXhbADCpIb XOCDRVVgGHFPJ0za4U+WZ/datGvtgRzOYepEj70N/lcneCjU6H/qQXf3BCTyy7/3Q2Oc gHvOIhVXCe7ttTQ30u16Ix6don6sXtsIZ04fX+uEW2zUD1ov/er0PMfgZBRAgPnpzZzv b1qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=yGHr1GbeVRsUQXammT6ZYRyjHyqV39eAYgQ5VxDK7W0=; fh=KNXRqWDmADAwa6G4uqtfRAe+lL6gGQwp8rS0sIlKKDw=; b=nY6UpsmCv5pHTdyxEyS0/J0yDrKup+xSPMePa5n7VkLfrg6zG4eupz3CphLRwdaZ88 8Na7gZR/lRsG6U5kvWd27pQ+bcDDsWELG03RcF+vLMQFcu+kE+UNpKuMOY2y1MqiUlV6 45/jm7WGmRzOMHU8oYwYZ/vM580mTsUOzC0tNSooO55/7mfrvi1kHzTou+PCMFKDN/A7 D7OzbNHhlcmXLON/YBtMywDqExPthwGYZ7puzUgwQh0e27EAhFmQXVG1+qdb+DPIFwNh rxZ0buAlbJmnFRcn35i+gjPG1oshYxECa5lHqczF3huzUr3ATInJSso4DW7VStempfrt 6Crw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CcE6dSn3; spf=pass (google.com: domain of linux-kernel+bounces-12334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x4-20020a63db44000000b005ca5b61ca25si12075123pgi.233.2023.12.27.17.24.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:24:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CcE6dSn3; spf=pass (google.com: domain of linux-kernel+bounces-12334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 91B8AB20B88 for ; Thu, 28 Dec 2023 01:24:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F9481106; Thu, 28 Dec 2023 01:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CcE6dSn3" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AED6ED8; Thu, 28 Dec 2023 01:24:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23D20C433CA; Thu, 28 Dec 2023 01:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703726669; bh=xHv0G5x2J88Pxkc5+do8/plUomGlF6DSGjvbPx0NqpE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CcE6dSn38KviQaoBTEb20h9ZVUMPTA2s8akbRkuOm26TEvOGVjXZneVUz4aJTlIKE 3Rhq6RVYaNuDFIzZl29dGop+46nsrNwLZvol7cFBwIQWjO4hkLXtJlIWzS4S/TQWKU yuZWPfprwIX2/DIM0RntYaUhdSjrKNkgnfFrawW3fC715HmwiSf8Zehzdpl+BBFS2h fiLx5r6hy+L3RXDIV8xYgjr5x5+G1O1RO3t6SFLsYrmLri6mHLesZg9H3e8vnE/TCK ftZRtWKIu/aMmUD3HeUkRR3TekspNrGV3hsZgIKrfmi2sGDDhVl4ZVU9xkp5nJjoEl etJCSIWlvOhqA== Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-554cffbad2fso3017261a12.1; Wed, 27 Dec 2023 17:24:29 -0800 (PST) X-Gm-Message-State: AOJu0YwUxzKJqcVbJX1xiRn22mGKM3LP8ROts+ahWG8IZuOkyVgybeev eRnYJoPQbYrRKQCbqaz1CqPEhIF48yTxy/MUQ14= X-Received: by 2002:a17:906:1688:b0:a23:665f:3981 with SMTP id s8-20020a170906168800b00a23665f3981mr2482371ejd.88.1703726667507; Wed, 27 Dec 2023 17:24:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Huacai Chen Date: Thu, 28 Dec 2023 09:24:17 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] LoongArch: use generic interface to support crashkernel=X,[high,low] To: Youling Tang Cc: Jonathan Corbet , WANG Xuerui , Baoquan He , loongarch@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Youling Tang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Youling, I squashed the two patches and applied here: https://github.com/chenhuacai/linux/commits/loongarch-next You can verify whether everything works. Huacai On Wed, Dec 27, 2023 at 8:31=E2=80=AFPM Youling Tang wrote: > > From: Youling Tang > > LoongArch already supports two crashkernel regions in kexec-tools, so we > can directly use the common interface to support crashkernel=3DX,[hign,lo= w] > after commit 0ab97169aa05("crash_core: add generic function to do reserva= tion"). > > With the help of newly changed function parse_crashkernel() and generic > reserve_crashkernel_generic(), crashkernel reservation can be simplified > by steps: > > 1) Add a new header file , and define 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() and > reserve_crashkernel_generic(); > > 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in > arch/loongarch/Kconfig. > > One can reserve the crash kernel from high memory above DMA zone range > by explicitly passing "crashkernel=3DX,high"; or reserve a memory range > below 4G with "crashkernel=3DX,low". Besides, there are few rules need > to take notice: > > 1) "crashkernel=3DX,[high,low]" will be ignored if "crashkernel=3Dsize" > is specified. > 2) "crashkernel=3DX,low" is valid only when "crashkernel=3DX,high" is pas= sed > and there is enough memory to be allocated under 4G. > 3) When allocating crashkernel above 4G and no "crashkernel=3DX,low" is > specified, a 128M low memory will be allocated automatically for > swiotlb bounce buffer. > See Documentation/admin-guide/kernel-parameters.txt for more information. > > Following test cases have been performed as expected: > 1) crashkernel=3D256M //low=3D256M > 2) crashkernel=3D1G //low=3D1G > 3) crashkernel=3D4G //high=3D4G, low=3D128M(de= fault) > 4) crashkernel=3D4G crashkernel=3D256M,high //high=3D4G, low=3D128M(= default), high is ignored > 5) crashkernel=3D4G crashkernel=3D256M,low //high=3D4G, low=3D128M(= default), low is ignored > 6) crashkernel=3D4G,high //high=3D4G, low=3D128M(de= fault) > 7) crashkernel=3D256M,low //low=3D0M, invalid > 8) crashkernel=3D4G,high crashkernel=3D256M,low //high=3D4G, low=3D256M > 9) crashkernel=3D4G,high crashkernel=3D4G,low //high=3D0M, low=3D0M, i= nvalid > 10) crashkernel=3D512M@2560M //low=3D512M > 11) crashkernel=3D1G,high crashkernel=3D0M,low //high=3D1G, low=3D0M > > Recommended usage in general: > 1) In the case of small memory: crashkernel=3D512M > 2) In the case of large memory: crashkernel=3D1024M,high crashkernel=3D12= 8M,low > > Signed-off-by: Youling Tang > --- > v2: > Submit information and format adjustments. > > arch/loongarch/Kconfig | 3 ++ > arch/loongarch/include/asm/crash_core.h | 11 ++++++ > arch/loongarch/kernel/setup.c | 46 ++++++------------------- > 3 files changed, 25 insertions(+), 35 deletions(-) > create mode 100644 arch/loongarch/include/asm/crash_core.h > > diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > index ee123820a476..02060b2ac3f2 100644 > --- a/arch/loongarch/Kconfig > +++ b/arch/loongarch/Kconfig > @@ -575,6 +575,9 @@ config ARCH_SELECTS_CRASH_DUMP > depends on CRASH_DUMP > select RELOCATABLE > > +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION > + def_bool CRASH_CORE > + > config RELOCATABLE > bool "Relocatable kernel" > help > diff --git a/arch/loongarch/include/asm/crash_core.h b/arch/loongarch/inc= lude/asm/crash_core.h > new file mode 100644 > index 000000000000..1f7040d8ed0f > --- /dev/null > +++ b/arch/loongarch/include/asm/crash_core.h > @@ -0,0 +1,11 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +#ifndef _LOONGARCH_CRASH_CORE_H > +#define _LOONGARCH_CRASH_CORE_H > + > +#define CRASH_ALIGN SZ_2M > + > +#define CRASH_ADDR_LOW_MAX SZ_4G > +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() > + > +extern phys_addr_t memblock_end_of_DRAM(void); > +#endif > diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.= c > index d183a745fb85..189cd9575758 100644 > --- a/arch/loongarch/kernel/setup.c > +++ b/arch/loongarch/kernel/setup.c > @@ -252,38 +252,23 @@ static void __init arch_reserve_vmcore(void) > #endif > } > > -/* 2MB alignment for crash kernel regions */ > -#define CRASH_ALIGN SZ_2M > -#define CRASH_ADDR_MAX SZ_4G > - > -static void __init arch_parse_crashkernel(void) > +static void __init arch_reserve_crashkernel(void) > { > -#ifdef CONFIG_KEXEC > - int ret; > - unsigned long long total_mem; > + unsigned long long low_size =3D 0; > unsigned long long crash_base, crash_size; > + char *cmdline =3D boot_command_line; > + bool high =3D false; > + int ret; > > - total_mem =3D memblock_phys_mem_size(); > - ret =3D parse_crashkernel(boot_command_line, total_mem, > - &crash_size, &crash_base, > - NULL, NULL); > - if (ret < 0 || crash_size <=3D 0) > + if (!IS_ENABLED(CONFIG_KEXEC_CORE)) > return; > > - if (crash_base <=3D 0) { > - crash_base =3D memblock_phys_alloc_range(crash_size, CRAS= H_ALIGN, CRASH_ALIGN, CRASH_ADDR_MAX); > - if (!crash_base) { > - pr_warn("crashkernel reservation failed - No suit= able area found.\n"); > - return; > - } > - } else if (!memblock_phys_alloc_range(crash_size, CRASH_ALIGN, cr= ash_base, crash_base + crash_size)) { > - pr_warn("Invalid memory region reserved for crash kernel\= n"); > + ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), > + &crash_size, &crash_base, &low_size, &hig= h); > + if (ret) > return; > - } > > - crashk_res.start =3D crash_base; > - crashk_res.end =3D crash_base + crash_size - 1; > -#endif > + reserve_crashkernel_generic(cmdline, crash_size, crash_base, low_= size, high); > } > > static void __init fdt_setup(void) > @@ -357,7 +342,7 @@ static void __init bootcmdline_init(char **cmdline_p) > void __init platform_init(void) > { > arch_reserve_vmcore(); > - arch_parse_crashkernel(); > + arch_reserve_crashkernel(); > > #ifdef CONFIG_ACPI_TABLE_UPGRADE > acpi_table_upgrade(); > @@ -467,15 +452,6 @@ static void __init resource_init(void) > request_resource(res, &data_resource); > request_resource(res, &bss_resource); > } > - > -#ifdef CONFIG_KEXEC > - if (crashk_res.start < crashk_res.end) { > - insert_resource(&iomem_resource, &crashk_res); > - pr_info("Reserving %ldMB of memory at %ldMB for crashkern= el\n", > - (unsigned long)((crashk_res.end - crashk_res.star= t + 1) >> 20), > - (unsigned long)(crashk_res.start >> 20)); > - } > -#endif > } > > static int __init add_legacy_isa_io(struct fwnode_handle *fwnode, > -- > 2.40.0 > >