Re: [PATCH v2 5/5] arm64: crash: Add crash hotplug support

From: Jinjie Ruan

Date: Mon Aug 17 2026 - 06:49:23 EST




在 2026/8/14 0:05, Catalin Marinas 写道:
> Hi Jinjie,
>
> On Wed, Jul 29, 2026 at 11:12:35AM +0800, Jinjie Ruan wrote:
>> +/**
>> + * update_crash_elfcorehdr() - Recreate the elfcorehdr and replace it with old
>> + * elfcorehdr in the kexec segment array.
>> + * @image: the active struct kimage
>> + */
>> +static void update_crash_elfcorehdr(struct kimage *image)
>> +{
>> + void *elfbuf = NULL, *old_elfcorehdr;
>> + unsigned long mem, memsz;
>> + unsigned long elfsz = 0;
>> +
>> + /*
>> + * Create the new elfcorehdr reflecting the changes to CPU and/or
>> + * memory resources.
>> + */
>> + if (crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
>> + pr_err("unable to create new elfcorehdr");
>> + goto out;
>> + }
>> +
>> + /*
>> + * Obtain address and size of the elfcorehdr segment, and
>> + * check it against the new elfcorehdr buffer.
>> + */
>> + mem = image->segment[image->elfcorehdr_index].mem;
>> + memsz = image->segment[image->elfcorehdr_index].memsz;
>> + if (elfsz > memsz) {
>> + pr_err("update elfcorehdr elfsz %lu > memsz %lu",
>> + elfsz, memsz);
>> + goto out;
>> + }
>> +
>> + /*
>> + * Copy new elfcorehdr over the old elfcorehdr at destination.
>> + */
>> + old_elfcorehdr = phys_to_virt(mem);
>> +
>> + /*
>> + * Temporarily invalidate the crash image while the
>> + * elfcorehdr is updated.
>> + */
>> + xchg(&kexec_crash_image, NULL);
>> + memcpy(old_elfcorehdr, elfbuf, elfsz);
>> + dcache_clean_inval_poc((unsigned long)old_elfcorehdr,
>> + (unsigned long)(old_elfcorehdr + elfsz));
>> + xchg(&kexec_crash_image, image);
>> + pr_debug("updated elfcorehdr\n");
>> +
>> +out:
>> + vfree(elfbuf);
>> +}
>> +
>> +/**
>> + * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes
>> + * @image: a pointer to kexec_crash_image
>> + * @arg: struct memory_notify handler for memory hotplug case and
>> + * NULL for CPU hotplug case.
>> + *
>> + * Update the kdump image based on the type of hotplug event:
>> + * - CPU add and remove: No action is needed.
>> + * - Memory add/remove: Update the elfcorehdr to reflect the current memory layout.
>> + *
>> + * Prepare the new elfcorehdr and replace the existing elfcorehdr.
>> + */
>> +void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
>> +{
>> + if (image->hp_action == KEXEC_CRASH_HP_ADD_CPU ||
>> + image->hp_action == KEXEC_CRASH_HP_REMOVE_CPU)
>> + return;
>> +
>> + update_crash_elfcorehdr(image);
>> +}
>
> Looking at powerpc, they pass the arg down to update_crash_elfcorehdr()
> to handle the memory hot-unplug case. It looks like the notifier is
> called before the memblock_remove(), so the update above will still
> count the memory being removed.

Hi Catalin,

After delving into the code flow, I believe you are correct.

We need to manually remove the hot-unplug memory here, just like in the
PowerPC case. Will update the code sooner.

>
> There are a few Sashiko comments as well, though some might be about
> existing issues (it would be nice to have them fixed ;)).

Thank you! I will take a close look and try to fix them later.

Best regards,
Jinjie

>