All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Tao Liu <ltao@redhat.com>
Cc: vgoyal@redhat.com, dyoung@redhat.com, kexec@lists.infradead.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCH v2] kdump: round up the total memory size to 128M for crashkernel reservation
Date: Mon, 27 Jun 2022 18:35:43 +0800	[thread overview]
Message-ID: <YrmH/728erRohHeU@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20220627074440.187222-1-ltao@redhat.com>

On 06/27/22 at 03:44pm, Tao Liu wrote:
> The total memory size we get in kernel is usually slightly less than
> the actual memory size because BIOS/firmware will reserve some memory
> region. So it won't export all memory as usable.
> 
> E.g, on my x86_64 kvm guest with 1G memory, the total_mem value shows:
> UEFI boot with ovmf:   0x3faef000
> Legacy boot kvm guest: 0x3ff7ec00
> 
> When specifying crashkernel=1G-2G:128M, if we have a 1G memory machine,
> we get total size 1023M from firmware. Then it will not fall into
> 1G-2G, thus no memory reserved. User will never know this, it is hard
> to let user know the exact total value in kernel.
> 
> One way is to use dmi/smbios to get physical memory size, but it's not
> reliable as well. According to Prarit hardware vendors sometimes screw
> this up. Thus round up total size to 128M to work around this problem.
> 
> This patch is a resend of [1] and rebased onto v5.19-rc2, and the
> original credit goes to Dave Young <dyoung@redhat.com>.

This should be put into cover letter, or put together with change log.
Other than this, LGTM,

Acked-by: Baoquan He <bhe@redhat.com>

> 
> [1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html
> 
> Signed-off-by: Tao Liu <ltao@redhat.com>
> ---
> v1 -> v2:
> Modified commit log based on Baoquan's advice.
> ---
>  kernel/crash_core.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index 71122e01623c..b58b27cbdb61 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -9,6 +9,7 @@
>  #include <linux/init.h>
>  #include <linux/utsname.h>
>  #include <linux/vmalloc.h>
> +#include <linux/sizes.h>
>  
>  #include <asm/page.h>
>  #include <asm/sections.h>
> @@ -43,6 +44,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
>  					unsigned long long *crash_base)
>  {
>  	char *cur = cmdline, *tmp;
> +	unsigned long long total_mem = system_ram;
> +
> +	/*
> +	 * Firmware sometimes reserves some memory regions for its own use,
> +	 * so the system memory size is less than the actual physical memory
> +	 * size. Work around this by rounding up the total size to 128M,
> +	 * which is enough for most test cases.
> +	 */
> +	total_mem = roundup(total_mem, SZ_128M);
>  
>  	/* for each entry of the comma-separated list */
>  	do {
> @@ -87,13 +97,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
>  			return -EINVAL;
>  		}
>  		cur = tmp;
> -		if (size >= system_ram) {
> +		if (size >= total_mem) {
>  			pr_warn("crashkernel: invalid size\n");
>  			return -EINVAL;
>  		}
>  
>  		/* match ? */
> -		if (system_ram >= start && system_ram < end) {
> +		if (total_mem >= start && total_mem < end) {
>  			*crash_size = size;
>  			break;
>  		}
> -- 
> 2.33.1
> 


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Tao Liu <ltao@redhat.com>
Cc: vgoyal@redhat.com, dyoung@redhat.com, kexec@lists.infradead.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCH v2] kdump: round up the total memory size to 128M for crashkernel reservation
Date: Mon, 27 Jun 2022 18:35:43 +0800	[thread overview]
Message-ID: <YrmH/728erRohHeU@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20220627074440.187222-1-ltao@redhat.com>

On 06/27/22 at 03:44pm, Tao Liu wrote:
> The total memory size we get in kernel is usually slightly less than
> the actual memory size because BIOS/firmware will reserve some memory
> region. So it won't export all memory as usable.
> 
> E.g, on my x86_64 kvm guest with 1G memory, the total_mem value shows:
> UEFI boot with ovmf:   0x3faef000
> Legacy boot kvm guest: 0x3ff7ec00
> 
> When specifying crashkernel=1G-2G:128M, if we have a 1G memory machine,
> we get total size 1023M from firmware. Then it will not fall into
> 1G-2G, thus no memory reserved. User will never know this, it is hard
> to let user know the exact total value in kernel.
> 
> One way is to use dmi/smbios to get physical memory size, but it's not
> reliable as well. According to Prarit hardware vendors sometimes screw
> this up. Thus round up total size to 128M to work around this problem.
> 
> This patch is a resend of [1] and rebased onto v5.19-rc2, and the
> original credit goes to Dave Young <dyoung@redhat.com>.

This should be put into cover letter, or put together with change log.
Other than this, LGTM,

Acked-by: Baoquan He <bhe@redhat.com>

> 
> [1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html
> 
> Signed-off-by: Tao Liu <ltao@redhat.com>
> ---
> v1 -> v2:
> Modified commit log based on Baoquan's advice.
> ---
>  kernel/crash_core.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index 71122e01623c..b58b27cbdb61 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -9,6 +9,7 @@
>  #include <linux/init.h>
>  #include <linux/utsname.h>
>  #include <linux/vmalloc.h>
> +#include <linux/sizes.h>
>  
>  #include <asm/page.h>
>  #include <asm/sections.h>
> @@ -43,6 +44,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
>  					unsigned long long *crash_base)
>  {
>  	char *cur = cmdline, *tmp;
> +	unsigned long long total_mem = system_ram;
> +
> +	/*
> +	 * Firmware sometimes reserves some memory regions for its own use,
> +	 * so the system memory size is less than the actual physical memory
> +	 * size. Work around this by rounding up the total size to 128M,
> +	 * which is enough for most test cases.
> +	 */
> +	total_mem = roundup(total_mem, SZ_128M);
>  
>  	/* for each entry of the comma-separated list */
>  	do {
> @@ -87,13 +97,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
>  			return -EINVAL;
>  		}
>  		cur = tmp;
> -		if (size >= system_ram) {
> +		if (size >= total_mem) {
>  			pr_warn("crashkernel: invalid size\n");
>  			return -EINVAL;
>  		}
>  
>  		/* match ? */
> -		if (system_ram >= start && system_ram < end) {
> +		if (total_mem >= start && total_mem < end) {
>  			*crash_size = size;
>  			break;
>  		}
> -- 
> 2.33.1
> 


  reply	other threads:[~2022-06-27 10:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27  7:44 [PATCH v2] kdump: round up the total memory size to 128M for crashkernel reservation Tao Liu
2022-06-27  7:44 ` Tao Liu
2022-06-27 10:35 ` Baoquan He [this message]
2022-06-27 10:35   ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YrmH/728erRohHeU@MiWiFi-R3L-srv \
    --to=bhe@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dyoung@redhat.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ltao@redhat.com \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.