Merge tag 'x86-microcode-2022-06-05' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 microcode updates from Thomas Gleixner:

- Disable late microcode loading by default. Unless the HW people get
their act together and provide a required minimum version in the
microcode header for making a halfways informed decision its just
lottery and broken.

- Warn and taint the kernel when microcode is loaded late

- Remove the old unused microcode loader interface

- Remove a redundant perf callback from the microcode loader

* tag 'x86-microcode-2022-06-05' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/microcode: Remove unnecessary perf callback
x86/microcode: Taint and warn on late loading
x86/microcode: Default-disable late loading
x86/microcode: Rip out the OLD_INTERFACE

+20 -112
+7 -8
arch/x86/Kconfig
··· 1358 If you select this option, microcode patch loading support for AMD 1359 processors will be enabled. 1360 1361 - config MICROCODE_OLD_INTERFACE 1362 - bool "Ancient loading interface (DEPRECATED)" 1363 default n 1364 depends on MICROCODE 1365 help 1366 - DO NOT USE THIS! This is the ancient /dev/cpu/microcode interface 1367 - which was used by userspace tools like iucode_tool and microcode.ctl. 1368 - It is inadequate because it runs too late to be able to properly 1369 - load microcode on a machine and it needs special tools. Instead, you 1370 - should've switched to the early loading method with the initrd or 1371 - builtin microcode by now: Documentation/x86/microcode.rst 1372 1373 config X86_MSR 1374 tristate "/dev/cpu/*/msr - Model-specific register support"
··· 1358 If you select this option, microcode patch loading support for AMD 1359 processors will be enabled. 1360 1361 + config MICROCODE_LATE_LOADING 1362 + bool "Late microcode loading (DANGEROUS)" 1363 default n 1364 depends on MICROCODE 1365 help 1366 + Loading microcode late, when the system is up and executing instructions 1367 + is a tricky business and should be avoided if possible. Just the sequence 1368 + of synchronizing all cores and SMT threads is one fragile dance which does 1369 + not guarantee that cores might not softlock after the loading. Therefore, 1370 + use this at your own risk. Late loading taints the kernel too. 1371 1372 config X86_MSR 1373 tristate "/dev/cpu/*/msr - Model-specific register support"
+2
arch/x86/kernel/cpu/common.c
··· 2222 } 2223 #endif 2224 2225 /* 2226 * The microcode loader calls this upon late microcode load to recheck features, 2227 * only when microcode has been updated. Caller holds microcode_mutex and CPU ··· 2252 pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n"); 2253 pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n"); 2254 } 2255 2256 /* 2257 * Invoked from core CPU hotplug code after hotplug operations
··· 2222 } 2223 #endif 2224 2225 + #ifdef CONFIG_MICROCODE_LATE_LOADING 2226 /* 2227 * The microcode loader calls this upon late microcode load to recheck features, 2228 * only when microcode has been updated. Caller holds microcode_mutex and CPU ··· 2251 pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n"); 2252 pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n"); 2253 } 2254 + #endif 2255 2256 /* 2257 * Invoked from core CPU hotplug code after hotplug operations
+11 -104
arch/x86/kernel/cpu/microcode/core.c
··· 373 return ret; 374 } 375 376 - #ifdef CONFIG_MICROCODE_OLD_INTERFACE 377 - static int do_microcode_update(const void __user *buf, size_t size) 378 - { 379 - int error = 0; 380 - int cpu; 381 - 382 - for_each_online_cpu(cpu) { 383 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 384 - enum ucode_state ustate; 385 - 386 - if (!uci->valid) 387 - continue; 388 - 389 - ustate = microcode_ops->request_microcode_user(cpu, buf, size); 390 - if (ustate == UCODE_ERROR) { 391 - error = -1; 392 - break; 393 - } else if (ustate == UCODE_NEW) { 394 - apply_microcode_on_target(cpu); 395 - } 396 - } 397 - 398 - return error; 399 - } 400 - 401 - static int microcode_open(struct inode *inode, struct file *file) 402 - { 403 - return capable(CAP_SYS_RAWIO) ? stream_open(inode, file) : -EPERM; 404 - } 405 - 406 - static ssize_t microcode_write(struct file *file, const char __user *buf, 407 - size_t len, loff_t *ppos) 408 - { 409 - ssize_t ret = -EINVAL; 410 - unsigned long nr_pages = totalram_pages(); 411 - 412 - if ((len >> PAGE_SHIFT) > nr_pages) { 413 - pr_err("too much data (max %ld pages)\n", nr_pages); 414 - return ret; 415 - } 416 - 417 - cpus_read_lock(); 418 - mutex_lock(&microcode_mutex); 419 - 420 - if (do_microcode_update(buf, len) == 0) 421 - ret = (ssize_t)len; 422 - 423 - if (ret > 0) 424 - perf_check_microcode(); 425 - 426 - mutex_unlock(&microcode_mutex); 427 - cpus_read_unlock(); 428 - 429 - return ret; 430 - } 431 - 432 - static const struct file_operations microcode_fops = { 433 - .owner = THIS_MODULE, 434 - .write = microcode_write, 435 - .open = microcode_open, 436 - .llseek = no_llseek, 437 - }; 438 - 439 - static struct miscdevice microcode_dev = { 440 - .minor = MICROCODE_MINOR, 441 - .name = "microcode", 442 - .nodename = "cpu/microcode", 443 - .fops = &microcode_fops, 444 - }; 445 - 446 - static int __init microcode_dev_init(void) 447 - { 448 - int error; 449 - 450 - error = misc_register(&microcode_dev); 451 - if (error) { 452 - pr_err("can't misc_register on minor=%d\n", MICROCODE_MINOR); 453 - return error; 454 - } 455 - 456 - return 0; 457 - } 458 - 459 - static void __exit microcode_dev_exit(void) 460 - { 461 - misc_deregister(&microcode_dev); 462 - } 463 - #else 464 - #define microcode_dev_init() 0 465 - #define microcode_dev_exit() do { } while (0) 466 - #endif 467 - 468 /* fake device for request_firmware */ 469 static struct platform_device *microcode_pdev; 470 471 /* 472 * Late loading dance. Why the heavy-handed stomp_machine effort? 473 * ··· 493 { 494 int ret; 495 496 atomic_set(&late_cpus_in, 0); 497 atomic_set(&late_cpus_out, 0); 498 ··· 544 if (ret == 0) 545 ret = size; 546 547 return ret; 548 } 549 550 static ssize_t version_show(struct device *dev, 551 struct device_attribute *attr, char *buf) ··· 568 return sprintf(buf, "0x%x\n", uci->cpu_sig.pf); 569 } 570 571 - static DEVICE_ATTR_WO(reload); 572 static DEVICE_ATTR(version, 0444, version_show, NULL); 573 static DEVICE_ATTR(processor_flags, 0444, pf_show, NULL); 574 ··· 720 } 721 722 static struct attribute *cpu_root_microcode_attrs[] = { 723 &dev_attr_reload.attr, 724 NULL 725 }; 726 ··· 756 757 cpus_read_lock(); 758 mutex_lock(&microcode_mutex); 759 - 760 error = subsys_interface_register(&mc_cpu_interface); 761 - if (!error) 762 - perf_check_microcode(); 763 mutex_unlock(&microcode_mutex); 764 cpus_read_unlock(); 765 ··· 771 goto out_driver; 772 } 773 774 - error = microcode_dev_init(); 775 - if (error) 776 - goto out_ucode_group; 777 - 778 register_syscore_ops(&mc_syscore_ops); 779 cpuhp_setup_state_nocalls(CPUHP_AP_MICROCODE_LOADER, "x86/microcode:starting", 780 mc_cpu_starting, NULL); ··· 780 pr_info("Microcode Update Driver: v%s.", DRIVER_VERSION); 781 782 return 0; 783 - 784 - out_ucode_group: 785 - sysfs_remove_group(&cpu_subsys.dev_root->kobj, 786 - &cpu_root_microcode_group); 787 788 out_driver: 789 cpus_read_lock();
··· 373 return ret; 374 } 375 376 /* fake device for request_firmware */ 377 static struct platform_device *microcode_pdev; 378 379 + #ifdef CONFIG_MICROCODE_LATE_LOADING 380 /* 381 * Late loading dance. Why the heavy-handed stomp_machine effort? 382 * ··· 584 { 585 int ret; 586 587 + pr_err("Attempting late microcode loading - it is dangerous and taints the kernel.\n"); 588 + pr_err("You should switch to early loading, if possible.\n"); 589 + 590 atomic_set(&late_cpus_in, 0); 591 atomic_set(&late_cpus_out, 0); 592 ··· 632 if (ret == 0) 633 ret = size; 634 635 + add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); 636 + 637 return ret; 638 } 639 + 640 + static DEVICE_ATTR_WO(reload); 641 + #endif 642 643 static ssize_t version_show(struct device *dev, 644 struct device_attribute *attr, char *buf) ··· 651 return sprintf(buf, "0x%x\n", uci->cpu_sig.pf); 652 } 653 654 static DEVICE_ATTR(version, 0444, version_show, NULL); 655 static DEVICE_ATTR(processor_flags, 0444, pf_show, NULL); 656 ··· 804 } 805 806 static struct attribute *cpu_root_microcode_attrs[] = { 807 + #ifdef CONFIG_MICROCODE_LATE_LOADING 808 &dev_attr_reload.attr, 809 + #endif 810 NULL 811 }; 812 ··· 838 839 cpus_read_lock(); 840 mutex_lock(&microcode_mutex); 841 error = subsys_interface_register(&mc_cpu_interface); 842 mutex_unlock(&microcode_mutex); 843 cpus_read_unlock(); 844 ··· 856 goto out_driver; 857 } 858 859 register_syscore_ops(&mc_syscore_ops); 860 cpuhp_setup_state_nocalls(CPUHP_AP_MICROCODE_LOADER, "x86/microcode:starting", 861 mc_cpu_starting, NULL); ··· 869 pr_info("Microcode Update Driver: v%s.", DRIVER_VERSION); 870 871 return 0; 872 873 out_driver: 874 cpus_read_lock();