Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: <will@kernel.org>, <akpm@linux-foundation.org>,
	<baoquan.he@linux.dev>, <rppt@kernel.org>,
	<pasha.tatashin@soleen.com>, <pratyush@kernel.org>,
	<thuth@redhat.com>, <mark.rutland@arm.com>, <jic23@kernel.org>,
	<james.morse@arm.com>, <ardb@kernel.org>, <leitao@debian.org>,
	<yeoreum.yun@arm.com>, <sourabhjain@linux.ibm.com>,
	<robh@kernel.org>, <kees@kernel.org>, <coxu@redhat.com>,
	<makb@juniper.net>, <piliu@redhat.com>, <graf@amazon.com>,
	<ebiggers@kernel.org>, <jbouron@amazon.com>, <bgwin@google.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <kexec@lists.infradead.org>
Subject: Re: [PATCH v2 5/5] arm64: crash: Add crash hotplug support
Date: Mon, 17 Aug 2026 18:45:36 +0800	[thread overview]
Message-ID: <df1317a2-68f1-4eb8-9fea-952349f672cb@huawei.com> (raw)
In-Reply-To: <an3rUZ7rd1mQH0Gz@arm.com>



在 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

> 



  reply	other threads:[~2026-08-17 10:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  3:12 [PATCH v2 0/5] arm64: crash: Add crash hotplug support Jinjie Ruan
2026-07-29  3:12 ` [PATCH v2 1/5] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
2026-07-29  3:12 ` [PATCH v2 2/5] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
2026-07-29  3:12 ` [PATCH v2 3/5] arm64: kexec_file: Fix image->elf_headers memory leak in retry loop Jinjie Ruan
2026-07-29  3:12 ` [PATCH v2 4/5] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
2026-07-29  3:12 ` [PATCH v2 5/5] arm64: crash: Add crash hotplug support Jinjie Ruan
2026-08-13 16:05   ` Catalin Marinas
2026-08-17 10:45     ` Jinjie Ruan [this message]
2026-08-11 13:05 ` [PATCH v2 0/5] " Jinjie Ruan
2026-08-13 14:40 ` Catalin Marinas
2026-08-14  1:15   ` Jinjie Ruan

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=df1317a2-68f1-4eb8-9fea-952349f672cb@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=bgwin@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=coxu@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=graf@amazon.com \
    --cc=james.morse@arm.com \
    --cc=jbouron@amazon.com \
    --cc=jic23@kernel.org \
    --cc=kees@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=makb@juniper.net \
    --cc=mark.rutland@arm.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=piliu@redhat.com \
    --cc=pratyush@kernel.org \
    --cc=robh@kernel.org \
    --cc=rppt@kernel.org \
    --cc=sourabhjain@linux.ibm.com \
    --cc=thuth@redhat.com \
    --cc=will@kernel.org \
    --cc=yeoreum.yun@arm.com \
    /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