arm64/cpuinfo: only show one cpu's info in c_show()
PATCH 1/1 arm64/cpuinfo: only show one cpu's info in c_show()
From: Ye Bin <[email protected]>
Currently, when ARM64 displays CPU information, every call to c_show() assembles all CPU information. However, as the number of CPUs increases, this can lead to insufficient buffer space due to excessive assembly in a single call, causing repeated expansion and multiple calls to c_show().
To prevent this invalid c_show() call, only one CPU's information is assembled each time c_show() is called.
--- arch/arm64/kernel/cpuinfo.c | 107 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 54 deletions(-)
arch/arm64/kernel/cpuinfo.c +53 -54
@@ -209,80 +209,79 @@ static const char *const compat_hwcap2_str[] = {static int c_show (struct seq_file *m,void *v) { -int i, j; +int j; +int cpu = m->index;bool compat =personality (current->personality) ==PER_LINUX32 ; +struct cpuinfo_arm64 *cpuinfo = v; +u32 midr = cpuinfo->reg_midr; -for_each_online_cpu (i) { -struct cpuinfo_arm64 *cpuinfo = &per_cpu (cpu_data, i); -u32 midr = cpuinfo->reg_midr; - -/* -* glibc reads /proc/cpuinfo to determine the number of -* online processors, looking for lines beginning with -* "processor". Give glibc what it expects. -*/ -seq_printf (m,"processor\t: %d\n" , i); -if (compat) -seq_printf (m,"model name\t: ARMv8 Processor rev %d (%s)\n" , -MIDR_REVISION (midr),COMPAT_ELF_PLATFORM ); +/* +* glibc reads /proc/cpuinfo to determine the number of +* online processors, looking for lines beginning with +* "processor". Give glibc what it expects. +*/ +seq_printf (m,"processor\t: %d\n" , cpu); +if (compat) +seq_printf (m,"model name\t: ARMv8 Processor rev %d (%s)\n" , +MIDR_REVISION (midr),COMPAT_ELF_PLATFORM ); -seq_printf (m,"BogoMIPS\t: %lu.%02lu\n" , - loops_per_jiffy / (500000UL /HZ ), - loops_per_jiffy / (5000UL /HZ ) %100 ); +seq_printf (m,"BogoMIPS\t: %lu.%02lu\n" , + loops_per_jiffy / (500000UL /HZ ), + loops_per_jiffy / (5000UL /HZ ) %100 ); -/* -* Dump out the common processor features in a single line. -* Userspace should read the hwcaps with getauxval(AT_HWCAP) -* rather than attempting to parse this, but there's a body of -* software which does already (at least for 32-bit). -*/ -seq_puts (m,"Features\t:" ); -if (compat) { +/* +* Dump out the common processor features in a single line. +* Userspace should read the hwcaps with getauxval(AT_HWCAP) +* rather than attempting to parse this, but there's a body of +* software which does already (at least for 32-bit). +*/ +seq_puts (m,"Features\t:" ); +if (compat) {#ifdef CONFIG_COMPAT -for (j =0 ; j <ARRAY_SIZE (compat_hwcap_str); j++) { -if (compat_elf_hwcap & (1 << j)) { -/* -* Warn once if any feature should not -* have been present on arm64 platform. -*/ -if (WARN_ON_ONCE (!compat_hwcap_str[j])) -continue ; - -seq_printf (m," %s" , compat_hwcap_str[j]); - } +for (j =0 ; j <ARRAY_SIZE (compat_hwcap_str); j++) { +if (compat_elf_hwcap & (1 << j)) { +/* +* Warn once if any feature should not +* have been present on arm64 platform. +*/ +if (WARN_ON_ONCE (!compat_hwcap_str[j])) +continue ; + +seq_printf (m," %s" , compat_hwcap_str[j]); } + } -for (j =0 ; j <ARRAY_SIZE (compat_hwcap2_str); j++) -if (compat_elf_hwcap2 & (1 << j)) -seq_printf (m," %s" , compat_hwcap2_str[j]); +for (j =0 ; j <ARRAY_SIZE (compat_hwcap2_str); j++) +if (compat_elf_hwcap2 & (1 << j)) +seq_printf (m," %s" , compat_hwcap2_str[j]);#endif /* CONFIG_COMPAT */ - }else { -for (j =0 ; j <ARRAY_SIZE (hwcap_str); j++) -if (cpu_have_feature (j)) -seq_printf (m," %s" , hwcap_str[j]); - } -seq_puts (m,"\n" ); - -seq_printf (m,"CPU implementer\t: 0x%02x\n" , -MIDR_IMPLEMENTOR (midr)); -seq_printf (m,"CPU architecture: 8\n" ); -seq_printf (m,"CPU variant\t: 0x%x\n" ,MIDR_VARIANT (midr)); -seq_printf (m,"CPU part\t: 0x%03x\n" ,MIDR_PARTNUM (midr)); -seq_printf (m,"CPU revision\t: %d\n\n" ,MIDR_REVISION (midr)); + }else { +for (j =0 ; j <ARRAY_SIZE (hwcap_str); j++) +if (cpu_have_feature (j)) +seq_printf (m," %s" , hwcap_str[j]); } +seq_puts (m,"\n" ); + +seq_printf (m,"CPU implementer\t: 0x%02x\n" , +MIDR_IMPLEMENTOR (midr)); +seq_puts (m,"CPU architecture: 8\n" ); +seq_printf (m,"CPU variant\t: 0x%x\n" ,MIDR_VARIANT (midr)); +seq_printf (m,"CPU part\t: 0x%03x\n" ,MIDR_PARTNUM (midr)); +seq_printf (m,"CPU revision\t: %d\n\n" ,MIDR_REVISION (midr));return 0 ; }static void *c_start (struct seq_file *m,loff_t *pos) { -return *pos <1 ? (void *)1 :NULL ; + *pos =cpumask_next (*pos -1 , cpu_online_mask); +return *pos < nr_cpu_ids ? &per_cpu (cpu_data, *pos) :NULL ; }static void *c_next (struct seq_file *m,void *v,loff_t *pos) { ++*pos; -return NULL ; +return c_start (m, pos); }static void c_stop (struct seq_file *m,void *v)
Signature · 1 line
2.34.1
Quoted 9 lines · Ye Bin
Currently, when ARM64 displays CPU information, every call to
c_show()assembles all CPU information. However, as the number of CPUs increases, this can lead to insufficient buffer space due to excessive assembly in a single call, causing repeated expansion and multiple calls toc_show().To prevent this invalid
c_show()call, only one CPU's information is assembled each timec_show()is called.[...]
Applied to arm64 (for-next/misc), thanks!
[1/1] arm64/cpuinfo: only show one cpu's info in c_show()
https://git.kernel.org/arm64/c/7bb797757bf5
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev