Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp8069785rdb; Thu, 4 Jan 2024 18:40:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEN+tO3Q53wwX0I/8415l35hK3v3PK9lh0lYVRssbmp0s2ufijmtw81LOe8I9tzlWfSn6Lx X-Received: by 2002:a05:6512:308c:b0:50e:35e2:a6ad with SMTP id z12-20020a056512308c00b0050e35e2a6admr911715lfd.83.1704422400684; Thu, 04 Jan 2024 18:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704422400; cv=none; d=google.com; s=arc-20160816; b=XYopzLZHaJh8C22WuaXpHcI0jug/MVicVmOn+kse7TyLnDyHeZVHka0KiCsc7yU1Tb fXebSdaq5kSw9OG5oMZrk0Y3hZkmdqa2ASvieS6By5AW75qv7q0s6y+E964ITa4bmIZX D/uBtVHkk7FtgLeIT1naf5ww0C9Rnr4kexI6N5ChjtueOMSzza7SJIqRsSZaAfNoUUig a88P5smotmczGDaFohApPwet0I6YkkB/pUB895hR+5Dqpte9f46KJVjjjm9nfDaJFAMJ IeAqj/klfkBBITP3TJ/7iCcvjYQf2lFTmUhNa1hBg4+slEtFU6FlwDaxZIKg2DTlk5nO I3Xg== 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=K9JQlWareGt/6o4HUXbRrcORjl8tVPDpWn8i60yxC1g=; fh=KNXRqWDmADAwa6G4uqtfRAe+lL6gGQwp8rS0sIlKKDw=; b=xRjSqRfOFSRDleeYtD4B9Jxwke87lH7u3gJ1kDoz/h/RqrcQlINwhe9i49k+TBIe3G rsMtxb506Gw457R6T6CrYcS601DPrDKqUfMVog7D0Tx4qVy3wdL+PabPBrprqHcXyhlA DoH/YBCWiawMg7vs7dqbUUmMZKHxAi73Tl4X97IKIimcl3hwZIKmCWtS3m7Kt7rqxc+4 /M/ztaFPxPH4PNEvdQLliwDINBcz+afN1WtrlHaeQ8E4pIjsqOkg78jxW2DIibHVww2a 4VsTZjX9lTdFMg9omHj2zNM3hOKZAqcaB2cUY2WCPi9k20hqFNOmmv7fLumm2nnLlPsF um3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tFFuQtN1; spf=pass (google.com: domain of linux-kernel+bounces-17427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17427-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b8-20020a170906d10800b00a26ea214a4bsi231771ejz.85.2024.01.04.18.40.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 18:40:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tFFuQtN1; spf=pass (google.com: domain of linux-kernel+bounces-17427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17427-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1F9221F235D5 for ; Fri, 5 Jan 2024 02:40:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2932A20EE; Fri, 5 Jan 2024 02:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tFFuQtN1" 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 4E0E820EB; Fri, 5 Jan 2024 02:39:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D67D9C433CD; Fri, 5 Jan 2024 02:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704422389; bh=ENpZuD2THtzGRqEXKNM+3GLOVzxifNZq0/t++tPGpFk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tFFuQtN1Ga8yvlhra26rSdWsrxKuwpSfpvSNZMMlzDICuKQA7+33dfpRrlcgG8MWf Xiv931JnxT+c/wdjDqGWGx9JNokESQfq4HNzNUbUC7Q3JsMQMVHl1hha2eBwvRg6vU wdtx2myM9s6kxxflbKpJwIDPGiIlGtBByDrqx7QzVuQaRsnuZCLEbZ9y7dERYAb65w cC/Tze4HWEQ6V3AghfUB6UKTKBUBsVfauzM7+a0BXbkzdY0qqvth1+hs8u8dUkull4 7ygvnSlQfSX2bSLDynuRkAi894IhNnWQqO0+TRTQFD9nmEBozR0jyLzfz7GMMNVTw5 JdKqanv/7Pfgw== Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50e8ca6c76dso1267496e87.3; Thu, 04 Jan 2024 18:39:49 -0800 (PST) X-Gm-Message-State: AOJu0Yz8qYMVSyQkJT8khvCQ+6pWTw3g0zdTNIRqtApkCJvMuVvShQxk M8I6du+2Q2w5zB104PP/M9wLnW3811PiHSq3FTA= X-Received: by 2002:a05:6512:684:b0:50e:a8ac:8ff9 with SMTP id t4-20020a056512068400b0050ea8ac8ff9mr850695lfe.14.1704422388019; Thu, 04 Jan 2024 18:39:48 -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: Fri, 5 Jan 2024 10:39:41 +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, On Thu, Dec 28, 2023 at 9:24=E2=80=AFAM Huacai Chen = wrote: > > Hi, Youling, > > I squashed the two patches and applied here: > https://github.com/chenhuacai/linux/commits/loongarch-next > > You can verify whether everything works. With this patch applied I found there is something wrong in /proc/iomem, and I fixed it with [1], could you please help to review it? [1] https://lore.kernel.org/kexec/20231229080213.2622204-1-chenhuacai@loong= son.cn/T/#u Huacai > > 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 w= e > > can directly use the common interface to support crashkernel=3DX,[hign,= low] > > after commit 0ab97169aa05("crash_core: add generic function to do reser= vation"). > > > > With the help of newly changed function parse_crashkernel() and generic > > reserve_crashkernel_generic(), crashkernel reservation can be simplifie= d > > 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 p= assed > > 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 informatio= n. > > > > 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(= default) > > 4) crashkernel=3D4G crashkernel=3D256M,high //high=3D4G, low=3D128= M(default), high is ignored > > 5) crashkernel=3D4G crashkernel=3D256M,low //high=3D4G, low=3D128= M(default), low is ignored > > 6) crashkernel=3D4G,high //high=3D4G, low=3D128M(= default) > > 7) crashkernel=3D256M,low //low=3D0M, invalid > > 8) crashkernel=3D4G,high crashkernel=3D256M,low //high=3D4G, low=3D256= M > > 9) crashkernel=3D4G,high crashkernel=3D4G,low //high=3D0M, low=3D0M,= invalid > > 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=3D= 128M,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/i= nclude/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/setu= p.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, CR= ASH_ALIGN, CRASH_ALIGN, CRASH_ADDR_MAX); > > - if (!crash_base) { > > - pr_warn("crashkernel reservation failed - No su= itable area found.\n"); > > - return; > > - } > > - } else if (!memblock_phys_alloc_range(crash_size, CRASH_ALIGN, = crash_base, crash_base + crash_size)) { > > - pr_warn("Invalid memory region reserved for crash kerne= l\n"); > > + ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), > > + &crash_size, &crash_base, &low_size, &h= igh); > > + 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, lo= w_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 crashke= rnel\n", > > - (unsigned long)((crashk_res.end - crashk_res.st= art + 1) >> 20), > > - (unsigned long)(crashk_res.start >> 20)); > > - } > > -#endif > > } > > > > static int __init add_legacy_isa_io(struct fwnode_handle *fwnode, > > -- > > 2.40.0 > > > >