| .. | .. |
|---|
| 55 | 55 | if (from_nid == NUMA_NO_NODE) |
|---|
| 56 | 56 | return -ENODEV; |
|---|
| 57 | 57 | |
|---|
| 58 | | - ret = cpu_up(cpuid); |
|---|
| 58 | + ret = cpu_device_up(dev); |
|---|
| 59 | 59 | /* |
|---|
| 60 | 60 | * When hot adding memory to memoryless node and enabling a cpu |
|---|
| 61 | 61 | * on the node, node number of the cpu may internally change. |
|---|
| .. | .. |
|---|
| 69 | 69 | |
|---|
| 70 | 70 | static int cpu_subsys_offline(struct device *dev) |
|---|
| 71 | 71 | { |
|---|
| 72 | | - return cpu_down(dev->id); |
|---|
| 72 | + return cpu_device_down(dev); |
|---|
| 73 | 73 | } |
|---|
| 74 | 74 | |
|---|
| 75 | 75 | void unregister_cpu(struct cpu *cpu) |
|---|
| .. | .. |
|---|
| 139 | 139 | #ifdef CONFIG_KEXEC |
|---|
| 140 | 140 | #include <linux/kexec.h> |
|---|
| 141 | 141 | |
|---|
| 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, |
|---|
| 143 | 144 | char *buf) |
|---|
| 144 | 145 | { |
|---|
| 145 | 146 | struct cpu *cpu = container_of(dev, struct cpu, dev); |
|---|
| 146 | | - ssize_t rc; |
|---|
| 147 | 147 | unsigned long long addr; |
|---|
| 148 | 148 | int cpunum; |
|---|
| 149 | 149 | |
|---|
| .. | .. |
|---|
| 156 | 156 | * operation should be safe. No locking required. |
|---|
| 157 | 157 | */ |
|---|
| 158 | 158 | 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); |
|---|
| 163 | 159 | |
|---|
| 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, |
|---|
| 165 | 165 | struct device_attribute *attr, |
|---|
| 166 | 166 | char *buf) |
|---|
| 167 | 167 | { |
|---|
| 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)); |
|---|
| 172 | 169 | } |
|---|
| 173 | | -static DEVICE_ATTR(crash_notes_size, 0400, show_crash_notes_size, NULL); |
|---|
| 170 | +static DEVICE_ATTR_ADMIN_RO(crash_notes_size); |
|---|
| 174 | 171 | |
|---|
| 175 | 172 | static struct attribute *crash_note_cpu_attrs[] = { |
|---|
| 176 | 173 | &dev_attr_crash_notes.attr, |
|---|
| .. | .. |
|---|
| 231 | 228 | static ssize_t print_cpus_kernel_max(struct device *dev, |
|---|
| 232 | 229 | struct device_attribute *attr, char *buf) |
|---|
| 233 | 230 | { |
|---|
| 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); |
|---|
| 236 | 232 | } |
|---|
| 237 | 233 | static DEVICE_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL); |
|---|
| 238 | 234 | |
|---|
| .. | .. |
|---|
| 242 | 238 | static ssize_t print_cpus_offline(struct device *dev, |
|---|
| 243 | 239 | struct device_attribute *attr, char *buf) |
|---|
| 244 | 240 | { |
|---|
| 245 | | - int n = 0, len = PAGE_SIZE-2; |
|---|
| 241 | + int len = 0; |
|---|
| 246 | 242 | cpumask_var_t offline; |
|---|
| 247 | 243 | |
|---|
| 248 | 244 | /* display offline cpus < nr_cpu_ids */ |
|---|
| 249 | 245 | if (!alloc_cpumask_var(&offline, GFP_KERNEL)) |
|---|
| 250 | 246 | return -ENOMEM; |
|---|
| 251 | 247 | 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)); |
|---|
| 253 | 249 | free_cpumask_var(offline); |
|---|
| 254 | 250 | |
|---|
| 255 | 251 | /* display offline cpus >= nr_cpu_ids */ |
|---|
| 256 | 252 | if (total_cpus && nr_cpu_ids < total_cpus) { |
|---|
| 257 | | - if (n && n < len) |
|---|
| 258 | | - buf[n++] = ','; |
|---|
| 253 | + len += sysfs_emit_at(buf, len, ","); |
|---|
| 259 | 254 | |
|---|
| 260 | 255 | 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); |
|---|
| 262 | 257 | 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); |
|---|
| 265 | 260 | } |
|---|
| 266 | 261 | |
|---|
| 267 | | - n += snprintf(&buf[n], len - n, "\n"); |
|---|
| 268 | | - return n; |
|---|
| 262 | + len += sysfs_emit_at(buf, len, "\n"); |
|---|
| 263 | + |
|---|
| 264 | + return len; |
|---|
| 269 | 265 | } |
|---|
| 270 | 266 | static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL); |
|---|
| 271 | 267 | |
|---|
| 272 | 268 | static ssize_t print_cpus_isolated(struct device *dev, |
|---|
| 273 | 269 | struct device_attribute *attr, char *buf) |
|---|
| 274 | 270 | { |
|---|
| 275 | | - int n = 0, len = PAGE_SIZE-2; |
|---|
| 271 | + int len; |
|---|
| 276 | 272 | cpumask_var_t isolated; |
|---|
| 277 | 273 | |
|---|
| 278 | 274 | if (!alloc_cpumask_var(&isolated, GFP_KERNEL)) |
|---|
| .. | .. |
|---|
| 280 | 276 | |
|---|
| 281 | 277 | cpumask_andnot(isolated, cpu_possible_mask, |
|---|
| 282 | 278 | 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)); |
|---|
| 284 | 280 | |
|---|
| 285 | 281 | free_cpumask_var(isolated); |
|---|
| 286 | 282 | |
|---|
| 287 | | - return n; |
|---|
| 283 | + return len; |
|---|
| 288 | 284 | } |
|---|
| 289 | 285 | static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL); |
|---|
| 290 | 286 | |
|---|
| 291 | 287 | #ifdef CONFIG_NO_HZ_FULL |
|---|
| 292 | 288 | static ssize_t print_cpus_nohz_full(struct device *dev, |
|---|
| 293 | | - struct device_attribute *attr, char *buf) |
|---|
| 289 | + struct device_attribute *attr, char *buf) |
|---|
| 294 | 290 | { |
|---|
| 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)); |
|---|
| 300 | 292 | } |
|---|
| 301 | 293 | static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); |
|---|
| 302 | 294 | #endif |
|---|
| .. | .. |
|---|
| 325 | 317 | struct device_attribute *attr, |
|---|
| 326 | 318 | char *buf) |
|---|
| 327 | 319 | { |
|---|
| 328 | | - ssize_t n; |
|---|
| 320 | + int len = 0; |
|---|
| 329 | 321 | u32 i; |
|---|
| 330 | 322 | |
|---|
| 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); |
|---|
| 333 | 326 | |
|---|
| 334 | 327 | for (i = 0; i < MAX_CPU_FEATURES; i++) |
|---|
| 335 | 328 | if (cpu_have_feature(i)) { |
|---|
| 336 | | - if (PAGE_SIZE < n + sizeof(",XXXX\n")) { |
|---|
| 329 | + if (len + sizeof(",XXXX\n") >= PAGE_SIZE) { |
|---|
| 337 | 330 | WARN(1, "CPU features overflow page\n"); |
|---|
| 338 | 331 | break; |
|---|
| 339 | 332 | } |
|---|
| 340 | | - n += sprintf(&buf[n], ",%04X", i); |
|---|
| 333 | + len += sysfs_emit_at(buf, len, ",%04X", i); |
|---|
| 341 | 334 | } |
|---|
| 342 | | - buf[n++] = '\n'; |
|---|
| 343 | | - return n; |
|---|
| 335 | + len += sysfs_emit_at(buf, len, "\n"); |
|---|
| 336 | + return len; |
|---|
| 344 | 337 | } |
|---|
| 345 | 338 | |
|---|
| 346 | 339 | static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env) |
|---|
| .. | .. |
|---|
| 409 | 402 | kfree(dev); |
|---|
| 410 | 403 | } |
|---|
| 411 | 404 | |
|---|
| 405 | +__printf(4, 0) |
|---|
| 412 | 406 | static struct device * |
|---|
| 413 | 407 | __cpu_device_create(struct device *parent, void *drvdata, |
|---|
| 414 | 408 | const struct attribute_group **groups, |
|---|
| .. | .. |
|---|
| 495 | 489 | bool cpu_is_hotpluggable(unsigned cpu) |
|---|
| 496 | 490 | { |
|---|
| 497 | 491 | 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); |
|---|
| 499 | 494 | } |
|---|
| 500 | 495 | EXPORT_SYMBOL_GPL(cpu_is_hotpluggable); |
|---|
| 501 | 496 | |
|---|
| .. | .. |
|---|
| 520 | 515 | ssize_t __weak cpu_show_meltdown(struct device *dev, |
|---|
| 521 | 516 | struct device_attribute *attr, char *buf) |
|---|
| 522 | 517 | { |
|---|
| 523 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 518 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 524 | 519 | } |
|---|
| 525 | 520 | |
|---|
| 526 | 521 | ssize_t __weak cpu_show_spectre_v1(struct device *dev, |
|---|
| 527 | 522 | struct device_attribute *attr, char *buf) |
|---|
| 528 | 523 | { |
|---|
| 529 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 524 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 530 | 525 | } |
|---|
| 531 | 526 | |
|---|
| 532 | 527 | ssize_t __weak cpu_show_spectre_v2(struct device *dev, |
|---|
| 533 | 528 | struct device_attribute *attr, char *buf) |
|---|
| 534 | 529 | { |
|---|
| 535 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 530 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 536 | 531 | } |
|---|
| 537 | 532 | |
|---|
| 538 | 533 | ssize_t __weak cpu_show_spec_store_bypass(struct device *dev, |
|---|
| 539 | 534 | struct device_attribute *attr, char *buf) |
|---|
| 540 | 535 | { |
|---|
| 541 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 536 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 542 | 537 | } |
|---|
| 543 | 538 | |
|---|
| 544 | 539 | ssize_t __weak cpu_show_l1tf(struct device *dev, |
|---|
| 545 | 540 | struct device_attribute *attr, char *buf) |
|---|
| 546 | 541 | { |
|---|
| 547 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 542 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 548 | 543 | } |
|---|
| 549 | 544 | |
|---|
| 550 | 545 | ssize_t __weak cpu_show_mds(struct device *dev, |
|---|
| 551 | 546 | struct device_attribute *attr, char *buf) |
|---|
| 552 | 547 | { |
|---|
| 553 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 548 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 554 | 549 | } |
|---|
| 555 | 550 | |
|---|
| 556 | 551 | ssize_t __weak cpu_show_tsx_async_abort(struct device *dev, |
|---|
| 557 | 552 | struct device_attribute *attr, |
|---|
| 558 | 553 | char *buf) |
|---|
| 559 | 554 | { |
|---|
| 560 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 555 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 561 | 556 | } |
|---|
| 562 | 557 | |
|---|
| 563 | 558 | ssize_t __weak cpu_show_itlb_multihit(struct device *dev, |
|---|
| 564 | | - struct device_attribute *attr, char *buf) |
|---|
| 559 | + struct device_attribute *attr, char *buf) |
|---|
| 565 | 560 | { |
|---|
| 566 | | - return sprintf(buf, "Not affected\n"); |
|---|
| 561 | + return sysfs_emit(buf, "Not affected\n"); |
|---|
| 567 | 562 | } |
|---|
| 568 | 563 | |
|---|
| 569 | 564 | ssize_t __weak cpu_show_srbds(struct device *dev, |
|---|
| 570 | 565 | struct device_attribute *attr, char *buf) |
|---|
| 571 | 566 | { |
|---|
| 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"); |
|---|
| 573 | 592 | } |
|---|
| 574 | 593 | |
|---|
| 575 | 594 | static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); |
|---|
| .. | .. |
|---|
| 581 | 600 | static DEVICE_ATTR(tsx_async_abort, 0444, cpu_show_tsx_async_abort, NULL); |
|---|
| 582 | 601 | static DEVICE_ATTR(itlb_multihit, 0444, cpu_show_itlb_multihit, NULL); |
|---|
| 583 | 602 | 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); |
|---|
| 584 | 607 | |
|---|
| 585 | 608 | static struct attribute *cpu_root_vulnerabilities_attrs[] = { |
|---|
| 586 | 609 | &dev_attr_meltdown.attr, |
|---|
| .. | .. |
|---|
| 592 | 615 | &dev_attr_tsx_async_abort.attr, |
|---|
| 593 | 616 | &dev_attr_itlb_multihit.attr, |
|---|
| 594 | 617 | &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, |
|---|
| 595 | 622 | NULL |
|---|
| 596 | 623 | }; |
|---|
| 597 | 624 | |
|---|