proc.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/smp.h>
  3. #include <linux/timex.h>
  4. #include <linux/string.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/cpufreq.h>
  7. #include <asm/prctl.h>
  8. #include <linux/proc_fs.h>
  9. #include "cpu.h"
  10. #ifdef CONFIG_X86_VMX_FEATURE_NAMES
  11. extern const char * const x86_vmx_flags[NVMXINTS*32];
  12. #endif
  13. /*
  14. * Get CPU information for use by the procfs.
  15. */
  16. static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,
  17. unsigned int cpu)
  18. {
  19. #ifdef CONFIG_SMP
  20. seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id);
  21. seq_printf(m, "siblings\t: %d\n",
  22. cpumask_weight(topology_core_cpumask(cpu)));
  23. seq_printf(m, "core id\t\t: %d\n", c->topo.core_id);
  24. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  25. seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid);
  26. seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid);
  27. #endif
  28. }
  29. #ifdef CONFIG_X86_32
  30. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  31. {
  32. seq_printf(m,
  33. "fdiv_bug\t: %s\n"
  34. "f00f_bug\t: %s\n"
  35. "coma_bug\t: %s\n"
  36. "fpu\t\t: %s\n"
  37. "fpu_exception\t: %s\n"
  38. "cpuid level\t: %d\n"
  39. "wp\t\t: yes\n",
  40. boot_cpu_has_bug(X86_BUG_FDIV) ? "yes" : "no",
  41. boot_cpu_has_bug(X86_BUG_F00F) ? "yes" : "no",
  42. boot_cpu_has_bug(X86_BUG_COMA) ? "yes" : "no",
  43. boot_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  44. boot_cpu_has(X86_FEATURE_FPU) ? "yes" : "no",
  45. c->cpuid_level);
  46. }
  47. #else
  48. static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)
  49. {
  50. seq_printf(m,
  51. "fpu\t\t: yes\n"
  52. "fpu_exception\t: yes\n"
  53. "cpuid level\t: %d\n"
  54. "wp\t\t: yes\n",
  55. c->cpuid_level);
  56. }
  57. #endif
  58. static int show_cpuinfo(struct seq_file *m, void *v)
  59. {
  60. struct cpuinfo_x86 *c = v;
  61. unsigned int cpu;
  62. int i;
  63. cpu = c->cpu_index;
  64. seq_printf(m, "processor\t: %u\n"
  65. "vendor_id\t: %s\n"
  66. "cpu family\t: %d\n"
  67. "model\t\t: %u\n"
  68. "model name\t: %s\n",
  69. cpu,
  70. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  71. c->x86,
  72. c->x86_model,
  73. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  74. if (c->x86_stepping || c->cpuid_level >= 0)
  75. seq_printf(m, "stepping\t: %d\n", c->x86_stepping);
  76. else
  77. seq_puts(m, "stepping\t: unknown\n");
  78. if (c->microcode)
  79. seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
  80. if (cpu_has(c, X86_FEATURE_TSC)) {
  81. unsigned int freq = arch_freq_get_on_cpu(cpu);
  82. seq_printf(m, "cpu MHz\t\t: %u.%03u\n", freq / 1000, (freq % 1000));
  83. }
  84. /* Cache size */
  85. if (c->x86_cache_size)
  86. seq_printf(m, "cache size\t: %u KB\n", c->x86_cache_size);
  87. show_cpuinfo_core(m, c, cpu);
  88. show_cpuinfo_misc(m, c);
  89. seq_puts(m, "flags\t\t:");
  90. for (i = 0; i < 32*NCAPINTS; i++)
  91. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  92. seq_printf(m, " %s", x86_cap_flags[i]);
  93. #ifdef CONFIG_X86_VMX_FEATURE_NAMES
  94. if (cpu_has(c, X86_FEATURE_VMX) && c->vmx_capability[0]) {
  95. seq_puts(m, "\nvmx flags\t:");
  96. for (i = 0; i < 32*NVMXINTS; i++) {
  97. if (test_bit(i, (unsigned long *)c->vmx_capability) &&
  98. x86_vmx_flags[i] != NULL)
  99. seq_printf(m, " %s", x86_vmx_flags[i]);
  100. }
  101. }
  102. #endif
  103. seq_puts(m, "\nbugs\t\t:");
  104. for (i = 0; i < 32*NBUGINTS; i++) {
  105. unsigned int bug_bit = 32*NCAPINTS + i;
  106. if (cpu_has_bug(c, bug_bit) && x86_bug_flags[i])
  107. seq_printf(m, " %s", x86_bug_flags[i]);
  108. }
  109. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  110. c->loops_per_jiffy/(500000/HZ),
  111. (c->loops_per_jiffy/(5000/HZ)) % 100);
  112. #ifdef CONFIG_X86_64
  113. if (c->x86_tlbsize > 0)
  114. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  115. #endif
  116. seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size);
  117. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  118. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  119. c->x86_phys_bits, c->x86_virt_bits);
  120. seq_puts(m, "power management:");
  121. for (i = 0; i < 32; i++) {
  122. if (c->x86_power & (1 << i)) {
  123. if (i < ARRAY_SIZE(x86_power_flags) &&
  124. x86_power_flags[i])
  125. seq_printf(m, "%s%s",
  126. x86_power_flags[i][0] ? " " : "",
  127. x86_power_flags[i]);
  128. else
  129. seq_printf(m, " [%d]", i);
  130. }
  131. }
  132. seq_puts(m, "\n\n");
  133. return 0;
  134. }
  135. static void *c_start(struct seq_file *m, loff_t *pos)
  136. {
  137. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  138. if ((*pos) < nr_cpu_ids)
  139. return &cpu_data(*pos);
  140. return NULL;
  141. }
  142. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  143. {
  144. (*pos)++;
  145. return c_start(m, pos);
  146. }
  147. static void c_stop(struct seq_file *m, void *v)
  148. {
  149. }
  150. const struct seq_operations cpuinfo_op = {
  151. .start = c_start,
  152. .next = c_next,
  153. .stop = c_stop,
  154. .show = show_cpuinfo,
  155. };
  156. #ifdef CONFIG_X86_USER_SHADOW_STACK
  157. static void dump_x86_features(struct seq_file *m, unsigned long features)
  158. {
  159. if (features & ARCH_SHSTK_SHSTK)
  160. seq_puts(m, "shstk ");
  161. if (features & ARCH_SHSTK_WRSS)
  162. seq_puts(m, "wrss ");
  163. }
  164. void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task)
  165. {
  166. seq_puts(m, "x86_Thread_features:\t");
  167. dump_x86_features(m, task->thread.features);
  168. seq_putc(m, '\n');
  169. seq_puts(m, "x86_Thread_features_locked:\t");
  170. dump_x86_features(m, task->thread.features_locked);
  171. seq_putc(m, '\n');
  172. }
  173. #endif /* CONFIG_X86_USER_SHADOW_STACK */