From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.218 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796192883; b=1vDO9npLQvOldkD+aYmbV3+ZhJnweclFpLj6wCd4eWhhv9SBfAmUSFd7T16rhCTAef9q rgVbGHHBtwEzQqXVNfnFssEBay0VqM2no/DfNhNDqXjg9f1QW43pfb/wcKd79LnO/5BBH lglkdKy4sZJTTq4Rmms8xIjs5aW/tVrY3cPoDnfGv2JYbyZmoMNV/0KcQoPVtXN/7eG8q qxEpFeY1kZGXRnEWbJyvlMhCLt7km/+f+vKVcgawjppyUZGOZsjfz2Cnr82waIFsU5vlX rSaBDsP9tp6BALrZ0/i11ckCG8pGWp15xNKXz8HhzR4v4xFoMYTqJSDWdvKMDyY++6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796192883; h=DMARC-Filter:dkim-signature:Received:Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:CC:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Originating-IP: X-ClientProxiedBy; bh=8Me7I/YXngQshK8Z7riMXXM9XJWCXrIiPkIvEkXjRs4=; b=fWxFaBtHkQQsg+z/KINPamwF2YPylbMm/aa3ixE7pD5zE98sOm3adtE5sf5+fh13clQu ye+HUF8OghZSjgoiR9rJwQVD80oi/Gj25J31XaD8rwBxEtPxHZvBLYyuDFQEQcKFtMj9P g5P8TNCN5N6Q5KyMmoWEkea/wIf2xJx2WzVPN7S7sJ8ywZnfhUGEfFRNjLo9TE9q7mZw4 zq6qlducFvEOUKBE/SNbD+/VDxZFxjMfYNAoayf45PabYFuYFyCC4IHZaJ5CKTwM5Evcs AauZG2uxqr6BvL+HBrJmfAp3gn4Hm/p092C2G4Vp6uvFwOhd4c1MBg7EIzVucwepI2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=H6izO4zm; arc=none smtp.remote-ip=113.46.200.218 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6398F606A31A for ; Wed, 2 Dec 2026 06:28:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6398F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=H6izO4zm dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=8Me7I/YXngQshK8Z7riMXXM9XJWCXrIiPkIvEkXjRs4=; b=H6izO4zmsbaPvKukgOXMm6O++NKi7bIBrALz17KtL3WEV/ZIrXXZ9nlvUJN2zRFQc3RBOCU3p QOPlLP9HaLrywQa5SO/4PF3umZneypMs8cxUk//He524BGgrpN8XOdhnWj3ESlpvEABpu4W/ATu RSTZq8suGO6aRkqC3BvI1Mk= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4jfST52PVCzpSw8; Wed, 2 Dec 2026 14:26:33 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id E52434057D; Wed, 2 Dec 2026 14:27:47 +0800 (CST) Received: from [10.67.110.68] (10.67.110.68) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Wed, 2 Dec 2026 14:27:47 +0800 Message-ID: Date: Wed, 2 Dec 2026 14:27:46 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/crash: Include Elf64_Ehdr and RAM ranges in elfcorehdr size To: Suseendran Bhaskaran , Thomas Gleixner , Ingo Molnar , Borislav Petkov , CC: "H . Peter Anvin" , Andrew Morton , Baoquan He , Mike Rapoport , Eric DeVolder , Sourabh Jain , Ionut Nechita , Greg Thelen , Dave Hansen , , References: <20261201172159.2671514-1-suseendranb@google.com> From: Jinjie Ruan In-Reply-To: <20261201172159.2671514-1-suseendranb@google.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) 在 2026/12/2 1:21, Suseendran Bhaskaran 写道: > arch_crash_get_elfcorehdr_size() computes the size exported via > /sys/kernel/kexec/crash_elfcorehdr_size for kexec_load() with crash > hotplug support. Unlike crash_load_segments(), it omits both > sizeof(Elf64_Ehdr) and the existing System RAM ranges when > CONFIG_MEMORY_HOTPLUG is disabled. > > With --hotplug, kexec-tools overrides the elfcorehdr segment memsz with > this sysfs value and truncates bufsz if bufsz > memsz, so the loaded > elfcorehdr can be silently truncated on CONFIG_MEMORY_HOTPLUG=n systems, > and subsequent hotplug updates fail. For example, on a default > CONFIG_NR_CPUS=64 kernel with CONFIG_MEMORY_HOTPLUG=n, 64 possible CPUs, > and 10 System RAM ranges, crash_elfcorehdr_size reports 3696 bytes > (memsz 4096) and CPU offline fails with: > > crash hp: update elfcorehdr elfsz 8192 > memsz 4096 > > Add arch_get_system_nr_ranges() when !IS_ENABLED(CONFIG_MEMORY_HOTPLUG) > and include sizeof(Elf64_Ehdr) so arch_crash_get_elfcorehdr_size() > matches crash_load_segments(). Tested with kexec-tools 2.0.32 in QEMU > under the configuration above: crash_elfcorehdr_size reports 4488 bytes > (memsz 8192) and CPU offline updates elfcorehdr cleanly. > > Gemini assisted with code analysis and the QEMU reproducer. All changes > and test results were reviewed by the author. > > Fixes: a72bbec70da2 ("crash: hotplug support for kexec_load()") > Signed-off-by: Suseendran Bhaskaran > --- > arch/x86/kernel/crash.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c > index e6f23933a6df2..49bc4bc5ebc0b 100644 > --- a/arch/x86/kernel/crash.c > +++ b/arch/x86/kernel/crash.c > @@ -433,7 +433,10 @@ unsigned int arch_crash_get_elfcorehdr_size(void) > sz = 2 + CONFIG_NR_CPUS; > if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) > sz += CONFIG_CRASH_MAX_MEMORY_RANGES; > + else > + sz += arch_get_system_nr_ranges(); > sz *= sizeof(Elf64_Phdr); > + sz += sizeof(Elf64_Ehdr); This is consistent with the calculation of the number of PT_LOAD phdr sections in crash_prepare_elf64_headers(). 182 >-------/* extra phdr for vmcoreinfo ELF note */ 183 >-------nr_phdr = nr_cpus + 1; 184 >-------nr_phdr += mem->nr_ranges; 185 186 >-------/* 187 >------- * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping 188 >------- * area (for example, ffffffff80000000 - ffffffffa0000000 on x86_64). 189 >------- * I think this is required by tools like gdb. So same physical 190 >------- * memory will be mapped in two ELF headers. One will contain kernel 191 >------- * text virtual addresses and other will have __va(physical) addresses. 192 >------- */ 193 194 >-------nr_phdr++; 195 >-------elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); 196 >-------elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); When I implemented crash hotplug on arm64, sashiko also pointed out similar issues. Link: https://sashiko.dev/#/patchset/20260918100442.3841135-1-ruanjinjie%40huawei.com LGTM Reviewed-by: Jinjie Ruan > return sz; > } > > > base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244