From nobody Tue Dec 16 23:26:07 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C869620C00D for ; Thu, 20 Feb 2025 16:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070287; cv=none; b=kI0iivVxVSTgxzu+7sP5MPfh/YsnCus3xNHpY+6Ts6P2xWzC4iYnKdIUtVROz6PX7TYgiNwMfuQ7iwD915pUA9g1iVLOjfG7FKB+UkB/dk4kE84yAczVRYp0/1hNTeIpsx3BKyjHc6JEJ1zJcM27y6ykp/LwHC8yMZw+//ycut0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070287; c=relaxed/simple; bh=0h4wB7rV9m4JcLwB/QCUZ4vyEivFt3z3EvUW7hE75Fg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bqwl5EdfQSTIbbj0SYtTg2yt3b7qKJ36Dtw0Ow8pdChlR2RGQMvgk1HyV3x7QLGk8PpqZf/TZBFPjB4ipMfsVBkBYE1UcbKCxwAOaABzejRXXXDLNcwoUUbX0SJcY5+f/1Bs68rHq3zXefA/KqHjLxN3vsYi4nZhku8RsD5HGMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=y/9DcSCY; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=RJDcgHbC; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=y/9DcSCY; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=RJDcgHbC; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="y/9DcSCY"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="RJDcgHbC"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="y/9DcSCY"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="RJDcgHbC" Received: from localhost (unknown [10.100.12.32]) by smtp-out1.suse.de (Postfix) with ESMTP id ADA9521186; Thu, 20 Feb 2025 16:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070283; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CYa5iwBvagWB6zghYY9Nh14wxqsIDPL4Qdse79P/EZI=; b=y/9DcSCYn3uSDLjS6D+oYnp587EhSI40JqZzMzOVKLvFci/Mu/SL4MEoaZocfvIcpybUUJ qwfdcZUj6RAIN2DDtHtHys5oZRPaY6W6gwkVw70Tjpej5pyq9m2CT9SnYHlVm3jgEXXs3n ZiyzZ824MJ12nvslxmIDL397qZ9kj80= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070283; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CYa5iwBvagWB6zghYY9Nh14wxqsIDPL4Qdse79P/EZI=; b=RJDcgHbCqcuZRFcVpxoJasXW/QFYnzDs55/Xn+vTfCmHu6yg6AU7BhmNWAlwoXWmtnFtBp imKog7j4g0ptTwBw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070283; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CYa5iwBvagWB6zghYY9Nh14wxqsIDPL4Qdse79P/EZI=; b=y/9DcSCYn3uSDLjS6D+oYnp587EhSI40JqZzMzOVKLvFci/Mu/SL4MEoaZocfvIcpybUUJ qwfdcZUj6RAIN2DDtHtHys5oZRPaY6W6gwkVw70Tjpej5pyq9m2CT9SnYHlVm3jgEXXs3n ZiyzZ824MJ12nvslxmIDL397qZ9kj80= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070283; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CYa5iwBvagWB6zghYY9Nh14wxqsIDPL4Qdse79P/EZI=; b=RJDcgHbCqcuZRFcVpxoJasXW/QFYnzDs55/Xn+vTfCmHu6yg6AU7BhmNWAlwoXWmtnFtBp imKog7j4g0ptTwBw== Date: Thu, 20 Feb 2025 17:51:23 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: Philipp Rudo , Donald Dutile , Pingfan Liu , Tao Liu , linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko Subject: [PATCH v2 1/5] Add a new optional ",cma" suffix to the crashkernel= command line option Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Level: X-Spamd-Result: default: False [-4.26 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.16)[-0.791]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,localhost:helo] X-Spam-Score: -4.26 X-Spam-Flag: NO Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new cma_size parameter to parse_crashkernel(). When not NULL, call __parse_crashkernel to parse the CMA reservation size from "crashkernel=3Dsize,cma" and store it in cma_size. Set cma_size to NULL in all calls to parse_crashkernel(). Signed-off-by: Jiri Bohac --- arch/arm/kernel/setup.c | 2 +- arch/arm64/mm/init.c | 2 +- arch/loongarch/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 2 +- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kexec/core.c | 2 +- arch/powerpc/mm/nohash/kaslr_booke.c | 2 +- arch/riscv/mm/init.c | 2 +- arch/s390/kernel/setup.c | 2 +- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/kernel/setup.c | 2 +- include/linux/crash_reserve.h | 3 ++- kernel/crash_reserve.c | 22 +++++++++++++++++----- 13 files changed, 30 insertions(+), 17 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index a41c93988d2c..0bfd66c7ada0 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1004,7 +1004,7 @@ static void __init reserve_crashkernel(void) total_mem =3D get_total_mem(); ret =3D parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base, - NULL, NULL); + NULL, NULL, NULL); /* invalid value specified or crashkernel=3D0 */ if (ret || !crash_size) return; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9c0b8d9558fc..06bf216a4b0d 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -107,7 +107,7 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), &crash_size, &crash_base, - &low_size, &high); + &low_size, NULL, &high); if (ret) return; =20 diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index edcfdfcad7d2..ffdfb5407043 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -266,7 +266,7 @@ static void __init arch_reserve_crashkernel(void) return; =20 ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), - &crash_size, &crash_base, &low_size, &high); + &crash_size, &crash_base, &low_size, NULL, &high); if (ret) return; =20 diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index fbfe0771317e..11b9b6b63e19 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -458,7 +458,7 @@ static void __init mips_parse_crashkernel(void) total_mem =3D memblock_phys_mem_size(); ret =3D parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base, - NULL, NULL); + NULL, NULL, NULL); if (ret !=3D 0 || crash_size <=3D 0) return; =20 diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index 4b371c738213..f90aaa2263aa 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -334,7 +334,7 @@ static __init u64 fadump_calculate_reserve_size(void) * memory at a predefined offset. */ ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &size, &base, NULL, NULL); + &size, &base, NULL, NULL, NULL); if (ret =3D=3D 0 && size > 0) { unsigned long max_size; =20 diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index 58a930a47422..35f92427d282 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -66,7 +66,7 @@ void __init reserve_crashkernel(void) total_mem_sz =3D memory_limit ? memory_limit : memblock_phys_mem_size(); /* use common parsing */ ret =3D parse_crashkernel(boot_command_line, total_mem_sz, - &crash_size, &crash_base, NULL, NULL); + &crash_size, &crash_base, NULL, NULL, NULL); if (ret =3D=3D 0 && crash_size > 0) { crashk_res.start =3D crash_base; crashk_res.end =3D crash_base + crash_size - 1; diff --git a/arch/powerpc/mm/nohash/kaslr_booke.c b/arch/powerpc/mm/nohash/= kaslr_booke.c index 5c8d1bb98b3e..5e4897daaaea 100644 --- a/arch/powerpc/mm/nohash/kaslr_booke.c +++ b/arch/powerpc/mm/nohash/kaslr_booke.c @@ -178,7 +178,7 @@ static void __init get_crash_kernel(void *fdt, unsigned= long size) int ret; =20 ret =3D parse_crashkernel(boot_command_line, size, &crash_size, - &crash_base, NULL, NULL); + &crash_base, NULL, NULL, NULL); if (ret !=3D 0 || crash_size =3D=3D 0) return; if (crash_base =3D=3D 0) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 15b2eda4c364..9634a800629b 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1405,7 +1405,7 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), &crash_size, &crash_base, - &low_size, &high); + &low_size, NULL, &high); if (ret) return; =20 diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index d78bcfe707b5..4d9b5b5d0cb2 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -607,7 +607,7 @@ static void __init reserve_crashkernel(void) int rc; =20 rc =3D parse_crashkernel(boot_command_line, ident_map_size, - &crash_size, &crash_base, NULL, NULL); + &crash_size, &crash_base, NULL, NULL, NULL); =20 crash_base =3D ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN); crash_size =3D ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN); diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c index 8321b31d2e19..37073ca1e0ad 100644 --- a/arch/sh/kernel/machine_kexec.c +++ b/arch/sh/kernel/machine_kexec.c @@ -146,7 +146,7 @@ void __init reserve_crashkernel(void) return; =20 ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), - &crash_size, &crash_base, NULL, NULL); + &crash_size, &crash_base, NULL, NULL, NULL); if (ret =3D=3D 0 && crash_size > 0) { crashk_res.start =3D crash_base; crashk_res.end =3D crash_base + crash_size - 1; diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index cebee310e200..853afde761a7 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -481,7 +481,7 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), &crash_size, &crash_base, - &low_size, &high); + &low_size, NULL, &high); if (ret) return; =20 diff --git a/include/linux/crash_reserve.h b/include/linux/crash_reserve.h index 5a9df944fb80..a681f265a361 100644 --- a/include/linux/crash_reserve.h +++ b/include/linux/crash_reserve.h @@ -16,7 +16,8 @@ extern struct resource crashk_low_res; =20 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base, - unsigned long long *low_size, bool *high); + unsigned long long *low_size, unsigned long long *cma_size, + bool *high); =20 #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION #ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index a620fb4b2116..e72a9c897694 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -172,17 +172,19 @@ static int __init parse_crashkernel_simple(char *cmdl= ine, =20 #define SUFFIX_HIGH 0 #define SUFFIX_LOW 1 -#define SUFFIX_NULL 2 +#define SUFFIX_CMA 2 +#define SUFFIX_NULL 3 static __initdata char *suffix_tbl[] =3D { - [SUFFIX_HIGH] =3D ",high", - [SUFFIX_LOW] =3D ",low", - [SUFFIX_NULL] =3D NULL, + [SUFFIX_HIGH] =3D ",high", + [SUFFIX_LOW] =3D ",low", + [SUFFIX_CMA] =3D ",cma", + [SUFFIX_NULL] =3D NULL, }; =20 /* * That function parses "suffix" crashkernel command lines like * - * crashkernel=3Dsize,[high|low] + * crashkernel=3Dsize,[high|low|cma] * * It returns 0 on success and -EINVAL on failure. */ @@ -298,9 +300,11 @@ int __init parse_crashkernel(char *cmdline, unsigned long long *crash_size, unsigned long long *crash_base, unsigned long long *low_size, + unsigned long long *cma_size, bool *high) { int ret; + unsigned long long __always_unused cma_base; =20 /* crashkernel=3DX[@offset] */ ret =3D __parse_crashkernel(cmdline, system_ram, crash_size, @@ -331,6 +335,14 @@ int __init parse_crashkernel(char *cmdline, =20 *high =3D true; } + + /* + * optional CMA reservation + * cma_base is ignored + */ + if (cma_size) + __parse_crashkernel(cmdline, 0, cma_size, + &cma_base, suffix_tbl[SUFFIX_CMA]); #endif if (!*crash_size) ret =3D -EINVAL; --=20 Jiri Bohac SUSE Labs, Prague, Czechia From nobody Tue Dec 16 23:26:07 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A68A214A72 for ; Thu, 20 Feb 2025 16:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070359; cv=none; b=uePjsQM6leyl93qye8uXPwO8/95EOurfuuuNMirKkei8cVZdevHZ4NOqHbAkT8SqpsRdE6r1mBCNc+DNhOxWkM3+4+Y24otBWUHqMyJUEFUYW1+y1z5LXx9tDxKUdMQm9jSEw1ECt1KRv5e5L1IUYlCTRvaqgIsHiX/UI12erWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070359; c=relaxed/simple; bh=6ZGEY1CUTUb9hIZs02aQ9APntILoEmml24syPbtm05w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K3bzZNix9TkSCZwGpW8KpZYHCPTg5+D9SN0CqqpdLZ17KLpDIhYIMNyuN47H+/w5UBrM8aJRQDKx/D1hru2a5c89h0P/DB+4mmkuaJCR6qWsSiUcjbEwI9YyOY2yBS7l9XFBp9yTPgOS90cRymg9NDmhW/dd3h+26upYosSmQ3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=vR7l+TDF; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=7zjXn4G4; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=vR7l+TDF; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=7zjXn4G4; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="vR7l+TDF"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="7zjXn4G4"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="vR7l+TDF"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="7zjXn4G4" Received: from localhost (unknown [10.100.12.32]) by smtp-out1.suse.de (Postfix) with ESMTP id B9A6221186; Thu, 20 Feb 2025 16:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hH9uSFhc8XNqgswkvUUEW9uh5z40NPrJwxzIGYRAvqU=; b=vR7l+TDFHoQkJcuzxpxWN12po112UZHuh6/OAATx4v9jBC9K9qy6mIAmm+LWAuBAK82iFZ SwDNsyO4jC7Rk/W89RhamlC+MXPERH2UtMnj23slI8py9ZKNqSDanS1JQYb68bY82WOuHp dTaoB8ckoNaLpJYYbytYXiuFO+N8hpE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hH9uSFhc8XNqgswkvUUEW9uh5z40NPrJwxzIGYRAvqU=; b=7zjXn4G4ZCuWjVS5/GJCXpVdrmZ3Aa1fUFf1swFrLtFv7JmkHLXPMd9XuUUBr1+M8LQeKn DjLfbLTdD0epgKCA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hH9uSFhc8XNqgswkvUUEW9uh5z40NPrJwxzIGYRAvqU=; b=vR7l+TDFHoQkJcuzxpxWN12po112UZHuh6/OAATx4v9jBC9K9qy6mIAmm+LWAuBAK82iFZ SwDNsyO4jC7Rk/W89RhamlC+MXPERH2UtMnj23slI8py9ZKNqSDanS1JQYb68bY82WOuHp dTaoB8ckoNaLpJYYbytYXiuFO+N8hpE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hH9uSFhc8XNqgswkvUUEW9uh5z40NPrJwxzIGYRAvqU=; b=7zjXn4G4ZCuWjVS5/GJCXpVdrmZ3Aa1fUFf1swFrLtFv7JmkHLXPMd9XuUUBr1+M8LQeKn DjLfbLTdD0epgKCA== Date: Thu, 20 Feb 2025 17:52:35 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: Philipp Rudo , Donald Dutile , Pingfan Liu , Tao Liu , linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko Subject: [PATCH v2 2/5] kdump: implement reserve_crashkernel_cma Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Score: -4.26 X-Spamd-Result: default: False [-4.26 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.16)[-0.776]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,localhost:helo] X-Spam-Flag: NO X-Spam-Level: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" reserve_crashkernel_cma() reserves CMA ranges for the crash kernel. If allocating the requested size fails, try to reserve in smaller blocks. Store the reserved ranges in the crashk_cma_ranges array and the number of ranges in crashk_cma_cnt. --- include/linux/crash_reserve.h | 12 +++++++++ kernel/crash_reserve.c | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/linux/crash_reserve.h b/include/linux/crash_reserve.h index a681f265a361..97964f2a583d 100644 --- a/include/linux/crash_reserve.h +++ b/include/linux/crash_reserve.h @@ -13,12 +13,24 @@ */ extern struct resource crashk_res; extern struct resource crashk_low_res; +extern struct range crashk_cma_ranges[]; +#if defined(CONFIG_CMA) && defined(CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RES= ERVATION) +#define CRASHKERNEL_CMA +#define CRASHKERNEL_CMA_RANGES_MAX 4 +extern int crashk_cma_cnt; +#else +#define crashk_cma_cnt 0 +#define CRASHKERNEL_CMA_RANGES_MAX 0 +#endif + =20 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base, unsigned long long *low_size, unsigned long long *cma_size, bool *high); =20 +void __init reserve_crashkernel_cma(unsigned long long cma_size); + #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION #ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index e72a9c897694..d71aff19a28d 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include =20 #include #include @@ -470,6 +472,53 @@ void __init reserve_crashkernel_generic(char *cmdline, #endif } =20 +struct range crashk_cma_ranges[CRASHKERNEL_CMA_RANGES_MAX]; +#ifdef CRASHKERNEL_CMA +int crashk_cma_cnt =3D 0; +void __init reserve_crashkernel_cma(unsigned long long cma_size) +{ + unsigned long long request_size =3D roundup(cma_size, PAGE_SIZE); + unsigned long long reserved_size =3D 0; + + while (cma_size > reserved_size && + crashk_cma_cnt < CRASHKERNEL_CMA_RANGES_MAX) { + + struct cma *res; + + if (cma_declare_contiguous(0, request_size, 0, 0, 0, false, + "crashkernel", &res)) { + /* reservation failed, try half-sized blocks */ + if (request_size <=3D PAGE_SIZE) + break; + + request_size =3D roundup(request_size / 2, PAGE_SIZE); + continue; + } + + crashk_cma_ranges[crashk_cma_cnt].start =3D cma_get_base(res); + crashk_cma_ranges[crashk_cma_cnt].end =3D + crashk_cma_ranges[crashk_cma_cnt].start + + cma_get_size(res) - 1; + ++crashk_cma_cnt; + reserved_size +=3D request_size; + } + + if (cma_size > reserved_size) + pr_warn("crashkernel CMA reservation failed: %lld MB requested, %lld MB = reserved in %d ranges\n", + cma_size >> 20, reserved_size >> 20, crashk_cma_cnt); + else + pr_info("crashkernel CMA reserved: %lld MB in %d ranges\n", + reserved_size >> 20, crashk_cma_cnt); +} + +#else /* CRASHKERNEL_CMA */ +void __init reserve_crashkernel_cma(unsigned long long cma_size) +{ + if (cma_size) + pr_warn("crashkernel CMA reservation not supported\n"); +} +#endif + #ifndef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY static __init int insert_crashkernel_resources(void) { --=20 Jiri Bohac SUSE Labs, Prague, Czechia From nobody Tue Dec 16 23:26:07 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 279FD17A2F0 for ; Thu, 20 Feb 2025 16:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070467; cv=none; b=mzqulfE1sbIVI9/sbHV8vLfPOzOzD3HzDEXJOY1qAlJJzdGQ/ZJ4tAcrE3tPEw2Bs5m8NRoeHnkf3h9Voy0T7NIy7C4ADcF7/oNxMjYkepjqC3KjsCKgqvB7U+Qs4Y6BIKm+epjCs1zvFc53orFawQ5s+UvxCoNvuczp92StL7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070467; c=relaxed/simple; bh=ci26Mu8FbxdZmJKduMzpDrDy7ncCG3jMAOBwVjjOSvM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=raJGWPn13BYsJXRzMCCvRqWuiaFi4JQHt/fOs2zmI2H/HPwOB93QdBIGp60F7PPBovXyibZrHF3idEfPQML8YSrAa2yTY5SuexkZe4kUoXx1FOYbTvjtoqM3EE73lSSqbHfBQIzTlghI4cIkjRGxz1BxtmXT2TPIUoAagLsy2Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=XTMerqX0; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=eaoodYHM; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=XTMerqX0; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=eaoodYHM; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="XTMerqX0"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="eaoodYHM"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="XTMerqX0"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="eaoodYHM" Received: from localhost (unknown [10.100.12.32]) by smtp-out1.suse.de (Postfix) with ESMTP id 7976721186; Thu, 20 Feb 2025 16:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070464; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wakkuwf1ugz5t/UIuNizagYe9kFHhtgEfpZOsreDN3A=; b=XTMerqX0GICjNsYCmpT3d86Y5d/iCOx3eeIgF+zW9pC0xqJUBLi1xpGj28SIdC6SbeWbMa 7NpY3W4Q9XcH8kNohCHJQ5QQWWzOPd1txXDLDLIIh5qQmdD73YynIG3U3SSssZMdl78yqh Uc7N/GG8qI0ZFM7ZFs7VsucAXvt/wCU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070464; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wakkuwf1ugz5t/UIuNizagYe9kFHhtgEfpZOsreDN3A=; b=eaoodYHMSTrDFPSZZoxEeoyhBJcAyVrRgb032l5UFSC5tZ7yzLRtWRtBEwYIhzM6LA/9La Q5TByx/Su9H0/ZDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070464; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wakkuwf1ugz5t/UIuNizagYe9kFHhtgEfpZOsreDN3A=; b=XTMerqX0GICjNsYCmpT3d86Y5d/iCOx3eeIgF+zW9pC0xqJUBLi1xpGj28SIdC6SbeWbMa 7NpY3W4Q9XcH8kNohCHJQ5QQWWzOPd1txXDLDLIIh5qQmdD73YynIG3U3SSssZMdl78yqh Uc7N/GG8qI0ZFM7ZFs7VsucAXvt/wCU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070464; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wakkuwf1ugz5t/UIuNizagYe9kFHhtgEfpZOsreDN3A=; b=eaoodYHMSTrDFPSZZoxEeoyhBJcAyVrRgb032l5UFSC5tZ7yzLRtWRtBEwYIhzM6LA/9La Q5TByx/Su9H0/ZDw== Date: Thu, 20 Feb 2025 17:54:24 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: Philipp Rudo , Donald Dutile , Pingfan Liu , Tao Liu , linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko Subject: [PATCH v2 3/5] kdump, documentation: describe craskernel CMA reservation Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Score: -4.26 X-Spamd-Result: default: False [-4.26 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.16)[-0.785]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,localhost:helo] X-Spam-Flag: NO X-Spam-Level: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Describe the new crashkernel ",cma" suffix in Documentation/ --- Documentation/admin-guide/kdump/kdump.rst | 19 +++++++++++++++++-- .../admin-guide/kernel-parameters.txt | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kdump/kdump.rst b/Documentation/admi= n-guide/kdump/kdump.rst index 5376890adbeb..3f7ff301c604 100644 --- a/Documentation/admin-guide/kdump/kdump.rst +++ b/Documentation/admin-guide/kdump/kdump.rst @@ -213,8 +213,7 @@ Dump-capture kernel config options (Arch Dependent, i38= 6 and x86_64) kernel. =20 Otherwise it should be the start of memory region reserved for - second kernel using boot parameter "crashkernel=3DY@X". Here X is - start of memory region reserved for dump-capture kernel. + second kernel using boot parameter "crashkernel=3DY@X". Here X is start= of memory region reserved for dump-capture kernel. Generally X is 16MB (0x1000000). So you can set CONFIG_PHYSICAL_START=3D0x1000000 =20 @@ -315,6 +314,22 @@ crashkernel syntax =20 crashkernel=3D0,low =20 +4) crashkernel=3Dsize,cma + + Reserves additional memory from CMA. A standard crashkernel reservation= , as + described above, is still needed, but can be just big enough to hold the + kernel and initrd. All the memory the crash kernel needs for its runtim= e and + for running the kdump userspace processes can be provided by this CMA + reservation, re-using memory available to the production system's users= pace. + Because of this, the CMA reservation should not be used if kdump is con= figured + to dump userspace memory - the re-used memory ranges won't be in the vm= core. + + This option increases the risk of a kdump failure: DMA transfers config= ured + by the first kernel may end up corrupting the second kernel's memory. T= his + reservation method is intended for systems that can't afford to sacrifi= ce + enough memory for standard crashkernel reservation and where less relia= ble + kdump is preferrable to no kdump at all. + Boot into System Kernel ----------------------- 1) Update the boot loader (such as grub, yaboot, or lilo) configuration diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index fb8752b42ec8..ea4d53435515 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -987,6 +987,20 @@ 0: to disable low allocation. It will be ignored when crashkernel=3DX,high is not used or memory reserved is below 4G. + crashkernel=3Dsize[KMG],cma + [KNL, X86] Reserve additional crash kernel memory from CMA. + This reservation is usable by the first system's userspace, + so this should not be used if dumping of userspace + memory is intended. A standard crashkernel reservation, + as described above, is still needed to hold the crash + kernel and initrd. + This option increases the risk of a kdump failure: DMA + transfers configured by the first kernel may end up + corrupting the second kernel's memory. This reservation + method is intended for systems that can't afford to + sacrifice enough memory for standard crashkernel + reservation and where less reliable kdump is preferrable=20 + to no kdump at all. =20 cryptomgr.notests [KNL] Disable crypto self-tests --=20 Jiri Bohac SUSE Labs, Prague, Czechia From nobody Tue Dec 16 23:26:07 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F8D721147F for ; Thu, 20 Feb 2025 16:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070556; cv=none; b=Bid8sW9oU1Bg59vplElpLCIDDnQPlWL/VpOI7+WFeG83j8hGEHwfaxYnhUWBZivfjx++RlpZ3U9wnH4fwdG8MrIB5Dd/7vljBFN/cXxHBxK0uHbyDVBMMGNPi8SyqSHEnP+V1VM2CF0vaohmtYConhCZrENwii+VV2Z/Cxf6iME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070556; c=relaxed/simple; bh=GQw3DwUWY+xaH6GbjJy2rGyxm2XeVwB6yo01yP+V1qQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ukAQFwjDaQ9vGBlVsas1fW4nmy+VGArj8odnLhsg+leoBFFUXkPK3WPESubuynKon8Axg+05u3BKbDSgWD2b2mdBaB23l5F4qumiBPzIoPerlLmns/BS8KchgXXInKu6Wy0B2o0omDrGBiRqLuBc6zHzIXHMfCIskxQo0jIjcro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=t69T0NAT; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=8GLOAiAw; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=t69T0NAT; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=8GLOAiAw; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="t69T0NAT"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="8GLOAiAw"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="t69T0NAT"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="8GLOAiAw" Received: from localhost (unknown [10.100.12.32]) by smtp-out1.suse.de (Postfix) with ESMTP id A1BBB21186; Thu, 20 Feb 2025 16:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070552; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Zg9TqkBWUtlYqKI0kTqM9WGsbClJXO8S/5dxvIXqVjg=; b=t69T0NATPpXZOU2SA8VYkNz0WUA60d7ENH3ZlMqKl+QcuykmdEThkCXST2Sl+3Z+3avg0K wBktJb7Iuy7TEVa9EVp5y17DJJJNISQDUUMEGJD1r1s2BFFtYhvOvFh8h/HDfLp5wGxW0i rrO6jxlXRHRkOp/lEHfOPRo0ZNFdaag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070552; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Zg9TqkBWUtlYqKI0kTqM9WGsbClJXO8S/5dxvIXqVjg=; b=8GLOAiAwgV61PAlnDUgNuZ79byMhByQu4gP4ibAQQGNRevOWgppNYgBu893Erf64B16Ktn 1ouARot+VJXZ8hCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070552; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Zg9TqkBWUtlYqKI0kTqM9WGsbClJXO8S/5dxvIXqVjg=; b=t69T0NATPpXZOU2SA8VYkNz0WUA60d7ENH3ZlMqKl+QcuykmdEThkCXST2Sl+3Z+3avg0K wBktJb7Iuy7TEVa9EVp5y17DJJJNISQDUUMEGJD1r1s2BFFtYhvOvFh8h/HDfLp5wGxW0i rrO6jxlXRHRkOp/lEHfOPRo0ZNFdaag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070552; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Zg9TqkBWUtlYqKI0kTqM9WGsbClJXO8S/5dxvIXqVjg=; b=8GLOAiAwgV61PAlnDUgNuZ79byMhByQu4gP4ibAQQGNRevOWgppNYgBu893Erf64B16Ktn 1ouARot+VJXZ8hCw== Date: Thu, 20 Feb 2025 17:55:52 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: Philipp Rudo , Donald Dutile , Pingfan Liu , Tao Liu , linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko Subject: [PATCH v2 4/5] kdump: wait for DMA to finish when using CMA Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Level: X-Spamd-Result: default: False [-4.26 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.16)[-0.782]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[localhost:helo,suse.cz:email,dwarf.suse.cz:mid] X-Spam-Score: -4.26 X-Spam-Flag: NO Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When re-using the CMA area for kdump there is a risk of pending DMA into pinned user pages in the CMA area. Pages that are pinned long-term are migrated away from CMA, so these are no= t a concern. Pages pinned without FOLL_LONGTERM remain in the CMA and may possi= bly be the source or destination of a pending DMA transfer. Although there is no clear specification how long a page may be pinned with= out FOLL_LONGTERM, pinning without the flag shows an intent of the caller to only use the memory for short-lived DMA transfers, not a transfer initiated by a device asynchronously at a random time in the future. Add a delay of CMA_DMA_TIMEOUT_MSEC milliseconds before starting the kdump kernel, giving such short-lived DMA transfers time to finish before the CMA memory is re-used by the kdump kernel. Set CMA_DMA_TIMEOUT_MSEC to 1000 (one second) - chosen arbitrarily as both a huge margin for a DMA transfer, yet not increasing the kdump time significantly. Signed-off-by: Jiri Bohac --- include/linux/crash_core.h | 5 +++++ kernel/crash_core.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index 44305336314e..543e4a71f13c 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -56,6 +56,11 @@ static inline unsigned int crash_get_elfcorehdr_size(voi= d) { return 0; } /* Alignment required for elf header segment */ #define ELF_CORE_HEADER_ALIGN 4096 =20 +/* Time to wait for possible DMA to finish before starting the kdump kernel + * when a CMA reservation is used + */ +#define CMA_DMA_TIMEOUT_MSEC 1000 + extern int crash_exclude_mem_range(struct crash_mem *mem, unsigned long long mstart, unsigned long long mend); diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 078fe5bc5a74..543e509b7926 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include #include @@ -97,6 +98,14 @@ int kexec_crash_loaded(void) } EXPORT_SYMBOL_GPL(kexec_crash_loaded); =20 +static void crash_cma_clear_pending_dma(void) +{ + if (!crashk_cma_cnt) + return; + + mdelay(CMA_DMA_TIMEOUT_MSEC); +} + /* * No panic_cpu check version of crash_kexec(). This function is called * only when panic_cpu holds the current CPU number; this is the only CPU @@ -116,6 +125,7 @@ void __noclone __crash_kexec(struct pt_regs *regs) if (kexec_crash_image) { struct pt_regs fixed_regs; =20 + crash_cma_clear_pending_dma(); crash_setup_regs(&fixed_regs, regs); crash_save_vmcoreinfo(); machine_crash_shutdown(&fixed_regs); --=20 Jiri Bohac SUSE Labs, Prague, Czechia From nobody Tue Dec 16 23:26:07 2025 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 322641D5CDD for ; Thu, 20 Feb 2025 16:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070659; cv=none; b=pVyLb/qYUZ/mt4Regoe3jI2I9CmNJ+tE+pb/9k8dddzMNYIdMoSrexQ23EL2DLetYY2MF17F/ywJnTeaZWFXziEgatoETW4rHkO0SDFUkx1E7brcsURt6ZMu96gNyxCtS6UxZut1hwtkiXSLW5EJbeJg9FcYEiuuqV6w84Jvuz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740070659; c=relaxed/simple; bh=XKX4Aucp/sBQshrMZR2LOMDydJSQWtIZFAAPJdcspIo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HmR4ZFUU7UffkAR7X+m27f9PJpr+ec/5SgphOkkc7mx0vy2JX8uehkaVNkis9fcdDIAgRIrjYr//BMCCR9jmPVTwCpmeVfTIZNz7bCsJxGMBFANw5aPT55B3O2ySTiANXsXY+RhNIONfURwOyzPL7vLGLBI1Or/bnExYThgY6wA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=WRAG8TLS; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=3qcjb+yB; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=WRAG8TLS; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=3qcjb+yB; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="WRAG8TLS"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="3qcjb+yB"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="WRAG8TLS"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="3qcjb+yB" Received: from localhost (unknown [10.100.12.32]) by smtp-out1.suse.de (Postfix) with ESMTP id 45FF721174; Thu, 20 Feb 2025 16:57:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AAje/oszgqXSx3kWAldq5HwVj5OdtILzxGPWJh8nXcM=; b=WRAG8TLSypGQ5C466jsiybvF2rx1BbQ4YXGiULc5T1WjBBMQMMS52pS4+K2TNj/zsPM2sn JuR6P5Qp3ib3PiWZf+v9N2AknxrG6LY+d9zj+cYuUNA8nul5lVGymKdByh3HwYuZtqhCwQ mRPI/hNfy6iyTcAa49pm0LCISTL8XAQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AAje/oszgqXSx3kWAldq5HwVj5OdtILzxGPWJh8nXcM=; b=3qcjb+yB67/aGGYDFCnH2i57/Z4h7UfX8KLx9GCpinpge687TQPf0+n8Khrc12fdlN1TK7 tO/2SgvjOlBWMcBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1740070656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AAje/oszgqXSx3kWAldq5HwVj5OdtILzxGPWJh8nXcM=; b=WRAG8TLSypGQ5C466jsiybvF2rx1BbQ4YXGiULc5T1WjBBMQMMS52pS4+K2TNj/zsPM2sn JuR6P5Qp3ib3PiWZf+v9N2AknxrG6LY+d9zj+cYuUNA8nul5lVGymKdByh3HwYuZtqhCwQ mRPI/hNfy6iyTcAa49pm0LCISTL8XAQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1740070656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AAje/oszgqXSx3kWAldq5HwVj5OdtILzxGPWJh8nXcM=; b=3qcjb+yB67/aGGYDFCnH2i57/Z4h7UfX8KLx9GCpinpge687TQPf0+n8Khrc12fdlN1TK7 tO/2SgvjOlBWMcBg== Date: Thu, 20 Feb 2025 17:57:36 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: Philipp Rudo , Donald Dutile , Pingfan Liu , Tao Liu , linux-kernel@vger.kernel.org, David Hildenbrand , Michal Hocko Subject: [PATCH v2 5/5] x86: implement crashkernel cma reservation Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Level: X-Spamd-Result: default: False [-4.26 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.16)[-0.782]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,localhost:helo,dwarf.suse.cz:mid] X-Spam-Score: -4.26 X-Spam-Flag: NO Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the crashkernel CMA reservation for x86: - enable parsing of the cma suffix by parse_crashkernel() - reserve memory with reserve_crashkernel_cma() - add the CMA-reserved ranges to the e820 map for the crash kernel - exclude the CMA-reserved ranges from vmcore Signed-off-by: Jiri Bohac --- arch/x86/kernel/crash.c | 26 ++++++++++++++++++++++---- arch/x86/kernel/setup.c | 5 +++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 340af8155658..70823fa9abea 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -163,10 +163,10 @@ static struct crash_mem *fill_up_crash_elf_data(void) return NULL; =20 /* - * Exclusion of crash region and/or crashk_low_res may cause - * another range split. So add extra two slots here. + * Exclusion of crash region, crashk_low_res and/or crashk_cma_ranges + * may cause range splits. So add extra slots here. */ - nr_ranges +=3D 2; + nr_ranges +=3D 2 + crashk_cma_cnt; cmem =3D vzalloc(struct_size(cmem, ranges, nr_ranges)); if (!cmem) return NULL; @@ -184,6 +184,7 @@ static struct crash_mem *fill_up_crash_elf_data(void) static int elf_header_exclude_ranges(struct crash_mem *cmem) { int ret =3D 0; + int i; =20 /* Exclude the low 1M because it is always reserved */ ret =3D crash_exclude_mem_range(cmem, 0, SZ_1M - 1); @@ -198,8 +199,17 @@ static int elf_header_exclude_ranges(struct crash_mem = *cmem) if (crashk_low_res.end) ret =3D crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); + if (ret) + return ret; =20 - return ret; + for (i =3D 0; i < crashk_cma_cnt; ++i) { + ret =3D crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start, + crashk_cma_ranges[i].end); + if (ret) + return ret; + } + + return 0; } =20 static int prepare_elf64_ram_headers_callback(struct resource *res, void *= arg) @@ -352,6 +362,14 @@ int crash_setup_memmap_entries(struct kimage *image, s= truct boot_params *params) add_e820_entry(params, &ei); } =20 + for (i =3D 0; i < crashk_cma_cnt; ++i) { + ei.addr =3D crashk_cma_ranges[i].start; + ei.size =3D crashk_cma_ranges[i].end - + crashk_cma_ranges[i].start + 1; + ei.type =3D E820_TYPE_RAM; + add_e820_entry(params, &ei); + } + out: vfree(cmem); return ret; diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 853afde761a7..90e10a18f0c9 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -471,7 +471,7 @@ static void __init memblock_x86_reserve_range_setup_dat= a(void) =20 static void __init arch_reserve_crashkernel(void) { - unsigned long long crash_base, crash_size, low_size =3D 0; + unsigned long long crash_base, crash_size, low_size =3D 0, cma_size =3D 0; char *cmdline =3D boot_command_line; bool high =3D false; int ret; @@ -481,7 +481,7 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), &crash_size, &crash_base, - &low_size, NULL, &high); + &low_size, &cma_size, &high); if (ret) return; =20 @@ -492,6 +492,7 @@ static void __init arch_reserve_crashkernel(void) =20 reserve_crashkernel_generic(cmdline, crash_size, crash_base, low_size, high); + reserve_crashkernel_cma(cma_size); } =20 static struct resource standard_io_resources[] =3D { --=20 Jiri Bohac SUSE Labs, Prague, Czechia