cpu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * CPU subsystem support
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/sched.h>
  9. #include <linux/cpu.h>
  10. #include <linux/topology.h>
  11. #include <linux/device.h>
  12. #include <linux/node.h>
  13. #include <linux/gfp.h>
  14. #include <linux/slab.h>
  15. #include <linux/percpu.h>
  16. #include <linux/acpi.h>
  17. #include <linux/of.h>
  18. #include <linux/cpufeature.h>
  19. #include <linux/tick.h>
  20. #include <linux/pm_qos.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched/isolation.h>
  23. #include "base.h"
  24. static DEFINE_PER_CPU(struct device *, cpu_sys_devices);
  25. static int cpu_subsys_match(struct device *dev, const struct device_driver *drv)
  26. {
  27. /* ACPI style match is the only one that may succeed. */
  28. if (acpi_driver_match_device(dev, drv))
  29. return 1;
  30. return 0;
  31. }
  32. #ifdef CONFIG_HOTPLUG_CPU
  33. static void change_cpu_under_node(struct cpu *cpu,
  34. unsigned int from_nid, unsigned int to_nid)
  35. {
  36. int cpuid = cpu->dev.id;
  37. unregister_cpu_under_node(cpuid, from_nid);
  38. register_cpu_under_node(cpuid, to_nid);
  39. cpu->node_id = to_nid;
  40. }
  41. static int cpu_subsys_online(struct device *dev)
  42. {
  43. struct cpu *cpu = container_of(dev, struct cpu, dev);
  44. int cpuid = dev->id;
  45. int from_nid, to_nid;
  46. int ret;
  47. int retries = 0;
  48. from_nid = cpu_to_node(cpuid);
  49. if (from_nid == NUMA_NO_NODE)
  50. return -ENODEV;
  51. retry:
  52. ret = cpu_device_up(dev);
  53. /*
  54. * If -EBUSY is returned, it is likely that hotplug is temporarily
  55. * disabled when cpu_hotplug_disable() was called. This condition is
  56. * transient. So we retry after waiting for an exponentially
  57. * increasing delay up to a total of at least 620ms as some PCI
  58. * device initialization can take quite a while.
  59. */
  60. if (ret == -EBUSY) {
  61. retries++;
  62. if (retries > 5)
  63. return ret;
  64. msleep(10 * (1 << retries));
  65. goto retry;
  66. }
  67. /*
  68. * When hot adding memory to memoryless node and enabling a cpu
  69. * on the node, node number of the cpu may internally change.
  70. */
  71. to_nid = cpu_to_node(cpuid);
  72. if (from_nid != to_nid)
  73. change_cpu_under_node(cpu, from_nid, to_nid);
  74. return ret;
  75. }
  76. static int cpu_subsys_offline(struct device *dev)
  77. {
  78. return cpu_device_down(dev);
  79. }
  80. void unregister_cpu(struct cpu *cpu)
  81. {
  82. int logical_cpu = cpu->dev.id;
  83. set_cpu_enabled(logical_cpu, false);
  84. unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu));
  85. device_unregister(&cpu->dev);
  86. per_cpu(cpu_sys_devices, logical_cpu) = NULL;
  87. return;
  88. }
  89. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  90. static ssize_t cpu_probe_store(struct device *dev,
  91. struct device_attribute *attr,
  92. const char *buf,
  93. size_t count)
  94. {
  95. ssize_t cnt;
  96. int ret;
  97. ret = lock_device_hotplug_sysfs();
  98. if (ret)
  99. return ret;
  100. cnt = arch_cpu_probe(buf, count);
  101. unlock_device_hotplug();
  102. return cnt;
  103. }
  104. static ssize_t cpu_release_store(struct device *dev,
  105. struct device_attribute *attr,
  106. const char *buf,
  107. size_t count)
  108. {
  109. ssize_t cnt;
  110. int ret;
  111. ret = lock_device_hotplug_sysfs();
  112. if (ret)
  113. return ret;
  114. cnt = arch_cpu_release(buf, count);
  115. unlock_device_hotplug();
  116. return cnt;
  117. }
  118. static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store);
  119. static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store);
  120. #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
  121. #endif /* CONFIG_HOTPLUG_CPU */
  122. #ifdef CONFIG_CRASH_DUMP
  123. #include <linux/kexec.h>
  124. static ssize_t crash_notes_show(struct device *dev,
  125. struct device_attribute *attr,
  126. char *buf)
  127. {
  128. struct cpu *cpu = container_of(dev, struct cpu, dev);
  129. unsigned long long addr;
  130. int cpunum;
  131. cpunum = cpu->dev.id;
  132. /*
  133. * Might be reading other cpu's data based on which cpu read thread
  134. * has been scheduled. But cpu data (memory) is allocated once during
  135. * boot up and this data does not change there after. Hence this
  136. * operation should be safe. No locking required.
  137. */
  138. addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum));
  139. return sysfs_emit(buf, "%llx\n", addr);
  140. }
  141. static DEVICE_ATTR_ADMIN_RO(crash_notes);
  142. static ssize_t crash_notes_size_show(struct device *dev,
  143. struct device_attribute *attr,
  144. char *buf)
  145. {
  146. return sysfs_emit(buf, "%zu\n", sizeof(note_buf_t));
  147. }
  148. static DEVICE_ATTR_ADMIN_RO(crash_notes_size);
  149. static struct attribute *crash_note_cpu_attrs[] = {
  150. &dev_attr_crash_notes.attr,
  151. &dev_attr_crash_notes_size.attr,
  152. NULL
  153. };
  154. static const struct attribute_group crash_note_cpu_attr_group = {
  155. .attrs = crash_note_cpu_attrs,
  156. };
  157. #endif
  158. static const struct attribute_group *common_cpu_attr_groups[] = {
  159. #ifdef CONFIG_CRASH_DUMP
  160. &crash_note_cpu_attr_group,
  161. #endif
  162. NULL
  163. };
  164. static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
  165. #ifdef CONFIG_CRASH_DUMP
  166. &crash_note_cpu_attr_group,
  167. #endif
  168. NULL
  169. };
  170. /*
  171. * Print cpu online, possible, present, and system maps
  172. */
  173. struct cpu_attr {
  174. struct device_attribute attr;
  175. const struct cpumask *const map;
  176. };
  177. static ssize_t show_cpus_attr(struct device *dev,
  178. struct device_attribute *attr,
  179. char *buf)
  180. {
  181. struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
  182. return cpumap_print_to_pagebuf(true, buf, ca->map);
  183. }
  184. #define _CPU_ATTR(name, map) \
  185. { __ATTR(name, 0444, show_cpus_attr, NULL), map }
  186. /* Keep in sync with cpu_subsys_attrs */
  187. static struct cpu_attr cpu_attrs[] = {
  188. _CPU_ATTR(online, &__cpu_online_mask),
  189. _CPU_ATTR(possible, &__cpu_possible_mask),
  190. _CPU_ATTR(present, &__cpu_present_mask),
  191. };
  192. /*
  193. * Print values for NR_CPUS and offlined cpus
  194. */
  195. static ssize_t print_cpus_kernel_max(struct device *dev,
  196. struct device_attribute *attr, char *buf)
  197. {
  198. return sysfs_emit(buf, "%d\n", NR_CPUS - 1);
  199. }
  200. static DEVICE_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
  201. /* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */
  202. unsigned int total_cpus;
  203. static ssize_t print_cpus_offline(struct device *dev,
  204. struct device_attribute *attr, char *buf)
  205. {
  206. int len = 0;
  207. cpumask_var_t offline;
  208. /* display offline cpus < nr_cpu_ids */
  209. if (!alloc_cpumask_var(&offline, GFP_KERNEL))
  210. return -ENOMEM;
  211. cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask);
  212. len += sysfs_emit_at(buf, len, "%*pbl", cpumask_pr_args(offline));
  213. free_cpumask_var(offline);
  214. /* display offline cpus >= nr_cpu_ids */
  215. if (total_cpus && nr_cpu_ids < total_cpus) {
  216. len += sysfs_emit_at(buf, len, ",");
  217. if (nr_cpu_ids == total_cpus-1)
  218. len += sysfs_emit_at(buf, len, "%u", nr_cpu_ids);
  219. else
  220. len += sysfs_emit_at(buf, len, "%u-%d",
  221. nr_cpu_ids, total_cpus - 1);
  222. }
  223. len += sysfs_emit_at(buf, len, "\n");
  224. return len;
  225. }
  226. static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);
  227. static ssize_t print_cpus_enabled(struct device *dev,
  228. struct device_attribute *attr, char *buf)
  229. {
  230. return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_enabled_mask));
  231. }
  232. static DEVICE_ATTR(enabled, 0444, print_cpus_enabled, NULL);
  233. static ssize_t print_cpus_isolated(struct device *dev,
  234. struct device_attribute *attr, char *buf)
  235. {
  236. int len;
  237. cpumask_var_t isolated;
  238. if (!alloc_cpumask_var(&isolated, GFP_KERNEL))
  239. return -ENOMEM;
  240. cpumask_andnot(isolated, cpu_possible_mask,
  241. housekeeping_cpumask(HK_TYPE_DOMAIN));
  242. len = sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(isolated));
  243. free_cpumask_var(isolated);
  244. return len;
  245. }
  246. static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
  247. #ifdef CONFIG_NO_HZ_FULL
  248. static ssize_t print_cpus_nohz_full(struct device *dev,
  249. struct device_attribute *attr, char *buf)
  250. {
  251. return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
  252. }
  253. static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
  254. #endif
  255. #ifdef CONFIG_CRASH_HOTPLUG
  256. static ssize_t crash_hotplug_show(struct device *dev,
  257. struct device_attribute *attr,
  258. char *buf)
  259. {
  260. return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
  261. }
  262. static DEVICE_ATTR_RO(crash_hotplug);
  263. #endif
  264. static void cpu_device_release(struct device *dev)
  265. {
  266. /*
  267. * This is an empty function to prevent the driver core from spitting a
  268. * warning at us. Yes, I know this is directly opposite of what the
  269. * documentation for the driver core and kobjects say, and the author
  270. * of this code has already been publically ridiculed for doing
  271. * something as foolish as this. However, at this point in time, it is
  272. * the only way to handle the issue of statically allocated cpu
  273. * devices. The different architectures will have their cpu device
  274. * code reworked to properly handle this in the near future, so this
  275. * function will then be changed to correctly free up the memory held
  276. * by the cpu device.
  277. *
  278. * Never copy this way of doing things, or you too will be made fun of
  279. * on the linux-kernel list, you have been warned.
  280. */
  281. }
  282. #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
  283. static ssize_t print_cpu_modalias(struct device *dev,
  284. struct device_attribute *attr,
  285. char *buf)
  286. {
  287. int len = 0;
  288. u32 i;
  289. len += sysfs_emit_at(buf, len,
  290. "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:",
  291. CPU_FEATURE_TYPEVAL);
  292. for (i = 0; i < MAX_CPU_FEATURES; i++)
  293. if (cpu_have_feature(i)) {
  294. if (len + sizeof(",XXXX\n") >= PAGE_SIZE) {
  295. WARN(1, "CPU features overflow page\n");
  296. break;
  297. }
  298. len += sysfs_emit_at(buf, len, ",%04X", i);
  299. }
  300. len += sysfs_emit_at(buf, len, "\n");
  301. return len;
  302. }
  303. static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
  304. {
  305. char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
  306. if (buf) {
  307. print_cpu_modalias(NULL, NULL, buf);
  308. add_uevent_var(env, "MODALIAS=%s", buf);
  309. kfree(buf);
  310. }
  311. return 0;
  312. }
  313. #endif
  314. const struct bus_type cpu_subsys = {
  315. .name = "cpu",
  316. .dev_name = "cpu",
  317. .match = cpu_subsys_match,
  318. #ifdef CONFIG_HOTPLUG_CPU
  319. .online = cpu_subsys_online,
  320. .offline = cpu_subsys_offline,
  321. #endif
  322. #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
  323. .uevent = cpu_uevent,
  324. #endif
  325. };
  326. EXPORT_SYMBOL_GPL(cpu_subsys);
  327. /*
  328. * register_cpu - Setup a sysfs device for a CPU.
  329. * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
  330. * sysfs for this CPU.
  331. * @num - CPU number to use when creating the device.
  332. *
  333. * Initialize and register the CPU device.
  334. */
  335. int register_cpu(struct cpu *cpu, int num)
  336. {
  337. int error;
  338. cpu->node_id = cpu_to_node(num);
  339. memset(&cpu->dev, 0x00, sizeof(struct device));
  340. cpu->dev.id = num;
  341. cpu->dev.bus = &cpu_subsys;
  342. cpu->dev.release = cpu_device_release;
  343. cpu->dev.offline_disabled = !cpu->hotpluggable;
  344. cpu->dev.offline = !cpu_online(num);
  345. cpu->dev.of_node = of_get_cpu_node(num, NULL);
  346. cpu->dev.groups = common_cpu_attr_groups;
  347. if (cpu->hotpluggable)
  348. cpu->dev.groups = hotplugable_cpu_attr_groups;
  349. error = device_register(&cpu->dev);
  350. if (error) {
  351. put_device(&cpu->dev);
  352. return error;
  353. }
  354. per_cpu(cpu_sys_devices, num) = &cpu->dev;
  355. register_cpu_under_node(num, cpu_to_node(num));
  356. dev_pm_qos_expose_latency_limit(&cpu->dev,
  357. PM_QOS_RESUME_LATENCY_NO_CONSTRAINT);
  358. set_cpu_enabled(num, true);
  359. return 0;
  360. }
  361. struct device *get_cpu_device(unsigned int cpu)
  362. {
  363. if (cpu < nr_cpu_ids && cpu_possible(cpu))
  364. return per_cpu(cpu_sys_devices, cpu);
  365. else
  366. return NULL;
  367. }
  368. EXPORT_SYMBOL_GPL(get_cpu_device);
  369. static void device_create_release(struct device *dev)
  370. {
  371. kfree(dev);
  372. }
  373. __printf(4, 0)
  374. static struct device *
  375. __cpu_device_create(struct device *parent, void *drvdata,
  376. const struct attribute_group **groups,
  377. const char *fmt, va_list args)
  378. {
  379. struct device *dev = NULL;
  380. int retval = -ENOMEM;
  381. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  382. if (!dev)
  383. goto error;
  384. device_initialize(dev);
  385. dev->parent = parent;
  386. dev->groups = groups;
  387. dev->release = device_create_release;
  388. device_set_pm_not_required(dev);
  389. dev_set_drvdata(dev, drvdata);
  390. retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
  391. if (retval)
  392. goto error;
  393. retval = device_add(dev);
  394. if (retval)
  395. goto error;
  396. return dev;
  397. error:
  398. put_device(dev);
  399. return ERR_PTR(retval);
  400. }
  401. struct device *cpu_device_create(struct device *parent, void *drvdata,
  402. const struct attribute_group **groups,
  403. const char *fmt, ...)
  404. {
  405. va_list vargs;
  406. struct device *dev;
  407. va_start(vargs, fmt);
  408. dev = __cpu_device_create(parent, drvdata, groups, fmt, vargs);
  409. va_end(vargs);
  410. return dev;
  411. }
  412. EXPORT_SYMBOL_GPL(cpu_device_create);
  413. #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
  414. static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
  415. #endif
  416. static struct attribute *cpu_root_attrs[] = {
  417. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  418. &dev_attr_probe.attr,
  419. &dev_attr_release.attr,
  420. #endif
  421. &cpu_attrs[0].attr.attr,
  422. &cpu_attrs[1].attr.attr,
  423. &cpu_attrs[2].attr.attr,
  424. &dev_attr_kernel_max.attr,
  425. &dev_attr_offline.attr,
  426. &dev_attr_enabled.attr,
  427. &dev_attr_isolated.attr,
  428. #ifdef CONFIG_NO_HZ_FULL
  429. &dev_attr_nohz_full.attr,
  430. #endif
  431. #ifdef CONFIG_CRASH_HOTPLUG
  432. &dev_attr_crash_hotplug.attr,
  433. #endif
  434. #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
  435. &dev_attr_modalias.attr,
  436. #endif
  437. NULL
  438. };
  439. static const struct attribute_group cpu_root_attr_group = {
  440. .attrs = cpu_root_attrs,
  441. };
  442. static const struct attribute_group *cpu_root_attr_groups[] = {
  443. &cpu_root_attr_group,
  444. NULL,
  445. };
  446. bool cpu_is_hotpluggable(unsigned int cpu)
  447. {
  448. struct device *dev = get_cpu_device(cpu);
  449. return dev && container_of(dev, struct cpu, dev)->hotpluggable
  450. && tick_nohz_cpu_hotpluggable(cpu);
  451. }
  452. EXPORT_SYMBOL_GPL(cpu_is_hotpluggable);
  453. #ifdef CONFIG_GENERIC_CPU_DEVICES
  454. DEFINE_PER_CPU(struct cpu, cpu_devices);
  455. bool __weak arch_cpu_is_hotpluggable(int cpu)
  456. {
  457. return false;
  458. }
  459. int __weak arch_register_cpu(int cpu)
  460. {
  461. struct cpu *c = &per_cpu(cpu_devices, cpu);
  462. c->hotpluggable = arch_cpu_is_hotpluggable(cpu);
  463. return register_cpu(c, cpu);
  464. }
  465. #ifdef CONFIG_HOTPLUG_CPU
  466. void __weak arch_unregister_cpu(int num)
  467. {
  468. unregister_cpu(&per_cpu(cpu_devices, num));
  469. }
  470. #endif /* CONFIG_HOTPLUG_CPU */
  471. #endif /* CONFIG_GENERIC_CPU_DEVICES */
  472. static void __init cpu_dev_register_generic(void)
  473. {
  474. int i, ret;
  475. if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES))
  476. return;
  477. for_each_present_cpu(i) {
  478. ret = arch_register_cpu(i);
  479. if (ret && ret != -EPROBE_DEFER)
  480. pr_warn("register_cpu %d failed (%d)\n", i, ret);
  481. }
  482. }
  483. #ifdef CONFIG_GENERIC_CPU_VULNERABILITIES
  484. static ssize_t cpu_show_not_affected(struct device *dev,
  485. struct device_attribute *attr, char *buf)
  486. {
  487. return sysfs_emit(buf, "Not affected\n");
  488. }
  489. #define CPU_SHOW_VULN_FALLBACK(func) \
  490. ssize_t cpu_show_##func(struct device *, \
  491. struct device_attribute *, char *) \
  492. __attribute__((weak, alias("cpu_show_not_affected")))
  493. CPU_SHOW_VULN_FALLBACK(meltdown);
  494. CPU_SHOW_VULN_FALLBACK(spectre_v1);
  495. CPU_SHOW_VULN_FALLBACK(spectre_v2);
  496. CPU_SHOW_VULN_FALLBACK(spec_store_bypass);
  497. CPU_SHOW_VULN_FALLBACK(l1tf);
  498. CPU_SHOW_VULN_FALLBACK(mds);
  499. CPU_SHOW_VULN_FALLBACK(tsx_async_abort);
  500. CPU_SHOW_VULN_FALLBACK(itlb_multihit);
  501. CPU_SHOW_VULN_FALLBACK(srbds);
  502. CPU_SHOW_VULN_FALLBACK(mmio_stale_data);
  503. CPU_SHOW_VULN_FALLBACK(retbleed);
  504. CPU_SHOW_VULN_FALLBACK(spec_rstack_overflow);
  505. CPU_SHOW_VULN_FALLBACK(gds);
  506. CPU_SHOW_VULN_FALLBACK(reg_file_data_sampling);
  507. CPU_SHOW_VULN_FALLBACK(indirect_target_selection);
  508. CPU_SHOW_VULN_FALLBACK(tsa);
  509. CPU_SHOW_VULN_FALLBACK(vmscape);
  510. static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
  511. static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
  512. static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
  513. static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL);
  514. static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL);
  515. static DEVICE_ATTR(mds, 0444, cpu_show_mds, NULL);
  516. static DEVICE_ATTR(tsx_async_abort, 0444, cpu_show_tsx_async_abort, NULL);
  517. static DEVICE_ATTR(itlb_multihit, 0444, cpu_show_itlb_multihit, NULL);
  518. static DEVICE_ATTR(srbds, 0444, cpu_show_srbds, NULL);
  519. static DEVICE_ATTR(mmio_stale_data, 0444, cpu_show_mmio_stale_data, NULL);
  520. static DEVICE_ATTR(retbleed, 0444, cpu_show_retbleed, NULL);
  521. static DEVICE_ATTR(spec_rstack_overflow, 0444, cpu_show_spec_rstack_overflow, NULL);
  522. static DEVICE_ATTR(gather_data_sampling, 0444, cpu_show_gds, NULL);
  523. static DEVICE_ATTR(reg_file_data_sampling, 0444, cpu_show_reg_file_data_sampling, NULL);
  524. static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
  525. static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
  526. static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
  527. static struct attribute *cpu_root_vulnerabilities_attrs[] = {
  528. &dev_attr_meltdown.attr,
  529. &dev_attr_spectre_v1.attr,
  530. &dev_attr_spectre_v2.attr,
  531. &dev_attr_spec_store_bypass.attr,
  532. &dev_attr_l1tf.attr,
  533. &dev_attr_mds.attr,
  534. &dev_attr_tsx_async_abort.attr,
  535. &dev_attr_itlb_multihit.attr,
  536. &dev_attr_srbds.attr,
  537. &dev_attr_mmio_stale_data.attr,
  538. &dev_attr_retbleed.attr,
  539. &dev_attr_spec_rstack_overflow.attr,
  540. &dev_attr_gather_data_sampling.attr,
  541. &dev_attr_reg_file_data_sampling.attr,
  542. &dev_attr_indirect_target_selection.attr,
  543. &dev_attr_tsa.attr,
  544. &dev_attr_vmscape.attr,
  545. NULL
  546. };
  547. static const struct attribute_group cpu_root_vulnerabilities_group = {
  548. .name = "vulnerabilities",
  549. .attrs = cpu_root_vulnerabilities_attrs,
  550. };
  551. static void __init cpu_register_vulnerabilities(void)
  552. {
  553. struct device *dev = bus_get_dev_root(&cpu_subsys);
  554. if (dev) {
  555. if (sysfs_create_group(&dev->kobj, &cpu_root_vulnerabilities_group))
  556. pr_err("Unable to register CPU vulnerabilities\n");
  557. put_device(dev);
  558. }
  559. }
  560. #else
  561. static inline void cpu_register_vulnerabilities(void) { }
  562. #endif
  563. void __init cpu_dev_init(void)
  564. {
  565. if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups))
  566. panic("Failed to register CPU subsystem");
  567. cpu_dev_register_generic();
  568. cpu_register_vulnerabilities();
  569. }