2019-04-21 03:58:13

by Dave Young

[permalink] [raw]
Subject: [PATCH 2/2] X86/kdump: fall back to reserve high crashkernel memory

crashkernel=xM tries to reserve crashkernel memory under 4G, which
is enough for usual cases. But this could fail sometimes, for example
one tries to reserve a big chunk like 2G, it is possible to fail.

So let the crashkernel=xM just fall back to use high memory in case it
fails to find a suitable low range. Do not set the ,high as default
because it allocs extra low memory for DMA buffers and swiotlb, this is
not always necessary for all machines. Typically like crashkernel=128M
usually work with low reservation under 4G, so still keep <4G as default.

Signed-off-by: Dave Young <[email protected]>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
arch/x86/kernel/setup.c | 22 ++++++++++++++--------
2 files changed, 19 insertions(+), 10 deletions(-)

--- linux-x86.orig/arch/x86/kernel/setup.c
+++ linux-x86/arch/x86/kernel/setup.c
@@ -541,21 +541,27 @@ static void __init reserve_crashkernel(v
}

/* 0 means: find the address automatically */
- if (crash_base <= 0) {
+ if (!crash_base) {
/*
* Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
- * as old kexec-tools loads bzImage below that, unless
- * "crashkernel=size[KMG],high" is specified.
+ * as crashkernel=x,high allocs memory over 4G, also allocs
+ * 256M extra low memory for DMA buffers and swiotlb.
+ * but the extra memory is not required for all machines.
+ * So prefer low memory first, and fallback to high memory
+ * unless "crashkernel=size[KMG],high" is specified.
*/
- crash_base = memblock_find_in_range(CRASH_ALIGN,
- high ? CRASH_ADDR_HIGH_MAX
- : CRASH_ADDR_LOW_MAX,
- crash_size, CRASH_ALIGN);
+ if (!high)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_LOW_MAX,
+ crash_size, CRASH_ALIGN);
+ if (!crash_base)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_HIGH_MAX,
+ crash_size, CRASH_ALIGN);
if (!crash_base) {
pr_info("crashkernel reservation failed - No suitable area found.\n");
return;
}
-
} else {
unsigned long long start;

--- linux-x86.orig/Documentation/admin-guide/kernel-parameters.txt
+++ linux-x86/Documentation/admin-guide/kernel-parameters.txt
@@ -704,8 +704,11 @@
upon panic. This parameter reserves the physical
memory region [offset, offset + size] for that kernel
image. If '@offset' is omitted, then a suitable offset
- is selected automatically. Check
- Documentation/kdump/kdump.txt for further details.
+ is selected automatically.
+ [KNL, x86_64] select a region under 4G first, and
+ fallback to reserve region above 4G in case without
+ '@offset'.
+ See Documentation/kdump/kdump.txt for further details.

crashkernel=range1:size1[,range2:size2,...][@offset]
[KNL] Same as above, but depends on the memory



2019-04-21 18:28:09

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 2/2] X86/kdump: fall back to reserve high crashkernel memory


* Dave Young <[email protected]> wrote:

> crashkernel=xM tries to reserve crashkernel memory under 4G, which
> is enough for usual cases. But this could fail sometimes, for example
> one tries to reserve a big chunk like 2G, it is possible to fail.
>
> So let the crashkernel=xM just fall back to use high memory in case it
> fails to find a suitable low range. Do not set the ,high as default
> because it allocs extra low memory for DMA buffers and swiotlb, this is
> not always necessary for all machines. Typically like crashkernel=128M
> usually work with low reservation under 4G, so still keep <4G as default.
>
> Signed-off-by: Dave Young <[email protected]>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
> arch/x86/kernel/setup.c | 22 ++++++++++++++--------
> 2 files changed, 19 insertions(+), 10 deletions(-)
>
> --- linux-x86.orig/arch/x86/kernel/setup.c
> +++ linux-x86/arch/x86/kernel/setup.c
> @@ -541,21 +541,27 @@ static void __init reserve_crashkernel(v
> }
>
> /* 0 means: find the address automatically */
> - if (crash_base <= 0) {
> + if (!crash_base) {
> /*
> * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
> - * as old kexec-tools loads bzImage below that, unless
> - * "crashkernel=size[KMG],high" is specified.
> + * as crashkernel=x,high allocs memory over 4G, also allocs

s/allocs
/allocates

> + * 256M extra low memory for DMA buffers and swiotlb.
> + * but the extra memory is not required for all machines.
> + * So prefer low memory first, and fallback to high memory

s/fallback
/fall back

> + * unless "crashkernel=size[KMG],high" is specified.
> */
> - crash_base = memblock_find_in_range(CRASH_ALIGN,
> - high ? CRASH_ADDR_HIGH_MAX
> - : CRASH_ADDR_LOW_MAX,
> - crash_size, CRASH_ALIGN);
> + if (!high)
> + crash_base = memblock_find_in_range(CRASH_ALIGN,
> + CRASH_ADDR_LOW_MAX,
> + crash_size, CRASH_ALIGN);
> + if (!crash_base)
> + crash_base = memblock_find_in_range(CRASH_ALIGN,
> + CRASH_ADDR_HIGH_MAX,
> + crash_size, CRASH_ALIGN);
> if (!crash_base) {
> pr_info("crashkernel reservation failed - No suitable area found.\n");
> return;
> }
> -
> } else {
> unsigned long long start;
>
> --- linux-x86.orig/Documentation/admin-guide/kernel-parameters.txt
> +++ linux-x86/Documentation/admin-guide/kernel-parameters.txt
> @@ -704,8 +704,11 @@
> upon panic. This parameter reserves the physical
> memory region [offset, offset + size] for that kernel
> image. If '@offset' is omitted, then a suitable offset
> - is selected automatically. Check
> - Documentation/kdump/kdump.txt for further details.
> + is selected automatically.
> + [KNL, x86_64] select a region under 4G first, and
> + fallback to reserve region above 4G in case without

s/fallback
/fall back

> + '@offset'.
> + See Documentation/kdump/kdump.txt for further details.
>
> crashkernel=range1:size1[,range2:size2,...][@offset]
> [KNL] Same as above, but depends on the memory

With the nits fixed:

Reviewed-by: Ingo Molnar <[email protected]>

Thanks,

Ingo

2019-04-22 03:04:26

by Dave Young

[permalink] [raw]
Subject: Re: [PATCH 2/2] X86/kdump: fall back to reserve high crashkernel memory

On 04/21/19 at 08:26pm, Ingo Molnar wrote:
>
> * Dave Young <[email protected]> wrote:
>
> > crashkernel=xM tries to reserve crashkernel memory under 4G, which
> > is enough for usual cases. But this could fail sometimes, for example
> > one tries to reserve a big chunk like 2G, it is possible to fail.
> >
> > So let the crashkernel=xM just fall back to use high memory in case it
> > fails to find a suitable low range. Do not set the ,high as default
> > because it allocs extra low memory for DMA buffers and swiotlb, this is
> > not always necessary for all machines. Typically like crashkernel=128M
> > usually work with low reservation under 4G, so still keep <4G as default.
> >
> > Signed-off-by: Dave Young <[email protected]>
> > ---
> > Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
> > arch/x86/kernel/setup.c | 22 ++++++++++++++--------
> > 2 files changed, 19 insertions(+), 10 deletions(-)
> >
> > --- linux-x86.orig/arch/x86/kernel/setup.c
> > +++ linux-x86/arch/x86/kernel/setup.c
> > @@ -541,21 +541,27 @@ static void __init reserve_crashkernel(v
> > }
> >
> > /* 0 means: find the address automatically */
> > - if (crash_base <= 0) {
> > + if (!crash_base) {
> > /*
> > * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
> > - * as old kexec-tools loads bzImage below that, unless
> > - * "crashkernel=size[KMG],high" is specified.
> > + * as crashkernel=x,high allocs memory over 4G, also allocs
>
> s/allocs
> /allocates
>
> > + * 256M extra low memory for DMA buffers and swiotlb.
> > + * but the extra memory is not required for all machines.
> > + * So prefer low memory first, and fallback to high memory
>
> s/fallback
> /fall back
>
> > + * unless "crashkernel=size[KMG],high" is specified.
> > */
> > - crash_base = memblock_find_in_range(CRASH_ALIGN,
> > - high ? CRASH_ADDR_HIGH_MAX
> > - : CRASH_ADDR_LOW_MAX,
> > - crash_size, CRASH_ALIGN);
> > + if (!high)
> > + crash_base = memblock_find_in_range(CRASH_ALIGN,
> > + CRASH_ADDR_LOW_MAX,
> > + crash_size, CRASH_ALIGN);
> > + if (!crash_base)
> > + crash_base = memblock_find_in_range(CRASH_ALIGN,
> > + CRASH_ADDR_HIGH_MAX,
> > + crash_size, CRASH_ALIGN);
> > if (!crash_base) {
> > pr_info("crashkernel reservation failed - No suitable area found.\n");
> > return;
> > }
> > -
> > } else {
> > unsigned long long start;
> >
> > --- linux-x86.orig/Documentation/admin-guide/kernel-parameters.txt
> > +++ linux-x86/Documentation/admin-guide/kernel-parameters.txt
> > @@ -704,8 +704,11 @@
> > upon panic. This parameter reserves the physical
> > memory region [offset, offset + size] for that kernel
> > image. If '@offset' is omitted, then a suitable offset
> > - is selected automatically. Check
> > - Documentation/kdump/kdump.txt for further details.
> > + is selected automatically.
> > + [KNL, x86_64] select a region under 4G first, and
> > + fallback to reserve region above 4G in case without
>
> s/fallback
> /fall back
>
> > + '@offset'.
> > + See Documentation/kdump/kdump.txt for further details.
> >
> > crashkernel=range1:size1[,range2:size2,...][@offset]
> > [KNL] Same as above, but depends on the memory
>
> With the nits fixed:
>
> Reviewed-by: Ingo Molnar <[email protected]>

Thanks for review, will reply to 2/2 with an update of those spelling
issues.

Dave

2019-04-22 03:32:18

by Dave Young

[permalink] [raw]
Subject: [PATCH 2/2 update] X86/kdump: fall back to reserve high crashkernel memory

crashkernel=xM tries to reserve crashkernel memory under 4G, which
is enough for usual cases. But this could fail sometimes, for example
one tries to reserve a big chunk like 2G, it is possible to fail.

So let the crashkernel=xM just fall back to use high memory in case it
fails to find a suitable low range. Do not set the ,high as default
because it allocates extra low memory for DMA buffers and swiotlb, this is
not always necessary for all machines. Typically like crashkernel=128M
usually work with low reservation under 4G, so still keep <4G as default.

Signed-off-by: Dave Young <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
arch/x86/kernel/setup.c | 22 ++++++++++++++--------
2 files changed, 19 insertions(+), 10 deletions(-)

--- linux-x86.orig/arch/x86/kernel/setup.c
+++ linux-x86/arch/x86/kernel/setup.c
@@ -541,21 +541,27 @@ static void __init reserve_crashkernel(v
}

/* 0 means: find the address automatically */
- if (crash_base <= 0) {
+ if (!crash_base) {
/*
* Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
- * as old kexec-tools loads bzImage below that, unless
- * "crashkernel=size[KMG],high" is specified.
+ * crashkernel=x,high reserves memory over 4G, also allocates
+ * 256M extra low memory for DMA buffers and swiotlb.
+ * but the extra memory is not required for all machines.
+ * So prefer low memory first, and fall back to high memory
+ * unless "crashkernel=size[KMG],high" is specified.
*/
- crash_base = memblock_find_in_range(CRASH_ALIGN,
- high ? CRASH_ADDR_HIGH_MAX
- : CRASH_ADDR_LOW_MAX,
- crash_size, CRASH_ALIGN);
+ if (!high)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_LOW_MAX,
+ crash_size, CRASH_ALIGN);
+ if (!crash_base)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_HIGH_MAX,
+ crash_size, CRASH_ALIGN);
if (!crash_base) {
pr_info("crashkernel reservation failed - No suitable area found.\n");
return;
}
-
} else {
unsigned long long start;

--- linux-x86.orig/Documentation/admin-guide/kernel-parameters.txt
+++ linux-x86/Documentation/admin-guide/kernel-parameters.txt
@@ -704,8 +704,11 @@
upon panic. This parameter reserves the physical
memory region [offset, offset + size] for that kernel
image. If '@offset' is omitted, then a suitable offset
- is selected automatically. Check
- Documentation/kdump/kdump.txt for further details.
+ is selected automatically.
+ [KNL, x86_64] select a region under 4G first, and
+ fall back to reserve region above 4G in case without
+ '@offset'.
+ See Documentation/kdump/kdump.txt for further details.

crashkernel=range1:size1[,range2:size2,...][@offset]
[KNL] Same as above, but depends on the memory

2019-04-22 03:36:04

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH 2/2 update] X86/kdump: fall back to reserve high crashkernel memory

On 04/22/19 at 11:19am, Dave Young wrote:
> crashkernel=xM tries to reserve crashkernel memory under 4G, which
> is enough for usual cases. But this could fail sometimes, for example
> one tries to reserve a big chunk like 2G, it is possible to fail.
>
> So let the crashkernel=xM just fall back to use high memory in case it
> fails to find a suitable low range. Do not set the ,high as default
> because it allocates extra low memory for DMA buffers and swiotlb, this is
> not always necessary for all machines. Typically like crashkernel=128M
> usually work with low reservation under 4G, so still keep <4G as default.
>
> Signed-off-by: Dave Young <[email protected]>
> Reviewed-by: Ingo Molnar <[email protected]>
> ---

Ack the whole series, thanks for the effort.

Acked-by: Baoquan He <[email protected]>

> Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
> arch/x86/kernel/setup.c | 22 ++++++++++++++--------
> 2 files changed, 19 insertions(+), 10 deletions(-)
>
> --- linux-x86.orig/arch/x86/kernel/setup.c
> +++ linux-x86/arch/x86/kernel/setup.c
> @@ -541,21 +541,27 @@ static void __init reserve_crashkernel(v
> }
>
> /* 0 means: find the address automatically */
> - if (crash_base <= 0) {
> + if (!crash_base) {
> /*
> * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
> - * as old kexec-tools loads bzImage below that, unless
> - * "crashkernel=size[KMG],high" is specified.
> + * crashkernel=x,high reserves memory over 4G, also allocates
> + * 256M extra low memory for DMA buffers and swiotlb.
> + * but the extra memory is not required for all machines.
> + * So prefer low memory first, and fall back to high memory
> + * unless "crashkernel=size[KMG],high" is specified.
> */
> - crash_base = memblock_find_in_range(CRASH_ALIGN,
> - high ? CRASH_ADDR_HIGH_MAX
> - : CRASH_ADDR_LOW_MAX,
> - crash_size, CRASH_ALIGN);
> + if (!high)
> + crash_base = memblock_find_in_range(CRASH_ALIGN,
> + CRASH_ADDR_LOW_MAX,
> + crash_size, CRASH_ALIGN);
> + if (!crash_base)
> + crash_base = memblock_find_in_range(CRASH_ALIGN,
> + CRASH_ADDR_HIGH_MAX,
> + crash_size, CRASH_ALIGN);
> if (!crash_base) {
> pr_info("crashkernel reservation failed - No suitable area found.\n");
> return;
> }
> -
> } else {
> unsigned long long start;
>
> --- linux-x86.orig/Documentation/admin-guide/kernel-parameters.txt
> +++ linux-x86/Documentation/admin-guide/kernel-parameters.txt
> @@ -704,8 +704,11 @@
> upon panic. This parameter reserves the physical
> memory region [offset, offset + size] for that kernel
> image. If '@offset' is omitted, then a suitable offset
> - is selected automatically. Check
> - Documentation/kdump/kdump.txt for further details.
> + is selected automatically.
> + [KNL, x86_64] select a region under 4G first, and
> + fall back to reserve region above 4G in case without
> + '@offset'.
> + See Documentation/kdump/kdump.txt for further details.
>
> crashkernel=range1:size1[,range2:size2,...][@offset]
> [KNL] Same as above, but depends on the memory

Subject: [tip:x86/kdump] x86/kdump: Fall back to reserve high crashkernel memory

Commit-ID: b9ac3849af412fd3887d7652bdbabf29d2aecc16
Gitweb: https://git.kernel.org/tip/b9ac3849af412fd3887d7652bdbabf29d2aecc16
Author: Dave Young <[email protected]>
AuthorDate: Mon, 22 Apr 2019 11:19:05 +0800
Committer: Borislav Petkov <[email protected]>
CommitDate: Mon, 22 Apr 2019 10:23:05 +0200

x86/kdump: Fall back to reserve high crashkernel memory

crashkernel=xM tries to reserve memory for the crash kernel under 4G,
which is enough, usually. But this could fail sometimes, for example
when one tries to reserve a big chunk like 2G, for example.

So let the crashkernel=xM just fall back to use high memory in case it
fails to find a suitable low range. Do not set the ,high as default
because it allocates extra low memory for DMA buffers and swiotlb, and
this is not always necessary for all machines.

Typically, crashkernel=128M usually works with low reservation under 4G,
so keep <4G as default.

[ bp: Massage. ]

Signed-off-by: Dave Young <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
Acked-by: Baoquan He <[email protected]>
Cc: Dave Young <[email protected]>
Cc: David Howells <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Kosina <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: [email protected]
Cc: "Paul E. McKenney" <[email protected]>
Cc: Petr Tesarik <[email protected]>
Cc: [email protected]
Cc: Ram Pai <[email protected]>
Cc: Sinan Kaya <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Thymo van Beers <[email protected]>
Cc: [email protected]
Cc: x86-ml <[email protected]>
Cc: Yinghai Lu <[email protected]>
Cc: Zhimin Gu <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++--
arch/x86/kernel/setup.c | 22 ++++++++++++++--------
2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 2b8ee90bb644..24d01648edeb 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -704,8 +704,11 @@
upon panic. This parameter reserves the physical
memory region [offset, offset + size] for that kernel
image. If '@offset' is omitted, then a suitable offset
- is selected automatically. Check
- Documentation/kdump/kdump.txt for further details.
+ is selected automatically.
+ [KNL, x86_64] select a region under 4G first, and
+ fall back to reserve region above 4G when '@offset'
+ hasn't been specified.
+ See Documentation/kdump/kdump.txt for further details.

crashkernel=range1:size1[,range2:size2,...][@offset]
[KNL] Same as above, but depends on the memory
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index daf7c5650c18..c15f362a2516 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -541,21 +541,27 @@ static void __init reserve_crashkernel(void)
}

/* 0 means: find the address automatically */
- if (crash_base <= 0) {
+ if (!crash_base) {
/*
* Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
- * as old kexec-tools loads bzImage below that, unless
- * "crashkernel=size[KMG],high" is specified.
+ * crashkernel=x,high reserves memory over 4G, also allocates
+ * 256M extra low memory for DMA buffers and swiotlb.
+ * But the extra memory is not required for all machines.
+ * So try low memory first and fall back to high memory
+ * unless "crashkernel=size[KMG],high" is specified.
*/
- crash_base = memblock_find_in_range(CRASH_ALIGN,
- high ? CRASH_ADDR_HIGH_MAX
- : CRASH_ADDR_LOW_MAX,
- crash_size, CRASH_ALIGN);
+ if (!high)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_LOW_MAX,
+ crash_size, CRASH_ALIGN);
+ if (!crash_base)
+ crash_base = memblock_find_in_range(CRASH_ALIGN,
+ CRASH_ADDR_HIGH_MAX,
+ crash_size, CRASH_ALIGN);
if (!crash_base) {
pr_info("crashkernel reservation failed - No suitable area found.\n");
return;
}
-
} else {
unsigned long long start;