1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2f7627e25SThomas Gleixner #include <linux/smp.h>
3f7627e25SThomas Gleixner #include <linux/timex.h>
4f7627e25SThomas Gleixner #include <linux/string.h>
5f7627e25SThomas Gleixner #include <linux/seq_file.h>
6890da9cfSLinus Torvalds #include <linux/cpufreq.h>
70ee44885SRick Edgecombe #include <asm/prctl.h>
80ee44885SRick Edgecombe #include <linux/proc_fs.h>
9f7627e25SThomas Gleixner
107d5905dcSRafael J. Wysocki #include "cpu.h"
117d5905dcSRafael J. Wysocki
1214442a15SSean Christopherson #ifdef CONFIG_X86_VMX_FEATURE_NAMES
1314442a15SSean Christopherson extern const char * const x86_vmx_flags[NVMXINTS*32];
1414442a15SSean Christopherson #endif
1514442a15SSean Christopherson
16f7627e25SThomas Gleixner /*
17f7627e25SThomas Gleixner * Get CPU information for use by the procfs.
18f7627e25SThomas Gleixner */
show_cpuinfo_core(struct seq_file * m,struct cpuinfo_x86 * c,unsigned int cpu)19a967ceacSHiroshi Shimamoto static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
20a967ceacSHiroshi Shimamoto unsigned int cpu)
21a967ceacSHiroshi Shimamoto {
22327f4387SJaswinder Singh Rajput #ifdef CONFIG_SMP
2302fb601dSThomas Gleixner seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id);
247d79a7bdSBartosz Golaszewski seq_printf(m, "siblings\t: %d\n",
257d79a7bdSBartosz Golaszewski cpumask_weight(topology_core_cpumask(cpu)));
26*e9525633SThomas Gleixner seq_printf(m, "core id\t\t: %d\n", c->topo.core_id);
27a967ceacSHiroshi Shimamoto seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
28b9655e70SThomas Gleixner seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid);
29b9655e70SThomas Gleixner seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid);
30a967ceacSHiroshi Shimamoto #endif
31a967ceacSHiroshi Shimamoto }
32a967ceacSHiroshi Shimamoto
33327f4387SJaswinder Singh Rajput #ifdef CONFIG_X86_32
show_cpuinfo_misc(struct seq_file * m,struct cpuinfo_x86 * c)34a967ceacSHiroshi Shimamoto static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
35a967ceacSHiroshi Shimamoto {
36a967ceacSHiroshi Shimamoto seq_printf(m,
37a967ceacSHiroshi Shimamoto "fdiv_bug\t: %s\n"
38a967ceacSHiroshi Shimamoto "f00f_bug\t: %s\n"
39a967ceacSHiroshi Shimamoto "coma_bug\t: %s\n"
40a967ceacSHiroshi Shimamoto "fpu\t\t: %s\n"
41a967ceacSHiroshi Shimamoto "fpu_exception\t: %s\n"
42a967ceacSHiroshi Shimamoto "cpuid level\t: %d\n"
436415813bSMathias Krause "wp\t\t: yes\n",
4467e87d43SBorislav Petkov boot_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
4567e87d43SBorislav Petkov boot_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
4667e87d43SBorislav Petkov boot_cpu_has_bug(X86_BUG_COMA) ? "yes" : "no",
4767e87d43SBorislav Petkov boot_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
4867e87d43SBorislav Petkov boot_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
496415813bSMathias Krause c->cpuid_level);
50a967ceacSHiroshi Shimamoto }
512aef7720SHiroshi Shimamoto #else
show_cpuinfo_misc(struct seq_file * m,struct cpuinfo_x86 * c)522aef7720SHiroshi Shimamoto static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
532aef7720SHiroshi Shimamoto {
542aef7720SHiroshi Shimamoto seq_printf(m,
552aef7720SHiroshi Shimamoto "fpu\t\t: yes\n"
562aef7720SHiroshi Shimamoto "fpu_exception\t: yes\n"
572aef7720SHiroshi Shimamoto "cpuid level\t: %d\n"
582aef7720SHiroshi Shimamoto "wp\t\t: yes\n",
592aef7720SHiroshi Shimamoto c->cpuid_level);
602aef7720SHiroshi Shimamoto }
612aef7720SHiroshi Shimamoto #endif
62a967ceacSHiroshi Shimamoto
show_cpuinfo(struct seq_file * m,void * v)63f7627e25SThomas Gleixner static int show_cpuinfo(struct seq_file *m, void *v)
64f7627e25SThomas Gleixner {
65f7627e25SThomas Gleixner struct cpuinfo_x86 *c = v;
66141168c3SKevin Winchester unsigned int cpu;
67a967ceacSHiroshi Shimamoto int i;
68f7627e25SThomas Gleixner
69a967ceacSHiroshi Shimamoto cpu = c->cpu_index;
70a967ceacSHiroshi Shimamoto seq_printf(m, "processor\t: %u\n"
71f7627e25SThomas Gleixner "vendor_id\t: %s\n"
72f7627e25SThomas Gleixner "cpu family\t: %d\n"
73a967ceacSHiroshi Shimamoto "model\t\t: %u\n"
74f7627e25SThomas Gleixner "model name\t: %s\n",
75a967ceacSHiroshi Shimamoto cpu,
76f7627e25SThomas Gleixner c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
77f7627e25SThomas Gleixner c->x86,
78f7627e25SThomas Gleixner c->x86_model,
79f7627e25SThomas Gleixner c->x86_model_id[0] ? c->x86_model_id : "unknown");
80f7627e25SThomas Gleixner
81b399151cSJia Zhang if (c->x86_stepping || c->cpuid_level >= 0)
82b399151cSJia Zhang seq_printf(m, "stepping\t: %d\n", c->x86_stepping);
83f7627e25SThomas Gleixner else
843736708fSRasmus Villemoes seq_puts(m, "stepping\t: unknown\n");
85506ed6b5SAndi Kleen if (c->microcode)
86881e23e5SBorislav Petkov seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
87f7627e25SThomas Gleixner
88890da9cfSLinus Torvalds if (cpu_has(c, X86_FEATURE_TSC)) {
89f3eca381SThomas Gleixner unsigned int freq = arch_freq_get_on_cpu(cpu);
90890da9cfSLinus Torvalds
91fb4c77c2SThomas Gleixner seq_printf(m, "cpu MHz\t\t: %u.%03u\n", freq / 1000, (freq % 1000));
92890da9cfSLinus Torvalds }
93f7627e25SThomas Gleixner
94f7627e25SThomas Gleixner /* Cache size */
9524dbc600SGustavo A. R. Silva if (c->x86_cache_size)
9624dbc600SGustavo A. R. Silva seq_printf(m, "cache size\t: %u KB\n", c->x86_cache_size);
97f7627e25SThomas Gleixner
98a967ceacSHiroshi Shimamoto show_cpuinfo_core(m, c, cpu);
99a967ceacSHiroshi Shimamoto show_cpuinfo_misc(m, c);
100f7627e25SThomas Gleixner
1013736708fSRasmus Villemoes seq_puts(m, "flags\t\t:");
102f7627e25SThomas Gleixner for (i = 0; i < 32*NCAPINTS; i++)
103a967ceacSHiroshi Shimamoto if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
104f7627e25SThomas Gleixner seq_printf(m, " %s", x86_cap_flags[i]);
105f7627e25SThomas Gleixner
10614442a15SSean Christopherson #ifdef CONFIG_X86_VMX_FEATURE_NAMES
10714442a15SSean Christopherson if (cpu_has(c, X86_FEATURE_VMX) && c->vmx_capability[0]) {
10814442a15SSean Christopherson seq_puts(m, "\nvmx flags\t:");
10914442a15SSean Christopherson for (i = 0; i < 32*NVMXINTS; i++) {
11014442a15SSean Christopherson if (test_bit(i, (unsigned long *)c->vmx_capability) &&
11114442a15SSean Christopherson x86_vmx_flags[i] != NULL)
11214442a15SSean Christopherson seq_printf(m, " %s", x86_vmx_flags[i]);
11314442a15SSean Christopherson }
11414442a15SSean Christopherson }
11514442a15SSean Christopherson #endif
11614442a15SSean Christopherson
1173736708fSRasmus Villemoes seq_puts(m, "\nbugs\t\t:");
11880a208bdSBorislav Petkov for (i = 0; i < 32*NBUGINTS; i++) {
11980a208bdSBorislav Petkov unsigned int bug_bit = 32*NCAPINTS + i;
12080a208bdSBorislav Petkov
12180a208bdSBorislav Petkov if (cpu_has_bug(c, bug_bit) && x86_bug_flags[i])
12280a208bdSBorislav Petkov seq_printf(m, " %s", x86_bug_flags[i]);
12380a208bdSBorislav Petkov }
12480a208bdSBorislav Petkov
125f84c3a42SHiroshi Shimamoto seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
126f84c3a42SHiroshi Shimamoto c->loops_per_jiffy/(500000/HZ),
127f84c3a42SHiroshi Shimamoto (c->loops_per_jiffy/(5000/HZ)) % 100);
1282aef7720SHiroshi Shimamoto
1292aef7720SHiroshi Shimamoto #ifdef CONFIG_X86_64
1302aef7720SHiroshi Shimamoto if (c->x86_tlbsize > 0)
1312aef7720SHiroshi Shimamoto seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
1322aef7720SHiroshi Shimamoto #endif
133f84c3a42SHiroshi Shimamoto seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
1342aef7720SHiroshi Shimamoto seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
1352aef7720SHiroshi Shimamoto seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
1362aef7720SHiroshi Shimamoto c->x86_phys_bits, c->x86_virt_bits);
137f84c3a42SHiroshi Shimamoto
1383736708fSRasmus Villemoes seq_puts(m, "power management:");
139f84c3a42SHiroshi Shimamoto for (i = 0; i < 32; i++) {
140f7627e25SThomas Gleixner if (c->x86_power & (1 << i)) {
141f7627e25SThomas Gleixner if (i < ARRAY_SIZE(x86_power_flags) &&
142f7627e25SThomas Gleixner x86_power_flags[i])
143f7627e25SThomas Gleixner seq_printf(m, "%s%s",
144f7627e25SThomas Gleixner x86_power_flags[i][0] ? " " : "",
145f7627e25SThomas Gleixner x86_power_flags[i]);
146f7627e25SThomas Gleixner else
147f7627e25SThomas Gleixner seq_printf(m, " [%d]", i);
148f7627e25SThomas Gleixner }
149f84c3a42SHiroshi Shimamoto }
150f7627e25SThomas Gleixner
1513736708fSRasmus Villemoes seq_puts(m, "\n\n");
152f7627e25SThomas Gleixner
153f7627e25SThomas Gleixner return 0;
154f7627e25SThomas Gleixner }
155f7627e25SThomas Gleixner
c_start(struct seq_file * m,loff_t * pos)156f7627e25SThomas Gleixner static void *c_start(struct seq_file *m, loff_t *pos)
157f7627e25SThomas Gleixner {
1584f062896SRusty Russell *pos = cpumask_next(*pos - 1, cpu_online_mask);
159bc8bcc79SLai Jiangshan if ((*pos) < nr_cpu_ids)
16092cb7612SMike Travis return &cpu_data(*pos);
16192cb7612SMike Travis return NULL;
162f7627e25SThomas Gleixner }
163a967ceacSHiroshi Shimamoto
c_next(struct seq_file * m,void * v,loff_t * pos)164f7627e25SThomas Gleixner static void *c_next(struct seq_file *m, void *v, loff_t *pos)
165f7627e25SThomas Gleixner {
166bc8bcc79SLai Jiangshan (*pos)++;
167f7627e25SThomas Gleixner return c_start(m, pos);
168f7627e25SThomas Gleixner }
169a967ceacSHiroshi Shimamoto
c_stop(struct seq_file * m,void * v)170f7627e25SThomas Gleixner static void c_stop(struct seq_file *m, void *v)
171f7627e25SThomas Gleixner {
172f7627e25SThomas Gleixner }
173a967ceacSHiroshi Shimamoto
1748a45eb31SJan Engelhardt const struct seq_operations cpuinfo_op = {
175f7627e25SThomas Gleixner .start = c_start,
176f7627e25SThomas Gleixner .next = c_next,
177f7627e25SThomas Gleixner .stop = c_stop,
178f7627e25SThomas Gleixner .show = show_cpuinfo,
179f7627e25SThomas Gleixner };
1800ee44885SRick Edgecombe
1810ee44885SRick Edgecombe #ifdef CONFIG_X86_USER_SHADOW_STACK
dump_x86_features(struct seq_file * m,unsigned long features)1820ee44885SRick Edgecombe static void dump_x86_features(struct seq_file *m, unsigned long features)
1830ee44885SRick Edgecombe {
1840ee44885SRick Edgecombe if (features & ARCH_SHSTK_SHSTK)
1850ee44885SRick Edgecombe seq_puts(m, "shstk ");
1860ee44885SRick Edgecombe if (features & ARCH_SHSTK_WRSS)
1870ee44885SRick Edgecombe seq_puts(m, "wrss ");
1880ee44885SRick Edgecombe }
1890ee44885SRick Edgecombe
arch_proc_pid_thread_features(struct seq_file * m,struct task_struct * task)1900ee44885SRick Edgecombe void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task)
1910ee44885SRick Edgecombe {
1920ee44885SRick Edgecombe seq_puts(m, "x86_Thread_features:\t");
1930ee44885SRick Edgecombe dump_x86_features(m, task->thread.features);
1940ee44885SRick Edgecombe seq_putc(m, '\n');
1950ee44885SRick Edgecombe
1960ee44885SRick Edgecombe seq_puts(m, "x86_Thread_features_locked:\t");
1970ee44885SRick Edgecombe dump_x86_features(m, task->thread.features_locked);
1980ee44885SRick Edgecombe seq_putc(m, '\n');
1990ee44885SRick Edgecombe }
2000ee44885SRick Edgecombe #endif /* CONFIG_X86_USER_SHADOW_STACK */
201