From: Youling Tang <youling.tang@linux.dev>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>, Baoquan He <bhe@redhat.com>,
kexec@lists.infradead.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org,
Youling Tang <tangyouling@kylinos.cn>
Subject: Re: [PATCH 3/6] LoongArch/kexec_file: Add initrd loading
Date: Tue, 12 Aug 2025 10:38:04 +0800 [thread overview]
Message-ID: <15fdef37-f380-4b5c-85bb-24482e883dcc@linux.dev> (raw)
In-Reply-To: <CAAhV-H4Sf=74-ni=qUkg3doC4iLrVt=m2bCYCgfmVC0WLNhiDQ@mail.gmail.com>
Hi, Huacai
On 2025/8/11 22:12, Huacai Chen wrote:
> Hi, Youling,
>
> On Mon, Aug 11, 2025 at 5:28 PM Youling Tang <youling.tang@linux.dev> wrote:
>> From: Youling Tang <tangyouling@kylinos.cn>
>>
>> Add inird loading support and pass it to the second kernel via the
>> cmdline 'initrd=start,size'.
> I think Patch-3 and Patch-5 should be merged into Patch-2.
Not all cases require loading initrd, so Patch-2 is a runnable basic patch.
Separating it into different patches makes it easier to understand and
review the code.
Patch-5 coming out separately can better illustrate the role of "mem"
parameters in capturing the kernel.
Youling.
>
> Huacai
>
>> Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
>> ---
>> arch/loongarch/kernel/machine_kexec_file.c | 71 ++++++++++++++++++++++
>> 1 file changed, 71 insertions(+)
>>
>> diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
>> index bc91ae0afa4c..e1240644f529 100644
>> --- a/arch/loongarch/kernel/machine_kexec_file.c
>> +++ b/arch/loongarch/kernel/machine_kexec_file.c
>> @@ -34,13 +34,84 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
>> return kexec_image_post_load_cleanup_default(image);
>> }
>>
>> +/* Adds the "initrd=start,size" command line parameter to command line. */
>> +static void cmdline_add_initrd(struct kimage *image, unsigned long *cmdline_tmplen,
>> + char *modified_cmdline, unsigned long initrd)
>> +{
>> + int initrd_strlen;
>> +
>> + initrd_strlen = sprintf(modified_cmdline + (*cmdline_tmplen), "initrd=0x%lx,0x%lx ",
>> + initrd, image->initrd_buf_len);
>> + *cmdline_tmplen += initrd_strlen;
>> +}
>> +
>> +/*
>> + * Tries to add the initrd to the image. If it is not possible to find
>> + * valid locations, this function will undo changes to the image and return non
>> + * zero.
>> + */
>> int load_other_segments(struct kimage *image,
>> unsigned long kernel_load_addr,
>> unsigned long kernel_size,
>> char *initrd, unsigned long initrd_len,
>> char *cmdline, unsigned long cmdline_len)
>> {
>> + struct kexec_buf kbuf;
>> + unsigned long orig_segments = image->nr_segments;
>> + char *modified_cmdline = NULL;
>> + unsigned long cmdline_tmplen = 0;
>> + unsigned long initrd_load_addr = 0;
>> + int ret = 0;
>> +
>> +
>> + kbuf.image = image;
>> + /* not allocate anything below the kernel */
>> + kbuf.buf_min = kernel_load_addr + kernel_size;
>> +
>> + modified_cmdline = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
>> + if (!modified_cmdline)
>> + return -EINVAL;
>> +
>> + /* Ensure it's nul terminated */
>> + modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0';
>> +
>> + /* load initrd */
>> + if (initrd) {
>> + kbuf.buffer = initrd;
>> + kbuf.bufsz = initrd_len;
>> + kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
>> + kbuf.memsz = initrd_len;
>> + kbuf.buf_align = 0;
>> + /* within 1GB-aligned window of up to 32GB in size */
>> + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G)
>> + + (unsigned long)SZ_1G * 32;
>> + kbuf.top_down = false;
>> +
>> + ret = kexec_add_buffer(&kbuf);
>> + if (ret)
>> + goto out_err;
>> + initrd_load_addr = kbuf.mem;
>> +
>> + kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
>> + initrd_load_addr, kbuf.bufsz, kbuf.memsz);
>> +
>> + /* Add the initrd=start,size parameter to the command line */
>> + cmdline_add_initrd(image, &cmdline_tmplen, modified_cmdline, initrd_load_addr);
>> + }
>> +
>> + if (cmdline_len + cmdline_tmplen > COMMAND_LINE_SIZE) {
>> + pr_err("Appending kdump cmdline exceeds cmdline size\n");
>> + ret = -EINVAL;
>> + goto out_err;
>> + }
>> + memcpy(modified_cmdline + cmdline_tmplen, cmdline, cmdline_len);
>> + cmdline = modified_cmdline;
>> image->arch.cmdline_ptr = (unsigned long)cmdline;
>>
>> return 0;
>> +
>> +out_err:
>> + image->nr_segments = orig_segments;
>> + kfree(modified_cmdline);
>> + return ret;
>> }
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2025-08-12 2:38 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 9:26 [PATCH 0/6] Add kexec_file support for LoongArch Youling Tang
2025-08-11 9:26 ` [PATCH 1/6] LoongArch: Add struct loongarch_image_header for kernel image Youling Tang
2025-08-11 9:26 ` [PATCH 2/6] LoongArch: Add kexec_file support Youling Tang
2025-08-11 14:07 ` Huacai Chen
2025-08-12 1:21 ` Youling Tang
2025-08-12 1:53 ` Yanteng Si
2025-08-12 9:32 ` Youling Tang
2025-08-13 1:15 ` Yanteng Si
2025-08-12 2:53 ` Huacai Chen
2025-08-11 17:06 ` Yao Zi
2025-08-12 2:39 ` Huacai Chen
2025-08-12 7:56 ` Yao Zi
2025-08-12 6:15 ` Youling Tang
2025-08-12 7:06 ` Youling Tang
2025-08-12 9:43 ` Yao Zi
2025-08-13 2:18 ` Youling Tang
2025-08-13 3:24 ` Yao Zi
2025-08-16 5:37 ` kernel test robot
2025-08-11 9:26 ` [PATCH 3/6] LoongArch/kexec_file: Add initrd loading Youling Tang
2025-08-11 14:12 ` Huacai Chen
2025-08-12 2:38 ` Youling Tang [this message]
2025-08-12 3:03 ` Huacai Chen
2025-08-11 17:58 ` Yao Zi
2025-08-12 4:05 ` Youling Tang
2025-08-12 6:25 ` Yao Zi
2025-08-11 9:26 ` [PATCH 4/6] LoongArch/kexec_file: Add crash dump support Youling Tang
2025-08-11 9:26 ` [PATCH 5/6] LoongArch/kexec_file: Add "mem" parameter to limit memory usage of kdump kernel Youling Tang
2025-08-11 9:26 ` [PATCH 6/6] LoongArch: Enable CONFIG_KEXEC_FILE Youling Tang
2025-08-11 16:20 ` [PATCH 0/6] Add kexec_file support for LoongArch Vincent Li
2025-08-12 6:21 ` Youling Tang
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=15fdef37-f380-4b5c-85bb-24482e883dcc@linux.dev \
--to=youling.tang@linux.dev \
--cc=bhe@redhat.com \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=tangyouling@kylinos.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®