powerpc/kdump: Add support for crashkernel CMA reservation
PATCH v4 1/1 powerpc/kdump: Add support for crashkernel CMA reservation
Commit 35c18f2933c5 ("Add a new optional ",cma" suffix to the crashkernel= command line option") and commit ab475510e042 ("kdump:
implement reserve_crashkernel_cma") added CMA support for kdump crashkernel reservation.
Extend crashkernel CMA reservation support to powerpc.
The following changes are made to enable CMA reservation on powerpc:
- Parse and obtain the CMA reservation size along with other crashkernel parameters
- Call reserve_crashkernel_cma() to allocate the CMA region for kdump
- Include the CMA-reserved ranges in the usable memory ranges for the kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through /proc/vmcore.
With the introduction of the CMA crashkernel regions, crash_exclude_mem_range() needs to be called multiple times to exclude both crashk_res and crashk_cma_ranges from the crash memory ranges. To avoid repetitive logic for validating mem_ranges size and handling reallocation when required, this functionality is moved to a new wrapper function crash_exclude_mem_range_guarded().
To ensure proper CMA reservation, reserve_crashkernel_cma() is called after pageblock_order is initialized.
---
Changlog:
v3 -> v4
- Removed repeated initialization to tmem in crash_exclude_mem_range_guarded()
- Call crash_exclude_mem_range() with right crashk ranges
--- arch/powerpc/include/asm/kexec.h | 2 ++ arch/powerpc/kernel/setup-common.c | 4 ++- arch/powerpc/kexec/core.c | 10 ++++++- arch/powerpc/kexec/ranges.c | 43 ++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kexec.h +2 -0
@@ -115,9 +115,11 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, struct crash_mem#ifdef CONFIG_CRASH_RESERVE int __init overlaps_crashkernel (unsigned long start,unsigned long size);extern void arch_reserve_crashkernel (void ); +extern void kdump_cma_reserve (void );#else static inline void arch_reserve_crashkernel (void ) {}static inline int overlaps_crashkernel (unsigned long start,unsigned long size) {return 0 ; } +static inline void kdump_cma_reserve (void ) { }#endif #if defined(CONFIG_CRASH_DUMP )
arch/powerpc/kernel/setup-common.c +3 -1
@@ -35,6 +35,7 @@#include <linux/of_irq.h> #include <linux/hugetlb.h> #include <linux/pgtable.h> +#include <asm/kexec.h> #include <asm/io.h> #include <asm/paca.h> #include <asm/processor.h>
@@ -995,11 +996,12 @@ void __init setup_arch(char **cmdline_p)initmem_init ();/* -* Reserve large chunks of memory for use by CMA for fadump, KVM and +* Reserve large chunks of memory for use by CMA for kdump, fadump, KVM and * hugetlb. These must be called after initmem_init(), so that * pageblock_order is initialised. */ fadump_cma_init (); +kdump_cma_reserve ();kvm_cma_reserve ();gigantic_hugetlb_cma_reserve ();
arch/powerpc/kexec/core.c +9 -1
@@ -33,6 +33,8 @@ void machine_kexec_cleanup(struct kimage *image) { } +unsigned long long cma_size; +/* * Do not allocate memory (or fail in any way) in machine_kexec(). * We are past the point of no return, committed to rebooting now.
@@ -110,7 +112,7 @@ void __init arch_reserve_crashkernel(void)/* use common parsing */ ret =parse_crashkernel (boot_command_line, total_mem_sz, &crash_size, - &crash_base,NULL ,NULL ,NULL ); + &crash_base,NULL , &cma_size,NULL );if (ret)return ;
@@ -130,6 +132,12 @@ void __init arch_reserve_crashkernel(void)reserve_crashkernel_generic (crash_size, crash_base,0 , false); } +void __init kdump_cma_reserve (void ) +{ +if (cma_size) +reserve_crashkernel_cma (cma_size); +} +int __init overlaps_crashkernel (unsigned long start,unsigned long size) {return (start + size) > crashk_res.start && start <= crashk_res.end;
arch/powerpc/kexec/ranges.c +32 -11
77 lines not on this page · raw message
Signature · 1 line
2.51.0
Ritesh Harjani (IBM)
reviewerQuoted 45 lines · Sourabh Jain
Commit
35c18f2933c5("Add a new optional ",cma" suffix to the crashkernel= command line option") and commitab475510e042("kdump:
implementreserve_crashkernel_cma") added CMA support for kdump crashkernel reservation.Extend crashkernel CMA reservation support to powerpc.
The following changes are made to enable CMA reservation on powerpc:
- Parse and obtain the CMA reservation size along with other crashkernel parameters
- Callreserve_crashkernel_cma()to allocate the CMA region for kdump
- Include the CMA-reserved ranges in the usable memory ranges for the kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through/proc/vmcore.With the introduction of the CMA crashkernel regions,
crash_exclude_mem_range()needs to be called multiple times to exclude bothcrashk_resandcrashk_cma_rangesfrom the crash memory ranges. To avoid repetitive logic for validatingmem_rangessize and handling reallocation when required, this functionality is moved to a new wrapper functioncrash_exclude_mem_range_guarded().To ensure proper CMA reservation,
reserve_crashkernel_cma()is called afterpageblock_orderis initialized.Cc Baoquan he <[email protected]>Cc Jiri Bohac <[email protected]>Cc Hari Bathini <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Mahesh Salgaonkar <[email protected]>Cc Michael Ellerman <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Shivang Upadhyay <[email protected]>Signed-off-by Sourabh Jain <[email protected]>---
Changlog:v3 -> v4
- Removed repeated initialization to tmem incrash_exclude_mem_range_guarded()
- Callcrash_exclude_mem_range()with right crashk ranges
Quoted 6 lines
--- arch/powerpc/include/asm/kexec.h | 2 ++ arch/powerpc/kernel/setup-common.c | 4 ++- arch/powerpc/kexec/core.c | 10 ++++++- arch/powerpc/kexec/ranges.c | 43 ++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 13 deletions(-)
I am not much familiar with the crash kernel workings but was curious about the following query related to this patch:
As I understand this patch allows for the remaining crash kernel memory to come from CMA region. But do we limit the CMA region to be lower than 4G? Is this patch dependent over your other patch series [1] which supports high crashkernel reservation?
[1]: https://lore.kernel.org/linuxppc-dev/[email protected]/
A minor comment: I guess we could reflect the support for ,cma for PPC too in Documentation/admin-guide/kernel-parameters.txt like how it is done for x86.
-ritesh
Hi Ritesh,
Quoted 54 lines · Ritesh Harjani (IBM)
Quoted 45 lines · Sourabh Jain
Commit
35c18f2933c5("Add a new optional ",cma" suffix to the crashkernel= command line option") and commitab475510e042("kdump:
implementreserve_crashkernel_cma") added CMA support for kdump crashkernel reservation.Extend crashkernel CMA reservation support to powerpc.
The following changes are made to enable CMA reservation on powerpc:
- Parse and obtain the CMA reservation size along with other crashkernel parameters
- Callreserve_crashkernel_cma()to allocate the CMA region for kdump
- Include the CMA-reserved ranges in the usable memory ranges for the kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through/proc/vmcore.With the introduction of the CMA crashkernel regions,
crash_exclude_mem_range()needs to be called multiple times to exclude bothcrashk_resandcrashk_cma_rangesfrom the crash memory ranges. To avoid repetitive logic for validatingmem_rangessize and handling reallocation when required, this functionality is moved to a new wrapper functioncrash_exclude_mem_range_guarded().To ensure proper CMA reservation,
reserve_crashkernel_cma()is called afterpageblock_orderis initialized.Cc Baoquan he <[email protected]>Cc Jiri Bohac <[email protected]>Cc Hari Bathini <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Mahesh Salgaonkar <[email protected]>Cc Michael Ellerman <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Shivang Upadhyay <[email protected]>Signed-off-by Sourabh Jain <[email protected]>---
Changlog:v3 -> v4
- Removed repeated initialization to tmem incrash_exclude_mem_range_guarded()
- Callcrash_exclude_mem_range()with right crashk rangesQuoted 6 lines
--- arch/powerpc/include/asm/kexec.h | 2 ++ arch/powerpc/kernel/setup-common.c | 4 ++- arch/powerpc/kexec/core.c | 10 ++++++- arch/powerpc/kexec/ranges.c | 43 ++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 13 deletions(-)
Quoted 6 lines
I am not much familiar with the crash kernel workings but was curious about the following query related to this patch:
As I understand this patch allows for the remaining crash kernel memory to come from CMA region. But do we limit the CMA region to be lower than 4G?
No we are not and we don't need to.
Quoted 4 lines
Is this patch dependent over your other patch series [1] which supports high crashkernel reservation?
[1]: https://lore.kernel.org/linuxppc-dev/[email protected]/
No, this is an independent patch.
Quoted 5 lines
A minor comment: I guess we could reflect the support for ,cma for PPC too in
Documentation/admin-guide/kernel-parameters.txtlike how it is done for x86.
Yes we should. I will make the change in the next version.
Thanks for the review.
- Sourabh Jain
Ritesh Harjani (IBM)
reviewerQuoted 64 lines · Sourabh Jain
Hi Ritesh,
Quoted 54 lines · Ritesh Harjani (IBM)
Quoted 45 lines · Sourabh Jain
Commit
35c18f2933c5("Add a new optional ",cma" suffix to the crashkernel= command line option") and commitab475510e042("kdump:
implementreserve_crashkernel_cma") added CMA support for kdump crashkernel reservation.Extend crashkernel CMA reservation support to powerpc.
The following changes are made to enable CMA reservation on powerpc:
- Parse and obtain the CMA reservation size along with other crashkernel parameters
- Callreserve_crashkernel_cma()to allocate the CMA region for kdump
- Include the CMA-reserved ranges in the usable memory ranges for the kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through/proc/vmcore.With the introduction of the CMA crashkernel regions,
crash_exclude_mem_range()needs to be called multiple times to exclude bothcrashk_resandcrashk_cma_rangesfrom the crash memory ranges. To avoid repetitive logic for validatingmem_rangessize and handling reallocation when required, this functionality is moved to a new wrapper functioncrash_exclude_mem_range_guarded().To ensure proper CMA reservation,
reserve_crashkernel_cma()is called afterpageblock_orderis initialized.Cc Baoquan he <[email protected]>Cc Jiri Bohac <[email protected]>Cc Hari Bathini <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Mahesh Salgaonkar <[email protected]>Cc Michael Ellerman <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Shivang Upadhyay <[email protected]>Signed-off-by Sourabh Jain <[email protected]>---
Changlog:v3 -> v4
- Removed repeated initialization to tmem incrash_exclude_mem_range_guarded()
- Callcrash_exclude_mem_range()with right crashk rangesQuoted 6 lines
--- arch/powerpc/include/asm/kexec.h | 2 ++ arch/powerpc/kernel/setup-common.c | 4 ++- arch/powerpc/kexec/core.c | 10 ++++++- arch/powerpc/kexec/ranges.c | 43 ++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 13 deletions(-)Quoted 6 lines
I am not much familiar with the crash kernel workings but was curious about the following query related to this patch:
As I understand this patch allows for the remaining crash kernel memory to come from CMA region. But do we limit the CMA region to be lower than 4G?
Quoted 9 lines
No we are not and we don't need to.
Quoted 4 lines
Is this patch dependent over your other patch series [1] which supports high crashkernel reservation?
[1]: https://lore.kernel.org/linuxppc-dev/[email protected]/
No, this is an independent patch.
Say, if we are in Hash mode and if the CMA reservations have come from higher addresses. Will that work with kdump kernel when it boots with Hash mmu? Because memory region beyond RMA is not accessible in Hash correct?
-ritesh
Quoted 11 lines
Quoted 5 lines
A minor comment: I guess we could reflect the support for ,cma for PPC too in
Documentation/admin-guide/kernel-parameters.txtlike how it is done for x86.Yes we should. I will make the change in the next version.
Thanks for the review.
- Sourabh Jain
Ritesh Harjani (IBM)
reviewerQuoted 13 lines · Ritesh Harjani (IBM)
Quoted 13 lines
Quoted 7 lines
I am not much familiar with the crash kernel workings but was curious about the following query related to this patch:
As I understand this patch allows for the remaining crash kernel memory to come from CMA region. But do we limit the CMA region to be lower than 4G?
No we are not and we don't need to.
Quoted 3 lines
Is this patch dependent over your other patch series [1] which supports high crashkernel reservation?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
[1]: https://lore.kernel.org/linuxppc-dev/[email protected]/
No, this is an independent patch.
Say, if we are in Hash mode and if the CMA reservations have come from higher addresses. Will that work with kdump kernel when it boots with Hash mmu? Because memory region beyond RMA is not accessible in Hash correct?
Oh sorry my bad! I think I got the answer to above question now. So this feature allows us to reserve the "extra memory" using CMA which is mainly used to serve the kdump kernel's memory allocation requests. So we will have two memory reservations i.e.
crashkernel=64M,crashkernel=1G,cma.
So the second 1G cma reservation is mainly to serve the kdump kernel's memory allocation requests to avoid the ooms. And this will only be required once the MMU is initialized, so we don't have those RMA restrictions which are only during early init time (before Hash is initialized).
-ritesh
Quoted 25 lines · Ritesh Harjani (IBM)
Quoted 11 lines · Ritesh Harjani (IBM)
Quoted 11 lines
Quoted 6 lines
I am not much familiar with the crash kernel workings but was curious about the following query related to this patch:
As I understand this patch allows for the remaining crash kernel memory to come from CMA region. But do we limit the CMA region to be lower than 4G?
No we are not and we don't need to.
Quoted 3 lines
Is this patch dependent over your other patch series [1] which supports high crashkernel reservation?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
[1]: https://lore.kernel.org/linuxppc-dev/[email protected]/
No, this is an independent patch.
Say, if we are in Hash mode and if the CMA reservations have come from higher addresses. Will that work with kdump kernel when it boots with Hash mmu? Because memory region beyond RMA is not accessible in Hash correct?
Oh sorry my bad! I think I got the answer to above question now. So this feature allows us to reserve the "extra memory" using CMA which is mainly used to serve the kdump kernel's memory allocation requests. So we will have two memory reservations i.e.
Quoted 7 lines
crashkernel=64M,crashkernel=1G,cma.
So the second 1G cma reservation is mainly to serve the kdump kernel's memory allocation requests to avoid the ooms. And this will only be required once the MMU is initialized, so we don't have those RMA restrictions which are only during early init time (before Hash is initialized).
Yes, exactly. The regular reservation will be done as usual, and the kdump image (vmlinux, initrd, dtb, etc.) will be loaded in the regular crashkernel reserved region. So, no impact is expected due to the MMU type in use.
- Sourabh Jain