Re: [PATCH v3 12/17] x86/crash: Use num_possible_cpus() for elfcorehdr size

Jinjie Ruan <[email protected]>
Newsgroups gmane.linux.ports.ppc.embedded
Message-ID <d12302b0-f0b3-4df6-963c-bf25b6e720c7__13226.6778194875$1788343310$gmane$org@huawei.com>

在 2026/9/2 14:14, Sourabh Jain 写道:
> Hello Jinjie,
> 
> This patch makes the below patch redundant..
> https://lore.kernel.org/all/20260826073527.21487-2-
> [email protected]/
> 
> I suggest dropping the first patch from the above series and including
> the second patch from that series in this patch series with the updated
> comment.

Agreed. This approach makes sense to me.

I will update it in v4.

> 
> - Sourabh Jain
> 
> 
> On 26/08/26 14:55, Jinjie Ruan wrote:
>> Use num_possible_cpus() instead of CONFIG_NR_CPUS to calculate the
>> elfcorehdr buffer size, matching what crash_prepare_elf64_headers()
>> already uses for the actual header content.
>>
>> This avoids over-allocation when the system has fewer possible CPUs
>> than the compile-time limit, and aligns x86 with PowerPC.
>>
>> Signed-off-by: Jinjie Ruan <[email protected]>
>> ---
>>   arch/x86/kernel/crash.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
>> index a3bf786286d4..afe2aea19f47 100644
>> --- a/arch/x86/kernel/crash.c
>> +++ b/arch/x86/kernel/crash.c
>> @@ -369,9 +369,9 @@ int crash_load_segments(struct kimage *image)
>>        * maximum CPUs and maximum memory ranges.
>>        */
>>       if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
>> -        pnum = 2 + CONFIG_NR_CPUS + CONFIG_CRASH_MAX_MEMORY_RANGES;
>> +        pnum = 2 + num_possible_cpus() + CONFIG_CRASH_MAX_MEMORY_RANGES;
>>       else
>> -        pnum += 2 + CONFIG_NR_CPUS;
>> +        pnum += 2 + num_possible_cpus();
>>         if (pnum < (unsigned long)PN_XNUM) {
>>           kbuf.memsz = elf64_phdr_size(pnum);
>> @@ -429,7 +429,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
>>       unsigned int sz;
>>         /* kernel_map, VMCOREINFO and maximum CPUs */
>> -    sz = 2 + CONFIG_NR_CPUS;
>> +    sz = 2 + num_possible_cpus();
>>       if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
>>           sz += CONFIG_CRASH_MAX_MEMORY_RANGES;
>>       sz *= sizeof(Elf64_Phdr);
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.