All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Jinjie Ruan <ruanjinjie@huawei.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: Thu, 13 Aug 2026 17:05:37 +0100	[thread overview]
Message-ID: <an3rUZ7rd1mQH0Gz@arm.com> (raw)
In-Reply-To: <20260729031235.2840255-6-ruanjinjie@huawei.com>

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.

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

-- 
Catalin


  reply	other threads:[~2026-08-13 16:05 UTC|newest]

Thread overview: 9+ 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 [this message]
2026-08-11 13:05 ` [PATCH v2 0/5] " Jinjie Ruan
2026-08-13 14:40 ` Catalin Marinas

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=an3rUZ7rd1mQH0Gz@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=bgwin@google.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=ruanjinjie@huawei.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.