* [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
@ 2025-12-26 14:06 Coiby Xu
2025-12-27 14:35 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Coiby Xu @ 2025-12-26 14:06 UTC (permalink / raw)
To: kexec, linuxppc-dev
Cc: Thomas Staudt, Arnaud Lefebvre, Baoquan he, Dave Young,
Kairui Song, Pingfan Liu, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
open list
Based on the CONFIG_CRASH_DM_CRYPT feature, this patch adds
LUKS-encrypted device dump target support to PowerPC by addressing two
challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some
machines, a system administrator may not have a chance to enter the
password to decrypt the device in kdump initramfs after the 1st kernel
crashes
- LUKS2 by default use the memory-hard Argon2 key derivation function
which is quite memory-consuming compared to the limited memory reserved
for kdump.
1st kernel will build up the kernel command parameter dmcryptkeys as
similar to elfcorehdr to pass the memory address of the stored info of
dm-crypt keys to the kdump kernel.
[1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
Cc: Thomas Staudt <tstaudt@de.ibm.com>
Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Pingfan Liu <kernelfans@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
arch/powerpc/include/asm/kexec.h | 3 ++-
arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++-
arch/powerpc/kexec/file_load.c | 19 +++++++++++--------
3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
index bd4a6c42a5f3..f3d098d543b4 100644
--- a/arch/powerpc/include/asm/kexec.h
+++ b/arch/powerpc/include/asm/kexec.h
@@ -80,7 +80,8 @@ struct kimage_arch {
};
char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
- unsigned long cmdline_len);
+ unsigned long cmdline_len,
+ char *name, unsigned long addr);
int setup_purgatory(struct kimage *image, const void *slave_code,
const void *fdt, unsigned long kernel_load_addr,
unsigned long fdt_load_addr);
diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index 5d6d616404cf..57cb3361d91b 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
/* Setup cmdline for kdump kernel case */
modified_cmdline = setup_kdump_cmdline(image, cmdline,
- cmdline_len);
+ cmdline_len,
+ "elfcorehdr",
+ image->elf_load_addr);
if (!modified_cmdline) {
pr_err("Setting up cmdline for kdump kernel failed\n");
ret = -EINVAL;
goto out;
}
cmdline = modified_cmdline;
+ cmdline_len = strlen(cmdline) + 1;
+
+ ret = crash_load_dm_crypt_keys(image);
+ if (ret == -ENOENT) {
+ kexec_dprintk("No dm crypt key to load\n");
+ } else if (ret) {
+ pr_err("Failed to load dm crypt keys\n");
+ return ERR_PTR(ret);
+ }
+
+ if (image->dm_crypt_keys_addr != 0) {
+ modified_cmdline = setup_kdump_cmdline(image, cmdline,
+ cmdline_len,
+ "dmcryptkeys",
+ image->dm_crypt_keys_addr);
+ if (!modified_cmdline) {
+ pr_err("Setting up cmdline for kdump kernel failed\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ cmdline = modified_cmdline;
+ }
}
if (initrd != NULL) {
diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c
index 4284f76cbef5..e1c08050286d 100644
--- a/arch/powerpc/kexec/file_load.c
+++ b/arch/powerpc/kexec/file_load.c
@@ -23,38 +23,41 @@
#define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */
/**
- * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
+ * setup_kdump_cmdline - Prepend "<name>=<addr> " to command line
* of kdump kernel for exporting the core.
* @image: Kexec image
* @cmdline: Command line parameters to update.
* @cmdline_len: Length of the cmdline parameters.
+ * @name: Name e.g elfcorehdr.
+ * @addr: Memory address.
*
* kdump segment must be setup before calling this function.
*
* Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
*/
char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
- unsigned long cmdline_len)
+ unsigned long cmdline_len,
+ char *name, unsigned long addr)
{
- int elfcorehdr_strlen;
+ unsigned long parameter_len;
char *cmdline_ptr;
cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
if (!cmdline_ptr)
return NULL;
- elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
- image->elf_load_addr);
+ parameter_len = sprintf(cmdline_ptr, "%s=0x%lx ", name, addr);
- if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
- pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
+ if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) {
+ pr_err("Appending %s=<addr> exceeds cmdline size\n", name);
kfree(cmdline_ptr);
return NULL;
}
- memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
+ memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len);
// Ensure it's nul terminated
cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
+ kfree(cmdline);
return cmdline_ptr;
}
base-commit: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
2025-12-26 14:06 [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel Coiby Xu
@ 2025-12-27 14:35 ` kernel test robot
2026-01-06 7:46 ` Coiby Xu
2026-01-01 15:06 ` Sourabh Jain
2026-01-06 7:40 ` [PATCH v2] " Coiby Xu
2 siblings, 1 reply; 8+ messages in thread
From: kernel test robot @ 2025-12-27 14:35 UTC (permalink / raw)
To: Coiby Xu, kexec, linuxppc-dev
Cc: llvm, oe-kbuild-all, Thomas Staudt, Arnaud Lefebvre, Baoquan he,
Dave Young, Kairui Song, Pingfan Liu, Andrew Morton,
Linux Memory Management List, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
linux-kernel
Hi Coiby,
kernel test robot noticed the following build errors:
[auto build test ERROR on ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1]
url: https://github.com/intel-lab-lkp/linux/commits/Coiby-Xu/powerpc-kdump-pass-dm-crypt-keys-to-kdump-kernel/20251226-220726
base: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
patch link: https://lore.kernel.org/r/20251226140636.1378505-1-coxu%40redhat.com
patch subject: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
config: powerpc64-randconfig-001-20251227 (https://download.01.org/0day-ci/archive/20251227/202512272218.ghBaSjzO-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251227/202512272218.ghBaSjzO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.com/
All errors (new ones prefixed by >>):
>> arch/powerpc/kexec/elf_64.c:95:9: error: call to undeclared function 'crash_load_dm_crypt_keys'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
95 | ret = crash_load_dm_crypt_keys(image);
| ^
1 error generated.
vim +/crash_load_dm_crypt_keys +95 arch/powerpc/kexec/elf_64.c
27
28 static void *elf64_load(struct kimage *image, char *kernel_buf,
29 unsigned long kernel_len, char *initrd,
30 unsigned long initrd_len, char *cmdline,
31 unsigned long cmdline_len)
32 {
33 int ret;
34 unsigned long kernel_load_addr;
35 unsigned long initrd_load_addr = 0, fdt_load_addr;
36 void *fdt;
37 const void *slave_code;
38 struct elfhdr ehdr;
39 char *modified_cmdline = NULL;
40 struct crash_mem *rmem = NULL;
41 struct kexec_elf_info elf_info;
42 struct kexec_buf kbuf = { .image = image, .buf_min = 0,
43 .buf_max = ppc64_rma_size };
44 struct kexec_buf pbuf = { .image = image, .buf_min = 0,
45 .buf_max = ppc64_rma_size, .top_down = true,
46 .mem = KEXEC_BUF_MEM_UNKNOWN };
47
48 ret = kexec_build_elf_info(kernel_buf, kernel_len, &ehdr, &elf_info);
49 if (ret)
50 return ERR_PTR(ret);
51
52 if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
53 /* min & max buffer values for kdump case */
54 kbuf.buf_min = pbuf.buf_min = crashk_res.start;
55 kbuf.buf_max = pbuf.buf_max =
56 ((crashk_res.end < ppc64_rma_size) ?
57 crashk_res.end : (ppc64_rma_size - 1));
58 }
59
60 ret = kexec_elf_load(image, &ehdr, &elf_info, &kbuf, &kernel_load_addr);
61 if (ret)
62 goto out;
63
64 kexec_dprintk("Loaded the kernel at 0x%lx\n", kernel_load_addr);
65
66 ret = kexec_load_purgatory(image, &pbuf);
67 if (ret) {
68 pr_err("Loading purgatory failed.\n");
69 goto out;
70 }
71
72 kexec_dprintk("Loaded purgatory at 0x%lx\n", pbuf.mem);
73
74 /* Load additional segments needed for panic kernel */
75 if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
76 ret = load_crashdump_segments_ppc64(image, &kbuf);
77 if (ret) {
78 pr_err("Failed to load kdump kernel segments\n");
79 goto out;
80 }
81
82 /* Setup cmdline for kdump kernel case */
83 modified_cmdline = setup_kdump_cmdline(image, cmdline,
84 cmdline_len,
85 "elfcorehdr",
86 image->elf_load_addr);
87 if (!modified_cmdline) {
88 pr_err("Setting up cmdline for kdump kernel failed\n");
89 ret = -EINVAL;
90 goto out;
91 }
92 cmdline = modified_cmdline;
93 cmdline_len = strlen(cmdline) + 1;
94
> 95 ret = crash_load_dm_crypt_keys(image);
96 if (ret == -ENOENT) {
97 kexec_dprintk("No dm crypt key to load\n");
98 } else if (ret) {
99 pr_err("Failed to load dm crypt keys\n");
100 return ERR_PTR(ret);
101 }
102
103 if (image->dm_crypt_keys_addr != 0) {
104 modified_cmdline = setup_kdump_cmdline(image, cmdline,
105 cmdline_len,
106 "dmcryptkeys",
107 image->dm_crypt_keys_addr);
108 if (!modified_cmdline) {
109 pr_err("Setting up cmdline for kdump kernel failed\n");
110 ret = -EINVAL;
111 goto out;
112 }
113 cmdline = modified_cmdline;
114 }
115 }
116
117 if (initrd != NULL) {
118 kbuf.buffer = initrd;
119 kbuf.bufsz = kbuf.memsz = initrd_len;
120 kbuf.buf_align = PAGE_SIZE;
121 kbuf.top_down = false;
122 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
123 ret = kexec_add_buffer(&kbuf);
124 if (ret)
125 goto out;
126 initrd_load_addr = kbuf.mem;
127
128 kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_load_addr);
129 }
130
131 ret = get_reserved_memory_ranges(&rmem);
132 if (ret)
133 goto out;
134
135 fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
136 initrd_len, cmdline,
137 kexec_extra_fdt_size_ppc64(image, rmem));
138 if (!fdt) {
139 pr_err("Error setting up the new device tree.\n");
140 ret = -EINVAL;
141 goto out;
142 }
143
144 ret = setup_new_fdt_ppc64(image, fdt, rmem);
145 if (ret)
146 goto out_free_fdt;
147
148 if (!IS_ENABLED(CONFIG_CRASH_HOTPLUG) || image->type != KEXEC_TYPE_CRASH)
149 fdt_pack(fdt);
150
151 kbuf.buffer = fdt;
152 kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
153 kbuf.buf_align = PAGE_SIZE;
154 kbuf.top_down = true;
155 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
156 ret = kexec_add_buffer(&kbuf);
157 if (ret)
158 goto out_free_fdt;
159
160 /* FDT will be freed in arch_kimage_file_post_load_cleanup */
161 image->arch.fdt = fdt;
162
163 fdt_load_addr = kbuf.mem;
164
165 kexec_dprintk("Loaded device tree at 0x%lx\n", fdt_load_addr);
166
167 slave_code = elf_info.buffer + elf_info.proghdrs[0].p_offset;
168 ret = setup_purgatory_ppc64(image, slave_code, fdt, kernel_load_addr,
169 fdt_load_addr);
170 if (ret)
171 pr_err("Error setting up the purgatory.\n");
172
173 goto out;
174
175 out_free_fdt:
176 kvfree(fdt);
177 out:
178 kfree(rmem);
179 kfree(modified_cmdline);
180 kexec_free_elf_info(&elf_info);
181
182 return ret ? ERR_PTR(ret) : NULL;
183 }
184
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
2025-12-26 14:06 [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel Coiby Xu
2025-12-27 14:35 ` kernel test robot
@ 2026-01-01 15:06 ` Sourabh Jain
2026-01-06 6:26 ` Coiby Xu
2026-01-06 7:40 ` [PATCH v2] " Coiby Xu
2 siblings, 1 reply; 8+ messages in thread
From: Sourabh Jain @ 2026-01-01 15:06 UTC (permalink / raw)
To: Coiby Xu, kexec, linuxppc-dev
Cc: Thomas Staudt, Arnaud Lefebvre, Baoquan he, Dave Young,
Kairui Song, Pingfan Liu, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
open list
On 26/12/25 19:36, Coiby Xu wrote:
> Based on the CONFIG_CRASH_DM_CRYPT feature, this patch adds
> LUKS-encrypted device dump target support to PowerPC by addressing two
> challenges [1],
> - Kdump kernel may not be able to decrypt the LUKS partition. For some
> machines, a system administrator may not have a chance to enter the
> password to decrypt the device in kdump initramfs after the 1st kernel
> crashes
>
> - LUKS2 by default use the memory-hard Argon2 key derivation function
> which is quite memory-consuming compared to the limited memory reserved
> for kdump.
>
> 1st kernel will build up the kernel command parameter dmcryptkeys as
> similar to elfcorehdr to pass the memory address of the stored info of
> dm-crypt keys to the kdump kernel.
>
> [1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
>
> Cc: Thomas Staudt <tstaudt@de.ibm.com>
> Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
> Cc: Baoquan he <bhe@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Kairui Song <ryncsn@gmail.com>
> Cc: Pingfan Liu <kernelfans@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Coiby Xu <coxu@redhat.com>
> ---
> arch/powerpc/include/asm/kexec.h | 3 ++-
> arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++-
> arch/powerpc/kexec/file_load.c | 19 +++++++++++--------
> 3 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
> index bd4a6c42a5f3..f3d098d543b4 100644
> --- a/arch/powerpc/include/asm/kexec.h
> +++ b/arch/powerpc/include/asm/kexec.h
> @@ -80,7 +80,8 @@ struct kimage_arch {
> };
>
> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
> - unsigned long cmdline_len);
> + unsigned long cmdline_len,
> + char *name, unsigned long addr);
> int setup_purgatory(struct kimage *image, const void *slave_code,
> const void *fdt, unsigned long kernel_load_addr,
> unsigned long fdt_load_addr);
> diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
> index 5d6d616404cf..57cb3361d91b 100644
> --- a/arch/powerpc/kexec/elf_64.c
> +++ b/arch/powerpc/kexec/elf_64.c
> @@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
>
> /* Setup cmdline for kdump kernel case */
> modified_cmdline = setup_kdump_cmdline(image, cmdline,
> - cmdline_len);
> + cmdline_len,
> + "elfcorehdr",
> + image->elf_load_addr);
> if (!modified_cmdline) {
> pr_err("Setting up cmdline for kdump kernel failed\n");
> ret = -EINVAL;
> goto out;
> }
> cmdline = modified_cmdline;
> + cmdline_len = strlen(cmdline) + 1;
> +
> + ret = crash_load_dm_crypt_keys(image);
> + if (ret == -ENOENT) {
> + kexec_dprintk("No dm crypt key to load\n");
> + } else if (ret) {
> + pr_err("Failed to load dm crypt keys\n");
> + return ERR_PTR(ret);
> + }
> +
> + if (image->dm_crypt_keys_addr != 0) {
> + modified_cmdline = setup_kdump_cmdline(image, cmdline,
> + cmdline_len,
> + "dmcryptkeys",
> + image->dm_crypt_keys_addr);
> + if (!modified_cmdline) {
> + pr_err("Setting up cmdline for kdump kernel failed\n");
> + ret = -EINVAL;
> + goto out;
> + }
> + cmdline = modified_cmdline;
> + }
> }
>
> if (initrd != NULL) {
> diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c
> index 4284f76cbef5..e1c08050286d 100644
> --- a/arch/powerpc/kexec/file_load.c
> +++ b/arch/powerpc/kexec/file_load.c
> @@ -23,38 +23,41 @@
> #define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */
>
> /**
> - * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
> + * setup_kdump_cmdline - Prepend "<name>=<addr> " to command line
> * of kdump kernel for exporting the core.
> * @image: Kexec image
> * @cmdline: Command line parameters to update.
> * @cmdline_len: Length of the cmdline parameters.
> + * @name: Name e.g elfcorehdr.
> + * @addr: Memory address.
> *
> * kdump segment must be setup before calling this function.
> *
> * Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
> */
> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
> - unsigned long cmdline_len)
> + unsigned long cmdline_len,
> + char *name, unsigned long addr)
> {
> - int elfcorehdr_strlen;
> + unsigned long parameter_len;
> char *cmdline_ptr;
>
> cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
> if (!cmdline_ptr)
> return NULL;
>
> - elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
> - image->elf_load_addr);
> + parameter_len = sprintf(cmdline_ptr, "%s=0x%lx ", name, addr);
>
> - if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
> - pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
> + if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) {
> + pr_err("Appending %s=<addr> exceeds cmdline size\n", name);
> kfree(cmdline_ptr);
> return NULL;
> }
>
> - memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
> + memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len);
> // Ensure it's nul terminated
> cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
> + kfree(cmdline);
When setup_kdump_cmdline() is called for elfcorehdr, cmdline holds the
same pointer as image->cmdline_buf. Freeing it here may therefore
cause issues, right?
Currently, image->cmdline_buf is not used after calling the
architecture-specific load function (elf64_load on powerpc).
However, kimage_file_post_load_cleanup() later calls kfree() on
the same address.
> return cmdline_ptr;
> }
>
>
> base-commit: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
2026-01-01 15:06 ` Sourabh Jain
@ 2026-01-06 6:26 ` Coiby Xu
0 siblings, 0 replies; 8+ messages in thread
From: Coiby Xu @ 2026-01-06 6:26 UTC (permalink / raw)
To: Sourabh Jain
Cc: kexec, linuxppc-dev, Thomas Staudt, Arnaud Lefebvre, Baoquan he,
Dave Young, Kairui Song, Pingfan Liu, Andrew Morton,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), open list
On Thu, Jan 01, 2026 at 08:36:09PM +0530, Sourabh Jain wrote:
>
>
>On 26/12/25 19:36, Coiby Xu wrote:
>>Based on the CONFIG_CRASH_DM_CRYPT feature, this patch adds
>>LUKS-encrypted device dump target support to PowerPC by addressing two
>>challenges [1],
>> - Kdump kernel may not be able to decrypt the LUKS partition. For some
>> machines, a system administrator may not have a chance to enter the
>> password to decrypt the device in kdump initramfs after the 1st kernel
>> crashes
>>
>> - LUKS2 by default use the memory-hard Argon2 key derivation function
>> which is quite memory-consuming compared to the limited memory reserved
>> for kdump.
>>
>>1st kernel will build up the kernel command parameter dmcryptkeys as
>>similar to elfcorehdr to pass the memory address of the stored info of
>>dm-crypt keys to the kdump kernel.
>>
>>[1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
>>
>>Cc: Thomas Staudt <tstaudt@de.ibm.com>
>>Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
>>Cc: Baoquan he <bhe@redhat.com>
>>Cc: Dave Young <dyoung@redhat.com>
>>Cc: Kairui Song <ryncsn@gmail.com>
>>Cc: Pingfan Liu <kernelfans@gmail.com>
>>Cc: Andrew Morton <akpm@linux-foundation.org>
>>Signed-off-by: Coiby Xu <coxu@redhat.com>
>>---
>> arch/powerpc/include/asm/kexec.h | 3 ++-
>> arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++-
>> arch/powerpc/kexec/file_load.c | 19 +++++++++++--------
>> 3 files changed, 38 insertions(+), 10 deletions(-)
>>
>>diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
>>index bd4a6c42a5f3..f3d098d543b4 100644
>>--- a/arch/powerpc/include/asm/kexec.h
>>+++ b/arch/powerpc/include/asm/kexec.h
>>@@ -80,7 +80,8 @@ struct kimage_arch {
>> };
>> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
>>- unsigned long cmdline_len);
>>+ unsigned long cmdline_len,
>>+ char *name, unsigned long addr);
>> int setup_purgatory(struct kimage *image, const void *slave_code,
>> const void *fdt, unsigned long kernel_load_addr,
>> unsigned long fdt_load_addr);
>>diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
>>index 5d6d616404cf..57cb3361d91b 100644
>>--- a/arch/powerpc/kexec/elf_64.c
>>+++ b/arch/powerpc/kexec/elf_64.c
>>@@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
>> /* Setup cmdline for kdump kernel case */
>> modified_cmdline = setup_kdump_cmdline(image, cmdline,
>>- cmdline_len);
>>+ cmdline_len,
>>+ "elfcorehdr",
>>+ image->elf_load_addr);
>> if (!modified_cmdline) {
>> pr_err("Setting up cmdline for kdump kernel failed\n");
>> ret = -EINVAL;
>> goto out;
>> }
>> cmdline = modified_cmdline;
>>+ cmdline_len = strlen(cmdline) + 1;
>>+
>>+ ret = crash_load_dm_crypt_keys(image);
>>+ if (ret == -ENOENT) {
>>+ kexec_dprintk("No dm crypt key to load\n");
>>+ } else if (ret) {
>>+ pr_err("Failed to load dm crypt keys\n");
>>+ return ERR_PTR(ret);
>>+ }
>>+
>>+ if (image->dm_crypt_keys_addr != 0) {
>>+ modified_cmdline = setup_kdump_cmdline(image, cmdline,
>>+ cmdline_len,
>>+ "dmcryptkeys",
>>+ image->dm_crypt_keys_addr);
>>+ if (!modified_cmdline) {
>>+ pr_err("Setting up cmdline for kdump kernel failed\n");
>>+ ret = -EINVAL;
>>+ goto out;
>>+ }
>>+ cmdline = modified_cmdline;
>>+ }
>> }
>> if (initrd != NULL) {
>>diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c
>>index 4284f76cbef5..e1c08050286d 100644
>>--- a/arch/powerpc/kexec/file_load.c
>>+++ b/arch/powerpc/kexec/file_load.c
>>@@ -23,38 +23,41 @@
>> #define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */
>> /**
>>- * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
>>+ * setup_kdump_cmdline - Prepend "<name>=<addr> " to command line
>> * of kdump kernel for exporting the core.
>> * @image: Kexec image
>> * @cmdline: Command line parameters to update.
>> * @cmdline_len: Length of the cmdline parameters.
>>+ * @name: Name e.g elfcorehdr.
>>+ * @addr: Memory address.
>> *
>> * kdump segment must be setup before calling this function.
>> *
>> * Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
>> */
>> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
>>- unsigned long cmdline_len)
>>+ unsigned long cmdline_len,
>>+ char *name, unsigned long addr)
>> {
>>- int elfcorehdr_strlen;
>>+ unsigned long parameter_len;
>> char *cmdline_ptr;
>> cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
>> if (!cmdline_ptr)
>> return NULL;
>>- elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
>>- image->elf_load_addr);
>>+ parameter_len = sprintf(cmdline_ptr, "%s=0x%lx ", name, addr);
>>- if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
>>- pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
>>+ if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) {
>>+ pr_err("Appending %s=<addr> exceeds cmdline size\n", name);
>> kfree(cmdline_ptr);
>> return NULL;
>> }
>>- memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
>>+ memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len);
>> // Ensure it's nul terminated
>> cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
>>+ kfree(cmdline);
>
>When setup_kdump_cmdline() is called for elfcorehdr, cmdline holds the
>same pointer as image->cmdline_buf. Freeing it here may therefore
>cause issues, right?
Yes, you are right, I'll drop the above kfree in next version.
>
>Currently, image->cmdline_buf is not used after calling the
>architecture-specific load function (elf64_load on powerpc).
>However, kimage_file_post_load_cleanup() later calls kfree() on
>the same address.
I missed kimage_file_post_load_cleanup. Thanks for pointing it out!
--
Best regards,
Coiby
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] powerpc/kdump: pass dm-crypt keys to kdump kernel
2025-12-26 14:06 [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel Coiby Xu
2025-12-27 14:35 ` kernel test robot
2026-01-01 15:06 ` Sourabh Jain
@ 2026-01-06 7:40 ` Coiby Xu
2026-01-07 9:02 ` Sourabh Jain
2 siblings, 1 reply; 8+ messages in thread
From: Coiby Xu @ 2026-01-06 7:40 UTC (permalink / raw)
To: kexec, linuxppc-dev
Cc: Thomas Staudt, Arnaud Lefebvre, Baoquan he, Dave Young,
Kairui Song, Pingfan Liu, Andrew Morton, Sourabh Jain,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Vivek Goyal, open list
CONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted
device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some
machines, a system administrator may not have a chance to enter the
password to decrypt the device in kdump initramfs after the 1st kernel
crashes
- LUKS2 by default use the memory-hard Argon2 key derivation function
which is quite memory-consuming compared to the limited memory reserved
for kdump.
To also enable this feature for PowerPC, we only need to let 1st kernel
build up the kernel command parameter dmcryptkeys as similar to
elfcorehdr to pass the memory address of the stored info of dm-crypt
keys to the kdump kernel.
Note to avoid a building failure [2] caused by undeclared function
crash_load_dm_crypt_keys when CONFIG_CRASH_DUMP is not enabled,
realign the function declaration with CONFIG_CRASH_DM_CRYPT.
[1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
[2] https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.com/
Cc: Thomas Staudt <tstaudt@de.ibm.com>
Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Pingfan Liu <kernelfans@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
v2:
- fix double kfree issue [Sourabh]
- corretly kfree old modified_cmdline
- use imperative mood for commit message
- fix a compiling error caught by kernel test robot
arch/powerpc/include/asm/kexec.h | 3 ++-
arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++-
arch/powerpc/kexec/file_load.c | 18 ++++++++++--------
include/linux/crash_core.h | 14 +++++++-------
4 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
index bd4a6c42a5f3..f3d098d543b4 100644
--- a/arch/powerpc/include/asm/kexec.h
+++ b/arch/powerpc/include/asm/kexec.h
@@ -80,7 +80,8 @@ struct kimage_arch {
};
char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
- unsigned long cmdline_len);
+ unsigned long cmdline_len,
+ char *name, unsigned long addr);
int setup_purgatory(struct kimage *image, const void *slave_code,
const void *fdt, unsigned long kernel_load_addr,
unsigned long fdt_load_addr);
diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index 5d6d616404cf..995d7e8e98e1 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
/* Setup cmdline for kdump kernel case */
modified_cmdline = setup_kdump_cmdline(image, cmdline,
- cmdline_len);
+ cmdline_len,
+ "elfcorehdr",
+ image->elf_load_addr);
if (!modified_cmdline) {
pr_err("Setting up cmdline for kdump kernel failed\n");
ret = -EINVAL;
goto out;
}
cmdline = modified_cmdline;
+ cmdline_len = strlen(cmdline) + 1;
+
+ ret = crash_load_dm_crypt_keys(image);
+ if (ret == -ENOENT) {
+ kexec_dprintk("No dm crypt key to load\n");
+ } else if (ret) {
+ pr_err("Failed to load dm crypt keys\n");
+ return ERR_PTR(ret);
+ }
+
+ if (image->dm_crypt_keys_addr != 0) {
+ modified_cmdline = setup_kdump_cmdline(image, cmdline,
+ cmdline_len,
+ "dmcryptkeys",
+ image->dm_crypt_keys_addr);
+ kfree(cmdline);
+ if (!modified_cmdline) {
+ pr_err("Setting up cmdline for kdump kernel failed\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ cmdline = modified_cmdline;
+ }
}
if (initrd != NULL) {
diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c
index 4284f76cbef5..9964c57785f5 100644
--- a/arch/powerpc/kexec/file_load.c
+++ b/arch/powerpc/kexec/file_load.c
@@ -23,36 +23,38 @@
#define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */
/**
- * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
+ * setup_kdump_cmdline - Prepend "<name>=<addr> " to command line
* of kdump kernel for exporting the core.
* @image: Kexec image
* @cmdline: Command line parameters to update.
* @cmdline_len: Length of the cmdline parameters.
+ * @name: Name e.g elfcorehdr.
+ * @addr: Memory address.
*
* kdump segment must be setup before calling this function.
*
* Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
*/
char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
- unsigned long cmdline_len)
+ unsigned long cmdline_len,
+ char *name, unsigned long addr)
{
- int elfcorehdr_strlen;
+ unsigned long parameter_len;
char *cmdline_ptr;
cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
if (!cmdline_ptr)
return NULL;
- elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
- image->elf_load_addr);
+ parameter_len = sprintf(cmdline_ptr, "%s=0x%lx ", name, addr);
- if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
- pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
+ if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) {
+ pr_err("Appending %s=<addr> exceeds cmdline size\n", name);
kfree(cmdline_ptr);
return NULL;
}
- memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
+ memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len);
// Ensure it's nul terminated
cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
return cmdline_ptr;
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index d35726d6a415..e128270c703f 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -34,13 +34,6 @@ static inline void arch_kexec_protect_crashkres(void) { }
static inline void arch_kexec_unprotect_crashkres(void) { }
#endif
-#ifdef CONFIG_CRASH_DM_CRYPT
-int crash_load_dm_crypt_keys(struct kimage *image);
-ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos);
-#else
-static inline int crash_load_dm_crypt_keys(struct kimage *image) {return 0; }
-#endif
-
#ifndef arch_crash_handle_hotplug_event
static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
#endif
@@ -96,4 +89,11 @@ static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};
static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { return 0; };
#endif /* CONFIG_CRASH_DUMP*/
+#ifdef CONFIG_CRASH_DM_CRYPT
+int crash_load_dm_crypt_keys(struct kimage *image);
+ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos);
+#else
+static inline int crash_load_dm_crypt_keys(struct kimage *image) { return 0; }
+#endif
+
#endif /* LINUX_CRASH_CORE_H */
base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
2025-12-27 14:35 ` kernel test robot
@ 2026-01-06 7:46 ` Coiby Xu
0 siblings, 0 replies; 8+ messages in thread
From: Coiby Xu @ 2026-01-06 7:46 UTC (permalink / raw)
To: kernel test robot
Cc: kexec, linuxppc-dev, llvm, oe-kbuild-all, Thomas Staudt,
Arnaud Lefebvre, Baoquan he, Dave Young, Kairui Song, Pingfan Liu,
Andrew Morton, Linux Memory Management List, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
linux-kernel
On Sat, Dec 27, 2025 at 10:35:11PM +0800, kernel test robot wrote:
>Hi Coiby,
>
>kernel test robot noticed the following build errors:
>
>[auto build test ERROR on ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1]
>
>url: https://github.com/intel-lab-lkp/linux/commits/Coiby-Xu/powerpc-kdump-pass-dm-crypt-keys-to-kdump-kernel/20251226-220726
>base: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
>patch link: https://lore.kernel.org/r/20251226140636.1378505-1-coxu%40redhat.com
>patch subject: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel
>config: powerpc64-randconfig-001-20251227 (https://download.01.org/0day-ci/archive/20251227/202512272218.ghBaSjzO-lkp@intel.com/config)
>compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279)
>reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251227/202512272218.ghBaSjzO-lkp@intel.com/reproduce)
>
>If you fix the issue in a separate patch/commit (i.e. not just a new version of
>the same patch/commit), kindly add following tags
>| Reported-by: kernel test robot <lkp@intel.com>
>| Closes: https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.com/
>
>All errors (new ones prefixed by >>):
>
>>> arch/powerpc/kexec/elf_64.c:95:9: error: call to undeclared function 'crash_load_dm_crypt_keys'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> 95 | ret = crash_load_dm_crypt_keys(image);
> | ^
> 1 error generated.
This issue has been addressed in v2
https://lore.kernel.org/all/20260106074039.564707-1-coxu@redhat.com/
Thanks!
--
Best regards,
Coiby
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] powerpc/kdump: pass dm-crypt keys to kdump kernel
2026-01-06 7:40 ` [PATCH v2] " Coiby Xu
@ 2026-01-07 9:02 ` Sourabh Jain
2026-01-08 10:32 ` Coiby Xu
0 siblings, 1 reply; 8+ messages in thread
From: Sourabh Jain @ 2026-01-07 9:02 UTC (permalink / raw)
To: Coiby Xu, kexec, linuxppc-dev
Cc: Thomas Staudt, Arnaud Lefebvre, Baoquan he, Dave Young,
Kairui Song, Pingfan Liu, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Vivek Goyal, open list
On 06/01/26 13:10, Coiby Xu wrote:
> CONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted
> device dump target by addressing two challenges [1],
> - Kdump kernel may not be able to decrypt the LUKS partition. For some
> machines, a system administrator may not have a chance to enter the
> password to decrypt the device in kdump initramfs after the 1st kernel
> crashes
>
> - LUKS2 by default use the memory-hard Argon2 key derivation function
> which is quite memory-consuming compared to the limited memory reserved
> for kdump.
>
> To also enable this feature for PowerPC, we only need to let 1st kernel
> build up the kernel command parameter dmcryptkeys as similar to
> elfcorehdr to pass the memory address of the stored info of dm-crypt
> keys to the kdump kernel.
>
> Note to avoid a building failure [2] caused by undeclared function
> crash_load_dm_crypt_keys when CONFIG_CRASH_DUMP is not enabled,
> realign the function declaration with CONFIG_CRASH_DM_CRYPT.
>
> [1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
> [2] https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.com/
>
> Cc: Thomas Staudt <tstaudt@de.ibm.com>
> Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
> Cc: Baoquan he <bhe@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Kairui Song <ryncsn@gmail.com>
> Cc: Pingfan Liu <kernelfans@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
> Signed-off-by: Coiby Xu <coxu@redhat.com>
> ---
> v2:
> - fix double kfree issue [Sourabh]
> - corretly kfree old modified_cmdline
> - use imperative mood for commit message
> - fix a compiling error caught by kernel test robot
>
> arch/powerpc/include/asm/kexec.h | 3 ++-
> arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++-
> arch/powerpc/kexec/file_load.c | 18 ++++++++++--------
> include/linux/crash_core.h | 14 +++++++-------
> 4 files changed, 45 insertions(+), 17 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
> index bd4a6c42a5f3..f3d098d543b4 100644
> --- a/arch/powerpc/include/asm/kexec.h
> +++ b/arch/powerpc/include/asm/kexec.h
> @@ -80,7 +80,8 @@ struct kimage_arch {
> };
>
> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
> - unsigned long cmdline_len);
> + unsigned long cmdline_len,
> + char *name, unsigned long addr);
> int setup_purgatory(struct kimage *image, const void *slave_code,
> const void *fdt, unsigned long kernel_load_addr,
> unsigned long fdt_load_addr);
> diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
> index 5d6d616404cf..995d7e8e98e1 100644
> --- a/arch/powerpc/kexec/elf_64.c
> +++ b/arch/powerpc/kexec/elf_64.c
> @@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
>
> /* Setup cmdline for kdump kernel case */
> modified_cmdline = setup_kdump_cmdline(image, cmdline,
> - cmdline_len);
> + cmdline_len,
> + "elfcorehdr",
> + image->elf_load_addr);
> if (!modified_cmdline) {
> pr_err("Setting up cmdline for kdump kernel failed\n");
> ret = -EINVAL;
> goto out;
> }
> cmdline = modified_cmdline;
> + cmdline_len = strlen(cmdline) + 1;
I have a limited understanding of the new dm-crypt keys, but the way they
are loaded and the additional command-line options added for the kdump
kernel look good to me.
Feel free to add:
Acked-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> +
> + ret = crash_load_dm_crypt_keys(image);
> + if (ret == -ENOENT) {
> + kexec_dprintk("No dm crypt key to load\n");
> + } else if (ret) {
> + pr_err("Failed to load dm crypt keys\n");
> + return ERR_PTR(ret);
> + }
> +
> + if (image->dm_crypt_keys_addr != 0) {
> + modified_cmdline = setup_kdump_cmdline(image, cmdline,
> + cmdline_len,
> + "dmcryptkeys",
> + image->dm_crypt_keys_addr);
> + kfree(cmdline);
> + if (!modified_cmdline) {
> + pr_err("Setting up cmdline for kdump kernel failed\n");
> + ret = -EINVAL;
> + goto out;
> + }
> + cmdline = modified_cmdline;
> + }
> }
>
> if (initrd != NULL) {
> diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c
> index 4284f76cbef5..9964c57785f5 100644
> --- a/arch/powerpc/kexec/file_load.c
> +++ b/arch/powerpc/kexec/file_load.c
> @@ -23,36 +23,38 @@
> #define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */
>
> /**
> - * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
> + * setup_kdump_cmdline - Prepend "<name>=<addr> " to command line
> * of kdump kernel for exporting the core.
> * @image: Kexec image
> * @cmdline: Command line parameters to update.
> * @cmdline_len: Length of the cmdline parameters.
> + * @name: Name e.g elfcorehdr.
> + * @addr: Memory address.
> *
> * kdump segment must be setup before calling this function.
> *
> * Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
> */
> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
> - unsigned long cmdline_len)
> + unsigned long cmdline_len,
> + char *name, unsigned long addr)
> {
> - int elfcorehdr_strlen;
> + unsigned long parameter_len;
> char *cmdline_ptr;
>
> cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
> if (!cmdline_ptr)
> return NULL;
>
> - elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
> - image->elf_load_addr);
> + parameter_len = sprintf(cmdline_ptr, "%s=0x%lx ", name, addr);
>
> - if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
> - pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
> + if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) {
> + pr_err("Appending %s=<addr> exceeds cmdline size\n", name);
> kfree(cmdline_ptr);
> return NULL;
> }
>
> - memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
> + memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len);
> // Ensure it's nul terminated
> cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
> return cmdline_ptr;
> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> index d35726d6a415..e128270c703f 100644
> --- a/include/linux/crash_core.h
> +++ b/include/linux/crash_core.h
> @@ -34,13 +34,6 @@ static inline void arch_kexec_protect_crashkres(void) { }
> static inline void arch_kexec_unprotect_crashkres(void) { }
> #endif
>
> -#ifdef CONFIG_CRASH_DM_CRYPT
> -int crash_load_dm_crypt_keys(struct kimage *image);
> -ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos);
> -#else
> -static inline int crash_load_dm_crypt_keys(struct kimage *image) {return 0; }
> -#endif
> -
> #ifndef arch_crash_handle_hotplug_event
> static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
> #endif
> @@ -96,4 +89,11 @@ static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};
> static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { return 0; };
> #endif /* CONFIG_CRASH_DUMP*/
>
> +#ifdef CONFIG_CRASH_DM_CRYPT
> +int crash_load_dm_crypt_keys(struct kimage *image);
> +ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos);
> +#else
> +static inline int crash_load_dm_crypt_keys(struct kimage *image) { return 0; }
> +#endif
> +
> #endif /* LINUX_CRASH_CORE_H */
>
> base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] powerpc/kdump: pass dm-crypt keys to kdump kernel
2026-01-07 9:02 ` Sourabh Jain
@ 2026-01-08 10:32 ` Coiby Xu
0 siblings, 0 replies; 8+ messages in thread
From: Coiby Xu @ 2026-01-08 10:32 UTC (permalink / raw)
To: Sourabh Jain
Cc: kexec, linuxppc-dev, Thomas Staudt, Arnaud Lefebvre, Baoquan he,
Dave Young, Kairui Song, Pingfan Liu, Andrew Morton,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Vivek Goyal, open list
On Wed, Jan 07, 2026 at 02:32:41PM +0530, Sourabh Jain wrote:
>
>
>On 06/01/26 13:10, Coiby Xu wrote:
>>CONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted
>>device dump target by addressing two challenges [1],
>> - Kdump kernel may not be able to decrypt the LUKS partition. For some
>> machines, a system administrator may not have a chance to enter the
>> password to decrypt the device in kdump initramfs after the 1st kernel
>> crashes
>>
>> - LUKS2 by default use the memory-hard Argon2 key derivation function
>> which is quite memory-consuming compared to the limited memory reserved
>> for kdump.
>>
>>To also enable this feature for PowerPC, we only need to let 1st kernel
>>build up the kernel command parameter dmcryptkeys as similar to
>>elfcorehdr to pass the memory address of the stored info of dm-crypt
>>keys to the kdump kernel.
>>
>>Note to avoid a building failure [2] caused by undeclared function
>>crash_load_dm_crypt_keys when CONFIG_CRASH_DUMP is not enabled,
>>realign the function declaration with CONFIG_CRASH_DM_CRYPT.
>>
>>[1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/
>>[2] https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.com/
>>
>>Cc: Thomas Staudt <tstaudt@de.ibm.com>
>>Cc: Arnaud Lefebvre <arnaud.lefebvre@clever-cloud.com>
>>Cc: Baoquan he <bhe@redhat.com>
>>Cc: Dave Young <dyoung@redhat.com>
>>Cc: Kairui Song <ryncsn@gmail.com>
>>Cc: Pingfan Liu <kernelfans@gmail.com>
>>Cc: Andrew Morton <akpm@linux-foundation.org>
>>Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
>>Signed-off-by: Coiby Xu <coxu@redhat.com>
>>---
>>v2:
>>- fix double kfree issue [Sourabh]
>>- corretly kfree old modified_cmdline
>>- use imperative mood for commit message
>>- fix a compiling error caught by kernel test robot
>>
>> arch/powerpc/include/asm/kexec.h | 3 ++-
>> arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++-
>> arch/powerpc/kexec/file_load.c | 18 ++++++++++--------
>> include/linux/crash_core.h | 14 +++++++-------
>> 4 files changed, 45 insertions(+), 17 deletions(-)
>>
>>diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
>>index bd4a6c42a5f3..f3d098d543b4 100644
>>--- a/arch/powerpc/include/asm/kexec.h
>>+++ b/arch/powerpc/include/asm/kexec.h
>>@@ -80,7 +80,8 @@ struct kimage_arch {
>> };
>> char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
>>- unsigned long cmdline_len);
>>+ unsigned long cmdline_len,
>>+ char *name, unsigned long addr);
>> int setup_purgatory(struct kimage *image, const void *slave_code,
>> const void *fdt, unsigned long kernel_load_addr,
>> unsigned long fdt_load_addr);
>>diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
>>index 5d6d616404cf..995d7e8e98e1 100644
>>--- a/arch/powerpc/kexec/elf_64.c
>>+++ b/arch/powerpc/kexec/elf_64.c
>>@@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
>> /* Setup cmdline for kdump kernel case */
>> modified_cmdline = setup_kdump_cmdline(image, cmdline,
>>- cmdline_len);
>>+ cmdline_len,
>>+ "elfcorehdr",
>>+ image->elf_load_addr);
>> if (!modified_cmdline) {
>> pr_err("Setting up cmdline for kdump kernel failed\n");
>> ret = -EINVAL;
>> goto out;
>> }
>> cmdline = modified_cmdline;
>>+ cmdline_len = strlen(cmdline) + 1;
>
>I have a limited understanding of the new dm-crypt keys, but the way they
>are loaded and the additional command-line options added for the kdump
>kernel look good to me.
>
>Feel free to add:
>Acked-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Thanks for reviewing and acknowledging the patch!
--
Best regards,
Coiby
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-01-08 10:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-26 14:06 [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel Coiby Xu
2025-12-27 14:35 ` kernel test robot
2026-01-06 7:46 ` Coiby Xu
2026-01-01 15:06 ` Sourabh Jain
2026-01-06 6:26 ` Coiby Xu
2026-01-06 7:40 ` [PATCH v2] " Coiby Xu
2026-01-07 9:02 ` Sourabh Jain
2026-01-08 10:32 ` Coiby Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).