Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2719283rdb; Tue, 26 Dec 2023 02:56:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQZisK0Cr/QNVOMPTCdVuciiQ+tlcKSZvgEjBAzr7HIseMKYzQhUxBM90wzF22ZD61PT/+ X-Received: by 2002:a0d:e851:0:b0:5d7:1941:3557 with SMTP id r78-20020a0de851000000b005d719413557mr3810123ywe.62.1703588210798; Tue, 26 Dec 2023 02:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703588210; cv=none; d=google.com; s=arc-20160816; b=Rldu68HCSDEnxSWqQL44yrO25hlvZ5RdIqqXpVIMK+6sZlQGXCJfFmNY9CdOBWQyvP eBqNyOpo2OjSofbKvFshqir/W6VQ2DA5JoRRarG/vyT9aSBMA6J+u9zWZMkrBTGwJyoz HDFFpAhigySP3QUS/NpSNooPBne9USLAiDk5YQzRMQn7gsxnv3rslsYXZtuKXRQzyLpw EiiC8miLfp1hbvoB6UnvxIOGz5UFlcWoEQjlU3oT2EymUz/xhpn6T/wxkVPsCj+yAgYR 4dJHEJ++pN86WSdvvEtPN43Lj5OaV7Lltu6/ilqjscz7TZi/HMEmJwHkEjqPF7sCV4SI ptjQ== 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=GnIj3M68SGEnT3l80nr+nRXhXLjtZhI5gpiBW6MyujA=; fh=0Tk6BrU0Igt1gSgZtOX8v2fVdjGVEPAuit0Bd7vg+hk=; b=pg4zxxuLjk6iTrfTi7is6xL4kg7WVSDFF4ZmmMa8i/dTLatypM0kyE+TCKP8TSdsC9 1irky2hvM+gulaggaSm3J8tbHnUGo+5UWKSd0YrIkcimmzW8wqwwfo27PcB8W0QWcSd3 F2m/SQIF1XLSz6RwE27E50FoIP0XOO17XtlY5S+IvTz+2rN+HV4WC5XwJuasr9nFpWPL AYJjDMPCPUnb3RhAwx3iYHs5NjHlinDkBkJjDO9YR/r3xIYO6GQjPEVKTWwuCyQpIEba xw8L+7+XBrdhnR1v+jnvj2UJuQUPsIuYRhiNpNpEeH2/ax9I7F7JWav9EuxcIcTw8onm gzBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UyNboUkH; spf=pass (google.com: domain of linux-kernel+bounces-11481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11481-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g24-20020a170902fe1800b001d3c3b750f7si7946899plj.332.2023.12.26.02.56.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 02:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UyNboUkH; spf=pass (google.com: domain of linux-kernel+bounces-11481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11481-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 676D0282FE9 for ; Tue, 26 Dec 2023 10:56:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D48B24E1BA; Tue, 26 Dec 2023 10:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UyNboUkH" 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 F11224E1A5 for ; Tue, 26 Dec 2023 10:56:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E373C433CB for ; Tue, 26 Dec 2023 10:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703588202; bh=7yAih3GoOhZJptIFU6wbb/T3rDQVto1u3wtn6V99Q58=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UyNboUkHZ3yp9xrDbz26+3eqXg7xEPDTtbnO8//0pDVKSe9ALYoaLvSXxwPJidaka KwCK4cbQGkPzbt7e6SZlfSwv4to5uaBvFA3nsQY67sdf1uBcrJpU9s1Ed29mqIzAzh wJxN/4wnI2mt45YRCHCCQ1UYtE4PXJSkecD0kFSQdFKrJ1Zn7+a5IDC7dRnt74LZJa TlsN1KAJ5ZWZyxCaCl/pGMo8/WDrrPdkkplgIVOpS9C6UfKm1uIIN3SZgDEWq+TDMh l35CIiSBVx8my3MP6YTAaCZI3cO0vc7qz6XYhL4nzVUw9uGO48pfTo03W5/6WB4TV0 SgWRp+RWCHqoA== Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33674f60184so4436042f8f.1 for ; Tue, 26 Dec 2023 02:56:42 -0800 (PST) X-Gm-Message-State: AOJu0Yxf1wAtcNwhceWGLiXoMcNlP6cFDogtgE9YD/Y6TwV2udN8B8vi LUb2Fju0YDpgAdp5eVwto/iYHlc07dkdnQIaVHc= X-Received: by 2002:a05:600c:198a:b0:40d:5358:8d77 with SMTP id t10-20020a05600c198a00b0040d53588d77mr1900602wmq.80.1703588200833; Tue, 26 Dec 2023 02:56:40 -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: Tue, 26 Dec 2023 18:56:28 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: use generic interface to support crashkernel=X,[high,low] To: Youling Tang Cc: WANG Xuerui , Baoquan He , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Youling Tang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Youling, On Mon, Dec 25, 2023 at 10:18=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]. > > With the help of newly changed function parse_crashkernel() and generic > reserve_crashkernel_generic(), crashkernel reservation can be simplified > by steps: It is better to refer the commits introduce those changes. > > 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: It is better to group them into "Recommended use cases", "Valid use cases (not recommended)" and "Invalid use cases". > 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 > > Signed-off-by: Youling Tang > --- > arch/loongarch/Kconfig | 3 ++ > arch/loongarch/include/asm/crash_core.h | 11 ++++++ > arch/loongarch/kernel/setup.c | 48 +++++++------------------ > 3 files changed, 27 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..2a69a36419da 100644 > --- a/arch/loongarch/kernel/setup.c > +++ b/arch/loongarch/kernel/setup.c > @@ -252,38 +252,25 @@ 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, &high); This line can be merged with its above line. > + 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); They can be in one line. Huacai > } > > static void __init fdt_setup(void) > @@ -357,7 +344,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 +454,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 >