hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/base/cpu.c
....@@ -55,7 +55,7 @@
5555 if (from_nid == NUMA_NO_NODE)
5656 return -ENODEV;
5757
58
- ret = cpu_up(cpuid);
58
+ ret = cpu_device_up(dev);
5959 /*
6060 * When hot adding memory to memoryless node and enabling a cpu
6161 * on the node, node number of the cpu may internally change.
....@@ -69,7 +69,7 @@
6969
7070 static int cpu_subsys_offline(struct device *dev)
7171 {
72
- return cpu_down(dev->id);
72
+ return cpu_device_down(dev);
7373 }
7474
7575 void unregister_cpu(struct cpu *cpu)
....@@ -139,11 +139,11 @@
139139 #ifdef CONFIG_KEXEC
140140 #include <linux/kexec.h>
141141
142
-static ssize_t show_crash_notes(struct device *dev, struct device_attribute *attr,
142
+static ssize_t crash_notes_show(struct device *dev,
143
+ struct device_attribute *attr,
143144 char *buf)
144145 {
145146 struct cpu *cpu = container_of(dev, struct cpu, dev);
146
- ssize_t rc;
147147 unsigned long long addr;
148148 int cpunum;
149149
....@@ -156,21 +156,18 @@
156156 * operation should be safe. No locking required.
157157 */
158158 addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum));
159
- rc = sprintf(buf, "%Lx\n", addr);
160
- return rc;
161
-}
162
-static DEVICE_ATTR(crash_notes, 0400, show_crash_notes, NULL);
163159
164
-static ssize_t show_crash_notes_size(struct device *dev,
160
+ return sysfs_emit(buf, "%llx\n", addr);
161
+}
162
+static DEVICE_ATTR_ADMIN_RO(crash_notes);
163
+
164
+static ssize_t crash_notes_size_show(struct device *dev,
165165 struct device_attribute *attr,
166166 char *buf)
167167 {
168
- ssize_t rc;
169
-
170
- rc = sprintf(buf, "%zu\n", sizeof(note_buf_t));
171
- return rc;
168
+ return sysfs_emit(buf, "%zu\n", sizeof(note_buf_t));
172169 }
173
-static DEVICE_ATTR(crash_notes_size, 0400, show_crash_notes_size, NULL);
170
+static DEVICE_ATTR_ADMIN_RO(crash_notes_size);
174171
175172 static struct attribute *crash_note_cpu_attrs[] = {
176173 &dev_attr_crash_notes.attr,
....@@ -231,8 +228,7 @@
231228 static ssize_t print_cpus_kernel_max(struct device *dev,
232229 struct device_attribute *attr, char *buf)
233230 {
234
- int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1);
235
- return n;
231
+ return sysfs_emit(buf, "%d\n", NR_CPUS - 1);
236232 }
237233 static DEVICE_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
238234
....@@ -242,37 +238,37 @@
242238 static ssize_t print_cpus_offline(struct device *dev,
243239 struct device_attribute *attr, char *buf)
244240 {
245
- int n = 0, len = PAGE_SIZE-2;
241
+ int len = 0;
246242 cpumask_var_t offline;
247243
248244 /* display offline cpus < nr_cpu_ids */
249245 if (!alloc_cpumask_var(&offline, GFP_KERNEL))
250246 return -ENOMEM;
251247 cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask);
252
- n = scnprintf(buf, len, "%*pbl", cpumask_pr_args(offline));
248
+ len += sysfs_emit_at(buf, len, "%*pbl", cpumask_pr_args(offline));
253249 free_cpumask_var(offline);
254250
255251 /* display offline cpus >= nr_cpu_ids */
256252 if (total_cpus && nr_cpu_ids < total_cpus) {
257
- if (n && n < len)
258
- buf[n++] = ',';
253
+ len += sysfs_emit_at(buf, len, ",");
259254
260255 if (nr_cpu_ids == total_cpus-1)
261
- n += snprintf(&buf[n], len - n, "%u", nr_cpu_ids);
256
+ len += sysfs_emit_at(buf, len, "%u", nr_cpu_ids);
262257 else
263
- n += snprintf(&buf[n], len - n, "%u-%d",
264
- nr_cpu_ids, total_cpus-1);
258
+ len += sysfs_emit_at(buf, len, "%u-%d",
259
+ nr_cpu_ids, total_cpus - 1);
265260 }
266261
267
- n += snprintf(&buf[n], len - n, "\n");
268
- return n;
262
+ len += sysfs_emit_at(buf, len, "\n");
263
+
264
+ return len;
269265 }
270266 static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);
271267
272268 static ssize_t print_cpus_isolated(struct device *dev,
273269 struct device_attribute *attr, char *buf)
274270 {
275
- int n = 0, len = PAGE_SIZE-2;
271
+ int len;
276272 cpumask_var_t isolated;
277273
278274 if (!alloc_cpumask_var(&isolated, GFP_KERNEL))
....@@ -280,23 +276,19 @@
280276
281277 cpumask_andnot(isolated, cpu_possible_mask,
282278 housekeeping_cpumask(HK_FLAG_DOMAIN));
283
- n = scnprintf(buf, len, "%*pbl\n", cpumask_pr_args(isolated));
279
+ len = sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(isolated));
284280
285281 free_cpumask_var(isolated);
286282
287
- return n;
283
+ return len;
288284 }
289285 static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
290286
291287 #ifdef CONFIG_NO_HZ_FULL
292288 static ssize_t print_cpus_nohz_full(struct device *dev,
293
- struct device_attribute *attr, char *buf)
289
+ struct device_attribute *attr, char *buf)
294290 {
295
- int n = 0, len = PAGE_SIZE-2;
296
-
297
- n = scnprintf(buf, len, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
298
-
299
- return n;
291
+ return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
300292 }
301293 static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
302294 #endif
....@@ -325,22 +317,23 @@
325317 struct device_attribute *attr,
326318 char *buf)
327319 {
328
- ssize_t n;
320
+ int len = 0;
329321 u32 i;
330322
331
- n = sprintf(buf, "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:",
332
- CPU_FEATURE_TYPEVAL);
323
+ len += sysfs_emit_at(buf, len,
324
+ "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:",
325
+ CPU_FEATURE_TYPEVAL);
333326
334327 for (i = 0; i < MAX_CPU_FEATURES; i++)
335328 if (cpu_have_feature(i)) {
336
- if (PAGE_SIZE < n + sizeof(",XXXX\n")) {
329
+ if (len + sizeof(",XXXX\n") >= PAGE_SIZE) {
337330 WARN(1, "CPU features overflow page\n");
338331 break;
339332 }
340
- n += sprintf(&buf[n], ",%04X", i);
333
+ len += sysfs_emit_at(buf, len, ",%04X", i);
341334 }
342
- buf[n++] = '\n';
343
- return n;
335
+ len += sysfs_emit_at(buf, len, "\n");
336
+ return len;
344337 }
345338
346339 static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
....@@ -409,6 +402,7 @@
409402 kfree(dev);
410403 }
411404
405
+__printf(4, 0)
412406 static struct device *
413407 __cpu_device_create(struct device *parent, void *drvdata,
414408 const struct attribute_group **groups,
....@@ -495,7 +489,8 @@
495489 bool cpu_is_hotpluggable(unsigned cpu)
496490 {
497491 struct device *dev = get_cpu_device(cpu);
498
- return dev && container_of(dev, struct cpu, dev)->hotpluggable;
492
+ return dev && container_of(dev, struct cpu, dev)->hotpluggable
493
+ && tick_nohz_cpu_hotpluggable(cpu);
499494 }
500495 EXPORT_SYMBOL_GPL(cpu_is_hotpluggable);
501496
....@@ -520,56 +515,80 @@
520515 ssize_t __weak cpu_show_meltdown(struct device *dev,
521516 struct device_attribute *attr, char *buf)
522517 {
523
- return sprintf(buf, "Not affected\n");
518
+ return sysfs_emit(buf, "Not affected\n");
524519 }
525520
526521 ssize_t __weak cpu_show_spectre_v1(struct device *dev,
527522 struct device_attribute *attr, char *buf)
528523 {
529
- return sprintf(buf, "Not affected\n");
524
+ return sysfs_emit(buf, "Not affected\n");
530525 }
531526
532527 ssize_t __weak cpu_show_spectre_v2(struct device *dev,
533528 struct device_attribute *attr, char *buf)
534529 {
535
- return sprintf(buf, "Not affected\n");
530
+ return sysfs_emit(buf, "Not affected\n");
536531 }
537532
538533 ssize_t __weak cpu_show_spec_store_bypass(struct device *dev,
539534 struct device_attribute *attr, char *buf)
540535 {
541
- return sprintf(buf, "Not affected\n");
536
+ return sysfs_emit(buf, "Not affected\n");
542537 }
543538
544539 ssize_t __weak cpu_show_l1tf(struct device *dev,
545540 struct device_attribute *attr, char *buf)
546541 {
547
- return sprintf(buf, "Not affected\n");
542
+ return sysfs_emit(buf, "Not affected\n");
548543 }
549544
550545 ssize_t __weak cpu_show_mds(struct device *dev,
551546 struct device_attribute *attr, char *buf)
552547 {
553
- return sprintf(buf, "Not affected\n");
548
+ return sysfs_emit(buf, "Not affected\n");
554549 }
555550
556551 ssize_t __weak cpu_show_tsx_async_abort(struct device *dev,
557552 struct device_attribute *attr,
558553 char *buf)
559554 {
560
- return sprintf(buf, "Not affected\n");
555
+ return sysfs_emit(buf, "Not affected\n");
561556 }
562557
563558 ssize_t __weak cpu_show_itlb_multihit(struct device *dev,
564
- struct device_attribute *attr, char *buf)
559
+ struct device_attribute *attr, char *buf)
565560 {
566
- return sprintf(buf, "Not affected\n");
561
+ return sysfs_emit(buf, "Not affected\n");
567562 }
568563
569564 ssize_t __weak cpu_show_srbds(struct device *dev,
570565 struct device_attribute *attr, char *buf)
571566 {
572
- return sprintf(buf, "Not affected\n");
567
+ return sysfs_emit(buf, "Not affected\n");
568
+}
569
+
570
+ssize_t __weak cpu_show_mmio_stale_data(struct device *dev,
571
+ struct device_attribute *attr, char *buf)
572
+{
573
+ return sysfs_emit(buf, "Not affected\n");
574
+}
575
+
576
+ssize_t __weak cpu_show_retbleed(struct device *dev,
577
+ struct device_attribute *attr, char *buf)
578
+{
579
+ return sysfs_emit(buf, "Not affected\n");
580
+}
581
+
582
+ssize_t __weak cpu_show_gds(struct device *dev,
583
+ struct device_attribute *attr, char *buf)
584
+{
585
+ return sysfs_emit(buf, "Not affected\n");
586
+}
587
+
588
+ssize_t __weak cpu_show_spec_rstack_overflow(struct device *dev,
589
+ struct device_attribute *attr, char *buf)
590
+{
591
+ return sysfs_emit(buf, "Not affected\n");
573592 }
574593
575594 static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
....@@ -581,6 +600,10 @@
581600 static DEVICE_ATTR(tsx_async_abort, 0444, cpu_show_tsx_async_abort, NULL);
582601 static DEVICE_ATTR(itlb_multihit, 0444, cpu_show_itlb_multihit, NULL);
583602 static DEVICE_ATTR(srbds, 0444, cpu_show_srbds, NULL);
603
+static DEVICE_ATTR(mmio_stale_data, 0444, cpu_show_mmio_stale_data, NULL);
604
+static DEVICE_ATTR(retbleed, 0444, cpu_show_retbleed, NULL);
605
+static DEVICE_ATTR(gather_data_sampling, 0444, cpu_show_gds, NULL);
606
+static DEVICE_ATTR(spec_rstack_overflow, 0444, cpu_show_spec_rstack_overflow, NULL);
584607
585608 static struct attribute *cpu_root_vulnerabilities_attrs[] = {
586609 &dev_attr_meltdown.attr,
....@@ -592,6 +615,10 @@
592615 &dev_attr_tsx_async_abort.attr,
593616 &dev_attr_itlb_multihit.attr,
594617 &dev_attr_srbds.attr,
618
+ &dev_attr_mmio_stale_data.attr,
619
+ &dev_attr_retbleed.attr,
620
+ &dev_attr_gather_data_sampling.attr,
621
+ &dev_attr_spec_rstack_overflow.attr,
595622 NULL
596623 };
597624